#include "test.h" namespace tester { inline test::test(TString fName) { gROOT->ProcessLine("#include "); // dumb root stuff fChain = new TChain("test_tree"); fChain->Add(fName); fChain->SetMakeClass(1); fChain->SetBranchStatus("*", 0); nEvent = fChain->GetEntries(); cout << "Chain has " << nEvent << " events" << endl; entry = 0; to_get.push_back("pt"); to_get.push_back("eta"); to_get.push_back("phi"); to_get.push_back("E"); } void test::LoadEvent(Long64_t& jentry) { cout << "Loading event " << jentry << endl; entry=jentry; fChain->GetEntry(jentry); }; // LoadEvent void test::GetBranches() { TString prefix = "jet"; TString var(prefix); // properties // first, create "brnchs" and "v_props" vectors for(vector::const_iterator p = to_get.begin(); p != to_get.end(); p++) { var = (prefix+"_"+*p); if(fChain->GetListOfBranches()->FindObject(var.Data())) { brnchs.push_back(0); v_props.push_back(0); } } // from now on, DO NOT RESIZE "brnchs" nor "v_props" vectors Long64_t ientry = fChain->LoadTree(entry); // if (ientry < 0) return; fChain->SetBranchStatus("*", 0); Int_t i = 0; for(vector::const_iterator p = to_get.begin(); p != to_get.end(); p++) { var = (prefix+"_"+*p); cout << "Looking for " << var << endl; if(fChain->GetListOfBranches()->FindObject(var.Data())) { #if 1 /* 0 or 1 */ // why is the "SetBranchStatus(..., 1)" needed? // in principle, the "SetBranchAddress" call below should // automatically set the "status" to 1, but it doesn't ... // one needs an explicit "SetBranchStatus" call here ... but why? // (note: if it's not done, "v_props[i]" will NOT be initialized) fChain->SetBranchStatus(var.Data(), 1); #endif /* 0 or 1 */ fChain->SetBranchAddress(var.Data(), &(v_props[i]), &(brnchs[i])); if(!(brnchs[i])) { cout << "Cannot find TBranch " << var << " in TTree" << endl; } if (brnchs[i]) (brnchs[i])->GetEntry(ientry); if(!(v_props[i])) { cout << "No vector loaded from TBranch " << var << endl; } if (v_props[i]) cout << "vector size " << (v_props[i])->size() << endl; i++; } } } // GetBranches void test::DumpProperties() { #if 0 /* 0 or 1 */ Long64_t ientry = fChain->LoadTree(entry); if (ientry < 0) return; for(vector::const_iterator br = brnchs.begin(); br != brnchs.end(); br++) { if (*br) (*br)->GetEntry(ientry); } #endif /* 0 or 1 */ if((v_props.size()==0) || (v_props[0]==0)) { return; } for(int j=0; j<(int)v_props[0]->size(); j++) { cout << j << "\t"; for(int k=0; k<(int)brnchs.size(); k++) { cout << (v_props.at(k))->at(j) << "\t"; } cout << endl; } } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- void test::Run() { cout <GetBranches(); atest->Run(); return 1; }