ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/src/baseClass.C
Revision: 1.2
Committed: Tue Jul 20 15:32:43 2010 UTC (14 years, 9 months ago) by jueugste
Content type: text/plain
Branch: MAIN
Changes since 1.1: +358 -25 lines
Log Message:
many changes...

File Contents

# User Rev Content
1 jueugste 1.1 #define baseClass_cxx
2     #include "baseClass.h"
3    
4 jueugste 1.2 #include "TH1I.h"
5     #include "TFile.h"
6    
7 jueugste 1.1 baseClass::baseClass(string * inputList, string * cutFile, string * treeName, string * outputFileName, string * cutEfficFile)
8     {
9     std::cout << "baseClass::baseClass(): begins " << std::endl;
10     inputList_ = inputList;
11     cutFile_ = cutFile;
12     treeName_= treeName;
13     outputFileName_ = outputFileName;
14     cutEfficFile_ = cutEfficFile;
15     init();
16     std::cout << "baseClass::baseClass(): ends " << std::endl;
17     }
18    
19     baseClass::~baseClass()
20     {
21     std::cout << "baseClass::~baseClass(): begin " << std::endl;
22 jueugste 1.2 // the following lines are from the jet prompt thing...
23     // if( !writeCutHistos() )
24     // {
25     // STDOUT("ERROR: writeCutHistos did not complete successfully.");
26     // }
27     // if( !writeCutEfficFile() )
28     // {
29     // STDOUT("ERROR: writeStatFile did not complete successfully.");
30     // }
31 jueugste 1.1 output_root_->Close();
32     std::cout << "baseClass::~baseClass(): end " << std::endl;
33     }
34    
35    
36     double baseClass::multiply(double a, double b)
37     {
38     double c;
39     c = a * b;
40     return c;
41     }
42    
43 jueugste 1.2 void baseClass::getHLTtable() {
44     bool printTriggerTable=true;
45     if(tree_ == NULL){
46     std::cout << "baseClass::init(): ERROR: tree_ = NULL " << std::endl;
47     return;
48     }
49    
50     tree_->GetEntry();
51     TFile *f = tree_->GetCurrentFile();
52    
53     cout<<f->GetName()<<endl;;
54     TH1I *hlt_stats = (TH1I*)f->Get("analyze/HLTTriggerStats");
55     cout<<"here 3"<<endl;
56    
57     // clear the map
58     if(!HLTmap.empty()) {
59     HLTmap.erase(HLTmap.begin(),HLTmap.end());
60     }
61    
62     for( int i=0; i < hlt_stats->GetNbinsX(); i++ ){
63     if(printTriggerTable==true) cout<<i<<": "<<hlt_stats->GetXaxis()->GetBinLabel(i+1)<<endl;
64     HLTmap[hlt_stats->GetXaxis()->GetBinLabel(i+1)] = i;
65     }
66     }
67    
68     int baseClass::getHLTtriggerBit(string triggerName) {
69     if(HLTmap.empty()) {
70     cerr<<"HLTtrigger: no HLTmap available!"<<endl;
71     return -1;
72     }
73     map<string, int>::iterator iter = HLTmap.find(triggerName);
74     //cout<<"HLT bit: "<<iter->second<<endl; // iter->second is the HLT trigger bit
75     if(iter==HLTmap.end()) {
76     cerr<<"HLTtrigger: trigger name "<<triggerName<< " not found!"<<endl;
77     return -1;
78     }
79     else {
80     return iter->second;
81     }
82     }
83    
84 jueugste 1.1 bool baseClass::triggerBitSelection(int hlt[200], int l1phys[128], int l1tech[64])
85     {
86     bool passed=false;
87     if((l1tech[40]==1 || l1tech[41]==1) && // pass BSC
88     (l1tech[36]==0 && l1tech[37]==0 && l1tech[38]==0 && l1tech[39]==0)// && // Beam Halo Veto
89     // l1tech[0]==1 && // pass BPTX
90     // hlt[116]==1 // pass Physics Declared Bit
91     )
92     {
93     passed=true;
94     }
95     return passed;
96    
97     }
98    
99     bool baseClass::goodPrimaryVertexSelection(int ndof, double z)
100     {
101     bool passed=false;
102     if(ndof>=5 && fabs(z)<15) passed=true;
103     return passed;
104     }
105    
106     // bool baseClass::noBeamScrapingSelection(int nTracks, int goodTrack)
107     // {
108     // passed=false;
109     // if(nTracks<10) passed=true;
110     // else if(ntracks>=10) {
111     // for(int i=0;i<nTracks;i++) {
112     // if()
113     // }
114     // }
115     // return passed;
116     // }
117    
118     bool myEvent::WorkingPointID(myEvent electron, vector<double> cuts)
119     {
120     bool passed=false;
121     double etaMax_B=1.44;
122     double etaMax_E=2.6;
123     // get the variables
124     double See=electron.sigmaIetaIeta[0];
125     double Dphi=fabs(electron.deltaPhi[0]);
126     double Deta=fabs(electron.deltaEta[0]);
127     double HoE=electron.HoverE[0];
128     double TrkIso=electron.trkIso[0];
129     double EcalIso=electron.ecalIso[0];
130     double HcalIso=electron.hcalIso[0];
131     double missingHits=electron.numberOfMissingInnerHits[0];
132     // get the cuts
133     double See_B=cuts[0];
134     double Dphi_B=cuts[1];
135     double Deta_B=cuts[2];
136     double HoE_B=cuts[3];
137     double TrkIso_B=cuts[4];
138     double EcalIso_B=cuts[5];
139     double HcalIso_B=cuts[6];
140     double missingHits_B=cuts[7];
141     double See_E=cuts[8];
142     double Dphi_E=cuts[9];
143     double Deta_E=cuts[10];
144     double HoE_E=cuts[11];
145     double TrkIso_E=cuts[12];
146     double EcalIso_E=cuts[13];
147     double HcalIso_E=cuts[14];
148     double missingHits_E=cuts[15];
149     if(fabs(electron.fourvector[0].Eta())<etaMax_B) {
150     if(See<See_B &&
151     Dphi<Dphi_B &&
152     Deta<Deta_B &&
153     HoE<HoE_B &&
154     TrkIso<TrkIso_B &&
155     EcalIso<EcalIso_B &&
156     HcalIso<HcalIso_B &&
157     missingHits<missingHits_B) passed=true;
158     }
159     else if(fabs(electron.fourvector[0].Eta())>etaMax_B && fabs(electron.fourvector[0].Eta())<etaMax_E) {
160     if(See<See_E &&
161     Dphi<Dphi_E &&
162     Deta<Deta_E &&
163     HoE<HoE_E &&
164     TrkIso<TrkIso_E &&
165     EcalIso<EcalIso_E &&
166     HcalIso<HcalIso_E &&
167     missingHits<missingHits_E) passed=true;
168     }
169     return passed;
170     }
171    
172     bool myEvent::WorkingPointNminus1(myEvent electron, vector<double> cuts, char *cut)
173     {
174     bool passed=false;
175     int combination[8]={0,0,0,0,0,0,0,0};
176     double etaMax_B=1.44;
177     double etaMax_E=2.6;
178     // get the variables
179     double See=electron.sigmaIetaIeta[0];
180     double Dphi=fabs(electron.deltaPhi[0]);
181     double Deta=fabs(electron.deltaEta[0]);
182     double HoE=electron.HoverE[0];
183     double TrkIso=electron.trkIso[0];
184     double EcalIso=electron.ecalIso[0];
185     double HcalIso=electron.hcalIso[0];
186     double missingHits=electron.numberOfMissingInnerHits[0];
187 jueugste 1.2
188    
189 jueugste 1.1 // get the cuts
190     double See_B=cuts[0];
191     double Dphi_B=cuts[1];
192     double Deta_B=cuts[2];
193     double HoE_B=cuts[3];
194     double TrkIso_B=cuts[4];
195     double EcalIso_B=cuts[5];
196     double HcalIso_B=cuts[6];
197 jueugste 1.2 double CombIso_B=cuts[7];
198     double missingHits_B=cuts[16];
199 jueugste 1.1 double See_E=cuts[8];
200     double Dphi_E=cuts[9];
201     double Deta_E=cuts[10];
202     double HoE_E=cuts[11];
203     double TrkIso_E=cuts[12];
204     double EcalIso_E=cuts[13];
205     double HcalIso_E=cuts[14];
206 jueugste 1.2 double CombIso_E=cuts[15];
207     double missingHits_E=cuts[16];
208     double dist=cuts[17];
209    
210    
211    
212    
213    
214 jueugste 1.1 // get the cut which should NOT be made
215     if(!strcmp(cut,"sigmaIetaIeta")) combination[0]=1;
216     else if(!strcmp(cut,"deltaPhi")) combination[1]=1;
217     else if(!strcmp(cut,"deltaEta")) combination[2]=1;
218     else if(!strcmp(cut,"HoverE")) combination[3]=1;
219     else if(!strcmp(cut,"trkIso")) combination[4]=1;
220     else if(!strcmp(cut,"ecalIso")) combination[5]=1;
221     else if(!strcmp(cut,"hcalIso")) combination[6]=1;
222     else if(!strcmp(cut,"conversions")) combination[7]=1;
223     else cout<<"ERROR: not able to give N-1 flag for the working point!"<<endl;
224     // divide in barrel and endcaps
225     if(fabs(electron.fourvector[0].Eta())<etaMax_B) {
226     // sigma ieta ieta
227     if(combination[0]==1 &&
228     Dphi<Dphi_B &&
229     Deta<Deta_B &&
230     HoE<HoE_B &&
231     TrkIso<TrkIso_B &&
232     EcalIso<EcalIso_B &&
233     HcalIso<HcalIso_B &&
234 jueugste 1.2 missingHits<=missingHits_B) passed=true;
235 jueugste 1.1 // delta phi
236     else if(combination[1]==1 &&
237     See<See_B &&
238     Deta<Deta_B &&
239     HoE<HoE_B &&
240     TrkIso<TrkIso_B &&
241     EcalIso<EcalIso_B &&
242     HcalIso<HcalIso_B &&
243 jueugste 1.2 missingHits<=missingHits_B) passed=true;
244 jueugste 1.1 // delta eta
245     else if(combination[2]==1 &&
246     See<See_B &&
247     Dphi<Dphi_B &&
248     HoE<HoE_B &&
249     TrkIso<TrkIso_B &&
250     EcalIso<EcalIso_B &&
251     HcalIso<HcalIso_B &&
252 jueugste 1.2 missingHits<=missingHits_B) passed=true;
253 jueugste 1.1 // H over E
254     else if(combination[3]==1 &&
255     See<See_B &&
256     Dphi<Dphi_B &&
257     Deta<Deta_B &&
258     TrkIso<TrkIso_B &&
259     EcalIso<EcalIso_B &&
260     HcalIso<HcalIso_B &&
261 jueugste 1.2 missingHits<=missingHits_B) passed=true;
262 jueugste 1.1 // Track isolation
263     else if(combination[4]==1 &&
264     See<See_B &&
265     Dphi<Dphi_B &&
266     Deta<Deta_B &&
267     HoE<HoE_B &&
268     EcalIso<EcalIso_B &&
269     HcalIso<HcalIso_B &&
270 jueugste 1.2 missingHits<=missingHits_B) passed=true;
271 jueugste 1.1 // ECAL isolation
272     else if(combination[5]==1 &&
273     See<See_B &&
274     Dphi<Dphi_B &&
275     Deta<Deta_B &&
276     HoE<HoE_B &&
277     TrkIso<TrkIso_B &&
278     HcalIso<HcalIso_B &&
279 jueugste 1.2 missingHits<=missingHits_B) passed=true;
280 jueugste 1.1 // HCAL isolation
281     else if(combination[6]==1 &&
282     See<See_B &&
283     Dphi<Dphi_B &&
284     Deta<Deta_B &&
285     HoE<HoE_B &&
286     TrkIso<TrkIso_B &&
287     EcalIso<EcalIso_B &&
288 jueugste 1.2 missingHits<=missingHits_B) passed=true;
289 jueugste 1.1 // Conversions
290     else if(combination[7]==1 &&
291     See<See_B &&
292     Dphi<Dphi_B &&
293     Deta<Deta_B &&
294     HoE<HoE_B &&
295     TrkIso<TrkIso_B &&
296     EcalIso<EcalIso_B &&
297     HcalIso<HcalIso_B) passed=true;
298    
299    
300     } // barrel
301     else if(fabs(electron.fourvector[0].Eta())>etaMax_B && fabs(electron.fourvector[0].Eta())<etaMax_E) {
302     // sigma ieta ieta
303     if(combination[0]==1 &&
304     Dphi<Dphi_E &&
305     Deta<Deta_E &&
306     HoE<HoE_E &&
307     TrkIso<TrkIso_E &&
308     EcalIso<EcalIso_E &&
309     HcalIso<HcalIso_E &&
310 jueugste 1.2 missingHits<=missingHits_E) passed=true;
311 jueugste 1.1 // delta phi
312     else if(combination[1]==1 &&
313     See<See_E &&
314     Deta<Deta_E &&
315     HoE<HoE_E &&
316     TrkIso<TrkIso_E &&
317     EcalIso<EcalIso_E &&
318     HcalIso<HcalIso_E &&
319 jueugste 1.2 missingHits<=missingHits_E) passed=true;
320 jueugste 1.1 // delta eta
321     else if(combination[2]==1 &&
322     See<See_E &&
323     Dphi<Dphi_E &&
324     HoE<HoE_E &&
325     TrkIso<TrkIso_E &&
326     EcalIso<EcalIso_E &&
327     HcalIso<HcalIso_E &&
328 jueugste 1.2 missingHits<=missingHits_E) passed=true;
329 jueugste 1.1 // H over E
330     else if(combination[3]==1 &&
331     See<See_E &&
332     Dphi<Dphi_E &&
333     Deta<Deta_E &&
334     TrkIso<TrkIso_E &&
335     EcalIso<EcalIso_E &&
336     HcalIso<HcalIso_E &&
337 jueugste 1.2 missingHits<=missingHits_E) passed=true;
338 jueugste 1.1 // Track isolation
339     else if(combination[4]==1 &&
340     See<See_E &&
341     Dphi<Dphi_E &&
342     Deta<Deta_E &&
343     HoE<HoE_E &&
344     EcalIso<EcalIso_E &&
345     HcalIso<HcalIso_E &&
346 jueugste 1.2 missingHits<=missingHits_E) passed=true;
347 jueugste 1.1 // ECAL isolation
348     else if(combination[5]==1 &&
349     See<See_E &&
350     Dphi<Dphi_E &&
351     Deta<Deta_E &&
352     HoE<HoE_E &&
353     TrkIso<TrkIso_E &&
354     HcalIso<HcalIso_E &&
355 jueugste 1.2 missingHits<=missingHits_E) passed=true;
356 jueugste 1.1 // HCAL isolation
357     else if(combination[6]==1 &&
358     See<See_E &&
359     Dphi<Dphi_E &&
360     Deta<Deta_E &&
361     HoE<HoE_E &&
362     TrkIso<TrkIso_E &&
363     EcalIso<EcalIso_E &&
364 jueugste 1.2 missingHits<=missingHits_E) passed=true;
365 jueugste 1.1 // Conversions
366     else if(combination[7]==1 &&
367     See<See_E &&
368     Dphi<Dphi_E &&
369     Deta<Deta_E &&
370     HoE<HoE_E &&
371     TrkIso<TrkIso_E &&
372     EcalIso<EcalIso_E &&
373     HcalIso<HcalIso_E) passed=true;
374    
375    
376    
377    
378    
379     } // endcaps
380     return passed;
381     }
382    
383 jueugste 1.2
384     testEvent baseClass::fillTestEvent() {
385     // fill the event struct
386     testEvent event;
387     for(int i=0; i<NEles;i++) {
388     TLorentzVector vec;
389     vec.SetPxPyPzE(ElPx[i],ElPy[i],ElPz[i],ElE[i]);
390     event.fourMomentum.push_back(vec);
391     }
392     return event;
393     }
394    
395     int baseClass::ElectronPreselection(int i) {
396     // function to make electron preselection
397     // 0: preselected electron
398     // 1: not accepted in eta
399     // 2: not accepted in pt
400     // 3: not accepted in H/E
401     // 4: not accepted in dphi
402     // 5: not accepted in deta
403    
404     //double etaMax_B=1.44;
405     double etaMax_E=2.5;
406     double ptMin=20;
407     double HoverEMin=0.15;
408     double deltaPhiMax=0.15;
409     double deltaEtaMax=0.02;
410    
411     bool cutOn_Eta = true;
412     bool cutOn_Pt = true;
413     bool cutOn_HoE = true;
414     bool cutOn_dPhi= true;
415     bool cutOn_dEta= true;
416    
417     double eta = ElSCEta[i];
418     // double eta = ElEta[i];
419    
420     // double dPhiCorr=dphiCorrections(ElEta[i], ElPhi[i]);
421     // double dEtaCorr=detaCorrections(ElEta[i], ElPhi[i]);
422     double dPhiCorr=dphiCorrections(eta, ElPhi[i]);
423     double dEtaCorr=detaCorrections(eta, ElPhi[i]);
424    
425     TVector3 track;
426     track.SetXYZ(ElPx[i], ElPy[i], ElPz[i]);
427     double trackEta=track.Eta();
428     // double pt=ElCaloEnergy[i]/cosh(trackEta);
429     double pt = ElPt[i];
430    
431     double hoe = ElHcalOverEcal[i];
432     double dphi = ElDeltaPhiSuperClusterAtVtx[i] - dPhiCorr;
433     double deta = ElDeltaEtaSuperClusterAtVtx[i] - dEtaCorr;
434     // double dphi = ElDeltaPhiSuperClusterAtVtx[i];
435     // double deta = ElDeltaEtaSuperClusterAtVtx[i];
436    
437     if(cutOn_Eta) if(fabs(eta) > etaMax_E) return 1;
438     if(cutOn_Pt) if(pt < ptMin) return 2;
439     if(cutOn_HoE) if(hoe > HoverEMin) return 3;
440     if(cutOn_dPhi) if(fabs(dphi) > deltaPhiMax) return 4;
441     if(cutOn_dEta) if(fabs(deta) > deltaEtaMax) return 5;
442    
443     return 0;
444     }
445    
446     int baseClass::WPElectronID(int i, NminusOneCutLabel c, vector<double> cuts) {
447     // function to ID and isolate electrons
448     // return values (int):
449     // 0 totally IDed & isolated electron
450     // 1 See cut not passed
451     // 2 dEta cut not passed
452     // 3 dPhi
453     // 4 HoE
454     // 5 combIso
455     // 6 conversion
456    
457     double etaMax_B=1.44;
458     double etaMin_E=1.56;
459     double etaMax_E=2.5;
460     double SeeMax_B=cuts[0];
461     double dPhiMax_B=cuts[1];
462     double dEtaMax_B=cuts[2];
463     double HoEMax_B=cuts[3];
464     double TrkIsoMax_B=cuts[4];
465     double EcalIsoMax_B=cuts[5];
466     double HcalIsoMax_B=cuts[6];
467     double combIsoMax_B=cuts[7];
468     double SeeMax_E=cuts[8];
469     double dPhiMax_E=cuts[9];
470     double dEtaMax_E=cuts[10];
471     double HoEMax_E=cuts[11];
472     double TrkIsoMax_E=cuts[12];
473     double EcalIsoMax_E=cuts[13];
474     double HcalIsoMax_E=cuts[14];
475     double combIsoMax_E=cuts[15];
476     int hits=cuts[16];
477     double dist=cuts[17];
478     double cot=dist;
479    
480     bool cutOn_See=true;
481     bool cutOn_dPhi=true;
482     bool cutOn_dEta=true;
483     bool cutOn_HoE=true;
484     bool cutOn_combIso=true;
485     bool cutOn_conversion=true;
486    
487     // check geometrical acceptance
488     // for the isolation use the SC eta instead
489     // of the electron eta
490     double eta = ElSCEta[i];
491     // double eta = ElEta[i];
492    
493     double dPhiCorr=dphiCorrections(eta, ElPhi[i]);
494     double dEtaCorr=detaCorrections(eta, ElPhi[i]);
495    
496     double See = ElSigmaIetaIeta[i];
497     // apply the correction for the endcaps
498     double dPhi = fabs(ElDeltaPhiSuperClusterAtVtx[i]-dPhiCorr);
499     double dEta = fabs(ElDeltaEtaSuperClusterAtVtx[i]-dEtaCorr);
500     double HoE = ElHcalOverEcal[i];
501     double trkIso = ElDR03TkSumPt[i];
502     double ecalIso = ElDR03EcalRecHitSumEt[i];
503     double hcalIso = ElDR03HcalTowerSumEt[i];
504     double combIso_B = (trkIso + max(0., ecalIso - 1.) + hcalIso) / ElPt[i];
505     double combIso_E = (trkIso + ecalIso + hcalIso) / ElPt[i];
506     bool isConversion;
507     if((fabs(ElConvPartnerTrkDist[i])<dist && fabs(ElConvPartnerTrkDCot[i])<cot) || ElNumberOfMissingInnerHits[i]>hits) isConversion=true;
508     else isConversion=false;
509    
510     if(c==see) cutOn_See = false;
511     if(c==dphi) cutOn_dPhi = false;
512     if(c==deta) cutOn_dEta = false;
513     if(c==hoe) cutOn_HoE = false;
514     if(c==combiso) cutOn_combIso = false;
515     if(c==conversion) cutOn_conversion = false;
516    
517    
518     // if(Event==27837545 || Event==73939173 || Event==15512525 || Event==191815699 || Event==29377895 || Event==29377895 || Event==74868952 || Event==76643965 || Event==62016483 || Event==4352136) {
519     // cout<<eta<<endl;
520     // cout<<combIso_B<<"/"<<combIso_E<<endl;
521     // cout<<combIsoMax_B<<"/"<<combIsoMax_E<<endl;
522     // cout<<"See: "<<See<<endl;
523     // cout<<"dPhi: "<<dPhi<<endl;
524     // cout<<"dEta: "<<dEta<<endl;
525     // cout<<"HoE: "<<HoE<<endl;
526     // cout<<"pt: "<<ElPt[i]<<endl;
527     // }
528    
529     if(fabs(eta)<=etaMax_B) {
530     if(cutOn_See) if(See > SeeMax_B) return 1;
531     if(cutOn_dPhi) if(dPhi > dPhiMax_B) return 2;
532     if(cutOn_dEta) if(dEta > dEtaMax_B) return 3;
533     if(cutOn_HoE) if(HoE > HoEMax_B) return 4;
534     if(cutOn_combIso) if(combIso_B > combIsoMax_B) return 5;
535     if(cutOn_conversion) if(isConversion==true) return 6;
536     return 0;
537     }
538     if(fabs(eta)>etaMin_E && fabs(eta)<etaMax_E) {
539     if(cutOn_See) if(See > SeeMax_E) return 1;
540     if(cutOn_dPhi) if(dPhi > dPhiMax_E) return 2;
541     if(cutOn_dEta) if(dEta > dEtaMax_E) return 3;
542     if(cutOn_HoE) if(HoE > HoEMax_E) return 4;
543     if(cutOn_combIso) if(combIso_E > combIsoMax_E) return 5;
544     if(cutOn_conversion) if(isConversion==true) return 6;
545     return 0;
546     }
547     else {
548     cout<<"WPelectronID: electron not in ECAL acceptance region!!"<<endl;
549     return -1;
550     }
551     }
552    
553     double baseClass::detaCorrections(double etaEle,double phiEle) {
554     // corrects for misalignement in the endcpas
555     TF2 f12_fit2("f12_fit2","[0]+(TMath::TanH(y)/325.)*([1]-([2]*TMath::SinH(y)*TMath::Cos(x-[3])))",-TMath::Pi(),TMath::Pi(),-10.,10.);
556     if (etaEle>1.479)
557     {
558     f12_fit2.SetParameter(0,0.0013);
559     f12_fit2.SetParameter(1,-0.06);
560     f12_fit2.SetParameter(2,0.52);
561     f12_fit2.SetParameter(3,2.17);
562     }
563     else if (etaEle<-1.479)
564     {
565     f12_fit2.SetParameter(0,-0.0013);
566     f12_fit2.SetParameter(1,-0.32);
567     f12_fit2.SetParameter(2,0.45);
568     f12_fit2.SetParameter(3,-1.58);
569     }
570     return f12_fit2.Eval(phiEle,etaEle);
571     }
572    
573     double baseClass::dphiCorrections(double etaEle,double phiEle) {
574     // corrects for misalignement in the endcpas
575     TF2 f12_fit2("f12_fit2","[0]+[1]*(TMath::SinH(y)/325.)*(TMath::Sin([2]-x))",-TMath::Pi(),TMath::Pi(),-10.,10.);
576     if (etaEle>1.479)
577     {
578     f12_fit2.SetParameter(0,0.0);
579     f12_fit2.SetParameter(1,0.52);
580     f12_fit2.SetParameter(2,2.17);
581     }
582     else if (etaEle<-1.479)
583     {
584     f12_fit2.SetParameter(0,0.0);
585     f12_fit2.SetParameter(1,0.45);
586     f12_fit2.SetParameter(2,-1.58);
587     }
588     return f12_fit2.Eval(phiEle,etaEle);
589     }
590    
591    
592     int baseClass::WSelection(int i, WNminusOneCutLabel c) {
593     // idea: write cuts into a vector and give the vector to the function
594     // double etaMax_B=1.44;
595     double pre_metMin=20;
596     double pre_ptMin=20;
597     double metMin=30;
598     double ptMin=25;
599     double mtMin=60;
600    
601     bool cutOn_Preselection=true;
602     bool cutOn_Met=true;
603     bool cutOn_Pt=true;
604     bool cutOn_Mt=true;
605    
606     double met=PFMET;
607     double pt=ElPt[i];
608     double delPhiMet=deltaPhi(ElPhi[i], PFMETphi);
609     double mt=transverseMass(pt, met, delPhiMet);
610     // check geometrical acceptance
611     // for the isolation use the SC eta instead
612     // of the electron eta
613     // double eta = ElSCEta[i];
614     // double eta = ElEta[i];
615    
616     if(c==pre) cutOn_Preselection = false;
617     if(c==misset) cutOn_Met = false;
618     if(c==pt) cutOn_Pt = false;
619     if(c==mt) cutOn_Mt = false;
620    
621    
622     // if(fabs(eta)<=etaMax_B) {
623     if(cutOn_Preselection) if(met<pre_metMin || pt<pre_ptMin) return 1;
624     if(cutOn_Met) if(met<metMin) return 2;
625     if(cutOn_Pt) if(pt<ptMin) return 3;
626     if(cutOn_Mt) if(mt<mtMin) return 4;
627     return 0;
628     // }
629     // if(fabs(eta)>etaMax_B) {
630     // if(cutOn_Preselection) if(met<pre_metMin || pt<pre_ptMin) return 1;
631     // if(cutOn_Met) if(met<metMin) return 2;
632     // if(cutOn_Pt) if(pt<ptMin) return 3;
633     // if(cutOn_Mt) if(mt<mtMin) return 4;
634     // return 0;
635     // }
636     }
637    
638    
639    
640     // void initializeWP(vector<double>cuts) {
641     // SeeMax_B=cuts[0];
642     // DphiMax_B=cuts[1];
643     // DetaMax_B=cuts[2];
644     // HoEMax_B=cuts[3];
645     // combIsoMax_B=cuts[4];
646     // // TrkIsoMax_B=cuts[4];
647     // // EcalIsoMax_B=cuts[5];
648     // // HcalIsoMax_B=cuts[6];
649     // SeeMax_E=cuts[8];
650     // DphiMax_E=cuts[9];
651     // DetaMax_E=cuts[10];
652     // HoEMax_E=cuts[11];
653     // // TrkIsoMax_E=cuts[12];
654     // // EcalIsoMax_E=cuts[13];
655     // // HcalIsoMax_E=cuts[14];
656     // combIsoMax_E=cuts[12];
657    
658     // }
659    
660 jueugste 1.1 bool baseClass::ethNminus1(int isECALdriven, double deltaPhi, double deltaEta, double e, double p, double eta, char *cut, bool iso)
661     {
662     bool passed=false;
663     double oneOverEoneOverP=1/e-1/p;
664     // cut values
665     double etaMax_B=1.44;
666     double etaMax_E=2.6;
667     double deltaPhiCut_B=0.02;
668     double deltaPhiCut_E=0.02;
669     double deltaEtaCut_B=0.004;
670     double deltaEtaCut_E=0.006;
671     double oneOverEoneOverPCut_B=0.005;
672     double oneOverEoneOverPCut_E=0.007;
673     int combination [4] = {0,0,0,0};
674     if(!strcmp(cut,"deltaPhi")) combination [0] = 1;
675     else if(!strcmp(cut,"deltaEta")) combination [1] =1;
676     else if(!strcmp(cut,"oneOverEminusOneOverP")) combination [2] = 1;
677     else if(!strcmp(cut,"iso")) combination[3] = 1;
678     else {
679     cout<<"ERROR: not able to give N-1 flag for the ETH!"<<endl;
680     }
681     if(isECALdriven == 1) {
682     // barrel
683     if(fabs(eta)<etaMax_B) {
684     // delta phi
685     if(combination[0]==1 && fabs(deltaEta)<deltaEtaCut_B && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_B && iso==true) {
686     passed = true;
687     }
688     // delta eta
689     else if(combination[1]==1 && fabs(deltaPhi)<deltaPhiCut_B && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_B && iso==true) {
690     passed = true;
691     }
692    
693    
694     // |1/E-1/p|
695     else if(combination[2]==1 && fabs(deltaPhi)<deltaPhiCut_B && fabs(deltaEta)< deltaEtaCut_B && iso==true) {
696     passed = true;
697     }
698     // iso
699     else if((combination[3]==1 && fabs(deltaPhi)<deltaPhiCut_B && fabs(deltaEta)< deltaEtaCut_B && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_B)) {
700     passed=true;
701     }
702     }
703     //endcap
704     else if(fabs(eta)>etaMax_B && fabs(eta)<etaMax_E) {
705     // delta phi
706     if(combination[0]==1 && fabs(deltaEta)< deltaEtaCut_E && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_E && iso==true) {
707     passed = true;
708     }
709     // delta eta
710     else if(combination[1]==1 && fabs(deltaPhi)< deltaPhiCut_E && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_E && iso==true) {
711     passed = true;
712     }
713     // |1/E-1/p|
714     else if(combination[2]==1 && fabs(deltaPhi)< deltaPhiCut_E && fabs(deltaEta)< deltaEtaCut_E && iso ==true) {
715     passed = true;
716     }
717     // iso
718     else if((combination[3]==1 && fabs(deltaPhi)< deltaPhiCut_E && fabs(deltaEta)< deltaEtaCut_E && fabs(oneOverEoneOverP)<oneOverEoneOverPCut_E)) {
719     passed=true;
720     }
721     } // endcap
722     } // ecal driven
723     return passed;
724     }
725    
726    
727     bool baseClass::ethID(int isECALdriven, double deltaPhi, double deltaEta, double e, double p, double eta)
728     {
729     bool passed=false;
730     double oneOverEoneOverP=1/e-1/p;
731     // cut values
732     double etaMax_B=1.44;
733     double etaMax_E=2.6;
734     double deltaPhiCut_B=0.02;
735     double deltaPhiCut_E=0.02;
736     double deltaEtaCut_B=0.004;
737     double deltaEtaCut_E=0.006;
738     double oneOverEoneOverPCut_B=0.005;
739     double oneOverEoneOverPCut_E=0.007;
740     if(isECALdriven == 1 &&
741     fabs(eta)<etaMax_B &&
742     fabs(deltaPhi)< deltaPhiCut_B &&
743     fabs(deltaEta)< deltaEtaCut_B &&
744     fabs(oneOverEoneOverP)<oneOverEoneOverPCut_B) {
745     passed=true;
746     }
747     else if(isECALdriven == 1 &&
748     fabs(eta)>etaMax_B &&
749     fabs(eta)<etaMax_E &&
750     fabs(deltaPhi)< deltaPhiCut_E &&
751     fabs(deltaEta)< deltaEtaCut_E &&
752     fabs(oneOverEoneOverP)<oneOverEoneOverPCut_E) {
753     passed=true;
754     }
755     return passed;
756     }
757    
758     bool baseClass::isolation(double sumpt, double e)
759     {
760     bool passed =false;
761     double iso;
762     iso = sumpt/e;
763     if(iso<0.1) {
764     passed =true;
765     }
766     return passed;
767     }
768    
769     double baseClass::deltaPhi(double phi1, double phi2) {
770     double delPhi;
771     double Pi=2*acos(0);
772     delPhi=fabs(phi1-phi2);
773     if(delPhi>Pi) {
774     delPhi=2*Pi-delPhi;
775     }
776     return delPhi;
777     }
778    
779     double baseClass::transverseMass(double pt1, double pt2, double delPhi) {
780     // pt2=met!!
781     double mt;
782     mt=sqrt(2*fabs(pt1)*fabs(pt2)*(1-cos(delPhi)));
783     return mt;
784     }
785    
786     void baseClass::init()
787     {
788     STDOUT("begin");
789     //std::cout << "baseClass::init(): begin " << std::endl;
790    
791     tree_ = NULL;
792     readInputList();
793 jueugste 1.2 // readCutFile(); // not using cut file, need dummy cut file as input...
794 jueugste 1.1 if(tree_ == NULL){
795     std::cout << "baseClass::init(): ERROR: tree_ = NULL " << std::endl;
796     return;
797     }
798     Init(tree_);
799    
800     //char output_root_title[200];
801     //sprintf(output_root_title,"%s%s",&std::string(*outputFileName_)[0],".root");
802     //output_root_ = new TFile(&output_root_title[0],"RECREATE");
803    
804     //directly from string
805     output_root_ = new TFile((*outputFileName_ + ".root").c_str(),"RECREATE");
806    
807     // for (map<string, cut>::iterator it = cutName_cut_.begin();
808     // it != cutName_cut_.end(); it++) STDOUT("cutName_cut->first = "<<it->first)
809     // for (vector<string>::iterator it = orderedCutNames_.begin();
810     // it != orderedCutNames_.end(); it++) STDOUT("orderedCutNames_ = "<<*it)
811     STDOUT("end");
812     }
813    
814     void baseClass::readInputList()
815     {
816    
817     TChain *chain = new TChain(treeName_->c_str());
818     char pName[500];
819     skimWasMade_ = true;
820     NBeforeSkim_ = 0;
821     int NBeforeSkim;
822    
823     std::cout << "baseClass::readinputList(): inputList_ = "<< *inputList_ << std::endl;
824    
825     ifstream is(inputList_->c_str());
826     if(is.good())
827     {
828     cout << "baseClass::readInputList: Reading list: " << *inputList_ << " ......." << endl;
829     while( is.getline(pName, 500, '\n') )
830     {
831     if (pName[0] == '#') continue;
832     //if (pName[0] == ' ') continue; // do we want to skip lines that start with a space?
833     if (pName[0] == '\n') continue;// simple protection against blank lines
834     STDOUT("Adding file: " << pName);
835     chain->Add(pName);
836     NBeforeSkim = getGlobalInfoNstart(pName);
837     NBeforeSkim_ = NBeforeSkim_ + NBeforeSkim;
838     STDOUT("Initial number of events: NBeforeSkim, NBeforeSkim_ = "<<NBeforeSkim<<", "<<NBeforeSkim_);
839     }
840 jueugste 1.2
841 jueugste 1.1 tree_ = chain;
842     cout << "baseClass::readInputList: Finished reading list: " << *inputList_ << endl;
843     }
844     else
845     {
846     cout << "baseClass::readInputList: ERROR opening inputList:" << *inputList_ << endl;
847     exit (1);
848     }
849     is.close();
850    
851     }
852    
853     void baseClass::readCutFile()
854     {
855     string s;
856     STDOUT("Reading cutFile_ = "<< *cutFile_)
857    
858     ifstream is(cutFile_->c_str());
859     if(is.good())
860     {
861     // STDOUT("Reading file: " << *cutFile_ );
862     int id=0;
863     int optimize_count=0;
864     while( getline(is,s) )
865     {
866     STDOUT("read line: " << s);
867     if (s[0] == '#' || s.empty()) continue;
868     vector<string> v = split(s);
869     if ( v.size() == 0 ) continue;
870     if (v[1]=="OPT") // add code for grabbing optimizer objects
871     {
872     if (optimizeName_cut_.size()>=6)
873     {
874     STDOUT("WARNING: Optimizer can only accept up to 6 variables.\nVariable "<<v[0]<<" is not being included.");
875     continue;
876     }
877     bool found=false;
878     for (int i=0;i<optimizeName_cut_.size();++i)
879     {
880     if (optimizeName_cut_[i].variableName==v[0])
881     {
882     STDOUT("ERROR: variableName = "<<v[0]<<" is already being optimized in optimizedName_cut_. Skipping.");
883     found=true;
884     break;
885     }
886     }
887     if (found) continue;
888    
889     int level_int = atoi(v[5].c_str());
890     bool greaterthan=true;
891     if (v[2]=="<") greaterthan=false;
892     double minval=atof(v[3].c_str());
893     double maxval=atof(v[4].c_str());
894     Optimize opt(optimize_count,v[0],minval, maxval, greaterthan, level_int);
895     optimizeName_cut_[optimize_count]=opt; // order cuts by cut #, rather than name, so that optimization histogram is consistently ordered
896     ++optimize_count;
897     continue;
898     }
899    
900     map<string, cut>::iterator cc = cutName_cut_.find(v[0]);
901     if( cc != cutName_cut_.end() )
902     {
903     STDOUT("ERROR: variableName = "<< v[0] << " exists already in cutName_cut_. Returning.");
904     return;
905     }
906    
907     int level_int = atoi( v[5].c_str() );
908     if(level_int == -1)
909     {
910     map<string, preCut>::iterator cc = preCutName_cut_.find(v[0]);
911     if( cc != preCutName_cut_.end() )
912     {
913     STDOUT("ERROR: variableName = "<< v[0] << " exists already in preCutName_cut_. Returning.");
914     return;
915     }
916     preCutInfo_ << "### Preliminary cut values: " << s <<endl;
917     preCut thisPreCut;
918     thisPreCut.variableName = v[0];
919     thisPreCut.value1 = decodeCutValue( v[1] );
920     thisPreCut.value2 = decodeCutValue( v[2] );
921     thisPreCut.value3 = decodeCutValue( v[3] );
922     thisPreCut.value4 = decodeCutValue( v[4] );
923     preCutName_cut_[thisPreCut.variableName]=thisPreCut;
924     continue;
925     }
926     cut thisCut;
927     thisCut.variableName = v[0];
928     string m1=v[1];
929     string M1=v[2];
930     string m2=v[3];
931     string M2=v[4];
932     if( m1=="-" || M1=="-" )
933     {
934     STDOUT("ERROR: minValue1 and maxValue2 have to be provided. Returning.");
935     return; // FIXME implement exception
936     }
937     if( (m2=="-" && M2!="-") || (m2!="-" && M2=="-") )
938     {
939     STDOUT("ERROR: if any of minValue2 and maxValue2 is -, then both have to be -. Returning");
940     return; // FIXME implement exception
941     }
942     if( m2=="-") m2="+inf";
943     if( M2=="-") M2="-inf";
944     thisCut.minValue1 = decodeCutValue( m1 );
945     thisCut.maxValue1 = decodeCutValue( M1 );
946     thisCut.minValue2 = decodeCutValue( m2 );
947     thisCut.maxValue2 = decodeCutValue( M2 );
948     thisCut.level_int = level_int;
949     thisCut.level_str = v[5];
950     thisCut.histoNBins = atoi( v[6].c_str() );
951     thisCut.histoMin = atof( v[7].c_str() );
952     thisCut.histoMax = atof( v[8].c_str() );
953     // Not filled from file
954     thisCut.id=++id;
955     string s1;
956     if(skimWasMade_)
957     {
958     s1 = "cutHisto_skim___________________" + thisCut.variableName;
959     }
960     else
961     {
962     s1 = "cutHisto_noCuts_________________" + thisCut.variableName;
963     }
964     string s2 = "cutHisto_allPreviousCuts________" + thisCut.variableName;
965     string s3 = "cutHisto_allOthrSmAndLwrLvlCuts_" + thisCut.variableName;
966     string s4 = "cutHisto_allOtherCuts___________" + thisCut.variableName;
967     string s5 = "cutHisto_allCuts________________" + thisCut.variableName;
968     thisCut.histo1 = TH1F (s1.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
969     thisCut.histo2 = TH1F (s2.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
970     thisCut.histo3 = TH1F (s3.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
971     thisCut.histo4 = TH1F (s4.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
972     thisCut.histo5 = TH1F (s5.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
973     thisCut.histo1.Sumw2();
974     thisCut.histo2.Sumw2();
975     thisCut.histo3.Sumw2();
976     thisCut.histo4.Sumw2();
977     thisCut.histo5.Sumw2();
978     // Filled event by event
979     thisCut.filled = false;
980     thisCut.value = 0;
981     thisCut.passed = false;
982     thisCut.nEvtInput=0;
983     thisCut.nEvtPassed=0;
984    
985     orderedCutNames_.push_back(thisCut.variableName);
986     cutName_cut_[thisCut.variableName]=thisCut;
987    
988     }
989     STDOUT( "baseClass::readCutFile: Finished reading cutFile: " << *cutFile_ );
990     }
991     else
992     {
993     STDOUT("ERROR opening cutFile:" << *cutFile_ );
994     exit (1);
995     }
996     // make optimizer histogram
997     if (optimizeName_cut_.size()>0)
998     {
999     h_optimizer_=new TH1F("optimizer","Optimization of cut variables",(int)pow(10,optimizeName_cut_.size()),0,
1000     pow(10,optimizeName_cut_.size()));
1001     }
1002    
1003     // Create a histogram that will show events passing cuts
1004     int cutsize=orderedCutNames_.size()+1;
1005     if (skimWasMade_) ++cutsize;
1006     gDirectory->cd();
1007     eventcuts_=new TH1F("EventsPassingCuts","Events Passing Cuts",cutsize,0,cutsize);
1008    
1009     is.close();
1010    
1011     }
1012    
1013     void baseClass::resetCuts()
1014     {
1015     for (map<string, cut>::iterator cc = cutName_cut_.begin(); cc != cutName_cut_.end(); cc++)
1016     {
1017     cut * c = & (cc->second);
1018     c->filled = false;
1019     c->value = 0;
1020     c->passed = false;
1021     }
1022     combCutName_passed_.clear();
1023     return;
1024     }
1025    
1026     void baseClass::fillVariableWithValue(const string& s, const double& d)
1027     {
1028     map<string, cut>::iterator cc = cutName_cut_.find(s);
1029     if( cc == cutName_cut_.end() )
1030     {
1031     //STDOUT("variableName = "<< s << " not found in cutName_cut_.");
1032     return;
1033     }
1034     else
1035     {
1036     cut * c = & (cc->second);
1037     c->filled = true;
1038     c->value = d;
1039     }
1040     fillOptimizerWithValue(s, d);
1041     return;
1042     }
1043    
1044     bool baseClass::variableIsFilled(const string& s)
1045     {
1046     map<string, cut>::iterator cc = cutName_cut_.find(s);
1047     if( cc == cutName_cut_.end() )
1048     {
1049     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
1050     }
1051     cut * c = & (cc->second);
1052     return (c->filled);
1053     }
1054    
1055     double baseClass::getVariableValue(const string& s)
1056     {
1057     map<string, cut>::iterator cc = cutName_cut_.find(s);
1058     if( cc == cutName_cut_.end() )
1059     {
1060     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_.");
1061     }
1062     cut * c = & (cc->second);
1063     if( !variableIsFilled(s) )
1064     {
1065     STDOUT("ERROR: requesting value of not filled variable "<<s);
1066     }
1067     return (c->value);
1068     }
1069    
1070     void baseClass::fillOptimizerWithValue(const string& s, const double& d)
1071     {
1072     for (int i=0;i<optimizeName_cut_.size();++i)
1073     {
1074     if (optimizeName_cut_[i].variableName==s)
1075     {
1076     optimizeName_cut_[i].value=d;
1077     return;
1078     }
1079     }
1080     return;
1081     }
1082    
1083     void baseClass::evaluateCuts()
1084     {
1085     // resetCuts();
1086     combCutName_passed_.clear();
1087     for (vector<string>::iterator it = orderedCutNames_.begin();
1088     it != orderedCutNames_.end(); it++)
1089     {
1090     cut * c = & (cutName_cut_.find(*it)->second);
1091     if( ! ( c->filled && (c->minValue1 < c->value && c->value <= c->maxValue1 || c->minValue2 < c->value && c->value <= c->maxValue2 ) ) )
1092     {
1093     c->passed = false;
1094     combCutName_passed_[c->level_str.c_str()] = false;
1095     combCutName_passed_["all"] = false;
1096     }
1097     else
1098     {
1099     c->passed = true;
1100     map<string,bool>::iterator cp = combCutName_passed_.find( c->level_str.c_str() );
1101     combCutName_passed_[c->level_str.c_str()] = (cp==combCutName_passed_.end()?true:cp->second);
1102     map<string,bool>::iterator ap = combCutName_passed_.find( "all" );
1103     combCutName_passed_["all"] = (ap==combCutName_passed_.end()?true:ap->second);
1104     }
1105     }
1106    
1107     // reset optimization cut values
1108     //for (int i=0;i<optimizeName_cut_.size();++i)
1109     // optimizeName_cut_[i].value=0;
1110     runOptimizer();
1111    
1112     if( !fillCutHistos() )
1113     {
1114     STDOUT("ERROR: fillCutHistos did not complete successfully.");
1115     }
1116    
1117     if( !updateCutEffic() )
1118     {
1119     STDOUT("ERROR: updateCutEffic did not complete successfully.");
1120     }
1121    
1122     return ;
1123     }
1124    
1125     void baseClass::runOptimizer()
1126     {
1127    
1128     // don't run optimizer if no optimized cuts specified
1129     if (optimizeName_cut_.size()==0)
1130     return;
1131    
1132     // first, check that all cuts (except those to be optimized) have been passed
1133    
1134     for (vector<string>::iterator it = orderedCutNames_.begin();
1135     it != orderedCutNames_.end(); it++)
1136     {
1137     bool ignorecut=false;
1138     for (unsigned int i=0; i < optimizeName_cut_.size();++i)
1139     {
1140     const string str = (const string)(*it);
1141     if (optimizeName_cut_[i].variableName.compare(str)==0)
1142     {
1143     ignorecut=true;
1144     break;
1145     }
1146     }
1147     if (ignorecut) continue;
1148     if (passedCut(*it) == false)
1149     return;
1150     }
1151    
1152     /*
1153     if (combCutName_passed_["all"] == false)
1154     return;
1155     */
1156    
1157     // loop over up to 6 cuts
1158     int counter=0;
1159     int thesize=optimizeName_cut_.size();
1160     int mysize=thesize;
1161     std::vector<bool> counterbins;
1162     for (int i=0;i<pow(10,thesize);++i) counterbins.push_back(true); // assume true
1163    
1164     // lowest-numbered cut appears first in cut ordering
1165     // That is, for cut: ABCDEF
1166     // A is the index of cut0, B is cut 1, etc.
1167     for (int cc=0;cc<thesize;++cc) // loop over all cuts, starting at cut 0
1168     {
1169     --mysize;
1170     for (int i=0;i<10;++i) // loop over 10 cuts for each
1171     {
1172     if (!optimizeName_cut_[cc].Compare(i)) // cut failed; set all values associated with cut to false
1173     {
1174     // loop over all cut values starting with current cut
1175     for (unsigned int j=(int)(i*pow(10,mysize));j<int(pow(10,thesize));++j)
1176     {
1177     // if relevant digit of the cut value matches the current (failed) cut, set this cut to false
1178     if ((j/int(pow(10,mysize)))%10==i)
1179     counterbins[j]=false;
1180     if (j>counterbins.size())
1181     continue; // shouldn't ever happen
1182     }
1183     } // if (cut comparison failed)
1184     } // for (int i=0;i<10;++i)
1185     }
1186     // now fill histograms
1187     for (int i=0;i<counterbins.size();++i)
1188     {
1189     if (counterbins[i]==true)
1190     h_optimizer_->Fill(i,1);
1191    
1192     }
1193    
1194     return;
1195     } //runOptimizer
1196    
1197     bool baseClass::passedCut(const string& s)
1198     {
1199     bool ret = false;
1200     // map<string, bool>::iterator vp = cutName_passed_.find(s);
1201     // if( vp != cutName_passed_.end() ) return ret = vp->second;
1202     map<string, cut>::iterator cc = cutName_cut_.find(s);
1203     if( cc != cutName_cut_.end() )
1204     {
1205     cut * c = & (cutName_cut_.find(s)->second);
1206     return (c->filled && c->passed);
1207     }
1208     map<string, bool>::iterator cp = combCutName_passed_.find(s);
1209     if( cp != combCutName_passed_.end() )
1210     {
1211     return ret = cp->second;
1212     }
1213     STDOUT("ERROR: did not find variableName = "<<s<<" neither in cutName_cut_ nor combCutName_passed_. Returning false.");
1214     return (ret=false);
1215     }
1216    
1217     bool baseClass::passedAllPreviousCuts(const string& s)
1218     {
1219     //STDOUT("Examining variableName = "<<s);
1220    
1221     map<string, cut>::iterator cc = cutName_cut_.find(s);
1222     if( cc == cutName_cut_.end() )
1223     {
1224     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1225     return false;
1226     }
1227    
1228     for (vector<string>::iterator it = orderedCutNames_.begin();
1229     it != orderedCutNames_.end(); it++)
1230     {
1231     cut * c = & (cutName_cut_.find(*it)->second);
1232     if( c->variableName == s )
1233     {
1234     return true;
1235     }
1236     else
1237     {
1238     if( ! (c->filled && c->passed) ) return false;
1239     }
1240     }
1241     STDOUT("ERROR. It should never pass from here.");
1242     }
1243    
1244     bool baseClass::passedAllOtherCuts(const string& s)
1245     {
1246     //STDOUT("Examining variableName = "<<s);
1247     bool ret = true;
1248    
1249     map<string, cut>::iterator cc = cutName_cut_.find(s);
1250     if( cc == cutName_cut_.end() )
1251     {
1252     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1253     return false;
1254     }
1255    
1256     for (map<string, cut>::iterator cc = cutName_cut_.begin(); cc != cutName_cut_.end(); cc++)
1257     {
1258     cut * c = & (cc->second);
1259     if( c->variableName == s )
1260     {
1261     continue;
1262     }
1263     else
1264     {
1265     if( ! (c->filled && c->passed) ) return false;
1266     }
1267     }
1268     return ret;
1269     }
1270    
1271     bool baseClass::passedAllOtherSameAndLowerLevelCuts(const string& s)
1272     {
1273     //STDOUT("Examining variableName = "<<s);
1274     bool ret = true;
1275     int cutLevel;
1276     map<string, cut>::iterator cc = cutName_cut_.find(s);
1277     if( cc == cutName_cut_.end() )
1278     {
1279     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1280     return false;
1281     }
1282     else
1283     {
1284     cutLevel = cc->second.level_int;
1285     }
1286    
1287     for (map<string, cut>::iterator cc = cutName_cut_.begin(); cc != cutName_cut_.end(); cc++)
1288     {
1289     cut * c = & (cc->second);
1290     if( c->level_int > cutLevel || c->variableName == s )
1291     {
1292     continue;
1293     }
1294     else
1295     {
1296     if( ! (c->filled && c->passed) ) return false;
1297     }
1298     }
1299     return ret;
1300     }
1301    
1302     double baseClass::getPreCutValue1(const string& s)
1303     {
1304     double ret;
1305     map<string, preCut>::iterator cc = preCutName_cut_.find(s);
1306     if( cc == preCutName_cut_.end() )
1307     {
1308     STDOUT("ERROR: did not find variableName = "<<s<<" in preCutName_cut_. Returning");
1309     }
1310     preCut * c = & (cc->second);
1311     if(c->value1 == -9999999) STDOUT("ERROR: value1 of preliminary cut "<<s<<" was not provided.");
1312     return (c->value1);
1313     }
1314    
1315     double baseClass::getPreCutValue2(const string& s)
1316     {
1317     double ret;
1318     map<string, preCut>::iterator cc = preCutName_cut_.find(s);
1319     if( cc == preCutName_cut_.end() )
1320     {
1321     STDOUT("ERROR: did not find variableName = "<<s<<" in preCutName_cut_. Returning");
1322     }
1323     preCut * c = & (cc->second);
1324     if(c->value2 == -9999999) STDOUT("ERROR: value2 of preliminary cut "<<s<<" was not provided.");
1325     return (c->value2);
1326     }
1327    
1328     double baseClass::getPreCutValue3(const string& s)
1329     {
1330     double ret;
1331     map<string, preCut>::iterator cc = preCutName_cut_.find(s);
1332     if( cc == preCutName_cut_.end() )
1333     {
1334     STDOUT("ERROR: did not find variableName = "<<s<<" in preCutName_cut_. Returning");
1335     }
1336     preCut * c = & (cc->second);
1337     if(c->value3 == -9999999) STDOUT("ERROR: value3 of preliminary cut "<<s<<" was not provided.");
1338     return (c->value3);
1339     }
1340    
1341     double baseClass::getPreCutValue4(const string& s)
1342     {
1343     double ret;
1344     map<string, preCut>::iterator cc = preCutName_cut_.find(s);
1345     if( cc == preCutName_cut_.end() )
1346     {
1347     STDOUT("ERROR: did not find variableName = "<<s<<" in preCutName_cut_. Returning");
1348     }
1349     preCut * c = & (cc->second);
1350     if(c->value4 == -9999999) STDOUT("ERROR: value4 of preliminary cut "<<s<<" was not provided.");
1351     return (c->value4);
1352     }
1353    
1354    
1355     double baseClass::getCutMinValue1(const string& s)
1356     {
1357     double ret;
1358     map<string, cut>::iterator cc = cutName_cut_.find(s);
1359     if( cc == cutName_cut_.end() )
1360     {
1361     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
1362     }
1363     cut * c = & (cc->second);
1364     return (c->minValue1);
1365     }
1366    
1367     double baseClass::getCutMaxValue1(const string& s)
1368     {
1369     double ret;
1370     map<string, cut>::iterator cc = cutName_cut_.find(s);
1371     if( cc == cutName_cut_.end() )
1372     {
1373     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
1374     }
1375     cut * c = & (cc->second);
1376     return (c->maxValue1);
1377     }
1378    
1379     double baseClass::getCutMinValue2(const string& s)
1380     {
1381     double ret;
1382     map<string, cut>::iterator cc = cutName_cut_.find(s);
1383     if( cc == cutName_cut_.end() )
1384     {
1385     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
1386     }
1387     cut * c = & (cc->second);
1388     return (c->minValue2);
1389     }
1390    
1391     double baseClass::getCutMaxValue2(const string& s)
1392     {
1393     double ret;
1394     map<string, cut>::iterator cc = cutName_cut_.find(s);
1395     if( cc == cutName_cut_.end() )
1396     {
1397     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
1398     }
1399     cut * c = & (cc->second);
1400     return (c->maxValue2);
1401     }
1402    
1403     const TH1F& baseClass::getHisto_noCuts_or_skim(const string& s)
1404     {
1405     map<string, cut>::iterator cc = cutName_cut_.find(s);
1406     if( cc == cutName_cut_.end() )
1407     {
1408     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1409     }
1410    
1411     cut * c = & (cutName_cut_.find(s)->second);
1412     return (c->histo1);
1413     }
1414    
1415     const TH1F& baseClass::getHisto_allPreviousCuts(const string& s)
1416     {
1417     map<string, cut>::iterator cc = cutName_cut_.find(s);
1418     if( cc == cutName_cut_.end() )
1419     {
1420     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1421     }
1422    
1423     cut * c = & (cutName_cut_.find(s)->second);
1424     return (c->histo2);
1425     }
1426    
1427     const TH1F& baseClass::getHisto_allOthrSmAndLwrLvlCuts(const string& s)
1428     {
1429     map<string, cut>::iterator cc = cutName_cut_.find(s);
1430     if( cc == cutName_cut_.end() )
1431     {
1432     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1433     }
1434    
1435     cut * c = & (cutName_cut_.find(s)->second);
1436     return (c->histo3);
1437     }
1438    
1439     const TH1F& baseClass::getHisto_allOtherCuts(const string& s)
1440     {
1441     map<string, cut>::iterator cc = cutName_cut_.find(s);
1442     if( cc == cutName_cut_.end() )
1443     {
1444     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1445     }
1446    
1447     cut * c = & (cutName_cut_.find(s)->second);
1448     return (c->histo4);
1449     }
1450    
1451     const TH1F& baseClass::getHisto_allCuts(const string& s)
1452     {
1453     map<string, cut>::iterator cc = cutName_cut_.find(s);
1454     if( cc == cutName_cut_.end() )
1455     {
1456     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1457     }
1458    
1459     cut * c = & (cutName_cut_.find(s)->second);
1460     return (c->histo5);
1461     }
1462    
1463     int baseClass::getHistoNBins(const string& s)
1464     {
1465     map<string, cut>::iterator cc = cutName_cut_.find(s);
1466     if( cc == cutName_cut_.end() )
1467     {
1468     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1469     }
1470     cut * c = & (cutName_cut_.find(s)->second);
1471     return (c->histoNBins);
1472     }
1473    
1474     double baseClass::getHistoMin(const string& s)
1475     {
1476     map<string, cut>::iterator cc = cutName_cut_.find(s);
1477     if( cc == cutName_cut_.end() )
1478     {
1479     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1480     }
1481     cut * c = & (cutName_cut_.find(s)->second);
1482     return (c->histoMin);
1483     }
1484    
1485     double baseClass::getHistoMax(const string& s)
1486     {
1487     map<string, cut>::iterator cc = cutName_cut_.find(s);
1488     if( cc == cutName_cut_.end() )
1489     {
1490     STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
1491     }
1492     cut * c = & (cutName_cut_.find(s)->second);
1493     return (c->histoMax);
1494     }
1495    
1496    
1497     bool baseClass::fillCutHistos()
1498     {
1499     bool ret = true;
1500     for (vector<string>::iterator it = orderedCutNames_.begin();
1501     it != orderedCutNames_.end(); it++)
1502     {
1503     cut * c = & (cutName_cut_.find(*it)->second);
1504     if( c->filled )
1505     {
1506     c->histo1.Fill( c->value );
1507     if( passedAllPreviousCuts(c->variableName) ) c->histo2.Fill( c->value );
1508     if( passedAllOtherSameAndLowerLevelCuts(c->variableName) ) c->histo3.Fill( c->value );
1509     if( passedAllOtherCuts(c->variableName) ) c->histo4.Fill( c->value );
1510     if( passedCut("all") ) c->histo5.Fill( c->value );
1511     }
1512     }
1513     return ret;
1514     }
1515    
1516     bool baseClass::writeCutHistos()
1517     {
1518     bool ret = true;
1519     for (vector<string>::iterator it = orderedCutNames_.begin();
1520     it != orderedCutNames_.end(); it++)
1521     {
1522     cut * c = & (cutName_cut_.find(*it)->second);
1523     c->histo1.Write();
1524     c->histo2.Write();
1525     c->histo3.Write();
1526     c->histo4.Write();
1527     c->histo5.Write();
1528     }
1529    
1530     // Any failure mode to implement?
1531     return ret;
1532     }
1533    
1534     bool baseClass::updateCutEffic()
1535     {
1536     bool ret = true;
1537     for (vector<string>::iterator it = orderedCutNames_.begin();
1538     it != orderedCutNames_.end(); it++)
1539     {
1540     cut * c = & (cutName_cut_.find(*it)->second);
1541     if( passedAllPreviousCuts(c->variableName) )
1542     {
1543     c->nEvtInput++;
1544     if( passedCut(c->variableName) ) c->nEvtPassed++;
1545     }
1546     }
1547     return ret;
1548     }
1549    
1550    
1551     bool baseClass::writeCutEfficFile()
1552     {
1553    
1554     bool ret = true;
1555    
1556     // Set bin labels for event counter histogram
1557     int bincounter=1;
1558     eventcuts_->GetXaxis()->SetBinLabel(bincounter,"NoCuts");
1559     ++bincounter;
1560     if (skimWasMade_)
1561     {
1562     eventcuts_->GetXaxis()->SetBinLabel(bincounter,"Skim");
1563     ++bincounter;
1564     }
1565     for (int i=0;i<orderedCutNames_.size();++i)
1566     {
1567     eventcuts_->GetXaxis()->SetBinLabel(bincounter,orderedCutNames_[i].c_str());
1568     ++bincounter;
1569     }
1570    
1571     bincounter=1;
1572    
1573     int nEntRoottuple = fChain->GetEntriesFast();
1574     int nEntTot = (skimWasMade_ ? NBeforeSkim_ : nEntRoottuple );
1575     string cutEfficFile = *cutEfficFile_ + ".dat";
1576     ofstream os(cutEfficFile.c_str());
1577    
1578     os << "################################## Preliminary Cut Values ###################################################################\n"
1579     << "########################### variableName value1 value2 value3 value4 level\n"
1580     << preCutInfo_.str();
1581    
1582     int cutIdPed=0;
1583     os.precision(4);
1584     os << "################################## Cuts #####################################################################################\n"
1585     <<"#id variableName min1 max1 min2 max2 level N Npass EffRel errEffRel EffAbs errEffAbs"<<endl
1586     << fixed
1587     << setw(3) << cutIdPed
1588     << setw(25) << "nocut"
1589     << setprecision(4)
1590     << setw(15) << "-"
1591     << setw(15) << "-"
1592     << setw(15) << "-"
1593     << setw(15) << "-"
1594     << setw(15) << "-"
1595     << setw(15) << nEntTot
1596     << setw(15) << nEntTot
1597     << setprecision(11)
1598     << setw(15) << "1.00000000000"
1599     << setw(15) << "0.00000000000"
1600     << setw(15) << "1.00000000000"
1601     << setw(15) << "0.00000000000"
1602     << endl;
1603    
1604     double effRel;
1605     double effRelErr;
1606     double effAbs;
1607     double effAbsErr;
1608    
1609     eventcuts_->SetBinContent(bincounter,nEntTot);
1610     if (optimizeName_cut_.size())
1611     h_optimizer_->SetBinContent(0, nEntTot);
1612    
1613     if(skimWasMade_)
1614     {
1615     ++bincounter;
1616     eventcuts_->SetBinContent(bincounter, nEntRoottuple);
1617     effRel = (double) nEntRoottuple / (double) NBeforeSkim_;
1618     effRelErr = sqrt( (double) effRel * (1.0 - (double) effRel) / (double) NBeforeSkim_ );
1619     effAbs = effRel;
1620     effAbsErr = effRelErr;
1621     os << fixed
1622     << setw(3) << ++cutIdPed
1623     << setw(25) << "skim"
1624     << setprecision(4)
1625     << setw(15) << "-"
1626     << setw(15) << "-"
1627     << setw(15) << "-"
1628     << setw(15) << "-"
1629     << setw(15) << "-"
1630     << setw(15) << NBeforeSkim_
1631     << setw(15) << nEntRoottuple
1632     << setprecision(11)
1633     << setw(15) << effRel
1634     << setw(15) << effRelErr
1635     << setw(15) << effAbs
1636     << setw(15) << effAbsErr
1637     << endl;
1638     }
1639     for (vector<string>::iterator it = orderedCutNames_.begin();
1640     it != orderedCutNames_.end(); it++)
1641     {
1642     cut * c = & (cutName_cut_.find(*it)->second);
1643     ++bincounter;
1644     eventcuts_->SetBinContent(bincounter, c->nEvtPassed);
1645     effRel = (double) c->nEvtPassed / (double) c->nEvtInput;
1646     effRelErr = sqrt( (double) effRel * (1.0 - (double) effRel) / (double) c->nEvtInput );
1647     effAbs = (double) c->nEvtPassed / (double) nEntTot;
1648     effAbsErr = sqrt( (double) effAbs * (1.0 - (double) effAbs) / (double) nEntTot );
1649    
1650     std::stringstream ssm1, ssM1, ssm2,ssM2;
1651     ssm1 << fixed << setprecision(4) << c->minValue1;
1652     ssM1 << fixed << setprecision(4) << c->maxValue1;
1653     if(c->minValue2 == -9999999)
1654     {
1655     ssm2 << "-inf";
1656     }
1657     else
1658     {
1659     ssm2 << fixed << setprecision(4) << c->minValue2;
1660     }
1661     if(c->maxValue2 == 9999999)
1662     {
1663     ssM2 << "+inf";
1664     }
1665     else
1666     {
1667     ssM2 << fixed << setprecision(4) << c->maxValue2;
1668     }
1669     os << setw(3) << cutIdPed+c->id
1670     << setw(25) << c->variableName
1671     << setprecision(4)
1672     << fixed
1673     << setw(15) << ( ( c->minValue1 == -9999999.0 ) ? "-inf" : ssm1.str() )
1674     << setw(15) << ( ( c->maxValue1 == 9999999.0 ) ? "+inf" : ssM1.str() )
1675     << setw(15) << ( ( c->minValue2 > c->maxValue2 ) ? "-" : ssm2.str() )
1676     << setw(15) << ( ( c->minValue2 > c->maxValue2 ) ? "-" : ssM2.str() )
1677     << setw(15) << c->level_int
1678     << setw(15) << c->nEvtInput
1679     << setw(15) << c->nEvtPassed
1680     << setprecision(11)
1681     << setw(15) << effRel
1682     << setw(15) << effRelErr
1683     << setw(15) << effAbs
1684     << setw(15) << effAbsErr
1685     << endl;
1686     }
1687    
1688     // Write optimization histograms
1689     if (optimizeName_cut_.size())
1690     {
1691     gDirectory->mkdir("Optimizer");
1692     gDirectory->cd("Optimizer");
1693     h_optimizer_->Write();
1694     for (int i=0;i<optimizeName_cut_.size();++i)
1695     {
1696     stringstream x;
1697     x<<"Cut"<<i<<"_"<<optimizeName_cut_[i].variableName;
1698     if (optimizeName_cut_[i].testgreater==true)
1699     x<<"_gt_";
1700     else
1701     x<<"_lt_";
1702     x<<optimizeName_cut_[i].minvalue<<"_to_"<<optimizeName_cut_[i].maxvalue;
1703     TObjString test(x.str().c_str());
1704     test.Write();
1705     }
1706     gDirectory->cd("..");
1707     }
1708    
1709     eventcuts_->Write(); // write here, since WriteCutHistos is called before WriteCutEfficFile
1710     // Any failure mode to implement?
1711     return ret;
1712     } // writeCutEffFile
1713    
1714    
1715     bool baseClass::sortCuts(const cut& X, const cut& Y)
1716     {
1717     return X.id < Y.id;
1718     }
1719    
1720    
1721     vector<string> baseClass::split(const string& s)
1722     {
1723     vector<string> ret;
1724     string::size_type i =0;
1725     while (i != s.size()){
1726     while (i != s.size() && isspace(s[i]))
1727     ++i;
1728     string::size_type j = i;
1729     while (j != s.size() && !isspace(s[j]))
1730     ++j;
1731     if (i != j){
1732     ret.push_back(s.substr(i, j -i));
1733     i = j;
1734     }
1735     }
1736     return ret;
1737     }
1738    
1739     double baseClass::decodeCutValue(const string& s)
1740     {
1741     //STDOUT("s = "<<s);
1742     double ret;
1743     if( s == "inf" || s == "+inf" )
1744     {
1745     ret = 9999999;
1746     }
1747     else if ( s == "-inf" || s == "-" )
1748     {
1749     ret = -9999999;
1750     }
1751     else
1752     {
1753     ret = atof( s.c_str() );
1754     }
1755     return ret;
1756     }
1757    
1758     int baseClass::getGlobalInfoNstart(char *pName)
1759     {
1760     int NBeforeSkim = 0;
1761     STDOUT(pName<<" "<< NBeforeSkim)
1762     TFile *f = new TFile(pName);
1763     string s1 = "LJFilter/EventCount/EventCounter";
1764     string s2 = "LJFilterPAT/EventCount/EventCounter";
1765     TH1I* hCount1 = (TH1I*)f->Get(s1.c_str());
1766     TH1I* hCount2 = (TH1I*)f->Get(s2.c_str());
1767     if( !hCount1 && !hCount2 )
1768     {
1769     STDOUT("Skim filter histogram(s) not found. Will assume skim was not made for ALL files.");
1770     skimWasMade_ = false;
1771     return NBeforeSkim;
1772     }
1773    
1774     if (hCount1) NBeforeSkim = (int)hCount1->GetBinContent(1);
1775     else NBeforeSkim = (int)hCount2->GetBinContent(1);
1776    
1777     // STDOUT(pName<<" "<< NBeforeSkim)
1778     f->Close();
1779    
1780     return NBeforeSkim;
1781     }
1782    
1783