10 #include "Rivet/Run.hh" 11 #include "Rivet/AnalysisHandler.hh" 12 #include "Rivet/Analysis.hh" 16 using namespace Rivet;
22 _outFileName(pset.getParameter<
std::
string>(
"OutputFile")),
25 _doFinalize(pset.getParameter<
bool>(
"DoFinalize")),
26 _produceDQM(pset.getParameter<
bool>(
"ProduceDQMOutput")),
27 _lheLabel(pset.getParameter<
edm::
InputTag>(
"LHECollection")),
29 usesResource(
"Rivet");
32 std::vector<std::string> analysisNames = pset.
getParameter<std::vector<std::string> >(
"AnalysisNames");
60 char*
cmsswbase = std::getenv(
"CMSSW_BASE");
61 char* cmsswrelease = std::getenv(
"CMSSW_RELEASE_BASE");
62 if (!std::getenv(
"RIVET_REF_PATH")) {
64 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
65 "/src/GeneratorInterface/RivetInterface/data";
66 char* rivetrefCstr = strdup(rivetref.c_str());
70 if (!std::getenv(
"RIVET_INFO_PATH")) {
72 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
73 "/src/GeneratorInterface/RivetInterface/data";
74 char* rivetinfoCstr = strdup(rivetinfo.c_str());
75 putenv(rivetinfoCstr);
84 typedef std::vector<LHERunInfoProduct::Header>::const_iterator headers_const_iterator;
86 std::regex reg(
"<weight.*> ?(.*?) ?<\\/weight>");
89 std::vector<std::string>
lines = iter->lines();
90 for (
unsigned int iLine = 0; iLine < lines.size(); iLine++) {
92 std::regex_search(lines.at(iLine),
match, reg);
122 std::unique_ptr<HepMC::GenEvent> tmpGenEvtPtr;
125 tmpGenEvtPtr = std::make_unique<HepMC::GenEvent>(*(evt->
GetEvent()));
128 HepMC::GenCrossSection xsec;
130 tmpGenEvtPtr->set_cross_section(xsec);
134 std::vector<double> mergedWeights;
135 for (
unsigned int i = 0;
i < tmpGenEvtPtr->weights().size();
i++) {
136 mergedWeights.push_back(tmpGenEvtPtr->weights()[
i]);
142 mergedWeights.push_back(tmpGenEvtPtr->weights()[0] * lheEventHandle->
weights().at(
i).wgt /
146 tmpGenEvtPtr->weights() = mergedWeights;
148 myGenEvent = tmpGenEvtPtr.get();
157 std::vector<std::string> cleanedWeightNames;
159 cleanedWeightNames.push_back(std::regex_replace(wn, std::regex(
"[^A-Za-z\\d\\._=]"),
"_"));
162 const HepMC::GenCrossSection* xs = myGenEvent->cross_section();
163 _analysisHandler.setCrossSection(make_pair(xs->cross_section(), xs->cross_section_error()));
194 using namespace YODA;
198 const string tmpdir =
"/RivetNormalizeTmp";
200 for (
const string& analysis : analyses) {
205 TH1F
nevent(
"nEvt",
"n analyzed Events", 1, 0., 1.);
void analyze(const edm::Event &, const edm::EventSetup &) override
double originalXWGTUP() const
T getParameter(std::string const &) const
bool getByLabel(std::string const &label, Handle< PROD > &result) const
void endRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
headers_const_iterator headers_end() const
const std::vector< WGT > & weights() const
Rivet::AnalysisHandler _analysisHandler
const edm::InputTag _lheLabel
#define DEFINE_FWK_MODULE(type)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
headers_const_iterator headers_begin() const
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< GenLumiInfoHeader > _genLumiInfoToken
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfoToken
const HepMC::GenEvent * GetEvent() const
void setCurrentFolder(std::string const &fullpath)
std::vector< std::string > _lheWeightNames
void endJob() override
List of registered analysis data objects.
edm::EDGetTokenT< LHEEventProduct > _LHECollection
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
std::vector< std::string > _weightNames
std::vector< MonitorElement * > _mes
~RivetAnalyzer() override