-
Notifications
You must be signed in to change notification settings - Fork 4
/
yieldMaker.C
3325 lines (3089 loc) · 243 KB
/
yieldMaker.C
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
// #define SSLOOP 1
// #undef SSLOOP
#include <bitset>
#include <iostream>
#include <algorithm>
#include "TChain.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TMath.h"
#include "TH2F.h"
#include "Math/LorentzVector.h"
#include "TKey.h"
#include "TSystem.h"
#include "TMVA/Reader.h"
#include "../misc/class_files/v8.02/SS.h"
// #include "../../common/CORE/SSSelections.h"
#include "../../common/CORE/Tools/dorky/dorky.h"
#include "../../common/CORE/Tools/goodrun.h"
#include "../../common/CORE/Tools/MT2/MT2Utility.h"
#include "../../common/CORE/Tools/MT2/MT2.h"
#include "../misc/common_utils.h"
#include "../misc/signal_regions.h"
// #include "../misc/bdt.h"
// namespace testbdt {
#include "../misc/bdt_run2.h"
// }
#include "../../babymaking/batch/nPoints.cc"
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include "../misc/tqdm.h"
#define WRITE(var) { if (plots.var) plots.var->Write(); }
bool STOP_REQUESTED = false;
float XSEC_TTTT = 11.97;
float scaleLumi = 1; // 75/35.87
// float scaleLumi = 400.0/137.2; // 75/35.87
TH2D *h_counts = 0;
TH1D *h_weights = 0;
void avoidNegativeYields(TH1F* plot);
struct SR_t {
TH1F* SR = 0;
TH1F* SRCR = 0;
TH1F* SRDISC = 0;
TH1F* HH = 0;
TH1F* HL = 0;
TH1F* LL = 0;
TH1F* ML = 0;
TH1F* LM = 0;
TH1F* MI1 = 0; // Scan over MET
TH1F* MI2 = 0; // Scan over HT
TH1F* INCL = 0;
void Write() {
AvoidNegativeYields();
if (SR) SR->Write();
if (SRCR) SRCR->Write();
if (SRDISC) SRDISC->Write();
if (HH) HH->Write();
if (HL) HL->Write();
if (LL) LL->Write();
if (ML) ML->Write();
if (LM) LM->Write();
if (MI1) MI1->Write();
if (MI2) MI2->Write();
if (INCL) INCL->Write();
}
#ifdef SSLOOP
void CatFill(region_t category, float value, float weight, int SRmi1, int SRmi2, std::vector<int> SRincl) {
if ((category == HighHigh ) && HH) HH->Fill(value, weight);
if ((category == HighLow ) && HL) HL->Fill(value, weight);
if ((category == LowLow ) && LL) LL->Fill(value, weight);
if ((category == Multilepton) && ML) ML->Fill(value, weight);
if ((category == LowMet) && LM) LM->Fill(value, weight);
if ((category == HighHigh) && MI1 && (value > 0) && (SRmi1 > 0)) { // MET
for (int i = 1; i <= SRmi1; i++) {
MI1->Fill(i,weight);
}
}
if (((category == HighHigh) || (category == LowMet)) && MI2 && (value > 0) && (SRmi2 > 0)) { // HT
for (int i = 1; i <= SRmi2; i++) {
MI2->Fill(i,weight);
}
}
if (INCL && (value > 0) && (SRincl.size() > 0)) {
for (unsigned int i = 0; i < SRincl.size(); i++) {
if (SRincl[i] > 0) {
INCL->Fill(SRincl[i], weight);
}
}
}
}
#else
void CatFill(int which, float value, float weight) {
if ((which == 0) && SR ) SR->Fill(value, weight );
if ((which == 1) && SRCR ) SRCR->Fill(value, weight );
if ((which == 2) && SRDISC) SRDISC->Fill(value, weight);
}
#endif
void AvoidNegativeYields() {
if (SR) avoidNegativeYields(SR);
if (SRCR) avoidNegativeYields(SRCR);
if (SRDISC) avoidNegativeYields(SRDISC);
if (HH) avoidNegativeYields(HH);
if (HL) avoidNegativeYields(HL);
if (LL) avoidNegativeYields(LL);
if (ML) avoidNegativeYields(ML);
if (LM) avoidNegativeYields(LM);
if (MI1) avoidNegativeYields(MI1);
if (MI2) avoidNegativeYields(MI2);
if (INCL) avoidNegativeYields(INCL);
}
void InitHistError(bool poisson) {
if (poisson) {
if (SR) SR->SetBinErrorOption(TH1::kPoisson);
if (SRCR) SRCR->SetBinErrorOption(TH1::kPoisson);
if (SRDISC) SRDISC->SetBinErrorOption(TH1::kPoisson);
if (HH) HH->SetBinErrorOption(TH1::kPoisson);
if (HL) HL->SetBinErrorOption(TH1::kPoisson);
if (LL) LL->SetBinErrorOption(TH1::kPoisson);
if (ML) ML->SetBinErrorOption(TH1::kPoisson);
if (LM) LM->SetBinErrorOption(TH1::kPoisson);
if (MI1) MI1->SetBinErrorOption(TH1::kPoisson);
if (MI2) MI2->SetBinErrorOption(TH1::kPoisson);
if (INCL) INCL->SetBinErrorOption(TH1::kPoisson);
} else {
if (SR) SR->Sumw2();
if (SRCR) SRCR->Sumw2();
if (SRDISC) SRDISC->Sumw2();
if (HH) HH->Sumw2();
if (HL) HL->Sumw2();
if (LL) LL->Sumw2();
if (ML) ML->Sumw2();
if (LM) LM->Sumw2();
if (MI1) MI1->Sumw2();
if (MI2) MI2->Sumw2();
if (INCL) INCL->Sumw2();
}
}
};
enum categbit_t {
kBaseline = 1<<0,
kSignalRegion = 1<<1,
kHighHigh = 1<<2,
kHighLow = 1<<3,
kLowLow = 1<<4,
kLowMet = 1<<5,
kMultilepton = 1<<6,
kMultileptonOnZ = 1<<7,
kMultileptonOffZ = 1<<8
};
struct triple_t {
TH1F* br = 0;
TH1F* ssbr = 0; // HH+HL+LL
TH1F* sr = 0;
TH1F* hh = 0;
TH1F* hl = 0;
TH1F* ll = 0;
TH1F* ml = 0;
TH1F* lm = 0;
TH1F* mloffz = 0;
TH1F* mlonz = 0;
TH1F* ttzcr = 0;
TH1F* ttwcr = 0;
void Init(TString label, TString chainTitle, int nbins, float xlow, float xhigh) {
ttwcr = new TH1F(Form("ttwcr_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); ttwcr->SetDirectory(0);
ttzcr = new TH1F(Form("ttzcr_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); ttzcr->SetDirectory(0);
sr = new TH1F(Form("sr_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); sr->SetDirectory(0);
br = new TH1F(Form("br_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); br->SetDirectory(0);
ssbr = new TH1F(Form("ssbr_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); ssbr->SetDirectory(0);
hh = new TH1F(Form("hh_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); hh->SetDirectory(0);
hl = new TH1F(Form("hl_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); hl->SetDirectory(0);
ll = new TH1F(Form("ll_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); ll->SetDirectory(0);
ml = new TH1F(Form("ml_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); ml->SetDirectory(0);
lm = new TH1F(Form("lm_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); lm->SetDirectory(0);
mloffz = new TH1F(Form("mloffz_%s_%s",label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); mloffz->SetDirectory(0);
mlonz = new TH1F(Form("mlonz_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); mlonz->SetDirectory(0);
sr = new TH1F(Form("sr_%s_%s" ,label.Data(),chainTitle.Data()), Form("%s_%s",label.Data(),chainTitle.Data()), nbins, xlow, xhigh); sr->SetDirectory(0);
}
void CatFill(int kcategs, float value, float weight) {
if ((kcategs & kBaseline ) && br) br->Fill(value, weight);
if (((kcategs & kHighHigh) | (kcategs & kHighLow) | (kcategs & kLowLow)) && ssbr) ssbr->Fill(value, weight);
if ((kcategs & kSignalRegion ) && sr) sr->Fill(value, weight);
if ((kcategs & kHighHigh ) && hh) hh->Fill(value, weight);
if ((kcategs & kHighLow ) && hl) hl->Fill(value, weight);
if ((kcategs & kLowLow ) && ll) ll->Fill(value, weight);
if ((kcategs & kLowMet) && lm) lm->Fill(value, weight);
if ((kcategs & kMultilepton) && ml) ml->Fill(value, weight);
if ((kcategs & kMultileptonOnZ) && mlonz) mlonz->Fill(value, weight);
if ((kcategs & kMultileptonOffZ) && mloffz) mloffz->Fill(value, weight);
}
void Write() {
if (br) { br->Write(); }
if (ssbr) { ssbr->Write(); }
if (ttzcr) { ttzcr->Write(); }
if (ttwcr) { ttwcr->Write(); }
if (hh) { hh->Write(); }
if (hl) { hl->Write(); }
if (ll) { ll->Write(); }
if (ml) { ml->Write(); }
if (lm) { lm->Write(); }
if (mloffz) { mloffz->Write(); }
if (mlonz) { mlonz->Write(); }
if (sr) { sr->Write(); }
}
};
struct tree_t {
TFile* out_file;
TTree* out_tree;
float tree_weight = -1.;
TString tree_name = "";
int tree_year = -1;
int tree_stype = -1;
int tree_SR = -1;
int tree_SRdisc = -1;
int tree_hyp_class = -1;
int tree_njets = -1;
int tree_nbtags = -1;
int tree_categ = -1;
int tree_event = 0;
int tree_run = 0;
int tree_lumi = 0;
bool tree_isdata = 0;
float tree_mtmin = -1.;
float tree_ht = -1.;
float tree_met = -1.;
int tree_lep1id = 0;
int tree_lep2id = 0;
int tree_lep3id = 0;
float tree_lep1pt = -1.;
float tree_lep2pt = -1.;
float tree_lep3pt = -1.;
float tree_lep1eta = -1.;
float tree_lep2eta = -1.;
float tree_lep3eta = -1.;
float tree_lep1phi = -1.;
float tree_lep2phi = -1.;
float tree_lep3phi = -1.;
int tree_iloose = -1;
void Init(int year, TString chainTitle) {
out_file = new TFile(Form("trees/tree_%i_%s.root",year,chainTitle.Data()),"RECREATE");
out_file->cd();
out_tree = new TTree("t", "tree_yieldMaker");
out_tree->Branch("name" , &tree_name );
out_tree->Branch("year" , &tree_year );
out_tree->Branch("stype" , &tree_stype );
out_tree->Branch("weight" , &tree_weight );
out_tree->Branch("SR" , &tree_SR );
out_tree->Branch("SRdisc" , &tree_SRdisc );
out_tree->Branch("hyp_class" , &tree_hyp_class );
out_tree->Branch("njets" , &tree_njets );
out_tree->Branch("nbtags" , &tree_nbtags );
out_tree->Branch("categ" , &tree_categ );
out_tree->Branch("mtmin" , &tree_mtmin );
out_tree->Branch("ht" , &tree_ht );
out_tree->Branch("met" , &tree_met );
out_tree->Branch("isdata" , &tree_isdata );
out_tree->Branch("lep1id", &tree_lep1id );
out_tree->Branch("lep2id", &tree_lep2id );
out_tree->Branch("lep3id", &tree_lep3id );
out_tree->Branch("lep1pt", &tree_lep1pt );
out_tree->Branch("lep2pt", &tree_lep2pt );
out_tree->Branch("lep3pt", &tree_lep3pt );
out_tree->Branch("lep1eta", &tree_lep1eta );
out_tree->Branch("lep2eta", &tree_lep2eta );
out_tree->Branch("lep3eta", &tree_lep3eta );
out_tree->Branch("lep1phi", &tree_lep1phi );
out_tree->Branch("lep2phi", &tree_lep2phi );
out_tree->Branch("lep3phi", &tree_lep3phi );
out_tree->Branch("iloose", &tree_iloose );
out_tree->Branch("event", &tree_event );
out_tree->Branch("run", &tree_run );
out_tree->Branch("lumi", &tree_lumi );
// macro: 0dwiout_tree->Branch("kjldf_ea", &);kjlD0f"lviwyf&atree_kjpa kj
tree_name = chainTitle;
tree_year = year;
if (chainTitle == "tttt") tree_stype = 0;
if (chainTitle == "fakes") tree_stype = 1;
if (chainTitle == "flips") tree_stype = 2;
if (chainTitle == "ttw") tree_stype = 3;
if (chainTitle == "ttz") tree_stype = 4;
if (chainTitle == "tth") tree_stype = 5;
if (chainTitle == "xg") tree_stype = 6;
if (chainTitle == "ttvv") tree_stype = 7;
if (chainTitle == "rares") tree_stype = 8;
if (chainTitle == "ww") tree_stype = 9;
if (chainTitle == "wz") tree_stype = 10;
// if (chainTitle == "data") tree_stype = -1;
}
void FillVars(
float weight, int SR, int SRdisc, int hyp_class
) {
tree_weight = weight;
tree_SR = SR;
tree_SRdisc = SRdisc;
tree_hyp_class = hyp_class;
out_tree->Fill();
}
void FillVars(
float weight, int SR, int categ, int hyp_class,
int njets, int nbtags, float mtmin, float ht, float met,
bool isdata, int lep1id, int lep2id, int lep3id,
float lep1pt, float lep2pt, float lep3pt
) {
tree_weight = weight;
tree_SR = SR;
tree_hyp_class = hyp_class;
tree_njets = njets;
tree_nbtags = nbtags;
tree_categ = categ;
tree_isdata = isdata;
tree_mtmin = mtmin;
tree_ht = ht;
tree_met = met;
tree_lep1id = lep1id;
tree_lep2id = lep2id;
tree_lep3id = lep3id;
tree_lep1pt = lep1pt;
tree_lep2pt = lep2pt;
tree_lep3pt = lep3pt;
if (tree_isdata) {
tree_event = ss::event();
tree_run = ss::run();
tree_lumi = ss::lumi();
}
if (tree_isdata and hyp_class == 2) {
tree_iloose = 1*(!ss::lep1_passes_id()) + 2*(!ss::lep2_passes_id());
}
// if (hyp_class == 1 or (hyp_class == 6 and (ss::lep1_passes_id()+ss::lep2_passes_id()+ss::lep3_passes_id())==1)) {
// // Two loose leptons, to calculate deltaR
// tree_lep1eta = ss::lep1_p4().eta();
// tree_lep2eta = ss::lep2_p4().eta();
// tree_lep3eta = ss::lep3_p4().eta();
// tree_lep1phi = ss::lep1_p4().phi();
// tree_lep2phi = ss::lep2_p4().phi();
// tree_lep3phi = ss::lep3_p4().phi();
// }
out_tree->Fill();
}
void Write() {
out_file->cd();
out_tree->Write();
out_file->Close();
}
};
struct plots_t {
SR_t SR;
SR_t p_alphas_alt_dn_SR;
SR_t p_alphas_alt_up_SR;
SR_t p_bb_alt_up_SR ;
SR_t p_bb_alt_dn_SR ;
SR_t p_prefire_alt_up_SR ;
SR_t p_prefire_alt_dn_SR ;
SR_t p_trigger_alt_up_SR ;
SR_t p_trigger_alt_dn_SR ;
SR_t p_btagSF_alt_up_SR;
SR_t p_btagSF_alt_dn_SR;
SR_t p_btagSFheavy_alt_up_SR;
SR_t p_btagSFheavy_alt_dn_SR;
SR_t p_btagSFlight_alt_up_SR;
SR_t p_btagSFlight_alt_dn_SR;
SR_t p_fake_alt_up_SR ;
SR_t p_fake_nb0_up_SR ;
SR_t p_fake_nb1_up_SR ;
SR_t p_fake_nb2_up_SR ;
SR_t p_fake_nb3_up_SR ;
SR_t p_fake_unw_up_SR ;
SR_t p_fsrvar_alt_dn_SR;
SR_t p_fsrvar_alt_up_SR;
SR_t p_isr_alt_up_SR ;
SR_t p_isr_alt_dn_SR ;
SR_t p_isrvar_alt_dn_SR;
SR_t p_isrvar_alt_up_SR;
SR_t p_jer_alt_dn_SR ;
SR_t p_jer_alt_up_SR ;
SR_t p_jes_alt_dn_SR ;
SR_t p_jes_alt_up_SR ;
SR_t p_met_alt_up_SR ;
SR_t p_met_alt_dn_SR ;
SR_t p_lep_alt_up_SR ;
SR_t p_lep_alt_dn_SR ;
SR_t p_pdf_alt_dn_SR ;
SR_t p_pdf_alt_up_SR ;
SR_t p_pu_alt_dn_SR ;
SR_t p_pu_alt_up_SR ;
SR_t p_scale_alt_dn_SR ;
SR_t p_scale_alt_up_SR ;
SR_t p_unw_raw_SR ;
SR_t p_unw_sgn_SR ;
triple_t h_ht;
triple_t h_met;
triple_t h_metnm1;
triple_t h_mll;
triple_t h_mllbig;
triple_t h_mllos;
triple_t h_mtmin;
triple_t h_mtmax;
triple_t h_mt1;
triple_t h_mt2;
triple_t h_mt2min;
triple_t h_nleptonicW;
triple_t h_njets;
triple_t h_nbtags;
triple_t h_l1pt;
triple_t h_l2pt;
triple_t h_l3pt;
triple_t h_type;
triple_t h_class;
triple_t h_type3;
triple_t h_category;
triple_t h_lumiblock;
triple_t h_run;
triple_t h_nvtx;
triple_t h_charge;
triple_t h_dphi;
triple_t h_el_charge;
triple_t h_mu_charge;
triple_t h_q3;
triple_t h_charge3;
triple_t h_nleps;
triple_t h_mu_l1pt;
triple_t h_el_l1pt;
triple_t h_mu_l2pt;
triple_t h_mu_l3pt;
triple_t h_el_l2pt;
triple_t h_el_l3pt;
triple_t h_el_nmiss;
triple_t h_disc;
triple_t h_mid1;
triple_t h_mid2;
triple_t h_mid3;
triple_t h_mvis;
triple_t h_mtvis;
triple_t h_ntops;
triple_t h_mtop1;
triple_t h_mtop2;
triple_t h_topdisc1;
triple_t h_topdisc2;
triple_t h_ntopness;
triple_t h_bjetpt;
triple_t h_jetpt;
triple_t h_mva;
triple_t h_mu_sip3d_lep1;
triple_t h_mu_l1eta;
triple_t h_mu_l1phi;
triple_t h_mu_lep1_miniIso;
triple_t h_mu_lep1_ptRel;
triple_t h_mu_lep1_ptRelfail;
triple_t h_mu_lep1_ptRatio;
triple_t h_el_sip3d_lep1;
triple_t h_el_l1eta;
triple_t h_el_l1phi;
triple_t h_el_lep1_miniIso;
triple_t h_el_lep1_ptRel;
triple_t h_el_lep1_ptRelfail;
triple_t h_el_lep1_ptRatio;
triple_t h_mu_sip3d_lep2;
triple_t h_mu_l2eta;
triple_t h_mu_l2phi;
triple_t h_mu_lep2_miniIso;
triple_t h_mu_lep2_ptRel;
triple_t h_mu_lep2_ptRelfail;
triple_t h_mu_lep2_ptRatio;
triple_t h_el_sip3d_lep2;
triple_t h_el_l2eta;
triple_t h_el_l2phi;
triple_t h_el_lep2_miniIso;
triple_t h_el_lep2_ptRel;
triple_t h_el_lep2_ptRelfail;
triple_t h_el_lep2_ptRatio;
triple_t h_mu_sip3d_lep3;
triple_t h_mu_l3eta;
triple_t h_mu_lep3_miniIso;
triple_t h_mu_lep3_ptRel;
triple_t h_mu_lep3_ptRelfail;
triple_t h_mu_lep3_ptRatio;
triple_t h_el_sip3d_lep3;
triple_t h_el_l3eta;
triple_t h_el_lep3_miniIso;
triple_t h_el_lep3_ptRel;
triple_t h_el_lep3_ptRelfail;
triple_t h_el_lep3_ptRatio;
triple_t h_lepsf;
triple_t h_btagsf;
triple_t h_wsf;
triple_t h_puw;
triple_t h_trigsf;
triple_t h_isrw;
triple_t h_dphil1l2;
triple_t h_htb;
triple_t h_nlb40;
triple_t h_ntb40;
triple_t h_detal1l2;
triple_t h_maxmjoverpt;
triple_t h_ml1j1;
triple_t h_ptj1;
triple_t h_ptj6;
triple_t h_ptj7;
triple_t h_ptj8;
};
//function declaration
plots_t run(TChain *chain, int year, TString options);
float calcDeltaPhi(float phi1, float phi2);
float calcMT(float pt1, float phi1, float pt2, float phi2);
float getSMSscale1fb(bool is1d);
float getRPVscale1fb();
float getWeightNormalization(int idx);
std::pair<float,float> getTrijetDiscs(TMVA::Reader* reader);
void getyields(TChain* ch, TString options="", TString outputdir="outputs/"){
// TFile f1(Form("%s/histos_%s.root", outputdir.Data(), ch->GetTitle()), "RECREATE");
signal(SIGINT, [](int){
cout << "SIGINT Caught, stopping after current event" << endl;
STOP_REQUESTED=true;
});
STOP_REQUESTED=false;
bool quiet = options.Contains("quiet");
int year = -1;
TString extra("");
if (options.Contains("Data2016")) {
year = 2016;
if (options.Contains("94x")) extra = "_94x";
} else if (options.Contains("Data2017")) {
year = 2017;
} else if (options.Contains("Data2018")) {
year = 2018;
} else {
cout << "Need to specify year!\n";
assert(year > 0);
}
int year_for_output = year;
if (options.Contains("FakeLumi2017")) {
if (!quiet) std::cout << "Faking 2017 in the output name" << std::endl;
year_for_output = 2017;
} else if (options.Contains("FakeLumi2018")) {
if (!quiet) std::cout << "Faking 2018 in the output name" << std::endl;
year_for_output = 2018;
}
plots_t plots = run(ch, year, options);
TString chainTitle = ch->GetTitle();
TString outname = Form("%s/output_%d%s_%s.root", outputdir.Data(), year_for_output, extra.Data(), chainTitle.Data());
if (!quiet) std::cout << "Writing out " << outname << std::endl;
TFile *fout = new TFile(outname, "RECREATE");
fout->cd();
plots.SR.Write();
plots.h_bjetpt.Write();
plots.h_btagsf.Write();
plots.h_charge.Write();
plots.h_dphi.Write();
plots.h_el_charge.Write();
plots.h_mu_charge.Write();
plots.h_q3.Write();
plots.h_charge3.Write();
plots.h_disc.Write();
plots.h_el_l1eta.Write();
plots.h_el_l1pt.Write();
plots.h_el_l1phi.Write();
plots.h_el_l2eta.Write();
plots.h_el_l2pt.Write();
plots.h_el_l2phi.Write();
plots.h_el_l3eta.Write();
plots.h_el_l3pt.Write();
plots.h_el_lep1_miniIso.Write();
plots.h_el_lep1_ptRatio.Write();
plots.h_el_lep1_ptRel.Write();
plots.h_el_lep1_ptRelfail.Write();
plots.h_el_lep2_miniIso.Write();
plots.h_el_lep2_ptRatio.Write();
plots.h_el_lep2_ptRel.Write();
plots.h_el_lep2_ptRelfail.Write();
plots.h_el_lep3_miniIso.Write();
plots.h_el_lep3_ptRatio.Write();
plots.h_el_lep3_ptRel.Write();
plots.h_el_lep3_ptRelfail.Write();
plots.h_el_nmiss.Write();
plots.h_el_sip3d_lep1.Write();
plots.h_el_sip3d_lep2.Write();
plots.h_el_sip3d_lep3.Write();
plots.h_ht.Write();
plots.h_isrw.Write();
plots.h_jetpt.Write();
plots.h_l1pt.Write();
plots.h_l2pt.Write();
plots.h_l3pt.Write();
plots.h_lepsf.Write();
plots.h_met.Write();
plots.h_metnm1.Write();
plots.h_mid1.Write();
plots.h_mll.Write();
plots.h_mllbig.Write();
plots.h_mllos.Write();
plots.h_mtmin.Write();
plots.h_mtmax.Write();
plots.h_mt2.Write();
plots.h_mt2min.Write();
plots.h_nleptonicW.Write();
plots.h_mtop1.Write();
plots.h_mtop2.Write();
plots.h_mtvis.Write();
plots.h_mu_l1eta.Write();
plots.h_mu_l1pt.Write();
plots.h_mu_l1phi.Write();
plots.h_mu_l2eta.Write();
plots.h_mu_l2pt.Write();
plots.h_mu_l2phi.Write();
plots.h_mu_l3eta.Write();
plots.h_mu_l3pt.Write();
plots.h_mu_lep1_miniIso.Write();
plots.h_mu_lep1_ptRatio.Write();
plots.h_mu_lep1_ptRel.Write();
plots.h_mu_lep1_ptRelfail.Write();
plots.h_mu_lep2_miniIso.Write();
plots.h_mu_lep2_ptRatio.Write();
plots.h_mu_lep2_ptRel.Write();
plots.h_mu_lep2_ptRelfail.Write();
plots.h_mu_lep3_miniIso.Write();
plots.h_mu_lep3_ptRatio.Write();
plots.h_mu_lep3_ptRel.Write();
plots.h_mu_lep3_ptRelfail.Write();
plots.h_mu_sip3d_lep1.Write();
plots.h_mu_sip3d_lep2.Write();
plots.h_mu_sip3d_lep3.Write();
plots.h_mva.Write();
plots.h_mvis.Write();
plots.h_nbtags.Write();
plots.h_njets.Write();
plots.h_nleps.Write();
plots.h_ntopness.Write();
plots.h_ntops.Write();
plots.h_nvtx.Write();
plots.h_puw.Write();
plots.h_topdisc1.Write();
plots.h_topdisc2.Write();
plots.h_trigsf.Write();
plots.h_type.Write();
plots.h_class.Write();
plots.h_type3.Write();
plots.h_category.Write();
plots.h_lumiblock.Write();
plots.h_run.Write();
plots.h_wsf.Write();
plots.h_dphil1l2.Write();
plots.h_htb.Write();
plots.h_nlb40.Write();
plots.h_ntb40.Write();
plots.h_detal1l2.Write();
plots.h_maxmjoverpt.Write();
plots.h_ml1j1.Write();
plots.h_ptj1.Write();
plots.h_ptj6.Write();
plots.h_ptj7.Write();
plots.h_ptj8.Write();
plots.p_alphas_alt_dn_SR.Write();
plots.p_alphas_alt_up_SR.Write();
plots.p_bb_alt_dn_SR.Write();
plots.p_bb_alt_up_SR.Write();
plots.p_prefire_alt_dn_SR.Write();
plots.p_prefire_alt_up_SR.Write();
plots.p_trigger_alt_dn_SR.Write();
plots.p_trigger_alt_up_SR.Write();
plots.p_btagSF_alt_up_SR.Write();
plots.p_btagSF_alt_dn_SR.Write();
plots.p_btagSFheavy_alt_up_SR.Write();
plots.p_btagSFheavy_alt_dn_SR.Write();
plots.p_btagSFlight_alt_up_SR.Write();
plots.p_btagSFlight_alt_dn_SR.Write();
plots.p_fake_alt_up_SR.Write();
plots.p_fake_nb0_up_SR.Write();
plots.p_fake_nb1_up_SR.Write();
plots.p_fake_nb2_up_SR.Write();
plots.p_fake_nb3_up_SR.Write();
plots.p_fake_unw_up_SR.Write();
plots.p_fsrvar_alt_dn_SR.Write();
plots.p_fsrvar_alt_up_SR.Write();
plots.p_isr_alt_dn_SR.Write();
plots.p_isr_alt_up_SR.Write();
plots.p_isrvar_alt_dn_SR.Write();
plots.p_isrvar_alt_up_SR.Write();
plots.p_jer_alt_dn_SR.Write();
plots.p_jer_alt_up_SR.Write();
plots.p_jes_alt_dn_SR.Write();
plots.p_jes_alt_up_SR.Write();
plots.p_lep_alt_dn_SR.Write();
plots.p_lep_alt_up_SR.Write();
plots.p_met_alt_dn_SR.Write();
plots.p_met_alt_up_SR.Write();
plots.p_pdf_alt_dn_SR.Write();
plots.p_pdf_alt_up_SR.Write();
plots.p_pu_alt_dn_SR.Write();
plots.p_pu_alt_up_SR.Write();
plots.p_scale_alt_dn_SR.Write();
plots.p_scale_alt_up_SR.Write();
plots.p_unw_raw_SR.Write();
plots.p_unw_sgn_SR.Write();
// TNamed metadata(TString("metadata"),dir);
// metadata.Write();
// fout->Write();
fout->Close();
// std::cout << " plots.h_ht.sr->GetEntries(): " << plots.h_ht.sr->GetEntries() << std::endl;
if (!quiet) std::cout << "Done writing out " << outname << std::endl;
// // copy the root file with kinematic plots to live with the cards
// gSystem->Exec(Form("cp histos.root ../limits/%s/", dir.Data()));
}
//doFakes = 1 for QCD, 2 for inSitu
plots_t run(TChain *chain, int year, TString options){
#ifdef SSLOOP
ana_t analysis = SSANA;
const bool isSS = true;
#else
ana_t analysis = FTANA;
const bool isSS = false;
#endif
// bool isSS = analysis == SSANA;
float lumiAG = getLumi(year);
int nsr = getNsrs();
int nCR = getNCRs();
int nbdtbins = 17;
int nHHsr = getNsrsHH();
int nHLsr = getNsrsHL();
int nLLsr = getNsrsLL();
int nMLsr = getNsrsML();
int nLMsr = getNsrsLM();
int nMI1sr = getNsrsMI1();
int nMI2sr = getNsrsMI2();
int nINCLsr = getNsrsINCL();
bool isData = 0;
bool doFlips = 0;
int doFakes = 0;
int exclude = 0;
bool isFastsim = 0;
bool isRPV = 0;
bool isRPVfullsim = 0;
bool isGamma = 0;
bool truthfake = 0;
bool skipmatching = 0;
bool ignoreFakeFactor = 0;
bool evaluateBDT = options.Contains("evaluateBDT") && not options.Contains("noBDT");
bool quiet = options.Contains("quiet");
bool write_tree = options.Contains("writeTree");
bool minPtFake18 = options.Contains("minPtFake18");
bool new2016FRBins = options.Contains("new2016FRBins");
bool doStitch = options.Contains("doStitch");
if (options.Contains("BDT10")) { nbdtbins = 10; }
if (options.Contains("BDT11")) { nbdtbins = 11; }
if (options.Contains("BDT12")) { nbdtbins = 12; }
if (options.Contains("BDT13")) { nbdtbins = 13; }
if (options.Contains("BDT14")) { nbdtbins = 14; }
if (options.Contains("BDT15")) { nbdtbins = 15; }
if (options.Contains("BDT16")) { nbdtbins = 16; }
if (options.Contains("BDT17")) { nbdtbins = 17; }
if (options.Contains("BDT18")) { nbdtbins = 18; }
if (options.Contains("BDT19")) { nbdtbins = 19; }
if (options.Contains("BDT20")) { nbdtbins = 20; }
// int nsrdisc = getNsrsDisc(nbdtbins); // this is supposed to be 1 more than nbdtbins (we add in CRZ as a "bin")
int nsrdisc = nbdtbins+1; // this is supposed to be 1 more than nbdtbins (we add in CRZ as a "bin")
float min_pt_fake = minPtFake18 ? 18. : -1;
if (options.Contains("FakeLumi2017")) {
if (!quiet) std::cout << "Faking 2017 luminosity" << std::endl;
lumiAG = getLumi(2017);
} else if (options.Contains("FakeLumi2018")) {
if (!quiet) std::cout << "Faking 2018 luminosity" << std::endl;
lumiAG = getLumi(2018);
}
bool partialUnblind = false;
if (options.Contains("partialUnblind")) {
set_goodrun_file("unblindjson/allsnt.txt");
if (year == 2017 or options.Contains("FakeLumi2017")) {
lumiAG = 10.;
}
if (year == 2018 or options.Contains("FakeLumi2018")) {
lumiAG = 15.415;
}
partialUnblind = true;
}
// Note the blocks and else/ifs
if (options.Contains("doData")) {
if (!quiet) std::cout << "Doing data" << std::endl;
isData = 1;
}
// --------
if (options.Contains("doFakesMCUnw")) {
if (!quiet) std::cout << "Doing fakesMC unweighted" << std::endl;
doFakes = 1;
ignoreFakeFactor = 1;
}
else if (options.Contains("doFakesUnw")) {
if (!quiet) std::cout << "Doing fakes unweighted" << std::endl;
isData = 1;
doFakes = 1;
ignoreFakeFactor = 1;
}
else if (options.Contains("doFakesMC")) {
if (!quiet) std::cout << "Doing fakesMC" << std::endl;
doFakes = 1;
}
else if (options.Contains("doFakes")) {
if (!quiet) std::cout << "Doing fakes" << std::endl;
isData = 1;
doFakes = 1;
}
// --------
if (options.Contains("doFlips")) {
if (!quiet) std::cout << "Doing flips" << std::endl;
isData = 1;
doFlips = 1;
}
// --------
if (options.Contains("doTruthFake")) {
if (!quiet) std::cout << "Doing truthfake" << std::endl;
truthfake = 1;
}
// --------
if (options.Contains("doSkipMatching")) {
if (!quiet) std::cout << "Skipping gen matching" << std::endl;
skipmatching = 1;
}
// --------
if (options.Contains("doXgamma")) {
if (!quiet) std::cout << "Doing x+gamma" << std::endl;
isGamma = 1;
}
if (!quiet) cout << "Running with lumi=" << lumiAG*scaleLumi << endl;
// out_file->cd();
TString chainTitle = chain->GetTitle();
const char* chainTitleCh = chainTitle.Data();
if (!quiet) std::cout << "Working on " << chainTitle << std::endl;
plots_t plots;
tree_t output_tree;
if (write_tree) {
if (!quiet) std::cout << "Initializing output tree" << std::endl;
output_tree.Init(year, chainTitle);
}
if (chainTitle.Contains("rpv_")) {
if (!quiet) std::cout << "RPV fullsim sample detected" << std::endl;
isRPVfullsim = true;
}
if (chainTitle.Contains("t1qqqql")) {
if (!quiet) std::cout << "RPV sample detected" << std::endl;
isRPV = true;
}
if (chainTitle.Contains("fs_")) {
if (!quiet) std::cout << "Fastsim sample detected" << std::endl;
isFastsim = true;
evaluateBDT = false;
}
bool isFakes = (chainTitle=="fakes") || (chainTitle=="fakes_mc");
bool isFlips = (chainTitle=="flips");
bool isRares = (chainTitle=="rares");
bool istt = (chainTitle=="ttbar") || (chainTitle=="fakes_mc") || (chainTitle=="fakes_mc_unw");
bool isttH = (chainTitle=="tth");
bool istttt = (chainTitle=="tttt");
bool isttVV = (chainTitle=="ttvv");
bool isttW = (chainTitle=="ttw");
bool isWW = (chainTitle=="ww");
bool isttZ = (chainTitle=="ttz");
bool isWZ = (chainTitle=="wz");
bool isXgamma = (chainTitle=="xg");
bool isT5qqqqWW = false;
bool isT6ttHZ = false;
bool isT6ttHZ_both = false;
bool isT6ttHZ_z = false;
bool isT6ttHZ_h = false;
float invFilterEff = 1.;
// float weightScale = 1.;
if (chainTitle.Contains("fs_t5qqqqvv")) {
// http://uaf-8.t2.ucsd.edu/~namin/dis/?query=%2FSMS-T5qqqqVV_TuneCUETP8M1_13TeV-madgraphMLM-pythia8%2FRunIISpring16MiniAODv2-PUSpring16Fast_80X_mcRun2_asymptotic_2016_miniAODv2_v0-v1%2FMINIAODSIM&type=mcm&short=short
// Do we need the line below still? I think that was for filtering ncharginos (W's, so we would write it as T5qqqqWW, but now we're ok with WW,WZ,ZZ (VV))
// invFilterEff = 9./4.;
}
if (chainTitle.Contains("fs_t5qqqqvvdm20")) {
// http://uaf-8.t2.ucsd.edu/~namin/dis/?query=%2FSMS-T5qqqqVV_dM20_TuneCUETP8M1_13TeV-madgraphMLM-pythia8%2FRunIISpring16MiniAODv2-PUSpring16Fast_80X_mcRun2_asymptotic_2016_miniAODv2_v0-v1%2FMINIAODSIM&type=mcm&short=short
// Do we need the line below still? I think that was for filtering ncharginos (W's, so we would write it as T5qqqqWW, but now we're ok with WW,WZ,ZZ (VV))
// invFilterEff = 9./4.;
invFilterEff *= 0.446; // efficiency of 1 lepton filter according to MCM for this sample
}
if (chainTitle.Contains("fs_t5qqqqww")) {
isT5qqqqWW = true;
invFilterEff = 9./4.;
}
if (chainTitle.Contains("fs_t5qqqqwwdm20")) {
isT5qqqqWW = true;
invFilterEff = 9./4.;
invFilterEff *= 0.446; // efficiency of 1 lepton filter according to MCM for this sample
}
// BR to higgs is 0.6 (/SMS-T6ttHZ_BR-H_0p6_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/RunIISummer16MiniAODv2-PUSummer16Fast_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/MINIAODSIM)
if (chainTitle.Contains("fs_t6tthzbrb")) { // both (50-50)
isT6ttHZ = true;
isT6ttHZ_both = true;
invFilterEff = 1/(2*0.4*0.6);
}
if (chainTitle.Contains("fs_t6tthzbrh")) { // higgs only
isT6ttHZ = true;
isT6ttHZ_h = true;
invFilterEff = 1/(0.6*0.6);
}
if (chainTitle.Contains("fs_t6tthzbrz")) { // z only
isT6ttHZ = true;
isT6ttHZ_z = true;
invFilterEff = 1/(0.4*0.4);
}
// if (chainTitle.Contains("rpv_")) {
// // FIXME this is just an adhoc scaling since I don't have xsecs
// weightScale = 0.000002;
// }
bool isHiggsScan = false;
bool isHiggsPseudoscalar = false;
bool isHiggsBoth = false;
int higgs_mass = -1;
float fastsim_isr_norm_central = 1.;
float fastsim_isr_norm_up = 1.;
float fastsim_isr_norm_down = 1.;
vector<float> mysparms;
if (chainTitle.Contains("higgsh")) {
isHiggsScan = true;
higgs_mass = chainTitle.Copy().ReplaceAll("higgsh","").Atoi();
mysparms.push_back((float)higgs_mass);
} else if (chainTitle.Contains("higgsa")) {
isHiggsScan = true;
isHiggsPseudoscalar = true;
higgs_mass = chainTitle.Copy().ReplaceAll("higgsa","").Atoi();
mysparms.push_back((float)higgs_mass);
} else if (chainTitle.Contains("higgsb")) {
isHiggsScan = true;
isHiggsBoth = true;
higgs_mass = chainTitle.Copy().ReplaceAll("higgsb","").Atoi();
mysparms.push_back((float)higgs_mass);
}
if (isFastsim) {
if ( chainTitle.Contains("higgs_scan") || chainTitle.Contains("higgs_ps_scan")
|| chainTitle.Contains("tth_scan") || chainTitle.Contains("thq_scan") || chainTitle.Contains("thw_scan")