CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
gen::BaseHadronizer Class Reference

#include <BaseHadronizer.h>

Inheritance diagram for gen::BaseHadronizer:
gen::AMPTHadronizer gen::Cascade2Hadronizer gen::ExhumeHadronizer gen::HijingHadronizer gen::Hydjet2Hadronizer gen::HydjetHadronizer gen::PomwigHadronizer gen::Py8InterfaceBase gen::PyquenHadronizer gen::Pythia6Hadronizer gen::ReggeGribovPartonMCHadronizer gen::ReggeGribovPartonMCHadronizer Herwig6Hadronizer Herwig7Hadronizer SherpaHadronizer

Public Member Functions

 BaseHadronizer (edm::ParameterSet const &ps)
 
void cleanLHE ()
 
void generateLHE (edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine, unsigned int ncpu)
 
edm::EventgetEDMEvent () const
 
std::unique_ptr< HepMC::GenEventgetGenEvent ()
 
std::unique_ptr< GenEventInfoProductgetGenEventInfo ()
 
virtual std::unique_ptr< GenLumiInfoHeadergetGenLumiInfoHeader () const
 
GenRunInfoProductgetGenRunInfo ()
 
std::unique_ptr< lhef::LHEEventgetLHEEvent ()
 
const std::shared_ptr< lhef::LHERunInfo > & getLHERunInfo () const
 
const std::string & gridpackPath () const
 
int randomIndex () const
 
const std::string & randomInitConfigDescription () const
 
void randomizeIndex (edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine)
 
void resetEvent (std::unique_ptr< HepMC::GenEvent > event)
 
void resetEventInfo (std::unique_ptr< GenEventInfoProduct > eventInfo)
 
virtual bool select (HepMC::GenEvent *) const
 
void setEDMEvent (edm::Event &event)
 
void setLHEEvent (std::unique_ptr< lhef::LHEEvent > event)
 
void setLHERunInfo (std::unique_ptr< lhef::LHERunInfo > runInfo)
 
void setRandomEngine (CLHEP::HepRandomEngine *v)
 
std::vector< std::string > const & sharedResources () const
 
virtual ~BaseHadronizer ()(false)
 

Protected Member Functions

std::unique_ptr< HepMC::GenEvent > & event ()
 
std::unique_ptr< GenEventInfoProduct > & eventInfo ()
 
lhef::LHEEventlheEvent ()
 
lhef::LHERunInfolheRunInfo ()
 
GenRunInfoProductrunInfo ()
 

Protected Attributes

std::string lheFile_
 
int randomIndex_
 

Private Member Functions

virtual void doSetRandomEngine (CLHEP::HepRandomEngine *v)
 
virtual std::vector< std::string > const & doSharedResources () const
 

Private Attributes

edm::EventedmEvent_
 
std::unique_ptr< HepMC::GenEventgenEvent_
 
std::unique_ptr< GenEventInfoProductgenEventInfo_
 
GenRunInfoProduct genRunInfo_
 
std::vector< std::string > gridpackPaths_
 
std::unique_ptr< lhef::LHEEventlheEvent_
 
std::shared_ptr< lhef::LHERunInfolheRunInfo_
 
std::vector< std::string > randomInitConfigDescriptions_
 
std::vector< double > randomInitWeights_
 

Static Private Attributes

static const std::vector< std::string > theSharedResources
 

Detailed Description

Definition at line 47 of file BaseHadronizer.h.

Constructor & Destructor Documentation

gen::BaseHadronizer::BaseHadronizer ( edm::ParameterSet const &  ps)

Definition at line 12 of file BaseHadronizer.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), gridpackPaths_, randomInitConfigDescriptions_, randomInitWeights_, runInfo(), GenRunInfoProduct::setExternalXSecLO(), GenRunInfoProduct::setExternalXSecNLO(), GenRunInfoProduct::setFilterEfficiency(), and AlCaHLTBitMon_QueryRunRegistry::string.

