69 ATH_MSG_INFO(
"Using Rivet version " << Rivet::version());
80 std::string env_rap(
getenv_str(
"RIVET_ANALYSIS_PATH"));
81 if (!m_anapath.empty()) {
82 ATH_MSG_INFO(
"Setting Rivet plugin analyses loader env path: " << m_anapath);
83 if (!env_rap.empty())
ATH_MSG_INFO(
"Overwriting environment's RIVET_ANALYSIS_PATH = " << env_rap <<
"!");
84 setenv(
"RIVET_ANALYSIS_PATH", m_anapath.c_str(), 1);
89 if (!env_rap.empty())
ATH_MSG_DEBUG(
"Loading Rivet plugin analyses from env path: " << env_rap);
92 #if RIVET_VERSION_CODE >= 40100
93 m_analysisHandler =
new Rivet::AnalysisHandler();
95 m_analysisHandler =
new Rivet::AnalysisHandler(m_runname);
97 assert(m_analysisHandler);
99 #if RIVET_VERSION_CODE >= 40000
100 m_analysisHandler->setCheckBeams(!m_ignorebeams);
101 m_analysisHandler->matchWeightNames(m_matchWeights);
102 m_analysisHandler->unmatchWeightNames(m_unmatchWeights);
104 m_analysisHandler->setIgnoreBeams(m_ignorebeams);
105 m_analysisHandler->selectMultiWeights(m_matchWeights);
106 m_analysisHandler->deselectMultiWeights(m_unmatchWeights);
108 m_analysisHandler->skipMultiWeights(m_skipweights);
109 m_analysisHandler->setNominalWeightName(m_nominalWeightName);
110 if (m_weightcap>0) m_analysisHandler->setWeightCap(m_weightcap);
116 if (msgLvl(MSG::VERBOSE)) {
117 std::vector<std::string> analysisNames = Rivet::AnalysisLoader::analysisNames();
123 for (
const std::string&
a : m_analysisNames) {
125 m_analysisHandler->addAnalysis(
a);
126 Rivet::Log::setLevel(
"Rivet.Analysis."+
a,
rivetLevel(
msg().level()));
133 if (m_preload!=
"") {
134 m_analysisHandler->readData(m_preload);
137 return StatusCode::SUCCESS;
262std::unique_ptr<HepMC::GenEvent>
Rivet_i::checkEvent(
const HepMC::GenEvent& event,
const EventContext& ctx) {
263 auto modEvent = std::make_unique<HepMC::GenEvent>(event);
268 modEvent->set_event_number(
static_cast<int>(evtInfo->eventNumber()));
273 std::shared_ptr<HepMC3::GenRunInfo> modRunInfo;
274 if (event.run_info()) {
275 modRunInfo = std::make_shared<HepMC3::GenRunInfo>(*(event.run_info().get()));
276 if (event.run_info()->weight_names().empty() && event.weights().size() == 1) {
277 modRunInfo->set_weight_names({
"Default"});
281 ATH_MSG_DEBUG(
"No run info, event weights size is " << event.weights().size() );
282 modRunInfo = std::make_shared<HepMC3::GenRunInfo>();
283 std::vector<std::string> w_names;
284 for (
size_t i = 0; i <
event.weights().size(); i++) { w_names.push_back(std::string(
"badweight") + std::to_string(i)); }
285 modRunInfo->set_weight_names(w_names);
287 modEvent->set_run_info(std::move(modRunInfo));
288 std::vector<std::string> w_names = modEvent->weight_names();
289 if (w_names.size()) {
290 std::vector<std::pair<std::string,std::string> > w_subs = {
303 for (std::string& wname : w_names) {
304 for (
const auto& sub : w_subs) {
305 size_t start_pos = wname.find(sub.first);
306 while (start_pos != std::string::npos) {
307 wname.replace(start_pos, sub.first.length(), sub.second);
308 start_pos = wname.find(sub.first);
312 modEvent->run_info()->set_weight_names(w_names);
315 const HepMC::WeightContainer& old_wc =
event.weights();
316 std::vector<std::string> old_wnames = old_wc.weight_names();
317 if (old_wnames.size()) {
318 HepMC::WeightContainer& new_wc = modEvent->weights();
320 std::vector<std::pair<std::string,std::string> > w_subs = {
333 std::map<std::string, double> new_name_to_value;
334 std::map<std::string, std::string> old_name_to_new_name;
335 for (
const std::string& old_name : old_wnames) {
336 std::string wname = std::string(old_name);
337 double value = old_wc[old_name];
338 for (
const auto& sub : w_subs) {
339 size_t start_pos = wname.find(sub.first);
340 while (start_pos != std::string::npos) {
341 wname.replace(start_pos, sub.first.length(), sub.second);
342 start_pos = wname.find(sub.first);
345 new_name_to_value[wname] = value;
346 old_name_to_new_name[old_name] = wname;
348 auto itEnd = old_name_to_new_name.end();
349 for (
const std::string& old_name : old_wnames) {
350 if (old_name_to_new_name.find(old_name) == itEnd)
continue;
351 const std::string& new_name = old_name_to_new_name[old_name];
352 new_wc[ new_name ] = new_name_to_value[new_name];
359 modEvent->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);
360 if (modEvent->particles().size() == 1) modEvent->set_beam_particles(modEvent->particles().front(), modEvent->particles().front());
365 for (
const auto& p : modEvent->particles()) {
367 etotal += p->momentum().e();
369 const double ebeam = 0.5*etotal;
371 HepMC::GenParticlePtr b1 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,ebeam,ebeam),2212,4);
372 HepMC::GenParticlePtr b2 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,-1*ebeam,ebeam),2212,4);
374 std::vector<HepMC::GenParticlePtr> notBeams;
379 for (
const auto& bp : notBeams) bp->production_vertex()->remove_particle_out(bp);
381 modEvent->set_beam_particles(std::move(b1), std::move(b2));
383 if (modEvent->beams().front()->momentum().e() > 50000.0) {
387 modEvent->use_units(HepMC::Units::GEV, HepMC::Units::MM);
388 if (modEvent->particles_size() == 1) modEvent->set_beam_particles(*modEvent->particles_begin(), *modEvent->particles_begin());
389 if (modEvent->beam_particles().first->momentum().e() > 50000.0) {