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 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 Attributes

SHERPA::Sherpa Generator
 
unsigned int maxEventsToPrint
 
CLHEP::HepRandomEngine * randomEngine
 
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 26 of file SherpaHadronizer.cc.

Constructor & Destructor Documentation

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

Definition at line 68 of file SherpaHadronizer.cc.

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

68  :
69  BaseHadronizer(params),
70  SherpaParameterSet(params.getParameter<edm::ParameterSet>("SherpaParameters"))
71 {
72  if (!params.exists("SherpaProcess")) SherpaProcess="";
73  else SherpaProcess=params.getParameter<std::string>("SherpaProcess");
74  if (!params.exists("SherpaPath")) SherpaPath="";
75  else SherpaPath=params.getParameter<std::string>("SherpaPath");
76  if (!params.exists("SherpaPathPiece")) SherpaPathPiece="";
77  else SherpaPathPiece=params.getParameter<std::string>("SherpaPathPiece");
78  if (!params.exists("SherpaResultDir")) SherpaResultDir="Result";
79  else SherpaResultDir=params.getParameter<std::string>("SherpaResultDir");
80  if (!params.exists("SherpaDefaultWeight")) SherpaDefaultWeight=1.;
81  else SherpaDefaultWeight=params.getParameter<double>("SherpaDefaultWeight");
82  if (!params.exists("maxEventsToPrint")) maxEventsToPrint=0;
83  else maxEventsToPrint=params.getParameter<int>("maxEventsToPrint");
84 
85 
86  spf::SherpackFetcher Fetcher(params);
87  int retval=Fetcher.Fetch();
88  if (retval != 0) {
89  std::cout << "SherpaHadronizer: Preparation of Sherpack failed ... " << std::endl;
90  std::cout << "SherpaHadronizer: Error code: " << retval << std::endl;
91  std::terminate();
92 
93  }
94  // The ids (names) of parameter sets to be read (Analysis,Run) to create Analysis.dat, Run.dat
95  //They are given as a vstring.
96  std::vector<std::string> setNames = SherpaParameterSet.getParameter<std::vector<std::string> >("parameterSets");
97  //Loop all set names...
98  for ( unsigned i=0; i<setNames.size(); ++i ) {
99  // ...and read the parameters for each set given in vstrings
100  std::vector<std::string> pars = SherpaParameterSet.getParameter<std::vector<std::string> >(setNames[i]);
101  std::cout << "Write Sherpa parameter set " << setNames[i] <<" to "<<setNames[i]<<".dat "<<std::endl;
102  std::string datfile = SherpaPath + "/" + setNames[i] +".dat";
103  std::ofstream os(datfile.c_str());
104  // Loop over all strings and write the according *.dat
105  for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
106  os<<(*itPar)<<std::endl;
107  }
108  }
109 
110  //To be conform to the default Sherpa usage create a command line:
111  //name of executable (only for demonstration, could also be empty)
112  std::string shRun = "./Sherpa";
113  //Path where the Sherpa libraries are stored
114  std::string shPath = "PATH=" + SherpaPath;
115  // new for Sherpa 1.3.0, suggested by authors
116  std::string shPathPiece = "PATH_PIECE=" + SherpaPathPiece;
117  //Path where results are stored
118  std::string shRes = "RESULT_DIRECTORY=" + SherpaResultDir; // from Sherpa 1.2.0 on
119  //Name of the external random number class
120  std::string shRng = "EXTERNAL_RNG=CMS_SHERPA_RNG";
121 
122  //create the command line
123  char* argv[5];
124  argv[0]=(char*)shRun.c_str();
125  argv[1]=(char*)shPath.c_str();
126  argv[2]=(char*)shPathPiece.c_str();
127  argv[3]=(char*)shRes.c_str();
128  argv[4]=(char*)shRng.c_str();
129 
130  //initialize Sherpa with the command line
131  Generator.InitializeTheRun(5,argv);
132 }
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
tuple cout
Definition: gather_cfg.py:121
SherpaHadronizer::~SherpaHadronizer ( )

Definition at line 134 of file SherpaHadronizer.cc.

135 {
136 }

Member Function Documentation

const char* SherpaHadronizer::classname ( ) const
inline

Definition at line 40 of file SherpaHadronizer.cc.

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

Definition at line 220 of file SherpaHadronizer.cc.

221 {
222  return true;
223 }
bool SherpaHadronizer::declareSpecialSettings ( const std::vector< std::string > &  )
inline

Definition at line 34 of file SherpaHadronizer.cc.

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

Definition at line 156 of file SherpaHadronizer.cc.

157 {
158 #if 0
159  for(std::vector<int>::const_iterator iter = pdgIds.begin();
160  iter != pdgIds.end(); ++iter)
161  if (!markStable(*iter))
162  return false;
163 
164  return true;
165 #else
166  return false;
167 #endif
168 }
void SherpaHadronizer::finalizeEvent ( )