12  :
13  randomIndex_(-1),
15  {
16 
17  if (ps.exists("RandomizedParameters")) {
18  std::vector<edm::ParameterSet> randomizedParameters = ps.getParameter<std::vector<edm::ParameterSet> >("RandomizedParameters");
19  randomInitWeights_.resize(randomizedParameters.size());
20  randomInitConfigDescriptions_.resize(randomizedParameters.size());
21  gridpackPaths_.resize(randomizedParameters.size());
22  for (unsigned int irand = 0; irand<randomizedParameters.size(); ++irand) {
23  randomInitWeights_[irand] = randomizedParameters[irand].getParameter<double>("ConfigWeight");
24  if (randomizedParameters[irand].exists("ConfigDescription")) {
25  randomInitConfigDescriptions_[irand] = randomizedParameters[irand].getParameter<std::string>("ConfigDescription");
26  }
27  if (randomizedParameters[irand].exists("GridpackPath")) {
28  gridpackPaths_[irand] = randomizedParameters[irand].getParameter<std::string>("GridpackPath");
29  }
30  }
31  }
32  else {
33  if (ps.exists("GridpackPath")) {
34  gridpackPaths_[0] = ps.getParameter<std::string>("GridpackPath");
35  }
36  }
37 
39  ps.getUntrackedParameter<double>("filterEfficiency", -1.) );
41  GenRunInfoProduct::XSec(ps.getUntrackedParameter<double>("crossSection", -1.)) );
43  GenRunInfoProduct::XSec(ps.getUntrackedParameter<double>("crossSectionNLO", -1.)) );
44 
45  }
std::vector< double > randomInitWeights_
void setFilterEfficiency(double effic)
GenRunInfoProduct & runInfo()
std::vector< std::string > gridpackPaths_
std::vector< std::string > randomInitConfigDescriptions_
void setExternalXSecNLO(const XSec &xsec)
void setExternalXSecLO(const XSec &xsec)
virtual gen::BaseHadronizer::~BaseHadronizer ( )
inlinevirtual

Definition at line 50 of file BaseHadronizer.h.

50 {}

Member Function Documentation

void gen::BaseHadronizer::cleanLHE ( )

Definition at line 146 of file BaseHadronizer.cc.

References lheFile_, and MatrixUtil::remove().

146  {
147  if (lheFile_.empty()) {
148  return;
149  }
150 
151  std::remove(lheFile_.c_str());
152  }
std::string lheFile_
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:212
virtual void gen::BaseHadronizer::doSetRandomEngine ( CLHEP::HepRandomEngine *  v)
inlineprivatevirtual
virtual std::vector<std::string> const& gen::BaseHadronizer::doSharedResources ( ) const
inlineprivatevirtual
std::unique_ptr<HepMC::GenEvent>& gen::BaseHadronizer::event ( )
inlineprotected

Definition at line 87 of file BaseHadronizer.h.

Referenced by gen::PomwigHadronizer::decay(), gen::PomwigHadronizer::finalizeEvent(), gen::Cascade2Hadronizer::finalizeEvent(), gen::Py8GunBase::finalizeEvent(), Herwig7Hadronizer::finalizeEvent(), SherpaHadronizer::finalizeEvent(), gen::ExhumeHadronizer::finalizeEvent(), gen::Pythia6Hadronizer::finalizeEvent(), Pythia8Hadronizer::finalizeEvent(), Herwig6Hadronizer::finalizeEvent(), gen::Py8PtAndDxyGun::generatePartonsAndHadronize(), gen::Py8PtGun::generatePartonsAndHadronize(), gen::Py8EGun::generatePartonsAndHadronize(), gen::Py8JetGun::generatePartonsAndHadronize(), gen::HijingHadronizer::generatePartonsAndHadronize(), gen::PomwigHadronizer::generatePartonsAndHadronize(), gen::PyquenHadronizer::generatePartonsAndHadronize(), gen::AMPTHadronizer::generatePartonsAndHadronize(), gen::HydjetHadronizer::generatePartonsAndHadronize(), gen::Cascade2Hadronizer::generatePartonsAndHadronize(), Herwig7Hadronizer::generatePartonsAndHadronize(), gen::ExhumeHadronizer::generatePartonsAndHadronize(), gen::Pythia6Hadronizer::generatePartonsAndHadronize(), gen::Hydjet2Hadronizer::generatePartonsAndHadronize(), Pythia8Hadronizer::generatePartonsAndHadronize(), gen::ReggeGribovPartonMCHadronizer::generatePartonsAndHadronize(), Herwig7Hadronizer::hadronize(), gen::Pythia6Hadronizer::hadronize(), Pythia8Hadronizer::hadronize(), Herwig6Hadronizer::hadronize(), gen::Cascade2Hadronizer::imposeProperTime(), gen::Pythia6Hadronizer::imposeProperTime(), Herwig6Hadronizer::pythiaStatusCodes(), gen::Cascade2Hadronizer::residualDecay(), gen::Py8GunBase::residualDecay(), gen::Pythia6Hadronizer::residualDecay(), and Pythia8Hadronizer::residualDecay().

