I have been trying to read and analyze the data from a tree by writing a class. I initialized the variables and array in the constructor and set the branch address in a function of the class. There is no error message compling the files and running the analysis but the data does not pass to these array and variables (in fact when I print them out they show 0). Here is the short version of my script.
Reader::Reader(const char* dirName, const char* fileName, int maxFiles):mMaxFiles(maxFiles), mDebug(0), mCurrentFile(0),mTTree(0)
{
multi=0;
Theta[20]={0};
KinEnergy[20]={0};
Phi[20]={0};
}
int Reader::Read()
{
Chain = new Chain("E12345","Event");
int nFiles=0;
//call a function that fills the chain with root files listed in a text file
if (file!="") { // if a filename was given
if( strstr(file.c_str(),".lis") || strstr(file.c_str(),".list") ) { // if a file list is specified
try {
nFiles = fillChain(mTChain, (dir+file).c_str(), mMaxFiles);
}
catch(StException e) {
throw e;
}
}
else { // a single file was specified
mTChain->Add((dir+file).c_str());
nFiles++;
}
Chain->SetBranchAddress("event.multi",&multi);
Chain->SetBranchAddress("event.Theta",Theta);
Chain->SetBranchAddress("event.Phi",Phi);
Chain->SetBranchAddress("event.KinEnergy",KinEnergy);
return nFiles;
}
However, the branch address are set if I simply use a macro like
double KinEnergy[20];
double Phi[20];
...
...
...
Chain->SetBranchAddress(event.KinEnergy,KinEnergy);
...etc
I dont understand what the problem is as the logic seems ok. So I am hoping someone can tell me the correct approach to set branch address in a class. Thank you very much.