10 #include "Rivet/Run.hh" 11 #include "Rivet/AnalysisHandler.hh" 12 #include "Rivet/Analysis.hh" 16 using namespace Rivet;
20 : _isFirstEvent(
true),
25 _doFinalize(
pset.getParameter<
bool>(
"DoFinalize")),
28 usesResource(
"Rivet");
55 char*
cmsswbase = std::getenv(
"CMSSW_BASE");
56 char* cmsswrelease = std::getenv(
"CMSSW_RELEASE_BASE");
57 if (!std::getenv(
"RIVET_REF_PATH")) {
59 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
60 "/src/GeneratorInterface/RivetInterface/data:.";
61 char* rivetrefCstr = strdup(rivetref.c_str());
62 setenv(
"RIVET_REF_PATH", rivetrefCstr, 1);
65 if (!std::getenv(
"RIVET_INFO_PATH")) {
67 "/src/GeneratorInterface/RivetInterface/data:" +
string(cmsswrelease) +
68 "/src/GeneratorInterface/RivetInterface/data:.";
69 char* rivetinfoCstr = strdup(rivetinfo.c_str());
70 setenv(
"RIVET_INFO_PATH", rivetinfoCstr, 1);
79 typedef std::vector<LHERunInfoProduct::Header>::const_iterator headers_const_iterator;
81 std::regex reg(
"<weight.*> ?(.*?) ?<\\/weight>");
84 std::vector<std::string>
lines = iter->lines();
85 for (
unsigned int iLine = 0; iLine <
lines.size(); iLine++) {
87 std::regex_search(
lines.at(iLine),
match, reg);
100 if (genLumiInfoHandle.isValid()) {
115 for (
unsigned int i = 0;
i < lheEventHandle->
weights().size();
i++) {
123 _cleanedWeightNames.push_back(std::regex_replace(wn, std::regex(
"[^A-Za-z\\d\\._=]"),
"_"));
133 std::unique_ptr<HepMC::GenEvent> tmpGenEvtPtr;
135 tmpGenEvtPtr = std::make_unique<HepMC::GenEvent>(*(evt->
GetEvent()));
138 HepMC::GenCrossSection xsec;
140 tmpGenEvtPtr->set_cross_section(xsec);
143 std::vector<double> mergedWeights;
144 for (
unsigned int i = 0;
i < tmpGenEvtPtr->weights().size();
i++) {
145 mergedWeights.push_back(tmpGenEvtPtr->weights()[
i]);
152 mergedWeights.push_back(tmpGenEvtPtr->weights()[0] * lheEventHandle->
weights().at(
i).wgt /
157 tmpGenEvtPtr->weights().clear();
161 myGenEvent = tmpGenEvtPtr.get();
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
std::string _deselectMultiWeights
std::unique_ptr< Rivet::AnalysisHandler > _analysisHandler
double originalXWGTUP() const
headers_const_iterator headers_begin() const
std::vector< std::string > _cleanedWeightNames
std::string _setNominalWeightName
std::vector< std::string > _analysisNames
static std::string to_string(const XMLCh *ch)
void free(void *ptr) noexcept
const edm::InputTag _lheLabel
headers_const_iterator headers_end() const
std::string _selectMultiWeights
bool getByLabel(std::string const &label, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< GenLumiInfoHeader > _genLumiInfoToken
const HepMC::GenEvent * GetEvent() const
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfoToken
std::vector< std::string > _lheWeightNames
edm::EDGetTokenT< LHEEventProduct > _LHECollection
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
std::vector< std::string > _weightNames
const std::vector< WGT > & weights() const
~RivetAnalyzer() override