-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHZZ4lNtupleMaker.cc
3447 lines (3000 loc) · 145 KB
/
HZZ4lNtupleMaker.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++ -*-
//
//
// Fill a tree for selected candidates.
//
// system include files
#include <cassert>
#include <memory>
#include <cmath>
#include <algorithm>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include <FWCore/Framework/interface/ESHandle.h>
#include <FWCore/Framework/interface/LuminosityBlock.h>
#include <FWCore/ParameterSet/interface/ParameterSet.h>
#include <DataFormats/Common/interface/TriggerResults.h>
#include <FWCore/Common/interface/TriggerNames.h>
#include <FWCore/ParameterSet/interface/ParameterSet.h>
#include <DataFormats/Common/interface/View.h>
#include <DataFormats/Candidate/interface/Candidate.h>
#include <DataFormats/PatCandidates/interface/CompositeCandidate.h>
#include <DataFormats/PatCandidates/interface/Muon.h>
#include <DataFormats/PatCandidates/interface/Electron.h>
#include <DataFormats/PatCandidates/interface/Photon.h>
#include <DataFormats/PatCandidates/interface/Jet.h>
#include <DataFormats/PatCandidates/interface/MET.h>
#include <DataFormats/METReco/interface/PFMET.h>
#include <DataFormats/METReco/interface/PFMETCollection.h>
#include <ZZAnalysis/AnalysisStep/interface/METCorrectionHandler.h>
#include <DataFormats/JetReco/interface/PFJet.h>
#include <DataFormats/JetReco/interface/PFJetCollection.h>
#include <DataFormats/Math/interface/LorentzVector.h>
#include <CommonTools/UtilAlgos/interface/TFileService.h>
#include <DataFormats/Common/interface/MergeableCounter.h>
#include <DataFormats/VertexReco/interface/Vertex.h>
#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include <SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h>
#include <SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h>
#include <ZZAnalysis/AnalysisStep/interface/DaughterDataHelpers.h>
#include <ZZAnalysis/AnalysisStep/interface/FinalStates.h>
#include <ZZAnalysis/AnalysisStep/interface/MCHistoryTools.h>
//#include <ZZAnalysis/AnalysisStep/interface/PileUpWeight.h>
#include <ZZAnalysis/AnalysisStep/interface/PileUpWeight.h>
#include "SimDataFormats/HTXS/interface/HiggsTemplateCrossSections.h"
#include "ZZAnalysis/AnalysisStep/interface/EwkCorrections.h"
#include "ZZAnalysis/AnalysisStep/src/kFactors.C"
#include <ZZAnalysis/AnalysisStep/interface/bitops.h>
#include <ZZAnalysis/AnalysisStep/interface/Fisher.h>
#include <ZZAnalysis/AnalysisStep/interface/LeptonIsoHelper.h>
#include <ZZAnalysis/AnalysisStep/interface/PhotonIDHelper.h>
#include <ZZAnalysis/AnalysisStep/interface/JetCleaner.h>
#include <ZZAnalysis/AnalysisStep/interface/utils.h>
#include <ZZAnalysis/AnalysisStep/interface/miscenums.h>
#include <ZZAnalysis/AnalysisStep/interface/ggF_qcd_uncertainty_2017.h>
#include <ZZAnalysis/AnalysisStep/interface/LeptonSFHelper.h>
#include <MelaAnalytics/CandidateLOCaster/interface/MELACandidateRecaster.h>
#include <CommonLHETools/LHEHandler/interface/LHEHandler.h>
#include <ZZAnalysis/AnalysisStep/interface/utils.h>//clara
#include "ZZ4lConfigHelper.h"
//#include "./ZZ4lConfigHelper.h"
//#include <./ZZ4lConfigHelper.h>
//#include "/afs/cern.ch/user/m/mrkim/work/HZZ/201211/CMSSW_10_2_18/src/ZZAnalysis/AnalysisStep/test/Ntuplizers/ZZ4lConfigHelper.h"
//#include </afs/cern.ch/user/m/mrkim/work/HZZ/201211/CMSSW_10_2_18/src/ZZAnalysis/AnalysisStep/test/Ntuplizers/ZZ4lConfigHelper.h>
//#include <ZZAnalysis/AnalysisStep/test/Ntuplizers/ZZ4lConfigHelper.h>
#include "HZZ4lNtupleFactory.h"
#include <TRandom3.h>
#include <TH2D.h>
#include "TLorentzVector.h"
#include "TSpline.h"
#include "TGraphErrors.h"
using namespace zzanalysis;//clara
namespace {
bool writeJets = true; // Write jets in the tree. FIXME: make this configurable
bool writePhotons = true; // Write photons in the tree. FIXME: make this configurable
bool addKinRefit = true;
bool addVtxFit = false;
bool addFSRDetails = false;
bool addQGLInputs = true;
bool skipMuDataMCWeight = false; // skip computation of data/MC weight for mu
bool skipEleDataMCWeight = false; // skip computation of data/MC weight for ele
bool skipFakeWeight = true; // skip computation of fake rate weight for CRs
bool skipHqTWeight = true; // skip computation of hQT weight
//List of variables with default values
Int_t RunNumber = 0;
Long64_t EventNumber = 0;
Int_t LumiNumber = 0;
Short_t NRecoMu = 0;
Short_t NRecoEle = 0;
Short_t Nvtx = 0;
Short_t NObsInt = 0;
Float_t NTrueInt = 0;
Float_t PUWeight = 0;
Float_t PUWeight_Up = 0;
Float_t PUWeight_Dn = 0;
Float_t KFactor_QCD_ggZZ_Nominal = 0;
Float_t KFactor_QCD_ggZZ_PDFScaleDn = 0;
Float_t KFactor_QCD_ggZZ_PDFScaleUp = 0;
Float_t KFactor_QCD_ggZZ_QCDScaleDn = 0;
Float_t KFactor_QCD_ggZZ_QCDScaleUp = 0;
Float_t KFactor_QCD_ggZZ_AsDn = 0;
Float_t KFactor_QCD_ggZZ_AsUp = 0;
Float_t KFactor_QCD_ggZZ_PDFReplicaDn = 0;
Float_t KFactor_QCD_ggZZ_PDFReplicaUp = 0;
Float_t KFactor_EW_qqZZ = 0;
Float_t KFactor_EW_qqZZ_unc = 0;
Float_t KFactor_QCD_qqZZ_dPhi = 0;
Float_t KFactor_QCD_qqZZ_M = 0;
Float_t KFactor_QCD_qqZZ_Pt = 0;
// Generic MET object
METObject metobj;
METObject metobj_corrected;
Float_t GenMET = -99;
Float_t GenMETPhi = -99;
// MET with no HF
//Float_t PFMETNoHF = -99;
//Float_t PFMETNoHFPhi = -99;
Short_t nCleanedJets = 0;
Short_t nCleanedJetsPt30 = 0;
Short_t nCleanedJetsPt30_jesUp = 0;
Short_t nCleanedJetsPt30_jesDn = 0;
Short_t nCleanedJetsPt30_jerUp = 0;
Short_t nCleanedJetsPt30_jerDn = 0;
Short_t nCleanedJetsPt30BTagged = 0;
Short_t nCleanedJetsPt30BTagged_bTagSF = 0;
Short_t nCleanedJetsPt30BTagged_bTagSF_jesUp = 0;
Short_t nCleanedJetsPt30BTagged_bTagSF_jesDn = 0;
Short_t nCleanedJetsPt30BTagged_bTagSF_jerUp = 0;
Short_t nCleanedJetsPt30BTagged_bTagSF_jerDn = 0;
Short_t nCleanedJetsPt30BTagged_bTagSFUp = 0;
Short_t nCleanedJetsPt30BTagged_bTagSFDn = 0;
Short_t trigWord = 0;
Float_t ZZMass = 0;
Float_t ZZMassErr = 0;
Float_t ZZMassErrCorr = 0;
Float_t ZZMassPreFSR = 0;
Short_t ZZsel = 0;
Float_t ZZPt = 0;
Float_t ZZEta = 0;
Float_t ZZPhi = 0;
Float_t ZZjjPt = 0;
Int_t CRflag = 0;
Float_t Z1Mass = 0;
Float_t Z1Pt = 0;
Short_t Z1Flav = 0;
Float_t ZZMassRefit = 0;
Float_t ZZMassRefitErr = 0;
Float_t ZZMassUnrefitErr = 0;
Float_t ZZMassCFit = 0;
Float_t ZZChi2CFit = 0;
Float_t Z2Mass = 0;
Float_t Z2Pt = 0;
Short_t Z2Flav = 0;
Float_t costhetastar = 0;
Float_t helphi = 0;
Float_t helcosthetaZ1 = 0;
Float_t helcosthetaZ2 = 0;
Float_t phistarZ1 = 0;
Float_t phistarZ2 = 0;
Float_t xi = 0;
Float_t xistar = 0;
Float_t TLE_dR_Z = -1; // Delta-R between a TLE and the Z it does not belong to.
Float_t TLE_min_dR_3l = 999; // Minimum DR between a TLE and any of the other leptons
Short_t evtPassMETTrigger = 0;
using namespace std;//Clara
//DEFINITION FOR JETTINESS
TLorentzVector v4_na(0.0,0.0,1.0,1.0);//xyzE, clara
TLorentzVector v4_nb(0.0,0.0,-1.0,1.0);//xy-zE, clara
Int_t j=0;//clara, Glover counter v4_PEPM;
std::vector<float> Jettiness;//clara
std::vector<float> LepPt;
std::vector<float> LepEta;
std::vector<float> LepPhi;
std::vector<float> LepPx;//clara
std::vector<float> LepPy;//clara
std::vector<float> LepPz;//clara
std::vector<float> LepE;//clara
std::vector<float> LepSCEta;
std::vector<short> LepLepId;
std::vector<float> LepSIP;
std::vector<float> Lepdxy;
std::vector<float> Lepdz;
std::vector<float> LepTime;
std::vector<bool> LepisID;
std::vector<float> LepBDT;
std::vector<bool> LepisCrack;
std::vector<char> LepMissingHit;
std::vector<float> LepChargedHadIso;
std::vector<float> LepNeutralHadIso;
std::vector<float> LepPhotonIso;
std::vector<float> LepPUIsoComponent;
std::vector<float> LepCombRelIsoPF;
std::vector<short> LepisLoose;
std::vector<float> LepSF;
std::vector<float> LepSF_Unc;
std::vector<float> LepScale_Total_Up;
std::vector<float> LepScale_Total_Dn;
std::vector<float> LepScale_Stat_Up;
std::vector<float> LepScale_Stat_Dn;
std::vector<float> LepScale_Syst_Up;
std::vector<float> LepScale_Syst_Dn;
std::vector<float> LepScale_Gain_Up;
std::vector<float> LepScale_Gain_Dn;
std::vector<float> LepSigma_Total_Up;
std::vector<float> LepSigma_Total_Dn;
std::vector<float> LepSigma_Rho_Up;
std::vector<float> LepSigma_Rho_Dn;
std::vector<float> LepSigma_Phi_Up;
std::vector<float> LepSigma_Phi_Dn;
std::vector<float> tau0;
std::vector<float> tau1;
std::vector<float> tau2;
std::vector<float> tau3;
std::vector<float> tau4;
std::vector<float> mintau;
std::vector<float> tausum;
std::vector<float> fsrPt;
std::vector<float> fsrEta;
std::vector<float> fsrPhi;
std::vector<float> fsrDR;
std::vector<short> fsrLept;
std::vector<short> fsrLeptID;
std::vector<float> fsrGenPt;
Bool_t passIsoPreFSR = 0;
std::vector<float> JetPt ;
std::vector<float> JetEta ;
std::vector<float> JetPhi ;
std::vector<float> JetMass ;
std::vector<float> JetBTagger ;
std::vector<float> JetIsBtagged;
std::vector<float> JetIsBtaggedWithSF;
std::vector<float> JetIsBtaggedWithSFUp;
std::vector<float> JetIsBtaggedWithSFDn;
std::vector<float> JetQGLikelihood;
std::vector<float> JetAxis2;
std::vector<float> JetMult;
std::vector<float> JetPtD;
std::vector<float> JetSigma ;
std::vector<short> JetHadronFlavour;
std::vector<short> JetPartonFlavour;
std::vector<float> JetPtJEC_noJER;
std::vector<float> JetRawPt;
std::vector<float> JetPUValue;
std::vector<short> JetPUID;
std::vector<short> JetID;
std::vector<float> JetJESUp ;
std::vector<float> JetJESDown ;
std::vector<float> JetJERUp ;
std::vector<float> JetJERDown ;
Float_t DiJetMass = -99;
// Float_t DiJetMassPlus = -99;
// Float_t DiJetMassMinus = -99;
Float_t DiJetDEta = -99;
Float_t DiJetFisher = -99;
Short_t nExtraLep = 0;
Short_t nExtraZ = 0;
std::vector<float> ExtraLepPt;
std::vector<float> ExtraLepEta;
std::vector<float> ExtraLepPhi ;
std::vector<float> ExtraLepPx;//clara
std::vector<float> ExtraLepPy;//clara
std::vector<float> ExtraLepPz;//clara
std::vector<float> ExtraLepE;//clara
std::vector<short> ExtraLepLepId;
// Photon info
std::vector<float> PhotonPt ;
std::vector<float> PhotonEta ;
std::vector<float> PhotonPhi ;
std::vector<bool> PhotonIsCutBasedLooseID;
Short_t genFinalState = 0;
Int_t genProcessId = 0;
Float_t genHEPMCweight = 0;
Float_t genHEPMCweight_NNLO = 0;
Float_t genHEPMCweight_POWHEGonly = 0;
std::vector<float> LHEMotherPz;
std::vector<float> LHEMotherE;
std::vector<short> LHEMotherId;
std::vector<float> LHEDaughterPt;
std::vector<float> LHEDaughterEta;
std::vector<float> LHEDaughterPhi;
std::vector<float> LHEDaughterMass;
std::vector<short> LHEDaughterId;
std::vector<float> LHEAssociatedParticlePt;
std::vector<float> LHEAssociatedParticleEta;
std::vector<float> LHEAssociatedParticlePhi;
std::vector<float> LHEAssociatedParticleMass;
std::vector<short> LHEAssociatedParticleId;
Float_t LHEPDFScale = 0;
Float_t LHEweight_QCDscale_muR1_muF1 = 0;
Float_t LHEweight_QCDscale_muR1_muF2 = 0;
Float_t LHEweight_QCDscale_muR1_muF0p5 = 0;
Float_t LHEweight_QCDscale_muR2_muF1 = 0;
Float_t LHEweight_QCDscale_muR2_muF2 = 0;
Float_t LHEweight_QCDscale_muR2_muF0p5 = 0;
Float_t LHEweight_QCDscale_muR0p5_muF1 = 0;
Float_t LHEweight_QCDscale_muR0p5_muF2 = 0;
Float_t LHEweight_QCDscale_muR0p5_muF0p5 = 0;
Float_t LHEweight_PDFVariation_Up = 0;
Float_t LHEweight_PDFVariation_Dn = 0;
Float_t LHEweight_AsMZ_Up = 0;
Float_t LHEweight_AsMZ_Dn = 0;
Float_t PythiaWeight_isr_muRoneoversqrt2 = 0;
Float_t PythiaWeight_fsr_muRoneoversqrt2 = 0;
Float_t PythiaWeight_isr_muRsqrt2 = 0;
Float_t PythiaWeight_fsr_muRsqrt2 = 0;
Float_t PythiaWeight_isr_muR0p5 = 0;
Float_t PythiaWeight_fsr_muR0p5 = 0;
Float_t PythiaWeight_isr_muR2 = 0;
Float_t PythiaWeight_fsr_muR2 = 0;
Float_t PythiaWeight_isr_muR0p25 = 0;
Float_t PythiaWeight_fsr_muR0p25 = 0;
Float_t PythiaWeight_isr_muR4 = 0;
Float_t PythiaWeight_fsr_muR4 = 0;
Short_t genExtInfo = 0;
Float_t xsection = 0;
Float_t genxsection = 0;
Float_t genbranchingratio = 0;
Float_t dataMCWeight = 0;
Float_t trigEffWeight = 0;
Float_t HqTMCweight = 0;
Float_t ZXFakeweight = 0;
Float_t overallEventWeight = 0;
Float_t L1prefiringWeight = 0;
Float_t L1prefiringWeightUp = 0;
Float_t L1prefiringWeightDn = 0;
Float_t GenHMass = 0;
Float_t GenHPt = 0;
Float_t GenHRapidity = 0;
Float_t GenZ1Mass = 0;
Float_t GenZ1Eta = 0;
Float_t GenZ1Pt = 0;
Float_t GenZ1Phi = 0;
Float_t GenZ1Flav = 0;
Float_t GenZ2Mass = 0;
Float_t GenZ2Eta = 0;
Float_t GenZ2Pt = 0;
Float_t GenZ2Phi = 0;
Float_t GenZ2Flav = 0;
Float_t GenLep1Pt = 0;
Float_t GenLep1Eta = 0;
Float_t GenLep1Phi = 0;
Short_t GenLep1Id = 0;
Float_t GenLep2Pt = 0;
Float_t GenLep2Eta = 0;
Float_t GenLep2Phi = 0;
Short_t GenLep2Id = 0;
Float_t GenLep3Pt = 0;
Float_t GenLep3Eta = 0;
Float_t GenLep3Phi = 0;
Short_t GenLep3Id = 0;
Float_t GenLep4Pt = 0;
Float_t GenLep4Eta = 0;
Float_t GenLep4Phi = 0;
Short_t GenLep4Id = 0;
Float_t GenAssocLep1Pt = 0;
Float_t GenAssocLep1Eta = 0;
Float_t GenAssocLep1Phi = 0;
Short_t GenAssocLep1Id = 0;
Float_t GenAssocLep2Pt = 0;
Float_t GenAssocLep2Eta = 0;
Float_t GenAssocLep2Phi = 0;
Short_t GenAssocLep2Id = 0;
Int_t htxsNJets = -1;
Float_t htxsHPt = 0;
Int_t htxs_errorCode=-1;
Int_t htxs_prodMode=-1;
Int_t htxs_stage0_cat = -1;
Int_t htxs_stage1p1_cat = -1;
Int_t htxs_stage1p0_cat = -1;
Int_t htxs_stage1p2_cat = -1;
Float_t ggH_NNLOPS_weight = 0;
Float_t ggH_NNLOPS_weight_unc = 0;
std::vector<float> qcd_ggF_uncertSF;
//FIXME: temporary fix to the mismatch of charge() and sign(pdgId()) for muons with BTT=4
int getPdgId(const reco::Candidate* p) {
int id = p->pdgId();
if (id!=22 && //for TLEs
signbit(id) && p->charge()<0) id*=-1; // negative pdgId must be positive charge
return id;
}
}//End of namespace
using namespace std;
using namespace edm;
//
// class declaration
//
class HZZ4lNtupleMaker : public edm::EDAnalyzer {
public:
explicit HZZ4lNtupleMaker(const edm::ParameterSet&);
~HZZ4lNtupleMaker();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
static float EvalSpline(TSpline3* const& sp, float xval);
static void addweight(float &weight, float weighttoadd);
private:
virtual void beginJob() ;
virtual void beginRun(edm::Run const&, edm::EventSetup const&);
virtual void endRun(edm::Run const&, edm::EventSetup const&);
virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
virtual void analyze(const edm::Event&, const edm::EventSetup&);
void BookAllBranches();
virtual void FillKFactors(edm::Handle<GenEventInfoProduct>& genInfo, std::vector<const reco::Candidate *>& genZLeps);
virtual void FillLHECandidate();
virtual void FillCandidate(const pat::CompositeCandidate& higgs, bool evtPass, const edm::Event&, const Int_t CRflag);
//virtual void FillJettiness(const pat::Jet& jet,const pat::MuonCollection& muon,const pat::ElectronCollection& electron,const pat::CompositeCandidate& higgs,const edm::Event&);
virtual void FillJet(const pat::Jet& jet);
virtual void FillPhoton(int year, const pat::Photon& photon);
virtual void endJob() ;
void FillHGenInfo(const math::XYZTLorentzVector Hp, float w);
void FillZGenInfo(Short_t Z1Id, Short_t Z2Id,
const math::XYZTLorentzVector pZ1, const math::XYZTLorentzVector pZ2);
void FillLepGenInfo(Short_t Lep1Id, Short_t Lep2Id, Short_t Lep3Id, Short_t Lep4Id,
const math::XYZTLorentzVector Lep1, const math::XYZTLorentzVector Lep2, const math::XYZTLorentzVector Lep3, const math::XYZTLorentzVector Lep4);
void FillAssocLepGenInfo(std::vector<const reco::Candidate *>& AssocLeps);
Float_t getAllWeight(const vector<const reco::Candidate*>& leptons);
Float_t getHqTWeight(double mH, double genPt) const;
Float_t getFakeWeight(Float_t LepPt, Float_t LepEta, Int_t LepID, Int_t LepZ1ID);
Int_t FindBinValue(TGraphErrors *tgraph, double value);
void getCheckedUserFloat(const pat::CompositeCandidate& cand, const std::string& strval, Float_t& setval, Float_t defaultval=0);
void buildMELABranches();
void computeMELABranches(MELACandidate* cand);
void updateMELAClusters_Common(const string clustertype);
void updateMELAClusters_NoInitialQ(const string clustertype);
void updateMELAClusters_NoInitialG(const string clustertype);
void updateMELAClusters_NoAssociatedG(const string clustertype);
void updateMELAClusters_NoInitialGNoAssociatedG(const string clustertype);
void updateMELAClusters_BestLOAssociatedZ(const string clustertype);
void updateMELAClusters_BestLOAssociatedW(const string clustertype);
void updateMELAClusters_BestLOAssociatedVBF(const string clustertype);
void updateMELAClusters_BestNLOVHApproximation(const string clustertype);
void updateMELAClusters_BestNLOVBFApproximation(const string clustertype);
void pushRecoMELABranches(const pat::CompositeCandidate& cand);
void pushLHEMELABranches();
void clearMELABranches();
// ----------member data ---------------------------
ZZ4lConfigHelper myHelper;
int theChannel;
std::string theCandLabel;
TString theFileName;
HZZ4lNtupleFactory *myTree;
TH1F *hCounter;
bool isMC;
bool is_loose_ele_selection; // Collection includes candidates with loose electrons/TLEs
bool applySkim; // " " " skim (if skipEmptyEvents=true)
bool skipEmptyEvents; // Skip events whith no selected candidate (otherwise, gen info is preserved for all events; candidates not passing trigger&&skim are flagged with negative ZZsel)
FailedTreeLevel failedTreeLevel; //if/how events with no selected candidate are written to a separate tree (see miscenums.h for details)
edm::InputTag metTag;
bool applyTrigger; // Keep only events passing trigger (overriden if skipEmptyEvents=False)
bool applyTrigEffWeight;// apply trigger efficiency weight (concerns samples where trigger is not applied)
Float_t xsec;
Float_t genxsec;
Float_t genbr;
int year;
double sqrts;
double Hmass;
Mela mela;
std::vector<std::string> recoMElist;
std::vector<MELAOptionParser*> recome_originalopts;
std::vector<MELAOptionParser*> recome_copyopts;
std::vector<std::string> lheMElist;
//std::vector<MELAOptionParser*> lheme_originalopts;
std::vector<MELAOptionParser*> lheme_copyopts;
std::vector<MELAHypothesis*> lheme_units;
std::vector<MELAHypothesis*> lheme_aliased_units;
std::vector<MELAComputation*> lheme_computers;
std::vector<MELACluster*> lheme_clusters;
bool addLHEKinematics;
LHEHandler* lheHandler;
METCorrectionHandler* metCorrHandler;
int apply_K_NNLOQCD_ZZGG; // 0: Do not; 1: NNLO/LO; 2: NNLO/NLO; 3: NLO/LO
bool apply_K_NNLOQCD_ZZQQB;
bool apply_K_NLOEW_ZZQQB;
bool apply_QCD_GGF_UNCERT;
edm::EDGetTokenT<edm::View<reco::Candidate> > genParticleToken;
edm::Handle<edm::View<reco::Candidate> > genParticles;
edm::EDGetTokenT<GenEventInfoProduct> genInfoToken;
edm::EDGetTokenT<edm::View<pat::CompositeCandidate> > candToken;
edm::EDGetTokenT<edm::View<pat::CompositeCandidate> > lhecandToken;
edm::EDGetTokenT<edm::TriggerResults> triggerResultToken;
edm::EDGetTokenT<vector<reco::Vertex> > vtxToken;
edm::EDGetTokenT<edm::View<pat::Jet> > jetToken;
edm::EDGetTokenT<pat::PhotonCollection> photonToken;
edm::EDGetTokenT<pat::METCollection> metToken;
//edm::EDGetTokenT<pat::METCollection> metNoHFToken;
edm::EDGetTokenT<pat::MuonCollection> muonToken;
edm::EDGetTokenT<pat::ElectronCollection> electronToken;
edm::EDGetTokenT<HTXS::HiggsClassification> htxsToken;
edm::EDGetTokenT<edm::MergeableCounter> preSkimToken;
edm::EDGetTokenT<LHERunInfoProduct> lheRunInfoToken;
edm::EDGetTokenT< double > prefweight_token;
edm::EDGetTokenT< double > prefweightup_token;
edm::EDGetTokenT< double > prefweightdown_token;
PileUpWeight* pileUpReweight;
//counters
Float_t Nevt_Gen;
Float_t Nevt_Gen_lumiBlock;
Float_t gen_ZZ4mu;
Float_t gen_ZZ4e;
Float_t gen_ZZ2mu2e;
Float_t gen_ZZ2l2tau;
Float_t gen_ZZ2emu2tau;
Float_t gen_ZZ4tau;
Float_t gen_ZZ4mu_EtaAcceptance;
Float_t gen_ZZ4mu_LeptonAcceptance;
Float_t gen_ZZ4e_EtaAcceptance;
Float_t gen_ZZ4e_LeptonAcceptance;
Float_t gen_ZZ2mu2e_EtaAcceptance;
Float_t gen_ZZ2mu2e_LeptonAcceptance;
Float_t gen_BUGGY;
Float_t gen_Unknown;
Float_t gen_sumPUWeight;
Float_t gen_sumGenMCWeight;
Float_t gen_sumWeights;
string sampleName;
std::vector<const reco::Candidate *> genFSR;
std::vector<std::vector<float> > ewkTable;
TSpline3* spkfactor_ggzz_nnlo[9]; // Nominal, PDFScaleDn, PDFScaleUp, QCDScaleDn, QCDScaleUp, AsDn, AsUp, PDFReplicaDn, PDFReplicaUp
TSpline3* spkfactor_ggzz_nlo[9]; // Nominal, PDFScaleDn, PDFScaleUp, QCDScaleDn, QCDScaleUp, AsDn, AsUp, PDFReplicaDn, PDFReplicaUp
LeptonSFHelper *lepSFHelper;
TH2D* h_weight; //HqT weights
//TH2F *h_ZXWeightMuo;
//TH2F *h_ZXWeightEle;
TH2D* h_ZXWeight[4];
TGraphErrors *gr_NNLOPSratio_pt_powheg_0jet;
TGraphErrors *gr_NNLOPSratio_pt_powheg_1jet;
TGraphErrors *gr_NNLOPSratio_pt_powheg_2jet;
TGraphErrors *gr_NNLOPSratio_pt_powheg_3jet;
bool printedLHEweightwarning;
};//End of class HZZ4lNtupleMaker
//
// constructors and destructor
//
HZZ4lNtupleMaker::HZZ4lNtupleMaker(const edm::ParameterSet& pset) :
myHelper(pset),
theChannel(myHelper.channel()), // Valid options: ZZ, ZLL, ZL
theCandLabel(pset.getUntrackedParameter<string>("CandCollection")), // Name of input ZZ collection
theFileName(pset.getUntrackedParameter<string>("fileName")),
myTree(nullptr),
skipEmptyEvents(pset.getParameter<bool>("skipEmptyEvents")), // Do not store events with no selected candidate (normally: true)
failedTreeLevel(FailedTreeLevel(pset.getParameter<int>("failedTreeLevel"))),
metTag(pset.getParameter<edm::InputTag>("metSrc")),
applyTrigger(pset.getParameter<bool>("applyTrigger")), // Reject events that do not pass trigger (normally: true)
applyTrigEffWeight(pset.getParameter<bool>("applyTrigEff")), //Apply an additional efficiency weights for MC samples where triggers are not present (normally: false)
xsec(pset.getParameter<double>("xsec")),
genxsec(pset.getParameter<double>("GenXSEC")),
genbr(pset.getParameter<double>("GenBR")),
year(pset.getParameter<int>("setup")),
sqrts(SetupToSqrts(year)),
Hmass(pset.getParameter<double>("superMelaMass")),
mela(sqrts, Hmass, TVar::ERROR),
recoMElist(pset.getParameter<std::vector<std::string>>("recoProbabilities")),
lheMElist(pset.getParameter<std::vector<std::string>>("lheProbabilities")),
addLHEKinematics(pset.getParameter<bool>("AddLHEKinematics")),
lheHandler(nullptr),
metCorrHandler(nullptr),
apply_K_NNLOQCD_ZZGG(pset.getParameter<int>("Apply_K_NNLOQCD_ZZGG")),
apply_K_NNLOQCD_ZZQQB(pset.getParameter<bool>("Apply_K_NNLOQCD_ZZQQB")),
apply_K_NLOEW_ZZQQB(pset.getParameter<bool>("Apply_K_NLOEW_ZZQQB")),
apply_QCD_GGF_UNCERT(pset.getParameter<bool>("Apply_QCD_GGF_UNCERT")),
pileUpReweight(nullptr),
sampleName(pset.getParameter<string>("sampleName")),
h_weight(0),
printedLHEweightwarning(false)
{
//cout<< "Beginning Constructor\n\n\n" <<endl;
consumesMany<std::vector< PileupSummaryInfo > >();
genParticleToken = consumes<edm::View<reco::Candidate> >(edm::InputTag("prunedGenParticles"));
genInfoToken = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
consumesMany<LHEEventProduct>();
candToken = consumes<edm::View<pat::CompositeCandidate> >(edm::InputTag(theCandLabel));
is_loose_ele_selection = false;
if(pset.exists("is_loose_ele_selection")) {
is_loose_ele_selection = pset.getParameter<bool>("is_loose_ele_selection");
}
triggerResultToken = consumes<edm::TriggerResults>(edm::InputTag("TriggerResults"));
vtxToken = consumes<vector<reco::Vertex> >(edm::InputTag("goodPrimaryVertices"));
jetToken = consumes<edm::View<pat::Jet> >(edm::InputTag("cleanJets"));
photonToken = consumes<pat::PhotonCollection>(edm::InputTag("slimmedPhotons"));
metToken = consumes<pat::METCollection>(metTag);
//metNoHFToken = consumes<pat::METCollection>(edm::InputTag("slimmedMETsNoHF"));
muonToken = consumes<pat::MuonCollection>(edm::InputTag("slimmedMuons"));
electronToken = consumes<pat::ElectronCollection>(edm::InputTag("slimmedElectrons"));
preSkimToken = consumes<edm::MergeableCounter,edm::InLumi>(edm::InputTag("preSkimCounter"));
lheRunInfoToken = consumes<LHERunInfoProduct,edm::InRun>(edm::InputTag("externalLHEProducer"));
if (skipEmptyEvents) {
applySkim=true;
} else {
applyTrigger=false; // This overrides the card applyTrigger
applySkim=false;
failedTreeLevel=noFailedTree; // This overrides the card failedTreeLevel
}
if (applyTrigEffWeight&&applyTrigger) {
cout << "ERROR: cannot have applyTrigEffWeight == applyTrigger == true" << endl;
}
isMC = myHelper.isMC();
if( isMC && (year == 2016 || year == 2017))
{
prefweight_token = consumes< double >(edm::InputTag("prefiringweight:nonPrefiringProb"));
prefweightup_token = consumes< double >(edm::InputTag("prefiringweight:nonPrefiringProbUp"));
prefweightdown_token = consumes< double >(edm::InputTag("prefiringweight:nonPrefiringProbDown"));
}
addLHEKinematics = addLHEKinematics || !lheMElist.empty();
if (isMC){
lheHandler = new LHEHandler(
((MELAEvent::CandidateVVMode)(pset.getParameter<int>("VVMode")+1)), // FIXME: Need to pass strings and interpret them instead!
pset.getParameter<int>("VVDecayMode"),
(addLHEKinematics ? LHEHandler::doHiggsKinematics : LHEHandler::noKinematics),
year, LHEHandler::tryNNPDF30, LHEHandler::tryNLO
);
metCorrHandler = new METCorrectionHandler(Form("%i", year));
htxsToken = consumes<HTXS::HiggsClassification>(edm::InputTag("rivetProducerHTXS","HiggsClassification"));
pileUpReweight = new PileUpWeight(myHelper.sampleType(), myHelper.setup());
}
Nevt_Gen = 0;
Nevt_Gen_lumiBlock = 0;
//For Efficiency studies
gen_ZZ4mu = 0;
gen_ZZ4e = 0;
gen_ZZ2mu2e = 0;
gen_ZZ2l2tau = 0;
gen_ZZ2emu2tau = 0;
gen_ZZ4tau = 0;
gen_ZZ4mu_EtaAcceptance = 0;
gen_ZZ4mu_LeptonAcceptance = 0;
gen_ZZ4e_EtaAcceptance = 0;
gen_ZZ4e_LeptonAcceptance = 0;
gen_ZZ2mu2e_EtaAcceptance = 0;
gen_ZZ2mu2e_LeptonAcceptance = 0;
gen_BUGGY = 0;
gen_Unknown = 0;
gen_sumPUWeight = 0.f;
gen_sumGenMCWeight = 0.f;
gen_sumWeights =0.f;
std::string fipPath;
// Read EWK K-factor table from file
edm::FileInPath ewkFIP("ZZAnalysis/AnalysisStep/data/kfactors/ZZ_EwkCorrections.dat");
fipPath=ewkFIP.fullPath();
ewkTable = EwkCorrections::readFile_and_loadEwkTable(fipPath.data());
// Read the ggZZ k-factor shape from file
TString strZZGGKFVar[9]={
"Nominal", "PDFScaleDn", "PDFScaleUp", "QCDScaleDn", "QCDScaleUp", "AsDn", "AsUp", "PDFReplicaDn", "PDFReplicaUp"
};
edm::FileInPath ggzzFIP_NNLO("ZZAnalysis/AnalysisStep/data/kfactors/Kfactor_Collected_ggHZZ_2l2l_NNLO_NNPDF_NarrowWidth_13TeV.root");
fipPath=ggzzFIP_NNLO.fullPath();
TFile* ggZZKFactorFile = TFile::Open(fipPath.data());
for (unsigned int ikf=0; ikf<9; ikf++) spkfactor_ggzz_nnlo[ikf] = (TSpline3*)ggZZKFactorFile->Get(Form("sp_kfactor_%s", strZZGGKFVar[ikf].Data()))->Clone(Form("sp_kfactor_%s_NNLO", strZZGGKFVar[ikf].Data()));
ggZZKFactorFile->Close();
edm::FileInPath ggzzFIP_NLO("ZZAnalysis/AnalysisStep/data/kfactors/Kfactor_Collected_ggHZZ_2l2l_NLO_NNPDF_NarrowWidth_13TeV.root");
fipPath=ggzzFIP_NLO.fullPath();
ggZZKFactorFile = TFile::Open(fipPath.data());
for (unsigned int ikf=0; ikf<9; ikf++) spkfactor_ggzz_nlo[ikf] = (TSpline3*)ggZZKFactorFile->Get(Form("sp_kfactor_%s", strZZGGKFVar[ikf].Data()))->Clone(Form("sp_kfactor_%s_NLO", strZZGGKFVar[ikf].Data()));
ggZZKFactorFile->Close();
edm::FileInPath NNLOPS_weight_path("ZZAnalysis/AnalysisStep/data/ggH_NNLOPS_Weights/NNLOPS_reweight.root");
fipPath=NNLOPS_weight_path.fullPath();
TFile* NNLOPS_weight_file = TFile::Open(fipPath.data());
gr_NNLOPSratio_pt_powheg_0jet = (TGraphErrors*)NNLOPS_weight_file->Get("gr_NNLOPSratio_pt_powheg_0jet");
gr_NNLOPSratio_pt_powheg_1jet = (TGraphErrors*)NNLOPS_weight_file->Get("gr_NNLOPSratio_pt_powheg_1jet");
gr_NNLOPSratio_pt_powheg_2jet = (TGraphErrors*)NNLOPS_weight_file->Get("gr_NNLOPSratio_pt_powheg_2jet");
gr_NNLOPSratio_pt_powheg_3jet = (TGraphErrors*)NNLOPS_weight_file->Get("gr_NNLOPSratio_pt_powheg_3jet");
//Scale factors for data/MC efficiency
if (!skipEleDataMCWeight && isMC) { lepSFHelper = new LeptonSFHelper(); }
if (!skipHqTWeight) {
//HqT weights
edm::FileInPath HqTfip("ZZAnalysis/AnalysisStep/test/Macros/HqTWeights.root");
std::string fipPath=HqTfip.fullPath();
TFile *fHqt = TFile::Open(fipPath.data(),"READ");
h_weight = (TH2D*)fHqt->Get("wH_400")->Clone();//FIXME: Ask simon to provide the 2D histo
fHqt->Close();
}
if (!skipFakeWeight) {
//CR fake rate weight
TString filename;filename.Form("ZZAnalysis/AnalysisStep/test/Macros/FR2_2011_AA_electron.root");
if(year==2015)filename.Form("ZZAnalysis/AnalysisStep/test/Macros/FR2_AA_ControlSample_ABCD.root");
edm::FileInPath fipEleZX(filename.Data());
std::string fipPath=fipEleZX.fullPath();
TFile *FileZXWeightEle = TFile::Open(fipPath.data(),"READ");
filename.Form("ZZAnalysis/AnalysisStep/test/Macros/FR2_2011_AA_muon.root");
if(year==2015)filename.Form("ZZAnalysis/AnalysisStep/test/Macros/FR2_AA_muon.root");
edm::FileInPath fipMuZX(filename.Data());
fipPath=fipMuZX.fullPath();
TFile *FileZXWeightMuo = TFile::Open(fipPath.data(),"READ");
h_ZXWeight[0]=(TH2D*)FileZXWeightEle->Get("eff_Z1ee_plus_electron")->Clone();
h_ZXWeight[1]=(TH2D*)FileZXWeightEle->Get("eff_Z1mumu_plus_electron")->Clone();
h_ZXWeight[2]=(TH2D*)FileZXWeightMuo->Get("eff_Z1ee_plus_muon")->Clone();
h_ZXWeight[3]=(TH2D*)FileZXWeightMuo->Get("eff_Z1mumu_plus_muon")->Clone();
FileZXWeightEle->Close();
FileZXWeightMuo->Close();
}
}//End of No name parentheis
HZZ4lNtupleMaker::~HZZ4lNtupleMaker()
{
clearMELABranches(); // Cleans LHE branches
delete lheHandler;
delete pileUpReweight;
delete metCorrHandler;
}
// ------------ method called for each event ------------
void HZZ4lNtupleMaker::analyze(const edm::Event& event, const edm::EventSetup& eSetup)
{
myTree->InitializeVariables();
//----------------------------------------------------------------------
// Analyze MC truth; collect MC weights and update counters (this is done for all generated events,
// including those that do not pass skim, trigger etc!)
bool gen_ZZ4lInEtaAcceptance = false; // All 4 gen leptons in eta acceptance
bool gen_ZZ4lInEtaPtAcceptance = false; // All 4 gen leptons in eta,pT acceptance
const reco::Candidate * genH = 0;
std::vector<const reco::Candidate *> genZLeps;
std::vector<const reco::Candidate *> genAssocLeps;
edm::Handle<GenEventInfoProduct> genInfo;
if (isMC) {
// get PU weights
vector<Handle<std::vector< PileupSummaryInfo > > > PupInfos; //FIXME support for miniAOD v1/v2 where name changed; catch does not work...
event.getManyByType(PupInfos);
Handle<std::vector< PileupSummaryInfo > > PupInfo = PupInfos.front();
// try {
// cout << "TRY HZZ4lNtupleMaker" <<endl;
// event.getByLabel(edm::InputTag("addPileupInfo"), PupInfo);
// } catch (const cms::Exception& e){
// cout << "FAIL HZZ4lNtupleMaker" <<endl;
// event.getByLabel(edm::InputTag("slimmedAddPileupInfo"), PupInfo);
// }
std::vector<PileupSummaryInfo>::const_iterator PVI;
for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
if(PVI->getBunchCrossing() == 0) {
NObsInt = PVI->getPU_NumInteractions();
NTrueInt = PVI->getTrueNumInteractions();
break;
}
}
// get PU weight
PUWeight = pileUpReweight->weight(NTrueInt);
PUWeight_Up = pileUpReweight->weight(NTrueInt, PileUpWeight::PUvar::VARUP);
PUWeight_Dn = pileUpReweight->weight(NTrueInt, PileUpWeight::PUvar::VARDOWN);
// L1 prefiring weights
if( year == 2016 || year == 2017 )
{
edm::Handle< double > theprefweight;
event.getByToken(prefweight_token, theprefweight ) ;
L1prefiringWeight =(*theprefweight);
edm::Handle< double > theprefweightup;
event.getByToken(prefweightup_token, theprefweightup ) ;
L1prefiringWeightUp =(*theprefweightup);
edm::Handle< double > theprefweightdown;
event.getByToken(prefweightdown_token, theprefweightdown ) ;
L1prefiringWeightDn =(*theprefweightdown);
}
else if ( year == 2018 )
{
L1prefiringWeight = 1.;
L1prefiringWeightUp = 1.;
L1prefiringWeightDn = 1.;
}
event.getByToken(genParticleToken, genParticles);
event.getByToken(genInfoToken, genInfo);
edm::Handle<HTXS::HiggsClassification> htxs;
event.getByToken(htxsToken,htxs);
MCHistoryTools mch(event, sampleName, genParticles, genInfo);
genFinalState = mch.genFinalState();
genProcessId = mch.getProcessID();
genHEPMCweight_NNLO = genHEPMCweight = mch.gethepMCweight(); // Overridden by LHEHandler if genHEPMCweight==1.
// For 2017 MC, genHEPMCweight is reweighted later from NNLO to NLO
const auto& genweights = genInfo->weights();
if (genweights.size() > 1){
if ((genweights.size() != 14 && genweights.size() != 46) || genweights[0] != genweights[1]){
cms::Exception e("GenWeights");
e << "Expected to find 1 gen weight, or 14 or 46 with the first two the same, found " << genweights.size() << ":\n";
for (auto w : genweights) e << w << " ";
throw e;
}
auto nominal = genweights[0];
PythiaWeight_isr_muRoneoversqrt2 = genweights[2] / nominal;
PythiaWeight_fsr_muRoneoversqrt2 = genweights[3] / nominal;
PythiaWeight_isr_muRsqrt2 = genweights[4] / nominal;
PythiaWeight_fsr_muRsqrt2 = genweights[5] / nominal;
PythiaWeight_isr_muR0p5 = genweights[6] / nominal;
PythiaWeight_fsr_muR0p5 = genweights[7] / nominal;
PythiaWeight_isr_muR2 = genweights[8] / nominal;
PythiaWeight_fsr_muR2 = genweights[9] / nominal;
PythiaWeight_isr_muR0p25 = genweights[10] / nominal;
PythiaWeight_fsr_muR0p25 = genweights[11] / nominal;
PythiaWeight_isr_muR4 = genweights[12] / nominal;
PythiaWeight_fsr_muR4 = genweights[13] / nominal;
} else {
PythiaWeight_isr_muRsqrt2 = PythiaWeight_isr_muRoneoversqrt2 = PythiaWeight_isr_muR2 =
PythiaWeight_isr_muR0p5 = PythiaWeight_isr_muR4 = PythiaWeight_isr_muR0p25 =
PythiaWeight_fsr_muRsqrt2 = PythiaWeight_fsr_muRoneoversqrt2 = PythiaWeight_fsr_muR2 =
PythiaWeight_fsr_muR0p5 = PythiaWeight_fsr_muR4 = PythiaWeight_fsr_muR0p25 = 1;
}
htxsNJets = htxs->jets30.size();
htxsHPt = htxs->higgs.Pt();
htxs_stage0_cat = htxs->stage0_cat;
htxs_stage1p0_cat = htxs->stage1_cat_pTjet30GeV;
htxs_stage1p1_cat = htxs->stage1_1_cat_pTjet30GeV;
htxs_stage1p2_cat = htxs->stage1_2_cat_pTjet30GeV;
htxs_errorCode=htxs->errorCode;
htxs_prodMode= htxs->prodMode;
genExtInfo = mch.genAssociatedFS();
//Information on generated candidates, will be used later
genH = mch.genH();
genZLeps = mch.sortedGenZZLeps();
genAssocLeps = mch.genAssociatedLeps();
genFSR = mch.genFSR();
if(genH != 0){
FillHGenInfo(genH->p4(),getHqTWeight(genH->p4().M(),genH->p4().Pt()));
}
else if(genZLeps.size()==4){ // for 4l events take the mass of the ZZ(4l) system
FillHGenInfo((genZLeps.at(0)->p4()+genZLeps.at(1)->p4()+genZLeps.at(2)->p4()+genZLeps.at(3)->p4()),0);
}
if (genFinalState!=BUGGY) {
if (genZLeps.size()==4) {
// "generated Zs" defined with standard pairing applied on gen leptons (genZLeps is sorted by MCHistoryTools)
FillZGenInfo(genZLeps.at(0)->pdgId()*genZLeps.at(1)->pdgId(),
genZLeps.at(2)->pdgId()*genZLeps.at(3)->pdgId(),
genZLeps.at(0)->p4()+genZLeps.at(1)->p4(),
genZLeps.at(2)->p4()+genZLeps.at(3)->p4());
// Gen leptons
FillLepGenInfo(genZLeps.at(0)->pdgId(), genZLeps.at(1)->pdgId(), genZLeps.at(2)->pdgId(), genZLeps.at(3)->pdgId(),
genZLeps.at(0)->p4(), genZLeps.at(1)->p4(), genZLeps.at(2)->p4(), genZLeps.at(3)->p4());
}
if (genZLeps.size()==3) {
FillLepGenInfo(genZLeps.at(0)->pdgId(), genZLeps.at(1)->pdgId(), genZLeps.at(2)->pdgId(), 0,
genZLeps.at(0)->p4(), genZLeps.at(1)->p4(), genZLeps.at(2)->p4(), *(new math::XYZTLorentzVector));
}
if (genZLeps.size()==2) {
FillLepGenInfo(genZLeps.at(0)->pdgId(), genZLeps.at(1)->pdgId(), 0, 0,
genZLeps.at(0)->p4(), genZLeps.at(1)->p4(), *(new math::XYZTLorentzVector), *(new math::XYZTLorentzVector));
}
if (genAssocLeps.size()==1 || genAssocLeps.size()==2) {
FillAssocLepGenInfo(genAssocLeps);
}
// LHE information
edm::Handle<LHEEventProduct> lhe_evt;
vector<edm::Handle<LHEEventProduct> > lhe_handles;
event.getManyByType(lhe_handles);
if (!lhe_handles.empty()){
lhe_evt = lhe_handles.front();
lheHandler->setHandle(&lhe_evt);
lheHandler->extract();
FillLHECandidate(); // Also writes weights
lheHandler->clear();
}
//else cerr << "lhe_handles.size()==0" << endl;
// keep track of sum of weights
addweight(gen_sumPUWeight, PUWeight);
addweight(gen_sumGenMCWeight, genHEPMCweight);
addweight(gen_sumWeights, PUWeight*genHEPMCweight);
mch.genAcceptance(gen_ZZ4lInEtaAcceptance, gen_ZZ4lInEtaPtAcceptance);
}//End of
addweight(Nevt_Gen_lumiBlock, 1); // Needs to be outside the if-block
if (genFinalState == EEEE) {
addweight(gen_ZZ4e, 1);
if (gen_ZZ4lInEtaAcceptance) addweight(gen_ZZ4e_EtaAcceptance, 1);
if (gen_ZZ4lInEtaPtAcceptance) addweight(gen_ZZ4e_LeptonAcceptance, 1);
} else if (genFinalState == MMMM) {
addweight(gen_ZZ4mu, 1);
if (gen_ZZ4lInEtaAcceptance) addweight(gen_ZZ4mu_EtaAcceptance, 1);
if (gen_ZZ4lInEtaPtAcceptance) addweight(gen_ZZ4mu_LeptonAcceptance, 1);
} else if (genFinalState == EEMM) {
addweight(gen_ZZ2mu2e, 1);
if (gen_ZZ4lInEtaAcceptance) addweight(gen_ZZ2mu2e_EtaAcceptance, 1);
if (gen_ZZ4lInEtaPtAcceptance) addweight(gen_ZZ2mu2e_LeptonAcceptance, 1);
} else if (genFinalState == llTT){