CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
SherpaHadronizer Class Reference
Inheritance diagram for SherpaHadronizer:
gen::BaseHadronizer

Public Member Functions

const char * classname () const
 
bool decay ()
 
bool declareSpecialSettings (const std::vector< std::string > &)
 
bool declareStableParticles (const std::vector< int > &pdgIds)
 
void finalizeEvent ()
 
bool generatePartonsAndHadronize ()
 
bool initializeForInternalPartons ()
 
bool readSettings (int)
 
bool residualDecay ()
 
 SherpaHadronizer (const edm::ParameterSet &params)
 
void statistics ()
 
 ~SherpaHadronizer ()
 
- Public Member Functions inherited from gen::BaseHadronizer
 BaseHadronizer (edm::ParameterSet const &ps)
 
void cleanLHE ()
 
void generateLHE (edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine)
 
edm::EventgetEDMEvent () const
 
HepMC::GenEvent * getGenEvent ()
 
GenEventInfoProductgetGenEventInfo ()
 
virtual GenLumiInfoHeadergetGenLumiInfoHeader () const
 
GenRunInfoProductgetGenRunInfo ()
 
const boost::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 (HepMC::GenEvent *event)
 
void resetEventInfo (GenEventInfoProduct *eventInfo)
 
virtual bool select (HepMC::GenEvent *) const
 
void setEDMEvent (edm::Event &event)
 
void setLHEEvent (lhef::LHEEvent *event)
 
void setLHERunInfo (lhef::LHERunInfo *runInfo)
 
void setRandomEngine (CLHEP::HepRandomEngine *v)
 
std::vector< std::string > const & sharedResources () const
 
 ~BaseHadronizer ()
 

Private Member Functions

virtual void doSetRandomEngine (CLHEP::HepRandomEngine *v) override
 

Private Attributes

std::vector< std::string > arguments
 
SHERPA::Sherpa Generator
 
bool isInitialized
 
bool isRNGinitialized
 
unsigned int maxEventsToPrint
 
std::string SherpaChecksum
 
double SherpaDefaultWeight
 
edm::ParameterSet SherpaParameterSet
 
std::string SherpaPath
 
std::string SherpaPathPiece
 
std::string SherpaProcess
 
std::string SherpaResultDir
 

Additional Inherited Members

- Protected Member Functions inherited from gen::BaseHadronizer
std::auto_ptr< HepMC::GenEvent > & event ()
 
std::auto_ptr
< GenEventInfoProduct > & 
eventInfo ()
 
lhef::LHEEventlheEvent ()
 
lhef::LHERunInfolheRunInfo ()
 
GenRunInfoProductrunInfo ()
 
- Protected Attributes inherited from gen::BaseHadronizer
std::string lheFile_
 
int randomIndex_
 

Detailed Description

Definition at line 37 of file SherpaHadronizer.cc.

Constructor & Destructor Documentation

SherpaHadronizer::SherpaHadronizer ( const edm::ParameterSet params)

Definition at line 109 of file SherpaHadronizer.cc.

References arguments, gather_cfg::cout, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), i, isInitialized, maxEventsToPrint, SherpaDefaultWeight, SherpaParameterSet, SherpaPath, SherpaPathPiece, SherpaProcess, SherpaResultDir, and AlCaHLTBitMon_QueryRunRegistry::string.

