6 #include "GaudiKernel/MsgStream.h"
13 #include "ATOOLS/Org/CXXFLAGS_PACKAGES.H"
19 #include "SHERPA/Main/Sherpa.H"
20 #include "SHERPA/Initialization/Initialization_Handler.H"
22 #include "ATOOLS/Phys/Variations.H"
24 #include "SHERPA/Tools/Variations.H"
26 #include "ATOOLS/Org/Exception.H"
27 #include "ATOOLS/Org/Run_Parameter.H"
34 #include "CLHEP/Random/RandFlat.h"
50 if (m_plugincode !=
"") {
51 compilePlugin(m_plugincode);
53 m_params.value().push_back(
"SHERPA_LDADD=Sherpa_iPlugin");
69 if (m_plugincode !=
"") {
70 compilePlugin(m_plugincode);
72 m_inputfiles[
"Base.yaml"] +=
"SHERPA_LDADD: Sherpa_iPlugin \n";
74 m_params.value().push_back(
"SHERPA_LDADD=Sherpa_iPlugin");
79 p_rndEngine = getRandomEngineDuringInitialize(
"SHERPA", m_randomSeed, m_dsid);
84 m_inputfiles[
"Base.yaml"] +=
"\nEVT_OUTPUT: 0 \n";
87 m_inputfiles[
"Base.yaml"] +=
"\nEVT_OUTPUT: 2 \n";
90 m_inputfiles[
"Base.yaml"] +=
"\nEVT_OUTPUT: 15 \n";
93 m_inputfiles[
"Base.yaml"] +=
"\nEVT_OUTPUT: 15 \n";
108 char**
argv =
new char*[2];
109 argv[0] =
new char[7];
110 argv[1] =
new char[34];
111 strcpy(
argv[0],
"Sherpa");
112 strcpy(
argv[1],
"RUNDATA: [Base.yaml, Sherpa.yaml]");
113 p_sherpa =
new SHERPA::Sherpa(
argc,
argv);
116 p_sherpa =
new SHERPA::Sherpa();
123 std::set_terminate(ATOOLS::Terminate);
124 std::set_unexpected(ATOOLS::Terminate);
126 signal(SIGSEGV,ATOOLS::HandleSignal);
127 signal(SIGINT,ATOOLS::HandleSignal);
128 signal(SIGPIPE,ATOOLS::HandleSignal);
129 signal(SIGBUS,ATOOLS::HandleSignal);
130 signal(SIGFPE,ATOOLS::HandleSignal);
131 signal(SIGABRT,ATOOLS::HandleSignal);
132 signal(SIGTERM,ATOOLS::HandleSignal);
133 signal(SIGXCPU,ATOOLS::HandleSignal);
134 signal(SIGUSR1,ATOOLS::HandleSignal);
137 p_sherpa->InitializeTheRun();
138 p_sherpa->InitializeTheEventHandler();
140 catch (
const ATOOLS::normal_exit&
exception) {
144 return StatusCode::FAILURE;
146 catch (
const ATOOLS::Exception&
exception) {
149 return StatusCode::FAILURE;
152 signal(SIGSEGV,ATOOLS::SignalHandler);
153 signal(SIGINT,ATOOLS::SignalHandler);
154 signal(SIGBUS,ATOOLS::SignalHandler);
155 signal(SIGFPE,ATOOLS::SignalHandler);
156 signal(SIGABRT,ATOOLS::SignalHandler);
157 signal(SIGTERM,ATOOLS::SignalHandler);
158 signal(SIGXCPU,ATOOLS::SignalHandler);
164 p_sherpa->InitializeTheRun(
argc,(
char **)
argv);
167 p_sherpa->InitializeTheEventHandler();
169 catch (
const ATOOLS::Exception&
exception) {
170 if (
exception.Class()==
"Matrix_Element_Handler" &&
exception.Type()==ATOOLS::ex::normal_exit) {
178 return StatusCode::FAILURE;
183 return StatusCode::FAILURE;
187 m_runinfo = std::make_shared<HepMC3::GenRunInfo>();
189 struct HepMC3::GenRunInfo::ToolInfo
generator = {
190 std::string(
"SHERPA"),
191 std::string(SHERPA_VERSION)+
"." + std::string(SHERPA_SUBVERSION),
192 std::string(
"Used generator")
196 return StatusCode::SUCCESS;
204 const EventContext& ctx = Gaudi::Hive::currentContext();
210 }
while (p_sherpa->GenerateOneEvent()==
false);
212 const size_t genEvents = ATOOLS::rpa->gen.NumberOfGeneratedEvents();
213 if (genEvents%1000==0) {
217 return StatusCode::SUCCESS;
223 if (!
event->run_info())
event->set_run_info(m_runinfo);
225 p_sherpa->FillHepMCEvent(*
event);
230 if (
event->weights().size()>2) {
231 double nominal =
event->weight(
"Weight");
232 for (
const auto&
name:
event->weight_names()) {
233 if (
name ==
"WeightNormalisation")
continue;
234 if (
name ==
"NTrials")
continue;
235 if (
name ==
"Weight")
continue;
236 if (
name ==
"NTrials")
continue;
237 if (std::abs(
event->weight(
name)) > m_variation_weight_cap*std::abs(nominal)) {
239 event->weight(
name) *= m_variation_weight_cap*std::abs(nominal)/std::abs(
event->weight(
name));
245 if (
event->weights().size()>2) {
246 for (
size_t i=0;
i<
event->weights().
size(); ++
i) {
249 if (std::abs(
event->weights()[
i]) > m_variation_weight_cap*std::abs(
event->weights()[0])) {
251 event->weights()[
i] *= m_variation_weight_cap*std::abs(
event->weights()[0])/std::abs(
event->weights()[
i]);
266 return StatusCode::SUCCESS;
273 std::cout <<
"MetaData: generator = Sherpa" << SHERPA_VERSION <<
"." << SHERPA_SUBVERSION << std::endl;
274 std::cout <<
"MetaData: cross-section (nb)= " << p_sherpa->TotalXS()/1000.0*m_xsscale << std::endl;
276 std::cout <<
"MetaData: PDF = " << p_sherpa->PDFInfo() << std::endl;
278 std::cout <<
"Named variations initialised by Sherpa:" << std::endl;
279 std::cout << *p_sherpa->GetInitHandler()->GetVariations() << std::endl;
281 p_sherpa->SummarizeRun();
285 ATH_MSG_INFO(
"Deleting left-over files from working directory.");
286 system(
"rm -rf Results.db Process MIG_*.db MPI_*.dat libSherpa*.so libProc*.so");
289 return StatusCode::SUCCESS;
295 std::vector<std::string>
params;
298 params.push_back(
"EXTERNAL_RNG=Atlas_RNG");
304 std::string verbose_arg;
307 params.push_back(
"OUTPUT=0");
309 else if(
log.level()==MSG::INFO){
310 params.push_back(
"OUTPUT=2");
313 params.push_back(
"OUTPUT=3");
316 params.push_back(
"OUTPUT=15");
320 if (m_runcard !=
"") m_params.value().push_back(
"RUNDATA=Run.dat");
326 if (m_runcard !=
"") {
327 FILE *
file = fopen(
"Run.dat",
"w");
328 fputs(m_runcard.value().c_str(),
file);
337 argv[0] =
new char[7];
338 strcpy(
argv[0],
"Sherpa");
348 ATH_MSG_INFO(
"Further Sherpa initialisation output will be redirected to the LOG_FILE specified above.");
355 FILE *
file = fopen(
"Sherpa_iPlugin.C",
"w");
356 fputs(pluginCode.c_str(),
file);
362 command +=
"tail -n +2 Sherpa_iPlugin.C | head -n -1 > Sherpa_iPlugin.C.tmp; mv Sherpa_iPlugin.C.tmp Sherpa_iPlugin.C; ";
363 command +=
"g++ -shared -std=c++0x -g ";
364 command +=
"-I`Sherpa-config --incdir` ";
365 command +=
"`Sherpa-config --ldflags` ";
366 command +=
"-I$FASTJETPATH/include ";
367 command +=
"-fPIC -o libSherpa_iPlugin.so Sherpa_iPlugin.C";
369 if (system(
command.c_str())!=0) {
380 External_RNG(), p_engine(engine), m_filename(
"Config.conf")
383 char alphabet[nMax] = {
'a',
'b',
'c',
'd',
'e',
'f',
'g',
384 'h',
'i',
'j',
'k',
'l',
'm',
'n',
385 'o',
'p',
'q',
'r',
's',
't',
'u',
386 'v',
'w',
'x',
'y',
'z' };
391 for (
size_t i = 0;
i < 6; ++
i)
394 std::cout <<
"RNG state being saved to: " <<
m_filename << std::endl;
401 return CLHEP::RandFlat::shoot(
p_engine);
412 DECLARE_GETTER(
Atlas_RNG,
"Atlas_RNG",External_RNG,RNG_Key);
415 template <>
class Getter<External_RNG,RNG_Key,
Atlas_RNG,std::
less<std::string>>:
416 public Getter_Function<External_RNG,RNG_Key,std::less<std::string>> {
418 static Getter<External_RNG,RNG_Key,Atlas_RNG,std::less<std::string>>
s_initializer;
424 Getter_Function<External_RNG,RNG_Key,std::
less<std::string>>(
"Atlas_RNG")
428 ATOOLS::Getter<External_RNG,RNG_Key,Atlas_RNG>
429 ATOOLS::Getter<External_RNG,RNG_Key,Atlas_RNG>::s_initializer(
true);
432 External_RNG *ATOOLS::Getter<External_RNG,RNG_Key,Atlas_RNG>::operator()(
const RNG_Key &)
const
435 void ATOOLS::Getter<External_RNG,RNG_Key,Atlas_RNG>::PrintInfo(std::ostream &
str,
const size_t)
const
436 {
str<<
"Atlas RNG interface"; }