87 { return genEvent_; }
std::unique_ptr< HepMC::GenEvent > genEvent_
std::unique_ptr<GenEventInfoProduct>& gen::BaseHadronizer::eventInfo ( )
inlineprotected
void gen::BaseHadronizer::generateLHE ( edm::LuminosityBlock const &  lumi,
CLHEP::HepRandomEngine *  rengine,
unsigned int  ncpu 
)

Definition at line 78 of file BaseHadronizer.cc.

References writedatasetfile::args, begin, constexpr, relativeConstraints::empty, Exception, edm::FileInPath::fullPath(), edm::pset::Registry::getMapped(), gridpackPath(), edm::LuminosityBlockBase::id(), edm::pset::Registry::instance(), lheFile_, edm::LuminosityBlockID::luminosityBlock(), sysUtil::pid, edm::LuminosityBlock::processHistory(), edm::ProcessHistory::rbegin(), edm::LuminosityBlockID::run(), and mps_update::status.

78  {
79 
80  if (gridpackPath().empty()) {
81  return;
82  }
83 
84  //get random seed from HepRandomEngine state plus run and lumi section numbers
85  //(random engine state will be the same for every lumi section in a job)
86  std::vector<long unsigned int> seeds = rengine->put();
87  seeds.push_back(lumi.id().run());
88  seeds.push_back(lumi.id().luminosityBlock());
89  std::seed_seq seedseq(seeds.begin(),seeds.end());
90  std::array<unsigned int,1> lheseed;
91  seedseq.generate(lheseed.begin(),lheseed.end());
92 
93  constexpr unsigned int maxseed = 30081*30081; //madgraph cannot handle seeds larger than this
94  unsigned int seedval = lheseed[0]%(maxseed+1);
95 
96  unsigned int nevents = edm::pset::Registry::instance()->getMapped(lumi.processHistory().rbegin()->parameterSetID())->getParameter<edm::ParameterSet>("@main_input").getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock");
97 
98  std::ostringstream nevStream;
99  nevStream << nevents;
100 
101  std::ostringstream randomStream;
102  randomStream << seedval;
103 
104  edm::FileInPath script("GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh");
105  const char *outfilename = "cmsgrid_final.lhe";
106 
107 
108 
109  std::array<std::string,5> argStrs;
110  argStrs[0]=script.fullPath();
111  argStrs[1]=gridpackPath();
112  argStrs[2]=nevStream.str();
113  argStrs[3]=randomStream.str();
114  argStrs[4]=std::to_string(ncpu);
115  std::array<char*,6>args{ { &argStrs[0][0], &argStrs[1][0],&argStrs[2][0],&argStrs[3][0], &argStrs[4][0], nullptr } };
116 
117  pid_t pid = fork();
118 
119  if (pid == -1) {
120  // error, failed to fork()
121  throw cms::Exception("BaseHadronizer::generateLHE") << "Unable to fork a child";
122  }
123  else if (pid==0) {
124  //child
125  execvp(args[0],std::begin(args));
126  _exit(1); // exec never returns
127  }
128  else {
129  //parent
130  int status;
131  waitpid(pid, &status, 0);
132  if (status) {
133  throw cms::Exception("BaseHadronizer::generateLHE") << "Failed to execute script";
134  }
135  }
136  FILE* lhef = std::fopen(outfilename, "r");
137  if (!lhef) {
138  throw cms::Exception("BaseHadronizer::generateLHE") << "Output file " << outfilename << " not found.";
139  }
140  std::fclose(lhef);
141 
142  lheFile_ = outfilename;
143 
144  }
std::string lheFile_
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
#define begin
Definition: vmac.h:32
const std::string & gridpackPath() const
#define constexpr
static Registry * instance()
Definition: Registry.cc:12
edm::Event& gen::BaseHadronizer::getEDMEvent ( ) const
inline
std::unique_ptr<HepMC::GenEvent> gen::BaseHadronizer::getGenEvent ( )
inline

Definition at line 54 of file BaseHadronizer.h.

