-
Notifications
You must be signed in to change notification settings - Fork 0
/
SusyAna_smearing.cc
1959 lines (1695 loc) · 94.5 KB
/
SusyAna_smearing.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- C++ -*-
#define SusyAna_smearing_cxx
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <utility>
#include "SusyAna_smearing.h"
#include "SusyEventPrinter.h"
#include "../jec/JetMETObjects/interface/JetCorrectorParameters.h"
#include "../jec/JetMETObjects/interface/FactorizedJetCorrector.h"
//my additions
#include "TAxis.h"
#include "TMath.h"
#include <TH3.h>
#include "TFile.h"
#include "TTree.h"
#include "TLegend.h"
#include "TLorentzVector.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include <iostream>
#include <fstream>
#include <string.h>
//user defiend
#include "utilities.h"
#include "cuts.h"
#include "params_arg.h"
//#include "GetError.h"
#include "hggx_analysers.h"
#include "quicksave.C"
#include "CMSStyle.C"
#include "TVector3.h"
#include "TLorentzVector.h"
#include "SFb.h"
#include "SFl.h"
#include "BTagWeight5.h"
#include <time.h>
#include "MCpoint.h"
using namespace std;
using namespace params;
template<typename T> bool EtGreater(const T* p1, const T* p2) {
return (p1->momentum.Et() > p2->momentum.Et());
}
template<typename T> bool EtGreaterpho(const T* p1, const T* p2) {
if(useMVAphoP) return ((p1->MVAregEnergyAndErr.first / p1->momentum.E())*p1->momentum).Et() > ((p2->MVAregEnergyAndErr.first / p2->momentum.E())*p2->momentum).Et();
else return p1->momentum.Et() > p2->momentum.Et();
}
void SusyAna_smearing::InitializePerEvent() {
}
bool SusyAna_smearing::isSameObject(TLorentzVector& p1, TLorentzVector& p2) {
float dEta = p1.Eta() - p2.Eta();
float dPhi = TVector2::Phi_mpi_pi(p1.Phi() - p2.Phi());
return std::sqrt(dEta*dEta + dPhi*dPhi) <= 0.6 || fabs(dPhi) <= 0.05; //dMorse as of April2013
//return std::sqrt(dEta*dEta + dPhi*dPhi) < 0.5;
}//dR05 cut
float SusyAna_smearing::d0correction(TVector3& beamSpot, susy::Track& track) const {
return track.d0() - beamSpot.X()*std::sin(track.phi()) + beamSpot.Y()*std::cos(track.phi());
}
bool SusyAna_smearing::PassTrigger(TString path) {
//Does not have to be an exact name. the trigger name must contain "path". So you can ignore the trigger version.
bool pass = false;
for(susy::TriggerMap::iterator it = event->hltMap.begin(); it != event->hltMap.end(); it++) {
if(it->first.Contains(path) && (int(it->second.second)) ) {
pass = true;
break;
}
}
return pass;
}
bool SusyAna_smearing::PassTriggers() {
bool pass = false;
for(std::vector<TString>::iterator it = hltNames.begin(); it != hltNames.end(); it++) {
if(PassTrigger(*it)) {
pass = true;
break;
}
}
return pass;
}
typedef std::map<string,int> nameint;
typedef std::map<string,float> namefloat;
typedef std::map<string,bool> namebool;
typedef std::map<string,string> labels;
typedef std::map<string,TH1F*> LabelHist;
typedef std::map<string,LabelHist> Label2Hist;
typedef std::map<string,TH1F**> LabelHistArr;
typedef std::map<string,LabelHistArr> Label2HistArr;
void addCounter(nameint & C, vector<string> & V, string Label){
C[Label]=0;
V.push_back(Label);
}
void remove_duplicate_photons(std::vector<susy::Photon*> & photons,bool keep_hardest_matched_photon=true){
/*
This takes a pt-sorted vector of Photon*. It looks through all pairs of photons, for dR matches (dR<0.6 or dPhi < 0.05)
If it finds a match and keep_hardest_matched_photon, it keeps the hardest one and deletes the others from the vector.
If it finds a match and !keep_hardest_matched_photon, it deletes all photons involved int the match. David Morse and I do the former.
*/
if (photons.size()<2) return;
std::vector<susy::Photon*>::iterator i_p1 = photons.begin(); int I_p1 = 0;
//cout<<"enter remove_duplicate_photons. Size = "<<photons.size()<<endl;
//cout<<"photon end: "<<*photons.end()<<" i_p1+1: "<<*(i_p1+1)<<endl;
int size = photons.size();
while(I_p1+1 < size){
//while(i_p1+1 != photons.end()){
bool match_found = false;
//cout<<"phoA. i="<<I_p1<<" "<<*i_p1<<endl;
TLorentzVector p1 = (useMVAphoP?(*i_p1)->MVAregEnergyAndErr.first / (*i_p1)->momentum.E():1.0)*(*i_p1)->momentum;
//TLorentzVector p1 = useMVAphoP?(*i_p1)->MVAcorrMomentum:(*i_p1)->momentum;
//TLorentzVector p1 = (*i_p1)->momentum;
std::vector<susy::Photon*>::iterator i_p2 = i_p1+1; int I_p2 = I_p1+1;
while(I_p2 < size){ //increments to the terminator, then does not terminate.
//while(i_p2 != photons.end()){ //increments to the terminator, then does not terminate.
//cout<<"phoB, i= "<<I_p2<<" "<<*i_p2<<endl;
//TLorentzVector p2 = (*i_p2)->momentum;
TLorentzVector p2 = (useMVAphoP?(*i_p2)->MVAregEnergyAndErr.first / (*i_p2)->momentum.E():1.0)*(*i_p2)->momentum;
//TLorentzVector p2 = useMVAphoP?(*i_p2)->MVAcorrMomentum:(*i_p2)->momentum;
//cout<<"rem4"<<endl;
if (dR(p1,p2)<0.6 || dPhi(p1,p2) < 0.05 ) {
std::vector<susy::Photon*>::iterator temp = i_p2+1;
i_p2 = photons.erase(i_p2);//this is supposed to return the next element but does not.
//cout<<"found match phoB new address: "<<*i_p2<<endl;
i_p2 = temp;
//cout<<"after =temp, address: "<<*i_p2<<endl;
size--;
match_found = true;
if(I_p2 == (int) photons.size()-1) break;
}
else{ i_p2++; I_p2++;}
}//end while2
if (match_found && !keep_hardest_matched_photon) {
i_p1 = photons.erase(i_p1);
}
else {i_p1++; I_p1++;}
}//end while
}//end remove_duplicate_photons
void PrintPhotonTriggers(susy::Event* event){
for(susy::TriggerMap::iterator it = event->hltMap.begin(); it != event->hltMap.end(); it++) {
if (it->first.Contains("Photon")) {
std::cout << "\t" << it->first << "(prescale=" << it->second.first << ", fire=" << int(it->second.second) << ")" << std::endl;
}
}
}
void SusyAna_smearing::Loop() {
ofstream firealarm;
bool onfire = false;
firealarm.open("tmpfirealarm.txt");
firealarm << "SusyAna_smearing is on FIRE"<<endl;
firealarm.close();
///////////////////////////////////////////////////////
int pl = 2;//print level
//0 = Stealth
//1 = Annouce birth, death, marriage, and explosions
//2 = Christmas and easter only; turn on 1000th event heart monitor, Normal for running
//3 = Casual: Tick off major blocks and probe suspicious lines
//***Begin compartmentalizing the verbosity with print blocks***
//4 = Currious: Tick off minor blocks
//5 = Probe loops 1 level deep and chosen significant lines
//6 = Probe loops 2 levels deep
//7 = Probe loops 3+ levels deep
//8 = Paranoid: Probe every significant operation that looks like it could fail
//9 = FBI Colonoscopy: Probe every operation, even if it's unlikely that it'll fail
//10= Hyperbarf: Print a probe after every line
// ...
//11= ALICE: Blast it's atoms appart and examine the entrails
///PRINT BLOCK SWITCHES
bool pbUSloop = 0;
bool pbColloop = 0;
bool pbMainLoop = 0;
bool pbMainLoopInit = 0 && pbMainLoop;
bool pbPhos = 0 && pbMainLoop;
bool pbVtx = 0 && pbMainLoop;
bool pbMu = 0 && pbMainLoop;
bool pbEle = 0 && pbMainLoop;
bool pbJets = 0 && pbMainLoop;
bool pbBJets = 0 && pbMainLoop;
bool pbMET = 0 && pbMainLoop;
bool pbCuts = 0 && pbMainLoop;
bool pbFill = 0 && pbMainLoop;
bool pbFinisUp = 1;
///////////////////////////////////////////////////////
int nKinemVars = (bumpJEC == 0 && bumpBtagEff ==0)?nKinemVars_all: nKinemVars_limit;
string *s_KinemVars = (bumpJEC == 0 && bumpBtagEff ==0)?s_KinemVars_all: s_KinemVars_limit;
string s_forTopo[nEventTopologies];
//s_forTopo[0]="";
for (int iTopo=0; iTopo<nEventTopologies; iTopo++){ //xxx may have to change this line back.
s_forTopo[iTopo]=string(" for ")+s_EventTopology[iTopo];
}
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntries();
if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries;
std::cout << "total events in files : " << nentries << std::endl;
std::cout << "events to be processed : " << processNEvents << std::endl;
//Initialize Counters
if(pl > 0) std::cout << "Initialize event counters." << std::endl;
vector <string> Counter_order;
nameint Counters;
addCounter(Counters,Counter_order,"no cuts");
//addCounter(Counters,Counter_order,"pass Json");
//addCounter(Counters,Counter_order,"pass duplicate check");
addCounter(Counters,Counter_order,"pass HLT");
//addCounter(Counters,Counter_order,"pass MET Filter");
addCounter(Counters,Counter_order,"have 2 loose photons");
//addCounter(Counters,Counter_order,"have 2 tight photons");
//addCounter(Counters,Counter_order,"have 2 tight photons passing dR cuts");
addCounter(Counters,Counter_order,"pass a primary vertex reqirement");
addCounter(Counters,Counter_order,"has met map");
addCounter(Counters,Counter_order,"number filtered");
addCounter(Counters,Counter_order,"ready for physics");
addCounter(Counters,Counter_order,"pass 2JbMLgbar2");
addCounter(Counters,Counter_order,"have match");
addCounter(Counters,Counter_order,"eta0_lowr9");
addCounter(Counters,Counter_order,"eta1_lowr9");
addCounter(Counters,Counter_order,"eta2_lowr9");
addCounter(Counters,Counter_order,"eta3_lowr9");
addCounter(Counters,Counter_order,"eta0_hir9");
addCounter(Counters,Counter_order,"eta1_hir9");
addCounter(Counters,Counter_order,"eta2_hir9");
addCounter(Counters,Counter_order,"eta3_hir9");
//no extra cuts.
/* for (int iTopo=0; iTopo<nEventTopologies; iTopo++) {
addCounter(Counters,Counter_order,string("are in tag region")+s_forTopo[iTopo]);
addCounter(Counters,Counter_order,string("are in sb region")+s_forTopo[iTopo]);
addCounter(Counters,Counter_order,string("are in usb region")+s_forTopo[iTopo]);
addCounter(Counters,Counter_order,string("are in lsb region")+s_forTopo[iTopo]);
}*/
TH1I *lsb_int = new TH1I("lsb_int","lower side band integrals",nEventTopologies,0,nEventTopologies);
TH1I *usb_int = new TH1I("usb_int","lower side band integrals",nEventTopologies,0,nEventTopologies);
//order:keeps the order of the s_EventTopology array in params.
int nFiltered = 0;
TTree* filterTree = 0;
//cout << "enableFilter is set to "<<enableFilter<<endl;
MCpoint* thisMCpoint = setupMCpoint(which_MC_to_use2);
/* if(enableFilter) {
cout <<endl<< "Making Filter File"<< outroot_data<<endl<<endl;
TFile* filterFile = new TFile("MCskim_2JbML_mst210_mho_150.root","RECREATE");
//TFile* filterFile = new TFile(thisMCpoint->outroot_mc.c_str(),"RECREATE");
filterTree = (TTree*) fChain->GetTree()->CloneTree(0);
filterTree->SetAutoSave();
}*/
ofstream eventlist;
if(makeEventsList) eventlist.open ("mcSmeraing_eventlist.txt");
ofstream tmvaOut;
//if(makeTMVAlist) tmvaOut.open ("tmva_signal_MC.txt");
//Set the first line to be the var names:
//format:
//TotEt/F:dPhi/F:METdPhiLead/F:METdPhiTrail/F:AlphaT/F:PhotonLessHT/F:DiEMPt/F:InvarMass/F:Met/F:MR/F
//if(makeTMVAlist) tmvaOut<<"MET/F:ST/F:HT/F:Bt/F:MHT/F:PtGG/F:EtaGG/F:phoPt0/F:phoPt1/F:phoEta0/F:phoEta1/F:phoEtaMax/F:phoEtaMin/F:nJets/I:nBjets/I:bestMjj/F:nLep/I:nMu/I:nEle/I:Mleplep/F:MTpho0MET/F:MTpho1MET/F:cosThetaStar/F:phoDPhi/F:dPhiPho0Met/F:dPhiPho1Met/F:dijetDEta01/F:dijetEta01/F:dijetDPhi01/F:dijetM01/F:dijetPt01/F:dPhiJet0Met/F:dPhiJet1Met/F"<<endl;
//load in histograms of b-tag efficiency.
TFile * BTagEff_file = new TFile(thisMCpoint->btageff_file.c_str(),"READ");//file full of histograms with b-tag efficiencies.
BTagEff_file->cd();
TH1F* h_BTagEff[3];
TH1F* h_BMisTagEff[3];
h_BTagEff[0] = (TH1F*)BTagEff_file->Get("bjetEff_CSVL");
h_BTagEff[1] = (TH1F*)BTagEff_file->Get("bjetEff_CSVM");
h_BTagEff[2] = (TH1F*)BTagEff_file->Get("bjetEff_CSVT");
h_BMisTagEff[0] = (TH1F*)BTagEff_file->Get("bMistag_CSVL");
h_BMisTagEff[1] = (TH1F*)BTagEff_file->Get("bMistag_CSVM");
h_BMisTagEff[2] = (TH1F*)BTagEff_file->Get("bMistag_CSVT");
// open hist file and define histograms
cout <<endl<< "Writing to Plots File "<<thisMCpoint->plotsroot_mc<<endl<<endl;
TFile* fout = new TFile("mcSmeraing.root","RECREATE");
fout->cd();
ofstream logfile;
logfile.open("mcSmeraing.log");
TH1F* h_vtxZ_unsliced = new TH1F("vtxZ_unsliced","Z position of the primary vertex;Z (cm);Events",100,-50.0,50.0);
TH1F* h_bsZ_unsliced = new TH1F("bsZ_unsliced","Z position of the beam spot;Z (cm);Events",100,-50.0,50.0);
//nameint nbins;
//namefloat hmin;
//namefloat hmax;
//labels xlabels;
//labels titles;
if(pl>=3)printf("Setup Kinematic Vars\n");
LabelKinVars KinVars = setupKinematicVar(); //setup all the binning and histogram info printf("worked!\n");
namebool topoCut;
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) topoCut[s_EventTopology[iTopo]] = false;
namefloat WeightForTopo;
namefloat SFbForTopo;
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) SFbForTopo[s_EventTopology[iTopo]] = 1.0;
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) WeightForTopo[s_EventTopology[iTopo]] = 1.0;
//no extra selection.
LabelHist lh_mGG_unsliced;
Label2Hist lh_unsliced;
Label2HistArr lha2;
if(pl>=4) printf("enter unsliced producer loop\n");
//make all the unsliced plots.
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) {
if(pbUSloop && pl>=5) cout<<"topo "<<iTopo<<endl;
lh_mGG_unsliced[s_EventTopology[iTopo]] = new TH1F(
(char*)(string("h_mGG")+s_EventTopology[iTopo]+"_unsliced").c_str(),
(char*)(string("Di Photon Mass Sectrum")+s_forTopo[iTopo]+";M^{#gamma #gamma} (GeV)").c_str(),
PhoMassNBins,PhoMassMin,PhoMassMax);
if(pbUSloop && pl>=8) m(1);
LabelHist tmpMapKinVar; if(pbUSloop && pl>=10) m(2);
for (int kKinVar = 0; kKinVar<nKinemVars_all; kKinVar++) {
if(pbUSloop && pl>=6) cout<<"kinvar "<<kKinVar<< " "<< s_KinemVars_all[kKinVar]<< endl;
if(KinVars[s_KinemVars_all[kKinVar]]->useCustomBinning){
if(pbUSloop && pl>=8) cout<<"going with custom binning"<<endl;;
if(pbUSloop && pl>=8) cout<<"-going with custom binning"<<endl;;
tmpMapKinVar[s_KinemVars_all[kKinVar]] = new TH1F(
(char*)(string("h_")+s_KinemVars_all[kKinVar]+s_EventTopology[iTopo]+"_unsliced").c_str(),
(char*)(KinVars[s_KinemVars_all[kKinVar]]->titles+s_forTopo[iTopo]+";"+KinVars[s_KinemVars_all[kKinVar]]->xlabels).c_str(),
KinVars[s_KinemVars_all[kKinVar]]->nbins,
KinVars[s_KinemVars_all[kKinVar]]->CustomBinning);
if(pbUSloop && pl>=8) m(31);
if(pbUSloop && pl>=8) m(31);
}
else{
if(pbUSloop && pl>=8) cout<<"Going with auto binning"<<endl;;
if(pbUSloop && pl>=8) cout<<"-Going with auto binning"<<endl;;
tmpMapKinVar[s_KinemVars_all[kKinVar]] = new TH1F(
(char*)(string("h_")+s_KinemVars_all[kKinVar]+s_EventTopology[iTopo]+"_unsliced").c_str(),
(char*)(KinVars[s_KinemVars_all[kKinVar]]->titles+s_forTopo[iTopo]+";"+KinVars[s_KinemVars_all[kKinVar]]->xlabels).c_str(),
KinVars[s_KinemVars_all[kKinVar]]->nbins,
KinVars[s_KinemVars_all[kKinVar]]->hmin,
KinVars[s_KinemVars_all[kKinVar]]->hmax);
if(pbUSloop && pl>=8) m(3);
if(pbUSloop && pl>=8) m(3);
}
if(pbUSloop && pl>=8) printf("out of if\n");
//tmpMapKinVar[s_KinemVars[kKinVar]] = new TH1F(
//(char*)(string("h_")+s_KinemVars[kKinVar]+s_EventTopology[iTopo]+"_unsliced").c_str(),
//(char*)(titles[s_KinemVars[kKinVar]]+s_forTopo[iTopo]+";"+xlabels[s_KinemVars[kKinVar]]).c_str(),
//nbins[s_KinemVars[kKinVar]],
//hmin[s_KinemVars[kKinVar]],
//hmax[s_KinemVars[kKinVar]]);
}//end for every kinematic varriable.
if(pbUSloop && pl>=9) m(4);
lh_unsliced[s_EventTopology[iTopo]] = tmpMapKinVar; if(pbUSloop && pl>=9) m(5);
}//end for every topology
if(pl>=4) cout<<"fin making unsliced plots, make collections\n";
if(pl>=4) cout<<"-fin making unsliced plots, make collections\n";
//make the collections.
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) {
if(pbColloop && pl>=5) m(7);
LabelHistArr tmpMapKinVar;
for (int kKinVar = 0; kKinVar<nKinemVars_all; kKinVar++) {
tmpMapKinVar[s_KinemVars_all[kKinVar]] = new TH1F*[nPhoMassAndBkgDists];
if(KinVars[s_KinemVars_all[kKinVar]]->useCustomBinning){
MakeHistSet(tmpMapKinVar[s_KinemVars_all[kKinVar]],
s_KinemVars_all[kKinVar]+s_EventTopology[iTopo],
KinVars[s_KinemVars_all[kKinVar]]->nbins,
KinVars[s_KinemVars_all[kKinVar]]->CustomBinning);
}
else{
MakeHistSet(tmpMapKinVar[s_KinemVars_all[kKinVar]],
s_KinemVars_all[kKinVar]+s_EventTopology[iTopo],
KinVars[s_KinemVars_all[kKinVar]]->nbins,
KinVars[s_KinemVars_all[kKinVar]]->hmin,
KinVars[s_KinemVars_all[kKinVar]]->hmax);
}
//MakeHistSet(tmpMapKinVar[s_KinemVars[kKinVar]],
//s_KinemVars[kKinVar]+s_EventTopology[iTopo],
//nbins[s_KinemVars[kKinVar]],
//hmin[s_KinemVars[kKinVar]],
//hmax[s_KinemVars[kKinVar]]);
}//end for every kinvar
lha2[s_EventTopology[iTopo]] = tmpMapKinVar;
}//end for every Topo,
if(pl>=4) printf("fin making collections, declare selvar hists\n");
//end make create histograms
//plots of things I cut on.
//////////////////////////////////////////////////////////////
///////////////////// OBJECT SELECTION VARS /////////////////
int nbinsSmearing = 180;
float Smearingxlow = -0.2;
float Smearingxhi = 0.2;
TH1F* smearing_eta0_lowr9 = new TH1F("smearing_eta0_lowr9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta1_lowr9 = new TH1F("smearing_eta1_lowr9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta2_lowr9 = new TH1F("smearing_eta2_lowr9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta3_lowr9 = new TH1F("smearing_eta3_lowr9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta0_hir9 = new TH1F("smearing_eta0_hir9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta1_hir9 = new TH1F("smearing_eta1_hir9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta2_hir9 = new TH1F("smearing_eta2_hir9","",nbinsSmearing,Smearingxlow,Smearingxhi);
TH1F* smearing_eta3_hir9 = new TH1F("smearing_eta3_hir9","",nbinsSmearing,Smearingxlow,Smearingxhi);
//PHOTONS
TH1F* pho_Et_0 = new TH1F("pho_Et_0","Leading Photon Pt;E_{t}^{#gamma}",200,0.,200.);
TH1F* pho_Et_1 = new TH1F("pho_Et_1","Subleading Photon Pt;E_{t}^{#gamma}",200,0.,200.);
TH1F* pho_Et_2 = new TH1F("pho_Et_2","Sub-sub-leading Photon Pt;E_{t}^{#gamma}",200,0.,200.);
TH1F* selvar_pho_nPho = new TH1F("selvar_pho_nPho","number of tight photons;n photons", 10,0.,10.);
TH1F* selvar_pho_Et = new TH1F("selvar_pho_Et","selvar_pho_Et;E_{t}^{#gamma}", 200,0.,200);
TH1F* selvar_pho_Eta= new TH1F("selvar_pho_Eta","selvar_pho_Eta;#gamma #eta", 100,-2.5,2.5);
TH1F* selvar_pho_Phi= new TH1F("selvar_pho_Phi","selvar_pho_Phi;#gamma #phi", 60,0.,3.15);
TH1F* selvar_pho_TrkIsoDR04= new TH1F("selvar_pho_TrkIsoDR04","selvar_pho_TrkIsoDR04;TrackIsoDR04", 32,-1.,7.);
TH1F* selvar_pho_EcalIsoDR04= new TH1F("selvar_pho_EcalIsoDR04","selvar_pho_EcalIsoDR04;EcalIsoDR04", 34,-2.,15.);
TH1F* selvar_pho_HcalIsoDR04= new TH1F("selvar_pho_HcalIsoDR04","selvar_pho_HcalIsoDR04;HCalIsoDR04", 32,-1.,7.);
TH1F* selvar_pho_TrkIsoDR03= new TH1F("selvar_pho_TrkIsoDR03","selvar_pho_TrkIsoDR03;TrackIsoDR03", 32,-1.,7.);
TH1F* selvar_pho_EcalIsoDR03= new TH1F("selvar_pho_EcalIsoDR03","selvar_pho_EcalIsoDR03;EcalIsoDR03", 34,-2.,15.);
TH1F* selvar_pho_HcalIsoDR03= new TH1F("selvar_pho_HcalIsoDR03","selvar_pho_HcalIsoDR03;HcalIsoDR03", 32,-1.,7.);
TH1F* selvar_pho_HE= new TH1F("selvar_pho_HE","selvar_pho_HE;H/E", 110,-0.01,0.1);
TH1F* selvar_pho_R9= new TH1F("selvar_pho_R9","selvar_pho_R9;R9", 150,-0.1,1.4);
TH1F* selvar_pho_sinin_bar= new TH1F("selvar_pho_sinin_bar","selvar_pho_sinin_bar;#sigma_{i #eta i #eta}", 140,0.,0.014);
TH1F* selvar_pho_sipip_bar= new TH1F("selvar_pho_sipip_bar","selvar_pho_sipip_bar;#sigma_{i #phi i #phi}", 0,0.,0.);
TH1F* selvar_pho_sinin_ec= new TH1F("selvar_pho_sinin_ec","selvar_pho_sinin_ec;#sigma_{i #eta i #eta}", 130,0.025,0.038);
TH1F* selvar_pho_sipip_ec= new TH1F("selvar_pho_sipip_ec","selvar_pho_sipip_ec;#sigma_{i #phi i #phi}", 0,0.,0.);
TH1F* selvar_pho_nPixelSeeds= new TH1F("selvar_pho_nPixelSeeds","selvar_pho_nPixelSeeds;n pixel seeds", 11,-1.,10.);
TH1F* selvar_pho_rho= new TH1F("selvar_pho_rho","selvar_pho_rho;rho25", 80,0.,40.);
TH1F* selvar_pho_PFcargedHadIso= new TH1F("selvar_pho_PFcargedHadIso","selvar_pho_PFcargedHadIso;PFcargedHadIso", 32,-1.,7.);
TH1F* selvar_pho_PFneutralHadIso= new TH1F("selvar_pho_PFneutralHadIso","selvar_pho_PFneutralHadIso;PFneutralHadIso", 32,-1.,7.);
TH1F* selvar_pho_PFphoIso= new TH1F("selvar_pho_PFphoIso","selvar_pho_PFphoIso;PFphoIso", 34,-1.,15.);
TH1F* selvar_pho_ChargeSafeEleVeto = new TH1F("selvar_pho_ChargeSafeEleVeto","ChargeSafeEleVeto",2,0.,2.);
/* TH2F* selvar_pho_TrkIso04_v_rho[7];
TH2F* selvar_pho_ECalIso04_v_rho[7];
TH2F* selvar_pho_ECalIso04_v_rho[7];
TH2F* selvar_pho_TrkIso03_v_rho[7];
TH2F* selvar_pho_ECalIso03_v_rho[7];
TH2F* selvar_pho_ECalIso03_v_rho[7];
TString regions[7] = {"<1", "1 - 1.479", "1.479 - 2", "2 - 2.2", "2.2 - 2.3", "2.3 - 2.4", ">2.4"};
for (int i=0; i<7; i++) {
selvar_pho_TrkIso04_v_rho[i] = new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
selvar_pho_ECalIso04_v_rho[7]= new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
selvar_pho_ECalIso04_v_rho[7]= new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
selvar_pho_TrkIso03_v_rho[7]= new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
selvar_pho_ECalIso03_v_rho[7]= new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
selvar_pho_ECalIso03_v_rho[7]= new TH1F("selvar_pho_TrkIso04_v_rho_"+i,"photon TrkIso04_v_rho for eta "+regions[i],140,-5.,30.,60,0.,30.);
}*/
//ELECTRONS
TH1F* selvar_ele_nele = new TH1F("selvar_ele_nele","selvar_ele_nele;n ele", 10,0.,10.);
TH1F* selvar_ele_Et = new TH1F("selvar_ele_Et","selvar_ele_Et;electron E_{t}", 200,0.,200);
TH1F* selvar_ele_Eta= new TH1F("selvar_ele_Eta","selvar_ele_Eta;ele #eta", 100,-2.5,2.5);
TH1F* selvar_ele_Phi= new TH1F("selvar_ele_Phi","selvar_ele_Phi;ele #phi", 60,0.,3.15);
TH1F* selvar_ele_relIso = new TH1F("selvar_ele_relIso","selvar_ele_relIso;ele relIso", 105,-0.1,2.);
// TH1F* selvar_ele_passMVAPreselect = new TH1F("selvar_ele_passMVAPreselect","selvar_ele_passMVAPreselect", 2,0.,2.);
// TH1F* selvar_ele_isPF = new TH1F("selvar_ele_isPF","selvar_ele_isPF", 2,0.,2.);
// TH1F* selvar_ele_d0 = new TH1F("selvar_ele_d0","selvar_ele_d0", 200,0.,20);
// TH1F* selvar_ele_dz_pVtxZ = new TH1F("selvar_ele_dz_pVtxZ","selvar_ele_dz_pVtxZ", 80,0.,20.);
//MUONS
TH1F* selvar_mu_nmu = new TH1F("selvar_mu_nmu","selvar_mu_nmu;n muons", 10,0.,10.);
TH1F* selvar_mu_Et = new TH1F("selvar_mu_Et","selvar_mu_Et;muon E_{t}", 200,0.,200);
TH1F* selvar_mu_Eta= new TH1F("selvar_mu_Eta","selvar_mu_Eta;muon #eta", 100,-2.5,2.5);
TH1F* selvar_mu_Phi= new TH1F("selvar_mu_Phi","selvar_mu_Phi;muon #phi", 60,0.,3.15);
TH1F* selvar_mu_relIso = new TH1F("selvar_mu_relIso","selvar_mu_relIso;mu relIso", 140,-5.,30.);
TH1F* selvars_mu_emEnergy= new TH1F("selvars_mu_emEnergy","selvars_mu_emEnergy;mu emEnergy", 140,-5.,30.);
TH1F* selvars_mu_hadEnergy= new TH1F("selvars_mu_hadEnergy","selvars_mu_hadEnergy;mu hadEnergy", 140,-5.,30.);
TH1F* selvar_mu_d0 = new TH1F("selvar_mu_d0","selvar_mu_d0;mu d0", 200,0.,20);
TH1F* selvar_mu_dz_pVtxZ = new TH1F("selvar_mu_dz_pVtxZ","mu dz-pVtxZ;mu dz-pVtxZ", 80,0.,20.);
TH1F* selvars_mu_dZ= new TH1F("selvars_mu_dZ","selvars_mu_dZ;mu dZ", 200,0.,20);
TH1F* selvars_mu_chi2OverNdof = new TH1F("selvars_mu_chi2OverNdof","selvars_mu_chi2OverNdof;mu chi2OverNdof", 200,0.,20);
TH1F* selvars_mu_nValidTrackerHits= new TH1F("selvars_mu_nValidTrackerHits","selvars_mu_nValidTrackerHits;mu nValidTrackerHits", 40,0.,40);
TH1F* selvars_mu_combinedTrackIndex= new TH1F("selvars_mu_combinedTrackIndex","selvars_mu_combinedTrackIndex;mu combinedTrackIndex", 40,0.,40);
TH1F* selvars_mu_numberOfValidPixelHits= new TH1F("selvars_mu_numberOfValidPixelHits","selvars_mu_numberOfValidPixelHits;mu_numberOfValidPixelHits", 40,0.,40);
TH1F* selvars_mu_numberOfValidMuonHits= new TH1F("selvars_mu_numberOfValidMuonHits","selvars_mu_numberOfValidMuonHits;mu_numberOfValidMuonHits", 40,0.,40);
TH1F* selvars_mu_isGlobalMuon= new TH1F("selvars_mu_isGlobalMuon","selvars_mu_isGlobalMuon;isGlobalMuon", 2,0.,2.);
TH1F* selvars_mu_isPFMuon= new TH1F("selvars_mu_isPFMuon","selvars_mu_isPFMuon;isPFMuon", 2,0.,2.);
//JETS
TH1F* selvar_jet_njet = new TH1F("selvar_jet_njet","selvar_jet_njet;n jets", 15,0.,15.);
TH1F* selvar_jet_Et = new TH1F("selvar_jet_Et","selvar_jet_Et; jet E_{t}", 250,0.,250);
TH1F* selvar_jet_Eta= new TH1F("selvar_jet_Eta","selvar_jet_Eta; jet #eta", 100,-2.5,2.5);
TH1F* selvar_jet_Phi= new TH1F("selvar_jet_Phi","selvar_jet_Phi; jet #phi", 60,0.,3.15);
TH1F* selvars_jet_nConstituents= new TH1F("selvars_jet_nConstituents","selvars_jet_nConstituents;jet_nConstituents", 41,-2.,80.);
TH1F* selvars_jet_NeutralHadFrac= new TH1F("selvars_jet_NeutralHadFrac","selvars_jet_NeutralHadFrac;jet_NeutralHadFrac", 100,0.,1.);
TH1F* selvars_jet_NeutralEMFrac= new TH1F("selvars_jet_NeutralEMFrac","selvars_jet_NeutralEMFrac;jet_NeutralEMFrac", 100,0.,1.);
TH1F* selvars_jet_ChargedHadFrac= new TH1F("selvars_jet_ChargedHadFrac","selvars_jet_ChargedHadFrac;jet_ChargedHadFrac", 100,0.,1.);
TH1F* selvars_jet_ChargedEMFrac= new TH1F("selvars_jet_ChargedEMFrac","selvars_jet_ChargedEMFrac;jet_ChargedEMFrac", 100,0.,1.);
TH1F* selvars_jet_chargedHadMult= new TH1F("selvars_jet_chargedHadMult","selvars_jet_chargedHadMult;jet_chargedHadMult", 60,0.,60.);
// TH1F* selvars_jet_dR_ele_min= new TH1F("selvar_jet_Phi","selvar_jet_Phi", 60,0.,3.);
// TH1F* selvars_jet_dR_mu_min= new TH1F("selvar_jet_Phi","selvar_jet_Phi", 60,0.,3.);
//VERTEX
TH1F* selvar_vtx_nVtx = new TH1F("selvar_vtx_nVtx","selvar_vtx_nVtx;N vertecies",40,0.,40.);
TH1F* selvar_vtx_isFake= new TH1F("selvar_vtx_isFake","selvar_vtx_isFake; vertex isFake flag",2,0,2);
TH1F* selvar_vtx_ndof= new TH1F("selvar_vtx_ndof","selvar_vtx_ndof; vertex ndof",40,0.,40.);
TH1F* selvar_vtx_chi2= new TH1F("selvar_vtx_chi2","selvar_vtx_chi2;vtx_chi2",200,0.,20);
TH1F* selvar_vtx_trackSize= new TH1F("selvar_vtx_trackSize","selvar_vtx_trackSize;vtx_trackSize",80,0,80.);
TH1F* selvar_vtx_rho= new TH1F("selvar_vtx_rho","selvar_vtx_rho;vtx_rho",100,0.,1.);
TH1F* selvar_vtx_Zpos=new TH1F("selvar_vtx_Zpos","selvar_vtx_Zpos;vtx_Zpos",72,0.,72.);
//B-TAG
TH1F* selvar_btag_nbtag= new TH1F("selvar_btag_nbtag","selvar_btag_nbtag;N b-tags",10,0.,10.);
TH1F* selvar_btag_csv= new TH1F("selvar_btag_csv","selvar_btag_csv;jet CSV",120,0.,1.2);
if(pl>=4) printf("finished declaring selvar hists, start HLT\n");
const int Nnonr9Triggers = 9;
const int Nr9Triggers = 4;
//const int NT = Nnonr9Triggers+Nr9Triggers;
//bool passHLTs[NT];
TString dmason_triggers[4] = { //not using these.
"HLT_Photon36_CaloId10_Iso50_Photon22_CaloId10_Iso50",
"HLT_Photon36_CaloId10_Iso50_Photon22_R9Id85",
"HLT_Photon36_R9Id85_Photon22_CaloId10_Iso50",
"HLT_Photon36_R9Id85_Photon22_R9Id85"};
//"HLT_Photon36_R9Id85_OR_CaloId10_Iso50_Photon22_R9Id85_OR_CaloId10_Iso50";
TString R9triggers[Nr9Triggers] = {
"HLT_Photon36_CaloId10_Iso50_Photon22_CaloId10_Iso50", //dmason
"HLT_Photon36_CaloIdL_Photon22_CaloIdL",
"HLT_Photon32_CaloIdL_Photon26_CaloIdL",
"HLT_Photon26_CaloId10_Iso50_Photon18_CaloId10_Iso50_Mass60"};
TString nonR9triggers[Nnonr9Triggers] = {
"HLT_Photon36_R9Id85_Photon22_R9Id85", //dmason
"HLT_Photon36_R9Id85_Photon22_CaloId10_Iso50", //dmason
"HLT_Photon36_CaloId10_Iso50_Photon22_R9Id85", //dmason
"HLT_Photon26_R9Id85_OR_CaloId10_Iso50_Photon18_R9Id85_OR_CaloId10_Iso50_Mass60",
"HLT_Photon26_R9Id85_OR_CaloId10_Iso50_Photon18_R9Id85_OR_CaloId10_Iso50_Mass70",
"HLT_Photon26_R9Id85_Photon18_R9Id85_Mass60",
"HLT_Photon26_R9Id85_Photon18_CaloId10_Iso50_Mass60",
"HLT_Photon26_CaloId10_Iso50_Photon18_R9Id85_Mass60",
"HLT_Photon36_R9Id85_OR_CaloId10_Iso50_Photon22_R9Id85_OR_CaloId10_Iso50"};
if(!useTrigger){
useTrigger = true;
cout<< endl<<"By some black magic, useTrigger is false, setting it to true"<<endl;
}
if (!useTrigger) cout << endl << endl << "WARNING!! NOT USING THE TRIGGER!!!"<<endl<<endl<<endl;
else cout << endl << "TRIGGER ON"<<endl<<endl;
if (!useJSON) cout << endl << endl << "THIS IS MC SO I'M NOT USING THE JSON FILE!!!"<<endl<<endl<<endl;
else cout << endl << "WARNING!! USING JSON"<<endl<<endl;
// to check duplicated events
std::map<int, std::set<int> > allEvents;
int nStop = 0;
int nNotStop = 0;
if(pl>=3) printf("Enter Main Analysis Loop\n");
// start event looping
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry < processNEvents; jentry++) {
//for (Long64_t jentry=0; jentry < 500; jentry++){ //master loop
if(pbMainLoopInit && pl > 3) std::cout << "Get the tree contents." << std::endl;
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
Counters["no cuts"]++;
nb = fChain->GetEntry(jentry); nbytes += nb;
if(pl > 2 && (printInterval > 0 && (jentry >= printInterval && jentry%printInterval == 0)) ) {
std::cout << int(jentry) << " events processed with run="
<< event->runNumber << ", event=" << event->eventNumber << std::endl;
//every 100 print intervals, print the trigger list. It should always on the first event.
//if (jentry%(printInterval*100) == 0) PrintPhotonTriggers(event);
}//end if millionth event.
if(pbMainLoopInit && pl > 0) std::cout << "Initialize any global variables to be reset per event." << std::endl;
InitializePerEvent();
//look over gen particels, determine if it's stop
if(!useElectroHiggs){
bool has_stop = false;
for(std::vector<susy::Particle>::iterator it = event->genParticles.begin(); !has_stop && it != event->genParticles.end(); it++) {
has_stop |= (abs(it->pdgId) == 1000006 || abs(it->pdgId) == 2000006); //ask if Stop
}
if(!has_stop){
nNotStop++;
continue;//throw out events without a stop in them.
}
else nStop++;//keep track of how many you've thrown out and what proportion.
}
if(event->runNumber<0){
if(pl > 0) std::cout << "Warning: run number less than zero" << std::endl;
continue;
}
if(pl > 1 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe is at point A"<<endl;
//if(pl > 0) std::cout << "Apply good run list." << std::endl;
//if(event->isRealData && useJSON && !isInJson(event->runNumber,event->luminosityBlockNumber)) continue;
//if(pl > 0 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes JSON"<<endl;
//Counters["pass Json"]++; // total number of events that pass Json
//Print(*event); // uncomment this to print all ntuple variables
/*if(pl > 1) cout << "Check duplicated events for data only." << endl;
if(event->isRealData){
bool duplicateEvent = ! (allEvents[event->runNumber].insert(event->eventNumber)).second;
if(duplicateEvent){
cout<<"Duplicate Event! Run "<<event->runNumber<<" Event "<<event->eventNumber<<endl;
continue;
}
}
if(pl > 0 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes Duplicate Filter"<<endl;
Counters["pass duplicate check"]++;*/
// if(pl > 0) Print(*event); // uncomment this to print all ntuple variables
if(pbMainLoopInit && pl >=3) std::cout << "Apply trigger selection in the event." << std::endl;
/*
NOTE
WE DO NOT APPLY HLT HERE, WE RELY ON THE PHOTON PT CUTS TO GET US ABOVE ALL TRIGGER THRESHOLDS
THE FASTSIM MAY DO A PERFECTLY HORRIBLE JOB OF EMULATING THE TRIGGER.
*/
//bool pass_non_r9id_trigger = false;
//bool pass_r9id_trigger = false;
/*bool pass_dmason_trigger = false;
bool passHLT = false;
for (int i=0; i<5 && !pass_dmason_trigger; i++) {
pass_dmason_trigger |= PassTrigger(dmason_triggers[i]);
}*/
/*for (int i=0; i<Nnonr9Triggers && !pass_non_r9id_trigger; i++) {
pass_non_r9id_trigger |= PassTrigger(nonR9triggers[i]);
}
if(!pass_non_r9id_trigger){
for (int i=0; i<Nr9Triggers && !pass_r9id_trigger; i++) {
pass_r9id_trigger |= PassTrigger(R9triggers[i]);
}
}*/
/*passHLT = pass_dmason_trigger;//pass_r9id_trigger || pass_non_r9id_trigger;
Counters["pre HLT"]++;
if(useTrigger && !passHLT) continue;
//if(event->isRealData && useTrigger && !passHLT) continue;
if(pl > 0 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes HLT"<<endl;
Counters["pass HLT"]++;*/
//if(useMETFilter_data && !event->passMetFilters()) continue; //don't use the met filter for MC, nothing passes.
//if(pl > 0 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes MetFilter"<<endl;
///MET FilterCounters["pass MET Filter"]++;
if(pbMainLoopInit && pl > 0) std::cout << "Setup object vectors." << std::endl;
float myST = 0.0;
float myPhotonST = 0.0;
float myLeptonST = 0.0;
TLorentzVector vMET,vH,vL,vPho;//Have gg for diphotons
std::vector<susy::Photon*> loose_photons; // loose objects have all standard cuts except for isolation
std::vector<susy::Photon*> tight_susy11_photons; // tight objects hava isolation cuts applied on top of loose objects
std::vector<susy::Photon*> tight_susy11Star_photons; // tight objects hava isolation cuts applied on top of loose objects
std::vector<susy::Photon*> medium_susy12_photons; // tight objects hava isolation cuts applied on top of loose objects
std::vector<susy::Photon*> loose_susy12_photons; // tight objects hava isolation cuts applied on top of loose objects
std::vector<susy::Photon*> tight_VG11_photons;
std::vector<susy::Photon*>* p_photonVector;
//std::vector<susy::Photon*>* p_photonVector = &tight_susy11_photons;
//use as (*p_photonVector)
std::vector<susy::PFJet*> pfJets;
std::vector<susy::PFJet*> pfBJetsTight;
std::vector<susy::PFJet*> pfBJetsMedium;
std::vector<susy::PFJet*> pfBJetsLoose;
std::vector<susy::Vertex*> good_vtx;
// std::vector<susy::Muon*> ra3_muons;
std::vector<susy::Muon*> Muons;//DM's collection
std::vector<susy::PFJet*> ra3_pfjets;
std::vector<susy::Electron*> pfEles;
// std::vector<susy::Photon*> tap_electrons;
//std::vector<susy::Track*> tap_tracks;
//std::vector<susy::PFJet*> ra3_pfjets_noid;
//std::vector<susy::PFJet*> ra3_pfjets_noclean;
//std::vector<susy::Photon*> r9_photons;
//std::vector<susy::Photon*> rho_photons;
//std::vector<MyEMObject> myEMObject_sorted;
//std::vector<MyEMObject> myEMObject; // applied all DR condition
//std::vector<susy::Photon*> ele_photons; // same as tight except for nPixelSeeds > 0
//std::vector<susy::Photon*> fake_photons; // same as tight except for reversing either trackIso or sigmaIetaIeta
//std::vector<susy::CaloJet*> caloJets;
/////////////////////////////////////////////////////////////////
//////////////////////////// PHOTONS ////////////////////////////
/////////////////////////////////////////////////////////////////
if(pbPhos && pl > 0) std::cout << "Find loose and tight photons in the event." << std::endl;
std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
if(phoMap != event->photons.end()) {
for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
it != phoMap->second.end(); it++) {
float MVAcor = it->MVAregEnergyAndErr.first/it->momentum.E();
/*bool tightSusy11Cut = is_tight_combIso_BFrancis(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->trkSumPtHollowConeDR03,
it->ecalRecHitSumEtConeDR03,
it->hcalTowerSumEtConeDR03(),
it->hadronicOverEm,
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->r9,
it->nPixelSeeds,
event->rho25);
bool loose11Cut = is_vloose_pho(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->trkSumPtHollowConeDR03,
it->ecalRecHitSumEtConeDR03,
it->hcalTowerSumEtConeDR03(),
it->hadronicOverEm,
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->r9,
it->nPixelSeeds,
event->rho25);
bool tightVG11Cut = is_tight_ManiTripathi(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->trkSumPtHollowConeDR04,
it->ecalRecHitSumEtConeDR04,
it->hcalTowerSumEtConeDR04(),
it->hadronicOverEm,
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->r9,
it->nPixelSeeds,
event->rho25);
bool istight2012Cut = is_tight_2012(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->chargedHadronIso,
it->neutralHadronIso,
it->photonIso,
it->hadTowOverEm, //single tower, same cut though
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->passelectronveto, //replaces pixel seed veto
event->rho25);*/
bool ismedium2012Cut = is_medium_2012(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->chargedHadronIso,
it->neutralHadronIso,
it->photonIso,
it->hadTowOverEm, //single tower, same cut though
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->passelectronveto, //replaces pixel seed veto
event->rho25);
bool isloose2012Cut = is_loose_2012(
//useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et(),//it->momentum.Et(),
((useMVAphoP?MVAcor:1.0)*it->momentum).Et(),
it->caloPosition.Eta(),
it->chargedHadronIso,
it->neutralHadronIso,
it->photonIso,
it->hadTowOverEm, //single tower, same cut though
it->sigmaIetaIeta,
it->sigmaIphiIphi,
it->passelectronveto, //replaces pixel seed veto
event->rho25);
//if((useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et()) < phoEtThresh1){ //if(it->momentum.Et() < phoEtThresh1){
if( ((useMVAphoP?MVAcor:1.0)*it->momentum).Et() < phoEtThresh1){ //if(it->momentum.Et() < phoEtThresh1){
selvar_pho_HE->Fill(it->hadronicOverEm);
if(fabs(it->caloPosition.Eta())<1.4442) {
selvar_pho_sinin_bar->Fill(it->sigmaIetaIeta);
selvar_pho_sipip_bar->Fill(it->sigmaIphiIphi);
}
else if(fabs(it->caloPosition.Eta())>1.56 && fabs(it->caloPosition.Eta())<2.5) {
selvar_pho_sinin_ec->Fill(it->sigmaIetaIeta);
selvar_pho_sipip_ec->Fill(it->sigmaIphiIphi);
}
selvar_pho_nPixelSeeds->Fill(it->nPixelSeeds);
selvar_pho_R9->Fill(it->r9);
}//fill selvars
selvar_pho_ChargeSafeEleVeto->Fill(it->passelectronveto?1:0);
//if(loose11Cut) { loose_photons.push_back(&*it); }
if(isloose2012Cut) {
//if((useMVAphoP?it-> MVAcorrMomentum.Et():it->momentum.Et()) < phoEtThresh1){
if( ((useMVAphoP?it->MVAregEnergyAndErr.first / it->momentum.E():1.0)*it->momentum).Et() < phoEtThresh1){ // if(it->momentum.Et() < phoEtThresh1){
selvar_pho_TrkIsoDR04->Fill(it->trkSumPtHollowConeDR04);
selvar_pho_EcalIsoDR04->Fill(it->ecalRecHitSumEtConeDR04);
selvar_pho_HcalIsoDR04->Fill(it->hcalTowerSumEtConeDR04());
selvar_pho_TrkIsoDR03->Fill(it->trkSumPtHollowConeDR04);
selvar_pho_EcalIsoDR03->Fill(it->ecalRecHitSumEtConeDR04);
selvar_pho_HcalIsoDR03->Fill(it->hcalTowerSumEtConeDR03());
selvar_pho_PFcargedHadIso->Fill(it->chargedHadronIso);
selvar_pho_PFneutralHadIso->Fill(it->neutralHadronIso);
selvar_pho_PFphoIso->Fill(it->photonIso);
selvar_pho_rho->Fill(event->rho25);
}
}
//if(tightSusy11Cut) { tight_susy11_photons.push_back(&*it); }
//if (tightVG11Cut) { tight_VG11_photons.push_back(&*it); }
if(isloose2012Cut){
loose_susy12_photons.push_back(&*it);
}
if(ismedium2012Cut){
medium_susy12_photons.push_back(&*it);
}
}// for all photon
}// else
// sort photons by Et
// std::sort(loose_photons.begin(),loose_photons.end(),EtGreaterpho<susy::Photon>);
//std::sort(tight_susy11_photons.begin(),tight_susy11_photons.end(),EtGreaterpho<susy::Photon>);
//std::sort(loose_photons.begin(),loose_photons.end(),EtGreaterpho<susy::Photon>);
//std::sort(tight_VG11_photons.begin(),tight_VG11_photons.end(),EtGreaterpho<susy::Photon>);
std::sort(medium_susy12_photons.begin(),medium_susy12_photons.end(),EtGreaterpho<susy::Photon>);
std::sort(loose_susy12_photons.begin(),loose_susy12_photons.end(),EtGreaterpho<susy::Photon>);
if(pbPhos && pl > 8) cout<<"e"<<endl;
//remove_duplicate_photons(tight_susy11_photons);
//remove_duplicate_photons(tight_VG11_photons);
//remove_duplicate_photons(loose_photons);
remove_duplicate_photons(loose_susy12_photons);
if(pbPhos && pl > 8) cout<<"f"<<endl;
remove_duplicate_photons(medium_susy12_photons);
if(pbPhos && pl > 8) cout<<"g"<<endl;
//////////////////////////////////////////////////////////////////////////////
//////////////////////// Set Which Kind of Photon You Use ////////////////////
//////////////////////////////////////////////////////////////////////////////
p_photonVector = &loose_susy12_photons; //use as (*p_photonVector)
//p_photonVector = &medium_susy12_photons; //use as (*p_photonVector)
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if(pbPhos && pl > 4) cout<<"set pho pointer"<<endl;
// I want to set this after all the removing and sorting is done in case some of
// that messes with the address of the start of the vector.
//fill photon dists.
if ((*p_photonVector).size()>=2 ){
float MVAcor0 = (*p_photonVector)[0]->MVAregEnergyAndErr.first/(*p_photonVector)[0]->momentum.E();
float Et0 = ((useMVAphoP?MVAcor0:1.0)*(*p_photonVector)[0]->momentum).Et();
//float Et0 = useMVAphoP?(*p_photonVector)[0]->MVAcorrMomentum.Et():(*p_photonVector)[0]->momentum.Et();
pho_Et_0->Fill(Et0);//look at pho0 with no pt cut. // pho_Et_0->Fill((*p_photonVector)[0]->momentum.Et());//look at pho0 with no pt cut.
if (Et0 >= phoEtThresh0){ // if ((*p_photonVector)[0]->momentum.Et() >= phoEtThresh0){
//float Et1 = useMVAphoP?(*p_photonVector)[1]->MVAcorrMomentum.Et():(*p_photonVector)[1]->momentum.Et();
float MVAcor1 = (*p_photonVector)[1]->MVAregEnergyAndErr.first/(*p_photonVector)[1]->momentum.E();
float Et1 = ((useMVAphoP?MVAcor1:1.0)*(*p_photonVector)[1]->momentum).Et();
pho_Et_1->Fill(Et1); //pho_Et_1->Fill((*p_photonVector)[1]->momentum.Et());
if ((*p_photonVector).size()>2 && Et1 >= phoEtThresh1) //if ((*p_photonVector).size()>2 && (*p_photonVector)[1]->momentum.Et() >= phoEtThresh1)
//float MVAcor2 = (*p_photonVector)[2]->MVAregEnergyAndErr.first/(*p_photonVector)[2]->momentum.E();
pho_Et_2->Fill( ((useMVAphoP?(*p_photonVector)[2]->MVAregEnergyAndErr.first/(*p_photonVector)[2]->momentum.E():1.0)*(*p_photonVector)[2]->momentum).Et() ); //pho_Et_2->Fill((*p_photonVector)[2]->momentum.Et());
//pho_Et_2->Fill( useMVAphoP?(*p_photonVector)[2]->MVAcorrMomentum.Et():(*p_photonVector)[2]->momentum.Et() );
}
}
selvar_pho_nPho->Fill((*p_photonVector).size());
for(std::vector<susy::Photon*>::iterator it = (*p_photonVector).begin(); it != (*p_photonVector).end(); it++) {
float Eti = ((useMVAphoP?(*it)->MVAregEnergyAndErr.first / (*it)->momentum.E():1.0)*(*it)->momentum).Et();
//float Eti = (useMVAphoP?(*it)-> MVAcorrMomentum.Et():(*it)->momentum.Et());
if(Eti < phoEtThresh1){//if((*it)->momentum.Et() < phoEtThresh1){
selvar_pho_Et->Fill(Eti);//selvar_pho_Et->Fill((*it)->momentum.Et());
selvar_pho_Eta ->Fill((*it)->caloPosition.Eta());
selvar_pho_Phi->Fill(fabs((*it)->caloPosition.Phi()));
}
}
//probe the event
if(pl >= 2 && event->eventNumber == ((unsigned int)probeevent)){
printf("probe: nPho_tight %li nPho_loose %li\n",(*p_photonVector).size(),loose_susy12_photons.size());
if(event->eventNumber == ((unsigned int)probeevent) && loose_susy12_photons.size() >= 2)
printf("tight: phoEt[0] %f, phoEt[1] %f phoEta[0] %.2f, phoEta[1] %.2f\n",
((useMVAphoP?loose_susy12_photons[0]->MVAregEnergyAndErr.first / loose_susy12_photons[0]->momentum.E():1.0)*loose_susy12_photons[0]->momentum).Et(),
((useMVAphoP?loose_susy12_photons[1]->MVAregEnergyAndErr.first / loose_susy12_photons[1]->momentum.E():1.0)*loose_susy12_photons[1]->momentum).Et(),
loose_susy12_photons[0]->momentum.Eta(),
loose_susy12_photons[1]->momentum.Eta() );
/* useMVAphoP?loose_susy12_photons[0]->MVAcorrMomentum.Et():loose_susy12_photons[0]->momentum.Et(),
useMVAphoP?loose_susy12_photons[1]->MVAcorrMomentum.Et():loose_susy12_photons[1]->momentum.Et(),
useMVAphoP?loose_susy12_photons[0]->MVAcorrMomentum.Eta():loose_susy12_photons[0]->momentum.Eta(),
useMVAphoP?loose_susy12_photons[1]->MVAcorrMomentum.Eta():loose_susy12_photons[1]->momentum.Eta() );*/
if(event->eventNumber == ((unsigned int)probeevent) && (*p_photonVector).size() >= 2)
printf("tight: phoEt[0] %f, phoEt[1] %f phoEta[0] %.2f, phoEta[1] %.2f\n",
((useMVAphoP?(*p_photonVector)[0]->MVAregEnergyAndErr.first / (*p_photonVector)[0]->momentum.E():1.0)*(*p_photonVector)[0]->momentum).Et(),
((useMVAphoP?(*p_photonVector)[1]->MVAregEnergyAndErr.first / (*p_photonVector)[1]->momentum.E():1.0)*(*p_photonVector)[1]->momentum).Et(),
(*p_photonVector)[0]->momentum.Eta(),
(*p_photonVector)[1]->momentum.Eta() );
/* useMVAphoP?(*p_photonVector)[0]->MVAcorrMomentum.Et():(*p_photonVector)[0]->momentum.Et(),
useMVAphoP?(*p_photonVector)[1]->MVAcorrMomentum.Et():(*p_photonVector)[1]->momentum.Et(),
useMVAphoP?(*p_photonVector)[0]->MVAcorrMomentum.Eta():(*p_photonVector)[0]->momentum.Eta(),
useMVAphoP?(*p_photonVector)[1]->MVAcorrMomentum.Eta():(*p_photonVector)[1]->momentum.Eta() );*/
printf("I see thresholds: %f, %f\n",phoEtThresh0,phoEtThresh1);
}
//////////////////make two photon cuts.///////////////////////
if(pbPhos && pl >= 8)
{
cout<<"ready to continue"<<endl;
// if((useMVAphoP?loose_susy12_photons[0]->MVAcorrMomentum.Et():loose_susy12_photons[0]->momentum.Et()) < phoEtThresh0) cout<<"pho0 below threshold"<<endl;
//if((useMVAphoP?loose_susy12_photons[1]->MVAcorrMomentum.Et():loose_susy12_photons[1]->momentum.Et()) < phoEtThresh1) cout<<"pho1 below threshold"<<endl;
if((((useMVAphoP?loose_susy12_photons[0]->MVAregEnergyAndErr.first / loose_susy12_photons[0]->momentum.E():1.0)*loose_susy12_photons[0]->momentum).Et()) < phoEtThresh0 ) cout<<"pho0 below threshold"<<endl;
if((((useMVAphoP?loose_susy12_photons[1]->MVAregEnergyAndErr.first / loose_susy12_photons[1]->momentum.E():1.0)*loose_susy12_photons[1]->momentum).Et()) < phoEtThresh1) cout<<"pho1 below threshold"<<endl;
}
if (loose_susy12_photons.size()<2 ||
(((useMVAphoP?loose_susy12_photons[0]->MVAregEnergyAndErr.first / loose_susy12_photons[0]->momentum.E():1.0)*loose_susy12_photons[0]->momentum).Et()) < phoEtThresh0 ||
(((useMVAphoP?loose_susy12_photons[1]->MVAregEnergyAndErr.first / loose_susy12_photons[1]->momentum.E():1.0)*loose_susy12_photons[1]->momentum).Et()) < phoEtThresh1) continue;
//(useMVAphoP?loose_susy12_photons[0]->MVAcorrMomentum.Et():loose_susy12_photons[0]->momentum.Et()) < phoEtThresh0 ||
//(useMVAphoP?loose_susy12_photons[1]->MVAcorrMomentum.Et():loose_susy12_photons[1]->momentum.Et()) < phoEtThresh1) continue;//firing all of the time.
Counters["have 2 loose photons"]++;
if(pbPhos && pl >=3 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes Two Loose Photons"<<endl;
if ((*p_photonVector).size()<2 ||
(((useMVAphoP?(*p_photonVector)[0]->MVAregEnergyAndErr.first / (*p_photonVector)[0]->momentum.E():1.0)*(*p_photonVector)[0]->momentum).Et()) < phoEtThresh0 ||
(((useMVAphoP?(*p_photonVector)[1]->MVAregEnergyAndErr.first / (*p_photonVector)[1]->momentum.E():1.0)*(*p_photonVector)[1]->momentum).Et()) < phoEtThresh1) continue;
//(useMVAphoP?(*p_photonVector)[0]->MVAcorrMomentum.Et():(*p_photonVector)[0]->momentum.Et()) < phoEtThresh0 ||
//(useMVAphoP?(*p_photonVector)[1]->MVAcorrMomentum.Et():(*p_photonVector)[1]->momentum.Et()) < phoEtThresh1) continue;
//Counters["have 2 tight photons"]++;
//if(pl > 0 && event->eventNumber == ((unsigned int)probeevent)) cout<<"probe passes Two Tight Photons"<<endl;
TLorentzVector p0, p1, gg;
p0 = (useMVAphoP?(*p_photonVector)[0]->MVAregEnergyAndErr.first / (*p_photonVector)[0]->momentum.E():1.0)*(*p_photonVector)[0]->momentum;
p1 = (useMVAphoP?(*p_photonVector)[1]->MVAregEnergyAndErr.first / (*p_photonVector)[1]->momentum.E():1.0)*(*p_photonVector)[1]->momentum;
//p0 = useMVAphoP?(*p_photonVector)[0]->MVAcorrMomentum:(*p_photonVector)[0]->momentum;
//p1 = useMVAphoP?(*p_photonVector)[1]->MVAcorrMomentum:(*p_photonVector)[1]->momentum;
gg = p0+p1;
float mgg = gg.M();//mass is fine
float ptgg = gg.Pt();//pt is fine
float mtgg = sqrt(gg.E()*gg.E() - gg.Perp2());