109  :
110  BaseHadronizer(params),
111  SherpaParameterSet(params.getParameter<edm::ParameterSet>("SherpaParameters")),
112  isRNGinitialized(false)
113 {
114  if (!params.exists("SherpaProcess")) SherpaProcess="";
115  else SherpaProcess=params.getParameter<std::string>("SherpaProcess");
116  if (!params.exists("SherpaPath")) SherpaPath="";
117  else SherpaPath=params.getParameter<std::string>("SherpaPath");
118  if (!params.exists("SherpaPathPiece")) SherpaPathPiece="";
119  else SherpaPathPiece=params.getParameter<std::string>("SherpaPathPiece");
120  if (!params.exists("SherpaResultDir")) SherpaResultDir="Result";
121  else SherpaResultDir=params.getParameter<std::string>("SherpaResultDir");
122  if (!params.exists("SherpaDefaultWeight")) SherpaDefaultWeight=1.;
123  else SherpaDefaultWeight=params.getParameter<double>("SherpaDefaultWeight");
124  if (!params.exists("maxEventsToPrint")) maxEventsToPrint=0;
125  else maxEventsToPrint=params.getParameter<int>("maxEventsToPrint");
126 
127 
128  spf::SherpackFetcher Fetcher(params);
129  int retval=Fetcher.Fetch();
130  if (retval != 0) {
131  std::cout << "SherpaHadronizer: Preparation of Sherpack failed ... " << std::endl;
132  std::cout << "SherpaHadronizer: Error code: " << retval << std::endl;
133  std::terminate();
134 
135  }
136  // The ids (names) of parameter sets to be read (Analysis,Run) to create Analysis.dat, Run.dat
137  //They are given as a vstring.
138  std::vector<std::string> setNames = SherpaParameterSet.getParameter<std::vector<std::string> >("parameterSets");
139  //Loop all set names...
140  for ( unsigned i=0; i<setNames.size(); ++i ) {
141  // ...and read the parameters for each set given in vstrings
142  std::vector<std::string> pars = SherpaParameterSet.getParameter<std::vector<std::string> >(setNames[i]);
143  std::cout << "Write Sherpa parameter set " << setNames[i] <<" to "<<setNames[i]<<".dat "<<std::endl;
144  std::string datfile = SherpaPath + "/" + setNames[i] +".dat";
145  std::ofstream os(datfile.c_str());
146  // Loop over all strings and write the according *.dat
147  for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
148  os<<(*itPar)<<std::endl;
149  }
150  }
151 
152  //To be conform to the default Sherpa usage create a command line:
153  //name of executable (only for demonstration, could also be empty)
154  std::string shRun = "./Sherpa";
155  //Path where the Sherpa libraries are stored
156  std::string shPath = "PATH=" + SherpaPath;
157  // new for Sherpa 1.3.0, suggested by authors
158  std::string shPathPiece = "PATH_PIECE=" + SherpaPathPiece;
159  //Path where results are stored
160  std::string shRes = "RESULT_DIRECTORY=" + SherpaResultDir; // from Sherpa 1.2.0 on
161  //Name of the external random number class
162  std::string shRng = "EXTERNAL_RNG=CMS_SHERPA_RNG";
163 
164  //create the command line
165  arguments.push_back(shRun.c_str());
166  arguments.push_back(shPath.c_str());
167  arguments.push_back(shPathPiece.c_str());
168  arguments.push_back(shRes.c_str());
169  arguments.push_back(shRng.c_str());
170  isInitialized=false;
171  //initialization of Sherpa moved to initializeForInternalPartons
172 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
BaseHadronizer(edm::ParameterSet const &ps)
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string SherpaPathPiece
unsigned int maxEventsToPrint
edm::ParameterSet SherpaParameterSet
std::string SherpaPath
std::string SherpaProcess
std::string SherpaResultDir
std::vector< std::string > arguments
tuple cout
Definition: gather_cfg.py:145
SherpaHadronizer::~SherpaHadronizer ( )

Definition at line 174 of file SherpaHadronizer.cc.

175 {
176 }

Member Function Documentation

const char* SherpaHadronizer::classname ( ) const
inline

Definition at line 51 of file SherpaHadronizer.cc.

51 { return "SherpaHadronizer"; }
bool SherpaHadronizer::decay ( )

Definition at line 274 of file SherpaHadronizer.cc.

275 {
276  return true;
277 }
bool SherpaHadronizer::declareSpecialSettings ( const std::vector< std::string > &  )
inline

Definition at line 45 of file SherpaHadronizer.cc.

45 { return true; }
bool SherpaHadronizer::declareStableParticles ( const std::vector< int > &  pdgIds)

Definition at line 201 of file SherpaHadronizer.cc.

202 {
203 #if 0
204  for(std::vector<int>::const_iterator iter = pdgIds.begin();
205  iter != pdgIds.end(); ++iter)
206  if (!markStable(*iter))
207  return false;
208 
209  return true;
210 #else
211  return false;
212 #endif
213 }
void SherpaHadronizer::doSetRandomEngine ( CLHEP::HepRandomEngine *  v)
overrideprivatevirtual

Reimplemented from gen::BaseHadronizer.

Definition at line 90 of file SherpaHadronizer.cc.

References gather_cfg::cout, Exception, isRNGinitialized, edm::errors::LogicError, summarizeEdmComparisonLogfiles::ran, and CMS_SHERPA_RNG::setRandomEngine().

90  {
91  CMS_SHERPA_RNG* cmsSherpaRng = dynamic_cast<CMS_SHERPA_RNG*>(ATOOLS::ran->GetExternalRng());
92  //~ assert(cmsSherpaRng != nullptr);
93  if (cmsSherpaRng ==nullptr) {
94  //First time call to this function makes the interface store the reference in the unnamed namespace
95  if (!isRNGinitialized){
96  isRNGinitialized=true;
97  std::cout << "Store assigned reference of the randomEngine" << std::endl;
98  SetExternalEngine(v);
99  // Throw exception if there is no reference to an external RNG and it is not the first call!
100  } else {
102  << "The Sherpa interface got a randomEngine reference but there is no reference to the external RNG to hand it over to\n";
103  }
104  } else {
105  cmsSherpaRng->setRandomEngine(v);
106  }
107 }
void setRandomEngine(CLHEP::HepRandomEngine *v)
tuple cout
Definition: gather_cfg.py:145
void SherpaHadronizer::finalizeEvent ( )

Definition at line 284 of file SherpaHadronizer.cc.

References gen::BaseHadronizer::event(), and maxEventsToPrint.

285 {
286 #if 0
287  for(HepMC::GenEvent::particle_iterator iter = event->particles_begin();
288  iter != event->particles_end(); iter++)
289  (*iter)->set_status(getStatus(*iter));
290 #endif
291  //******** Verbosity *******
292  if (maxEventsToPrint > 0) {
294  event()->print();
295  }
296 }
unsigned int maxEventsToPrint
std::auto_ptr< HepMC::GenEvent > & event()
bool SherpaHadronizer::generatePartonsAndHadronize ( )