References eostools::move().

54 { return std::move(genEvent_); }
std::unique_ptr< HepMC::GenEvent > genEvent_
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr<GenEventInfoProduct> gen::BaseHadronizer::getGenEventInfo ( )
inline

Definition at line 55 of file BaseHadronizer.h.

References eostools::move().

55 { return std::move(genEventInfo_); }
std::unique_ptr< GenEventInfoProduct > genEventInfo_
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< GenLumiInfoHeader > gen::BaseHadronizer::getGenLumiInfoHeader ( ) const
virtual

Reimplemented in Pythia8Hadronizer, Herwig7Hadronizer, and SherpaHadronizer.

Definition at line 47 of file BaseHadronizer.cc.

References genWeightsTable_cfi::genLumiInfoHeader, randomIndex_, and randomInitConfigDescription().

47  {
48 
49  auto genLumiInfoHeader = std::make_unique<GenLumiInfoHeader>();
50 
51  //fill information on randomized configs for parameter scans
52  genLumiInfoHeader->setRandomConfigIndex(randomIndex_);
53  if (randomIndex_>=0) {
54  genLumiInfoHeader->setConfigDescription(randomInitConfigDescription());
55  }
56 
57  return genLumiInfoHeader;
58 
59  }
const std::string & randomInitConfigDescription() const
GenRunInfoProduct& gen::BaseHadronizer::getGenRunInfo ( )
inline

Definition at line 53 of file BaseHadronizer.h.

53 { return genRunInfo_; }
GenRunInfoProduct genRunInfo_
std::unique_ptr<lhef::LHEEvent> gen::BaseHadronizer::getLHEEvent ( )
inline

Definition at line 57 of file BaseHadronizer.h.

References eostools::move().

57 { return std::move(lheEvent_);}
std::unique_ptr< lhef::LHEEvent > lheEvent_
def move(src, dest)
Definition: eostools.py:511
const std::shared_ptr<lhef::LHERunInfo>& gen::BaseHadronizer::getLHERunInfo ( ) const
inline

Definition at line 63 of file BaseHadronizer.h.

63 { return lheRunInfo_; }
std::shared_ptr< lhef::LHERunInfo > lheRunInfo_
const std::string& gen::BaseHadronizer::gridpackPath ( ) const
inline

Definition at line 79 of file BaseHadronizer.h.

References SiStripPI::max.

Referenced by generateLHE().

lhef::LHEEvent* gen::BaseHadronizer::lheEvent ( )
inlineprotected
lhef::LHERunInfo* gen::BaseHadronizer::lheRunInfo ( )
inlineprotected
int gen::BaseHadronizer::randomIndex ( ) const
inline

Definition at line 77 of file BaseHadronizer.h.

Referenced by gen::Py8InterfaceBase::readSettings().

77 { return randomIndex_; }
const std::string& gen::BaseHadronizer::randomInitConfigDescription ( ) const
inline

Definition at line 78 of file BaseHadronizer.h.

Referenced by getGenLumiInfoHeader().

std::vector< std::string > randomInitConfigDescriptions_
void gen::BaseHadronizer::randomizeIndex ( edm::LuminosityBlock const &  lumi,
CLHEP::HepRandomEngine *  rengine 
)

Definition at line 61 of file BaseHadronizer.cc.

References edm::LuminosityBlockBase::id(), edm::LuminosityBlockID::luminosityBlock(), randomIndex_, randomInitWeights_, and edm::LuminosityBlockID::run().

61  {
62  if (!randomInitWeights_.empty()) {
63  //randomly select from a list of provided configuration sets (for parameter scans)
64 
65  //seeds std 32-bit mersene twister with HepRandomEngine state plus run and lumi section numbers
66  //(random engine state will be the same for every lumi section in a job)
67  std::vector<long unsigned int> seeds = rengine->put();
68  seeds.push_back(lumi.id().run());
69  seeds.push_back(lumi.id().luminosityBlock());
70  std::seed_seq seedseq(seeds.begin(),seeds.end());
71  std::mt19937 randgen(seedseq);
72  std::discrete_distribution<int> randdist(randomInitWeights_.begin(),randomInitWeights_.end());
73 
74  randomIndex_ = randdist(randgen);
75  }
76  }
std::vector< double > randomInitWeights_
void gen::BaseHadronizer::resetEvent ( std::unique_ptr< HepMC::GenEvent event)
inline

