1 #include "SummarySelector.h" 6 #include "DrawStrings.h" 7 #include "TTreeFormula.h" 9 #include "TTreeFormulaManager.h" 21 : TSelector(), fChain(NULL),
22 fCuts(new TList), fCutFormulas(NULL),
26 fDemoHist(NULL), fDoDemoHist(false)
30 fCuts->SetName(
"fCuts");
52 fCuts->Add(const_cast<TCut*>(analysisCut));
74 fCutFormulas =
new TList;
76 fCutFormulas->SetOwner(
true);
77 fCutFormulas->Delete();
79 if(fCutFormulas->GetEntries()==0){
80 const int nForm = fCuts->GetEntries();
81 fCutReturns.resize(nForm, std::vector<Int_t>());
85 for(UInt_t fInd=0; fInd < nForm; fInd++){
86 const TCut* eventSelection =
dynamic_cast<const TCut*
>(fCuts->At(fInd));
88 TString formName = TString::Format(
"cutForm_%s", eventSelection->GetName());
89 TTreeFormula* f =
new TTreeFormula(formName, eventSelection->GetTitle(), fTree);
92 if(f->GetNdata() > fMaxNdata){
93 fMaxNdata = f->GetNdata();
98 for(UInt_t fInd=0; fInd < fCutReturns.size(); fInd++){
99 fCutReturns.at(fInd).resize(fMaxNdata,
false);
101 fCumulativeCutReturns.resize(fMaxNdata,
false);
105 fDemoForm =
new TTreeFormula(
"demo_form",
"run", fTree);
132 Bool_t Acclaim::SummarySelector::Notify()
134 TIter next(fCutFormulas);
135 while(TTreeFormula* form = dynamic_cast<TTreeFormula*>(next())){
155 fInput->Add(
new TNamed(
"fDoDemo",
"hDemo"));
169 fCuts =
dynamic_cast<TList*
>(fInput->FindObject(
"fCuts"));
171 TNamed* n =
dynamic_cast<TNamed*
>(fInput->FindObject(
"fDoDemo"));
172 fDoDemoHist = n ? true :
false;
174 fDemoHist =
new TH1D(
"hDemo",
"Demo histogram - run; run; number of events", 310, 130, 440);
175 fOutput->Add(fDemoHist);
210 fTree->LoadTree(entry);
212 Bool_t matchesSelection =
true;
213 for(
int i=0; i < fMaxNdata; i++){
214 fCumulativeCutReturns[i] =
true;
219 TIter next(fCutFormulas);
221 while (TObject* obj = next()){
222 TTreeFormula* form =
dynamic_cast<TTreeFormula*
>(obj);
224 bool anyIterationsPass =
false;
225 for(
int i=0; i < fMaxNdata; i++){
226 Float_t cutVal = form->GetNdata() > 1 && i < form->GetNdata() ? form->EvalInstance(i) : form->EvalInstance();
227 fCutReturns.at(fInd).at(i) = cutVal;
229 bool thisPass = cutVal > 0;
231 fCumulativeCutReturns.at(i) = bool(fCumulativeCutReturns.at(i)) && thisPass;
233 anyIterationsPass = anyIterationsPass || fCumulativeCutReturns.at(i);
250 matchesSelection = matchesSelection && anyIterationsPass;
257 if(!matchesSelection){
263 if(matchesSelection && fDemoHist){
264 fDemoHist->Fill(fDemoForm->EvalInstance());
275 return matchesSelection;
304 fDemoHist =
dynamic_cast<TH1D *
>(fOutput->FindObject(
"hDemo"));
306 TCanvas *c1 =
new TCanvas();
307 fDemoHist->Draw(
"hist");
314 Warning(
"Terminate",
"histogram not found");
virtual Bool_t Process(Long64_t entry)
Reads the AnitaEventSummary TTree entry and sets the fSum pointer. Cycles through the fCuts...
virtual ~SummarySelector()
SummarySelector(const char *sumBranchName="sum")
Set this to true to generate and fill fDemoHist.
virtual void Begin(TTree *tree)
TList * fCuts
Which TTree formula determines the peak direction?
Template TSelector to be inherited from, designed for use with SummarySet.
virtual void Init(TTree *tree)
void addCut(const TCut *analysisCut)
virtual void SlaveTerminate()
virtual void SlaveBegin(TTree *tree)