////////////////////////////////////////////////////////// // // By E.N. March 5th 2002 // modified to use TMBTreeInclude.h, 7-OCT-2002 SP // updated by EN april 26 2004 to latest branches and // to adopt to d0root_tmbtree // beautified by AN 2004-04-05 // ////////////////////////////////////////////////////////// #ifndef TMBTree_bu_h #define TMBTree_bu_h #include "TROOT.h" #include "TFile.h" #include "TTree.h" #include "TClonesArray.h" #include "TBranchElement.h" #include "tmb_tree/TMBTreeInclude.h" #include #include #include #include class TH1; class TMBTree_bu { public: TTree *fChain; //!pointer to the analyzed TTree or TChain std::vector fH; // example & test histos std::list fBranchesFound; // all of fChain's branches that are used std::list fBranchesNotFound; // branches that are not in fChain // Top branch objects TClonesArray* fTrks; // Container of tracks TClonesArray* fIsoTrks; // Container of isolated trackss TClonesArray* fEmcl; // Container of Emcl TClonesArray* fEmCells; // Container of EmCells TClonesArray* fMuons; // Container of Muon TClonesArray* fJets; // Container of Jets TClonesArray* fVrts; // Container of Jets TClonesArray* fFps; // Container of Fps TClonesArray* fCps; // Container of Cps TClonesArray* fTaus; // Container of Taus TClonesArray* fMCvtx; // Container of MCvtx TClonesArray* fMCpart; // Container of MCpart TClonesArray* fTRefs; // Container of TRefs TClonesArray* fTrig; // Container of Trig TClonesArray* fLeBob; // Container of LeBob TClonesArray* fBCJets; // Container of BCJets TMBMet* fMet; TMBGlob* fGlob; TMBCalQual* fCalQual; TMBMCevtInfo* fMCevtInfo; // MC Event Info TMBL1Muon* fL1Muon; //Container of L1Muon TClonesArray* fL1CalTwr; //Container of L1CalTwr TClonesArray* fL1CalEMTwr; //Container of L1CalEMTwr TClonesArray* fL2Muon; //Container of L2Muon TClonesArray* fL2Jet; //Container of L2Jet TClonesArray* fL2EM; //Container of L2EM TMBL3ToolResults* fL3ToolResults; //Container of L3ToolResults TClonesArray* fHist; //Container of Hist Bool_t SetBranchAddress(const char* branchname, TClonesArray** member); Bool_t SetBranchAddress(const char* branchname, void* val); TMBTree_bu(TTree *tree=0); TMBTree_bu(const char* filename); ~TMBTree_bu(); Int_t Cut(Int_t entry); void Init(TTree *tree); void Loop(); void Status(); void Show(Int_t entry = -1); void Walk(TMBMCpart * mcpart, Bool_t debug=kFALSE); Bool_t GetEntry(Int_t entry); TTree* GetTree() const { return fChain; } }; #endif #ifdef TMBTree_bu_cxx TMBTree_bu::TMBTree_bu(const char* filename): fChain(0), fTrks(0), fIsoTrks(0), fEmcl(0), fEmCells(0), fMuons(0), fJets(0), fVrts(0), fFps(0), fCps(0), fTaus(0), fMCvtx(0), fMCpart(0), fTRefs(0), fTrig(0), fLeBob(0), fBCJets(0), fMet(0), fGlob(0), fCalQual(0), fMCevtInfo(0), fL1Muon(0), fL1CalTwr(0), fL1CalEMTwr(0), fL2Muon(0), fL2Jet(0), fL2EM(0), fL3ToolResults(0), fHist(0) { if (!filename) filename = "tmb_tree.root"; TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename); if (!f) f = new TFile(filename); if (!f) return; TTree *tree = (TTree*)gDirectory->Get("TMBTree"); // Default tree name Init(tree); } TMBTree_bu::TMBTree_bu(TTree *tree): fChain(0), fTrks(0), fIsoTrks(0), fEmcl(0), fEmCells(0), fMuons(0), fJets(0), fVrts(0), fFps(0), fCps(0), fTaus(0), fMCvtx(0), fMCpart(0), fTRefs(0), fTrig(0), fLeBob(0), fBCJets(0), fMet(0), fGlob(0), fCalQual(0), fMCevtInfo(0), fL1Muon(0), fL1CalTwr(0), fL1CalEMTwr(0), fL2Muon(0), fL2Jet(0), fL2EM(0), fL3ToolResults(0), fHist(0) { // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. //Info("TMBTree_bu::TMBTree_bu(TTree *tree)", "tree = %p", tree); if (tree == 0) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("tmb_tree.root"); if (!f) f = new TFile("tmb_tree.root"); if (!f) return; tree = (TTree*)gDirectory->Get("TMBTree"); // Default tree name } Init(tree); } TMBTree_bu::~TMBTree_bu() { if (!fChain) return; delete fChain->GetCurrentFile(); } void TMBTree_bu::Init(TTree *tree) { // Set branch addresses if (tree == 0) return; fChain = tree; SetBranchAddress("Trks", &fTrks); SetBranchAddress("IsoTrks", &fIsoTrks); SetBranchAddress("Emcl", &fEmcl); SetBranchAddress("EmCells", &fEmCells); SetBranchAddress("Muon", &fMuons); SetBranchAddress("Jets", &fJets); SetBranchAddress("Vrts", &fVrts); SetBranchAddress("Fps", &fFps); SetBranchAddress("Cps", &fCps); SetBranchAddress("Taus", &fTaus); SetBranchAddress("MCvtx", &fMCvtx); SetBranchAddress("MCpart", &fMCpart); SetBranchAddress("TRefs", &fTRefs); SetBranchAddress("Trig", &fTrig); SetBranchAddress("Hist", &fHist); SetBranchAddress("BCJets", &fBCJets); SetBranchAddress("L1CalTwr", &fL1CalTwr); SetBranchAddress("L1CalEMTwr", &fL1CalEMTwr); SetBranchAddress("L2Muon", &fL2Muon); SetBranchAddress("L2Jet", &fL2Jet); SetBranchAddress("L2EM", &fL2EM); SetBranchAddress("Met", &fMet); SetBranchAddress("Glob", &fGlob); SetBranchAddress("MCevtInfo", &fMCevtInfo); SetBranchAddress("L1Muon", &fL1Muon); SetBranchAddress("L3ToolResults", &fL3ToolResults); SetBranchAddress("CalQual", &fCalQual); Status(); } Bool_t TMBTree_bu::GetEntry(Int_t entry) { Bool_t ret=(fChain->LoadTree(entry)>=0); // LoadTree ret val incompatible for TChain and TTree // until ROOT cvs 2004-05-10 if (fChain->IsA()==TTree::Class()) ret=(fChain->GetEntries()>entry); return (ret& fChain->GetEntry(entry)>=0); } Bool_t TMBTree_bu::SetBranchAddress(const char* branchname, void* val) { if (!fChain) { Warning("SetBranchAddress", "Chain is not initialized yet!"); return kFALSE; } Bool_t found=(fChain->GetBranch(branchname)); std::list* list=(found ? &fBranchesFound : &fBranchesNotFound); list->push_back(branchname); if (found) fChain->SetBranchAddress(branchname, val); return found; } Bool_t TMBTree_bu::SetBranchAddress(const char* branchname, TClonesArray** member) { // internal method - just don't call it. if (!fChain) { Warning("SetBranchAddress", "Chain is not initialized yet!"); return kFALSE; } TBranch* b=fChain->GetBranch(branchname); if (!b) { fBranchesNotFound.push_back(branchname); return kFALSE; } TClass* cl=gROOT->GetClass(b->GetClassName(), kTRUE); if (!cl) { Warning("SetBranchAddress", "Branch \"%s\" contains objects of unknown class \"%s\"!", branchname, b->GetClassName()); return kFALSE; } if (cl==TClonesArray::Class()) { TBranchElement* be=(TBranchElement*)b; cl=gROOT->GetClass(be->GetClonesName(), kTRUE); if (!cl) { Warning("SetBranchAddress", "Branch \"%s\" contains objects of unknown class \"%s\"!", branchname, be->GetClonesName()); return kFALSE; } *member=new TClonesArray(be->GetClonesName()); } else { Warning("SetBranchAddress", "Branch \"%s\" does not contain a TClonesArray but \"%s\"!", branchname, b->GetClassName()); return kFALSE; } fChain->SetBranchAddress(branchname, member); fBranchesFound.push_back(branchname); return kTRUE; } void TMBTree_bu::Status() { std::list* l[2]={&fBranchesFound, &fBranchesNotFound}; for (Int_t iL=0; iL<2; iL++) { l[iL]->sort(); Bool_t first=kTRUE; std::list::iterator iB; for(iB=l[iL]->begin(); iB!=l[iL]->end(); iB++) { if (first) { std::cout << (iL? "--- Known branches not found in tmb_tree:" : "+++ Known and available branches:") << std::endl << *iB; first=kFALSE; } else std::cout << ", " << *iB; } std::cout << std::endl; } } void TMBTree_bu::Show(Int_t entry) { // Print contents of entry. // If entry is not specified, print current entry if (!fChain) return; fChain->Show(entry); } Int_t TMBTree_bu::Cut(Int_t entry) { // This function may be called from Loop. // returns 1 if entry is accepted. // returns -1 otherwise. // dummy: if (entry<0) return -1; return 1; } #endif // #ifdef TMBTree_bu_cxx