// ------------------------------------------------------------------------------- // --------- PndSimpleNtuple -------- // ------------------------------------------------------------------------------- // // Represents a simplified N-Tuple based on a ROOT TTree. // // Branches of type double, float, int or bool are created on the fly with the // command // // 'Column(TString name, double/float/int/bool value);' // // At the end of each event (i.e. when the N-Tuple should be filled) either // // 'DumpData()' or // 'AcceptData()' // // has to be called. The method 'AcceptData()' is a conditional fill in case a // certain precut is fulfilled, which can be set either in the constructor with // // PndSimpleNtuple(TString name, TString title, TString ) // // or with the method // // SetPrecut(TString precut) // // which can even be changed inbetween. The precut is a TFormula directly based // on the branches of the TTree. // // ------------------------------------------------------------------------------- #include "PndSimpleNtuple.h" #include "TRegexp.h" #include using std::cout; using std::endl; TString typearr[8] = {"D","F","I","B","D[]","F[]","I[]","B[]"}; // ------------------------------------------------------------------------------- PndSimpleNtuple::PndSimpleNtuple(TString name, TString title, TString precut) : fTree(new TTree(name, title)),fTmpTree(new TTree("tmp", "")), fPrecut(precut), fFml(0) { fTree->SetDirectory(0); fTmpTree->SetDirectory(0); }; // ---------------------------------- // DOUBLE VALUES // ---------------------------------- void PndSimpleNtuple::Column(const TString &name, double value) { // new branch? if (fBrTypes.find(name) == fBrTypes.end()) { fBrTypes[name] = 0; // type double fDValues[name] = value; fTree->Branch(name.Data(), &(fDValues[name]), (name+"/D").Data()); fTmpTree->Branch(name.Data(), &(fDValues[name]), (name+"/D").Data()); } else if ( fBrTypes[name] != 0) { std::cout<<" - WARNING - Type mismatch of branch '"<Branch(name.Data(), &(fFValues[name]), (name+"/F").Data()); fTmpTree->Branch(name.Data(), &(fFValues[name]), (name+"/F").Data()); } else if ( fBrTypes[name] != 1) { std::cout<<" - WARNING - Type mismatch of branch '"<Branch(name.Data(), &(fIValues[name]), (name+"/I").Data()); fTmpTree->Branch(name.Data(), &(fIValues[name]), (name+"/I").Data()); } else if ( fBrTypes[name] != 2) { std::cout<<" - WARNING - Type mismatch of branch '"<Branch(name.Data(), &(fBValues[name]), (name+"/B").Data()); fTmpTree->Branch(name.Data(), &(fBValues[name]), (name+"/B").Data()); } else if ( fBrTypes[name] != 3) { std::cout<<" - WARNING - Type mismatch of branch '"<Fill(); fTmpTree->GetEntry(fTmpTree->GetEntriesFast()-1); return fFml->EvalInstance(); } // ---------------------------------- int PndSimpleNtuple::ShowBranches() { int cnt=0; for (auto x: fBrTypes) { cout <