-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysisMain.cpp
1086 lines (1007 loc) · 42.8 KB
/
analysisMain.cpp
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 <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include "TH1.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TPad.h"
#include "config_parser.h"
#include "AnalysisEvent.h"
#include "cutClass.h"
#include <libconfig.h++>
#include "histogramPlotter.h"
#include <iomanip>
#include <map>
#include <math.h>
#include <LHAPDF/LHAPDF.h>
double zptSF(TString channel, float zpt){
double param1 = 0;
double param2 = 0;
double param3 = 0;
if(channel == "mumumu"){
//mumumu
//1 p0 1.64891e+00 9.46744e-02 8.94955e-05 5.38436e-04
//2 p1 -3.18363e-02 1.83020e-03 1.43202e-06 2.28732e-02
//3 p2 1.96813e-01 1.80560e-02 2.59898e-05 7.20918e-03
//1 p0 9.12190e-01 6.16931e-02 8.40864e-05 3.40620e-05
//2 p1 -2.12648e-02 1.47982e-03 1.38426e-06 2.38949e-01
//3 p2 2.32868e-01 2.61906e-02 3.56068e-05 8.38502e-03
param1 = 9.12190e-01;
param2 =-2.12648e-02;
param3 = 2.32868e-01;
}
if(channel == "emumu"){
//mumue
//1 p0 1.08009e+00 2.20412e-01 1.81954e-04 -2.77029e-04
//2 p1 -1.83319e-02 2.98128e-03 1.46500e-06 -2.16667e-02
//3 p2 -3.79236e-03 2.77700e-02 1.94305e-05 -8.63841e-05
//1 p0 5.88293e-01 5.43378e-02 6.56657e-05 -2.55726e-03
//2 p1 -9.58817e-03 1.49703e-03 6.91871e-07 1.64841e-01
//3 p2 -3.15588e-02 7.50287e-02 3.63099e-05 1.24242e-03
param1 = 5.88293e-01;
param2 = -9.58817e-03;
param3 = -3.15588e-02;
}
if(channel == "eemu"){
//eemu
//1 p0 1.81997e+00 1.09691e-01 1.27075e-04 2.67625e-03
//2 p1 -3.53330e-02 2.11348e-03 2.01050e-06 2.95414e-01
//3 p2 2.00004e-01 1.93575e-02 3.33897e-05 1.34863e-02
//1 p0 1.03732e+00 6.79924e-02 1.10651e-04 -4.52533e-02
//2 p1 -2.11550e-02 1.34032e-03 1.62803e-06 -2.88549e+00
//3 p2 1.52830e-01 2.17467e-02 4.20291e-05 -5.57304e-02
param1 = 1.03732e+00;
param2 =-2.11550e-02;
param3 = 1.52830e-01;
}
if(channel == "eee"){
//eee
//1 p0 1.66655e+00 2.04856e-01 1.22417e-04 -8.87600e-06
// 2 p1 -2.90064e-02 3.37196e-03 1.67677e-06 1.94266e-05
//3 p2 1.12276e-01 2.87604e-02 2.89272e-05 -1.94049e-07
//1 p0 8.23251e-01 8.60477e-02 6.95364e-05 3.23597e-03
//2 p1 -1.74036e-02 2.04299e-03 1.02005e-06 2.12854e-01
//3 p2 1.64031e-01 4.57851e-02 3.12269e-05 7.55832e-03
param1 = 8.23251e-01;
param2 = -1.74036e-02;
param3 = 1.64031e-01;
}
return (exp(param1+param2*zpt) +param3 );
}
//This method is here to set up a load of branches in the TTrees that I will be analysing. Because it's vastly quicker to not load the whole damned thing.
void setBranchStatusAll(TTree * chain, bool isMC, std::string triggerFlag){
//Get electron branches
chain->SetBranchStatus("numElePF2PAT",1);
chain->SetBranchStatus("elePF2PATPT",1);
chain->SetBranchStatus("elePF2PATPX",1);
chain->SetBranchStatus("elePF2PATPY",1);
chain->SetBranchStatus("elePF2PATPZ",1);
chain->SetBranchStatus("elePF2PATE",1);
chain->SetBranchStatus("elePF2PATIsGsf",1);
chain->SetBranchStatus("elePF2PATGsfPx",1);
chain->SetBranchStatus("elePF2PATGsfPy",1);
chain->SetBranchStatus("elePF2PATGsfPz",1);
chain->SetBranchStatus("elePF2PATGsfE",1);
chain->SetBranchStatus("elePF2PATEta",1);
chain->SetBranchStatus("elePF2PATPhi",1);
chain->SetBranchStatus("elePF2PATBeamSpotCorrectedTrackD0",1);
chain->SetBranchStatus("elePF2PATMissingInnerLayers",1);
chain->SetBranchStatus("elePF2PATPhotonConversionVeto",1);
chain->SetBranchStatus("elePF2PATMVA",1);
chain->SetBranchStatus("elePF2PATComRelIsoRho",1);
chain->SetBranchStatus("elePF2PATComRelIsodBeta",1);
chain->SetBranchStatus("elePF2PATComRelIso",1);
chain->SetBranchStatus("elePF2PATChHadIso",1);
chain->SetBranchStatus("elePF2PATNtHadIso",1);
chain->SetBranchStatus("elePF2PATGammaIso",1);
chain->SetBranchStatus("elePF2PATRhoIso",1);
chain->SetBranchStatus("elePF2PATAEff03",1);
chain->SetBranchStatus("elePF2PATCharge",1);
chain->SetBranchStatus("elePF2PATTrackD0",1);
chain->SetBranchStatus("elePF2PATTrackDBD0",1);
chain->SetBranchStatus("elePF2PATD0PV",1);
chain->SetBranchStatus("elePF2PATBeamSpotCorrectedTrackD0",1);
chain->SetBranchStatus("elePF2PATSCEta",1);
//get muon branches
chain->SetBranchStatus("muonPF2PATIsPFMuon",1);
chain->SetBranchStatus("muonPF2PATGlobalID",1);
chain->SetBranchStatus("muonPF2PATTrackID",1);
chain->SetBranchStatus("numMuonPF2PAT",1);
chain->SetBranchStatus("muonPF2PATPt",1);
chain->SetBranchStatus("muonPF2PATPX",1);
chain->SetBranchStatus("muonPF2PATPY",1);
chain->SetBranchStatus("muonPF2PATPZ",1);
chain->SetBranchStatus("muonPF2PATE",1);
chain->SetBranchStatus("muonPF2PATEta",1);
chain->SetBranchStatus("muonPF2PATPhi",1);
chain->SetBranchStatus("muonPF2PATCharge",1);
chain->SetBranchStatus("muonPF2PATComRelIsodBeta",1);
chain->SetBranchStatus("muonPF2PATTrackDBD0",1);
chain->SetBranchStatus("muonPF2PATD0",1);
chain->SetBranchStatus("muonPF2PATDBInnerTrackD0",1);
chain->SetBranchStatus("muonPF2PATTrackDBD0",1);
chain->SetBranchStatus("muonPF2PATBeamSpotCorrectedD0",1);
chain->SetBranchStatus("muonPF2PATD0",1);
chain->SetBranchStatus("muonPF2PATChi2",1);
chain->SetBranchStatus("muonPF2PATNDOF",1);
chain->SetBranchStatus("muonPF2PATVertX",1);
chain->SetBranchStatus("muonPF2PATVertY",1);
chain->SetBranchStatus("muonPF2PATVertZ",1);
chain->SetBranchStatus("muonPF2PATNChambers",1);
chain->SetBranchStatus("muonPF2PATTrackNHits",1);
chain->SetBranchStatus("muonPF2PATMuonNHits",1);
chain->SetBranchStatus("muonPF2PATTkLysWithMeasurements",1);
chain->SetBranchStatus("muonPF2PATGlbTkNormChi2",1);
chain->SetBranchStatus("muonPF2PATDBPV",1);
chain->SetBranchStatus("muonPF2PATDZPV",1);
chain->SetBranchStatus("muonPF2PATVldPixHits",1);
chain->SetBranchStatus("muonPF2PATMatchedStations",1);
//Jet variables
chain->SetBranchStatus("numJetPF2PAT",1);
chain->SetBranchStatus("jetPF2PATPx",1);
chain->SetBranchStatus("jetPF2PATPy",1);
chain->SetBranchStatus("jetPF2PATPz",1);
chain->SetBranchStatus("jetPF2PATE",1);
chain->SetBranchStatus("jetPF2PATEt",1);
chain->SetBranchStatus("jetPF2PATPt",1);
chain->SetBranchStatus("jetPF2PATPtRaw",1);
chain->SetBranchStatus("jetPF2PATUnCorPt",1);
chain->SetBranchStatus("jetPF2PATEta",1);
chain->SetBranchStatus("jetPF2PATPhi",1);
chain->SetBranchStatus("jetPF2PATNConstituents",1);
chain->SetBranchStatus("jetPF2PAT*EnergyFractionCorr",1);
chain->SetBranchStatus("jetPF2PAT*EnergyFraction",1);
chain->SetBranchStatus("jetPF2PATChargedMultiplicity",1);
chain->SetBranchStatus("jetPF2PATdRClosestLepton",1);
//BTag
chain->SetBranchStatus("jetPF2PATBDiscriminator",1);
//MET variables - for plotting (no cuts on these)
chain->SetBranchStatus("metPF2PATEt",1);
chain->SetBranchStatus("metPF2PATPt",1);
//primary vertex info. For muon cut
chain->SetBranchStatus("pvX",1);
chain->SetBranchStatus("pvY",1);
chain->SetBranchStatus("pvZ",1);
//Event info
chain->SetBranchStatus("eventNum",1);
chain->SetBranchStatus("eventRun",1);
chain->SetBranchStatus("eventLumiblock",1);
if (!isMC){
chain->SetBranchStatus("HLT_Mu17_Mu8_v*",1);
chain->SetBranchStatus("HLT_Mu17_TkMu8_v*",1);
chain->SetBranchStatus("HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_*",1);
chain->SetBranchStatus("HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_*",1);
chain->SetBranchStatus("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*",1);
}
else{
chain->SetBranchStatus("HLT_Mu17_Mu8_v12",1);
chain->SetBranchStatus("HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_v9",1);
chain->SetBranchStatus("HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_v9",1);
chain->SetBranchStatus("HLT_Mu17_TkMu8_v5",1);
chain->SetBranchStatus("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v11",1);
}
}
static void show_usage(std::string name){
std::cerr << "Usage: " << name << " <options>"
<< "Options:\n"
<< "\t-c --config\tCONFIGURATION\tThe configuration file to be run over\n"
<< "\t-p\t\t\t\tMake all plots. Currently segfaults if this isn't set, I believe.\n"
<< "\t-n\t\t\t\tSet the number of events to run over. Leave blank for all.\n"
<< "\t-l\t\t\t\tIf this option is set, scale MC plots to a fixed lumi. Default is lumi from data samples.\n"
<< "\t-o --outFolder\tOUTFOLDER\tOutput folder for plots. If set overwrites what may be in the config file.\n"
<< "\t-s --postfix\tPOSTFIX\t\tPostfix for produced plots. Over-rides anything set in a configuration file.\n"
<< "\t-d\t\t\t\tDump event info. For now this is the yield at each stage. May also include event lists later on. \n\t\t\t\t\tIf this flag is set all event weights are 1.\n"
<< "\t-x --cutConf\tCUTCONF\t\tOverrides the cut configuration given in the usual configuration file.\n\t\t\t\t\tThis is mostly so that MC can be run on different cuts without having to make wqhole new confs.\n"
<< "\t --plotConf\tPLOTCONF\tOverrides the plot configuration file in the usual configuration file. \n\t\t\t\t\tFor various reasons I guess. Also sets -p flag automatically. If you don't want plots, DON'T USE THIS OPTION.\n"
<< "\t-i\t\t\t\tInvert the isolation cut of the third lepton. This is for background estimation purposes. \n\t\t\t\t\tWho knows how I am supposed to use that though.\n"
<< "\t-a --synch\t\t\tMakes cutflows for synch exercise i.e. detailed lepSel cutflows. Doesn't do full event selection.\n"
<< "\t-e\t\t\t\tGive a comma separated list of events to run on. This is for synch, but might be useful later?\n"
<< "\t-f --nFiles \tNFILES\t\tUses a specific number of files to run over. \n\t\t\t\t\tThis is useful if testing stuff so that it doesn't have to access the T2 a lot etc.\n"
<< "\t-m\t\t\t\tMonte carlo only mode. Will not run over any data in the configuration.\n"
<< "\t-b\t\t\t\tData only mode. Only runs over data, skips all MC.\n"
<< "\t-t\t\t\t\tUse b-tagging efficiencies to reweight MC\n"
<< "\t-y\t\t\t\tProduces a file of event dumps for stages of the synch.\n"
<< "\t-g\t\t\t\tMakes post-lepSel tree\n"
<< "\t-u\t\t\t\tUses post-lepSel trees\n"
<< "\t-z --makeMVATree\t\tProduce a tree after event selection for MVA purposes\n"
<< "\t-v --syst \tSYST\t\tDo the desired systematic. Brief workaround here, not final yet\n"
<< "\t-j\t\t\t\tMake b-tagging efficiency histograms. Probably doesn't need to be run too many times.\n"
<< "\t-k \tCHANS\t\tBit mask dealy for the channels. 1 - eee 2 - eemu 4 - emumu 8 - mumumu 16 through 128 are same but for inverted third lep iso.\n"
<< "\t --skipTrig\t\t\tSkip running triggers. Used for trigger studies or something.\n"
<< "\t --mvaDir \tDIR\t\tChange the name of the folder the mva outputs go to. mvaTest/ by default. Include the /.\n"
<< "\t --jetRegion \t\tSet the jet region that the analysis will look at. Takes arguments NJETS,NBJETS,MAXJETS,MAXBJETS.\n"
<< "\t --metCut \tCUT\t\tAlter the MET cut of the analysis. 0 by default.\n"
<< "\t --mtwCut \tCUT\t\tAlter the mTW cut of the analysis. 0 by default.\n"
<< "\t-h --help\t\t\tShow this help message\n"
<< std::endl;
}
int main(int argc, char* argv[]){
gErrorIgnoreLevel = kInfo;
//Set up environment a little.
std::cerr << std::setprecision(1) << std::fixed;
std::cout << std::setprecision(1) << std::fixed;
// "This is the main function. It basically just loads a load of other stuff.";
//Parse command line arguments - looking for config file.
if (argc < 3){
show_usage(argv[0]);
return 1;
}
//Various variables that will be used in the analysis. These should really be in a .h file but... I'm lazy. Sorry.
std::string config = "";
bool plots = false;
double usePreLumi = 19700.;
long nEvents = 0.;
std::string outFolder = "plots/";
std::string postfix = "default";
std::string channel = "";
bool infoDump = false;
bool invertIsoCut = false; //For z+jets background estimation
bool synchCutFlow = false; // For synch
bool skipData = false; //utility stuff. True if flags are set and will skip either data or mc.
bool skipMC = false;
std::string* cutConfName = new std::string("");
std::string* plotConfName = new std::string("");
int numFiles = -1;
bool readEventList = false;
bool dumpEventNumbers = false;
bool makePostLepTree = false;
bool makeMVATree = false;
bool usePostLepTree = false;
bool usebTagWeight = false;
int systToRun = 0;
bool makeBTagEffPlots = false;
int channelsToRun = 0; //0 makes it run the one in the config, I guess.
bool skipTrig = false;
std::string mvaDir = "mvaTest/";
bool customJetRegion = false;
float metCut = 0.;
float mtwCut = 0.;
// variables for plotting.
std::vector<std::string> plotNames;
std::vector<float> xMin;
std::vector<float> xMax;
std::vector<int> nBins,cutStage;
std::vector<std::string> fillExp;
std::vector<std::string> xAxisLabels;
std::vector<int> eventNumbers;
std::vector<unsigned int> jetRegVars;
// Loop for parsing command line arguments.
for (int i = 1; i < argc; ++i){
std::string arg = argv[i];
if ((arg=="-h") || (arg == "--help")){ // Display help stuff
show_usage(argv[0]);
return 0;
}
else if ((arg=="-c")||(arg=="--config")){ // Sets configuration file - Required!
if (i + 1 < argc) {
config = argv[++i];
} else{
std::cerr << "--config requires an argument!";
return 0;
}
}
else if (arg=="-n") { // using this option sets the number of entries to run over.
if (i+1 < argc){
nEvents = atol(argv[++i]);
}else{
std::cerr << "-n requires a number of events to run over! You idiot!";
}
}
else if (arg=="-p") {
plots = true;
}
else if ((arg=="-o")||(arg=="--outFolder")){//Set output folder
if (i + 1 < argc){
outFolder = argv[++i];
} else{
std::cerr << "requires a string for output folder name.";
}
}
else if ((arg=="-s")||(arg=="--postfix")){//Set plot postfix
if (i + 1 < argc){
postfix = argv[++i];
} else{
std::cerr << "requires a string for plot postfix.";
}
}
else if (arg=="-l"){
if (i+1 < argc){
usePreLumi = atof(argv[++i]);
}else{
std::cerr << "-l requries a float!";
return 0;
}
}
else if (arg == "-d"){//Option for dumping event information about selected events.
infoDump = true;
}
else if (arg == "-x" || arg == "--cutConf"){
if (i+1 < argc){
*cutConfName = argv[++i];
}else{
std::cerr <<" -x requires an argument";
return 0;
}
}
else if (arg == "--plotConf"){
if (i+1 < argc){
*plotConfName = argv[++i];
plots = true;
}else{
std::cerr <<" --plotConf requires an argument";
return 0;
}
}
else if (arg == "-i"){ //Set up anti-isolation cut for
invertIsoCut = true;
}
else if (arg == "-a" || arg == "--synch"){ // Change to synch exercise cut flow.
synchCutFlow = true;
}
else if (arg == "-m"){
skipData = true;
}
else if (arg == "-b"){
skipMC = true;
}
else if (arg == "-y"){
dumpEventNumbers = true;
}
else if (arg == "-t"){
usebTagWeight = true;
}
else if (arg == "-f" || arg == "--nFiles"){
if (i+1 < argc){
numFiles = atoi(argv[++i]);
}else{
std::cerr << "-f requires an int";
return 0;
}
}
else if (arg == "-e"){
readEventList = true;
std::stringstream ss(argv[++i]);
std::string item;
while (std::getline(ss,item,',')){
jetRegVars.push_back(atoi(item.c_str()));
}
}
else if (arg == "-g"){
makePostLepTree = true;
}
else if (arg == "-z" || arg == "--makeMVATree"){
makeMVATree = true;
}
else if (arg == "-u"){
usePostLepTree = true;
}
else if (arg == "-v" || arg == "--syst"){
if (i+1 < argc){
systToRun = atoi(argv[++i]);
}
else{
std::cerr << "-v requires an int";
return 0;
}
}
else if (arg == "-j"){
makeBTagEffPlots = true;
}
else if (arg == "-k"){
if (i+1 < argc){
channelsToRun = atoi(argv[++i]);
}
else{
std::cerr << "-k needs a config file!";
return 0;
}
}
else if (arg == "--skipTrig"){
skipTrig = true;
std::cout << "Note that you're skipping the trigger!" << std::endl;
}
else if (arg == "--mvaDir"){
mvaDir = argv[++i];
}
else if (arg == "--jetRegion"){
customJetRegion = true;
std::stringstream ss(argv[++i]);
std::string item;
while (std::getline(ss,item,',')){
jetRegVars.push_back(atoi(item.c_str()));
}
std::cout << "CAUTION! Using a custom jet region of "<< jetRegVars[0] << "-" << jetRegVars[2] << " jets, and " << jetRegVars[1] << "-" << jetRegVars[3] << " b-jets" <<std::endl;
}
else if (arg == "--metCut"){
metCut = atof(argv[++i]);
std::cout << "Non zero MET cut! Applied " << metCut << " cut." << std::endl;
}
else if (arg == "--mtwCut"){
mtwCut = atof(argv[++i]);
std::cout << "Non zero mTW cut! Applied " << mtwCut << " cut." << std::endl;
}
} // End command line arguments loop.
if (config == ""){
std::cerr << "We need a configuration file! Type -h for usage. Error";
return 0;
}
if (usebTagWeight && !usePostLepTree){
std::cerr << "At the moment only getting btag weights from post lep-sel trees is supported. Sorry everyone.";
return 0;
}
if (usebTagWeight && makeBTagEffPlots){
std::cerr << "I doubt that set of options is a good idea, so I'm going to just quietly exit here. Don't generate and use b-tag efficiency numbers at the same time...";
return 0;
}
//Make some vectors that will be filled in the parsing.
std::vector<Dataset> datasets;
double totalLumi = 0;
double* lumiPtr = &totalLumi;
if (!Parser::parse_config(config,&datasets,lumiPtr,&plotNames,&xMin,&xMax,&nBins,&fillExp,&xAxisLabels,&cutStage,cutConfName,plotConfName,&outFolder,&postfix,&channel)){
std::cerr << "There was an error parsing the config file.\n";
return 0;
}
//Making a vector of strings that will give systematics name.
std::vector<std::string> systNames;
systNames.push_back("");
systNames.push_back("__trig__plus");
systNames.push_back("__trig__minus");
systNames.push_back("__jer__plus");
systNames.push_back("__jer__minus");
systNames.push_back("__jes__plus");
systNames.push_back("__jes__minus");
systNames.push_back("__pileup__plus");
systNames.push_back("__pileup__minus");
systNames.push_back("__bTag__plus");
systNames.push_back("__bTag__minus");
systNames.push_back("__pdf__plus");
systNames.push_back("__pdf__minus");
//Make cuts object. The methods in it should perhaps just be i nthe AnalysisEvent class....
Cuts * cutObj = new Cuts(plots,plots||infoDump,invertIsoCut,synchCutFlow,dumpEventNumbers);
if (!cutObj->parse_config(*cutConfName)){
std::cerr << "There was a problem with parsing the config!" << std::endl;
return 0;
};
//For studying some trigger things. Default is false.
cutObj->setSkipTrig(skipTrig);
if (customJetRegion) cutObj->setJetRegion(jetRegVars[0],jetRegVars[1],jetRegVars[2],jetRegVars[3]);
cutObj->setMetCut(metCut);
cutObj->setMTWCut(mtwCut);
if (channelsToRun){
std::cout << "Running over the channels: " << std::endl;
for (unsigned int channelInd = 1; channelInd != 256; channelInd = channelInd << 1){
if (!(channelInd & channelsToRun) && channelsToRun) continue;
if (channelInd & 17){
std::cout << "eee ";
}
if (channelInd & 34){ //eemu channels
std::cout << "eemu ";
}
if (channelInd & 68){ // emumu channels
std::cout << "emumu ";
}
if (channelInd & 136){ // mumumu channels
std::cout << "mumumu ";
}
if (channelInd & 15){ //nominal samples
std::cout << "nominal" << std::endl;
}
if (channelInd & 240){ //inv iso samples
std::cout << "inverted" << std::endl;
}
}
}
//Make pileupReweighting stuff here
TFile * dataPileupFile = new TFile("pileup/truePileupTest.root","READ");
TH1F* dataPU = (TH1F*)(dataPileupFile->Get("pileup")->Clone());
TFile * mcPileupFile = new TFile("pileup/pileupMC.root","READ");
TH1F* mcPU = (TH1F*)(mcPileupFile->Get("pileup")->Clone());
//Get systematic files too.
TFile * systUpFile = new TFile("pileup/truePileupUp.root","READ");
TH1F* pileupUpHist = (TH1F*)(systUpFile->Get("pileup")->Clone());
TFile * systDownFile = new TFile("pileup/truePileupDown.root","READ");
TH1F* pileupDownHist = (TH1F*)(systDownFile->Get("pileup")->Clone());
TH1F* puReweight = (TH1F*)dataPU->Clone();
puReweight->Scale(1.0/puReweight->Integral());
mcPU->Scale(1.0/mcPU->Integral());
puReweight->Divide(mcPU);
puReweight->SetDirectory(0);
/// And do the same for systematic sampl
TH1F* puSystUp = (TH1F*)pileupUpHist->Clone();
puSystUp->Scale(1.0/puSystUp->Integral());
puSystUp->Divide(mcPU);
puSystUp->SetDirectory(0);
TH1F* puSystDown = (TH1F*)pileupDownHist->Clone();
puSystDown->Scale(1.0/puSystDown->Integral());
puSystDown->Divide(mcPU);
puSystDown->SetDirectory(0);
dataPileupFile->Close();
mcPileupFile->Close();
systUpFile->Close();
systDownFile->Close();
//Initialise PDFs
if (systToRun & 1024 || systToRun & 2048){
LHAPDF::initPDFSet(1, "CT10nnlo.LHgrid");
// LHAPDF::initPDFSet(1, "cteq6ll.LHpdf");
// LHAPDF::initPDFSet(1, "cteq6lg.LHgrid");
}
// LHAPDF::initPDFSet(1, "CT10nnlo.LHgrid");
//Do a little initialisation for the plots here. Will later on be done in a config file.
//Initialise plot stage names.
std::vector<std::string> stageNames (4);
stageNames = {"lepSel","zMass","jetSel","bTag"};
//Make the plots. If plots have been set. Changing this to a map.
std::map<std::string, std::map<std::string, std::map<std::string, Plots*> > > plotsMap;
std::map<std::string, TH1F*> cutFlowMap;
//A couple of things for plotting. These will soon be set in a config file.
std::vector<std::string> legOrder;
std::vector<std::string > plotOrder;
std::map<std::string, datasetInfo> datasetInfos;
std::vector<std::string> plotsVec;
bool datasetFilled = false;
if (totalLumi == 0.) totalLumi = usePreLumi;
std::cout << "Using lumi: " << totalLumi << std::endl;
for (std::vector<Dataset>::iterator dataset = datasets.begin(); dataset!=datasets.end(); ++dataset){
datasetFilled = false;
TChain * datasetChain = new TChain(dataset->treeName().c_str());
for (unsigned int channelInd = 1; channelInd != 256; channelInd = channelInd << 1){
std::string chanName = "";
if (!(channelInd & channelsToRun) && channelsToRun) continue;
if (channelsToRun){
if (channelInd & 17){ // eee channels
cutObj->setNumLeps(0,0,3,3);
cutObj->setCutConfTrigLabel("e");
channel = "eee";
postfix = "eee";
chanName += "eee";
}
if (channelInd & 34){ //eemu channels
cutObj->setNumLeps(1,1,2,2);
cutObj->setCutConfTrigLabel("d");
channel = "eemu";
postfix = "eemu";
chanName += "eemu";
}
if (channelInd & 68){ // emumu channels
cutObj->setNumLeps(2,2,1,1);
cutObj->setCutConfTrigLabel("d");
channel = "emumu";
postfix = "emumu";
chanName += "emumu";
}
if (channelInd & 136){ // mumumu channels
cutObj->setNumLeps(3,3,0,0);
cutObj->setCutConfTrigLabel("m");
channel = "mumumu";
postfix = "mumumu";
chanName += "mumumu";
}
if (channelInd & 15){ //nominal samples
cutObj->setInvIsoCut(false);
invertIsoCut = false;
chanName += "nom";
}
if (channelInd & 240){ //inv iso samples
cutObj->setInvIsoCut(true);
invertIsoCut = true;
chanName += "inv";
}
}
if (dataset->isMC() && skipMC) continue;
if (!dataset->isMC() && skipData) continue;
if (plots||infoDump) { // Initialise a load of stuff that's required by the plotting macro.
int systMask = 1;
for (unsigned int systInd = 0; systInd < systNames.size(); systInd++){
if (systInd > 0 && !(systToRun & systMask)){
systMask = systMask << 1;
continue;
}
if (cutFlowMap.find(dataset->getFillHisto()+systNames[systInd]) == cutFlowMap.end()){
cutFlowMap[dataset->getFillHisto()] = new TH1F((dataset->getFillHisto()+systNames[systInd]+"cutFlow").c_str(),(dataset->getFillHisto()+systNames[systInd]+"cutFlow").c_str(),4,0,4); //Hopefully make this configurable later on. Same deal as the rest of the plots I guess, work out libconfig.
if (systInd == 0 && datasetInfos.find(dataset->getFillHisto()) == datasetInfos.end()){
legOrder.push_back(dataset->getFillHisto());
plotOrder.push_back(dataset->getFillHisto());
datasetInfos[dataset->getFillHisto()] = datasetInfo();
datasetInfos[dataset->getFillHisto()].colour = dataset->getColour();
datasetInfos[dataset->getFillHisto()].legLabel = dataset->getPlotLabel();
datasetInfos[dataset->getFillHisto()].legType = dataset->getPlotType();
}
if (plots){ // Only make all the plots if it's entirely necessary.
std::cout << "Made plots under" << (dataset->getFillHisto()+systNames[systInd]+channel).c_str() << std::endl;
if (plotsMap.find(channel) == plotsMap.end()){
plotsVec.push_back(systNames[systInd]+channel);
}
plotsMap[systNames[systInd]+channel][(dataset->getFillHisto()).c_str()] = std::map<std::string,Plots*>();
for (unsigned int j = 0; j < stageNames.size(); j++){
plotsMap[systNames[systInd]+channel][(dataset->getFillHisto()).c_str()][stageNames[j]] = new Plots(plotNames, xMin, xMax,nBins, fillExp, xAxisLabels, cutStage, j, dataset->getFillHisto()+"_"+stageNames[j]+systNames[systInd]+"_"+channel);
}
}
}//end cutFlow find loop
if (systInd > 0) systMask = systMask << 1;
}//end systematic loop
} //end plots if
//If making either plots or doing the event dump, make cut flow object.
std::cerr << "Processing dataset " << dataset->name() << std::endl;
if (!usePostLepTree){
if (!datasetFilled){
if (!dataset->fillChain(datasetChain,numFiles)){
std::cerr << "There was a problem constructing the chain for " << dataset->name() << ". Continuing with next dataset.\n";
continue;
}
datasetFilled = true;
}
}
else{
std::string inputPostfix = "";
inputPostfix += postfix;
inputPostfix += invertIsoCut?"invIso":"";
std::cout << "skims/"+dataset->name()+inputPostfix + "SmallSkim.root" << std::endl;
datasetChain->Add(("skims/"+dataset->name()+inputPostfix + "SmallSkim.root").c_str());
std::ifstream secondTree(("skims/"+dataset->name()+inputPostfix + "SmallSkim1.root").c_str());
if (secondTree.good()) datasetChain->Add(("skims/"+dataset->name()+inputPostfix + "SmallSkim1.root").c_str());
std::ifstream thirdTree(("skims/"+dataset->name()+inputPostfix + "SmallSkim2.root").c_str());
if (thirdTree.good()) datasetChain->Add(("skims/"+dataset->name()+inputPostfix + "SmallSkim2.root").c_str());
}
cutObj->setMC(dataset->isMC());
cutObj->setEventInfoFlag(readEventList);
cutObj->setTriggerFlag(dataset->getTriggerFlag());
std::cout << "Trigger flag: " << dataset->getTriggerFlag() << std::endl;
//Here we will initialise the b-tag eff plots if we are doing b-tag efficiencies
std::vector<TH2D*> bTagEffPlots;
std::vector<std::string> denomNum {"Denom","Num"};
std::vector<std::string> typesOfEff {"b","c","uds","g"};
if (makeBTagEffPlots && dataset->isMC()){
int ptBins = 4, etaBins = 4;
float ptMin = 0., ptMax = 200., etaMin = 0., etaMax = 2.4;
for (int unsigned denNum = 0; denNum < denomNum.size(); denNum++){
for (int unsigned type = 0; type < typesOfEff.size(); type++){
bTagEffPlots.push_back(new TH2D(("bTagEff_"+denomNum[denNum]+"_"+typesOfEff[type]).c_str(),("bTagEff_"+denomNum[denNum]+"_"+typesOfEff[type]).c_str(),ptBins,ptMin,ptMax,etaBins,etaMin,etaMax));
}
}
cutObj->setBTagPlots(bTagEffPlots,true);
}//end btag eff plots.
if (usePostLepTree && usebTagWeight && dataset->isMC()){
//Get efficiency plots from the file. Will have to be from post-lep sel trees I guess.
std::string inputPostfix = "";
inputPostfix += postfix;
inputPostfix += invertIsoCut?"invIso":"";
TFile * datasetFileForHists = new TFile(("skims/"+dataset->name() + inputPostfix + "SmallSkim.root").c_str(), "READ");
for (int unsigned denNum = 0; denNum < denomNum.size(); denNum++){
for (int unsigned eff = 0; eff < typesOfEff.size(); eff++){
bTagEffPlots.push_back((TH2D*)(datasetFileForHists->Get(("bTagEff_"+denomNum[denNum]+"_"+typesOfEff[eff]).c_str())->Clone()));
}
}
for (int unsigned plotIt = 0; plotIt < bTagEffPlots.size(); plotIt++){
bTagEffPlots[plotIt]->SetDirectory(0);
}
cutObj->setBTagPlots(bTagEffPlots,false);
datasetFileForHists->Close();
}
//extract the dataset weight.
float datasetWeight = dataset->getDatasetWeight(totalLumi);
//Apply trigger SF here. Also does systematic for trigger +-
if (infoDump) datasetWeight = 1;
std::cout << datasetChain->GetEntries() << " number of items in tree. Dataset weight: " << datasetWeight << std::endl;
AnalysisEvent * event = new AnalysisEvent(dataset->isMC(),dataset->getTriggerFlag(),datasetChain);
//Adding in some stuff here to make a skim file out of post lep sel stuff
TTree * cloneTree = 0;
TTree * cloneTree2 = 0;
TTree * cloneTree3 = 0;
if (makePostLepTree){
cloneTree = datasetChain->CloneTree(0);
cloneTree2 = datasetChain->CloneTree(0);
cloneTree3 = datasetChain->CloneTree(0);
cutObj->setCloneTree(cloneTree,cloneTree2,cloneTree3);
}
//If we're making the MVA tree, set it up here.
std::vector<TTree *> mvaTree;
//Add a few variables into the MVA tree for easy access of stuff like lepton index etc
float eventWeight = 0;
int zLep1Index = -1; // Addresses in elePF2PATWhatever of the z lepton
int zLep2Index = -1;
int wLepIndex = -1;
int jetInd[15]; // The index of the selected jets;
int bJetInd[10]; // Index of selected b-jets;
//Now add in the branches:
if (makeMVATree){
int systMask = 1;
std::cout << "Making systematic trees for " << dataset->name() << ": ";
for (unsigned int systIn = 0; systIn < systNames.size(); systIn++){
std::cout << systNames[systIn] << " ";
// std::cout << "Making systs: " << systMask << " " << systToRun << " " << systIn << " " << (systMask & systToRun) << std::endl;
/* if (systIn > 0 && !(systMask & systToRun)){
if (systIn > 0) systMask = systMask << 1;
continue;
}*/
mvaTree.push_back(datasetChain->CloneTree(0));
mvaTree[systIn]->SetName((mvaTree[systIn]->GetName()+systNames[systIn]).c_str());
mvaTree[systIn]->Branch("eventWeight", &eventWeight, "eventWeight/F");
mvaTree[systIn]->Branch("zLep1Index",&zLep1Index,"zLep1Index/I");
mvaTree[systIn]->Branch("zLep2Index",&zLep2Index,"zLep2Index/I");
mvaTree[systIn]->Branch("wLepIndex",&wLepIndex,"wLepIndex/I");
mvaTree[systIn]->Branch("jetInd",jetInd,"jetInd[15]/I");
mvaTree[systIn]->Branch("bJetInd",bJetInd,"jetInd[10]/I");
if (systIn > 0) systMask = systMask << 1;
}
std::cout <<std::endl;
}
/* else{
event->fChain->SetBranchStatus("*",0); //Should disable most branches.
setBranchStatusAll(event->fChain,dataset->isMC(),dataset->getTriggerFlag());
}*/
int numberOfEvents = datasetChain->GetEntries();
if (nEvents && nEvents < numberOfEvents) numberOfEvents = nEvents;
// datasetChain->Draw("numElePF2PAT","numMuonPF2PAT > 2");
// TH1F * htemp = (TH1F*)gPad->GetPrimitive("htemp");
// htemp->SaveAs("tempCanvas.png");
int foundEvents = 0;
for (int i = 0; i < numberOfEvents; i++){
if (i % 500 < 0.01) std::cerr << i << " (" << 100*float(i)/numberOfEvents << "%) with " << event->numElePF2PAT << " electrons. Found " << (synchCutFlow?cutObj->numFound():foundEvents) << " events.\r";
event->GetEntry(i);
//Do the systematics indicated by the systematic flag, oooor just do data if that's your thing. Whatevs.
int systMask = 1;
for (unsigned int systInd = 0; systInd < systNames.size(); systInd++){
if (!dataset->isMC() && systInd > 0) break;
// std::cout << systInd << " " << systMask << std::endl;
if (systInd > 0 && !(systMask & systToRun)) {
if (systInd > 0) systMask = systMask << 1;
continue;
}
eventWeight = 1;
//apply trigger weights here.
if (dataset->isMC()){
float pileupWeight = puReweight->GetBinContent(puReweight->GetXaxis()->FindBin(event->numVert));
if (systMask == 64) pileupWeight = puSystUp->GetBinContent(puSystUp->GetXaxis()->FindBin(event->numVert));
if (systMask == 128) pileupWeight = puSystDown->GetBinContent(puSystDown->GetXaxis()->FindBin(event->numVert));
eventWeight *= pileupWeight;
if (channel == "eee"){
float twgt = 0.987;
if (systInd > 0 && (systMask == 1)) twgt += 0.036;
if (systInd > 0 && (systMask == 2)) twgt -= 0.036;
eventWeight *= twgt;
}
else if (channel == "eemu"){
float twgt = 0.987;
if (systInd > 0 && (systMask == 1)) twgt += 0.035;
if (systInd > 0 && (systMask == 2)) twgt -= 0.035;
eventWeight *= twgt;
}
if (channel == "emumu"){
float twgt = 0.886;
if (systInd > 0 && (systMask == 1)) twgt += 0.042;
if (systInd > 0 && (systMask == 2)) twgt -= 0.042;
eventWeight *= twgt;
}
if (channel == "mumumu"){
float twgt = 0.9871;
if (systInd > 0 && (systMask == 1)) twgt += 0.0242;
if (systInd > 0 && (systMask == 2)) twgt -= 0.0212;
eventWeight *= twgt;
}
}
if (infoDump) eventWeight = 1;
if (readEventList) {
bool tempBool = false;
for (unsigned int i = 0; i < eventNumbers.size(); i++){
if (eventNumbers[i] == event->eventNum) {
tempBool = true;
break;
}
}
if (!tempBool) continue;
std::cout << event->eventNum << " " << event->eventRun << " " << event->eventLumiblock << " " << datasetChain->GetFile()->GetName() << std::endl;
cutObj->dumpLooseLepInfo(event);
cutObj->dumpLeptonInfo(event);
}
eventWeight*=datasetWeight;
if (!cutObj->makeCuts(event,&eventWeight,plotsMap[systNames[systInd]+channel][dataset->getFillHisto()],cutFlowMap[dataset->getFillHisto()+systNames[systInd]],systInd?systMask:systInd)) {
if (systInd) systMask = systMask << 1;
continue;
}
// std::cout << std::setprecision(9) << eventWeight << " " << datasetWeight << std::endl;
//Do PDF reweighting things here
if (systMask == 1024 || systMask == 2048){
//std::cout << std::setprecision(15) << eventWeight << " ";
LHAPDF::usePDFMember(1,0);
float q = event->genPDFScale;
float x1 = event->genPDFx1;
float x2 = event->genPDFx2;
int id1 = event->genPDFf1;
int id2 = event->genPDFf2;
if (id2 == 21) id2 = 0;
if (id1 == 21) id1 = 0;
double xpdf1 = LHAPDF::xfx(1, x1, q, id1);
double xpdf2 = LHAPDF::xfx(1, x2, q, id2);
std::vector<float> pdf_weights;
//std::cout << q << " " << x1 << " " << x2 << " " << id1 << " " << id2 << " ";
//std::cout << xpdf1 << " " << xpdf2 << " " << xpdf1 * xpdf2 << " ";
float min = 1.0;
float max = 1.0;
float pdfWeightUp = 0.0;
float pdfWeightDown = 0.0;
for (int i = 1; i <=50; ++i){
LHAPDF::usePDFMember(1,i);
double xpdf1_new = LHAPDF::xfx(1, x1, q, id1);
double xpdf2_new = LHAPDF::xfx(1, x2, q, id2);
//std::cout << " " << x1 << " " << id1 << " " << x2 << " " << id2 << " " << q << " " <<xpdf1 << " " << xpdf2 << " " << xpdf1_new << " " << xpdf2_new << " ";
double weight = 1.;
if( (xpdf1 * xpdf2) > 0.00001)
weight = xpdf1_new * xpdf2_new / (xpdf1 * xpdf2);
pdf_weights.push_back(weight);
if (weight > 1.0) pdfWeightUp += (1-weight) * (1-weight);
if (weight < 1.0) pdfWeightDown += (1-weight) * (1-weight);
if (weight > max) max = weight;
if (weight < min) min = weight;
// std::cout << " " << xpdf1_new << " " << xpdf2_new << " " << weight << " ";
}
if (systMask == 1024) eventWeight *= max;
if (systMask == 2048) eventWeight *= min;
//std::cout << eventWeight << std::setprecision(4) << max << " " << min << " " << 1+std::sqrt(pdfWeightUp) << " " << 1-std::sqrt(pdfWeightDown) << std::endl;
//std::cout << std::setprecision(9) << " " << min << " " << max << " " << eventWeight << std::endl;
}
// if (synchCutFlow){
// std::cout << event->eventNum << " " << event->eventRun << " " << event->eventLumiblock << " " << std::endl;
//}
//Do the Zpt reweighting here
if (invertIsoCut){
float zPT = (event->zPairLeptons.first+event->zPairLeptons.second).Pt();
eventWeight *= zptSF(channel,zPT);
}
if (makeMVATree){
zLep1Index = event->zPairIndex.first;
zLep2Index = event->zPairIndex.second;
wLepIndex = event->wLepIndex;
for (unsigned int jetIndexIt = 0; jetIndexIt < 15; jetIndexIt++){
if (jetIndexIt < event->jetIndex.size()) jetInd[jetIndexIt] = event->jetIndex[jetIndexIt];
else jetInd[jetIndexIt] = -1;
}
for (unsigned int bJetIt = 0; bJetIt < 10; bJetIt++){
if (bJetIt < event->bTagIndex.size()) bJetInd[bJetIt] = event->bTagIndex[bJetIt];
else bJetInd[bJetIt] = -1;
}
mvaTree[systInd]->Fill();
}
foundEvents++;
if (systInd > 0) systMask = systMask << 1;
}// End systematics loop.
} //end event loop
//If we're making post lepSel skims save the tree here
if (makePostLepTree){
TFile outFile(("skims/"+dataset->name() + postfix + (invertIsoCut?"invIso":"") + "SmallSkim.root").c_str(),"RECREATE");
outFile.cd();
std::cout << "\nPrinting some info on the tree " <<dataset->name() << " " << cloneTree->GetEntries() << std::endl;
std::cout << "But there were :" << datasetChain->GetEntries() << " entries in the original tree" << std::endl;
cloneTree->Write();
//If we're doing b-tag efficiencies, let's save them here.
if (makeBTagEffPlots){
for (int unsigned i = 0; i < bTagEffPlots.size(); i++){
bTagEffPlots[i]->Write();
}
}
outFile.Write();
outFile.Close();
delete cloneTree;
//If we have any events in the second tree:
if (cloneTree2->GetEntries() > 0){
std::cout << "There are " << cloneTree2->GetEntries() << " entries in the second tree!" << std::endl;
TFile outFile1(("skims/"+dataset->name() + postfix + (invertIsoCut?"invIso":"") + "SmallSkim1.root").c_str(),"RECREATE");
outFile1.cd();
cloneTree2->Write();
outFile1.Write();
outFile1.Close();
}
if (cloneTree3->GetEntries() > 0){
std::cout << "There are " << cloneTree3->GetEntries() << " entries in the third tree! What a lot of trees we've made." << std::endl;
TFile outFile1(("skims/"+dataset->name() + postfix + (invertIsoCut?"invIso":"") + "SmallSkim2.root").c_str(),"RECREATE");
outFile1.cd();
cloneTree3->Write();
outFile1.Write();
outFile1.Close();
}
delete cloneTree2;
delete cloneTree3;
}
//Save mva outputs
if (makeMVATree){
std::cout << (mvaDir + dataset->name() + postfix + (invertIsoCut?"invIso":"") + "mvaOut.root") << std::endl;
TFile mvaOutFile((mvaDir + dataset->name() + postfix + (invertIsoCut?"invIso":"") + "mvaOut.root").c_str(),"RECREATE");
mvaOutFile.cd();
std::cout << std::endl;
int systMask = 1;
std::cout << "Saving Systematics: ";
for (unsigned int systInd = 0; systInd < systNames.size(); systInd++){
if (systInd > 0 && !(systToRun & systMask)){
systMask = systMask << 1;
continue;
}
std::cout << systNames[systInd] << ": " << mvaTree[systInd]->GetEntriesFast() << " " << std::flush;
mvaTree[systInd]->Write();
if (systInd > 0) systMask = systMask << 1;
if (!dataset->isMC()) break;
}
std::cout << std::endl;
//Save the efficiency plots for b-tagging here if we're doing that.
if (makeBTagEffPlots){
for (int unsigned i = 0; i < bTagEffPlots.size(); i++){
bTagEffPlots[i]->Write();
}
}
mvaOutFile.Write();