9 #include "Rivet/AnalysisHandler.hh" 10 #include "Rivet/Analysis.hh" 12 using namespace Rivet;
18 _outFileName(pset.getParameter<
std::
string>(
"OutputFile")),
21 _doFinalize(pset.getParameter<
bool>(
"DoFinalize")),
22 _produceDQM(pset.getParameter<
bool>(
"ProduceDQMOutput")),
26 std::vector<std::string> analysisNames = pset.
getParameter<std::vector<std::string> >(
"AnalysisNames");
32 if (!pset.
exists(
"GenEventInfoCollection")){
33 throw cms::Exception(
"RivetAnalyzer") <<
"when using an external event weight you have to specify the GenEventInfoProduct collection from which the weight has to be taken " ;
42 _LHEweightNumber = pset.
getParameter<
int>(
"LHEweightNumber");
50 const std::set< AnaHandle, CmpAnaHandle > & analyses =
_analysisHandler.analyses();
52 std::set< AnaHandle, CmpAnaHandle >::const_iterator ibeg = analyses.begin();
53 std::set< AnaHandle, CmpAnaHandle >::const_iterator iend = analyses.end();
54 std::set< AnaHandle, CmpAnaHandle >::const_iterator iana;
56 for (iana = ibeg; iana != iend; ++iana){
57 if ((*iana)->needsCrossSection())
74 char * cmsswbase = getenv(
"CMSSW_BASE");
75 char * cmsswrelease = getenv(
"CMSSW_RELEASE_BASE");
76 if ( !getenv(
"RIVET_REF_PATH") )
78 const std::string rivetref =
"RIVET_REF_PATH=" +
string(cmsswbase) +
"/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
"/src/GeneratorInterface/RivetInterface/data";
79 putenv(strdup(rivetref.c_str()));
81 if ( !getenv(
"RIVET_INFO_PATH") )
83 const std::string rivetinfo =
"RIVET_INFO_PATH=" +
string(cmsswbase) +
"/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
"/src/GeneratorInterface/RivetInterface/data";
84 putenv(strdup(rivetinfo.c_str()));
100 std::unique_ptr<HepMC::GenEvent> tmpGenEvtPtr;
103 tmpGenEvtPtr = std::make_unique<HepMC::GenEvent>(*(evt->
GetEvent()));
106 HepMC::GenCrossSection xsec;
108 tmpGenEvtPtr->set_cross_section(xsec);
112 if (tmpGenEvtPtr->weights().size() == 0) {
113 throw cms::Exception(
"RivetAnalyzer") <<
"Original weight container has 0 size ";
115 if (tmpGenEvtPtr->weights().size() > 1) {
116 edm::LogWarning(
"RivetAnalyzer") <<
"Original event weight size is " << tmpGenEvtPtr->weights().size() <<
". Will change only the first one ";
122 tmpGenEvtPtr->weights()[0] = genEventInfoProduct->
weight();
127 tmpGenEvtPtr->weights()[0] = wgt.
wgt;
130 myGenEvent = tmpGenEvtPtr.get();
176 using namespace YODA;
180 const string tmpdir =
"/RivetNormalizeTmp";
182 foreach (
const string& analysis, analyses) {
184 dbe->setCurrentFolder((
"Rivet/"+analysis).c_str());
187 TH1F
nevent(
"nEvt",
"n analyzed Events", 1, 0., 1.);
189 _mes.push_back(
dbe->book1D(
"nEvt",&nevent));
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const std::vector< WGT > & weights() const
Rivet::AnalysisHandler _analysisHandler
virtual void beginJob() override
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
const HepMC::GenEvent * GetEvent() const
virtual void endJob() override
List of registered analysis data objects.
edm::EDGetTokenT< LHEEventProduct > _LHECollection
edm::EDGetTokenT< GenEventInfoProduct > _genEventInfoCollection
std::vector< MonitorElement * > _mes