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")),
24 usesResource(
"Rivet");
27 std::vector<std::string> analysisNames = pset.
getParameter<std::vector<std::string> >(
"AnalysisNames");
33 if (!pset.
exists(
"GenEventInfoCollection")) {
34 throw cms::Exception(
"RivetAnalyzer") <<
"when using an external event weight you have to specify the " 35 "GenEventInfoProduct collection from which the weight has to be taken ";
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())
72 char* cmsswbase = getenv(
"CMSSW_BASE");
73 char* cmsswrelease = getenv(
"CMSSW_RELEASE_BASE");
74 if (!getenv(
"RIVET_REF_PATH")) {
76 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
77 "/src/GeneratorInterface/RivetInterface/data";
78 char* rivetrefCstr = strdup(rivetref.c_str());
82 if (!getenv(
"RIVET_INFO_PATH")) {
84 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
85 "/src/GeneratorInterface/RivetInterface/data";
86 char* rivetinfoCstr = strdup(rivetinfo.c_str());
87 putenv(rivetinfoCstr);
101 std::unique_ptr<HepMC::GenEvent> tmpGenEvtPtr;
104 tmpGenEvtPtr = std::make_unique<HepMC::GenEvent>(*(evt->
GetEvent()));
107 HepMC::GenCrossSection xsec;
109 tmpGenEvtPtr->set_cross_section(xsec);
113 if (tmpGenEvtPtr->weights().empty()) {
114 throw cms::Exception(
"RivetAnalyzer") <<
"Original weight container has 0 size ";
116 if (tmpGenEvtPtr->weights().size() > 1) {
117 edm::LogWarning(
"RivetAnalyzer") <<
"Original event weight size is " << tmpGenEvtPtr->weights().size()
118 <<
". Will change only the first one ";
123 double weightForRivet = genEventInfoProduct->
weight();
134 tmpGenEvtPtr->weights()[0] = weightForRivet;
136 myGenEvent = tmpGenEvtPtr.get();
171 using namespace YODA;
175 const string tmpdir =
"/RivetNormalizeTmp";
177 foreach (
const string& analysis, analyses) {
179 dbe->setCurrentFolder(
"Rivet/" + analysis);
182 TH1F
nevent(
"nEvt",
"n analyzed Events", 1, 0., 1.);
184 _mes.push_back(
dbe->book1D(
"nEvt", &nevent));
void analyze(const edm::Event &, const edm::EventSetup &) override
double originalXWGTUP() const
T getParameter(std::string const &) const
void endRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const std::vector< WGT > & weights() const
Rivet::AnalysisHandler _analysisHandler
#define DEFINE_FWK_MODULE(type)
void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
const HepMC::GenEvent * GetEvent() const
void endJob() override
List of registered analysis data objects.
edm::EDGetTokenT< LHEEventProduct > _LHECollection
std::vector< double > & weights()
edm::EDGetTokenT< GenEventInfoProduct > _genEventInfoCollection
std::vector< MonitorElement * > _mes
~RivetAnalyzer() override