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" 15 #include "ATOOLS/Org/CXXFLAGS.H" 16 #include "ATOOLS/Org/CXXFLAGS_PACKAGES.H" 17 #include "ATOOLS/Org/My_MPI.H" 25 #include "CLHEP/Random/RandomEngine.h" 35 CLHEP::HepRandomEngine* ExternalEngine=
nullptr;
36 CLHEP::HepRandomEngine* GetExternalEngine() {
return ExternalEngine; }
37 void SetExternalEngine(CLHEP::HepRandomEngine*
v) { ExternalEngine=
v; }
56 const char *
classname()
const {
return "SherpaHadronizer"; }
86 edm::LogVerbatim(
"SherpaHadronizer") <<
"Use stored reference for the external RNG";
92 double Get()
override;
99 if (cmsSherpaRng ==
nullptr) {
103 edm::LogVerbatim(
"SherpaHadronizer") <<
"Store assigned reference of the randomEngine";
104 SetExternalEngine(v);
108 <<
"The Sherpa interface got a randomEngine reference but there is no reference to the external RNG to hand it over to\n";
140 if (!params.
exists(
"SherpaWeightsBlock")) {
145 if (WeightsBlock.
exists(
"SherpaWeights"))
148 throw cms::Exception(
"SherpaInterface") <<
"SherpaWeights does not exists in SherpaWeightsBlock" << std::endl;
149 if (WeightsBlock.
exists(
"SherpaVariationWeights"))
152 throw cms::Exception(
"SherpaInterface") <<
"SherpaVariationWeights does not exists in SherpaWeightsBlock" << std::endl;
153 edm::LogVerbatim(
"SherpaHadronizer") <<
"SherpaHadronizer will try rearrange the event weights according to SherpaWeights and SherpaVariationWeights";
158 int retval=Fetcher.
Fetch();
160 throw cms::Exception(
"SherpaInterface") <<
"SherpaHadronizer: Preparation of Sherpack failed ... ";
166 for (
unsigned i=0;
i<setNames.size(); ++
i ) {
169 edm::LogVerbatim(
"SherpaHadronizer") <<
"Write Sherpa parameter set " << setNames[
i] <<
" to "<<setNames[
i]<<
".dat ";
171 std::ofstream os(datfile.c_str());
173 for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
174 os<<(*itPar)<<std::endl;
251 bool gen_event =
true;
252 while((itry < 3) && gen_event){
258 std::cerr <<
"Exception from Generator->GenerateOneEvent() catch. Call # " 259 << itry <<
" for this event\n";
276 bool unweighted =
false;
277 double weight_normalization = -1;
278 if(ATOOLS::ToType<int>(ATOOLS::rpa->
gen.Variable(
"EVENT_GENERATION_MODE")) == 1){
279 if (evt->weights().size()>2) {
281 weight_normalization = evt->weights()[2];
283 throw cms::Exception(
"SherpaInterface") <<
"Requested unweighted production. Missing normalization weight." << std::endl;
288 std::vector<double> newWeights;
291 if (evt->weights().has_key(
i)) {
292 newWeights.push_back(evt->weights()[
i]);
294 throw cms::Exception(
"SherpaInterface") <<
"Missing weights! Key " <<
i <<
" not found, please check the weight definition!" << std::endl;
298 if (evt->weights().has_key(
i)) {
300 newWeights.push_back(evt->weights()[
i]/weight_normalization);
302 newWeights.push_back(evt->weights()[
i]);
305 throw cms::Exception(
"SherpaInterface") <<
"Missing weights! Key " <<
i <<
" not found, please check the weight definition!" << std::endl;
311 evt->weights().clear();
312 for (
auto&
elem: newWeights) {
313 evt->weights().push_back(
elem);
318 evt->weights()[0]/=weight_normalization;
351 ATOOLS::External_RNG *ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::operator()(
const ATOOLS::RNG_Key &)
const 354 void ATOOLS::Getter<ATOOLS::External_RNG,ATOOLS::RNG_Key,CMS_SHERPA_RNG>::PrintInfo(std::ostream &
str,
const size_t)
const 355 {
str<<
"CMS_SHERPA_RNG interface"; }
360 <<
"The Sherpa code attempted to a generate random number while\n" 361 <<
"the engine pointer was null. This might mean that the code\n" 362 <<
"was modified to generate a random number outside the event and\n" 363 <<
"beginLuminosityBlock methods, which is not allowed.\n";
372 edm::LogPrint(
"SherpaHadronizer") <<
"The order of event weights was changed!" ;
382 return genLumiInfoHeader;
CLHEP::HepRandomEngine * randomEngine
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
CLHEP::HepRandomEngine * randomEngine
BaseHadronizer(edm::ParameterSet const &ps)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< std::string > weightlist
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()
void setRandomEngine(CLHEP::HepRandomEngine *v)
std::vector< std::string > variationweightlist
bool generatePartonsAndHadronize()
def elem(elemtype, innerHTML='', html_class='', kwargs)
~SherpaHadronizer() override
bool declareSpecialSettings(const std::vector< std::string > &)
void setRandomEngine(CLHEP::HepRandomEngine *v)
double SherpaDefaultWeight
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::string SherpaProcess
GenLumiInfoHeader * getGenLumiInfoHeader() const override
std::string SherpaResultDir
std::vector< std::string > arguments
SherpaHadronizer(const edm::ParameterSet ¶ms)
void resetEvent(HepMC::GenEvent *event)
DECLARE_GETTER(CMS_SHERPA_RNG,"CMS_SHERPA_RNG", ATOOLS::External_RNG, ATOOLS::RNG_Key)
const char * classname() const
std::string SherpaChecksum