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\\._=]"),
"_"));
125 runinfo = make_shared<HepMC3::GenRunInfo>();
134 const HepMC3::GenEventData* genEventData = evt->
GetEvent();
135 std::unique_ptr<HepMC3::GenEvent>
genEvent = std::make_unique<HepMC3::GenEvent>();
138 std::vector<double> mergedWeights;
139 for (
unsigned int i = 0;
i <
genEvent->weights().size();
i++) {
140 mergedWeights.push_back(
genEvent->weights()[
i]);
147 mergedWeights.push_back(
genEvent->weights()[0] * lheEventHandle->
weights().at(
i).wgt /
153 HepMC3::GenCrossSectionPtr xsec = make_shared<HepMC3::GenCrossSection>();
154 xsec->set_cross_section(std::vector<double>(mergedWeights.size(),
xsection),
155 std::vector<double>(mergedWeights.size(), 0.));
158 genEvent->weights() = mergedWeights;
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
edm::EDGetTokenT< edm::HepMC3Product > _hepmcCollection
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
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfoToken
std::shared_ptr< HepMC3::GenRunInfo > runinfo
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
const HepMC3::GenEventData * GetEvent() const
~RivetAnalyzer() override