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"; }
78 std::cout <<
"Use stored reference for the external RNG" << std::endl;
84 double Get()
override;
92 if (cmsSherpaRng ==
nullptr) {
96 std::cout <<
"Store assigned reference of the randomEngine" << std::endl;
101 <<
"The Sherpa interface got a randomEngine reference but there is no reference to the external RNG to hand it over to\n";
109 BaseHadronizer(params),
110 SherpaParameterSet(params.getParameter<edm::
ParameterSet>(
"SherpaParameters")),
111 isRNGinitialized(
false)
128 int retval=Fetcher.Fetch();
130 std::cout <<
"SherpaHadronizer: Preparation of Sherpack failed ... " << std::endl;
131 std::cout <<
"SherpaHadronizer: Error code: " << retval << std::endl;
139 for (
unsigned i=0;
i<setNames.size(); ++
i ) {
142 std::cout <<
"Write Sherpa parameter set " << setNames[
i] <<
" to "<<setNames[
i]<<
".dat "<<std::endl;
144 std::ofstream os(datfile.c_str());
146 for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
147 os<<(*itPar)<<std::endl;
168 arguments.push_back(shPathPiece.c_str());
205 for(std::vector<int>::const_iterator iter = pdgIds.begin();
206 iter != pdgIds.end(); ++iter)
207 if (!markStable(*iter))
237 bool gen_event =
true;
238 while((itry < 3) && gen_event){
244 std::cerr <<
"Exception from Generator.GenerateOneEvent() catch. Call # "
245 << itry <<
" for this event\n";
250 HepMC::GenEvent* evt =
new HepMC::GenEvent();
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];
288 for(HepMC::GenEvent::particle_iterator iter =
event->particles_begin();
289 iter !=
event->particles_end(); iter++)
290 (*iter)->set_status(getStatus(*iter));
303 ATOOLS::External_RNG *ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::operator()(
const ATOOLS::RNG_Key &)
const
306 void ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::PrintInfo(std::ostream &str,
const size_t)
const
307 { str<<
"CMS_SHERPA_RNG interface"; }
312 <<
"The Sherpa code attempted to a generate random number while\n"
313 <<
"the engine pointer was null. This might mean that the code\n"
314 <<
"was modified to generate a random number outside the event and\n"
315 <<
"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