diff --git a/Generators/Rivet_i/CMakeLists.txt b/Generators/Rivet_i/CMakeLists.txt index a7d029d17e5073e13b6c3da54c3574ce530812e3..c018ff34c60f1fe4c889e9b8048e03cc51428d23 100644 --- a/Generators/Rivet_i/CMakeLists.txt +++ b/Generators/Rivet_i/CMakeLists.txt @@ -21,6 +21,7 @@ find_package( HepMC ) find_package( ROOT COMPONENTS Matrix Core Tree MathCore Hist RIO pthread ) find_package( Rivet ) find_package( YODA ) +find_package( GSL ) # Remove the --as-needed linker flags: atlas_disable_as_needed() @@ -30,12 +31,12 @@ atlas_add_library( Rivet_iLib src/*.cxx PUBLIC_HEADERS Rivet_i INCLUDE_DIRS ${RIVET_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${YODA_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} + PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${YODA_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} LINK_LIBRARIES ${RIVET_LIBRARIES} AthenaBaseComps GaudiKernel - PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} ${YODA_LIBRARIES} ${FASTJET_LIBRARIES} AthenaKernel GeneratorObjects PathResolver ) + PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${GSL_LIBRARIES} ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} ${YODA_LIBRARIES} ${FASTJET_LIBRARIES} AthenaKernel GeneratorObjects PathResolver ) atlas_add_component( Rivet_i src/components/*.cxx - INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${YODA_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} ${RIVET_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} ${YODA_LIBRARIES} ${FASTJET_LIBRARIES} ${RIVET_LIBRARIES} AthenaBaseComps GaudiKernel AthenaKernel GeneratorObjects PathResolver Rivet_iLib ) + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${YODA_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} ${RIVET_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} + LINK_LIBRARIES ${Boost_LIBRARIES} ${GSL_LIBRARIES} ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} ${YODA_LIBRARIES} ${FASTJET_LIBRARIES} ${RIVET_LIBRARIES} AthenaBaseComps GaudiKernel AthenaKernel GeneratorObjects PathResolver Rivet_iLib ) diff --git a/Generators/Rivet_i/Rivet_i/Rivet_i.h b/Generators/Rivet_i/Rivet_i/Rivet_i.h index 8e44605838e909ca848f9af3defaa30b9f51cac3..c3ce4f744f96d33cb03d92b0e2d9402378c46509 100644 --- a/Generators/Rivet_i/Rivet_i/Rivet_i.h +++ b/Generators/Rivet_i/Rivet_i/Rivet_i.h @@ -105,6 +105,9 @@ private: /// The cross section for this run of events, set from the job properties. double m_crossSection; + /// The name of the weight to use in case the input HepMC contains multiple weights + std::string m_weightName; + /// Flag to determine whether Rivet init has already happened (in execute()) bool m_init; diff --git a/Generators/Rivet_i/cmt/requirements b/Generators/Rivet_i/cmt/requirements index 62492c9fe350abd5d02d09fa197bf1ff9af6df38..1fe3ec4c96b1ea9880fd8382bfb5a7f7afa4d38a 100644 --- a/Generators/Rivet_i/cmt/requirements +++ b/Generators/Rivet_i/cmt/requirements @@ -33,3 +33,4 @@ end_private ## Athena stuff apply_pattern named_dual_use_library library="Rivet_i" files="*.cxx" apply_pattern declare_joboptions files="*.py" + diff --git a/Generators/Rivet_i/src/Rivet_i.cxx b/Generators/Rivet_i/src/Rivet_i.cxx index af8c93f1c718809f45b7453d1518401a143e1a5a..494de74c4d6e5fb23b9982bc9b8a810522307116 100644 --- a/Generators/Rivet_i/src/Rivet_i.cxx +++ b/Generators/Rivet_i/src/Rivet_i.cxx @@ -48,6 +48,7 @@ Rivet_i::Rivet_i(const std::string& name, ISvcLocator* pSvcLocator) : declareProperty("McEventKey", m_genEventKey="GEN_EVENT"); declareProperty("Analyses", m_analysisNames); declareProperty("CrossSection", m_crossSection=-1.0); + declareProperty("WeightName", m_weightName=""); declareProperty("Stream", m_stream="/Rivet"); declareProperty("RunName", m_runname=""); declareProperty("HistoFile", m_file="Rivet.yoda"); @@ -187,6 +188,11 @@ StatusCode Rivet_i::execute() { // ATH_MSG_ALWAYS("CHK1 BEAM ENERGY = " << checkedEvent->beam_particles().first->momentum().e()); // ATH_MSG_ALWAYS("CHK1 UNITS == MEV = " << std::boolalpha << (checkedEvent->momentum_unit() == HepMC::Units::MEV)); + if(!checkedEvent) { + ATH_MSG_ERROR("Check on HepMC event failed!"); + return StatusCode::FAILURE; + } + // Initialize Rivet (on the first event only) if (!m_init) { m_analysisHandler->init(*checkedEvent); @@ -196,8 +202,7 @@ StatusCode Rivet_i::execute() { // Analyse the event m_analysisHandler->analyze(*checkedEvent); - // Delete the modified event copy - if (checkedEvent != event) delete checkedEvent; + delete checkedEvent; return StatusCode::SUCCESS; } @@ -220,18 +225,35 @@ StatusCode Rivet_i::finalize() { const string basename = ao->path().substr(ao->path().rfind("/")+1); // There should always be >= 1 slash // Convert YODA histos to heap-allocated ROOT objects and register + /// @todo Counter if (ao->type() == "Histo1D") { TH1* h = (TH1*) YODA::toTH1D(*boost::dynamic_pointer_cast<YODA::Histo1D>(ao)).Clone(basename.c_str()); CHECK(m_histSvc->regHist(m_stream + path, h)); ATH_MSG_INFO("TH1D " + path + " created from YODA::Histo1D"); + } else if (ao->type() == "Histo2D") { + TH2* h = (TH2*) YODA::toTH2D(*boost::dynamic_pointer_cast<YODA::Histo2D>(ao)).Clone(basename.c_str()); + CHECK(m_histSvc->regHist(m_stream + path, h)); + ATH_MSG_INFO("TH2 " + path + " created from YODA::Histo2D"); + // } else if (ao->type() == "Profile2D") { + // TProfile2D* h = (TProfile2D*) YODA::toTProfile2D(*boost::dynamic_pointer_cast<YODA::Profile2D>(ao)).Clone(basename.c_str()); + // CHECK(m_histSvc->regHist(m_stream + path, h)); + // ATH_MSG_INFO("TProfile2D " + path + " created from YODA::Profile2D"); } else if (ao->type() == "Profile1D") { TH1* h = (TH1*) YODA::toTProfile(*boost::dynamic_pointer_cast<YODA::Profile1D>(ao)).Clone(basename.c_str()); CHECK(m_histSvc->regHist(m_stream + path, h)); ATH_MSG_INFO("TProfile " + path + " created from YODA::Profile1D"); + // } else if (ao->type() == "Scatter1D") { + // TGraph* g = (TGraph*) YODA::toTGraph(*boost::dynamic_pointer_cast<YODA::Scatter1D>(ao)).Clone(basename.c_str()); + // CHECK(m_histSvc->regGraph(m_stream + path, g)); + // ATH_MSG_INFO("TGraph " + path + " created from YODA::Scatter2D"); } else if (ao->type() == "Scatter2D") { TGraph* g = (TGraph*) YODA::toTGraph(*boost::dynamic_pointer_cast<YODA::Scatter2D>(ao)).Clone(basename.c_str()); CHECK(m_histSvc->regGraph(m_stream + path, g)); ATH_MSG_INFO("TGraph " + path + " created from YODA::Scatter2D"); + // } else if (ao->type() == "Scatter3D") { + // TGraph* g = (TGraph*) YODA::toTGraph(*boost::dynamic_pointer_cast<YODA::Scatter3D>(ao)).Clone(basename.c_str()); + // CHECK(m_histSvc->regGraph(m_stream + path, g)); + // ATH_MSG_INFO("TGraph " + path + " created from YODA::Scatter2D"); } else { ATH_MSG_WARNING("Couldn't convert YODA histo " + path + " to ROOT: unsupported data type " + ao->type()); } @@ -255,6 +277,20 @@ bool cmpGenParticleByEDesc(const HepMC::GenParticle* a, const HepMC::GenParticle const HepMC::GenEvent* Rivet_i::checkEvent(const HepMC::GenEvent* event) { std::vector<HepMC::GenParticle*> beams; + HepMC::GenEvent* modEvent = new HepMC::GenEvent(*event); + + if(m_weightName != ""){ + if(event->weights().has_key(m_weightName)){ + double weight = event->weights()[m_weightName]; + modEvent->weights().clear(); + modEvent->weights()[m_weightName] = weight; + }else{ + ATH_MSG_ERROR("Weight named " + m_weightName + " could not be found in the HepMC event!"); + delete modEvent; + return (HepMC::GenEvent*)0; + } + } + if (!event->valid_beam_particles()) { for (HepMC::GenEvent::particle_const_iterator p = event->particles_begin(); p != event->particles_end(); ++p) { if (!(*p)->production_vertex() && (*p)->pdg_id() != 0) { @@ -283,9 +319,8 @@ const HepMC::GenEvent* Rivet_i::checkEvent(const HepMC::GenEvent* event) { #endif if (scalefactor == 1.0 && event->valid_beam_particles()) { - return event; + return modEvent; } else { - HepMC::GenEvent* modEvent = new HepMC::GenEvent(*event); if (scalefactor != 1.0) { // ATH_MSG_ALWAYS("RESCALING * " << scalefactor); for (HepMC::GenEvent::particle_iterator p = modEvent->particles_begin(); p != modEvent->particles_end(); ++p) {