I have a tree that was made with another root script, and I want to read certain values for my analysis. The docs say I should define my variables, call SetBranchAddress on my tree, call GetEntry on the tree, and after that I my variables should have the values appropriate to that entry of the tree. A colleague tried it this way on his tree, and it worked fine:
f = new TFile(“tree.root”);
float test;
T->SetBranchAddress(“integradius”, &test);
T->GetEntries();
for(int i = 0; i<50; i++){ T->GetEntry(i); cout << test << endl;}
I tried to do the identical thing with my tree, …
root [0] f = new TFile("…/data/20110419090551_DES2219-4147.root");
Warning in TClass::TClass: no dictionary for class Db::DBImage is available
Warning in TClass::TClass: no dictionary for class Db::DatabaseBase is available
Warning in TClass::TClass: no dictionary for class XYZTree is available
Warning in TClass::TClass: no dictionary for class Db::DBTruth is available
Warning in TClass::TClass: no dictionary for class Db::DBSCoaddObject is available
Warning in TClass::TClass: no dictionary for class Db::DBSObject is available
root [1] float test = 9.9;
root [2] tree->SetBranchAddress(“magerr_model_g”, &test);
root [3] tree->GetEntries();
root [4] for(int i = 0; i<50; i++){ tree->GetEntry(i); cout << test << endl;}
9.9
9.9
9.9
…
9.9
9.9
9.9
… and found that GetEntry never changes the value of my variable. (Those warnings always come, and I ignore them, apparently without ill effects.) A Scan …
root [5] tree->Scan(“magerr_model_g”);
Warning in TGMimeTypes::TGMimeTypes: error opening mime type file /etc/root/root.mimes
- Row * magerr_mo *
-
0 * 0.1407223 *
-
1 * 0.2882340 *
-
2 * 0.1940311 *
…
-
22 * 0.0596469 *
-
23 * 0.0983687 *
-
24 * 0.1284388 *
Type to continue or q to quit ==> q
… verifies that the values in this branch of the tree are “interesting”. In addition, if there were no branch with this name, or if the values were of a different type, root would have complained (even without the Scan). It doesn’t make any difference whether test is declared as float of Float_t.
It seems to me I am not doing anything complicated or esoteric here. Calling SetBranchAddress and GetEntry in this way is “the default and recommended way” to read a TTree. (root.cern.ch/root/html528/TTree. … e:GetEntry) I have boiled the code down to a few lines, so typos and strange interactions are unlikely. I am totally puzzled by this behavior and would appreciate any help to get this script working properly. (I have browsed this forum and found a number of similar posts, but nothing close enough to get me moving again.)
Regards,
Art Carlson
University Observatory Munich