9 #include "SHERPA/Main/Sherpa.H" 10 #include "ATOOLS/Math/Random.H" 12 #include "ATOOLS/Org/Run_Parameter.H" 13 #include "ATOOLS/Org/MyStrStream.H" 14 #include "ATOOLS/Org/CXXFLAGS.H" 15 #include "ATOOLS/Org/CXXFLAGS_PACKAGES.H" 16 #include "ATOOLS/Org/My_MPI.H" 24 #include "CLHEP/Random/RandomEngine.h" 33 CLHEP::HepRandomEngine *ExternalEngine =
nullptr;
34 CLHEP::HepRandomEngine *GetExternalEngine() {
return ExternalEngine; }
35 void SetExternalEngine(CLHEP::HepRandomEngine *
v) { ExternalEngine =
v; }
54 const char *
classname()
const {
return "SherpaHadronizer"; }
78 edm::LogVerbatim(
"SherpaHadronizer") <<
"Use stored reference for the external RNG";
84 double Get()
override;
90 if (cmsSherpaRng ==
nullptr) {
94 edm::LogVerbatim(
"SherpaHadronizer") <<
"Store assigned reference of the randomEngine";
99 "no reference to the external RNG to hand it over to\n";
110 if (!params.
exists(
"SherpaProcess"))
114 if (!params.
exists(
"SherpaPath"))
118 if (!params.
exists(
"SherpaPathPiece"))
122 if (!params.
exists(
"SherpaResultDir"))
126 if (!params.
exists(
"SherpaDefaultWeight"))
130 if (!params.
exists(
"maxEventsToPrint"))
142 if (!params.
exists(
"SherpaWeightsBlock")) {
147 if (WeightsBlock.
exists(
"SherpaWeights"))
150 throw cms::Exception(
"SherpaInterface") <<
"SherpaWeights does not exists in SherpaWeightsBlock" << std::endl;
151 if (WeightsBlock.
exists(
"SherpaVariationWeights"))
155 <<
"SherpaVariationWeights does not exists in SherpaWeightsBlock" << std::endl;
156 edm::LogVerbatim(
"SherpaHadronizer") <<
"SherpaHadronizer will try rearrange the event weights according to " 157 "SherpaWeights and SherpaVariationWeights";
161 int retval = Fetcher.
Fetch();
163 throw cms::Exception(
"SherpaInterface") <<
"SherpaHadronizer: Preparation of Sherpack failed ... ";
169 for (
unsigned i = 0;
i < setNames.size(); ++
i) {
172 edm::LogVerbatim(
"SherpaHadronizer") <<
"Write Sherpa parameter set " << setNames[
i] <<
" to " << setNames[
i]
175 std::ofstream os(datfile.c_str());
177 for (std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar) {
178 os << (*itPar) << std::endl;
246 bool gen_event =
true;
247 while ((itry < 3) && gen_event) {
253 std::cerr <<
"Exception from Generator->GenerateOneEvent() catch. Call # " << itry <<
" for this event\n";
258 auto evt = std::make_unique<HepMC::GenEvent>();
270 bool unweighted =
false;
271 double weight_normalization = -1;
272 if (ATOOLS::ToType<int>(ATOOLS::rpa->
gen.Variable(
"EVENT_GENERATION_MODE")) == 1) {
273 if (evt->weights().size() > 2) {
275 weight_normalization = evt->weights()[2];
278 <<
"Requested unweighted production. Missing normalization weight." << std::endl;
283 std::vector<double> newWeights;
286 if (evt->weights().has_key(
i)) {
287 newWeights.push_back(evt->weights()[
i]);
290 <<
"Missing weights! Key " <<
i <<
" not found, please check the weight definition!" << std::endl;
294 if (evt->weights().has_key(
i)) {
296 newWeights.push_back(evt->weights()[
i] / weight_normalization);
298 newWeights.push_back(evt->weights()[
i]);
302 <<
"Missing weights! Key " <<
i <<
" not found, please check the weight definition!" << std::endl;
307 evt->weights().clear();
308 for (
auto &
elem : newWeights) {
309 evt->weights().push_back(
elem);
314 evt->weights()[0] /= weight_normalization;
338 ATOOLS::External_RNG *ATOOLS::Getter<ATOOLS::External_RNG, ATOOLS::RNG_Key, CMS_SHERPA_RNG>::operator()(
339 const ATOOLS::RNG_Key &)
const {
343 void ATOOLS::Getter<ATOOLS::External_RNG, ATOOLS::RNG_Key, CMS_SHERPA_RNG>::PrintInfo(std::ostream &
str,
344 const size_t)
const {
345 str <<
"CMS_SHERPA_RNG interface";
351 <<
"the engine pointer was null. This might mean that the code\n" 352 <<
"was modified to generate a random number outside the event and\n" 353 <<
"beginLuminosityBlock methods, which is not allowed.\n";
361 edm::LogPrint(
"SherpaHadronizer") <<
"The order of event weights was changed!";
CLHEP::HepRandomEngine * randomEngine
T getParameter(std::string const &) const
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)
GenRunInfoProduct & runInfo()
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
edm::ParameterSet SherpaParameterSet
#define DEFINE_FWK_MODULE(type)
bool initializeForInternalPartons()
void setRandomEngine(CLHEP::HepRandomEngine *v)
void resetEvent(std::unique_ptr< HepMC::GenEvent > event)
std::vector< std::string > variationweightlist
std::unique_ptr< HepMC::GenEvent > & event()
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
std::string SherpaResultDir
std::vector< std::string > arguments
SherpaHadronizer(const edm::ParameterSet ¶ms)
DECLARE_GETTER(CMS_SHERPA_RNG,"CMS_SHERPA_RNG", ATOOLS::External_RNG, ATOOLS::RNG_Key)
const char * classname() const
std::string SherpaChecksum