Skip to content

Commit

Permalink
scram code-format
Browse files Browse the repository at this point in the history
  • Loading branch information
SanghyunKo committed Feb 17, 2022
1 parent 3553ce2 commit eaab8d7
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 154 deletions.
29 changes: 18 additions & 11 deletions Validation/EventGenerator/interface/GenWeightValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,29 @@ class GenWeightValidation : public DQMEDAnalyzer {
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override;

private:
void bookTemplates(std::vector<MonitorElement*>& tmps, std::string name, std::string title, int nbin, float low, float high, std::string xtitle, std::string ytitle);
void fillTemplates(std::vector<MonitorElement*>& tmps, float obs);
void bookTemplates(std::vector<MonitorElement *> &tmps,
std::string name,
std::string title,
int nbin,
float low,
float high,
std::string xtitle,
std::string ytitle);
void fillTemplates(std::vector<MonitorElement *> &tmps, float obs);
WeightManager wmanager_;
DQMHelper* dqm;
DQMHelper *dqm;

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;
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;

edm::EDGetTokenT<reco::GenParticleCollection> genParticleToken;
edm::EDGetTokenT<reco::GenJetCollection> genJetToken;
Expand Down
4 changes: 3 additions & 1 deletion Validation/EventGenerator/interface/HepMCValidationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace HepMCValidationHelper {
}

template <class T>
inline bool sortByPtRef(const T lhs, const T rhs) { return lhs->pt() > rhs->pt(); }
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) {
Expand Down
31 changes: 21 additions & 10 deletions Validation/EventGenerator/interface/LheWeightValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"

class TH1F; // forward declaration for ROOT
class TH1F; // forward declaration for ROOT

class LheWeightValidation : public DQMOneEDAnalyzer<> {
public:
explicit LheWeightValidation(const edm::ParameterSet &);
explicit LheWeightValidation(const edm::ParameterSet&);
~LheWeightValidation() override;
void analyze(const edm::Event &, const edm::EventSetup &) override;
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override;
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void bookHistograms(DQMStore::IBooker& i, edm::Run const&, edm::EventSetup const&) override;
void dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) override;
void dqmEndRun(const edm::Run& r, const edm::EventSetup& c) override;

private:
void bookTemplates(std::vector<std::unique_ptr<TH1F>>& scaleVar, std::vector<std::unique_ptr<TH1F>>& pdfVar, std::vector<MonitorElement*>& tmps,
std::string name, std::string title, int nbin, float low, float high, std::string xtitle, 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 bookTemplates(std::vector<std::unique_ptr<TH1F>>& scaleVar,
std::vector<std::unique_ptr<TH1F>>& pdfVar,
std::vector<MonitorElement*>& tmps,
std::string name,
std::string title,
int nbin,
float low,
float high,
std::string xtitle,
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);
Expand Down Expand Up @@ -83,7 +94,7 @@ class LheWeightValidation : public DQMOneEDAnalyzer<> {
int nJetsNbin, jetPtNbin;
double jetPtCut, jetEtaCut, jetPtRange;

int nScaleVar; // including Nominal
int nScaleVar; // including Nominal
int idxPdfStart, idxPdfEnd, nPdfVar;
};

Expand Down
2 changes: 1 addition & 1 deletion Validation/EventGenerator/interface/WeightManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WeightManager {
edm::InputTag _hepmcCollection;

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

#endif
124 changes: 78 additions & 46 deletions Validation/EventGenerator/plugins/GenWeightValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include "Validation/EventGenerator/interface/HepMCValidationHelper.h"
using namespace edm;

GenWeightValidation::GenWeightValidation(const edm::ParameterSet& iPSet)
: wmanager_(iPSet, consumesCollector())
{
GenWeightValidation::GenWeightValidation(const edm::ParameterSet& iPSet) : wmanager_(iPSet, consumesCollector()) {
genParticleToken = consumes<reco::GenParticleCollection>(iPSet.getParameter<edm::InputTag>("genParticles"));
genJetToken = consumes<reco::GenJetCollection>(iPSet.getParameter<edm::InputTag>("genJets"));
idxGenEvtInfo = iPSet.getParameter<int>("whichGenEventInfo");
Expand All @@ -27,7 +25,7 @@ GenWeightValidation::GenWeightValidation(const edm::ParameterSet& iPSet)
jetPtRange = iPSet.getParameter<double>("jetPtRange");
jetPtNbin = iPSet.getParameter<int>("jetPtNbin");

std::vector<int> idxs = {idxFSRup,idxFSRdown,idxISRup,idxISRdown};
std::vector<int> idxs = {idxFSRup, idxFSRdown, idxISRup, idxISRdown};
std::sort(idxs.begin(), idxs.end(), std::greater<int>());
idxMax = idxs.at(0);
}
Expand All @@ -42,32 +40,66 @@ void GenWeightValidation::bookHistograms(DQMStore::IBooker& i, edm::Run const&,

// Number of analyzed events
nEvt = dqm->book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events");
nlogWgt = dqm->book1dHisto("nlogWgt","Log10(n weights)",100,0.,3.,"log_{10}(nWgts)","Number of Events");
wgtVal = dqm->book1dHisto("wgtVal","weights",100,-1.5,3.,"weight","Number of Weigths");
bookTemplates(leadLepPtTemp,"leadLepPt","leading lepton Pt",leadLepPtNbin,0.,leadLepPtRange,"Pt_{l} (GeV)","Number of Events");
bookTemplates(leadLepEtaTemp,"leadLepEta","leading lepton #eta",rapidityNbin,-rapidityRange,rapidityRange,"#eta_{l}","Number of Events");
bookTemplates(jetMultTemp,"JetMultiplicity","Gen jet multiplicity",nJetsNbin,0,nJetsNbin,"n","Number of Events");
bookTemplates(leadJetPtTemp,"leadJetPt","leading Gen jet Pt",jetPtNbin,0.,jetPtRange,"Pt_{j} (GeV)","Number of Events");
bookTemplates(leadJetEtaTemp,"leadJetEta","leading Gen jet #eta",rapidityNbin,-rapidityRange,rapidityRange,"#eta_{j}","Number of Events");
nlogWgt = dqm->book1dHisto("nlogWgt", "Log10(n weights)", 100, 0., 3., "log_{10}(nWgts)", "Number of Events");
wgtVal = dqm->book1dHisto("wgtVal", "weights", 100, -1.5, 3., "weight", "Number of Weigths");
bookTemplates(leadLepPtTemp,
"leadLepPt",
"leading lepton Pt",
leadLepPtNbin,
0.,
leadLepPtRange,
"Pt_{l} (GeV)",
"Number of Events");
bookTemplates(leadLepEtaTemp,
"leadLepEta",
"leading lepton #eta",
rapidityNbin,
-rapidityRange,
rapidityRange,
"#eta_{l}",
"Number of Events");
bookTemplates(
jetMultTemp, "JetMultiplicity", "Gen jet multiplicity", nJetsNbin, 0, nJetsNbin, "n", "Number of Events");
bookTemplates(
leadJetPtTemp, "leadJetPt", "leading Gen jet Pt", jetPtNbin, 0., jetPtRange, "Pt_{j} (GeV)", "Number of Events");
bookTemplates(leadJetEtaTemp,
"leadJetEta",
"leading Gen jet #eta",
rapidityNbin,
-rapidityRange,
rapidityRange,
"#eta_{j}",
"Number of Events");

return;
}

void GenWeightValidation::bookTemplates(std::vector<MonitorElement*>& tmps, std::string name, std::string title, int nbin, float low, float high, std::string xtitle, std::string ytitle) {
tmps.push_back(dqm->book1dHisto(name,title,nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name+"FSRup",title+" FSR up",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name+"FSRdn",title+" FSR down",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name+"FSRup_ratio","Ratio of "+title+" FSR up / Nominal",nbin,low,high,xtitle,ytitle));
void GenWeightValidation::bookTemplates(std::vector<MonitorElement*>& tmps,
std::string name,
std::string title,
int nbin,
float low,
float high,
std::string xtitle,
std::string ytitle) {
tmps.push_back(dqm->book1dHisto(name, title, nbin, low, high, xtitle, ytitle));
tmps.push_back(dqm->book1dHisto(name + "FSRup", title + " FSR up", nbin, low, high, xtitle, ytitle));
tmps.push_back(dqm->book1dHisto(name + "FSRdn", title + " FSR down", nbin, low, high, xtitle, ytitle));
tmps.push_back(dqm->book1dHisto(
name + "FSRup_ratio", "Ratio of " + title + " FSR up / Nominal", nbin, low, high, xtitle, ytitle));
tmps.at(3)->setEfficiencyFlag();
tmps.push_back(dqm->book1dHisto(name+"FSRdn_ratio","Ratio of "+title+" FSR down / Nominal",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(
name + "FSRdn_ratio", "Ratio of " + title + " FSR down / Nominal", nbin, low, high, xtitle, ytitle));
tmps.at(4)->setEfficiencyFlag();
tmps.push_back(dqm->book1dHisto(name+"ISRup",title+" ISR up",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name+"ISRdn",title+" ISR down",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name+"ISRup_ratio","Ratio of "+title+" ISR up / Nominal",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->book1dHisto(name + "ISRup", title + " ISR up", nbin, low, high, xtitle, ytitle));
tmps.push_back(dqm->book1dHisto(name + "ISRdn", title + " ISR down", nbin, low, high, xtitle, ytitle));
tmps.push_back(dqm->book1dHisto(
name + "ISRup_ratio", "Ratio of " + title + " ISR up / Nominal", nbin, low, high, xtitle, ytitle));
tmps.at(7)->setEfficiencyFlag();
tmps.push_back(dqm->book1dHisto(name+"ISRdn_ratio","Ratio of "+title+" ISR down / Nominal",nbin,low,high,xtitle,ytitle));
tmps.push_back(dqm->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!
} // to get ratio plots correctly - need to modify PostProcessor_cff.py as well!

void GenWeightValidation::dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) {}

Expand All @@ -78,62 +110,62 @@ void GenWeightValidation::analyze(const edm::Event& iEvent, const edm::EventSetu
nEvt->Fill(0.5, weight);
nlogWgt->Fill(std::log10(weights.at(idxGenEvtInfo).size()), weight);

if ( weights.at(idxGenEvtInfo).size() < 1 )
return; // no weights in GenEventInfo
if (weights.at(idxGenEvtInfo).empty())
return; // no weights in GenEventInfo

for (unsigned idx = 0; idx < weights.at(idxGenEvtInfo).size(); idx++)
wgtVal->Fill(weights.at(idxGenEvtInfo)[idx]/weights.at(idxGenEvtInfo)[1], weight);
wgtVal->Fill(weights.at(idxGenEvtInfo)[idx] / weights.at(idxGenEvtInfo)[1], weight);

if ((int)weights.at(idxGenEvtInfo).size() <= idxMax)
return; // no PS weights in GenEventInfo
return; // no PS weights in GenEventInfo

edm::Handle<reco::GenParticleCollection> ptcls;
iEvent.getByToken(genParticleToken,ptcls);
iEvent.getByToken(genParticleToken, ptcls);
edm::Handle<reco::GenJetCollection> genjets;
iEvent.getByToken(genJetToken,genjets);
iEvent.getByToken(genJetToken, genjets);

std::vector<reco::GenParticleRef> 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 )
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<reco::GenParticleRef>);

if ( leptons.size() > 0 ) {
if (!leptons.empty()) {
reco::GenParticleRef leadLep = leptons.at(0);
fillTemplates(leadLepPtTemp,leadLep->pt());
fillTemplates(leadLepEtaTemp,leadLep->eta());
fillTemplates(leadLepPtTemp, leadLep->pt());
fillTemplates(leadLepEtaTemp, leadLep->eta());
}

std::vector<reco::GenJetRef> genjetVec;

for (unsigned igj = 0; igj < genjets->size(); igj++) {
reco::GenJetRef genjet(genjets,igj);
reco::GenJetRef genjet(genjets, igj);

if ( genjet->pt() > jetPtCut && std::abs(genjet->eta()) < jetEtaCut )
if (genjet->pt() > jetPtCut && std::abs(genjet->eta()) < jetEtaCut)
genjetVec.push_back(genjet);
}

fillTemplates(jetMultTemp,(float)genjetVec.size());
fillTemplates(jetMultTemp, (float)genjetVec.size());

if (genjetVec.size() > 0) {
if (!genjetVec.empty()) {
std::sort(genjetVec.begin(), genjetVec.end(), HepMCValidationHelper::sortByPtRef<reco::GenJetRef>);

auto leadJet = genjetVec.at(0);
fillTemplates(leadJetPtTemp,leadJet->pt());
fillTemplates(leadJetEtaTemp,leadJet->eta());
fillTemplates(leadJetPtTemp, leadJet->pt());
fillTemplates(leadJetEtaTemp, leadJet->eta());
}
} //analyze
} //analyze

void GenWeightValidation::fillTemplates(std::vector<MonitorElement*>& 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]);
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]);
}
Loading

0 comments on commit eaab8d7

Please sign in to comment.