-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathAnalyzer.cc
3802 lines (3182 loc) · 159 KB
/
Analyzer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Analyzer.h"
#include "Compression.h"
#include <regex>
#include <sstream>
#include <cmath>
#include <map>
#include <typeinfo>
//// Used to convert Enums to integers
#define ival(x) static_cast<int>(x)
//// BIG_NUM = sqrt(sizeof(int)) so can use diparticle convention of
//// index = BIG_NUM * i1 + i2
//// This insures easy way to extract indices
//// Needs to be changed if go to size_t instead (if want to play safe
#define BIG_NUM 46340
///// Macros defined to shorten code. Made since lines used A LOT and repeative. May change to inlines
///// if tests show no loss in speed
#define histAddVal2(val1, val2, name) ihisto.addVal(val1, val2, group, max, name, wgt);
#define histAddVal(val, name) ihisto.addVal(val, group, max, name, wgt);
#define SetBranch(name, variable) BOOM->SetBranchStatus(name, 1); BOOM->SetBranchAddress(name, &variable);
typedef std::vector<int>::iterator vec_iter;
//////////////////////////////////////////////////////////////////
///////////////////CONSTANTS DEFINITONS///////////////////////////
//////////////////////////////////////////////////////////////////
//Filespace that has all of the .in files
const std::string PUSPACE = "Pileup/";
//////////PUBLIC FUNCTIONS////////////////////
const std::vector<CUTS> Analyzer::genCuts = {
CUTS::eGTau, CUTS::eGNuTau, CUTS::eGTop,
CUTS::eGElec, CUTS::eGMuon, CUTS::eGZ,
CUTS::eGW, CUTS::eGHiggs, CUTS::eGJet,
CUTS::eGBJet, CUTS::eGHadTau, CUTS::eGBParton,
CUTS::eGMatchedHadTau
};
const std::vector<CUTS> Analyzer::jetCuts = {
CUTS::eRJet1, CUTS::eRJet2, CUTS::eRCenJet,
CUTS::eR1stJet, CUTS::eR2ndJet, CUTS::eRBJet
};
const std::vector<CUTS> Analyzer::nonParticleCuts = {
CUTS::eRVertex,CUTS::eRTrig1, CUTS::eRTrig2,
};
//01.16.19
const std::unordered_map<std::string, CUTS> Analyzer::cut_num = {
{"NGenTau", CUTS::eGTau}, {"NGenTop", CUTS::eGTop},
{"NGenElectron", CUTS::eGElec}, {"NGenMuon", CUTS::eGMuon},
{"NGenZ", CUTS::eGZ}, {"NGenW", CUTS::eGW},
{"NGenHiggs", CUTS::eGHiggs}, {"NGenJet", CUTS::eGJet},
{"NGenBJet", CUTS::eGBJet}, {"NGenHadTau", CUTS::eGHadTau},
{"NGenMatchedHadTau", CUTS::eGMatchedHadTau}, {"NGenBParton", CUTS::eGBParton},
{"NRecoMuon1", CUTS::eRMuon1}, {"NRecoMuon2", CUTS::eRMuon2},
{"NRecoElectron1", CUTS::eRElec1}, {"NRecoElectron2",CUTS::eRElec2},
{"NRecoTau1", CUTS::eRTau1}, {"NRecoTau2", CUTS::eRTau2},
{"NRecoJet1", CUTS::eRJet1}, {"NRecoJet2", CUTS::eRJet2},
{"NRecoCentralJet", CUTS::eRCenJet}, {"NRecoBJet", CUTS::eRBJet},
{"NRecoTriggers1", CUTS::eRTrig1}, {"NRecoTriggers2", CUTS::eRTrig2},
{"NRecoFirstLeadingJet", CUTS::eR1stJet}, {"NRecoSecondLeadingJet", CUTS::eR2ndJet},
{"NDiMuonCombinations", CUTS::eDiMuon}, {"NDiElectronCombinations", CUTS::eDiElec},
{"NDiTauCombinations", CUTS::eDiTau}, {"NDiJetCombinations", CUTS::eDiJet},
{"NMuon1Tau1Combinations", CUTS::eMuon1Tau1}, {"NMuon1Tau2Combinations", CUTS::eMuon1Tau2},
{"NMuon2Tau1Combinations", CUTS::eMuon2Tau1}, {"NMuon2Tau2Combinations", CUTS::eMuon2Tau2},
{"NElectron1Tau1Combinations", CUTS::eElec1Tau1}, {"NElectron1Tau2Combinations", CUTS::eElec1Tau2},
{"NElectron2Tau1Combinations", CUTS::eElec2Tau1}, {"NElectron2Tau2Combinations", CUTS::eElec2Tau2},
{"NMuon1Electron1Combinations", CUTS::eMuon1Elec1}, {"NMuon1Electron2Combinations", CUTS::eMuon1Elec2},
{"NMuon2Electron1Combinations", CUTS::eMuon2Elec1}, {"NMuon2Electron2Combinations", CUTS::eMuon2Elec2},
{"NElectron1Jet1Combinations", CUTS::eElec1Jet1}, {"NElectron1Jet2Combinations", CUTS::eElec1Jet2},
{"NElectron2Jet1Combinations", CUTS::eElec2Jet1}, {"NElectron2Jet2Combinations", CUTS::eElec2Jet2},
{"NLeadJetCombinations", CUTS::eSusyCom}, {"METCut", CUTS::eMET},
{"NRecoWJet", CUTS::eRWjet}, {"NRecoVertex", CUTS::eRVertex}
};
//////////////////////////////////////////////////////
//////////////////PUBLIC FUNCTIONS////////////////////
//////////////////////////////////////////////////////
///Constructor
Analyzer::Analyzer(std::vector<std::string> infiles, std::string outfile, bool setCR, std::string configFolder, std::string year) : goodParts(getArray()), genName_regex(".*([A-Z][^[:space:]]+)"){
std::cout << "setup start" << std::endl;
routfile = new TFile(outfile.c_str(), "RECREATE", outfile.c_str(), ROOT::CompressionSettings(ROOT::kLZMA, 9));
add_metadata(infiles);
BOOM= new TChain("Events");
infoFile=0;
for( std::string infile: infiles){
BOOM->AddFile(infile.c_str());
}
nentries = (int) BOOM->GetEntries();
BOOM->SetBranchStatus("*", 0);
std::cout << "TOTAL EVENTS: " << nentries << std::endl;
srand(0);
filespace=configFolder;//"PartDet";
filespace+="/";
setupGeneral(year);
CalculatePUSystematics = distats["Run"].bfind("CalculatePUSystematics");
// New variable to do special PU weight calculation (2017)
specialPUcalculation = distats["Run"].bfind("SpecialMCPUCalculation");
// If specialPUcalculation is true, then take the name of the output file (when submitting jobs)
// to retrieve the right MC nTruePU distribution to calculate the PU weights, otherwise, it will do
// the calculation as usual, having a single MC nTruePU histogram (MCHistos option).
// If you need to run the Analyzer interactively and use the specialPUcalculation option, make sure that you
// include the name of the sample to analyze. For example, you can look at the names given to output files in past
// runs sumbitted as jobs and use those names instead. This will be improved later.
if(specialPUcalculation){
std::string outputname = outfile;
std::string delimitertune = "_Tune";
std::string delimiterenergy = "_13TeV";
bool istuneinname = outputname.find(delimitertune.c_str()) != std::string::npos;
std::string samplename;
if((samplename.length() == 0) && istuneinname){
unsigned int pos = outputname.find(delimitertune.c_str());
samplename = outputname.erase(pos, (outputname.substr(pos).length()));
}
if((samplename.length() == 0) && (!istuneinname)){
unsigned int pos = outputname.find(delimiterenergy.c_str());
samplename = outputname.erase(pos, (outputname.substr(pos).length()));
}
initializePileupInfo(distats["Run"].smap.at("SpecialMCPUHistos"),distats["Run"].smap.at("DataHistos"),distats["Run"].smap.at("DataPUHistName"), samplename);
}
else{
// No special PU calculation.
initializePileupInfo(distats["Run"].smap.at("MCHistos"),distats["Run"].smap.at("DataHistos"),distats["Run"].smap.at("DataPUHistName"),distats["Run"].smap.at("MCPUHistName") );
}
syst_names.push_back("orig");
std::unordered_map<CUTS, std::vector<int>*, EnumHash> tmp;
syst_parts.push_back(tmp);
if(!isData && distats["Systematics"].bfind("useSystematics")) {
for(auto systname : distats["Systematics"].bset) {
if( systname == "useSystematics")
doSystematics= true;
else {
syst_names.push_back(systname);
syst_parts.push_back(getArray());
}
}
}else {
doSystematics=false;
}
_Electron = new Electron(BOOM, filespace + "Electron_info.in", syst_names, year);
_Muon = new Muon(BOOM, filespace + "Muon_info.in", syst_names, year);
_Tau = new Taus(BOOM, filespace + "Tau_info.in", syst_names, year);
_Jet = new Jet(BOOM, filespace + "Jet_info.in", syst_names, year);
_FatJet = new FatJet(BOOM, filespace + "FatJet_info.in", syst_names, year);
_MET = new Met(BOOM, "MET" , syst_names, distats["Run"].dmap.at("MT2Mass"), year);
// B-tagging scale factor stuff
setupBJetSFInfo(_Jet->pstats["BJet"]);
// Here the calibration module will be defined, which is then needed to define the readers below.
btagsfreader.load(calib, BTagEntry::FLAV_B, "comb");
btagsfreaderup.load(calib, BTagEntry::FLAV_B, "comb");
btagsfreaderdown.load(calib, BTagEntry::FLAV_B, "comb");
if(!isData) {
std::cout<<"This is MC if not, change the flag!"<<std::endl;
_Gen = new Generated(BOOM, filespace + "Gen_info.in", syst_names);
_GenHadTau = new GenHadronicTau(BOOM, filespace + "Gen_info.in", syst_names);
_GenJet = new GenJet(BOOM, filespace + "Gen_info.in", syst_names);
allParticles= {_Gen,_GenHadTau,_GenJet,_Electron,_Muon,_Tau,_Jet,_FatJet};
} else {
std::cout<<"This is Data if not, change the flag!"<<std::endl;
allParticles= {_Electron,_Muon,_Tau,_Jet,_FatJet};
}
particleCutMap[CUTS::eGElec]=_Electron;
particleCutMap[CUTS::eGMuon]=_Muon;
particleCutMap[CUTS::eGTau]=_Tau;
std::vector<std::string> cr_variables;
if(setCR) {
char buf[64];
read_info(filespace + "Control_Regions.in");
crbins = pow(2.0, distats["Control_Region"].dmap.size());
for(auto maper: distats["Control_Region"].dmap) {
cr_variables.push_back(maper.first);
sprintf(buf, "%.*G", 16, maper.second);
cr_variables.push_back(buf);
}
if(isData) {
if(distats["Control_Region"].smap.find("SR") == distats["Control_Region"].smap.end()) {
std::cout << "Using Control Regions with data, but no signal region specified can lead to accidentially unblinding a study before it should be. Please specify a SR in the file PartDet/Control_Region.in" << std::endl;
exit(1);
} else if(distats["Control_Region"].smap.at("SR").length() != distats["Control_Region"].dmap.size()) {
std::cout << "Signal Region specified incorrectly: check signal region variable to make sure the number of variables matches the number of signs in SR" << std::endl;
exit(1);
}
int factor = 1;
SignalRegion = 0;
for(auto gtltSign: distats["Control_Region"].smap["SR"]) {
if(gtltSign == '>') SignalRegion += factor;
factor *= 2;
}
if(distats["Control_Region"].smap.find("Unblind") != distats["Control_Region"].smap.end()) {
blinded = distats["Control_Region"].smap["Unblind"] == "false";
std::cout << "we have " << blinded << std::endl;
}
}
}
//we update the root file if it exist so now we have to delete it:
//std::remove(outfile.c_str()); // delete file
histo = Histogramer(1, filespace+"Hist_entries.in", filespace+"Cuts.in", outfile, isData, cr_variables);
if(doSystematics)
syst_histo=Histogramer(1, filespace+"Hist_syst_entries.in", filespace+"Cuts.in", outfile, isData, cr_variables,syst_names);
systematics = Systematics(distats);
// setupJetCorrections(year, outfile);
///this can be done nicer
//put the variables that you use here:
zBoostTree["tau1_pt"] =0;
zBoostTree["tau1_eta"]=0;
zBoostTree["tau1_phi"]=0;
zBoostTree["tau2_pt"] =0;
zBoostTree["tau2_eta"]=0;
zBoostTree["tau2_phi"]=0;
zBoostTree["met"] =0;
zBoostTree["mt_tau1"] =0;
zBoostTree["mt_tau2"] =0;
zBoostTree["mt2"] =0;
zBoostTree["cosDphi1"]=0;
zBoostTree["cosDphi2"]=0;
zBoostTree["jet1_pt"] =0;
zBoostTree["jet1_eta"]=0;
zBoostTree["jet1_phi"]=0;
zBoostTree["jet2_pt"] =0;
zBoostTree["jet2_eta"]=0;
zBoostTree["jet2_phi"]=0;
zBoostTree["jet_mass"]=0;
histo.createTree(&zBoostTree,"TauTauTree");
if(setCR) {
cuts_per.resize(histo.get_folders()->size());
cuts_cumul.resize(histo.get_folders()->size());
} else {
cuts_per.resize(histo.get_cuts()->size());
cuts_cumul.resize(histo.get_cuts()->size());
}
create_fillInfo();
for(auto maper: distats["Control_Region"].dmap) {
setupCR(maper.first, maper.second);
}
// check if we need to make gen level cuts to cross clean the samples:
for(auto iselect : gen_selection){
if(iselect.second){
std::cout<<"Waning: The selection "<< iselect.first<< " is active!"<<std::endl;
}
}
if(distats["Run"].bfind("InitializeMCSelection")){
std::cout << "MC selection initialized." << std::endl;
initializeMCSelection(infiles);
}
initializeWkfactor(infiles);
setCutNeeds();
std::cout << "setup complete" << std::endl << std::endl;
start = std::chrono::system_clock::now();
}
void Analyzer::add_metadata(std::vector<std::string> infiles){
std::cout << "------------------------------------------------------------ " << std::endl;
std::cout << "Copying minimal original trees from input files:"<<std::endl;
// Define all the variables needed for this function
TFile* rfile;
std::string keyname;
TTree* keytree;
// Loop over the list of input files.
for( std::string infile: infiles){
std::cout << "File: " << infile << std::endl;
// Open the input file
rfile = TFile::Open(infile.c_str());
routfile->cd();
// Loop over all key stored in the current input file
std::cout << "Processing key: " << std::endl;
for(const auto&& inkey : *rfile->GetListOfKeys()){
keyname = inkey->GetName();
std::cout << "\t" << keyname << std::endl;
if(keyname == "Events"){
keytree= ((TTree*) rfile->Get(keyname.c_str())); // Get the tree from file
keytree->SetBranchStatus("*",0); // Disable all branches
keytree->SetBranchStatus("run",1); // Enable only the branch named run
originalTrees[keyname] = keytree->CopyTree("1","",1); // Add this tree to the original trees map. No selection nor option (1st and 2nd arg.) are applied, only 1 event is stored (3rd arg.)
}else if(keyname == "MetaData" or keyname == "ParameterSets" or keyname == "Runs"){ // All branches from these trees are included but only 1 event is stored.
originalTrees[keyname] = ((TTree*) rfile->Get(keyname.c_str()))->CopyTree("1","",1);
}else if(keyname == "LuminosityBlocks"){
originalTrees[keyname] = ((TTree*) rfile->Get(keyname.c_str()))->CopyTree("1"); // All events for this tree are stored since they are useful when comparing with lumi filtering (JSON)
}else if( std::string(inkey->ClassName()) == "TTree"){
std::cout << "Not copying unknown tree " << inkey->GetName() << std::endl;
}
}
routfile->cd();
for(auto tree : originalTrees){
tree.second->Write();
}
rfile->Close();
delete rfile;
}
std::cout << "Finished copying minimal original trees." << std::endl;
std::cout << "------------------------------------------------------------ " << std::endl;
}
std::unordered_map<CUTS, std::vector<int>*, EnumHash> Analyzer::getArray() {
std::unordered_map<CUTS, std::vector<int>*, EnumHash> rmap;
for(auto e: Enum<CUTS>()) {
rmap[e] = new std::vector<int>();
}
return rmap;
}
void Analyzer::create_fillInfo() {
fillInfo["FillLeadingJet"] = new FillVals(CUTS::eSusyCom, FILLER::Dipart, _Jet, _Jet);
fillInfo["FillGen"] = new FillVals(CUTS::eGen, FILLER::Single, _Gen);
fillInfo["FillTau1"] = new FillVals(CUTS::eRTau1, FILLER::Single, _Tau);
fillInfo["FillTau2"] = new FillVals(CUTS::eRTau2, FILLER::Single, _Tau);
fillInfo["FillMuon1"] = new FillVals(CUTS::eRMuon1, FILLER::Single, _Muon);
fillInfo["FillMuon2"] = new FillVals(CUTS::eRMuon2, FILLER::Single, _Muon);
fillInfo["FillElectron1"] = new FillVals(CUTS::eRElec1, FILLER::Single, _Electron);
fillInfo["FillElectron2"] = new FillVals(CUTS::eRElec2, FILLER::Single, _Electron);
fillInfo["FillJet1"] = new FillVals(CUTS::eRJet1, FILLER::Single, _Jet);
fillInfo["FillJet2"] = new FillVals(CUTS::eRJet2, FILLER::Single, _Jet);
fillInfo["FillBJet"] = new FillVals(CUTS::eRBJet, FILLER::Single, _Jet);
fillInfo["FillCentralJet"] = new FillVals(CUTS::eRCenJet, FILLER::Single, _Jet);
fillInfo["FillWJet"] = new FillVals(CUTS::eRWjet, FILLER::Single, _FatJet);
fillInfo["FillDiElectron"] = new FillVals(CUTS::eDiElec, FILLER::Dipart, _Electron, _Electron);
fillInfo["FillDiMuon"] = new FillVals(CUTS::eDiMuon, FILLER::Dipart, _Muon, _Muon);
fillInfo["FillDiTau"] = new FillVals(CUTS::eDiTau, FILLER::Dipart, _Tau, _Tau);
fillInfo["FillMetCuts"] = new FillVals();
fillInfo["FillDiJet"] = new FillVals(CUTS::eDiJet, FILLER::Dipart, _Jet, _Jet);
fillInfo["FillMuon1Tau1"] = new FillVals(CUTS::eMuon1Tau1, FILLER::Dipart, _Muon, _Tau);
fillInfo["FillMuon1Tau2"] = new FillVals(CUTS::eMuon1Tau1, FILLER::Dipart, _Muon, _Tau);
fillInfo["FillMuon2Tau1"] = new FillVals(CUTS::eMuon2Tau1, FILLER::Dipart, _Muon, _Tau);
fillInfo["FillMuon2Tau2"] = new FillVals(CUTS::eMuon2Tau2, FILLER::Dipart, _Muon, _Tau);
fillInfo["FillElectron1Tau1"] = new FillVals(CUTS::eElec1Tau1, FILLER::Dipart, _Electron, _Tau);
fillInfo["FillElectron1Tau2"] = new FillVals(CUTS::eElec1Tau1, FILLER::Dipart, _Electron, _Tau);
fillInfo["FillElectron2Tau1"] = new FillVals(CUTS::eElec2Tau1, FILLER::Dipart, _Electron, _Tau);
fillInfo["FillElectron2Tau2"] = new FillVals(CUTS::eElec2Tau2, FILLER::Dipart, _Electron, _Tau);
fillInfo["FillMuon1Electron1"] = new FillVals(CUTS::eMuon1Elec1, FILLER::Dipart, _Muon, _Electron);
fillInfo["FillMuon1Electron2"] = new FillVals(CUTS::eMuon1Elec1, FILLER::Dipart, _Muon, _Electron);
fillInfo["FillMuon2Electron1"] = new FillVals(CUTS::eMuon2Elec1, FILLER::Dipart, _Muon, _Electron);
fillInfo["FillMuon2Electron2"] = new FillVals(CUTS::eMuon2Elec2, FILLER::Dipart, _Muon, _Electron);
fillInfo["FillElectron1Jet1"] = new FillVals(CUTS::eElec1Jet1, FILLER::Dilepjet, _Electron, _Jet);
fillInfo["FillElectron1Jet2"] = new FillVals(CUTS::eElec1Jet1, FILLER::Dilepjet, _Electron, _Jet);
fillInfo["FillElectron2Jet1"] = new FillVals(CUTS::eElec2Jet1, FILLER::Dilepjet, _Electron, _Jet);
fillInfo["FillElectron2Jet2"] = new FillVals(CUTS::eElec2Jet2, FILLER::Dilepjet, _Electron, _Jet);
//////I hate this solution so much. Its terrible
fillInfo["FillElectron1Electron2"] = new FillVals(CUTS::eDiElec, FILLER::Single, _Electron, _Electron);
fillInfo["FillMuon1Muon2"] = new FillVals(CUTS::eDiMuon, FILLER::Single, _Muon, _Muon);
fillInfo["FillTau1Tau2"] = new FillVals(CUTS::eDiTau, FILLER::Single, _Tau, _Tau);
//efficiency plots
//In principal the efficiency plots should only be used, when also the object is used, but hey nobody knows!
fillInfo["FillTauEfficiency1"] = new FillVals(CUTS::eRTau1, FILLER::Single, _Tau);
fillInfo["FillTauEfficiency2"] = new FillVals(CUTS::eRTau2, FILLER::Single, _Tau);
fillInfo["FillMuonEfficiency1"] = new FillVals(CUTS::eRMuon1, FILLER::Single, _Muon);
fillInfo["FillMuonEfficiency2"] = new FillVals(CUTS::eRMuon2, FILLER::Single, _Muon);
fillInfo["FillElectronEfficiency1"] = new FillVals(CUTS::eRElec1, FILLER::Single, _Electron);
fillInfo["FillElectronEfficiency2"] = new FillVals(CUTS::eRElec2, FILLER::Single, _Electron);
fillInfo["FillJetEfficiency1"] = new FillVals(CUTS::eRJet1, FILLER::Single, _Jet);
fillInfo["FillJetEfficiency2"] = new FillVals(CUTS::eRJet2, FILLER::Single, _Jet);
for(auto it: *histo.get_groups()) {
if(fillInfo[it] == nullptr) fillInfo[it] = new FillVals();
}
}
void Analyzer::setupCR(std::string var, double val) {
std::smatch m;
std::regex part ("^(.+)_(.+)$");
if(std::regex_match(var, m, part)) {
std::string name = m[1];
std::string cut = "Fill" + name;
if(fillInfo.find(cut) == fillInfo.end()) {
std::cout << cut << " not found, put into fillInfo" << std::endl;
exit(1);
}
std::cout << cut << " " << m[2] << " " << val << " " << name << std::endl;
testVec.push_back(new CRTester(fillInfo.at(cut), m[2], val, name));
} else {
std::cout << "Could not process line: " << var << std::endl;
exit(1);
}
}
////destructor
Analyzer::~Analyzer() {
clear_values();
delete BOOM;
delete _Electron;
delete _Muon;
delete _Tau;
delete _Jet;
if(!isData){
delete _Gen;
delete _GenJet;
delete _GenHadTau;
}
for(auto fpair: fillInfo) {
delete fpair.second;
fpair.second=nullptr;
}
for(auto e: Enum<CUTS>()) {
delete goodParts[e];
goodParts[e]=nullptr;
}
//for(auto &it: syst_parts) {
//for(auto e: Enum<CUTS>()) {
//if( it[e] != nullptr) {
//if(it.find(e) != it.end()){
//delete it[e];
//it[e]=nullptr;
//}
//}
//}
//}
for(auto it: testVec){
delete it;
it=nullptr;
}
}
///resets values so analysis can start
void Analyzer::clear_values() {
for(auto e: Enum<CUTS>()) {
goodParts[e]->clear();
}
//faster!!
for(auto &it: syst_parts) {
if (it.size() == 0) continue;
for(auto e: Enum<CUTS>()) {
it[e]->clear();
}
}
if(infoFile!=BOOM->GetFile()){
std::cout<<"New file!"<<std::endl;
infoFile=BOOM->GetFile();
}
leadIndex=-1;
maxCut = 0;
}
// New function: this sets up parameters that only need to be called once per event.
void Analyzer::setupEventGeneral(int nevent){
// This class is an intermediate step called from preprocess that will set up all the variables that are common to the event and not particle specific.
// We want to set those branches first here and then call BOOM->GetEntry(nevent) so that the variables change properly for each event.
// For MC samples, set number of true pileup interactions, gen-HT and gen-weights.
if(!isData){
SetBranch("Pileup_nTrueInt",nTruePU);
SetBranch("genWeight",gen_weight);
if (BOOM->FindBranch("LHE_HT") != 0){
SetBranch("LHE_HT",generatorht);
}
}
// Get the number of primary vertices, applies to both data and MC
SetBranch("PV_npvs", bestVertices);
// Get the offset energy density for jet energy corrections: https://twiki.cern.ch/twiki/bin/view/CMS/IntroToJEC
SetBranch("fixedGridRhoFastjetAll", jec_rho);
// Finally, call get entry so all the branches assigned here are filled with the proper values for each event.
BOOM->GetEntry(nevent);
// Check that the sample does not have crazy values of nTruePU
if(nTruePU < 100.0){
// std::cout << "pileupntrueint = " << pileupntrueint << std::endl;
}
else{
// std::cout << "event with abnormal pileup = " << pileupntrueint << std::endl;
clear_values();
return;
}
// Calculate the pu_weight for this event.
pu_weight = (!isData && CalculatePUSystematics) ? hPU[(int)(nTruePU+1)] : 1.0;
// Get the trigger decision vector.
triggerDecision = false; // Reset the decision flag for each event.
for(std::string triggname : triggerBranchesList){
SetBranch(triggname.c_str(), triggerDecision);
BOOM->GetEntry(nevent);
//std::cout << "Trigger name: " << triggname << ", decision = " << triggerDecision << std::endl;
triggernamedecisions.push_back(&triggerDecision);
}
}
bool Analyzer::passGenHTFilter(float genhtvalue){
if(genhtvalue >= distats["Run"].dmap.at("LowerGenHtCut") && genhtvalue <= distats["Run"].dmap.at("UpperGenHtCut")){
//std::cout << "genhtvalue = " << genhtvalue << ", passed genht filter " << std::endl;
return true;
}
else{
//std::cout << "genhtvalue = " << genhtvalue << ", failed genht filter " << std::endl;
return false;
}
}
bool Analyzer::checkGoodRunsAndLumis(int event){
UInt_t run_num; //NEW: create run_num to store the run number.
UInt_t luminosityBlock_num; //NEW: create luminosityBlock_num to store the number of the luminosity block.
SetBranch("run",run_num); //NEW: define the branch for the run number.
SetBranch("luminosityBlock",luminosityBlock_num); //NEW: define the branch for the luminosity block.
BOOM->GetEntry(event); //NEW: get event.
int key = run_num;
int element = luminosityBlock_num;
auto search = jsonlinedict.find(key); //NEW: see if the run number is in the json dictionary.
if(search != jsonlinedict.end()){ //NEW: this means that the run is in there.
std::vector<int> lumivector; //NEW: going to make a container to store the lumis for the run.
for (auto itr = jsonlinedict.begin(); itr != jsonlinedict.end(); itr++){ //NEW: go through all the pairs of run, lumibound in the dictionary.
if (itr->first != key) continue; //{ //NEW: look for the run number.
lumivector.push_back(itr->second); //NEW: grab all of the lumibounds corresponding to the run number.
}
// NEW: going to go through pairs. good lumi sections defined by [lumibound1, lumibound2], [lumibound3, lumibound4], etc.
// This is why we have to step through the check in twos.
for(size_t lowbound = 0; lowbound < lumivector.size(); lowbound = lowbound+2){
int upbound = lowbound+1; //NEW: checking bounds that are side-by-side in the vector.
if(!(element >= lumivector[lowbound] && element <= lumivector[upbound])) continue; //NEW: if the lumisection is not within the bounds continue, check all lumi pairs.
// if the lumisection falls within one of the lumipairs, you will make it here. Then, return true
return true;
}
}
else{
return false;
}
return false;
}
///Function that does most of the work. Calculates the number of each particle
void Analyzer::preprocess(int event, std::string year){ // This function no longer needs to get the JSON dictionary as input.
std::cout << " preprocess initiated " << std::endl;
int test= BOOM->GetEntry(event);
if(test<0){
std::cout << "Could not read the event from the following file: "<<BOOM->GetFile()->GetNewUrl().Data() << std::endl;
}
int i = 0;
for(Particle* ipart: allParticles){
std::cout << "Particle item " << i << std::endl;
i++;
ipart->init();
}
_MET->init();
active_part = &goodParts;
if(!select_mc_background()){
//we will put nothing in good particles
clear_values();
return;
}
// Call the new function setupEventGeneral: this will set generatorht, pu weight and genweight
setupEventGeneral(event);
if(!isData){ // Do everything that corresponds only to MC
//--- filtering inclusive HT-binned samples: must be done after setupEventGeneral ---
if(distats["Run"].bfind("DiscrByGenHT")){
//std::cout << "generatorht = " << generatorht << std::endl;
if(passGenHTFilter(generatorht) == false){
clear_values();
return;
}
}
// Initialize the lists of generator-level particles.
_Gen->setOrigReco();
_GenHadTau->setOrigReco();
_GenJet->setOrigReco();
getGoodGen(_Gen->pstats["Gen"]);
getGoodGenHadronicTaus(_GenHadTau->pstats["Gen"]);
getGoodGenJets(_GenJet->pstats["Gen"]);
getGoodGenBJets(_GenJet->pstats["Gen"]);
getGoodGenHadronicTauNeutrinos(_Gen->pstats["Gen"]);
getGoodGenBPartons(); //01.16.19
}
else if(isData){
// If you want to filter data by good run and lumi sections, turn on this option in Run_info.in
// SingleMuon data sets need to be filtered. SingleElectron does not (?).
if(distats["Run"].bfind("FilterDataByGoldenJSON")){
if(checkGoodRunsAndLumis(event) == false){
clear_values();
return;
}
}
}
// Call the new function passMetFilters
// Apply here the MET filters, in case the option is turned on. It applies to both data and MC
applymetfilters = distats["Run"].bfind("ApplyMetFilters");
if(applymetfilters){
passedmetfilters = passMetFilters(year, event);
if(!passedmetfilters){
clear_values();
return;
}
}
// ------- Number of primary vertices requirement -------- //
active_part->at(CUTS::eRVertex)->resize(bestVertices);
// ---------------- Trigger requirement ------------------ //
TriggerCuts(CUTS::eRTrig1);
// Print met before it is updated
// for(size_t i=0; i< _Jet->size(); i++) {
// std::cout << "Jet pt (initial) = " << _Jet->pt(i) << std::endl;
// }
// std::cout << "Initial MET: px = " << _MET->px() << ", py = " << _MET->py() << ", pt = " << _MET->pt() << std::endl;
for(size_t i=0; i < syst_names.size(); i++) {
//////Smearing
smearLepton(*_Electron, CUTS::eGElec, _Electron->pstats["Smear"], distats["Electron_systematics"], i);
smearLepton(*_Muon, CUTS::eGMuon, _Muon->pstats["Smear"], distats["Muon_systematics"], i);
// smearLepton(*_Tau, CUTS::eGTau, _Tau->pstats["Smear"], distats["Tau_systematics"], i);
smearLepton(*_Tau, CUTS::eGHadTau, _Tau->pstats["Smear"], distats["Tau_systematics"], i);
// smearJet(*_Jet,CUTS::eGJet,_Jet->pstats["Smear"], year, i);
// smearJet(*_FatJet,CUTS::eGJet,_FatJet->pstats["Smear"], year, i);
// updateMet(i);
}
for(size_t i=0; i < syst_names.size(); i++) {
std::string systname = syst_names.at(i);
// Here is where all corrections applied are loaded to the particle collections and MET.
for( auto part: allParticles) part->setCurrentP(i);
_MET->setCurrentP(i);
/*
for(size_t i=0; i< _Jet->size(); i++) {
std::cout << "Jet pt (intermediate corrected) = " << _Jet->pt(i) << std::endl;
}
std::cout << "Intermediate MET: px = " << _MET->px() << ", py = " << _MET->py() << ", pt = " << _MET->pt() << std::endl;
*/
// Here is where all cuts to particles and MET take place.
updateMet(i);
getGoodParticles(i);
}
// for(size_t i=0; i< _Jet->size(); i++) {
// std::cout << "Jet pt (final corrected) = " << _Jet->pt(i) << std::endl;
// }
// std::cout << "Final MET: px = " << _MET->px() << ", py = " << _MET->py() << ", pt = " << _MET->pt() << std::endl;
// std::cout << " ----------- " << std::endl;
active_part = &goodParts;
if( event < 10 || ( event < 100 && event % 10 == 0 ) ||
( event < 1000 && event % 100 == 0 ) ||
( event < 10000 && event % 1000 == 0 ) ||
( event >= 10000 && event % 10000 == 0 ) ) {
std::cout << std::setprecision(2)<<event << " Events analyzed "<< static_cast<double>(event)/nentries*100. <<"% done"<<std::endl;
std::cout << std::setprecision(5);
}
std::cout << "preprocess finished " << std::endl;
}
void Analyzer::getGoodParticles(int syst){
std::string systname=syst_names.at(syst);
if(syst == 0) active_part = &goodParts;
else active_part=&syst_parts.at(syst);
// syst=syst_names[syst];
// // SET NUMBER OF RECO PARTICLES
// // MUST BE IN ORDER: Muon/Electron, Tau, Jet
getGoodRecoLeptons(*_Electron, CUTS::eRElec1, CUTS::eGElec, _Electron->pstats["Elec1"],syst);
getGoodRecoLeptons(*_Electron, CUTS::eRElec2, CUTS::eGElec, _Electron->pstats["Elec2"],syst);
getGoodRecoLeptons(*_Muon, CUTS::eRMuon1, CUTS::eGMuon, _Muon->pstats["Muon1"],syst);
getGoodRecoLeptons(*_Muon, CUTS::eRMuon2, CUTS::eGMuon, _Muon->pstats["Muon2"],syst);
//getGoodRecoLeptons(*_Tau, CUTS::eRTau1, CUTS::eGTau, _Tau->pstats["Tau1"],syst);
//getGoodRecoLeptons(*_Tau, CUTS::eRTau2, CUTS::eGTau, _Tau->pstats["Tau2"],syst);
getGoodRecoLeptons(*_Tau, CUTS::eRTau1, CUTS::eGHadTau, _Tau->pstats["Tau1"],syst);
getGoodRecoLeptons(*_Tau, CUTS::eRTau2, CUTS::eGHadTau, _Tau->pstats["Tau2"],syst);
getGoodRecoBJets(CUTS::eRBJet, _Jet->pstats["BJet"],syst); //01.16.19
//getGoodRecoJets(CUTS::eRBJet, _Jet->pstats["BJet"],syst);
getGoodRecoJets(CUTS::eRJet1, _Jet->pstats["Jet1"],syst);
getGoodRecoJets(CUTS::eRJet2, _Jet->pstats["Jet2"],syst);
getGoodRecoJets(CUTS::eRCenJet, _Jet->pstats["CentralJet"],syst);
getGoodRecoJets(CUTS::eR1stJet, _Jet->pstats["FirstLeadingJet"],syst);
getGoodRecoJets(CUTS::eR2ndJet, _Jet->pstats["SecondLeadingJet"],syst);
getGoodRecoFatJets(CUTS::eRWjet, _FatJet->pstats["Wjet"],syst);
// treatMuons_Met(systname);
///VBF Susy cut on leadin jets
VBFTopologyCut(distats["VBFSUSY"],syst);
/////lepton lepton topology cuts
getGoodLeptonCombos(*_Electron, *_Tau, CUTS::eRElec1,CUTS::eRTau1, CUTS::eElec1Tau1, distats["Electron1Tau1"],syst);
getGoodLeptonCombos(*_Electron, *_Tau, CUTS::eRElec2, CUTS::eRTau1, CUTS::eElec2Tau1, distats["Electron2Tau1"],syst);
getGoodLeptonCombos(*_Electron, *_Tau, CUTS::eRElec1, CUTS::eRTau2, CUTS::eElec1Tau2, distats["Electron1Tau2"],syst);
getGoodLeptonCombos(*_Electron, *_Tau, CUTS::eRElec2, CUTS::eRTau2, CUTS::eElec2Tau2, distats["Electron2Tau2"],syst);
getGoodLeptonCombos(*_Muon, *_Tau, CUTS::eRMuon1, CUTS::eRTau1, CUTS::eMuon1Tau1, distats["Muon1Tau1"],syst);
getGoodLeptonCombos(*_Muon, *_Tau, CUTS::eRMuon1, CUTS::eRTau2, CUTS::eMuon1Tau2, distats["Muon1Tau2"],syst);
getGoodLeptonCombos(*_Muon, *_Tau, CUTS::eRMuon2, CUTS::eRTau1, CUTS::eMuon2Tau1, distats["Muon2Tau1"],syst);
getGoodLeptonCombos(*_Muon, *_Tau, CUTS::eRMuon2, CUTS::eRTau2, CUTS::eMuon2Tau2, distats["Muon2Tau2"],syst);
getGoodLeptonCombos(*_Muon, *_Electron, CUTS::eRMuon1, CUTS::eRElec1, CUTS::eMuon1Elec1, distats["Muon1Electron1"],syst);
getGoodLeptonCombos(*_Muon, *_Electron, CUTS::eRMuon1, CUTS::eRElec2, CUTS::eMuon1Elec2, distats["Muon1Electron2"],syst);
getGoodLeptonCombos(*_Muon, *_Electron, CUTS::eRMuon2, CUTS::eRElec1, CUTS::eMuon2Elec1, distats["Muon2Electron1"],syst);
getGoodLeptonCombos(*_Muon, *_Electron, CUTS::eRMuon2, CUTS::eRElec2, CUTS::eMuon2Elec2, distats["Muon2Electron2"],syst);
////DIlepton topology cuts
getGoodLeptonCombos(*_Tau, *_Tau, CUTS::eRTau1, CUTS::eRTau2, CUTS::eDiTau, distats["DiTau"],syst);
getGoodLeptonCombos(*_Electron, *_Electron, CUTS::eRElec1, CUTS::eRElec2, CUTS::eDiElec, distats["DiElectron"],syst);
getGoodLeptonCombos(*_Muon, *_Muon, CUTS::eRMuon1, CUTS::eRMuon2, CUTS::eDiMuon, distats["DiMuon"],syst);
//
getGoodLeptonJetCombos(*_Electron, *_Jet, CUTS::eRElec1, CUTS::eRJet1, CUTS::eElec1Jet1, distats["Electron1Jet1"],syst);
getGoodLeptonJetCombos(*_Electron, *_Jet, CUTS::eRElec1, CUTS::eRJet2, CUTS::eElec1Jet2, distats["Electron1Jet2"],syst);
getGoodLeptonJetCombos(*_Electron, *_Jet, CUTS::eRElec2, CUTS::eRJet1, CUTS::eElec2Jet1, distats["Electron2Jet1"],syst);
getGoodLeptonJetCombos(*_Electron, *_Jet, CUTS::eRElec2, CUTS::eRJet2, CUTS::eElec2Jet2, distats["Electron2Jet2"],syst);
////Dijet cuts
getGoodDiJets(distats["DiJet"],syst);
}
void Analyzer::fill_efficiency() {
//cut efficiency
const std::vector<CUTS> goodGenLep={CUTS::eGElec,CUTS::eGMuon,CUTS::eGTau};
//just the lepton 1 for now
const std::vector<CUTS> goodRecoLep={CUTS::eRElec1,CUTS::eRMuon1,CUTS::eRTau1};
for(size_t igen=0;igen<goodGenLep.size();igen++){
Particle* part =particleCutMap.at(goodGenLep[igen]);
CUTS cut=goodRecoLep[igen];
std::smatch mGen;
std::string tmps=part->getName();
std::regex_match(tmps, mGen, genName_regex);
//loop over all gen leptons
for(int iigen : *active_part->at(goodGenLep[igen])){
int foundReco=-1;
for(size_t ireco=0; ireco<part->size(); ireco++){
if(part->p4(ireco).DeltaR(_Gen->p4(iigen))<0.3){
foundReco=ireco;
}
}
histo.addEffiency("eff_Reco_"+std::string(mGen[1])+"Pt", _Gen->pt(iigen), foundReco>=0,0);
histo.addEffiency("eff_Reco_"+std::string(mGen[1])+"Eta",_Gen->eta(iigen),foundReco>=0,0);
histo.addEffiency("eff_Reco_"+std::string(mGen[1])+"Phi",_Gen->phi(iigen),foundReco>=0,0);
if(foundReco>=0){
bool id_particle= (find(active_part->at(cut)->begin(),active_part->at(cut)->end(),foundReco)!=active_part->at(cut)->end());
histo.addEffiency("eff_"+std::string(mGen[1])+"Pt", _Gen->pt(iigen), id_particle,0);
histo.addEffiency("eff_"+std::string(mGen[1])+"Eta",_Gen->eta(iigen),id_particle,0);
histo.addEffiency("eff_"+std::string(mGen[1])+"Phi",_Gen->phi(iigen),id_particle,0);
}
}
}
//for(Particle* part : allParticles){
//regex genName_regex(".*([A-Z][^[:space:]]+)");
//smatch mGen;
//std::string tmps=part->getName();
//regex_match(tmps, mGen, genName_regex);
////no efficiency for gen particles
//if(part->getName().find("Gen") != std::string::npos)
//continue;
////we don't want to make met efficiency plots
//if(particleCutMap.find(part) == particleCutMap.end())
//continue;
//if(part->cutMap.find(part->type) == part->cutMap.end())
//continue;
//for(size_t i=0; i < part->size(); i++){
////make match to gen
//if(matchLeptonToGen(part->p4(i), part->pstats.at("Smear") ,part->cutMap.at(part->type)) == TLorentzVector(0,0,0,0)) continue;
////check if the particle is part of the reco
//for(CUTS cut: particleCutMap.at(part).first){
//bool id_particle= (find(active_part->at(cut)->begin(),active_part->at(cut)->end(),i)!=active_part->at(cut)->end());
//histo.addEffiency("eff_"+std::string(mGen[1])+"Pt",part->pt(i),id_particle,0);
//histo.addEffiency("eff_"+std::string(mGen[1])+"Eta",part->eta(i),id_particle,0);
//histo.addEffiency("eff_"+std::string(mGen[1])+"Phi",part->phi(i),id_particle,0);
//}
//}
//}
}
////Reads cuts from Cuts.in file and see if the event has enough particles
bool Analyzer::fillCuts(bool fillCounter) {
const std::unordered_map<std::string,std::pair<int,int> >* cut_info = histo.get_cuts();
const std::vector<std::string>* cut_order = histo.get_cutorder();
bool prevTrue = true;
maxCut=0;
// std::cout << active_part << std::endl;;
for(size_t i = 0; i < cut_order->size(); i++) {
std::string cut = cut_order->at(i);
if(isData && cut.find("Gen") != std::string::npos){
maxCut += 1;
continue;
}
int min= cut_info->at(cut).first;
int max= cut_info->at(cut).second;
int nparticles = active_part->at(cut_num.at(cut))->size();
//if(!fillCounter) std::cout << cut << ": " << nparticles << " (" << min << ", " << max << ")" <<std::endl;
if( (nparticles >= min) && (nparticles <= max || max == -1)) {
if((cut_num.at(cut) == CUTS::eR1stJet || cut_num.at(cut) == CUTS::eR2ndJet) && active_part->at(cut_num.at(cut))->at(0) == -1 ) {
//cout<<"here "<<std::endl;
prevTrue = false;
continue; ////dirty dirty hack
}
if(fillCounter && crbins == 1) {
cuts_per[i]++;
cuts_cumul[i] += (prevTrue) ? 1 : 0;
maxCut += (prevTrue) ? 1 : 0;
}else{
maxCut += (prevTrue) ? 1 : 0;
}
}else {
//cout<<"here 2 "<<std::endl;
prevTrue = false;
}
}
if(crbins != 1) {
if(!prevTrue) {
maxCut = -1;
return prevTrue;
}
int factor = crbins;
for(auto tester: testVec) {
factor /= 2;
/////get variable value from maper.first.
if(tester->test(this)) { ///pass cut
maxCut += factor;
}
}
if(isData && blinded && maxCut == SignalRegion) return false;
cuts_per[maxCut]++;
}
return prevTrue;
}
///Prints the number of events that passed each cut per event and cumulatively
//done at the end of the analysis
void Analyzer::printCuts() {
std::vector<std::string> cut_order;
if(crbins > 1) cut_order = *(histo.get_folders());
else cut_order = *(histo.get_cutorder());
std::chrono::time_point<std::chrono::system_clock> end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
double run_time_real=elapsed_seconds.count();
std::cout.setf(std::ios::floatfield,std::ios::fixed);
std::cout<<std::setprecision(3);
std::cout << "\n";
std::cout << "Selection Efficiency " << "\n";
std::cout << "Total events: " << nentries << "\n";
std::cout << "\n";
std::cout << "Run Time (real): " <<run_time_real <<" s\n";
std::cout << "Time per 1k Events (real): " << run_time_real/(nentries/1000) <<" s\n";
std::cout << "Events/s: " << static_cast<double>(nentries)/(run_time_real) <<" 1/s (real) \n";
std::cout << " Name Indiv.";
if(crbins == 1) std::cout << " Cumulative";
std::cout << std::endl << "---------------------------------------------------------------------------\n";
for(size_t i = 0; i < cut_order.size(); i++) {
std::cout << std::setw(28) << cut_order.at(i) << " ";
if(isData && cut_order.at(i).find("Gen") != std::string::npos) std::cout << "Skipped" << std::endl;
else if(crbins != 1 && blinded && i == (size_t)SignalRegion) std::cout << "Blinded Signal Region" << std::endl;
else {
std::cout << std::setw(10) << cuts_per.at(i) << " ( " << std::setw(5) << ((float)cuts_per.at(i)) / nentries << ") ";
if(crbins == 1) std::cout << std::setw(12) << cuts_cumul.at(i) << " ( " << std::setw(5) << ((float)cuts_cumul.at(i)) / nentries << ") ";
std::cout << std::endl;
}
}
std::cout <<std::setprecision(5);
std::cout << "---------------------------------------------------------------------------\n";
//write all the histograms
//attention this is not the fill_histogram method from the Analyser
histo.fill_histogram(routfile);
if(doSystematics)
syst_histo.fill_histogram(routfile);
}
/////////////PRIVATE FUNCTIONS////////////////