// For some reason the branches // of the tree don't get reactivated once they were // deactivated. But strangely this is the case when only // one tree is in the chain, it works with two trees in it. // // This is a minimal example. // // Tested in // * Root 5.26/00 // * Root 5.34/03 // // root -l TestTTreeBranchActivation.C++ // #include #include #include #include #include "TROOT.h" #include "TChain.h" TTree *t; // branches float scanpoint; float scanbest; float chi2minToy; float chi2minGlobalToy; void open() { t->SetBranchAddress("scanpoint", &scanpoint); t->SetBranchAddress("scanbest", &scanbest); t->SetBranchAddress("chi2minToy", &chi2minToy); t->SetBranchAddress("chi2minGlobalToy", &chi2minGlobalToy); } /// /// Loop over the tree onece. /// (originally to get min and max values) /// void computeMinMaxN() { t->SetBranchStatus("*", 0); t->SetBranchStatus("scanpoint", 1); Long64_t nentries = t->GetEntries(); for (Long64_t i = 0; i < nentries; i++) t->GetEntry(i); t->SetBranchStatus("*", 1); } void TestTTreeBranchActivation() { // open TTrees into a chain TChain *c = new TChain("plugin"); c->Add("run1.root"); // c->Add("run2.root"); // UNCOMMENT AND IT WILL WORK t = c; // connect branches open(); // deactivate branches, loop over tree, re-activate branches computeMinMaxN(); // main loop, loops over tree again int nentries = t->GetEntries(); for (int i = 0; i < nentries; i++) { t->GetEntry(i); // print some branches if ( i%1000==0) printf("%5i %f %f %f %f\n", i, chi2minToy,chi2minGlobalToy, scanpoint,scanbest); } }