-
Notifications
You must be signed in to change notification settings - Fork 3
/
JMEAnalyzer.cc
3180 lines (2652 loc) · 137 KB
/
JMEAnalyzer.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
// Original Author: Laurent Thomas
// Created: Fri, 26 Apr 2019 12:51:46 GMT
// system include files
#include <memory>
#include <iostream>
#include <fstream>
#include <string>
// user include files
#include "JetMETCorrections/Objects/interface/JetCorrector.h"
#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
#include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
#include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
#include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "DataFormats/L1Trigger/interface/EGamma.h"
#include "DataFormats/L1Trigger/interface/Jet.h"
#include "DataFormats/L1Trigger/interface/BXVector.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "DataFormats/PatCandidates/interface/MET.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Photon.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
#include "DataFormats/JetReco/interface/GenJet.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
#include "JetMETStudies/JMEAnalyzer/interface/Tools.h"
#include "RecoJets/JetProducers/plugins/PileupJetIdProducer.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TTree.h"
#include "TString.h"
#include "TMath.h"
#include "TLorentzVector.h"
#include "Math/Vector4D.h"
#include "Math/Vector4Dfwd.h"
//#include "JetMETStudies/JMEAnalyzer/python/RochesterCorrections/RoccoR.h"
#include "JetMETStudies/JMEAnalyzer/interface/RoccoR.h"
const int N_METFilters=18;
enum METFilterIndex{
idx_Flag_goodVertices,
idx_Flag_globalTightHalo2016Filter,
idx_Flag_globalSuperTightHalo2016Filter,
idx_Flag_HBHENoiseFilter,
idx_Flag_HBHENoiseIsoFilter,
idx_Flag_EcalDeadCellTriggerPrimitiveFilter,
idx_Flag_BadPFMuonFilter,
idx_Flag_BadPFMuonDzFilter,
idx_Flag_hfNoisyHitsFilter,
idx_Flag_BadChargedCandidateFilter,
idx_Flag_eeBadScFilter,
idx_Flag_ecalBadCalibFilter,
idx_Flag_ecalLaserCorrFilter,
idx_Flag_EcalDeadCellBoundaryEnergyFilter,
idx_PassecalBadCalibFilter_Update,
idx_PassecalLaserCorrFilter_Update,
idx_PassEcalDeadCellBoundaryEnergyFilter_Update,
idx_PassBadChargedCandidateFilter_Update
};
//
// class declaration
//
// If the analyzer does not use TFileService, please remove
// the template argument to the base class so the class inherits
// from edm::one::EDAnalyzer<>
// This will improve performance in multithreaded jobs.
using namespace edm;
using namespace std;
using namespace reco;
using namespace tools;
class JMEAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources,edm::one::WatchRuns> {
public:
explicit JMEAnalyzer(const edm::ParameterSet&);
~JMEAnalyzer();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
virtual void beginJob() override;
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
virtual void endJob() override;
virtual void beginRun(const edm::Run&, const edm::EventSetup&);
virtual void endRun(const edm::Run&, const edm::EventSetup&);
virtual bool PassSkim();
virtual bool GetMETFilterDecision(const edm::Event& iEvent, edm::Handle<TriggerResults> METFilterResults, TString studiedfilter);
virtual bool GetIdxFilterDecision(int it);
virtual TString GetIdxFilterName(int it);
virtual void InitandClearStuff();
virtual void CalcDileptonInfo(const int& i, const int& j, Float_t & themass, Float_t & theptll, Float_t & thepzll, Float_t & theyll, Float_t & thephill, Float_t & thedphill, Float_t & thecosthll);
virtual void CalcDileptonInfoGen(const int& i, const int& j, Float_t & themass, Float_t & theptll, Float_t & thepzll, Float_t & theyll, Float_t & thephill, Float_t & thedphill, Float_t & thecosthll);
virtual int GetRecoIdx(const reco::GenJet * genjet , vector <Float_t> recojetpt, vector <Float_t> recojeteta, vector <Float_t> recojetphi, vector <Float_t> recojetptgen );
virtual bool IsLeptonPhotonCleaned(const pat::Jet *iJ);
virtual bool IsLeptonPhotonCleaned(const reco::CaloJet *iJ);
virtual bool PassJetPreselection(const pat::Jet * iJ, double genjetpt, bool ispuppi);
virtual bool PassJetPreselection(const reco::CaloJet * iJ, double genjetpt);
bool PassTriggerLeg(std::string triggerlegstring, std::string triggerlegstringalt,const pat::Muon *muonit, const edm::Event&);
bool PassTriggerLeg(std::string triggerlegstring, std::string triggerlegstringalt,const pat::Electron *eleit, const edm::Event&);
bool PassTriggerLeg(std::string triggerlegstring, std::string triggerlegstringalt,const pat::Photon *photonit, const edm::Event&);
bool PassTriggerLeg(std::string triggerlegstring, std::string triggerlegstringalt,const pat::Jet *jetit, const edm::Event&);
bool PassTriggerLeg(std::string triggerlegstring, const pat::Muon *muonit, const edm::Event& theevent){return PassTriggerLeg(triggerlegstring,"Noalttrigger",muonit,theevent);};
bool PassTriggerLeg(std::string triggerlegstring, const pat::Electron *eleit, const edm::Event& theevent){ return PassTriggerLeg(triggerlegstring,"Noalttrigger",eleit,theevent);};
bool PassTriggerLeg(std::string triggerlegstring, const pat::Photon *photonit, const edm::Event& theevent){ return PassTriggerLeg(triggerlegstring,"Noalttrigger",photonit,theevent);};
bool PassTriggerLeg(std::string triggerlegstring, const pat::Jet *jetit, const edm::Event& theevent){ return PassTriggerLeg(triggerlegstring,"Noalttrigger",jetit,theevent);};
// ----------member data ---------------------------
edm::EDGetTokenT<TriggerResults> metfilterspatToken_;
edm::EDGetTokenT<TriggerResults> metfiltersrecoToken_;
edm::EDGetTokenT<bool> ecalBadCalibFilterUpdateToken_;
edm::EDGetTokenT<bool> ecalLaserCorrFilterUpdateToken_;
edm::EDGetTokenT<bool> ecalDeadCellBoundaryEnergyFilterUpdateToken_;
edm::EDGetTokenT<bool> badChargedCandidateFilterUpdateToken_;
edm::EDGetTokenT<std::vector<Vertex> > verticesToken_;
edm::EDGetTokenT<double> rhoJetsToken_;
edm::EDGetTokenT<double> rhoJetsNCToken_;
edm::EDGetTokenT<std::vector< pat::Jet> > jetToken_;
edm::EDGetTokenT<std::vector< pat::Jet> > jetAK8Token_;
edm::EDGetTokenT<std::vector< pat::Jet> > jetPuppiToken_;
edm::EDGetTokenT<std::vector< pat::Jet> > jetPuppiAK8Token_;
edm::EDGetTokenT<std::vector< reco::CaloJet> > jetCaloToken_;
edm::EDGetTokenT<std::vector< pat::Jet> > jetnoCHSToken_;
edm::EDGetTokenT<std::vector< reco::GenJet> > genjetToken_;
edm::EDGetTokenT<std::vector< reco::GenJet> > genAK8jetToken_;
edm::EDGetTokenT<edm::ValueMap<float> > pileupJetIdDiscriminantUpdateToken_;
edm::EDGetTokenT<edm::ValueMap<float> > pileupJetIdDiscriminantUpdate2017Token_;
edm::EDGetTokenT<edm::ValueMap<float> > pileupJetIdDiscriminantUpdate2018Token_;
edm::EDGetTokenT<edm::ValueMap<StoredPileupJetIdentifier> > pileupJetIdVariablesUpdateToken_;
edm::EDGetTokenT<edm::ValueMap<float> > qgLToken_;
edm::EDGetTokenT<std::vector< pat::PackedCandidate>> pfcandsToken_;
edm::EDGetTokenT<edm::ValueMap<float> > puppiweightsToken_;
edm::EDGetTokenT<std::vector< pat::MET> > metToken_;
edm::EDGetTokenT<std::vector< pat::MET> > puppimetToken_;
edm::EDGetTokenT<std::vector< pat::Electron> > electronToken_;
edm::EDGetTokenT<std::vector< pat::Muon> > muonToken_;
edm::EDGetTokenT<std::vector< pat::Photon> > photonToken_;
edm::EDGetTokenT<GenParticleCollection> genpartToken_;
edm::EDGetTokenT<std::vector< pat::PackedGenParticle>> packedgenpartToken_;
edm::EDGetTokenT<GenEventInfoProduct> geninfoToken_;
edm::EDGetTokenT<LHEEventProduct> lheEventToken_;
edm::EDGetTokenT<LHEEventProduct> lheEventALTToken_;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > genJetAssocCHSToken_;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > genJetWithNuAssocCHSToken_;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > genJetAssocPuppiToken_;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > genJetWithNuAssocPuppiToken_;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > genJetAssocCaloToken_;
edm::EDGetTokenT<vector<PileupSummaryInfo> > puInfoToken_;
edm::EDGetTokenT<edm::TriggerResults> trgresultsToken_;
edm::EDGetTokenT<pat::TriggerObjectStandAloneCollection> trigobjectToken_;
edm::EDGetTokenT<BXVector<GlobalAlgBlk>> l1GtToken_;
edm::EDGetTokenT<l1t::MuonBxCollection>l1MuonToken_;
edm::EDGetTokenT<l1t::EGammaBxCollection>l1EGammaToken_;
edm::EDGetTokenT<l1t::JetBxCollection>l1JetToken_;
edm::EDGetTokenT<GlobalExtBlkBxCollection> UnprefirableEventToken_;
Float_t JetPtCut_;
Float_t AK8JetPtCut_;
Float_t ElectronPtCut_;
string ElectronVetoWP_, ElectronTightWP_, ElectronLooseWP_;
Float_t MuonPtCut_;
string RochCorrFile_;
Float_t PhotonPtCut_;
string PhotonTightWP_;
Float_t PFCandPtCut_;
Bool_t SaveTree_, IsMC_, SavePUIDVariables_, SaveAK8Jets_, SaveCaloJets_, SavenoCHSJets_, DropUnmatchedJets_, DropBadJets_, SavePFinJets_, ApplyPhotonID_;
string Skim_;
Bool_t Debug_;
Float_t _PtCutPFforMultiplicity[6]={0,0.3,0.5,1,5,10};
//Some histos to be saved for simple checks
TH1F *h_PFMet, *h_PuppiMet, *h_nvtx;
//These two histos are used to count the nb of events processed and the simulated PU distribution
//They should be filled before any skim is applied
TH1D *h_Counter, *h_trueNVtx;
//The output TTree
TTree* outputTree;
TTree* jetPFTree;
ifstream myfile_unprefevts;
//Variables associated to leaves of the TTree
unsigned long _eventNb;
unsigned long _runNb;
unsigned long _lumiBlock;
unsigned long _bx;
//Nb of primary vertices
int _n_PV;
Float_t _LV_x,_LV_y,_LV_z;
Float_t _LV_errx,_LV_erry,_LV_errz;
Float_t _PUV1_x,_PUV1_y,_PUV1_z;
int trueNVtx;
//Rho and RhoNC;
Float_t _rho, _rhoNC;
//MINIAOD original MET filters decisions
bool Flag_goodVertices;
bool Flag_globalTightHalo2016Filter;
bool Flag_globalSuperTightHalo2016Filter;
bool Flag_HBHENoiseFilter;
bool Flag_HBHENoiseIsoFilter;
bool Flag_EcalDeadCellTriggerPrimitiveFilter;
bool Flag_BadPFMuonFilter;
bool Flag_BadChargedCandidateFilter;
bool Flag_eeBadScFilter;
bool Flag_ecalBadCalibFilter;
bool Flag_ecalLaserCorrFilter;
bool Flag_EcalDeadCellBoundaryEnergyFilter;
bool Flag_BadPFMuonDzFilter;
bool Flag_hfNoisyHitsFilter;
//Decision obtained rerunning the filters on top of MINIAOD
bool PassecalBadCalibFilter_Update;
bool PassecalLaserCorrFilter_Update;
bool PassEcalDeadCellBoundaryEnergyFilter_Update;
bool PassBadChargedCandidateFilter_Update;
bool Flag_IsUnprefirable;
//AK4 CHS Jets
vector<Float_t> _jetEta;
vector<Float_t> _jetPhi;
vector<Float_t> _jetPt;
vector<Float_t> _jetRawPt;
vector<Float_t> _jet_CHEF;
vector<Float_t> _jet_NHEF;
vector<Float_t> _jet_NEEF;
vector<Float_t> _jet_CEEF;
vector<Float_t> _jet_MUEF;
vector <int> _jet_CHM;
vector <int> _jet_NHM;
vector <int> _jet_PHM;
vector <int> _jet_NM;
vector <Float_t> _jetArea;
vector <bool> _jetPassID;
vector <bool> _jetLeptonPhotonCleaned;
vector <Float_t> _jethfsigmaEtaEta;
vector <Float_t> _jethfsigmaPhiPhi;
vector <Int_t> _jethfcentralEtaStripSize;
vector <Int_t> _jethfadjacentEtaStripsSize;
vector <Float_t> _jetPtGen;
vector <Float_t> _jetEtaGen;
vector <Float_t> _jetPhiGen;
vector <Float_t> _jetPtGenWithNu;
vector<Float_t> _jetJECuncty;
vector<Float_t> _jetPUMVA;
vector<Float_t> _jetPUMVAUpdate2017;
vector<Float_t> _jetPUMVAUpdate2018;
vector<Float_t> _jetPUMVAUpdate;
vector<Float_t> _jetPtNoL2L3Res;
vector<Float_t> _jet_corrjecs;
vector<int> _jethadronFlavour;
vector<int> _jetpartonFlavour;
vector<Float_t> _jetDeepJet_b;
vector<Float_t> _jetParticleNet_b;
vector<Float_t> _jetDeepJet_c;
vector<Float_t> _jetDeepJet_uds;
vector<Float_t> _jetDeepJet_g;
vector<Float_t> _jetQuarkGluonLikelihood;
vector<Float_t> _jet_beta ;
vector<Float_t> _jet_dR2Mean ;
vector<Float_t> _jet_majW ;
vector<Float_t> _jet_minW ;
vector<Float_t> _jet_frac01 ;
vector<Float_t> _jet_frac02 ;
vector<Float_t> _jet_frac03 ;
vector<Float_t> _jet_frac04 ;
vector<Float_t> _jet_ptD ;
vector<Float_t> _jet_betaStar ;
vector<Float_t> _jet_pull ;
vector<Float_t> _jet_jetR ;
vector<Float_t> _jet_jetRchg ;
vector<int> _jet_nParticles ;
vector<int> _jet_nCharged ;
vector<Float_t> _ak8jetEta ;
vector<Float_t> _ak8jetPhi ;
vector<Float_t> _ak8jetPt ;
vector<Float_t> _ak8jetArea ;
vector<Float_t> _ak8jetRawPt ;
vector<Float_t> _ak8jetPtGen ;
//AK4 Puppi jets
vector<Float_t> _puppijetEta;
vector<Float_t> _puppijetPhi;
vector<Float_t> _puppijetPt;
vector<Float_t> _puppijetRawPt;
vector<Float_t> _puppijetJECuncty;
vector <Float_t> _puppijetPtGen;
vector <Float_t> _puppijetPtGenWithNu;
vector<bool> _puppijetPassID;
vector<bool> _puppijetLeptonPhotonCleaned;
vector <Float_t> _puppijetPtNoL2L3Res;
//AK8 Puppi jets
vector<Float_t> _puppiak8jetEta ;
vector<Float_t> _puppiak8jetPhi ;
vector<Float_t> _puppiak8jetPt ;
vector<Float_t> _puppiak8jetRawPt ;
vector<Float_t> _puppiak8jetPtGen ;
vector<Float_t> _puppiak8jet_tau1 ;
vector<Float_t> _puppiak8jet_tau2 ;
vector<Float_t> _puppiak8jet_tau3 ;
//AK4 Calo jets
vector<Float_t> _calojetEta;
vector<Float_t> _calojetPhi;
vector<Float_t> _calojetPt;
vector<Float_t> _calojetRawPt;
vector <Float_t> _calojetPtGen;
vector<bool> _calojetLeptonPhotonCleaned;
//Non CHS jets
vector<Float_t> _noCHSjetEta;
vector<Float_t> _noCHSjetPhi;
vector<Float_t> _noCHSjetPt;
vector<Float_t> _noCHSjetRawPt;
vector<Float_t> _noCHSjetPtGen;
vector<bool> _noCHSjetLeptonPhotonCleaned;
//Gen AK4 jets
vector<Float_t> _genjetEta;
vector<Float_t> _genjetPhi;
vector<Float_t> _genjetPt;
vector<Int_t> _genjet_noCHSIdx;
vector<Int_t> _genjet_CaloIdx;
vector<Int_t> _genjet_CHSIdx;
vector<Int_t> _genjet_PuppiIdx;
//Gen AK8 jets
vector<Float_t> _genAK8jetEta;
vector<Float_t> _genAK8jetPhi;
vector<Float_t> _genAK8jetPt;
vector<Int_t> _genAK8jet_CHSIdx;
vector<Int_t> _genAK8jet_PuppiIdx;
//Leptons
vector<Float_t> _lEta;
vector<Float_t> _lPhi;
vector<Float_t> _lPt;
vector<Float_t> _lPtcorr;
vector<Float_t> _ldz;
vector<Float_t> _ldzError;
vector<Float_t> _ldxy;
vector<Float_t> _ldxyError;
vector<Float_t> _l3dIP;
vector<Float_t> _l3dIPError;
vector<Bool_t> _lPassTightID;
vector<Bool_t> _lPassLooseID;
vector<Bool_t> _lisSAMuon ;
vector<int> _lpdgId;
int _nEles, _nMus;
//Gen leptons
vector<Float_t> _lgenEta;
vector<Float_t> _lgenPhi;
vector<Float_t> _lgenPt;
vector<int> _lgenpdgId;
//Reco Photons
vector<Float_t> _phEta;
vector<Float_t> _phPhi;
vector<Float_t> _phPt;
vector<Bool_t> _phPassIso;
vector<Float_t> _phPtcorr;
vector<Bool_t> _phPassTightID;
//Gen photons
vector<Float_t> _phgenEta;
vector<Float_t> _phgenPhi;
vector<Float_t> _phgenPt;
//Event variables (reco)
//For dilepton studies
Float_t _mll;
Float_t _ptll;
Float_t _pzll;
Float_t _yll;
Float_t _dphill;
Float_t _phill;
Float_t _costhCSll;
Int_t _nElesll ;
//For single photon studies
Float_t _ptgamma;
Float_t _phigamma;
//Event variables (gen)
Float_t _mll_gen;
Float_t _ptll_gen;
Float_t _pzll_gen;
Float_t _yll_gen;
Float_t _dphill_gen;
Float_t _phill_gen;
Float_t _costhCSll_gen;
Int_t _ngenElesll ;
Float_t _ptgamma_gen;
Float_t _phigamma_gen;
//Some gen variables
Float_t _genHT, _weight;
//PF candidates
vector <Float_t> _PFcand_pt;
vector <Float_t> _PFcand_eta;
vector <Float_t> _PFcand_phi;
vector <int> _PFcand_pdgId;
vector <int> _PFcand_fromPV;
vector <Float_t> _PFcand_dz;
vector <Float_t> _PFcand_dzError;
vector <Float_t> _PFcand_hcalFraction;
vector <int> _PFcand_PVfitidx;
vector <Float_t> _PFcand_puppiweight;
//Nb of CH in PV fit and corresponding HT, for different pt cuts
int _n_CH_fromvtxfit[6];
Float_t _HT_CH_fromvtxfit[6];
vector <Float_t> _METCH_PV;
vector <Float_t> _METPhiCH_PV;
vector <Float_t> _SumPT2CH_PV;
vector <Float_t> _DztoLV_PV;
//Nb of electrons in vtx fit
int _n_PFele_fromvtxfit;
int _n_PFmu_fromvtxfit;
//Reco MET (PFME, PUPPIMET, CHS MET, T1 first and then Raw)
Float_t _met;
Float_t _met_phi;
Float_t _puppimet;
Float_t _puppimet_phi;
Float_t _chsmet;
Float_t _chsmet_phi;
Float_t _rawmet;
Float_t _rawmet_phi;
Float_t _puppirawmet;
Float_t _puppirawmet_phi;
Float_t _rawchsmet;
Float_t _rawchsmet_phi;
//GenMET
Float_t _genmet;
Float_t _genmet_phi;
Float_t _genptvec;
Float_t _genptscal;
//Triggers
bool HLT_Photon110EB_TightID_TightIso;
bool HLT_Photon165_R9Id90_HE10_IsoM;
bool HLT_Photon120_R9Id90_HE10_IsoM;
bool HLT_Photon90_R9Id90_HE10_IsoM;
bool HLT_Photon75_R9Id90_HE10_IsoM;
bool HLT_Photon50_R9Id90_HE10_IsoM;
bool HLT_Photon200;
bool HLT_Photon175;
bool HLT_DiJet110_35_Mjj650_PFMET110;
bool HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_PFHT60;
bool HLT_PFMETNoMu120_PFMHTNoMu120_IDTight;
bool HLT_PFMET120_PFMHT120_IDTight_PFHT60;
bool HLT_PFMET120_PFMHT120_IDTight;
bool HLT_PFHT1050;
bool HLT_PFHT900;
bool HLT_PFJet500;
bool HLT_AK8PFJet500;
bool HLT_Ele35_WPTight_Gsf ;
bool HLT_Ele32_WPTight_Gsf ;
bool HLT_Ele27_WPTight_Gsf;
bool HLT_IsoMu27;
bool HLT_IsoMu24;
bool HLT_IsoTkMu24;
bool HLT_TkMu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ;
bool HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ;
bool HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL;
bool HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ;
bool HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass3p8;
bool HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL;
bool HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ;
bool HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_DZ;
bool HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_DZ;
bool HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL;
bool HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL;
bool _l1prefire;
//These are variables for a TTree where each entry is a jet and where one stores all PF cands
vector <Float_t> _Jet_PFcand_pt;
vector <Float_t> _Jet_PFcand_eta;
vector <Float_t> _Jet_PFcand_phi;
vector <int> _Jet_PFcand_pdgId;
vector <int> _Jet_PFcand_fromPV;
vector <Float_t> _Jet_PFcand_dz;
vector <Float_t> _Jet_PFcand_dzError;
Float_t _Jet_Pt;
Float_t _Jet_PtGen;
Float_t _Jet_Eta;
Float_t _Jet_EtaGen;
Float_t _Jet_Phi;
Float_t _Jet_PhiGen;
//Trigger matching variables: is a reco object matched to a trigger filter
vector < bool >hltL3crIsoL1sMu22L1f0L2f10QL3f24QL3trkIsoFiltered0p09;
vector < bool >hltL3crIsoL1sMu22Or25L1f0L2f10QL3f27QL3trkIsoFiltered0p09;
vector < bool >hltEle27WPTightGsfTrackIsoFilter;
vector < bool >hltEle35noerWPTightGsfTrackIsoFilter;
vector < bool >hltEle32WPTightGsfTrackIsoFilter;
vector < bool >hltEG175HEFilter;
vector < bool >hltEG200HEFilter;
vector < bool >hltEG165R9Id90HE10IsoMTrackIsoFilter;
vector < bool >hltEG120R9Id90HE10IsoMTrackIsoFilter;
vector < bool >hltEG90R9Id90HE10IsoMTrackIsoFilter;
vector < bool >hltEG75R9Id90HE10IsoMTrackIsoFilter;
vector < bool >hltEG50R9Id90HE10IsoMTrackIsoFilter;
vector < bool >hltSinglePFJet60;
vector < bool >hltSinglePFJet80;
vector < bool >hltSinglePFJet140 ;
vector < bool >hltSinglePFJet200;
vector < bool >hltSinglePFJet260;
vector < bool >hltSinglePFJet320;
vector < bool >hltSinglePFJet400;
vector < bool >hltSinglePFJet450;
vector < bool >hltSinglePFJet500;
vector<bool> hltHIPhoton40Eta3p1;
vector<bool> hltEle17WPLoose1GsfTrackIsoFilterForHI;
vector<bool> hltEle15WPLoose1GsfTrackIsoFilterForHI;
vector<bool> hltL3fL1sMu10lqL1f0L2f10L3Filtered12;
vector<bool> hltL3fL1sMu10lqL1f0L2f10L3Filtered15;
//L1 muon
vector <int> _L1mu_Qual;
vector <Float_t> _L1mu_pt;
vector <Float_t> _L1mu_eta;
vector <Float_t> _L1mu_phi;
vector <int> _L1mu_bx;
//L1 EG
vector <Float_t> _L1eg_pt;
vector <Float_t> _L1eg_eta;
vector <Float_t> _L1eg_phi;
vector <int> _L1eg_bx;
//L1 jet
vector <Float_t> _L1jet_pt;
vector <Float_t> _L1jet_eta;
vector <Float_t> _L1jet_phi;
vector <int> _L1jet_bx;
//Rochester correction (for muons)
RoccoR rc;
//JEC uncertainties
JetCorrectionUncertainty *jecUnc;
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
JMEAnalyzer::JMEAnalyzer(const edm::ParameterSet& iConfig)
:
metfilterspatToken_(consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("METFiltersPAT"))),
metfiltersrecoToken_(consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("METFiltersRECO"))),
ecalBadCalibFilterUpdateToken_(consumes<bool>(iConfig.getParameter<edm::InputTag>("ECALBadCalibFilterUpdate"))),
ecalLaserCorrFilterUpdateToken_(consumes<bool>(iConfig.getParameter<edm::InputTag>("ECALLaserCorrFilterUpdate"))),
ecalDeadCellBoundaryEnergyFilterUpdateToken_(consumes<bool>(iConfig.getParameter<edm::InputTag>("ECALDeadCellBoundaryEnergyFilterUpdate"))),
badChargedCandidateFilterUpdateToken_(consumes<bool>(iConfig.getParameter<edm::InputTag>("BadChargedCandidateFilterUpdate"))),
verticesToken_(consumes<std::vector<Vertex> > (iConfig.getParameter<edm::InputTag>("Vertices"))),
rhoJetsToken_(consumes<double>(edm::InputTag("fixedGridRhoFastjetAll",""))),
rhoJetsNCToken_(consumes<double>(edm::InputTag("fixedGridRhoFastjetCentralNeutral",""))),
jetToken_(consumes< std::vector< pat::Jet> >(iConfig.getParameter<edm::InputTag>("Jets"))),
jetAK8Token_(consumes< std::vector< pat::Jet> >(iConfig.getParameter<edm::InputTag>("JetsAK8"))),
jetPuppiToken_(consumes< std::vector< pat::Jet> >(iConfig.getParameter<edm::InputTag>("JetsPuppi"))),
jetPuppiAK8Token_(consumes< std::vector< pat::Jet> >(iConfig.getParameter<edm::InputTag>("JetsPuppiAK8"))),
jetCaloToken_(consumes< std::vector< reco::CaloJet> >(iConfig.getParameter<edm::InputTag>("JetsCalo"))),
jetnoCHSToken_(consumes< std::vector< pat::Jet> >(iConfig.getParameter<edm::InputTag>("JetsPFnoCHS"))),
genjetToken_(consumes< std::vector< reco::GenJet> >(iConfig.getParameter<edm::InputTag>("GenJets"))),
genAK8jetToken_(consumes< std::vector< reco::GenJet> >(iConfig.getParameter<edm::InputTag>("GenAK8Jets"))),
pileupJetIdDiscriminantUpdateToken_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("pileupJetIdDiscriminantUpdate"))),
pileupJetIdDiscriminantUpdate2017Token_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("pileupJetIdDiscriminantUpdate2017"))),
pileupJetIdDiscriminantUpdate2018Token_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("pileupJetIdDiscriminantUpdate2018"))),
pileupJetIdVariablesUpdateToken_(consumes<edm::ValueMap<StoredPileupJetIdentifier> >(iConfig.getParameter<edm::InputTag>("pileupJetIdVariablesUpdate"))),
qgLToken_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("QuarkGluonLikelihood"))),
pfcandsToken_(consumes<std::vector< pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("PFCandidates"))),
puppiweightsToken_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("PuppiWeights"))),
metToken_(consumes<std::vector<pat::MET> > (iConfig.getParameter<edm::InputTag>("PFMet"))),
puppimetToken_(consumes<std::vector<pat::MET> > (iConfig.getParameter<edm::InputTag>("PuppiMet"))),
electronToken_(consumes< std::vector< pat::Electron> >(iConfig.getParameter<edm::InputTag>("Electrons"))),
muonToken_(consumes< std::vector< pat::Muon> >(iConfig.getParameter<edm::InputTag>("Muons"))),
photonToken_(consumes< std::vector< pat::Photon> >(iConfig.getParameter<edm::InputTag>("Photons"))),
genpartToken_(consumes<GenParticleCollection> (iConfig.getParameter<edm::InputTag>("GenParticles"))),
packedgenpartToken_(consumes<std::vector< pat::PackedGenParticle>>(iConfig.getParameter<edm::InputTag>("PackedGenParticles"))),
geninfoToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("GenInfo"))),
lheEventToken_(consumes<LHEEventProduct> ( iConfig.getParameter<InputTag>("LHELabel"))),
lheEventALTToken_(consumes<LHEEventProduct> ( iConfig.getParameter<InputTag>("LHELabelALT"))),
genJetAssocCHSToken_(consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("GenJetMatchCHS"))),
genJetWithNuAssocCHSToken_(consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("GenJetWithNuMatchCHS"))),
genJetAssocPuppiToken_(consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("GenJetMatchPuppi"))),
genJetWithNuAssocPuppiToken_(consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("GenJetWithNuMatchPuppi"))),
genJetAssocCaloToken_(consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("GenJetMatchCalo"))),
puInfoToken_(consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("PULabel"))),
trgresultsToken_(consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("Triggers"))),
trigobjectToken_(consumes<pat::TriggerObjectStandAloneCollection>(edm::InputTag("slimmedPatTrigger"))),
l1GtToken_(consumes<BXVector<GlobalAlgBlk>>(iConfig.getParameter<edm::InputTag>("l1GtSrc"))),
l1MuonToken_(consumes<l1t::MuonBxCollection>(edm::InputTag("gmtStage2Digis","Muon"))),
l1EGammaToken_(consumes<l1t::EGammaBxCollection>(edm::InputTag("caloStage2Digis","EGamma"))),
l1JetToken_(consumes<l1t::JetBxCollection>(edm::InputTag("caloStage2Digis","Jet"))),
UnprefirableEventToken_(consumes<GlobalExtBlkBxCollection>(edm::InputTag("simGtExtUnprefireable"))),
JetPtCut_(iConfig.getParameter<double>("JetPtCut")),
AK8JetPtCut_(iConfig.getParameter<double>("AK8JetPtCut")),
ElectronPtCut_(iConfig.getParameter<double>("ElectronPtCut")),
ElectronVetoWP_(iConfig.getParameter<string>("ElectronVetoWorkingPoint")),
ElectronTightWP_(iConfig.getParameter<string>("ElectronTightWorkingPoint")),
ElectronLooseWP_(iConfig.getParameter<string>("ElectronLooseWorkingPoint")),
MuonPtCut_(iConfig.getParameter<double>("MuonPtCut")),
RochCorrFile_(iConfig.getParameter<string>("RochCorrFile")),
PhotonPtCut_(iConfig.getParameter<double>("PhotonPtCut")),
PhotonTightWP_(iConfig.getParameter<string>("PhotonTightWorkingPoint")),
PFCandPtCut_(iConfig.getParameter<double>("PFCandPtCut")),
SaveTree_(iConfig.getParameter<bool>("SaveTree")),
IsMC_(iConfig.getParameter<bool>("IsMC")),
SavePUIDVariables_(iConfig.getParameter<bool>("SavePUIDVariables")),
SaveAK8Jets_(iConfig.getParameter<bool>("SaveAK8Jets")),
SaveCaloJets_(iConfig.getParameter<bool>("SaveCaloJets")),
SavenoCHSJets_(iConfig.getParameter<bool>("SavenoCHSJets")),
DropUnmatchedJets_(iConfig.getParameter<bool>("DropUnmatchedJets")),
DropBadJets_(iConfig.getParameter<bool>("DropBadJets")),
SavePFinJets_(iConfig.getParameter<bool>("SavePFinJets")),
ApplyPhotonID_(iConfig.getParameter<bool>("ApplyPhotonID")),
Skim_(iConfig.getParameter<string>("Skim")),
Debug_(iConfig.getParameter<bool>("Debug"))
{
//now do what ever initialization is needed
edm::Service<TFileService> fs;
h_nvtx = fs->make<TH1F>("h_nvtx" , "Number of reco vertices;N_{vtx};Events" , 100, 0., 100.);
h_PFMet = fs->make<TH1F>("h_PFMet" , "Type 1 PFMET (GeV);Type 1 PFMET (GeV);Events" , 1000, 0., 5000.);
h_PuppiMet = fs->make<TH1F>("h_PuppiMet" , "PUPPI MET (GeV);PUPPI MET (GeV);Events" , 1000, 0., 5000.);
h_Counter = fs->make<TH1D>("h_Counter", "Events counter", 5,0,5);
h_trueNVtx = fs->make<TH1D>("h_trueNVtx", "Nb of generated vertices", 200,0,200);
outputTree = fs->make<TTree>("tree","tree");
if(SavePFinJets_) jetPFTree = fs->make<TTree>("jetPFtree","tree");
rc.init(RochCorrFile_);
}
JMEAnalyzer::~JMEAnalyzer()
{
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
//
// member functions
//
void JMEAnalyzer::beginRun(edm::Run const & iRun, edm::EventSetup const& iSetup)
{
//JES uncties: https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#JetCorUncertainties
edm::ESHandle<JetCorrectorParametersCollection> JetCorParColl;
iSetup.get<JetCorrectionsRecord>().get("AK4PFchs",JetCorParColl);
if(JetCorParColl.isValid()){
JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"];
jecUnc = new JetCorrectionUncertainty(JetCorPar);
}
else jecUnc = 0;
//The following lines are needed for picking events from a list (currently unprefirable events)
int runnb = iRun.id().run();
TString str_runnb =Form("%d", runnb) ;
myfile_unprefevts.open("UnprefireableEventList/run_"+str_runnb+".txt");
cout << "Run is " <<str_runnb <<endl;
}
void JMEAnalyzer::endRun(edm::Run const & iRun, edm::EventSetup const& iSetup)
{
myfile_unprefevts.close();
delete jecUnc;
}
// ------------ method called for each event ------------
void
JMEAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
InitandClearStuff();
_runNb = iEvent.id().run();
_eventNb = iEvent.id().event();
_lumiBlock = iEvent.luminosityBlock();
_bx=iEvent.bunchCrossing();
//Gen info, needed pre skim !!
edm::Handle<GenEventInfoProduct> GenInfoHandle;
iEvent.getByToken(geninfoToken_, GenInfoHandle);
if(GenInfoHandle.isValid())_weight=GenInfoHandle->weight();
else _weight = 0;
h_Counter->Fill(0.,_weight);
/*for(unsigned int a =0; a< (GenInfoHandle->binningValues()).size();a++){
double thebinning = GenInfoHandle->hasBinningValues() ? (GenInfoHandle->binningValues())[a] : 0.0 ;
}*/
//Pile up info at gen level
Handle<std::vector<PileupSummaryInfo> > puInfo;
iEvent.getByToken(puInfoToken_, puInfo);
if(puInfo.isValid()){
vector<PileupSummaryInfo>::const_iterator pvi;
for (pvi = puInfo->begin(); pvi != puInfo->end(); ++pvi) {
if (pvi->getBunchCrossing() == 0) trueNVtx = pvi->getTrueNumInteractions();
}
}
else trueNVtx = -1.;
h_trueNVtx->Fill(trueNVtx);
//Triggers
edm::Handle<TriggerResults> trigResults;
iEvent.getByToken(trgresultsToken_, trigResults);
if( !trigResults.failedToGet() ) {
int N_Triggers = trigResults->size();
const edm::TriggerNames & trigName = iEvent.triggerNames(*trigResults);
for( int i_Trig = 0; i_Trig < N_Triggers; ++i_Trig ) {
if (trigResults.product()->accept(i_Trig)) {
TString TrigPath =trigName.triggerName(i_Trig);
if(TrigPath.Contains("HLT_Photon110EB_TightID_TightIso_v"))HLT_Photon110EB_TightID_TightIso =true;
if(TrigPath.Contains("HLT_Photon165_R9Id90_HE10_IsoM_v"))HLT_Photon165_R9Id90_HE10_IsoM =true;
if(TrigPath.Contains("HLT_Photon120_R9Id90_HE10_IsoM_v"))HLT_Photon120_R9Id90_HE10_IsoM =true;
if(TrigPath.Contains("HLT_Photon90_R9Id90_HE10_IsoM_v"))HLT_Photon90_R9Id90_HE10_IsoM =true;
if(TrigPath.Contains("HLT_Photon75_R9Id90_HE10_IsoM_v"))HLT_Photon75_R9Id90_HE10_IsoM =true;
if(TrigPath.Contains("HLT_Photon50_R9Id90_HE10_IsoM_v"))HLT_Photon50_R9Id90_HE10_IsoM =true;
if(TrigPath.Contains("HLT_Photon200_v"))HLT_Photon200 =true;
if(TrigPath.Contains("HLT_Photon175_v"))HLT_Photon175 =true;
if(TrigPath.Contains("HLT_DiJet110_35_Mjj650_PFMET110_v"))HLT_DiJet110_35_Mjj650_PFMET110 =true;
if(TrigPath.Contains("HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_PFHT60_v"))HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_PFHT60 =true;
if(TrigPath.Contains("HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_v"))HLT_PFMETNoMu120_PFMHTNoMu120_IDTight =true;
if(TrigPath.Contains("HLT_PFMET120_PFMHT120_IDTight_PFHT60_v"))HLT_PFMET120_PFMHT120_IDTight_PFHT60 =true;
if(TrigPath.Contains("HLT_PFMET120_PFMHT120_IDTight_v"))HLT_PFMET120_PFMHT120_IDTight =true;
if(TrigPath.Contains("HLT_PFHT1050_v"))HLT_PFHT1050 =true;
if(TrigPath.Contains("HLT_PFHT900_v"))HLT_PFHT900 =true;
if(TrigPath.Contains("HLT_PFJet500_v"))HLT_PFJet500 =true;
if(TrigPath.Contains("HLT_AK8PFJet500_v"))HLT_AK8PFJet500 =true;
if(TrigPath.Contains("HLT_Ele35_WPTight_Gsf_v"))HLT_Ele35_WPTight_Gsf =true;
if(TrigPath.Contains("HLT_Ele32_WPTight_Gsf_v"))HLT_Ele32_WPTight_Gsf =true;
if(TrigPath.Contains("HLT_Ele27_WPTight_Gsf_v"))HLT_Ele27_WPTight_Gsf =true;
if(TrigPath.Contains("HLT_IsoMu27_v"))HLT_IsoMu27 =true;
if(TrigPath.Contains("HLT_IsoMu24_v"))HLT_IsoMu24 =true;
if(TrigPath.Contains("HLT_IsoTkMu24_v"))HLT_IsoTkMu24 =true;
if(TrigPath.Contains("HLT_TkMu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v"))HLT_TkMu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ =true;
if(TrigPath.Contains("HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v"))HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ =true;
if(TrigPath.Contains("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v"))HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL =true;
if(TrigPath.Contains("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v"))HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ =true;
if(TrigPath.Contains("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass3p8_v"))HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass3p8 =true;
if(TrigPath.Contains("HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_v"))HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL =true;
if(TrigPath.Contains("HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v"))HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ =true;
if(TrigPath.Contains("HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v"))HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_DZ =true;
if(TrigPath.Contains("HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_DZ_v"))HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_DZ =true;
if(TrigPath.Contains("HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_v"))HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL =true;
if(TrigPath.Contains("HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v"))HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL =true;
}
}
}
//Prefiring, see: https://github.com/nsmith-/PrefireAnalysis/#usage
edm::Handle<BXVector<GlobalAlgBlk>> l1GtHandle;
iEvent.getByToken(l1GtToken_, l1GtHandle);
_l1prefire= false;
if(!IsMC_)_l1prefire = l1GtHandle->begin(-1)->getFinalOR();
edm::Handle<l1t::MuonBxCollection> l1muoncoll;
iEvent.getByToken(l1MuonToken_ , l1muoncoll);
// const int nbx = IsMC_ ? 0:2;
for(int i = l1muoncoll->getFirstBX() ; i<= l1muoncoll->getLastBX() ;i++){
for( l1t::MuonBxCollection::const_iterator l1muonit= l1muoncoll->begin(i); l1muonit != l1muoncoll->end(i) ; ++l1muonit){
if(l1muonit->pt()<8) continue;
_L1mu_Qual.push_back( l1muonit->hwQual() );
_L1mu_pt.push_back( l1muonit->pt() );
_L1mu_eta.push_back( l1muonit->eta() );
_L1mu_phi.push_back( l1muonit->phi() );
_L1mu_bx.push_back( i);
}
}
//L1 eg
edm::Handle<l1t::EGammaBxCollection> l1egcoll;
iEvent.getByToken(l1EGammaToken_ , l1egcoll);
for(int i = l1egcoll->getFirstBX() ; i<= l1egcoll->getLastBX() ;i++){
for( l1t::EGammaBxCollection::const_iterator l1egit= l1egcoll->begin(i); l1egit != l1egcoll->end(i) ; ++l1egit){
if(l1egit->pt()<5) continue;
_L1eg_pt.push_back( l1egit->pt() );
_L1eg_eta.push_back( l1egit->eta() );
_L1eg_phi.push_back( l1egit->phi() );
_L1eg_bx.push_back( i);
}
}
//L1 jet
edm::Handle<l1t::JetBxCollection> l1jetcoll;
iEvent.getByToken(l1JetToken_ , l1jetcoll);
for(int i = l1jetcoll->getFirstBX() ; i<= l1jetcoll->getLastBX() ;i++){
for( l1t::JetBxCollection::const_iterator l1jetit= l1jetcoll->begin(i); l1jetit != l1jetcoll->end(i) ; ++l1jetit){
if(l1jetit->pt()<10) continue;
_L1jet_pt.push_back( l1jetit->pt() );
_L1jet_eta.push_back( l1jetit->eta() );
_L1jet_phi.push_back( l1jetit->phi() );
_L1jet_bx.push_back( i);
}
}
//Unprefirable
Flag_IsUnprefirable = false;
edm::Handle<GlobalExtBlkBxCollection> handleUnprefEventResults;
iEvent.getByToken(UnprefirableEventToken_, handleUnprefEventResults);
if(handleUnprefEventResults.isValid()){
if (handleUnprefEventResults->size() != 0) {
Flag_IsUnprefirable = handleUnprefEventResults->at(0, 0).getExternalDecision(GlobalExtBlk::maxExternalConditions - 1);
}
}
if(Skim_=="L1Unprefirable" && !PassSkim() ) return;
//Vertices
// NB there are usually two available collection of vertices in MINIAOD
edm::Handle<std::vector<Vertex> > theVertices;
iEvent.getByToken(verticesToken_,theVertices) ;
_n_PV = theVertices->size();
Vertex::Point PV(0,0,0);
if(_n_PV){ PV = theVertices->begin()->position();}
//Storing leading vertex coordinates, as well as leading PU vertex (primarily for bad vertex choice studies)
const Vertex* LVtx = &((*theVertices)[0]);
_LV_x = LVtx->x();
_LV_y = LVtx->y();
_LV_z = LVtx->z();
_LV_errx = LVtx->xError();
_LV_erry = LVtx->yError();
_LV_errz = LVtx->zError();
_PUV1_x = 0;
_PUV1_y = 0;
_PUV1_z = 0;
if(_n_PV>=2) {
_PUV1_x = ((*theVertices)[1]).x();
_PUV1_y = ((*theVertices)[1]).y();
_PUV1_z = ((*theVertices)[1]).z();
}
//Storing information from all vertex to study vertex sorting
vector <TVector2 > metPV;
for(unsigned int i = 0;i < theVertices->size(); i++){
const Vertex* PVtx = &((*theVertices)[i]);
TVector2 dummyT2V(0.,0.);
metPV.push_back(dummyT2V);
_METCH_PV.push_back(-99.);
_METPhiCH_PV.push_back(-99.);
_SumPT2CH_PV.push_back(0.);
_DztoLV_PV.push_back( PVtx->z()- LVtx->z());
}
//Rho
edm::Handle<double> rhoJets;
iEvent.getByToken(rhoJetsToken_,rhoJets);
_rho = *rhoJets;
//Rho Neutral Central
edm::Handle<double> rhoJetsNC;
iEvent.getByToken(rhoJetsNCToken_,rhoJetsNC);
_rhoNC = *rhoJetsNC;
//MET filters are stored in TriggerResults::RECO or TriggerResults::PAT . Should take the latter if it exists
edm::Handle<TriggerResults> METFilterResults;
iEvent.getByToken(metfilterspatToken_, METFilterResults);
if(!(METFilterResults.isValid())) iEvent.getByToken(metfiltersrecoToken_, METFilterResults);
Flag_goodVertices= GetMETFilterDecision(iEvent,METFilterResults,"Flag_goodVertices");
Flag_globalTightHalo2016Filter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_globalTightHalo2016Filter");
Flag_globalSuperTightHalo2016Filter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_globalSuperTightHalo2016Filter");
Flag_HBHENoiseFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_HBHENoiseFilter");
Flag_HBHENoiseIsoFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_HBHENoiseIsoFilter");
Flag_EcalDeadCellTriggerPrimitiveFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_EcalDeadCellTriggerPrimitiveFilter");
Flag_BadPFMuonFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_BadPFMuonFilter");
Flag_BadPFMuonDzFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_BadPFMuonDzFilter");
Flag_BadChargedCandidateFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_BadChargedCandidateFilter");
Flag_eeBadScFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_eeBadScFilter");
Flag_ecalBadCalibFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_ecalBadCalibFilter");
Flag_EcalDeadCellBoundaryEnergyFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_EcalDeadCellBoundaryEnergyFilter");
Flag_ecalLaserCorrFilter= GetMETFilterDecision(iEvent,METFilterResults,"Flag_ecalLaserCorrFilter");
Flag_hfNoisyHitsFilter = GetMETFilterDecision(iEvent,METFilterResults,"Flag_hfNoisyHitsFilter");
//Now accessing the decisions of some filters that we reran on top of MINIAOD
edm::Handle<bool> handle_PassecalBadCalibFilter_Update ;
iEvent.getByToken(ecalBadCalibFilterUpdateToken_,handle_PassecalBadCalibFilter_Update);
if(handle_PassecalBadCalibFilter_Update.isValid()) PassecalBadCalibFilter_Update = (*handle_PassecalBadCalibFilter_Update );
else{
if(Debug_) std::cout <<"handle_PassecalBadCalibFilter_Update.isValid() =false" <<endl;
PassecalBadCalibFilter_Update = true;
}
edm::Handle<bool> handle_PassecalLaserCorrFilter_Update ;
iEvent.getByToken(ecalLaserCorrFilterUpdateToken_,handle_PassecalLaserCorrFilter_Update);
if(handle_PassecalLaserCorrFilter_Update.isValid())PassecalLaserCorrFilter_Update = (*handle_PassecalLaserCorrFilter_Update );
else{
if(Debug_) std::cout <<"handle_PassecalLaserCorrFilter_Update.isValid() =false" <<endl;
PassecalLaserCorrFilter_Update = true;