-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTreeMaker.cc
More file actions
3639 lines (2878 loc) · 141 KB
/
TreeMaker.cc
File metadata and controls
3639 lines (2878 loc) · 141 KB
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
//// Analysis code for search for Displaced letpton. ////
//////////////////////////////////////////////////////////////////////////////
// ttbar @ NLO 13 TeV:
//all-had ->679 * .46 = 312.34
//semi-lep ->679 *.45 = 305.55
//di-lep-> 679* .09 = 61.11
#define _USE_MATH_DEFINES
#include "TStyle.h"
#include "TPaveText.h"
#include "TTree.h"
#include "TNtuple.h"
#include <TMatrixDSym.h>
#include <TMatrixDSymEigen.h>
#include <TVectorD.h>
#include <ctime>
#include <cmath>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
#include <errno.h>
#include "TRandom3.h"
#include "TRandom.h"
#include "TProfile.h"
#include <iostream>
#include <map>
#include <array>
#include <cstdlib>
//user code
#include "TopTreeProducer/interface/TRootRun.h"
#include "TopTreeProducer/interface/TRootEvent.h"
#include "TopTreeAnalysisBase/Selection/interface/SelectionTable.h"
#include "TopTreeAnalysisBase/Selection/interface/Run2Selection.h"
#include "TopTreeAnalysisBase/Selection/interface/MuonSelection.h"
#include "TopTreeAnalysisBase/Selection/interface/ElectronSelection.h"
#include "TopTreeAnalysisBase/Content/interface/AnalysisEnvironment.h"
#include "TopTreeAnalysisBase/Content/interface/Dataset.h"
#include "TopTreeAnalysisBase/Tools/interface/JetTools.h"
#include "TopTreeAnalysisBase/Tools/interface/PlottingTools.h"
#include "TopTreeAnalysisBase/Tools/interface/MultiSamplePlot.h"
#include "TopTreeAnalysisBase/Tools/interface/TTreeLoader.h"
#include "TopTreeAnalysisBase/Tools/interface/AnalysisEnvironmentLoader.h"
#include "TopTreeAnalysisBase/Reconstruction/interface/JetCorrectorParameters.h"
#include "TopTreeAnalysisBase/Reconstruction/interface/JetCorrectionUncertainty.h"
#include "TopTreeAnalysisBase/Reconstruction/interface/MakeBinning.h"
#include "TopTreeAnalysisBase/MCInformation/interface/LumiReWeighting.h"
#include "TopTreeAnalysisBase/MCInformation/interface/JetPartonMatching.h"
#include "TopTreeAnalysisBase/Reconstruction/interface/MEzCalculator.h"
#include "TopTreeAnalysisBase/Tools/interface/LeptonTools.h"
#include "TopTreeAnalysisBase/Reconstruction/interface/TTreeObservables.h"
//This header file is taken directly from the BTV wiki. It contains
// to correctly apply an event level Btag SF. It is not yet on CVS
// as I hope to merge the functionality into BTagWeigtTools.h
//#include "TopTreeAnalysisBase/Tools/interface/BTagSFUtil.h"
#include "TopTreeAnalysisBase/Tools/interface/BTagWeightTools.h"
#include "TopTreeAnalysisBase/Tools/interface/JetCombiner.h"
#include "TopTreeAnalysisBase/Tools/interface/JetTools.h"
#include "Trigger_displaced.h"
#include "Constants.h"
using namespace std;
using namespace TopTree;
using namespace reweight;
Bool_t debug = false;
Bool_t testTree = false;
//if (debug) testTree=true;
int nMatchedEvents=0;
/// Normal Plots (TH1F* and TH2F*)
map<string,TH1F*> histo1D;
map<string,TH2F*> histo2D;
map<string,TProfile*> histoProfile;
/// MultiSamplePlot
map<string,MultiSamplePlot*> MSPlot;
/// MultiPadPlot
map<string,MultiSamplePlot*> MultiPadPlot;
//http://stackoverflow.com/questions/3487717/erasing-multiple-objects-from-a-stdvector
/*
void quickDelete( int idx, vector *vec )
{
vec[idx] = vec.back();
vec.pop_back();
}
*/
struct HighestCSVBtag
{
bool operator()( TRootJet* j1, TRootJet* j2 ) const
{
return j1->btag_combinedInclusiveSecondaryVertexV2BJetTags() > j2->btag_combinedInclusiveSecondaryVertexV2BJetTags();
}
};
float ElectronRelIso(TRootElectron* el, float rho)
{
double EffectiveArea = 0.;
// Updated to Spring 2015 EA from https://github.com/cms-sw/cmssw/blob/CMSSW_7_4_14/RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt#L8
if (fabs(el->superClusterEta()) >= 0.0 && fabs(el->superClusterEta()) < 1.0 ) EffectiveArea = 0.1752;
if (fabs(el->superClusterEta()) >= 1.0 && fabs(el->superClusterEta()) < 1.479 ) EffectiveArea = 0.1862;
if (fabs(el->superClusterEta()) >= 1.479 && fabs(el->superClusterEta()) < 2.0 ) EffectiveArea = 0.1411;
if (fabs(el->superClusterEta()) >= 2.0 && fabs(el->superClusterEta()) < 2.2 ) EffectiveArea = 0.1534;
if (fabs(el->superClusterEta()) >= 2.2 && fabs(el->superClusterEta()) < 2.3 ) EffectiveArea = 0.1903;
if (fabs(el->superClusterEta()) >= 2.3 && fabs(el->superClusterEta()) < 2.4 ) EffectiveArea = 0.2243;
if (fabs(el->superClusterEta()) >= 2.4 && fabs(el->superClusterEta()) < 5.0 ) EffectiveArea = 0.2687;
float isoCorr = el->neutralHadronIso(3) + el->photonIso(3) - rho*EffectiveArea;
float relIsolation = (el->chargedHadronIso(3) + (isoCorr > 0.0 ? isoCorr : 0.0))/(el->Pt());
return relIsolation;
}
// declare infinity as a global float
float infinity = std::numeric_limits<float>::infinity();
int main (int argc, char *argv[])
{
//Checking Passed Arguments to ensure proper execution of MACRO
if (debug)
{
cout << "list of arguments are ..." << endl;
for (int n_arg=1; n_arg<argc; n_arg++)
{
std:: cerr << "arg number " << n_arg << " is " << argv[n_arg] << std::endl;
}
}
if(argc < 16 )
{
std::cerr << "TOO FEW INPUTs FROM XMLFILE. CHECK XML INPUT FROM SCRIPT. " << argc << " ARGUMENTS HAVE BEEN PASSED." << std::endl;
for (int n_arg=1; n_arg<argc; n_arg++)
{
std:: cerr << "arg number " << n_arg << " is " << argv[n_arg] << std::endl;
}
return 1;
}
//Placing arguments in properly typed variables for Dataset creation
string dName = argv[1];
const string dTitle = argv[2];
const int color = strtol(argv[4], NULL, 10);
const int ls = strtol(argv[5], NULL, 10);
const int lw = strtol(argv[6], NULL, 10);
const float normf = strtod(argv[7], NULL);
const float EqLumi = strtod(argv[8], NULL);
const float xSect = strtod(argv[9], NULL);
const float PreselEff = strtod(argv[10], NULL);
string fileName = argv[11];
// if there only two arguments after the fileName, the jobNum will be set to 0 by default as an integer is expected and it will get a string (lastfile of the list)
const string channel = argv[argc-5];
const string btagWP = argv[argc-4];
const int JobNum = strtol(argv[argc-3], NULL, 10);
const int startEvent = strtol(argv[argc-2], NULL, 10);
const int endEvent = strtol(argv[argc-1], NULL, 10);
// all the files are stored from arg 11 to argc-4
vector<string> vecfileNames;
for(int args = 11; args < argc-5; args++)
{
vecfileNames.push_back(argv[args]);
}
if (debug){
cout << "The list of file to run over will be printed..." << endl;
for ( int nfiles = 0; nfiles < vecfileNames.size(); nfiles++)
{
cout << "file number " << nfiles << " is " << vecfileNames[nfiles] << endl;
}
}
cout << "---Dataset accepted from command line---" << endl;
cout << "Dataset Name: " << dName << endl;
cout << "Dataset Title: " << dTitle << endl;
cout << "Dataset color: " << color << endl;
cout << "Dataset ls: " << ls << endl;
cout << "Dataset lw: " << lw << endl;
cout << "Dataset normf: " << normf << endl;
cout << "Dataset EqLumi: " << EqLumi << endl;
cout << "Dataset xSect: " << xSect << endl;
cout << "Dataset File Name: " << vecfileNames[0] << endl;
cout << "Btag working point is " << btagWP << endl;
cout << "Channel is " << channel << endl;
cout << "Beginning Event: " << startEvent << endl;
cout << "Ending Event: " << endEvent << endl;
cout << "JobNum: " << JobNum << endl;
std::transform(dName.begin(), dName.end(), dName.begin(), ::tolower);
bool isData= false;
if(dName.find("Data")!=string::npos || dName.find("data")!=string::npos || dName.find("DATA")!=string::npos){
isData = true;
cout << "running on data !!!!" << endl;
}
bool isSignal = false;
if(dName.find("stoptobl")!=string::npos){
isSignal = true;
cout << "running on signal !!!!" << endl;
}
cout << "----------------------------------------" << endl;
// ofstream eventlist;
// eventlist.open ("interesting_events_mu.txt");
int passed = 0;
int passed_pc = 0;
int ndefs =0;
int negWeights = 0;
float weightCount = 0.0;
int eventCount = 0;
int skippedEvent =0;
int passedBothTrig = 0;
bool bx25 = false; // faco
clock_t start = clock();
int doJESShift = 0; // 0: off 1: minus 2: plus
cout << "doJESShift: " << doJESShift << endl;
int doJERShift = 0; // 0: off (except nominal scalefactor for jer) 1: minus 2: plus
cout << "doJERShift: " << doJERShift << endl;
int domisTagEffShift = 0; //0: off (except nominal scalefactor for mistag eff) 1: minus 2: plus
cout << "domisTagEffShift: " << domisTagEffShift << endl;
cout << "*************************************************************" << endl;
cout << " Beginning of the program for the Displaced Top search ! " << endl;
cout << "*************************************************************" << endl;
string postfix = "_Run2_TopTree_Study_" + dName; // to relabel the names of the output file
///////////////////////////////////////
// Configuration
///////////////////////////////////////
bool printTriggers = false;
bool applyTriggers = true;
string channelpostfix = "";
string btagpostfix = "";
string xmlFileName = "";
bool writeTable = false;
bool applyBlinding = true;
//bool applyBlinding = false;
bool selectOnZPeak = false;
bool saveRawCollection = false; // fill the pc tree
//Setting bools for different channal and or final state. They are all mutually exclusive
bool elel = false; // e-e final state
bool elmu = false; // e-mu final state
bool mumu = false; // mu-mu final state
bool bbel = false; // bbbar + el (Control region)
bool bbmu = false; // bbbar + mu (Control region)
bool ttelel = false; // ttbar + elel
bool ttmumu = false; // ttbar + mumu
// Setting a extra bool for the iso requirement on the lepton. This can be cobined with the previous channels
bool antiIso = false; // 0.15 < iso < 1.5
bool looseIso = false; // iso < 1.5
//bool antiIso = true; // 0.15 < iso < 1.5
//bool looseIso = true; // iso < 1.5
// extra bool for ttbar enriching cut (one b-jet)
bool ttbarEnriched = false;
// Beam spot hard coded values!! This needs to be improved!!!
Double_t BSx = 0.104823;
Double_t BSy = 0.168665;
Double_t BSz = -1.07339;
// bo the logic for the channels
if(channel=="ElMu" || channel== "MuEl")
{
cout << " --> Using the Muon-Electron channel..." << endl;
elmu=true;
channelpostfix = "_MuEl";
}
else if(channel=="MuMu")
{
cout << " --> Using the Muon-Muon channel..." << endl;
mumu=true;
channelpostfix = "_MuMu";
}
else if(channel=="ElEl")
{
cout << " --> Using the Electron-Electron channel..." << endl;
elel=true;
channelpostfix = "_ElEl";
}
else if(channel=="bbMu")
{
cout << " --> Using the bbar+muon control region..." << endl;
bbmu=true;
channelpostfix = "_bbMu";
}
else if(channel=="bbEl")
{
cout << " --> Using the bbar+electron control region..." << endl;
bbel=true;
channelpostfix = "_bbEl";
}
else if(channel=="ttMuMu")
{
cout << " --> Using the ttbar+muons selection..." << endl;
ttmumu=true;
ttbarEnriched=true;
channelpostfix = "_ttMuMu";
}
else if(channel=="ttElEl")
{
cout << " --> Using the ttbar+electrons selection..." << endl;
ttelel=true;
ttbarEnriched=true;
channelpostfix = "_ttElEl";
}
else
{
cerr << "The channel --" << channel << "-- is not in the list of allowed channels !!"<<endl;
exit(1);
}
// eo the logic for the channels
// bo the logic for the btagWP
Float_t bTagDiscriminantCut = 0.0 ;
if (bbel || bbmu){
if(btagWP == "Loose")
{
cout << "btagWP is " << btagWP << endl;
bTagDiscriminantCut = 0.5426;
}
else if(btagWP == "Medium")
{
cout << "btagWP is " << btagWP << endl;
bTagDiscriminantCut = 0.8484;
}
else if(btagWP == "Tight")
{
cout << "btagWP is " << btagWP << endl;
bTagDiscriminantCut = 0.9535;
}
else
{
cerr << "btagWP is " << btagWP << "and this is not in the list of allowed working points" << endl;
}
btagpostfix += "_" + btagWP;
}
// eo the logic for the btagWP
const char *xmlfile = xmlFileName.c_str();
cout << "used config file: " << xmlfile << endl;
/////////////////////////////
// Set up AnalysisEnvironment
/////////////////////////////
AnalysisEnvironment anaEnv;
cout<<" - Creating environment ..."<<endl;
anaEnv.PrimaryVertexCollection = "PrimaryVertex";
anaEnv.JetCollection = "PFJets_slimmedJets";
anaEnv.FatJetCollection = "FatJets_slimmedJetsAK8";
anaEnv.METCollection = "PFMET_slimmedMETs";
anaEnv.MuonCollection = "Muons_slimmedMuons";
anaEnv.ElectronCollection = "Electrons_selectedElectrons";
anaEnv.GenJetCollection = "GenJets_slimmedGenJets";
anaEnv.NPGenEventCollection = "NPGenEvent";
anaEnv.MCParticlesCollection = "MCParticles";
anaEnv.loadFatJetCollection = true;
anaEnv.loadNPGenEventCollection = false;
anaEnv.loadMCParticles = true;
anaEnv.JetType = 2;
anaEnv.METType = 2;
int verbose = 2;//anaEnv.Verbose;
////////////////////////////////
// Load datasets
////////////////////////////////
TTreeLoader treeLoader;
vector < Dataset* > datasets;
cout << " - Creating Dataset ..." << endl;
Dataset* theDataset = new Dataset(dName, dTitle, true, color, ls, lw, normf, xSect, vecfileNames);
// skip if data and no blinding
if ((isData && !applyBlinding && !selectOnZPeak)) cout << endl << "--------------------------------" << endl
<< "You are not applying the blinding cuts but you are trying to run over Data.\
You are a bad boy and all the data root file will be empty" << endl
<< "--------------------------------" << endl << endl;
else datasets.push_back(theDataset);
string dataSetName;
////////////////////////////////
// Event Scale Factor
////////////////////////////////
string pathToCaliDir="../TopTreeAnalysisBase/Calibrations/";
/// Leptons
// bo Muon SF
double muonSFID, muonSFIso;
// Muon ID SF
MuonSFWeight* muonSFWeightID_BCDEF;
MuonSFWeight* muonSFWeightID_GH;
MuonSFWeight* muonSFWeightIso_BCDEF;
MuonSFWeight* muonSFWeightIso_GH;
TFile *muontrackfile = new TFile("../TopTreeAnalysisBase/Calibrations/LeptonSF/MuonSF/Tracking_EfficienciesAndSF_BCDEFGH.root","read");
TGraph* h_muonSFWeightTrack = static_cast<TGraph*>( muontrackfile->Get("ratio_eff_eta3_dr030e030_corr")->Clone() );//Tracking efficiency as function of eta
muonSFWeightID_BCDEF = new MuonSFWeight("../TopTreeAnalysisBase/Calibrations/LeptonSF/MuonSF/MuonID_EfficienciesAndSF_BCDEF.root", "MC_NUM_TightID_DEN_genTracks_PAR_pt_eta/abseta_pt_ratio", true, false, false);
muonSFWeightID_GH = new MuonSFWeight("../TopTreeAnalysisBase/Calibrations/LeptonSF/MuonSF/MuonID_EfficienciesAndSF_GH.root", "MC_NUM_TightID_DEN_genTracks_PAR_pt_eta/abseta_pt_ratio", true, false, false);
muonSFWeightIso_BCDEF = new MuonSFWeight("../TopTreeAnalysisBase/Calibrations/LeptonSF/MuonSF/MuonIso_EfficienciesAndSF_BCDEF.root", "TightISO_TightID_pt_eta/abseta_pt_ratio", true, false, false); // Tight RelIso, Tight ID
muonSFWeightIso_GH = new MuonSFWeight("../TopTreeAnalysisBase/Calibrations/LeptonSF/MuonSF/MuonIso_EfficienciesAndSF_GH.root", "TightISO_TightID_pt_eta/abseta_pt_ratio", true, false, false); // Tight RelIso, Tight ID
// eo Muon SF
// Electron SF
// Electron reco SF
string electronRecoSFFile= "../TopTreeAnalysisBase/Calibrations/LeptonSF/ElectronSF/Moriond17/egammaEffi.txt_EGM2D_RecoEff.root";
ElectronSFWeight *electronSFWeightReco_ = new ElectronSFWeight (electronRecoSFFile,"EGamma_SF2D",true, false, false); // (... , ... , extendRange , debug, print warning)
// Electron ID SF
string electronIdSFFile= "../TopTreeAnalysisBase/Calibrations/LeptonSF/ElectronSF/Moriond17/egammaEffi.txt_EGM2D_CutBasedTightID.root";
ElectronSFWeight *electronSFWeightId_T_ = new ElectronSFWeight (electronIdSFFile,"EGamma_SF2D",true, false, false);
// eo Electron SF
// PU SF
LumiReWeighting LumiWeights_down_("../TopTreeAnalysisBase/Calibrations/PileUpReweighting/MCPileup_Summer16.root", "../TopTreeAnalysisBase/Calibrations/PileUpReweighting/pileup_2016Data80X_Run271036-284044Cert__Full2016DataSet.root", "pileup", "pileup");
LumiReWeighting LumiWeights_("../TopTreeAnalysisBase/Calibrations/PileUpReweighting/MCPileup_Summer16.root", "../TopTreeAnalysisBase/Calibrations/PileUpReweighting/pileup_2016Data80X_Run271036-284044Cert__Full2016DataSet.root", "pileup", "pileup");
LumiReWeighting LumiWeights_up_("../TopTreeAnalysisBase/Calibrations/PileUpReweighting/MCPileup_Summer16.root", "../TopTreeAnalysisBase/Calibrations/PileUpReweighting/pileup_2016Data80X_Run271036-284044Cert__Full2016DataSet_sysPlus.root", "pileup", "pileup");
/////////////////////////////////
// Loop over Datasets
/////////////////////////////////
dataSetName = theDataset->Name();
int ndatasets = datasets.size() - 1 ;
double currentLumi;
double newlumi;
//Output ROOT file
channelpostfix += "_v9_mutrig_nod0cut_noIsocut";
string outputDirectory("MACRO_Output"+channelpostfix);
mkdir(outputDirectory.c_str(),0777);
// add jobs number at the end of file if
stringstream ss;
ss << JobNum;
string strJobNum = ss.str();
if (antiIso) channelpostfix = channelpostfix+"_antiIso";
if (looseIso) channelpostfix = channelpostfix+"_looseIso";
if (!applyBlinding) channelpostfix = channelpostfix+"_NoBlinding";
if (selectOnZPeak) channelpostfix = channelpostfix+"_ZPeak";
channelpostfix = btagpostfix +channelpostfix;
string rootFileName (outputDirectory+"/DisplacedTop"+postfix+channelpostfix+".root");
if (strJobNum != "0")
{
cout << "strJobNum is " << strJobNum << endl;
rootFileName = outputDirectory+"/DisplacedTop"+postfix+channelpostfix+"_"+strJobNum+".root";
}
TFile *fout = new TFile (rootFileName.c_str(), "RECREATE");
//vector of objects
cout << " - Variable declaration ..." << endl;
vector < TRootVertex* > vertex;
vector < TRootMuon* > init_muons;
vector < TRootElectron* > init_electrons;
vector < TRootJet* > init_jets;
vector < TRootJet* > init_fatjets;
vector < TRootMET* > mets;
//Global variable
TRootEvent* event = 0;
////////////////////////////////////////////////////////////////////
////////////////// MultiSample plots //////////////////////////////
////////////////////////////////////////////////////////////////////
/*
MSPlot["NbOfVertices"] = new MultiSamplePlot(datasets, "NbOfVertices", 60, 0, 60, "Nb. of vertices");
//Muons
MSPlot["MuonPt"] = new MultiSamplePlot(datasets, "MuonPt", 30, 0, 300, "PT_{#mu}");
MSPlot["MuonEta"] = new MultiSamplePlot(datasets, "MuonEta", 40,-4, 4, "Muon #eta");
MSPlot["MuonRelIsolation"] = new MultiSamplePlot(datasets, "MuonRelIsolation", 10, 0, .25, "RelIso");
//Electrons
MSPlot["ElectronRelIsolation"] = new MultiSamplePlot(datasets, "ElectronRelIsolation", 10, 0, .25, "RelIso");
MSPlot["ElectronPt"] = new MultiSamplePlot(datasets, "ElectronPt", 30, 0, 300, "PT_{e}");
MSPlot["ElectronEta"] = new MultiSamplePlot(datasets, "ElectronEta", 40,-4, 4, "Jet #eta");
MSPlot["NbOfElectronsPreSel"] = new MultiSamplePlot(datasets, "NbOfElectronsPreSel", 10, 0, 10, "Nb. of electrons");
//Init Electron Plots
MSPlot["InitElectronPt"] = new MultiSamplePlot(datasets, "InitElectronPt", 30, 0, 300, "PT_{e}");
*/
///////////////////
// 1D histograms //
///////////////////
map <string,TH1F*> histo1D;
std::string titlePlot = "";
titlePlot = "cutFlow"+channelpostfix;
histo1D["h_cutFlow"] = new TH1F(titlePlot.c_str(), "cutflow", 13,-0.5,12.5);
///////////////////
// 2D histograms //
///////////////////
// histo2D["HTLepSep"] = new TH2F("HTLepSep","dR_{ll}:HT",50,0,1000, 20, 0,4);
//Plots
//string pathPNG = "MSPlots_FourTop"+postfix+channelpostfix;
// pathPNG += "_MSPlots/";
// pathPNG = pathPNG +"/";
// mkdir(pathPNG.c_str(),0777);
// -------------------------
// bo defining cuts value --
// -------------------------
// think to do it in a loop as it will be faster and much less error prompt
// electron
float el_pt_cut = 42.; // 42
float el_eta_cut = 2.4; // 2.4
//float el_d0_cut = 0.02; // 0.02
float el_d0_cut = 10.0; // 0.02
float el_relIsoB_cut = 0.0354;
float el_relIsoEC_cut = 0.0646;
// muon
float mu_pt_cut = 40.; // 40
float mu_eta_cut = 2.4; // 2.4
float mu_iso_cut = 0.15; // 0.15
//float mu_d0_cut = 0.02; //0.02
float mu_d0_cut = 10.0; //0.02
// change value depending on the trigger
if (elel){
el_pt_cut=42.;
}
else if (mumu){
mu_pt_cut=35.;
}
else if (elmu){
mu_pt_cut=40.;
el_pt_cut=42.;
}
else if (bbel){
el_pt_cut=42.;
}
else if (bbmu){
mu_pt_cut=35.;
}
else if (ttelel){
el_pt_cut=0.1;
}
else if (ttmumu){
mu_pt_cut=0.1;
}
else{
cerr << "None of the channel bool was set to true!!! Exiting ... " << endl;
exit(1);
}
// convert into string
std::ostringstream el_pt_cut_strs, el_eta_cut_strs, el_d0_cut_strs, mu_pt_cut_strs, mu_eta_cut_strs, mu_iso_cut_strs, mu_d0_cut_strs;
std::string el_pt_cut_str, el_eta_cut_str, el_d0_cut_str, mu_pt_cut_str, mu_eta_cut_str, mu_iso_cut_str, mu_d0_cut_str;
el_pt_cut_strs << el_pt_cut;
el_eta_cut_strs << el_eta_cut;
el_d0_cut_strs << el_d0_cut;
mu_pt_cut_strs << mu_pt_cut;
mu_eta_cut_strs << mu_eta_cut;
mu_iso_cut_strs << mu_iso_cut;
mu_d0_cut_strs << mu_d0_cut;
el_pt_cut_str = el_pt_cut_strs.str();
el_eta_cut_str = el_eta_cut_strs.str();
el_d0_cut_str = el_d0_cut_strs.str();
mu_pt_cut_str = mu_pt_cut_strs.str();
mu_eta_cut_str = mu_eta_cut_strs.str();
mu_iso_cut_str = mu_iso_cut_strs.str();
mu_d0_cut_str = mu_d0_cut_strs.str();
// -------------------------
// eo defining cuts value --
// -------------------------
// check
vector<string> CutFlowPresel;
CutFlowPresel.push_back(string("initial"));
CutFlowPresel.push_back(string("ecal crack veto"));
CutFlowPresel.push_back(string("at least one good electron: pt $>$ "+el_pt_cut_str+", eta $<$ "+el_eta_cut_str));
CutFlowPresel.push_back(string("at least one good muon: pt $>$ "+mu_pt_cut_str+", eta $<$ "+mu_eta_cut_str+", iso $<$ "+mu_iso_cut_str));
CutFlowPresel.push_back(string("extra electron veto"));
CutFlowPresel.push_back(string("extra muon veto"));
CutFlowPresel.push_back(string("electron d0 $<$ "+el_d0_cut_str));
CutFlowPresel.push_back(string("muon d0 $<$ "+mu_d0_cut_str));
// CutFlowPresel.push_back(string("OS leptons"));
CutFlowPresel.push_back(string(""));
// CutFlowPresel.push_back(string("Non overlaping leptons"));
CutFlowPresel.push_back(string(" "));
SelectionTable CutFlowPreselTable(CutFlowPresel, datasets);
// CutFlowPreselTable.SetLuminosity(Luminosity);
CutFlowPreselTable.SetPrecision(1);
// ---------------------
// bo Synch cut flows --
// ---------------------
// start a new table (electrons only)
vector<string> CutFlow_oneEl;
CutFlow_oneEl.push_back(string("initial"));
CutFlow_oneEl.push_back(string("At least one electron with: pt $>$ "+el_pt_cut_str));
CutFlow_oneEl.push_back(string("ecal crack veto (!isEBEEGAP)"));
CutFlow_oneEl.push_back(string("electron with abs eta $<$ "+el_eta_cut_str));
CutFlow_oneEl.push_back(string("electron Id"));
CutFlow_oneEl.push_back(string("delta rho isolation"));
CutFlow_oneEl.push_back(string("electron d0 $<$ "+el_d0_cut_str));
SelectionTable CutFlow_oneElTable(CutFlow_oneEl, datasets);
// CutFlow_oneElTable.SetLuminosity(Luminosity);
CutFlow_oneElTable.SetPrecision(1);
// start a new table (muon only)
vector<string> CutFlow_oneMu;
CutFlow_oneMu.push_back(string("initial"));
CutFlow_oneMu.push_back(string("at least one muon with pt $>$ "+mu_pt_cut_str));
CutFlow_oneMu.push_back(string("muon with abs eta $<$ "+mu_eta_cut_str));
CutFlow_oneMu.push_back(string("muon id"));
CutFlow_oneMu.push_back(string("delta beta iso $<$ "+mu_iso_cut_str));
CutFlow_oneMu.push_back(string("muon d0 $<$ "+mu_d0_cut_str));
SelectionTable CutFlow_oneMuTable(CutFlow_oneMu, datasets);
// CutFlow_oneMuTable.SetLuminosity(Luminosity);
CutFlow_oneMuTable.SetPrecision(1);
// start a table (full synch)
vector<string> CutFlow;
CutFlow.push_back(string("initial"));
CutFlow.push_back(string("At least one electron with: pt $>$ "+el_pt_cut_str));
// CutFlow.push_back(string("ecal crack veto (!isEBEEGAP)"));
CutFlow.push_back(string("electron with abs eta $<$ "+el_eta_cut_str));
CutFlow.push_back(string("electron Id"));
CutFlow.push_back(string("delta rho isolation"));
CutFlow.push_back(string("at least one muon with pt $>$ "+mu_pt_cut_str));
CutFlow.push_back(string("muon with abs eta $<$ "+mu_eta_cut_str));
CutFlow.push_back(string("muon Id"));
CutFlow.push_back(string("delta beta iso $<$ "+mu_iso_cut_str));
CutFlow.push_back(string("extra electron veto"));
CutFlow.push_back(string("extra muon veto"));
CutFlow.push_back(string("electron d0 $<$ "+el_d0_cut_str));
CutFlow.push_back(string("muon d0 $<$ "+mu_d0_cut_str));
CutFlow.push_back(string("electron and muon with OS"));
CutFlow.push_back(string("electron-muon pair with deltaR $>$ 0.5"));
SelectionTable CutFlowTable(CutFlow, datasets);
// CutFlow_oneMuTable.SetLuminosity(Luminosity);
CutFlowTable.SetPrecision(1);
// ---------------------
// eo Synch cut flows --
// ---------------------
////////////////////////////
/// Initialise trigger ///
////////////////////////////
//Trigger* trigger = new Trigger(hasMuon, hasElectron, trigSingleLep, trigDoubleLep);
Trigger * trigger;
Trigger * crossTrigger;
if (channel=="ElEl"){
trigger = new Trigger(0, 1, 0, 1);
}
else if (channel=="MuMu"){
trigger = new Trigger(1, 0, 0, 1);
}
else if (channel=="ElMu"){
trigger = new Trigger(1, 1, 0, 1);
}
else if (channel=="bbEl"){
trigger = new Trigger(0, 1, 1, 0);
}
else if (channel=="bbMu"){
trigger = new Trigger(1, 0, 1, 0);
}
else if (channel=="ttElEl"){
trigger = new Trigger(0, 0, 0, 0);
crossTrigger = new Trigger (0, 1, 0, 1);
}
else if(channel=="ttMuMu"){
trigger = new Trigger(0, 0, 0, 0);
crossTrigger = new Trigger (1, 0, 0, 1);
}
else {
cout << endl << "------------------------------" << endl;
cout << "No triggger was booked because the channel provided (" << channel << ") does not match any of the expected channel!" << endl;
cout << "------------------------------" << endl << endl;
}
/////////////////////////////////
// Loop on datasets
/////////////////////////////////
cout << " - Loop over datasets ... " << datasets.size () << " datasets !" << endl;
for (unsigned int d = 0; d < datasets.size(); d++)
{
cout << "Load Dataset" << endl;
treeLoader.LoadDataset (datasets[d], anaEnv); //open files and load dataset
string previousFilename = "";
int iFile = -1;
bool nlo = false;
dataSetName = datasets[d]->Name();
if(dataSetName.find("bx50") != std::string::npos) bx25 = false;
else bx25 = true;
if(dataSetName.find("NLO") != std::string::npos || dataSetName.find("nlo") !=std::string::npos) nlo = true;
else nlo = false;
if(bx25) cout << "Dataset with 25ns Bunch Spacing!" <<endl;
else cout << "Dataset with 50ns Bunch Spacing!" <<endl;
if(nlo) cout << "NLO Dataset!" <<endl;
else cout << "LO Dataset!" << endl;
cout <<"found sample with equivalent lumi "<< theDataset->EquivalentLumi() <<endl;
TTree * booktup = new TTree("bookkeeping", "bookkeeping");
long long runId = 0; booktup -> Branch("Runnr",&runId,"Runnr/I");
long long evId = 0; booktup -> Branch("Eventnr",&evId,"Evnr/I");
long long lumBlkId = 0; booktup -> Branch("Lumisec",&lumBlkId,"Lumisec/I");
long long nPV = 0; booktup -> Branch("nPV",&nPV,"nPV/I");
std::string tag = "v6(7)DispDLSLPrompt"; booktup -> Branch("Tag",&tag);
/// book triggers
if (applyTriggers) {
trigger->bookTriggers(isData);
// only if ttbarenriched we had the cross trigger
if (ttbarEnriched) crossTrigger->bookTriggers(isData);
}
// Lumi scale
Bool_t applyLumiScale = false;
double lumiScale = -99.;
/*
if (isData || !applyLumiScale) {
cout << "Lumi scale is not applied!! " << endl << endl;
if (debug){
cout << "isData is " << isData << endl;
cout << "applyLumiScale is " << !applyLumiScale << endl;
}
lumiScale = 1. ;
}
else {
lumiScale = Luminosity*xSect/datasets[d]->NofEvtsToRunOver();
cout << "dataset has equilumi = " << datasets[d]->EquivalentLumi() << endl;
cout << "the weight to apply for each event of this data set is " << "Lumi * (xs/NSample) --> " << Luminosity << " * (" << xSect << "/" << datasets[d]->NofEvtsToRunOver() << ") = " << Luminosity*xSect/datasets[d]->NofEvtsToRunOver() << endl;
}
*/
//////////////////////////////////////////////
// Setup Date string and nTuple for output //
//////////////////////////////////////////////
time_t t = time(0); // get time now
struct tm * now = localtime( & t );
int year = now->tm_year + 1900;
int month = now->tm_mon + 1;
int day = now->tm_mday;
int hour = now->tm_hour;
int min = now->tm_min;
int sec = now->tm_sec;
string year_str;
string month_str;
string day_str;
string hour_str;
string min_str;
string sec_str;
ostringstream convert; // stream used for the conversion
convert << year; // insert the textual representation of 'Number' in the characters in the stream
year_str = convert.str();
convert.str("");
convert.clear();
convert << month; // insert the textual representation of 'Number' in the characters in the stream
month_str = convert.str();
convert.str("");
convert.clear();
convert << day; // insert the textual representation of 'Number' in the characters in the stream
day_str = convert.str();
convert.str("");
convert.clear();
convert << hour; // insert the textual representation of 'Number' in the characters in the stream
hour_str = convert.str();
convert.str("");
convert.clear();
convert << min; // insert the textual representation of 'Number' in the characters in the stream
min_str = convert.str();
convert.str("");
convert.clear();
convert << day; // insert the textual representation of 'Number' in the characters in the stream
sec_str = convert.str();
convert.str("");
convert.clear();
string date_str = day_str + "_" + month_str + "_" + year_str;
cout <<"DATE STRING "<<date_str << endl;
// bo of the main Tree
// trigger variables
std::array<Int_t,200> triggers_container;
// variables for electrons
Int_t nElectrons;
Double_t pt_electron[10];
Double_t phi_electron[10];
Double_t eta_electron[10];
Double_t eta_superCluster_electron[10];
Double_t E_electron[10];
Double_t vz_electron[10];
Double_t v0_electron[10];
// Double_t v0BeamSpot_electron[10];
Double_t d0_electron[10];
Double_t d0BeamSpot_electron[10];
Double_t chargedHadronIso_electron[10];
Double_t neutralHadronIso_electron[10];
Double_t photonIso_electron[10];
Double_t pfIso_electron[10];
Double_t relIso_electron[10];
Int_t charge_electron[10];
//bo id related variables
Double_t sigmaIEtaIEta_electron[10];
Double_t deltaEtaIn_electron[10];
Double_t deltaPhiIn_electron[10];
Double_t hadronicOverEm_electron[10];
Int_t missingHits_electron[10];
Bool_t passConversion_electron[10];
// eo id realted variables
Bool_t isId_electron[10];
Bool_t isIso_electron[10];
Bool_t isEBEEGap[10];
Double_t sf_id_down_electron[10];
Double_t sf_id_electron[10];
Double_t sf_id_up_electron[10];
Double_t sf_reco_down_electron[10];
Double_t sf_reco_electron[10];
Double_t sf_reco_up_electron[10];
Double_t sf_electron[10];
// variables for electronPairs
Int_t nElectronPairs; // if there is n electrons there is (n*n - n)/2 distinct pairs
Double_t deltaVz_elel[10]; // max 5 electrons -> max (25 -5)/2 = 10 electronPairs
Double_t deltaV0_elel[10];
Double_t deltaR_elel[10];
Double_t invMass_elel[10];
// variables for muons
Int_t nMuons;
Double_t pt_muon[10];
Double_t phi_muon[10];
Double_t eta_muon[10];
Double_t E_muon[10];
Double_t vz_muon[10];
Double_t v0_muon[10];
Double_t d0_muon[10];
Double_t d0BeamSpot_muon[10];
Double_t chargedHadronIso_muon[10];
Double_t neutralHadronIso_muon[10];
Double_t photonIso_muon[10];
Double_t pfIso_muon[10];
Double_t relIso_muon[10];
Int_t charge_muon[10];
Bool_t isId_muon[10];
Bool_t isIso_muon[10];
Double_t sf_iso_down_muon[10];
Double_t sf_iso_muon[10];
Double_t sf_iso_up_muon[10];
Double_t sf_id_down_muon[10];
Double_t sf_id_muon[10];
Double_t sf_id_up_muon[10];
Double_t sf_muon[10];