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)
 
edm::EventgetEDMEvent () const
 
HepMC::GenEvent * getGenEvent ()
 
GenEventInfoProductgetGenEventInfo ()
 
GenRunInfoProductgetGenRunInfo ()
 
const boost::shared_ptr
< lhef::LHERunInfo > & 
getLHERunInfo () const
 
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 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 ()
 

Detailed Description

Definition at line 37 of file SherpaHadronizer.cc.

Constructor & Destructor Documentation

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

Definition at line 108 of file SherpaHadronizer.cc.

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

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

Definition at line 176 of file SherpaHadronizer.cc.

177 {
178 }

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 275 of file SherpaHadronizer.cc.

276 {
277  return true;
278 }
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 202 of file SherpaHadronizer.cc.

References getDQMSummary::iter.

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

Reimplemented from gen::BaseHadronizer.

Definition at line 89 of file SherpaHadronizer.cc.

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

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

Definition at line 285 of file SherpaHadronizer.cc.

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

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

Definition at line 232 of file SherpaHadronizer.cc.

References dtNoiseDBValidation_cfg::cerr, relval_steps::gen(), and gen::BaseHadronizer::resetEvent().

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

Definition at line 180 of file SherpaHadronizer.cc.

References dir2webdir::argc, arguments, getDQMSummary::argv, and ConfigFiles::l.

181 {
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 
186  Generator.InitializeTheRun(argc,argv);
187  //initialize Sherpa
188  Generator.InitializeTheEventHandler();
189 
190  return true;
191 }
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 280 of file SherpaHadronizer.cc.

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

Definition at line 217 of file SherpaHadronizer.cc.

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

218 {
219  //calculate statistics
220  Generator.SummarizeRun();
221 
222  //get the xsec & err
223  double xsec_val = Generator.TotalXS();
224  double xsec_err = Generator.TotalErr();
225 
226  //set the internal cross section in pb in GenRunInfoProduct
227  runInfo().setInternalXSec(GenRunInfoProduct::XSec(xsec_val,xsec_err));
228 
229 }
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::isRNGinitialized
private

Definition at line 68 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().