Definition at line 231 of file SherpaHadronizer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, relval_steps::gen(), and gen::BaseHadronizer::resetEvent().

232 {
233  //get the next event and check if it produced
234  bool rc = false;
235  int itry = 0;
236  bool gen_event = true;
237  while((itry < 3) && gen_event){
238  try{
239  rc = Generator.GenerateOneEvent();
240  gen_event = false;
241  } catch(...){
242  ++itry;
243  std::cerr << "Exception from Generator.GenerateOneEvent() catch. Call # "
244  << itry << " for this event\n";
245  }
246  }
247  if (rc) {
248  //convert it to HepMC2
249  HepMC::GenEvent* evt = new HepMC::GenEvent();
250  Generator.FillHepMCEvent(*evt);
251 
252  // in case of unweighted events sherpa puts the max weight as event weight.
253  // this is not optimal, we want 1 for unweighted events, so we check
254  // whether we are producing unweighted events ("EVENT_GENERATION_MODE" == "1")
255  // the information about the weights to the HepMC weight vector:
256  // [0] event weight
257  // [1] combined matrix element and phase space weight (missing only PDF information, thus directly suitable for PDF reweighting)
258  // [2] event weight normalisation (in case of unweighted events event weights of ~ +/-1 can be obtained by (event weight)/(event weight normalisation))
259  // [3] number of trials.
260  // see also: https://sherpa.hepforge.org/doc/SHERPA-MC-2.1.0.html#Event-output-formats
261  if(ATOOLS::ToType<int>(ATOOLS::rpa->gen.Variable("EVENT_GENERATION_MODE")) == 1){
262  if (evt->weights().size()>2) {
263  evt->weights()[0]/=evt->weights()[2];
264  }
265  }
266  resetEvent(evt);
267  return true;
268  }
269  else {
270  return false;
271  }
272 }
void resetEvent(HepMC::GenEvent *event)
bool SherpaHadronizer::initializeForInternalPartons ( )

Definition at line 178 of file SherpaHadronizer.cc.

References dir2webdir::argc, arguments, cmsStageWithFailover::argv, isInitialized, and cmsLHEtoEOSManager::l.

179 {
180  //initialize Sherpa but only once
181  if (!isInitialized){
182  int argc=arguments.size();
183  char* argv[argc];
184  for (int l=0; l<argc; l++) argv[l]=(char*)arguments[l].c_str();
185  Generator.InitializeTheRun(argc,argv);
186  Generator.InitializeTheEventHandler();
187  isInitialized=true;
188  }
189  return true;
190 }
tuple argc
Definition: dir2webdir.py:38
std::vector< std::string > arguments
bool SherpaHadronizer::readSettings ( int  )
inline

Definition at line 42 of file SherpaHadronizer.cc.

42 { return true; }
bool SherpaHadronizer::residualDecay ( )

Definition at line 279 of file SherpaHadronizer.cc.

280 {
281  return true;
282 }
void SherpaHadronizer::statistics ( )

Definition at line 216 of file SherpaHadronizer.cc.

References gen::BaseHadronizer::runInfo(), and GenRunInfoProduct::setInternalXSec().

217 {
218  //calculate statistics
219  Generator.SummarizeRun();
220 
221  //get the xsec & err
222  double xsec_val = Generator.TotalXS();
223  double xsec_err = Generator.TotalErr();
224 
225  //set the internal cross section in pb in GenRunInfoProduct
226  runInfo().setInternalXSec(GenRunInfoProduct::XSec(xsec_val,xsec_err));
227 
228 }
void setInternalXSec(const XSec &xsec)
GenRunInfoProduct & runInfo()

Member Data Documentation

std::vector<std::string> SherpaHadronizer::arguments
private

Definition at line 66 of file SherpaHadronizer.cc.

Referenced by initializeForInternalPartons(), and SherpaHadronizer().

SHERPA::Sherpa SherpaHadronizer::Generator
private

Definition at line 67 of file SherpaHadronizer.cc.

bool SherpaHadronizer::isInitialized
private

Definition at line 68 of file SherpaHadronizer.cc.

Referenced by initializeForInternalPartons(), and SherpaHadronizer().

bool SherpaHadronizer::isRNGinitialized
private

Definition at line 69 of file SherpaHadronizer.cc.

Referenced by doSetRandomEngine().

unsigned int SherpaHadronizer::maxEventsToPrint
private

Definition at line 65 of file SherpaHadronizer.cc.

Referenced by finalizeEvent(), and SherpaHadronizer().

std::string SherpaHadronizer::SherpaChecksum
private

Definition at line 59 of file SherpaHadronizer.cc.

double SherpaHadronizer::SherpaDefaultWeight
private

Definition at line 63 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

edm::ParameterSet SherpaHadronizer::SherpaParameterSet
private

Definition at line 64 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPath
private

Definition at line 60 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPathPiece
private

Definition at line 61 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaProcess
private

Definition at line 58 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaResultDir
private

Definition at line 62 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().