diff --git a/Configuration/Generator/python/Hadronizer_TuneCP5_13TeV_aMCatNLO_FXFX_5f_max2j_max1p_LHE_pythia8_cff.py b/Configuration/Generator/python/Hadronizer_TuneCP5_13TeV_aMCatNLO_FXFX_5f_max2j_max1p_LHE_pythia8_cff.py index dac02133f06a5..97df5b9c491d4 100644 --- a/Configuration/Generator/python/Hadronizer_TuneCP5_13TeV_aMCatNLO_FXFX_5f_max2j_max1p_LHE_pythia8_cff.py +++ b/Configuration/Generator/python/Hadronizer_TuneCP5_13TeV_aMCatNLO_FXFX_5f_max2j_max1p_LHE_pythia8_cff.py @@ -3,6 +3,7 @@ from Configuration.Generator.Pythia8CommonSettings_cfi import * from Configuration.Generator.MCTunes2017.PythiaCP5Settings_cfi import * from Configuration.Generator.Pythia8aMCatNLOSettings_cfi import * +from Configuration.Generator.PSweightsPythia.PythiaPSweightsSettings_cfi import * generator = cms.EDFilter("Pythia8ConcurrentHadronizerFilter", maxEventsToPrint = cms.untracked.int32(1), @@ -13,6 +14,7 @@ PythiaParameters = cms.PSet( pythia8CommonSettingsBlock, pythia8CP5SettingsBlock, + pythia8PSweightsSettingsBlock, pythia8aMCatNLOSettingsBlock, processParameters = cms.vstring( 'JetMatching:setMad = off', @@ -30,6 +32,7 @@ ), parameterSets = cms.vstring('pythia8CommonSettings', 'pythia8CP5Settings', + 'pythia8PSweightsSettings', 'pythia8aMCatNLOSettings', 'processParameters', ) diff --git a/Validation/EventGenerator/interface/GenWeightValidation.h b/Validation/EventGenerator/interface/GenWeightValidation.h new file mode 100644 index 0000000000000..6a368cdcbd35e --- /dev/null +++ b/Validation/EventGenerator/interface/GenWeightValidation.h @@ -0,0 +1,69 @@ +#ifndef GENWEIGHTVALIDATION_H +#define GENWEIGHTVALIDATION_H + +// framework & common header files +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" + +//DQM services +#include "DQMServices/Core/interface/DQMStore.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "DQMServices/Core/interface/DQMEDAnalyzer.h" + +#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" + +#include "Validation/EventGenerator/interface/WeightManager.h" +#include "Validation/EventGenerator/interface/DQMHelper.h" + +class GenWeightValidation : public DQMEDAnalyzer { +public: + explicit GenWeightValidation(const edm::ParameterSet &); + ~GenWeightValidation() override = default; + void analyze(const edm::Event &, const edm::EventSetup &) override; + void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override; + void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override; + +private: + void bookTemplates(DQMHelper &aDqmHelper, + std::vector &tmps, + const std::string &name, + const std::string &title, + int nbin, + float low, + float high, + const std::string &xtitle, + const std::string &ytitle); + void fillTemplates(std::vector &tmps, float obs); + WeightManager wmanager_; + + double weight_; + std::vector> weights_; + + MonitorElement *nEvt_; + MonitorElement *nlogWgt_; + MonitorElement *wgtVal_; + std::vector leadLepPtTemp_; + std::vector leadLepEtaTemp_; + std::vector jetMultTemp_; + std::vector leadJetPtTemp_; + std::vector leadJetEtaTemp_; + + const edm::EDGetTokenT genParticleToken_; + const edm::EDGetTokenT genJetToken_; + + const int idxGenEvtInfo_, idxFSRup_, idxFSRdown_, idxISRup_, idxISRdown_, leadLepPtNbin_, rapidityNbin_; + const double leadLepPtRange_, leadLepPtCut_, lepEtaCut_, rapidityRange_; + const int nJetsNbin_, jetPtNbin_; + const double jetPtCut_, jetEtaCut_, jetPtRange_; + int idxMax_; +}; + +#endif diff --git a/Validation/EventGenerator/interface/HepMCValidationHelper.h b/Validation/EventGenerator/interface/HepMCValidationHelper.h index 451e5cc4a37de..d5c0068964b99 100644 --- a/Validation/EventGenerator/interface/HepMCValidationHelper.h +++ b/Validation/EventGenerator/interface/HepMCValidationHelper.h @@ -16,6 +16,11 @@ namespace HepMCValidationHelper { return a->momentum().perp() > b->momentum().perp(); } + template + inline bool sortByPtRef(const T lhs, const T rhs) { + return lhs->pt() > rhs->pt(); + } + //sort by energy inline bool sortByE(const HepMC::GenParticle* a, const HepMC::GenParticle* b) { return a->momentum().e() > b->momentum().e(); diff --git a/Validation/EventGenerator/interface/LheWeightValidation.h b/Validation/EventGenerator/interface/LheWeightValidation.h new file mode 100644 index 0000000000000..021a88dc93e0f --- /dev/null +++ b/Validation/EventGenerator/interface/LheWeightValidation.h @@ -0,0 +1,99 @@ +#ifndef LHEWEIGHTVALIDATION_H +#define LHEWEIGHTVALIDATION_H + +// framework & common header files +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" + +//DQM services +#include "DQMServices/Core/interface/DQMStore.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "DQMServices/Core/interface/DQMOneEDAnalyzer.h" + +#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" + +#include "Validation/EventGenerator/interface/DQMHelper.h" + +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" + +class TH1F; // forward declaration for ROOT + +class LheWeightValidation : public DQMOneEDAnalyzer<> { +public: + explicit LheWeightValidation(const edm::ParameterSet&); + ~LheWeightValidation() override = default; + void analyze(const edm::Event&, const edm::EventSetup&) override; + void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override; + void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override; + void dqmEndRun(const edm::Run&, const edm::EventSetup&) override; + +private: + void bookTemplates(DQMHelper& aDqmHelper, + std::vector>& scaleVar, + std::vector>& pdfVar, + std::vector& tmps, + const std::string& name, + const std::string& title, + int nbin, + float low, + float high, + const std::string& xtitle, + const std::string& ytitle); + + void fillTemplates(std::vector>& scaleVar, + std::vector>& pdfVar, + std::vector& tmps, + float obs); + + void envelop(const std::vector>& var, std::vector& tmps); + void pdfRMS(const std::vector>& var, std::vector& tmps); + + double weight_, orgWgt_; + std::vector weights_; + + MonitorElement* nEvt_; + MonitorElement* nlogWgt_; + MonitorElement* wgtVal_; + std::vector leadLepPtTemp_; + std::vector leadLepEtaTemp_; + std::vector jetMultTemp_; + std::vector leadJetPtTemp_; + std::vector leadJetEtaTemp_; + + std::vector> leadLepPtScaleVar_; + std::vector> leadLepPtPdfVar_; + std::vector> leadLepEtaScaleVar_; + std::vector> leadLepEtaPdfVar_; + std::vector> jetMultScaleVar_; + std::vector> jetMultPdfVar_; + std::vector> leadJetPtScaleVar_; + std::vector> leadJetPtPdfVar_; + std::vector> leadJetEtaScaleVar_; + std::vector> leadJetEtaPdfVar_; + + const edm::InputTag lheLabel_; + const edm::EDGetTokenT genParticleToken_; + const edm::EDGetTokenT lheEvtToken_; + const edm::EDGetTokenT lheRunToken_; + const edm::EDGetTokenT genJetToken_; + + const bool dumpLHEheader_; + const int leadLepPtNbin_, rapidityNbin_; + const double leadLepPtRange_, leadLepPtCut_, lepEtaCut_, rapidityRange_; + const int nJetsNbin_, jetPtNbin_; + const double jetPtCut_, jetEtaCut_, jetPtRange_; + + const int nScaleVar_; // including Nominal + const int idxPdfStart_, idxPdfEnd_, nPdfVar_; +}; + +#endif diff --git a/Validation/EventGenerator/interface/WeightManager.h b/Validation/EventGenerator/interface/WeightManager.h index 8d4335e380d7b..bde1f8ca38d66 100644 --- a/Validation/EventGenerator/interface/WeightManager.h +++ b/Validation/EventGenerator/interface/WeightManager.h @@ -6,9 +6,10 @@ // or returning the product of the weights stored in // a vector of GenEventInfoProducts -#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Utilities/interface/InputTag.h" #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" + #include "FWCore/Framework/interface/ConsumesCollector.h" #include @@ -23,6 +24,7 @@ class WeightManager { ~WeightManager(){}; double weight(const edm::Event&); + std::vector> weightsCollection(const edm::Event&); private: bool _useHepMC; @@ -30,7 +32,7 @@ class WeightManager { edm::InputTag _hepmcCollection; edm::EDGetTokenT hepmcCollectionToken_; - std::vector > > genEventInfosTokens_; + std::vector> genEventInfosTokens_; }; #endif diff --git a/Validation/EventGenerator/plugins/GenWeightValidation.cc b/Validation/EventGenerator/plugins/GenWeightValidation.cc new file mode 100644 index 0000000000000..f864810f9372a --- /dev/null +++ b/Validation/EventGenerator/plugins/GenWeightValidation.cc @@ -0,0 +1,187 @@ +#include "Validation/EventGenerator/interface/GenWeightValidation.h" + +#include "DataFormats/Math/interface/LorentzVector.h" +#include "Validation/EventGenerator/interface/HepMCValidationHelper.h" + +using namespace edm; + +GenWeightValidation::GenWeightValidation(const edm::ParameterSet& iPSet) + : wmanager_(iPSet, consumesCollector()), + genParticleToken_(consumes(iPSet.getParameter("genParticles"))), + genJetToken_(consumes(iPSet.getParameter("genJets"))), + idxGenEvtInfo_(iPSet.getParameter("whichGenEventInfo")), + idxFSRup_(iPSet.getParameter("idxFSRup")), + idxFSRdown_(iPSet.getParameter("idxFSRdown")), + idxISRup_(iPSet.getParameter("idxISRup")), + idxISRdown_(iPSet.getParameter("idxISRdown")), + leadLepPtNbin_(iPSet.getParameter("leadLepPtNbin")), + rapidityNbin_(iPSet.getParameter("rapidityNbin")), + leadLepPtRange_(iPSet.getParameter("leadLepPtRange")), + leadLepPtCut_(iPSet.getParameter("leadLepPtCut")), + lepEtaCut_(iPSet.getParameter("lepEtaCut")), + rapidityRange_(iPSet.getParameter("rapidityRange")), + nJetsNbin_(iPSet.getParameter("nJetsNbin")), + jetPtNbin_(iPSet.getParameter("jetPtNbin")), + jetPtCut_(iPSet.getParameter("jetPtCut")), + jetEtaCut_(iPSet.getParameter("jetEtaCut")), + jetPtRange_(iPSet.getParameter("jetPtRange")) { + std::vector idxs = {idxFSRup_, idxFSRdown_, idxISRup_, idxISRdown_}; + std::sort(idxs.begin(), idxs.end(), std::greater()); + idxMax_ = idxs.at(0); +} + +void GenWeightValidation::bookHistograms(DQMStore::IBooker& iBook, edm::Run const&, edm::EventSetup const&) { + ///Setting the DQM top directories + std::string folderName = "Generator/GenWeight"; + DQMHelper aDqmHelper(&iBook); + iBook.setCurrentFolder(folderName); + + // Number of analyzed events + nEvt_ = aDqmHelper.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events"); + nlogWgt_ = aDqmHelper.book1dHisto("nlogWgt", "Log10(n weights)", 100, 0., 3., "log_{10}(nWgts)", "Number of Events"); + wgtVal_ = aDqmHelper.book1dHisto("wgtVal", "weights", 100, -1.5, 3., "weight", "Number of Weights"); + bookTemplates(aDqmHelper, + leadLepPtTemp_, + "leadLepPt", + "leading lepton Pt", + leadLepPtNbin_, + 0., + leadLepPtRange_, + "Pt_{l} (GeV)", + "Number of Events"); + bookTemplates(aDqmHelper, + leadLepEtaTemp_, + "leadLepEta", + "leading lepton #eta", + rapidityNbin_, + -rapidityRange_, + rapidityRange_, + "#eta_{l}", + "Number of Events"); + bookTemplates(aDqmHelper, + jetMultTemp_, + "JetMultiplicity", + "Gen jet multiplicity", + nJetsNbin_, + 0, + nJetsNbin_, + "n", + "Number of Events"); + bookTemplates(aDqmHelper, + leadJetPtTemp_, + "leadJetPt", + "leading Gen jet Pt", + jetPtNbin_, + 0., + jetPtRange_, + "Pt_{j} (GeV)", + "Number of Events"); + bookTemplates(aDqmHelper, + leadJetEtaTemp_, + "leadJetEta", + "leading Gen jet #eta", + rapidityNbin_, + -rapidityRange_, + rapidityRange_, + "#eta_{j}", + "Number of Events"); + + return; +} + +void GenWeightValidation::bookTemplates(DQMHelper& aDqmHelper, + std::vector& tmps, + const std::string& name, + const std::string& title, + int nbin, + float low, + float high, + const std::string& xtitle, + const std::string& ytitle) { + tmps.push_back(aDqmHelper.book1dHisto(name, title, nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto(name + "FSRup", title + " FSR up", nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto(name + "FSRdn", title + " FSR down", nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto( + name + "FSRup_ratio", "Ratio of " + title + " FSR up / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(3)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto( + name + "FSRdn_ratio", "Ratio of " + title + " FSR down / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(4)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto(name + "ISRup", title + " ISR up", nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto(name + "ISRdn", title + " ISR down", nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto( + name + "ISRup_ratio", "Ratio of " + title + " ISR up / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(7)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto( + name + "ISRdn_ratio", "Ratio of " + title + " ISR down / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(8)->setEfficiencyFlag(); +} // to get ratio plots correctly - need to modify PostProcessor_cff.py as well! + +void GenWeightValidation::dqmBeginRun(const edm::Run&, const edm::EventSetup&) {} + +void GenWeightValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + weights_ = wmanager_.weightsCollection(iEvent); + + if (weights_.at(idxGenEvtInfo_).empty()) + return; // no weights in GenEventInfo + + weight_ = weights_.at(idxGenEvtInfo_)[0] / std::abs(weights_.at(idxGenEvtInfo_)[0]); + nEvt_->Fill(0.5, weight_); + nlogWgt_->Fill(std::log10(weights_.at(idxGenEvtInfo_).size()), weight_); + + for (unsigned idx = 0; idx < weights_.at(idxGenEvtInfo_).size(); idx++) + wgtVal_->Fill(weights_.at(idxGenEvtInfo_)[idx] / weights_.at(idxGenEvtInfo_)[1], weight_); + + if ((int)weights_.at(idxGenEvtInfo_).size() <= idxMax_) + return; // no PS weights in GenEventInfo + + edm::Handle ptcls; + iEvent.getByToken(genParticleToken_, ptcls); + edm::Handle genjets; + iEvent.getByToken(genJetToken_, genjets); + + std::vector leptons; + + for (unsigned iptc = 0; iptc < ptcls->size(); iptc++) { + reco::GenParticleRef ptc(ptcls, iptc); + if (ptc->status() == 1 && (std::abs(ptc->pdgId()) == 11 || std::abs(ptc->pdgId()) == 13)) { + if (ptc->pt() > leadLepPtCut_ && std::abs(ptc->eta()) < lepEtaCut_) + leptons.push_back(ptc); + } + } + + std::sort(leptons.begin(), leptons.end(), HepMCValidationHelper::sortByPtRef); + + if (!leptons.empty()) { + reco::GenParticleRef leadLep = leptons.at(0); + fillTemplates(leadLepPtTemp_, leadLep->pt()); + fillTemplates(leadLepEtaTemp_, leadLep->eta()); + } + + std::vector genjetVec; + + for (unsigned igj = 0; igj < genjets->size(); igj++) { + reco::GenJetRef genjet(genjets, igj); + + if (genjet->pt() > jetPtCut_ && std::abs(genjet->eta()) < jetEtaCut_) + genjetVec.push_back(genjet); + } + + fillTemplates(jetMultTemp_, (float)genjetVec.size()); + + if (!genjetVec.empty()) { + std::sort(genjetVec.begin(), genjetVec.end(), HepMCValidationHelper::sortByPtRef); + + auto leadJet = genjetVec.at(0); + fillTemplates(leadJetPtTemp_, leadJet->pt()); + fillTemplates(leadJetEtaTemp_, leadJet->eta()); + } +} //analyze + +void GenWeightValidation::fillTemplates(std::vector& tmps, float obs) { + tmps.at(0)->Fill(obs, weight_); + tmps.at(1)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxFSRup_] / weights_.at(idxGenEvtInfo_)[1]); + tmps.at(2)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxFSRdown_] / weights_.at(idxGenEvtInfo_)[1]); + tmps.at(5)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxISRup_] / weights_.at(idxGenEvtInfo_)[1]); + tmps.at(6)->Fill(obs, weights_.at(idxGenEvtInfo_)[idxISRdown_] / weights_.at(idxGenEvtInfo_)[1]); +} diff --git a/Validation/EventGenerator/plugins/LheWeightValidation.cc b/Validation/EventGenerator/plugins/LheWeightValidation.cc new file mode 100644 index 0000000000000..a9175845e6eeb --- /dev/null +++ b/Validation/EventGenerator/plugins/LheWeightValidation.cc @@ -0,0 +1,338 @@ +#include "Validation/EventGenerator/interface/LheWeightValidation.h" + +#include "DataFormats/Math/interface/LorentzVector.h" +#include "Validation/EventGenerator/interface/HepMCValidationHelper.h" + +using namespace edm; + +LheWeightValidation::LheWeightValidation(const edm::ParameterSet& iPSet) + : lheLabel_(iPSet.getParameter("lheProduct")), + genParticleToken_(consumes(iPSet.getParameter("genParticles"))), + lheEvtToken_(consumes(lheLabel_)), + lheRunToken_(consumes(lheLabel_)), + genJetToken_(consumes(iPSet.getParameter("genJets"))), + dumpLHEheader_(iPSet.getParameter("dumpLHEheader")), + leadLepPtNbin_(iPSet.getParameter("leadLepPtNbin")), + rapidityNbin_(iPSet.getParameter("rapidityNbin")), + leadLepPtRange_(iPSet.getParameter("leadLepPtRange")), + leadLepPtCut_(iPSet.getParameter("leadLepPtCut")), + lepEtaCut_(iPSet.getParameter("lepEtaCut")), + rapidityRange_(iPSet.getParameter("rapidityRange")), + nJetsNbin_(iPSet.getParameter("nJetsNbin")), + jetPtNbin_(iPSet.getParameter("jetPtNbin")), + jetPtCut_(iPSet.getParameter("jetPtCut")), + jetEtaCut_(iPSet.getParameter("jetEtaCut")), + jetPtRange_(iPSet.getParameter("jetPtRange")), + nScaleVar_(iPSet.getParameter("nScaleVar")), + idxPdfStart_(iPSet.getParameter("idxPdfStart")), + idxPdfEnd_(iPSet.getParameter("idxPdfEnd")), + nPdfVar_(idxPdfEnd_ - idxPdfStart_ + 1) {} + +void LheWeightValidation::bookHistograms(DQMStore::IBooker& iBook, edm::Run const& iRun, edm::EventSetup const&) { + // check LHE product exists + edm::Handle lheInfo; + // getByToken throws an exception unless we're in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) + iRun.getByLabel(lheLabel_, lheInfo); + + if (!lheInfo.isValid()) + return; + + ///Setting the DQM top directories + std::string folderName = "Generator/LHEWeight"; + DQMHelper aDqmHelper(&iBook); + iBook.setCurrentFolder(folderName); + + // Number of analyzed events + nEvt_ = aDqmHelper.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events"); + nlogWgt_ = aDqmHelper.book1dHisto("nlogWgt", "Log10(n weights)", 100, 0., 5., "log_{10}(nWgts)", "Number of Events"); + wgtVal_ = aDqmHelper.book1dHisto("wgtVal", "weights", 100, -1.5, 3., "weight", "Number of Weights"); + + bookTemplates(aDqmHelper, + leadLepPtScaleVar_, + leadLepPtPdfVar_, + leadLepPtTemp_, + "leadLepPt", + "leading lepton Pt", + leadLepPtNbin_, + 0., + leadLepPtRange_, + "Pt_{l} (GeV)", + "Number of Events"); + bookTemplates(aDqmHelper, + leadLepEtaScaleVar_, + leadLepEtaPdfVar_, + leadLepEtaTemp_, + "leadLepEta", + "leading lepton #eta", + rapidityNbin_, + -rapidityRange_, + rapidityRange_, + "#eta_{l}", + "Number of Events"); + bookTemplates(aDqmHelper, + jetMultScaleVar_, + jetMultPdfVar_, + jetMultTemp_, + "JetMultiplicity", + "Gen jet multiplicity", + nJetsNbin_, + 0, + nJetsNbin_, + "n", + "Number of Events"); + bookTemplates(aDqmHelper, + leadJetPtScaleVar_, + leadJetPtPdfVar_, + leadJetPtTemp_, + "leadJetPt", + "leading Gen jet Pt", + jetPtNbin_, + 0., + jetPtRange_, + "Pt_{j} (GeV)", + "Number of Events"); + bookTemplates(aDqmHelper, + leadJetEtaScaleVar_, + leadJetEtaPdfVar_, + leadJetEtaTemp_, + "leadJetEta", + "leading Gen jet #eta", + rapidityNbin_, + -rapidityRange_, + rapidityRange_, + "#eta_{j}", + "Number of Events"); + + return; +} + +void LheWeightValidation::bookTemplates(DQMHelper& aDqmHelper, + std::vector>& scaleVar, + std::vector>& pdfVar, + std::vector& tmps, + const std::string& name, + const std::string& title, + int nbin, + float low, + float high, + const std::string& xtitle, + const std::string& ytitle) { + tmps.push_back(aDqmHelper.book1dHisto(name, title, nbin, low, high, xtitle, ytitle)); + tmps.push_back(aDqmHelper.book1dHisto(name + "ScaleUp", title + " scale up", nbin, low, high, xtitle, ytitle)); + tmps.at(1)->getTH1()->Sumw2(false); + tmps.push_back(aDqmHelper.book1dHisto(name + "ScaleDn", title + " scale down", nbin, low, high, xtitle, ytitle)); + tmps.at(2)->getTH1()->Sumw2(false); + tmps.push_back(aDqmHelper.book1dHisto( + name + "ScaleUp_ratio", "Ratio of " + title + " scale upper envelop / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(3)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto( + name + "ScaleDn_ratio", "Ratio of " + title + " scale lower envelop / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(4)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto(name + "PdfUp", title + " PDF upper RMS", nbin, low, high, xtitle, ytitle)); + tmps.at(5)->getTH1()->Sumw2(false); + tmps.push_back(aDqmHelper.book1dHisto(name + "PdfDn", title + " PDF lower RMS", nbin, low, high, xtitle, ytitle)); + tmps.at(6)->getTH1()->Sumw2(false); + tmps.push_back(aDqmHelper.book1dHisto( + name + "PdfUp_ratio", "Ratio of " + title + " PDF upper RMS / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(7)->setEfficiencyFlag(); + tmps.push_back(aDqmHelper.book1dHisto( + name + "PdfDn_ratio", "Ratio of " + title + " PDF lower RMS / Nominal", nbin, low, high, xtitle, ytitle)); + tmps.at(8)->setEfficiencyFlag(); + + for (int idx = 0; idx < nScaleVar_; idx++) { + scaleVar.push_back( + std::make_unique(std::string(name + "Scale" + std::to_string(idx)).c_str(), + std::string(";" + std::string(xtitle) + ";" + std::string(ytitle)).c_str(), + nbin, + low, + high)); + scaleVar.at(idx)->Sumw2(); + } + + for (int idx = 0; idx < nPdfVar_; idx++) { + pdfVar.push_back(std::make_unique(std::string(name + "Pdf" + std::to_string(idx)).c_str(), + std::string(";" + std::string(xtitle) + ";" + std::string(ytitle)).c_str(), + nbin, + low, + high)); + pdfVar.at(idx)->Sumw2(); + } +} // to get ratio plots correctly - need to modify PostProcessor_cff.py as well! + +void LheWeightValidation::dqmBeginRun(const edm::Run&, const edm::EventSetup&) {} + +void LheWeightValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle lheEvt; + + if (!lheEvtToken_.isUninitialized()) + iEvent.getByToken(lheEvtToken_, lheEvt); + + if (!lheEvt.isValid()) + return; // do nothing if there is no LHE product + + orgWgt_ = lheEvt->originalXWGTUP(); + weight_ = orgWgt_ / std::abs(orgWgt_); + weights_ = lheEvt->weights(); + + nEvt_->Fill(0.5, weight_); + nlogWgt_->Fill(std::log10(lheEvt->weights().size()), weight_); + + for (unsigned idx = 0; idx < lheEvt->weights().size(); idx++) + wgtVal_->Fill(weights_[idx].wgt / orgWgt_); + + edm::Handle ptcls; + iEvent.getByToken(genParticleToken_, ptcls); + edm::Handle genjets; + iEvent.getByToken(genJetToken_, genjets); + + std::vector leptons; + + for (unsigned iptc = 0; iptc < ptcls->size(); iptc++) { + reco::GenParticleRef ptc(ptcls, iptc); + if (ptc->status() == 1 && (std::abs(ptc->pdgId()) == 11 || std::abs(ptc->pdgId()) == 13)) { + if (ptc->pt() > leadLepPtCut_ && std::abs(ptc->eta()) < lepEtaCut_) + leptons.push_back(ptc); + } + } + + std::sort(leptons.begin(), leptons.end(), HepMCValidationHelper::sortByPtRef); + + if (!leptons.empty()) { + reco::GenParticleRef leadLep = leptons.at(0); + fillTemplates(leadLepPtScaleVar_, leadLepPtPdfVar_, leadLepPtTemp_, leadLep->pt()); + fillTemplates(leadLepEtaScaleVar_, leadLepEtaPdfVar_, leadLepEtaTemp_, leadLep->eta()); + } + + std::vector genjetVec; + + for (unsigned igj = 0; igj < genjets->size(); igj++) { + reco::GenJetRef genjet(genjets, igj); + + if (genjet->pt() > jetPtCut_ && std::abs(genjet->eta()) < jetEtaCut_) + genjetVec.push_back(genjet); + } + + fillTemplates(jetMultScaleVar_, jetMultPdfVar_, jetMultTemp_, (float)genjetVec.size()); + + if (!genjetVec.empty()) { + std::sort(genjetVec.begin(), genjetVec.end(), HepMCValidationHelper::sortByPtRef); + + auto leadJet = genjetVec.at(0); + fillTemplates(leadJetPtScaleVar_, leadJetPtPdfVar_, leadJetPtTemp_, leadJet->pt()); + fillTemplates(leadJetEtaScaleVar_, leadJetEtaPdfVar_, leadJetEtaTemp_, leadJet->eta()); + } +} //analyze + +void LheWeightValidation::fillTemplates(std::vector>& scaleVar, + std::vector>& pdfVar, + std::vector& tmps, + float obs) { + tmps.at(0)->Fill(obs, weight_); + + if (static_cast(weights_.size()) >= nScaleVar_) { + for (int iWgt = 0; iWgt < nScaleVar_; iWgt++) + scaleVar.at(iWgt)->Fill(obs, weights_[iWgt].wgt / orgWgt_); + } + + if (static_cast(weights_.size()) >= idxPdfEnd_) { + for (int iWgt = 0; iWgt < nPdfVar_; iWgt++) + pdfVar.at(iWgt)->Fill(obs, weights_[idxPdfStart_ + iWgt].wgt / orgWgt_); + } +} + +void LheWeightValidation::dqmEndRun(const edm::Run& iRun, const edm::EventSetup&) { + if (lheRunToken_.isUninitialized()) + return; + + edm::Handle lheInfo; + iRun.getByToken(lheRunToken_, lheInfo); + + if (!lheInfo.isValid()) + return; + + envelop(leadLepPtScaleVar_, leadLepPtTemp_); + pdfRMS(leadLepPtPdfVar_, leadLepPtTemp_); + envelop(leadLepEtaScaleVar_, leadLepEtaTemp_); + pdfRMS(leadLepEtaPdfVar_, leadLepEtaTemp_); + envelop(jetMultScaleVar_, jetMultTemp_); + pdfRMS(jetMultPdfVar_, jetMultTemp_); + envelop(leadJetPtScaleVar_, leadJetPtTemp_); + pdfRMS(leadJetPtPdfVar_, leadJetPtTemp_); + envelop(leadJetEtaScaleVar_, leadJetEtaTemp_); + pdfRMS(leadJetEtaPdfVar_, leadJetEtaTemp_); + + if (dumpLHEheader_) { + for (auto it = lheInfo->headers_begin(); it != lheInfo->headers_end(); it++) { + std::cout << "Header start" << std::endl; + std::cout << "Tag: " << it->tag() << std::endl; + for (const auto& l : it->lines()) { + std::cout << l << std::endl; + } + std::cout << "Header end" << std::endl; + } + } +} + +void LheWeightValidation::envelop(const std::vector>& var, std::vector& tmps) { + if (var.empty()) + return; + + for (int b = 0; b < var.at(0)->GetNbinsX() + 2; b++) { + float valU = var.at(0)->GetBinContent(b); + float valD = valU; + + if (valU == 0.) + continue; + + for (unsigned v = 1; v < var.size(); v++) { + if (var.at(v)->GetEntries() == 0.) + continue; + + valU = std::max(valU, (float)var.at(v)->GetBinContent(b)); + valD = std::min(valD, (float)var.at(v)->GetBinContent(b)); + } + tmps.at(1)->setBinContent(b, valU); + tmps.at(2)->setBinContent(b, valD); + } + + tmps.at(1)->setEntries(var.at(0)->GetEntries()); + tmps.at(2)->setEntries(var.at(0)->GetEntries()); + tmps.at(1)->getTH1()->Sumw2(true); + tmps.at(2)->getTH1()->Sumw2(true); + + return; +} + +void LheWeightValidation::pdfRMS(const std::vector>& var, std::vector& tmps) { + if (var.empty()) + return; + + float denom = var.size(); + for (int b = 0; b < tmps.at(0)->getNbinsX() + 2; b++) { + float valNom = tmps.at(0)->getBinContent(b); + float rmsSq = 0.; + if (valNom == 0.) + continue; + + for (unsigned v = 0; v < var.size(); v++) { + if (var.at(v)->GetEntries() == 0.) + continue; + + float dev = (float)var.at(v)->GetBinContent(b) - valNom; + rmsSq += dev * dev; + } + + float rms = std::sqrt(rmsSq / denom); + float rmsup = valNom + rms; + float rmsdn = valNom - rms; + tmps.at(5)->setBinContent(b, rmsup); + tmps.at(6)->setBinContent(b, rmsdn); + } + + tmps.at(5)->setEntries(tmps.at(0)->getTH1F()->GetEntries()); + tmps.at(6)->setEntries(tmps.at(0)->getTH1F()->GetEntries()); + tmps.at(5)->getTH1()->Sumw2(true); + tmps.at(6)->getTH1()->Sumw2(true); + + return; +} diff --git a/Validation/EventGenerator/plugins/Module.cc b/Validation/EventGenerator/plugins/Module.cc index 0cfa427f61fa1..72cd3fc33137c 100644 --- a/Validation/EventGenerator/plugins/Module.cc +++ b/Validation/EventGenerator/plugins/Module.cc @@ -45,3 +45,9 @@ DEFINE_FWK_MODULE(BPhysicsValidation); #include "Validation/EventGenerator/interface/BPhysicsSpectrum.h" DEFINE_FWK_MODULE(BPhysicsSpectrum); + +#include "Validation/EventGenerator/interface/GenWeightValidation.h" +DEFINE_FWK_MODULE(GenWeightValidation); + +#include "Validation/EventGenerator/interface/LheWeightValidation.h" +DEFINE_FWK_MODULE(LheWeightValidation); diff --git a/Validation/EventGenerator/plugins/WeightManager.cc b/Validation/EventGenerator/plugins/WeightManager.cc deleted file mode 100644 index 1bfa03461bd33..0000000000000 --- a/Validation/EventGenerator/plugins/WeightManager.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include "Validation/EventGenerator/interface/WeightManager.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/Common/interface/Handle.h" -#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" -#include "Validation/EventGenerator/interface/DQMHelper.h" - -using namespace edm; - -WeightManager::WeightManager(const ParameterSet& iConfig, edm::ConsumesCollector iC) - : _useHepMC(iConfig.getParameter("UseWeightFromHepMC")) { - if (_useHepMC) { - _hepmcCollection = iConfig.getParameter("hepmcCollection"); - hepmcCollectionToken_ = iC.consumes(_hepmcCollection); - } else { - _genEventInfos = iConfig.getParameter >("genEventInfos"); - for (unsigned int i = 0; i < _genEventInfos.size(); i++) - genEventInfosTokens_.push_back(iC.consumes >(_genEventInfos[i])); - } -} - -double WeightManager::weight(const Event& iEvent) { - if (_useHepMC) { - edm::Handle evt; - iEvent.getByToken(hepmcCollectionToken_, evt); - const HepMC::GenEvent* myGenEvent = evt->GetEvent(); - - double weight = 1.; - if (!myGenEvent->weights().empty()) - weight = myGenEvent->weights()[0]; - return weight; - } else { - double weight = 1.; - for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i) { - edm::Handle info; - iEvent.getByToken(genEventInfosTokens_[i], info); - weight *= info->weight(); - } - return weight; - } -} diff --git a/Validation/EventGenerator/python/BasicGenValidation_cff.py b/Validation/EventGenerator/python/BasicGenValidation_cff.py index 29ed3aa1f90ae..76e85449d1be5 100644 --- a/Validation/EventGenerator/python/BasicGenValidation_cff.py +++ b/Validation/EventGenerator/python/BasicGenValidation_cff.py @@ -24,11 +24,14 @@ from Validation.EventGenerator.TTbar_Validation_cfi import * #Higgs -from Validation.EventGenerator.HiggsValidation_cfi import * +from Validation.EventGenerator.HiggsValidation_cfi import * #B-physics from Validation.EventGenerator.BPhysicsValidation_cfi import * +from Validation.EventGenerator.GenWeightValidation_cff import * +from Validation.EventGenerator.LheWeightValidation_cff import * + # define sequences... basicGenTest_seq = cms.Sequence(basicHepMCValidation+basicGenParticleValidation) basicGenTestHiMix_seq = cms.Sequence(basicHepMCValidation+basicGenParticleValidationHiMix) @@ -50,6 +53,14 @@ genvalid_w = cms.Sequence(basicGenTest_seq+mbueAndqcdValidation_seq+wValidation_seq+tauValidation_seq) genvalid_top = cms.Sequence(basicGenTest_seq+mbueAndqcdValidation_seq+TTbarfull_seq) genvalid_higgs = cms.Sequence(basicGenTest_seq+mbueAndqcdValidation_seq+higgsvalidation_seq) -genvalid_all = cms.Sequence(basicGenTest_seq+mbueAndqcdValidation_seq+drellYanValidation_seq+wValidation_seq+tauValidation_seq+TTbarfull_seq+higgsValidation+bphysics) + +genvalid_genWgt = cms.Sequence(genWeightValidationSeq) +genvalid_lheWgt = cms.Sequence(lheWeightValidationSeq) +genvalid_allWeight = cms.Sequence(genWeightValidationSeq+lheWeightValidationSeq) + genvalid_all_hiMix = cms.Sequence(basicGenTestHiMix_seq+mbueAndqcdValidation_seq+drellYanValidation_seq+wValidation_seq+tauValidation_seq+TTbarfull_seq+higgsValidation+bphysics) -genvalid_all_and_dup_check = cms.Sequence(duplicationChecker_seq+genvalid_all) +genvalid_all_noWgt = cms.Sequence(basicGenTest_seq+mbueAndqcdValidation_seq+drellYanValidation_seq+wValidation_seq+tauValidation_seq+TTbarfull_seq+higgsValidation+bphysics) +genvalid_all_and_dup_check = cms.Sequence(duplicationChecker_seq+genvalid_all_noWgt) +genvalid_all_genWgt = cms.Sequence(genvalid_all_noWgt+genvalid_genWgt) +genvalid_all_lheWgt = cms.Sequence(genvalid_all_noWgt+genvalid_lheWgt) +genvalid_all = cms.Sequence(genvalid_all_noWgt+genvalid_allWeight) diff --git a/Validation/EventGenerator/python/GenWeightValidation_cff.py b/Validation/EventGenerator/python/GenWeightValidation_cff.py new file mode 100644 index 0000000000000..33ca1627b4bd3 --- /dev/null +++ b/Validation/EventGenerator/python/GenWeightValidation_cff.py @@ -0,0 +1,27 @@ +import FWCore.ParameterSet.Config as cms + +from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer +genWeightValidation = DQMEDAnalyzer('GenWeightValidation', + UseWeightFromHepMC = cms.bool(False), + genEventInfos = cms.VInputTag('generator'), + genParticles = cms.InputTag('genParticles'), + genJets = cms.InputTag('ak4GenJets'), + whichGenEventInfo = cms.int32(0), + idxFSRup = cms.int32(5), + idxFSRdown = cms.int32(4), + idxISRup = cms.int32(27), + idxISRdown = cms.int32(26), + leadLepPtRange = cms.double(200.), + leadLepPtNbin = cms.int32(100), + leadLepPtCut = cms.double(20.), + lepEtaCut = cms.double(2.4), + jetPtCut = cms.double(20.), + rapidityRange = cms.double(2.4), + rapidityNbin = cms.int32(120), + jetEtaCut = cms.double(2.4), + nJetsNbin = cms.int32(20), + jetPtRange = cms.double(200.), + jetPtNbin = cms.int32(100) +) + +genWeightValidationSeq = cms.Sequence(genWeightValidation) diff --git a/Validation/EventGenerator/python/LheWeightValidation_cff.py b/Validation/EventGenerator/python/LheWeightValidation_cff.py new file mode 100644 index 0000000000000..c59366826184c --- /dev/null +++ b/Validation/EventGenerator/python/LheWeightValidation_cff.py @@ -0,0 +1,25 @@ +import FWCore.ParameterSet.Config as cms + +from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer +lheWeightValidation = DQMEDAnalyzer('LheWeightValidation', + lheProduct = cms.InputTag('externalLHEProducer'), + genParticles = cms.InputTag('genParticles'), + genJets = cms.InputTag('ak4GenJets'), + dumpLHEheader = cms.bool(False), + nScaleVar = cms.int32(9), + idxPdfStart = cms.int32(9), + idxPdfEnd = cms.int32(111), + leadLepPtRange = cms.double(200.), + leadLepPtNbin = cms.int32(100), + leadLepPtCut = cms.double(20.), + lepEtaCut = cms.double(2.4), + rapidityRange = cms.double(2.4), + rapidityNbin = cms.int32(120), + jetPtCut = cms.double(20.), + jetEtaCut = cms.double(2.4), + nJetsNbin = cms.int32(20), + jetPtRange = cms.double(200.), + jetPtNbin = cms.int32(100) +) + +lheWeightValidationSeq = cms.Sequence(lheWeightValidation) diff --git a/Validation/EventGenerator/python/PostProcessor_cff.py b/Validation/EventGenerator/python/PostProcessor_cff.py index d5ca389b12289..513a721c8411d 100755 --- a/Validation/EventGenerator/python/PostProcessor_cff.py +++ b/Validation/EventGenerator/python/PostProcessor_cff.py @@ -351,22 +351,22 @@ subDirs = cms.untracked.vstring("Generator/GenParticles*"), efficiency = cms.vstring(""), resolution = cms.vstring(""), - normalization = cms.untracked.vstring("genPMultiplicity nEvt", - "genMatched nEvt", - "multipleMatching nEvt", - "matchedResolution nEvt", - "genJetMult nEvt", - "genJetEnergy nEvt", - "genJetPt nEvt", - "genJetEta nEvt", - "genJetPhi nEvt", - "genJetDeltaEtaMin nEvt", - "genJetPto1 nEvt", - "genJetPto10 nEvt", - "genJetPto100 nEvt", - "genJetCentral nEvt", - "genJetTotPt nEvt") -) + normalization = cms.untracked.vstring("genPMultiplicity nEvt", + "genMatched nEvt", + "multipleMatching nEvt", + "matchedResolution nEvt", + "genJetMult nEvt", + "genJetEnergy nEvt", + "genJetPt nEvt", + "genJetEta nEvt", + "genJetPhi nEvt", + "genJetDeltaEtaMin nEvt", + "genJetPto1 nEvt", + "genJetPto10 nEvt", + "genJetPto100 nEvt", + "genJetCentral nEvt", + "genJetTotPt nEvt") +) postProcessorMBUEandQCDValidation = DQMEDHarvester( "DQMGenericClient", @@ -444,56 +444,56 @@ "sumET1 nEvt", "sumET2 nEvt", "sumET3 nEvt", - "sumET4 nEvt", + "sumET4 nEvt", "sumET5 nEvt", "nEvt1 nEvt", "nEvt2 nEvt", "nHFflow nEvt", "nHFSD nEvt", "Tracketa nEvt") -) +) postProcessorWValidation = DQMEDHarvester( "DQMGenericClient", subDirs = cms.untracked.vstring("Generator/W*"), efficiency = cms.vstring(""), resolution = cms.vstring(""), - normalization = cms.untracked.vstring("Wmass nEvt", - "WmassPeak nEvt", - "Wpt nEvt", - "WptLog nEvt", - "Wrap nEvt", - "Wdaughters nEvt", - "lepmet_mT nEvt", - "lepmet_mTPeak nEvt", - "lepmet_pt nEvt", - "lepmet_ptLog nEvt", - "gamma_energy nEvt", + normalization = cms.untracked.vstring("Wmass nEvt", + "WmassPeak nEvt", + "Wpt nEvt", + "WptLog nEvt", + "Wrap nEvt", + "Wdaughters nEvt", + "lepmet_mT nEvt", + "lepmet_mTPeak nEvt", + "lepmet_pt nEvt", + "lepmet_ptLog nEvt", + "gamma_energy nEvt", "cos_theta_gamma_lepton nEvt", "leppt nEvt", "met nEvt", "lepeta nEvt", "leadpt nEvt", "leadeta nEvt") -) +) postProcessorDrellYanValidation = DQMEDHarvester( "DQMGenericClient", subDirs = cms.untracked.vstring("Generator/DrellYan*"), efficiency = cms.vstring(""), resolution = cms.vstring(""), - normalization = cms.untracked.vstring("Zmass nEvt", - "ZmassPeak nEvt", - "Zpt nEvt", - "ZptLog nEvt", - "Zrap nEvt", - "Zdaughters nEvt", - "dilep_mass nEvt", - "dilep_massPeak nEvt", - "dilep_pt nEvt", + normalization = cms.untracked.vstring("Zmass nEvt", + "ZmassPeak nEvt", + "Zpt nEvt", + "ZptLog nEvt", + "Zrap nEvt", + "Zdaughters nEvt", + "dilep_mass nEvt", + "dilep_massPeak nEvt", + "dilep_pt nEvt", "dilep_ptLog nEvt", "dilep_rap nEvt", - "gamma_energy nEvt", + "gamma_energy nEvt", "cos_theta_gamma_lepton nEvt", "leadpt nEvt", "secpt nEvt", @@ -588,17 +588,17 @@ efficiency = cms.vstring(""), resolution = cms.vstring(""), normalization = cms.untracked.vstring("TTbar_BottomE nEvt", - "TTbar_BottomEta nEvt", - "TTbar_BottomMass nEvt", - "TTbar_BottomPt nEvt", - "TTbar_BottomPz nEvt", - "TTbar_BottomY nEvt", + "TTbar_BottomEta nEvt", + "TTbar_BottomMass nEvt", + "TTbar_BottomPt nEvt", + "TTbar_BottomPz nEvt", + "TTbar_BottomY nEvt", "TTbar_TTbarMass nEvt", "TTbar_TTbarPt nEvt", "TTbar_TTbarY nEvt", "TTbar_TopMass nEvt", - "TTbar_TopPt nEvt", - "TTbar_TopY nEvt", + "TTbar_TopPt nEvt", + "TTbar_TopY nEvt", "TTbar_WminPz nEvt", "TTbar_WplusPz nEvt", "TTbar_jetEta1 nEvt", @@ -616,21 +616,21 @@ "TTbar_lepEta3 nEvt", "TTbar_lepEta4 nEvt", "TTbar_lepEtaAll nEvt", - "TTbar_lepN nEvt", - "TTbar_lepPt1_genParticlesElectrons nEvt", - "TTbar_lepPt1_genParticlesMuons nEvt", - "TTbar_lepPt1_genParticlesNeutrinos nEvt", - "TTbar_lepPt2_genParticlesElectrons nEvt", - "TTbar_lepPt2_genParticlesMuons nEvt", - "TTbar_lepPt2_genParticlesNeutrinos nEvt", - "TTbar_lepPt3_genParticlesElectrons nEvt", - "TTbar_lepPt3_genParticlesMuons nEvt", - "TTbar_lepPt3_genParticlesNeutrinos nEvt", - "TTbar_lepPt4_genParticlesElectrons nEvt", - "TTbar_lepPt4_genParticlesMuons nEvt", - "TTbar_lepPt4_genParticlesNeutrinos nEvt", + "TTbar_lepN nEvt", + "TTbar_lepPt1_genParticlesElectrons nEvt", + "TTbar_lepPt1_genParticlesMuons nEvt", + "TTbar_lepPt1_genParticlesNeutrinos nEvt", + "TTbar_lepPt2_genParticlesElectrons nEvt", + "TTbar_lepPt2_genParticlesMuons nEvt", + "TTbar_lepPt2_genParticlesNeutrinos nEvt", + "TTbar_lepPt3_genParticlesElectrons nEvt", + "TTbar_lepPt3_genParticlesMuons nEvt", + "TTbar_lepPt3_genParticlesNeutrinos nEvt", + "TTbar_lepPt4_genParticlesElectrons nEvt", + "TTbar_lepPt4_genParticlesMuons nEvt", + "TTbar_lepPt4_genParticlesNeutrinos nEvt", "TTbar_lepPtAll_genParticlesElectrons nEvt", - "TTbar_lepPtAll_genParticlesMuons nEvt", + "TTbar_lepPtAll_genParticlesMuons nEvt", "TTbar_lepPtAll_genParticlesNeutrinos nEvt" ) ) @@ -682,7 +682,7 @@ "tau_eta nEvt", "tau_pt nEvt", "u_eta nEvt", - "u_pt nEvt" + "u_pt nEvt" ) ) @@ -784,6 +784,118 @@ ) ) +postProcessorGenWeightValidation = DQMEDHarvester( + "DQMGenericClient", + subDirs = cms.untracked.vstring("Generator/GenWeight*"), + efficiency = cms.vstring( + "leadLepPtFSRup_ratio 'Ratio of leading lepton Pt FSR up / Nominal' leadLepPtFSRup leadLepPt simpleratio", + "leadLepPtFSRdn_ratio 'Ratio of leading lepton Pt FSR down / Nominal' leadLepPtFSRdn leadLepPt simpleratio", + "leadLepPtISRup_ratio 'Ratio of leading lepton Pt ISR up / Nominal' leadLepPtISRup leadLepPt simpleratio", + "leadLepPtISRdn_ratio 'Ratio of leading lepton Pt ISR down / Nominal' leadLepPtISRdn leadLepPt simpleratio", + "leadLepEtaFSRup_ratio 'Ratio of leading lepton #eta FSR up / Nominal' leadLepEtaFSRup leadLepEta simpleratio", + "leadLepEtaFSRdn_ratio 'Ratio of leading lepton #eta FSR down / Nominal' leadLepEtaFSRdn leadLepEta simpleratio", + "leadLepEtaISRup_ratio 'Ratio of leading lepton #eta ISR up / Nominal' leadLepEtaISRup leadLepEta simpleratio", + "leadLepEtaISRdn_ratio 'Ratio of leading lepton #eta ISR down / Nominal' leadLepEtaISRdn leadLepEta simpleratio", + "JetMultiplicityFSRup_ratio 'Ratio of Gen jet multiplicity FSR up / Nominal' JetMultiplicityFSRup JetMultiplicity simpleratio", + "JetMultiplicityFSRdn_ratio 'Ratio of Gen jet multiplicity FSR down / Nominal' JetMultiplicityFSRdn JetMultiplicity simpleratio", + "JetMultiplicityISRup_ratio 'Ratio of Gen jet multiplicity ISR up / Nominal' JetMultiplicityISRup JetMultiplicity simpleratio", + "JetMultiplicityISRdn_ratio 'Ratio of Gen jet multiplicity ISR down / Nominal' JetMultiplicityISRdn JetMultiplicity simpleratio", + "leadJetPtFSRup_ratio 'Ratio of leading Gen jet Pt FSR up / Nominal' leadJetPtFSRup leadJetPt simpleratio", + "leadJetPtFSRdn_ratio 'Ratio of leading Gen jet Pt FSR down / Nominal' leadJetPtFSRdn leadJetPt simpleratio", + "leadJetPtISRup_ratio 'Ratio of leading Gen jet Pt ISR up / Nominal' leadJetPtISRup leadJetPt simpleratio", + "leadJetPtISRdn_ratio 'Ratio of leading Gen jet Pt ISR down / Nominal' leadJetPtISRdn leadJetPt simpleratio", + "leadJetEtaFSRup_ratio 'Ratio of leading Gen jet #eta FSR up / Nominal' leadJetEtaFSRup leadJetEta simpleratio", + "leadJetEtaFSRdn_ratio 'Ratio of leading Gen jet #eta FSR down / Nominal' leadJetEtaFSRdn leadJetEta simpleratio", + "leadJetEtaISRup_ratio 'Ratio of leading Gen jet #eta ISR up / Nominal' leadJetEtaISRup leadJetEta simpleratio", + "leadJetEtaISRdn_ratio 'Ratio of leading Gen jet #eta ISR down / Nominal' leadJetEtaISRdn leadJetEta simpleratio" + ), + resolution = cms.vstring(""), + normalization = cms.untracked.vstring("nlogWgt nEvt", + "wgtVal nEvt", + "leadLepPt nEvt", + "leadLepPtFSRup nEvt", + "leadLepPtFSRdn nEvt", + "leadLepPtISRup nEvt", + "leadLepPtISRdn nEvt", + "leadLepEta nEvt", + "leadLepEtaFSRup nEvt", + "leadLepEtaFSRdn nEvt", + "leadLepEtaISRup nEvt", + "leadLepEtaISRdn nEvt", + "JetMultiplicity nEvt", + "JetMultiplicityFSRup nEvt", + "JetMultiplicityFSRdn nEvt", + "JetMultiplicityISRup nEvt", + "JetMultiplicityISRdn nEvt", + "leadJetPt nEvt", + "leadJetPtFSRup nEvt", + "leadJetPtFSRdn nEvt", + "leadJetPtISRup nEvt", + "leadJetPtISRdn nEvt", + "leadJetEta nEvt", + "leadJetEtaFSRup nEvt", + "leadJetEtaFSRdn nEvt", + "leadJetEtaISRup nEvt", + "leadJetEtaISRdn nEvt" + ) +) + +postProcessorLheWeightValidation = DQMEDHarvester( + "DQMGenericClient", + subDirs = cms.untracked.vstring("Generator/LHEWeight*"), + efficiency = cms.vstring( + "leadLepPtScaleUp_ratio 'Ratio of leading lepton Pt scale upper envelop / Nominal' leadLepPtScaleUp leadLepPt simpleratio", + "leadLepPtScaleDn_ratio 'Ratio of leading lepton Pt scale lower envelop / Nominal' leadLepPtScaleDn leadLepPt simpleratio", + "leadLepPtPdfUp_ratio 'Ratio of leading lepton Pt PDF upper RMS / Nominal' leadLepPtPdfUp leadLepPt simpleratio", + "leadLepPtPdfDn_ratio 'Ratio of leading lepton Pt PDF lower RMS / Nominal' leadLepPtPdfDn leadLepPt simpleratio", + "leadLepEtaScaleUp_ratio 'Ratio of leading lepton #eta scale upper envelop / Nominal' leadLepEtaScaleUp leadLepEta simpleratio", + "leadLepEtaScaleDn_ratio 'Ratio of leading lepton #eta scale lower envelop / Nominal' leadLepEtaScaleDn leadLepEta simpleratio", + "leadLepEtaPdfUp_ratio 'Ratio of leading lepton #eta PDF upper RMS / Nominal' leadLepEtaPdfUp leadLepEta simpleratio", + "leadLepEtaPdfDn_ratio 'Ratio of leading lepton #eta PDF lower RMS / Nominal' leadLepEtaPdfDn leadLepEta simpleratio", + "JetMultiplicityScaleUp_ratio 'Ratio of Gen jet multiplicity scale upper envelop / Nominal' JetMultiplicityScaleUp JetMultiplicity simpleratio", + "JetMultiplicityScaleDn_ratio 'Ratio of Gen jet multiplicity scale lower envelop / Nominal' JetMultiplicityScaleDn JetMultiplicity simpleratio", + "JetMultiplicityPdfUp_ratio 'Ratio of Gen jet multiplicity PDF upper RMS / Nominal' JetMultiplicityPdfUp JetMultiplicity simpleratio", + "JetMultiplicityPdfDn_ratio 'Ratio of Gen jet multiplicity PDF lower RMS / Nominal' JetMultiplicityPdfDn JetMultiplicity simpleratio", + "leadJetPtScaleUp_ratio 'Ratio of leading Gen jet Pt scale upper envelop / Nominal' leadJetPtScaleUp leadJetPt simpleratio", + "leadJetPtScaleDn_ratio 'Ratio of leading Gen jet Pt scale lower envelop / Nominal' leadJetPtScaleDn leadJetPt simpleratio", + "leadJetPtPdfUp_ratio 'Ratio of leading Gen jet Pt PDF upper RMS / Nominal' leadJetPtPdfUp leadJetPt simpleratio", + "leadJetPtPdfDn_ratio 'Ratio of leading Gen jet Pt PDF lower RMS / Nominal' leadJetPtPdfDn leadJetPt simpleratio", + "leadJetEtaScaleUp_ratio 'Ratio of leading Gen jet #eta scale upper envelop / Nominal' leadJetEtaScaleUp leadJetEta simpleratio", + "leadJetEtaScaleDn_ratio 'Ratio of leading Gen jet #eta scale lower envelop / Nominal' leadJetEtaScaleDn leadJetEta simpleratio", + "leadJetEtaPdfUp_ratio 'Ratio of leading Gen jet #eta PDF upper RMS / Nominal' leadJetEtaPdfUp leadJetEta simpleratio", + "leadJetEtaPdfDn_ratio 'Ratio of leading Gen jet #eta PDF lower RMS / Nominal' leadJetEtaPdfDn leadJetEta simpleratio" + ), + resolution = cms.vstring(""), + normalization = cms.untracked.vstring("nlogWgt nEvt", + "wgtVal nEvt", + "leadLepPt nEvt", + "leadLepPtScaleUp nEvt", + "leadLepPtScaleDn nEvt", + "leadLepPtPdfUp nEvt", + "leadLepPtPdfDn nEvt", + "leadLepEta nEvt", + "leadLepEtaScaleUp nEvt", + "leadLepEtaScaleDn nEvt", + "leadLepEtaPdfUp nEvt", + "leadLepEtaPdfDn nEvt", + "JetMultiplicity nEvt", + "JetMultiplicityScaleUp nEvt", + "JetMultiplicityScaleDn nEvt", + "JetMultiplicityPdfUp nEvt", + "JetMultiplicityPdfDn nEvt", + "leadJetPt nEvt", + "leadJetPtScaleUp nEvt", + "leadJetPtScaleDn nEvt", + "leadJetPtPdfUp nEvt", + "leadJetPtPdfDn nEvt", + "leadJetEta nEvt", + "leadJetEtaScaleUp nEvt", + "leadJetEtaScaleDn nEvt", + "leadJetEtaPdfUp nEvt", + "leadJetEtaPdfDn nEvt" + ) +) + -EventGeneratorPostProcessor = cms.Sequence(postProcessorBasicHepMCValidation+postProcessorBasicGenParticleValidation+postProcessorMBUEandQCDValidation+postProcessorWValidation+postProcessorDrellYanValidation+postProcessorTauValidation+postProcessorTTbarValidation+postProcessorTTbarSpinCorr+postProcessorHiggsValidation+postProcessorHplusValidation+postProcessorBPhysicsValidation) +EventGeneratorPostProcessor = cms.Sequence(postProcessorBasicHepMCValidation+postProcessorBasicGenParticleValidation+postProcessorMBUEandQCDValidation+postProcessorWValidation+postProcessorDrellYanValidation+postProcessorTauValidation+postProcessorTTbarValidation+postProcessorTTbarSpinCorr+postProcessorHiggsValidation+postProcessorHplusValidation+postProcessorBPhysicsValidation+postProcessorGenWeightValidation+postProcessorLheWeightValidation) diff --git a/Validation/EventGenerator/src/WeightManager.cc b/Validation/EventGenerator/src/WeightManager.cc index c79b216bb0396..ef86b4bb848f2 100644 --- a/Validation/EventGenerator/src/WeightManager.cc +++ b/Validation/EventGenerator/src/WeightManager.cc @@ -14,9 +14,9 @@ WeightManager::WeightManager(const ParameterSet& iConfig, edm::ConsumesCollector _hepmcCollection = iConfig.getParameter("hepmcCollection"); hepmcCollectionToken_ = iC.consumes(_hepmcCollection); } else { - _genEventInfos = iConfig.getParameter >("genEventInfos"); + _genEventInfos = iConfig.getParameter>("genEventInfos"); for (unsigned int i = 0; i < _genEventInfos.size(); i++) - genEventInfosTokens_.push_back(iC.consumes >(_genEventInfos[i])); + genEventInfosTokens_.push_back(iC.consumes(_genEventInfos[i])); } } @@ -40,3 +40,14 @@ double WeightManager::weight(const Event& iEvent) { return weight; } } + +std::vector> WeightManager::weightsCollection(const Event& iEvent) { + std::vector> weightsCollection; + for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i) { + edm::Handle info; + iEvent.getByToken(genEventInfosTokens_[i], info); + weightsCollection.push_back(info->weights()); + } + + return weightsCollection; +}