Definition at line 59 of file BaseHadronizer.h.

References eostools::move().

Referenced by SherpaHadronizer::generatePartonsAndHadronize().

std::unique_ptr< HepMC::GenEvent > genEvent_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
void gen::BaseHadronizer::resetEventInfo ( std::unique_ptr< GenEventInfoProduct eventInfo)
inline

Definition at line 60 of file BaseHadronizer.h.

References eostools::move().

std::unique_ptr< GenEventInfoProduct > genEventInfo_
std::unique_ptr< GenEventInfoProduct > & eventInfo()
def move(src, dest)
Definition: eostools.py:511
GenRunInfoProduct& gen::BaseHadronizer::runInfo ( )
inlineprotected
virtual bool gen::BaseHadronizer::select ( HepMC::GenEvent ) const
inlinevirtual

Reimplemented in gen::PyquenHadronizer.

Definition at line 71 of file BaseHadronizer.h.

71 { return true;}
void gen::BaseHadronizer::setEDMEvent ( edm::Event event)
inline

Definition at line 69 of file BaseHadronizer.h.

References event().

69 { edmEvent_ = &event; }
edm::Event * edmEvent_
std::unique_ptr< HepMC::GenEvent > & event()
void gen::BaseHadronizer::setLHEEvent ( std::unique_ptr< lhef::LHEEvent event)
inline

Definition at line 66 of file BaseHadronizer.h.

References eostools::move().

std::unique_ptr< lhef::LHEEvent > lheEvent_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
void gen::BaseHadronizer::setLHERunInfo ( std::unique_ptr< lhef::LHERunInfo runInfo)
inline

Definition at line 65 of file BaseHadronizer.h.

References eostools::move().

GenRunInfoProduct & runInfo()
std::shared_ptr< lhef::LHERunInfo > lheRunInfo_
def move(src, dest)
Definition: eostools.py:511
void gen::BaseHadronizer::setRandomEngine ( CLHEP::HepRandomEngine *  v)
inline

Definition at line 73 of file BaseHadronizer.h.

Referenced by CMS_SHERPA_RNG::CMS_SHERPA_RNG().

73 { doSetRandomEngine(v); }
double v[5][pyjets_maxn]
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v)
std::vector<std::string> const& gen::BaseHadronizer::sharedResources ( ) const
inline

Definition at line 75 of file BaseHadronizer.h.

75 { return doSharedResources(); }
virtual std::vector< std::string > const & doSharedResources() const

Member Data Documentation

edm::Event* gen::BaseHadronizer::edmEvent_
private

Definition at line 108 of file BaseHadronizer.h.

std::unique_ptr<HepMC::GenEvent> gen::BaseHadronizer::genEvent_
private

Definition at line 102 of file BaseHadronizer.h.

std::unique_ptr<GenEventInfoProduct> gen::BaseHadronizer::genEventInfo_
private

Definition at line 103 of file BaseHadronizer.h.

GenRunInfoProduct gen::BaseHadronizer::genRunInfo_
private

Definition at line 101 of file BaseHadronizer.h.

std::vector<std::string> gen::BaseHadronizer::gridpackPaths_
private

Definition at line 114 of file BaseHadronizer.h.

Referenced by BaseHadronizer().

std::unique_ptr<lhef::LHEEvent> gen::BaseHadronizer::lheEvent_
private

Definition at line 106 of file BaseHadronizer.h.

std::string gen::BaseHadronizer::lheFile_
protected
std::shared_ptr<lhef::LHERunInfo> gen::BaseHadronizer::lheRunInfo_
private

Definition at line 105 of file BaseHadronizer.h.

int gen::BaseHadronizer::randomIndex_
protected

Definition at line 92 of file BaseHadronizer.h.

Referenced by getGenLumiInfoHeader(), and randomizeIndex().

std::vector<std::string> gen::BaseHadronizer::randomInitConfigDescriptions_
private

Definition at line 113 of file BaseHadronizer.h.

Referenced by BaseHadronizer().

std::vector<double> gen::BaseHadronizer::randomInitWeights_
private

Definition at line 112 of file BaseHadronizer.h.

Referenced by BaseHadronizer(), and randomizeIndex().

const std::vector< std::string > gen::BaseHadronizer::theSharedResources
staticprivate

Definition at line 110 of file BaseHadronizer.h.