From 08b23c6d9462da93d3a5e94777c24f973c1ac651 Mon Sep 17 00:00:00 2001 From: Markus Seidel Date: Wed, 11 Nov 2020 12:21:36 +0100 Subject: [PATCH 1/2] Add LHE HT and generator weights to TagAndProbe tree --- .../TagAndProbe/interface/BaseTreeFiller.h | 12 +++++- .../TagAndProbe/src/BaseTreeFiller.cc | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h b/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h index 19f574b22e0ef..6db7a09223a81 100644 --- a/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h +++ b/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h @@ -28,6 +28,9 @@ #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include @@ -174,7 +177,12 @@ namespace tnp { /// How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file, 'External' = read weight from the event (as double) enum WeightMode { None, Fixed, External }; WeightMode weightMode_; + bool LHEinfo_; edm::EDGetTokenT weightSrcToken_; + edm::EDGetTokenT _LHECollection; + edm::EDGetTokenT _genLumiInfoToken; + edm::EDGetTokenT _lheRunInfoToken; + edm::EDGetTokenT genParticlesToken_; edm::EDGetTokenT PUweightSrcToken_; edm::EDGetTokenT rhoToken_; edm::EDGetTokenT recVtxsToken_; @@ -204,13 +212,15 @@ namespace tnp { //implementation notice: these two are 'mutable' because we will fill them from a 'const' method mutable TTree *tree_; mutable float weight_, PUweight_, totWeight_; + mutable float lheWeight_[9]; + mutable float psWeight_[5]; mutable uint32_t run_, lumi_, mNPV_; mutable uint64_t event_; mutable int truePU_; mutable float mPVx_, mPVy_, mPVz_, mBSx_, mBSy_, mBSz_; mutable float rho_; - mutable float mMET_, mSumET_, mMETSign_, mtcMET_, mtcSumET_, mtcMETSign_, mpfMET_, mpfSumET_, mpfMETSign_, mpfPhi_; + mutable float mMET_, mSumET_, mMETSign_, mtcMET_, mtcSumET_, mtcMETSign_, mpfMET_, mpfSumET_, mpfMETSign_, mpfPhi_, lhe_ht_; }; } // namespace tnp diff --git a/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc b/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc index fbd50c2f4504e..3fc90a92611ba 100644 --- a/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc +++ b/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc @@ -45,6 +45,7 @@ tnp::BaseTreeFiller::BaseTreeFiller(const char *name, const edm::ParameterSet &i } else if (iConfig.existsAs("eventWeight")) { weightMode_ = External; weightSrcToken_ = iC.consumes(iConfig.getParameter("eventWeight")); + tree_->Branch("psWeight", &psWeight_, "psWeight[5]/F"); } else { weightMode_ = None; } @@ -52,6 +53,13 @@ tnp::BaseTreeFiller::BaseTreeFiller(const char *name, const edm::ParameterSet &i tree_->Branch("weight", &weight_, "weight/F"); tree_->Branch("totWeight", &totWeight_, "totWeight/F"); } + + LHEinfo_ = iConfig.existsAs("LHEWeightSrc"); + if (LHEinfo_) { + _LHECollection = iC.consumes(iConfig.getParameter("LHEWeightSrc")); + tree_->Branch("lheWeight", &lheWeight_, "lheWeight[9]/F"); + tree_->Branch("lhe_ht", &lhe_ht_, "lhe_ht/F"); + } storePUweight_ = iConfig.existsAs("PUWeightSrc") ? true : false; if (storePUweight_) { @@ -194,6 +202,9 @@ void tnp::BaseTreeFiller::init(const edm::Event &iEvent) const { for (std::vector::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) { it->init(iEvent); } + for (int i = 0; i < 5; i++) { + psWeight_[i] = 1.; // init + } if (weightMode_ == External) { // edm::Handle weight; // iEvent.getByToken(weightSrcToken_, weight); @@ -202,6 +213,35 @@ void tnp::BaseTreeFiller::init(const edm::Event &iEvent) const { iEvent.getByToken(weightSrcToken_, weight); weight_ = weight->weight(); totWeight_ *= weight_; + if (weight->weights().size() >= 10) { + int k = 1; + for (int i = 6; i < 10; i++) { + // hardcoded Pythia 8 isrDefHi,fsrDefHi,isrDefLo,fsrDefLo + psWeight_[k] = weight->weights().at(i) / weight->weight(); + k++; + } + } + } + + for (unsigned int i = 0; i < 9; i++) { + lheWeight_ [i] = 1.; // init + } + lhe_ht_ = 0.; + if (LHEinfo_ and !_LHECollection.isUninitialized()) { + edm::Handle lheEventHandle; + iEvent.getByToken(_LHECollection, lheEventHandle); + for (unsigned int i = 0; i < 9; i++) { + lheWeight_ [i] = lheEventHandle->weights().at(i).wgt / lheEventHandle->originalXWGTUP(); + } + for (int i = 0; i < lheEventHandle->hepeup().NUP; i++) { + int id = lheEventHandle->hepeup().IDUP[i]; + int st = lheEventHandle->hepeup().ISTUP[i]; + + // calculate HT at LHE level + if( ( abs(id) < 6 || id == 21 ) && st > 0 ) { + lhe_ht_ += sqrt(pow(lheEventHandle->hepeup().PUP[i][0], 2) + pow(lheEventHandle->hepeup().PUP[i][1], 2)); + } + } } ///// ********** Pileup weight: needed for MC re-weighting for PU ************* From f9ee5eb4a6e9e261d1ede2186a83537f82796d8e Mon Sep 17 00:00:00 2001 From: Markus Seidel Date: Wed, 11 Nov 2020 12:47:46 +0100 Subject: [PATCH 2/2] Apply code-format --- PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h | 3 ++- PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h b/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h index 6db7a09223a81..1c3f5fc587fb5 100644 --- a/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h +++ b/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h @@ -220,7 +220,8 @@ namespace tnp { mutable float mPVx_, mPVy_, mPVz_, mBSx_, mBSy_, mBSz_; mutable float rho_; - mutable float mMET_, mSumET_, mMETSign_, mtcMET_, mtcSumET_, mtcMETSign_, mpfMET_, mpfSumET_, mpfMETSign_, mpfPhi_, lhe_ht_; + mutable float mMET_, mSumET_, mMETSign_, mtcMET_, mtcSumET_, mtcMETSign_, mpfMET_, mpfSumET_, mpfMETSign_, mpfPhi_, + lhe_ht_; }; } // namespace tnp diff --git a/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc b/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc index 3fc90a92611ba..85d8515ad5b01 100644 --- a/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc +++ b/PhysicsTools/TagAndProbe/src/BaseTreeFiller.cc @@ -53,7 +53,7 @@ tnp::BaseTreeFiller::BaseTreeFiller(const char *name, const edm::ParameterSet &i tree_->Branch("weight", &weight_, "weight/F"); tree_->Branch("totWeight", &totWeight_, "totWeight/F"); } - + LHEinfo_ = iConfig.existsAs("LHEWeightSrc"); if (LHEinfo_) { _LHECollection = iC.consumes(iConfig.getParameter("LHEWeightSrc")); @@ -203,7 +203,7 @@ void tnp::BaseTreeFiller::init(const edm::Event &iEvent) const { it->init(iEvent); } for (int i = 0; i < 5; i++) { - psWeight_[i] = 1.; // init + psWeight_[i] = 1.; // init } if (weightMode_ == External) { // edm::Handle weight; @@ -224,21 +224,21 @@ void tnp::BaseTreeFiller::init(const edm::Event &iEvent) const { } for (unsigned int i = 0; i < 9; i++) { - lheWeight_ [i] = 1.; // init + lheWeight_[i] = 1.; // init } lhe_ht_ = 0.; if (LHEinfo_ and !_LHECollection.isUninitialized()) { edm::Handle lheEventHandle; iEvent.getByToken(_LHECollection, lheEventHandle); for (unsigned int i = 0; i < 9; i++) { - lheWeight_ [i] = lheEventHandle->weights().at(i).wgt / lheEventHandle->originalXWGTUP(); + lheWeight_[i] = lheEventHandle->weights().at(i).wgt / lheEventHandle->originalXWGTUP(); } for (int i = 0; i < lheEventHandle->hepeup().NUP; i++) { int id = lheEventHandle->hepeup().IDUP[i]; int st = lheEventHandle->hepeup().ISTUP[i]; // calculate HT at LHE level - if( ( abs(id) < 6 || id == 21 ) && st > 0 ) { + if ((abs(id) < 6 || id == 21) && st > 0) { lhe_ht_ += sqrt(pow(lheEventHandle->hepeup().PUP[i][0], 2) + pow(lheEventHandle->hepeup().PUP[i][1], 2)); } }