1 #include "CutTreeSelector.h" 2 #include "TProofOutputFile.h" 3 #include "TTreeFormula.h" 4 #include "DrawStrings.h" 5 #include "CutOptimizer.h" 16 : fOutTree(NULL), fProofOutFile(NULL), fOutFileName(
"fOutFileName", outFileName), fTreeName(
"fTreeName", treeName),
17 fFormulaStrings(new TList), fFormulas(NULL), fIterationFormula()
32 SummarySelector::Notify();
33 TIter next(fFormulas);
34 while(TTreeFormula* form = dynamic_cast<TTreeFormula*>(next())){
52 fFormulaStrings->Delete();
54 std::vector<const char*>::const_iterator it = formulaStrings.begin();
55 for(; it != formulaStrings.end(); ++it){
56 fFormulaStrings->Add(
new TObjString(*it));
58 fFormulaStrings->SetOwner();
67 fInput->Add(&fOutFileName);
68 fInput->Add(&fTreeName);
69 fInput->Add(fFormulaStrings);
78 fOutFileName = *(
dynamic_cast<TNamed*
>(fInput->FindObject(
"fOutFileName")));
79 fTreeName = *(
dynamic_cast<TNamed*
>(fInput->FindObject(
"fTreeName")));
80 fFormulaStrings =
dynamic_cast<TList*
>(fInput->FindObject(
"fFormulaStrings"));
84 fProofOutFile =
new TProofOutputFile(fOutFileName.GetTitle(), TProofOutputFile::kMerge);
85 fOutput->Add(fProofOutFile);
87 fOut = fProofOutFile->OpenFile(
"recreate");
88 fOutTree =
new TTree(fTreeName.GetTitle(), fTreeName.GetTitle());
90 fFormulas =
new TList();
91 fFormulas->SetOwner(
true);
93 const size_t nForm = fFormulaStrings->GetEntries();
94 fIntVals.resize(nForm, 0);
95 fFloatVals.resize(nForm, 0);
96 fFormulaReturnTypes.resize(nForm, 0);
112 fFormulas->SetOwner(
true);
115 if(fFormulas->GetEntries()==0){
117 const size_t nForm = fFormulaStrings->GetEntries();
118 TObjArray* fOutBranchList = fOutTree->GetListOfBranches();
119 fIterationFormula.resize(nForm,
false);
121 for(UInt_t fInd=0; fInd < nForm; fInd++){
122 const TString& formula =
dynamic_cast<TObjString*
>(fFormulaStrings->At(fInd))->String();
124 TString formName = TString::Format(
"form%u", fInd);
125 TTreeFormula* f =
new TTreeFormula(formName, formula, tree);
130 if(formula.Contains(
"Iteration$")){
131 fIterationFormula[fInd] =
true;
135 if(fOutBranchList->GetEntries() < (Int_t)nForm){
138 fFormulaReturnTypes.at(fInd) = f->IsInteger();
139 if(fFormulaReturnTypes.at(fInd) > 0){
140 fOutTree->Branch(bName, &fIntVals.at(fInd));
143 fOutTree->Branch(bName, &fFloatVals.at(fInd));
176 if(matchesSelection){
178 TIter next(fFormulas);
179 while(TObject* obj = next()){
180 TTreeFormula* f =
dynamic_cast<TTreeFormula*
>(obj);
182 fIntVals.at(fInd) = -9999;
183 fFloatVals.at(fInd) = -9999;
185 bool doneAnIteration =
false;
192 for(
int i=0; i < fMaxNdata; i++){
193 if(!doneAnIteration && fCumulativeCutReturns.at(i) > 0){
195 bool requireIteration = fIterationFormula[fInd] || (f->GetNdata() > 1 && i < f->GetNdata());
198 if(fFormulaReturnTypes.at(fInd) > 0){
199 fIntVals.at(fInd) = requireIteration ? f->EvalInstance(i) : f->EvalInstance();
203 fFloatVals.at(fInd) = requireIteration ? f->EvalInstance(i) : f->EvalInstance();
206 doneAnIteration =
true;
244 fFormulaReturnTypes.clear();
260 fProofOutFile =
dynamic_cast<TProofOutputFile*
>(fOutput->FindObject(fOutFileName.GetTitle()));
263 TFile* f = fProofOutFile->OpenFile(
"read");
266 TTree* t =
dynamic_cast<TTree*
>(f->Get(fTreeName.GetTitle()));
269 std::cout <<
"Created " << t->GetName() <<
" in file " << f->GetName() <<
" has " 270 << t->GetEntries() <<
" entries..." << std::endl;
void setFormulaStrings(const std::vector< const char *> &formulaStrings)
Set the formula strings to evaluate and put into the created output tree.
virtual Bool_t Process(Long64_t entry)
Reads the AnitaEventSummary TTree entry and sets the fSum pointer. Cycles through the fCuts...
CutTreeSelector(const char *outFileName="CutTreeSelector.root", const char *reducedSumTreeName="cutTree")
To force eval instance with an argument.
TList * fFormulaStrings
Where the formula results are written in the case of a int-like variable.
virtual void Begin(TTree *tree)
virtual void SlaveBegin(TTree *tree)
virtual void Begin(TTree *tree)
static TString branchifyName(const char *formStr)
**
virtual void Init(TTree *tree)
virtual void SlaveTerminate()
virtual void Init(TTree *tree)
virtual Bool_t Process(Long64_t entry)
virtual void SlaveTerminate()
bool fDoDemoHist
A histogram of peak[1][0].value.
virtual void SlaveBegin(TTree *tree)