10 #include "SHERPA/Main/Sherpa.H"
11 #include "ATOOLS/Math/Random.H"
13 #include "ATOOLS/Org/Run_Parameter.H"
14 #include "ATOOLS/Org/MyStrStream.H"
22 #include "CLHEP/Random/RandomEngine.h"
32 CLHEP::HepRandomEngine* ExternalEngine=
nullptr;
33 CLHEP::HepRandomEngine* GetExternalEngine() {
return ExternalEngine; }
34 void SetExternalEngine(CLHEP::HepRandomEngine*
v) { ExternalEngine=
v; }
51 const char *
classname()
const {
return "SherpaHadronizer"; }
79 std::cout <<
"Use stored reference for the external RNG" << std::endl;
85 double Get()
override;
93 if (cmsSherpaRng ==
nullptr) {
97 std::cout <<
"Store assigned reference of the randomEngine" << std::endl;
102 <<
"The Sherpa interface got a randomEngine reference but there is no reference to the external RNG to hand it over to\n";
110 BaseHadronizer(params),
111 SherpaParameterSet(params.getParameter<edm::
ParameterSet>(
"SherpaParameters")),
112 isRNGinitialized(
false)
129 int retval=Fetcher.Fetch();
131 std::cout <<
"SherpaHadronizer: Preparation of Sherpack failed ... " << std::endl;
132 std::cout <<
"SherpaHadronizer: Error code: " << retval << std::endl;
140 for (
unsigned i=0;
i<setNames.size(); ++
i ) {
143 std::cout <<
"Write Sherpa parameter set " << setNames[
i] <<
" to "<<setNames[
i]<<
".dat "<<std::endl;
145 std::ofstream os(datfile.c_str());
147 for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
148 os<<(*itPar)<<std::endl;
167 arguments.push_back(shPathPiece.c_str());
204 for(std::vector<int>::const_iterator iter = pdgIds.begin();
205 iter != pdgIds.end(); ++iter)
206 if (!markStable(*iter))
236 bool gen_event =
true;
237 while((itry < 3) && gen_event){
243 std::cerr <<
"Exception from Generator.GenerateOneEvent() catch. Call # "
244 << itry <<
" for this event\n";
249 HepMC::GenEvent* evt =
new HepMC::GenEvent();
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];
287 for(HepMC::GenEvent::particle_iterator iter =
event->particles_begin();
288 iter !=
event->particles_end(); iter++)
289 (*iter)->set_status(getStatus(*iter));
302 ATOOLS::External_RNG *ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::operator()(
const ATOOLS::RNG_Key &)
const
305 void ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::PrintInfo(std::ostream &str,
const size_t)
const
306 { str<<
"CMS_SHERPA_RNG interface"; }
311 <<
"The Sherpa code attempted to a generate random number while\n"
312 <<
"the engine pointer was null. This might mean that the code\n"
313 <<
"was modified to generate a random number outside the event and\n"
314 <<
"beginLuminosityBlock methods, which is not allowed.\n";
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
CLHEP::HepRandomEngine * randomEngine
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string SherpaPathPiece
unsigned int maxEventsToPrint
edm::GeneratorFilter< SherpaHadronizer, gen::ExternalDecayDriver > SherpaGeneratorFilter
void setInternalXSec(const XSec &xsec)
bool declareStableParticles(const std::vector< int > &pdgIds)
std::auto_ptr< HepMC::GenEvent > & event()
GenRunInfoProduct & runInfo()
edm::ParameterSet SherpaParameterSet
bool initializeForInternalPartons()
bool generatePartonsAndHadronize()
bool declareSpecialSettings(const std::vector< std::string > &)
void setRandomEngine(CLHEP::HepRandomEngine *v)
double SherpaDefaultWeight
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::string SherpaProcess
std::string SherpaResultDir
std::vector< std::string > arguments
SherpaHadronizer(const edm::ParameterSet ¶ms)
void resetEvent(HepMC::GenEvent *event)
volatile std::atomic< bool > shutdown_flag false
DECLARE_GETTER(CMS_SHERPA_RNG,"CMS_SHERPA_RNG", ATOOLS::External_RNG, ATOOLS::RNG_Key)
const char * classname() const
std::string SherpaChecksum