CMS 3D CMS Logo

CepGenEventGenerator.cc
Go to the documentation of this file.
1 // CepGen-CMSSW interfacing module
2 // 2022-2024, Laurent Forthomme
3 
7 
10 
11 #include <CepGen/Core/Exception.h>
12 #include <CepGen/Core/RunParameters.h>
13 #include <CepGen/Event/Event.h>
14 #include <CepGen/EventFilter/EventExporter.h>
15 #include <CepGen/EventFilter/EventModifier.h>
16 #include <CepGen/Generator.h>
17 #include <CepGen/Modules/EventExporterFactory.h>
18 #include <CepGen/Modules/EventModifierFactory.h>
19 #include <CepGen/Modules/ProcessFactory.h>
20 #include <CepGen/Process/Process.h>
21 #include <CepGenAddOns/HepMC2Wrapper/HepMC2EventInterface.h>
22 
23 using namespace gen;
24 
26  : BaseHadronizer(iConfig),
27  proc_params_(cepgen::fromParameterSet(iConfig.getParameter<edm::ParameterSet>("process"))) {
28  // specify the overall module verbosity
29  cepgen::utils::Logger::get().setLevel(
30  static_cast<cepgen::utils::Logger::Level>(iConfig.getUntrackedParameter<int>("verbosity", 0)));
31 
32  // build the process
33  edm::LogInfo("CepGenEventGenerator") << "Process to be generated: " << proc_params_ << ".";
34 
35  const auto modif_mods = cepgen::fromParameterSet(
36  iConfig.getUntrackedParameter<edm::ParameterSet>("modifierModules", edm::ParameterSet{}));
37  edm::LogInfo("CepGenEventGenerator") << "Event modifier modules: " << modif_mods << ".";
38  for (const auto& mod : modif_mods.keys())
39  modif_modules_.emplace_back(std::make_pair(mod, modif_mods.get<cepgen::ParametersList>(mod)));
40 
41  const auto output_mods =
43  edm::LogInfo("CepGenEventGenerator") << "Output modules: " << output_mods << ".";
44  for (const auto& mod : output_mods.keys())
45  output_modules_.emplace_back(std::make_pair(mod, output_mods.get<cepgen::ParametersList>(mod)));
46 }
47 
48 CepGenEventGenerator::~CepGenEventGenerator() { edm::LogInfo("CepGenEventGenerator") << "Destructor called."; }
49 
51  gen_ = new cepgen::Generator(true /* "safe" mode: start without plugins */);
52 
53  auto pproc = proc_params_;
54  { // little treatment to allow for standard CepGen configurations to be copy-pasted in place
55  pproc += proc_params_.get<cepgen::ParametersList>("processParameters");
56  pproc.erase("processParameters");
57  auto& pkin = pproc.operator[]<cepgen::ParametersList>("kinematics");
58  pkin += pproc.get<cepgen::ParametersList>("inKinematics");
59  pproc.erase("inKinematics");
60  pkin += pproc.get<cepgen::ParametersList>("outKinematics");
61  pproc.erase("outKinematics");
62  if (pproc.has<unsigned long long>("mode"))
63  pkin.set<int>("mode", pproc.get<unsigned long long>("mode"));
64  }
65 
66  gen_->runParameters().setProcess(cepgen::ProcessFactory::get().build(pproc));
67  if (!gen_->runParameters().hasProcess())
68  throw cms::Exception("CepGenEventGenerator") << "Failed to retrieve a process from the configuration";
69  for (const auto& mod : modif_modules_) {
70  auto modifier = cepgen::EventModifierFactory::get().build(mod.first, mod.second);
71  for (const auto& cfg : mod.second.get<std::vector<std::string> >("preConfiguration"))
72  modifier->readString(cfg);
73  for (const auto& cfg : mod.second.get<std::vector<std::string> >("processConfiguration"))
74  modifier->readString(cfg);
75  gen_->runParameters().addModifier(std::move(modifier));
76  }
77  for (const auto& mod : output_modules_)
78  gen_->runParameters().addEventExporter(cepgen::EventExporterFactory::get().build(mod.first, mod.second));
79 
80  edm::LogInfo("CepGenEventGenerator") << "Run parameters:\n" << gen_->runParameters();
81  const auto xsec = gen_->computeXsection();
82  xsec_.set_cross_section(xsec, xsec.uncertainty());
83  runInfo().setInternalXSec(GenRunInfoProduct::XSec(xsec, xsec.uncertainty()));
84  return true;
85 }
86 
88  event().reset(new HepMC::CepGenEvent(gen_->next()));
89  event()->set_cross_section(xsec_);
90  event()->weights().push_back(1.);
91  return true;
92 }
void setInternalXSec(const XSec &xsec)
T getUntrackedParameter(std::string const &, T const &) const
GenRunInfoProduct & runInfo()
HepMC::GenCrossSection xsec_
std::vector< std::pair< std::string, cepgen::ParametersList > > modif_modules_
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< std::pair< std::string, cepgen::ParametersList > > output_modules_
Log< level::Info, false > LogInfo
const cepgen::ParametersList proc_params_
HLT enums.
#define get
ParametersList fromParameterSet(const edm::ParameterSet &iConfig)
CepGenEventGenerator(const edm::ParameterSet &, edm::ConsumesCollector &&)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
def move(src, dest)
Definition: eostools.py:511