Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GEN/LHE weight validation subdirectories for GEN Relval #36994

Merged
merged 13 commits into from
Mar 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -13,6 +14,7 @@
PythiaParameters = cms.PSet(
pythia8CommonSettingsBlock,
pythia8CP5SettingsBlock,
pythia8PSweightsSettingsBlock,
pythia8aMCatNLOSettingsBlock,
processParameters = cms.vstring(
'JetMatching:setMad = off',
Expand All @@ -30,6 +32,7 @@
),
parameterSets = cms.vstring('pythia8CommonSettings',
'pythia8CP5Settings',
'pythia8PSweightsSettings',
'pythia8aMCatNLOSettings',
'processParameters',
)
Expand Down
69 changes: 69 additions & 0 deletions Validation/EventGenerator/interface/GenWeightValidation.h
Original file line number Diff line number Diff line change
@@ -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<MonitorElement *> &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<MonitorElement *> &tmps, float obs);
WeightManager wmanager_;

double weight_;
std::vector<std::vector<double>> weights_;

MonitorElement *nEvt_;
MonitorElement *nlogWgt_;
MonitorElement *wgtVal_;
std::vector<MonitorElement *> leadLepPtTemp_;
std::vector<MonitorElement *> leadLepEtaTemp_;
std::vector<MonitorElement *> jetMultTemp_;
std::vector<MonitorElement *> leadJetPtTemp_;
std::vector<MonitorElement *> leadJetEtaTemp_;

const edm::EDGetTokenT<reco::GenParticleCollection> genParticleToken_;
const edm::EDGetTokenT<reco::GenJetCollection> 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
5 changes: 5 additions & 0 deletions Validation/EventGenerator/interface/HepMCValidationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace HepMCValidationHelper {
return a->momentum().perp() > b->momentum().perp();
}

template <class T>
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();
Expand Down
99 changes: 99 additions & 0 deletions Validation/EventGenerator/interface/LheWeightValidation.h
Original file line number Diff line number Diff line change
@@ -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<std::unique_ptr<TH1F>>& scaleVar,
std::vector<std::unique_ptr<TH1F>>& pdfVar,
std::vector<MonitorElement*>& 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<std::unique_ptr<TH1F>>& scaleVar,
std::vector<std::unique_ptr<TH1F>>& pdfVar,
std::vector<MonitorElement*>& tmps,
float obs);

void envelop(const std::vector<std::unique_ptr<TH1F>>& var, std::vector<MonitorElement*>& tmps);
void pdfRMS(const std::vector<std::unique_ptr<TH1F>>& var, std::vector<MonitorElement*>& tmps);

double weight_, orgWgt_;
std::vector<LHEEventProduct::WGT> weights_;

MonitorElement* nEvt_;
MonitorElement* nlogWgt_;
MonitorElement* wgtVal_;
std::vector<MonitorElement*> leadLepPtTemp_;
std::vector<MonitorElement*> leadLepEtaTemp_;
std::vector<MonitorElement*> jetMultTemp_;
std::vector<MonitorElement*> leadJetPtTemp_;
std::vector<MonitorElement*> leadJetEtaTemp_;

std::vector<std::unique_ptr<TH1F>> leadLepPtScaleVar_;
std::vector<std::unique_ptr<TH1F>> leadLepPtPdfVar_;
std::vector<std::unique_ptr<TH1F>> leadLepEtaScaleVar_;
std::vector<std::unique_ptr<TH1F>> leadLepEtaPdfVar_;
std::vector<std::unique_ptr<TH1F>> jetMultScaleVar_;
std::vector<std::unique_ptr<TH1F>> jetMultPdfVar_;
std::vector<std::unique_ptr<TH1F>> leadJetPtScaleVar_;
std::vector<std::unique_ptr<TH1F>> leadJetPtPdfVar_;
std::vector<std::unique_ptr<TH1F>> leadJetEtaScaleVar_;
std::vector<std::unique_ptr<TH1F>> leadJetEtaPdfVar_;

const edm::InputTag lheLabel_;
const edm::EDGetTokenT<reco::GenParticleCollection> genParticleToken_;
const edm::EDGetTokenT<LHEEventProduct> lheEvtToken_;
const edm::EDGetTokenT<LHERunInfoProduct> lheRunToken_;
const edm::EDGetTokenT<reco::GenJetCollection> 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
6 changes: 4 additions & 2 deletions Validation/EventGenerator/interface/WeightManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>

Expand All @@ -23,14 +24,15 @@ class WeightManager {
~WeightManager(){};

double weight(const edm::Event&);
std::vector<std::vector<double>> weightsCollection(const edm::Event&);

private:
bool _useHepMC;
std::vector<edm::InputTag> _genEventInfos;
edm::InputTag _hepmcCollection;

edm::EDGetTokenT<edm::HepMCProduct> hepmcCollectionToken_;
std::vector<edm::EDGetTokenT<std::vector<edm::InputTag> > > genEventInfosTokens_;
std::vector<edm::EDGetTokenT<GenEventInfoProduct>> genEventInfosTokens_;
};

#endif
Loading