Definition at line 230 of file SherpaHadronizer.cc.

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

231 {
232 #if 0
233  for(HepMC::GenEvent::particle_iterator iter = event->particles_begin();
234  iter != event->particles_end(); iter++)
235  (*iter)->set_status(getStatus(*iter));
236 #endif
237  //******** Verbosity *******
238  if (maxEventsToPrint > 0) {
240  event()->print();
241  }
242 }
unsigned int maxEventsToPrint
std::auto_ptr< HepMC::GenEvent > & event()
bool SherpaHadronizer::generatePartonsAndHadronize ( )

Definition at line 187 of file SherpaHadronizer.cc.

References relval_steps::gen(), gen::BaseHadronizer::resetEvent(), SherpaDefaultWeight, and histoStyle::weight.

188 {
189  //get the next event and check if it produced
190  if (Generator.GenerateOneEvent()) {
191  //convert it to HepMC2
192  SHERPA::Input_Output_Handler* ioh = Generator.GetIOHandler();
193  SHERPA::HepMC2_Interface* hm2i = ioh->GetHepMC2Interface();
194  //get the event weight from blobs
195  ATOOLS::Blob_List* blobs = Generator.GetEventHandler()-> GetBlobs();
196  ATOOLS::Blob* sp(blobs->FindFirst(ATOOLS::btp::Signal_Process));
197  double weight((*sp)["Weight"]->Get<double>());
198  double ef((*sp)["Enhance"]->Get<double>());
199  // in case of unweighted events sherpa puts the max weight as event weight.
200  // this is not optimal, we want 1 for unweighted events, so we check
201  // whether we are producing unweighted events ("EVENT_GENERATION_MODE" == "1")
202  if ( ATOOLS::ToType<int>( ATOOLS::rpa->gen.Variable("EVENT_GENERATION_MODE") ) == 1 ) {
203  if (ef > 0.) {
205  } else {
206  weight = -1234.;
207  }
208  }
209  //create and empty event and then hand it to SherpaIOHandler to fill it
210  HepMC::GenEvent* evt = new HepMC::GenEvent();
211  hm2i->Sherpa2HepMC(blobs, *evt, weight);
212  resetEvent(evt);
213  return true;
214  }
215  else {
216  return false;
217  }
218 }
void resetEvent(HepMC::GenEvent *event)
int weight
Definition: histoStyle.py:50
bool SherpaHadronizer::initializeForInternalPartons ( )

Definition at line 138 of file SherpaHadronizer.cc.

139 {
140 
141  //initialize Sherpa
142  Generator.InitializeTheEventHandler();
143 
144  return true;
145 }
bool SherpaHadronizer::readSettings ( int  )
inline

Definition at line 31 of file SherpaHadronizer.cc.

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

Definition at line 225 of file SherpaHadronizer.cc.

226 {
227  return true;
228 }
void SherpaHadronizer::statistics ( )

Definition at line 171 of file SherpaHadronizer.cc.

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

172 {
173  //calculate statistics
174  Generator.SummarizeRun();
175 
176  //get the xsec from EventHandler
177  SHERPA::Event_Handler* theEventHandler = Generator.GetEventHandler();
178  double xsec_val = theEventHandler->TotalXS();
179  double xsec_err = theEventHandler->TotalErr();
180 
181  //set the internal cross section in pb in GenRunInfoProduct
182  runInfo().setInternalXSec(GenRunInfoProduct::XSec(xsec_val,xsec_err));
183 
184 }
void setInternalXSec(const XSec &xsec)
GenRunInfoProduct & runInfo()

Member Data Documentation

SHERPA::Sherpa SherpaHadronizer::Generator
private

Definition at line 53 of file SherpaHadronizer.cc.

unsigned int SherpaHadronizer::maxEventsToPrint
private

Definition at line 51 of file SherpaHadronizer.cc.

Referenced by finalizeEvent(), and SherpaHadronizer().

CLHEP::HepRandomEngine* SherpaHadronizer::randomEngine
private

Definition at line 54 of file SherpaHadronizer.cc.

std::string SherpaHadronizer::SherpaChecksum
private

Definition at line 45 of file SherpaHadronizer.cc.

double SherpaHadronizer::SherpaDefaultWeight
private

Definition at line 49 of file SherpaHadronizer.cc.

Referenced by generatePartonsAndHadronize(), and SherpaHadronizer().

edm::ParameterSet SherpaHadronizer::SherpaParameterSet
private

Definition at line 50 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPath
private

Definition at line 46 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPathPiece
private

Definition at line 47 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaProcess
private

Definition at line 44 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaResultDir
private

Definition at line 48 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().