ATLAS Offline Software
Loading...
Searching...
No Matches
Sherpa_i Class Reference

#include <Sherpa_i.h>

Inheritance diagram for Sherpa_i:
Collaboration diagram for Sherpa_i:

Public Member Functions

 Sherpa_i (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode genInitialize ()
 For initializing the generator, if required.
StatusCode callGenerator ()
 For calling the generator on each iteration of the event loop.
StatusCode genFinalize ()
 For finalising the generator, if required.
StatusCode fillEvt (HepMC::GenEvent *evt)
 For filling the HepMC event object.
void getParameters (int &argc, char **&argv)
void compilePlugin (const std::string &)
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Event loop algorithm methods: not to be overloaded
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()
Gen-specific event loop methods: to be overloaded
virtual StatusCode genuserInitialize ()
 For initialization of user code, if required. Called after genInitialize.
Event collection accessors (const and non-const)
HepMC::GenEvent *event ATLAS_NOT_CONST_THREAD_SAFE ()
 Access the current signal event (first in the McEventCollection)
McEventCollection *events ATLAS_NOT_CONST_THREAD_SAFE ()
 Access the current event's McEventCollection.
const HepMC::GenEvent * event_const () const
 Access the current signal event (const)
const McEventCollectionevents_const () const
 Access the current event's McEventCollection (const)
const McEventCollectionevents_const (const EventContext &ctx) const
Particle data accessors
const ServiceHandle< IPartPropSvc > partPropSvc () const
 Access the particle property service.
const HepPDT::ParticleDataTable & particleTable () const
 Get a particle data table.
const HepPDT::ParticleDataTable & pdt () const
 Shorter alias to get a particle data table.
const HepPDT::ParticleData * particleData (int pid) const
 Access an element in the particle data table.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

SHERPA::Sherpa * p_sherpa {}
std::string m_basefragment
 Sherpa base settings (read from base fragment file)
StringProperty m_runcard {this, "RunCard", ""}
 FIXME unused?
StringArrayProperty m_params {this, "Parameters", {} }
 List of additional Sherpa parameters beyond run card snippet (from JO file)
StringArrayProperty m_openloopslibs {this, "OpenLoopsLibs", {} }
 List of needed OpenLoops process libraries (from JO file)
StringArrayProperty m_extrafiles {this, "ExtraFiles", {} }
 List of any additional needed files, e.g. custom libraries, PDF sets (from JO file)
IntegerProperty m_ncores {this, "NCores", 1}
 Number of cores recommended for multi-core integration file.
DoubleProperty m_memorymb {this, "MemoryMB", 2500.}
 Memory required for integration/evgen.
StringProperty m_plugincode {this, "PluginCode", ""}
 Optional code for plugin library to compile and load at run time.
DoubleProperty m_variation_weight_cap {this, "VariationWeightCap", 10.0}
 Variation weight cap factor.
DoubleProperty m_xsscale {this, "CrossSectionScaleFactor", 1.0}
BooleanProperty m_cleanup {this, "CleanupGeneratedFiles", true}
IntegerProperty m_dsid {this, "Dsid", 999999, "Dataset ID number"}

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

DataObjIDColl m_extendedExtraObjects
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Features for derived classes to use internally

IntegerProperty m_randomSeed {this, "RandomSeed", 1234567, "Random seed for the built-in random engine"}
 Seed for random number engine.
BooleanProperty m_isAfterburner {this, "IsAfterburner", false, "Set true if generator modifies existing events rather than creating new ones"}
 Flag for normal vs. afterburner generators.
ServiceHandle< IAthRNGSvcm_rndmSvc {this, "RndmSvc", "AthRNGSvc"}
 Data members.
ServiceHandle< IIncidentSvc > m_incidentSvc {this, "IncidentSvc", "IncidentSvc"}
 Handle on the incident service.
CLHEP::HepRandomEngine * getRandomEngine (const std::string &streamName, const EventContext &ctx) const
CLHEP::HepRandomEngine * getRandomEngine (const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize (const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const

Properties

std::string m_mcEventKey {}
 StoreGate key for the MC event collection (defaults to GEN_EVENT)
BooleanProperty m_mkMcEvent {this, "MakeMcEvent", false, "Create a new MC event collection if it doesn't exist"}
 Flag to determine if a new MC event collection should be made if it doesn't exist.
ServiceHandle< IPartPropSvc > m_ppSvc {this, "PartPropSvc", "PartPropSvc"}
 Handle on the particle property service.
SG::ReadHandleKey< McEventCollectionm_mcevents_const { this, "McEventKey", "GEN_EVENT", "StoreGate key of the MC event collection" }
 Const handle to the MC event collection.

Detailed Description

Definition at line 18 of file Sherpa_i.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ Sherpa_i()

Sherpa_i::Sherpa_i ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 41 of file Sherpa_i.cxx.

42 : GenModule(name, pSvcLocator)
43{
44 #ifdef IS_SHERPA_3
45 declareProperty("BaseFragment", m_inputfiles["Base.yaml"] = "");
46 declareProperty("RunCard", m_inputfiles["Sherpa.yaml"] = "");
47 #endif
48}
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
GenModule(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenModule.cxx:14

Member Function Documentation

◆ ATLAS_NOT_CONST_THREAD_SAFE() [1/2]

HepMC::GenEvent *event GenBase::ATLAS_NOT_CONST_THREAD_SAFE ( )
inlineinherited

Access the current signal event (first in the McEventCollection)

Note
This function will make a new McEventCollection if there is not already a valid one and MakeMcEvent=True.

Definition at line 76 of file GenBase.h.

76 {
77 if (events()->empty())
78 ATH_MSG_ERROR("McEventCollection is empty during first event access");
79 return *(events()->begin());
80 }
#define ATH_MSG_ERROR(x)
static const Attributes_t empty

◆ ATLAS_NOT_CONST_THREAD_SAFE() [2/2]

McEventCollection *events GenBase::ATLAS_NOT_CONST_THREAD_SAFE ( )
inherited

Access the current event's McEventCollection.

Note
This function will make a new McEventCollection if there is not already a valid one and MakeMcEvent=True.

◆ callGenerator()

StatusCode Sherpa_i::callGenerator ( )
virtual

For calling the generator on each iteration of the event loop.

Reimplemented from GenModule.

Definition at line 186 of file Sherpa_i.cxx.

186 {
187 ATH_MSG_DEBUG("Sherpa_i in callGenerator()");
188 //Re-seed the random number stream
189 long seeds[7];
190 const EventContext& ctx = Gaudi::Hive::currentContext();
191 ATHRNG::calculateSeedsMC21(seeds, "SHERPA", ctx.eventID().event_number(), m_dsid, m_randomSeed);
192 p_rndEngine->setSeeds(seeds, 0); // NOT THREAD-SAFE
193
194 do {
195 ATH_MSG_DEBUG("Trying to generate event with Sherpa");
196 } while (p_sherpa->GenerateOneEvent()==false);
197
198 const size_t genEvents = ATOOLS::rpa->gen.NumberOfGeneratedEvents();
199 if (genEvents%1000==0) {
200 ATH_MSG_INFO("Passed "<<genEvents<<" events.");
201 }
202
203 return StatusCode::SUCCESS;
204}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
CLHEP::HepRandomEngine * p_rndEngine
Definition Sherpa_i.cxx:39
IntegerProperty m_randomSeed
Seed for random number engine.
Definition GenModule.h:84
SHERPA::Sherpa * p_sherpa
Definition Sherpa_i.h:32
IntegerProperty m_dsid
Definition Sherpa_i.h:70
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.

◆ compilePlugin()

void Sherpa_i::compilePlugin ( const std::string & pluginCode)

Definition at line 343 of file Sherpa_i.cxx.

343 {
344 // TODO: not very pretty, should we eventually do this in Python instead (base fragment)
345 FILE *file = fopen("Sherpa_iPlugin.C","w");
346 if (!file) {
347 ATH_MSG_ERROR("Cannot open Sherpa_iPlugin.C");
348 }
349 else {
350 fputs(pluginCode.c_str(),file);
351 fclose(file);
352 }
353 std::string command;
354 // Python -> C++ string conversion seems to add quote character as first
355 // and last line if the string contains quotes (like always in a plugin)
356 // thus removing them here
357 command += "tail -n +2 Sherpa_iPlugin.C | head -n -1 > Sherpa_iPlugin.C.tmp; mv Sherpa_iPlugin.C.tmp Sherpa_iPlugin.C; ";
358 command += "g++ -shared -std=c++0x -g ";
359 command += "-I`Sherpa-config --incdir` ";
360 command += "`Sherpa-config --ldflags` ";
361 command += "-I$FASTJETPATH/include ";
362 command += "-fPIC -o libSherpa_iPlugin.so Sherpa_iPlugin.C";
363 ATH_MSG_INFO("Now compiling plugin library using: "+command);
364 if (system(command.c_str())!=0) {
365 ATH_MSG_ERROR("Error compiling plugin library.");
366 }
367}
TFile * file

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ event_const()

const HepMC::GenEvent * GenBase::event_const ( ) const
inlineinherited

Access the current signal event (const)

Definition at line 83 of file GenBase.h.

83 {
84 if (events_const()->empty())
85 ATH_MSG_ERROR("Const McEventCollection is empty during first event access");
86 return *(events_const()->begin());
87 }
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const McEventCollection * events_const() const
Access the current event's McEventCollection (const)
Definition GenBase.h:96

◆ events_const() [1/2]

const McEventCollection * GenBase::events_const ( ) const
inlineinherited

Access the current event's McEventCollection (const)

Definition at line 96 of file GenBase.h.

96 {
97 return events_const( getContext() );
98 }

◆ events_const() [2/2]

const McEventCollection * GenBase::events_const ( const EventContext & ctx) const
inlineinherited

Definition at line 99 of file GenBase.h.

99 {
100 SG::ReadHandle<McEventCollection> ret = SG::makeHandle(m_mcevents_const, ctx);
101 if (!ret.isValid())
102 ATH_MSG_ERROR("No McEventCollection found in StoreGate with key " << m_mcevents_const.key());
103 return ret.cptr();
104 }
SG::ReadHandleKey< McEventCollection > m_mcevents_const
Const handle to the MC event collection.
Definition GenBase.h:147
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode GenModule::execute ( )
virtualinherited
Todo
Remove hard-coded alg name checking (already incomplete)

Reimplemented from GenBase.

Definition at line 70 of file GenModule.cxx.

70 {
71 // Examples of how to retrieve the random number engine for a given
72 // stream.
73 // NB getRandomEngine should only be called once per event for a
74 // given stream, as it causes the stream to be re-seeded each time
75 // it is called.
76
77 // Example 1 - seeded based on the current event number (+ slot, run, streamName)
78 //const EventContext& ctx = Gaudi::Hive::currentContext();
79 //CLHEP::HepRandomEngine* rndmEngine = this->getRandomEngine("MyStream", ctx);
80
81 // Example 2 - seeded based on the m_randomSeed property (+ slot, run, streamName)
82 //const EventContext& ctx = Gaudi::Hive::currentContext();
83 //CLHEP::HepRandomEngine* rndmEngine = this->getRandomEngine("MyStream", m_randomSeed.value(), ctx);
84
85 // Call the code that generates an event
86 CHECK(this->callGenerator());
87
88 // Create the MC event and send the GeneratorEvent stored in it to fillEvt
89 HepMC::GenEvent* evt = HepMC::newGenEvent(1,1);
90 CHECK(this->fillEvt(evt));
92
93 // Add the event to the MC event collection
94 if (events()) {
95 // If this is an "afterburner" generator, replace the last event rather than add a new one
97 if (m_isAfterburner.value() || name() == "Tauola" || name() == "Photos") {
98 events()->pop_back();
99 }
100 // Add the event to the end of the collection
101 events()->push_back(evt);
102 ATH_MSG_DEBUG("MC event added to McEventCollection");
103
104 // remove the empty event in case of ParticleDecayer
105 if (name() == "ParticleDecayer") {
106 events()->pop_back();
107 }
108 }
109
110 // Call the incident service to notify that an event has been made
111 m_incidentSvc->fireIncident( Incident(name(), "McEventGenerated") );
112 return StatusCode::SUCCESS;
113}
#define CHECK(...)
Evaluate an expression and check for errors.
ServiceHandle< IIncidentSvc > m_incidentSvc
Handle on the incident service.
Definition GenModule.h:101
virtual StatusCode callGenerator()
For calling the generator on each iteration of the event loop.
Definition GenModule.h:66
virtual StatusCode fillEvt(HepMC::GenEvent *evt)=0
For filling the HepMC event object.
BooleanProperty m_isAfterburner
Flag for normal vs. afterburner generators.
Definition GenModule.h:87
void fillBarcodesAttribute(GenEvent *)
Definition GenEvent.h:626
GenEvent * newGenEvent(const int a, const int b)
Definition GenEvent.h:624

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}
DataObjIDColl m_extendedExtraObjects

◆ fillEvt()

StatusCode Sherpa_i::fillEvt ( HepMC::GenEvent * evt)
virtual

For filling the HepMC event object.

Implements GenModule.

Definition at line 206 of file Sherpa_i.cxx.

206 {
207 ATH_MSG_DEBUG( "Sherpa_i Filling event");
208#ifdef HEPMC3
209 if (!event->run_info()) event->set_run_info(m_runinfo);
210#endif
211 p_sherpa->FillHepMCEvent(*event);
212
213
214#ifdef HEPMC3
215//Weight, MEWeight, WeightNormalisation, NTrials
216 if (event->weights().size()>2) {
217 double nominal = event->weight("Weight");
218 for (const auto& name: event->weight_names()) {
219 if (name == "WeightNormalisation") continue;
220 if (name == "NTrials") continue;
221 if (name == "Weight") continue;
222 if (name == "NTrials") continue;
223 if (std::abs(event->weight(name)) > m_variation_weight_cap*std::abs(nominal)) {
224 ATH_MSG_INFO("Capping variation" << name << " = " << event->weight(name)/nominal << "*nominal");
225 event->weight(name) *= m_variation_weight_cap*std::abs(nominal)/std::abs(event->weight(name));
226 }
227 ATH_MSG_DEBUG("Sherpa WEIGHT " << name << " value="<< event->weight(name));
228 }
229 }
230#else
231 if (event->weights().size()>2) {
232 for (size_t i=0; i<event->weights().size(); ++i) {
233 if (i>3) { // cap variation weights
234 // cap variation weights at m_variation_weight_cap*nominal to avoid spikes from numerical instability
235 if (std::abs(event->weights()[i]) > m_variation_weight_cap*std::abs(event->weights()[0])) {
236 ATH_MSG_INFO("Capping variation" << i << " = " << event->weights()[i]/event->weights()[0] << "*nominal");
237 event->weights()[i] *= m_variation_weight_cap*std::abs(event->weights()[0])/std::abs(event->weights()[i]);
238 }
239 }
240 ATH_MSG_DEBUG("Sherpa WEIGHT " << i << " value="<< event->weights()[i]);
241 }
242 }
243#endif
244
245#ifdef HEPMC3
246 event->set_units(HepMC3::Units::MEV, HepMC3::Units::MM);
247#else
248 MC::GeVToMeV(event); //Only scales momenta and masses
249#endif
250
251
252 return StatusCode::SUCCESS;
253}
DoubleProperty m_variation_weight_cap
Variation weight cap factor.
Definition Sherpa_i.h:64
void GeVToMeV(HepMC::GenEvent *evt)

◆ finalize()

StatusCode GenModule::finalize ( )
inlineinherited

Definition at line 55 of file GenModule.h.

55{ return genFinalize(); }
virtual StatusCode genFinalize()
For finalising the generator, if required.
Definition GenModule.h:70

◆ genFinalize()

StatusCode Sherpa_i::genFinalize ( )
virtual

For finalising the generator, if required.

Reimplemented from GenModule.

Definition at line 255 of file Sherpa_i.cxx.

255 {
256
257 ATH_MSG_INFO("Sherpa_i finalize()");
258
259 std::cout << "MetaData: generator = Sherpa" << SHERPA_VERSION << "." << SHERPA_SUBVERSION << std::endl;
260 std::cout << "MetaData: cross-section (nb)= " << p_sherpa->TotalXS()/1000.0*m_xsscale << std::endl;
261
262 std::cout << "MetaData: PDF = " << p_sherpa->PDFInfo() << std::endl;
263
264 std::cout << "Named variations initialised by Sherpa:" << std::endl;
265 std::cout << *p_sherpa->GetInitHandler()->GetVariations() << std::endl;
266
267 p_sherpa->SummarizeRun();
268
269 if (m_cleanup) {
270 ATH_MSG_INFO("Deleting left-over files from working directory.");
271 system("rm -rf Results.db Process MIG_*.db MPI_*.dat libSherpa*.so libProc*.so");
272 }
273
274 return StatusCode::SUCCESS;
275}
BooleanProperty m_cleanup
Definition Sherpa_i.h:67
DoubleProperty m_xsscale
Definition Sherpa_i.h:66

◆ genInitialize()

StatusCode Sherpa_i::genInitialize ( )
virtual

For initializing the generator, if required.

Reimplemented from GenModule.

Definition at line 52 of file Sherpa_i.cxx.

52 {
53 if (m_plugincode != "") {
55 #ifndef IS_SHERPA_3
56 m_params.value().push_back("SHERPA_LDADD=Sherpa_iPlugin");
57 #endif
58 }
59
60 ATH_MSG_INFO("Sherpa initialising...");
61
62 #ifdef IS_SHERPA_3
63 for (auto& inputfile : m_inputfiles) {
64 // remove first line and last character containing '"'
65 // TODO fix Python/C++ string passing, to not contain " in first place
66 inputfile.second.erase(0, inputfile.second.find("\n") + 1);
67 inputfile.second.pop_back();
68 }
69 #endif
70
71 ATH_MSG_DEBUG("... compiling plugin code");
72 if (m_plugincode != "") {
74 #ifdef IS_SHERPA_3
75 m_inputfiles["Base.yaml"] += "SHERPA_LDADD: Sherpa_iPlugin \n";
76 #else
77 m_params.value().push_back("SHERPA_LDADD=Sherpa_iPlugin");
78 #endif
79 }
80
81 ATH_MSG_DEBUG("... seeding Athena random number generator");
82 p_rndEngine = getRandomEngineDuringInitialize("SHERPA", m_randomSeed, m_dsid); // NOT THREAD-SAFE
83
84 #ifdef IS_SHERPA_3
85 ATH_MSG_DEBUG("... adapting output level");
86 if( msg().level()==MSG::FATAL || msg().level()==MSG::ERROR || msg().level()==MSG::WARNING ){
87 m_inputfiles["Base.yaml"] += "\nEVT_OUTPUT: 0 \n";
88 }
89 else if(msg().level()==MSG::INFO){
90 m_inputfiles["Base.yaml"] += "\nEVT_OUTPUT: 2 \n";
91 }
92 else if(msg().level()==MSG::DEBUG){
93 m_inputfiles["Base.yaml"] += "\nEVT_OUTPUT: 15 \n";
94 }
95 else{
96 m_inputfiles["Base.yaml"] += "\nEVT_OUTPUT: 15 \n";
97 }
98
99 ATH_MSG_DEBUG("... writing input files to directory");
100 for (auto& inputfile : m_inputfiles) {
101 // write input content to file in working directory
102 FILE *file = fopen(inputfile.first.c_str(),"w");
103 if (!file) {
104 ATH_MSG_ERROR("Cannot open " << inputfile.first);
105 return StatusCode::FAILURE;
106 }
107 fputs(inputfile.second.c_str(),file);
108 fclose(file);
109 ATH_MSG_INFO("Sherpa_i using the following settings in "+inputfile.first);
110 ATH_MSG_INFO("\n"+inputfile.second+"\n");
111 }
112
113 ATH_MSG_DEBUG("... go Sherpa!");
114 int argc = 2;
115 char** argv = new char*[2];
116 argv[0] = new char[7];
117 argv[1] = new char[34];
118 strcpy(argv[0], "Sherpa");
119 strcpy(argv[1], "RUNDATA: [Base.yaml, Sherpa.yaml]");
120 p_sherpa = new SHERPA::Sherpa(argc, argv);
121 delete [] argv;
122 #else
123 p_sherpa = new SHERPA::Sherpa();
124 #endif
125
126
127 #ifdef IS_SHERPA_3
128
129 try {
130 p_sherpa->InitializeTheRun();
131 p_sherpa->InitializeTheEventHandler();
132 }
133 catch (const ATOOLS::normal_exit& exception) {
134 ATH_MSG_ERROR("Normal exit caught, this probably means:");
135 ATH_MSG_ERROR("Have to compile Amegic libraries");
136 ATH_MSG_ERROR("You probably want to run ./makelibs");
137 return StatusCode::FAILURE;
138 }
139 catch (const ATOOLS::Exception& exception) {
140 ATH_MSG_ERROR("Unwanted ATOOLS::exception caught.");
141 ATH_MSG_ERROR(exception);
142 return StatusCode::FAILURE;
143 }
144 #else
145
146 try {
147 int argc;
148 char** argv;
149 getParameters(argc, argv);
150 p_sherpa->InitializeTheRun(argc,(char **)argv);
151 delete [] argv;
152
153 p_sherpa->InitializeTheEventHandler();
154 }
155 catch (const ATOOLS::Exception& exception) {
156 if (exception.Class()=="Matrix_Element_Handler" && exception.Type()==ATOOLS::ex::normal_exit) {
157 ATH_MSG_ERROR("Have to compile Amegic libraries");
158 ATH_MSG_ERROR("You probably want to run ./makelibs");
159 }
160 else {
161 ATH_MSG_ERROR("Unwanted ATOOLS::exception caught.");
162 ATH_MSG_ERROR(exception);
163 }
164 return StatusCode::FAILURE;
165 }
166 #endif
167 catch (const std::exception& exception) {
168 ATH_MSG_ERROR("std::exception caught.");
169 return StatusCode::FAILURE;
170 }
171
172 #ifdef HEPMC3
173 m_runinfo = std::make_shared<HepMC3::GenRunInfo>();
175 struct HepMC3::GenRunInfo::ToolInfo generator = {
176 std::string("SHERPA"),
177 std::string(SHERPA_VERSION)+ "." + std::string(SHERPA_SUBVERSION),
178 std::string("Used generator")
179 };
180 m_runinfo->tools().push_back(std::move(generator));
181 #endif
182 return StatusCode::SUCCESS;
183}
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
Definition GenModule.cxx:53
StringProperty m_plugincode
Optional code for plugin library to compile and load at run time.
Definition Sherpa_i.h:61
StringArrayProperty m_params
List of additional Sherpa parameters beyond run card snippet (from JO file)
Definition Sherpa_i.h:45
void compilePlugin(const std::string &)
Definition Sherpa_i.cxx:343
void getParameters(int &argc, char **&argv)
Definition Sherpa_i.cxx:279
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...
MsgStream & msg
Definition testRead.cxx:32

◆ genuserInitialize()

virtual StatusCode GenModule::genuserInitialize ( )
inlinevirtualinherited

For initialization of user code, if required. Called after genInitialize.

Reimplemented in Pythia8B_i.

Definition at line 64 of file GenModule.h.

64{ return StatusCode::SUCCESS; }

◆ getParameters()

void Sherpa_i::getParameters ( int & argc,
char **& argv )

Definition at line 279 of file Sherpa_i.cxx.

279 {
280 std::vector<std::string> params;
281
282 // set some ATLAS specific default values as a starting point
283 params.push_back("EXTERNAL_RNG=Atlas_RNG");
284
285 /***
286 Adopt Atlas Debug Level Scheme
287 ***/
288
289 std::string verbose_arg;
290 MsgStream log(msgSvc(), name());
291 if( log.level()==MSG::FATAL || log.level()==MSG::ERROR || log.level()==MSG::WARNING ){
292 params.push_back("OUTPUT=0");
293 }
294 else if(log.level()==MSG::INFO){
295 params.push_back("OUTPUT=2");
296 }
297 else if(log.level()==MSG::DEBUG){
298 params.push_back("OUTPUT=3");
299 }
300 else{
301 params.push_back("OUTPUT=15");
302 }
303
304 // disregard manual RUNDATA setting if run card given in JO
305 if (m_runcard != "") m_params.value().push_back("RUNDATA=Run.dat");
306
307 // allow to overwrite all parameters from JO file
308 params.insert(params.begin()+params.size(), m_params.begin(), m_params.end());
309
310 // create Run.dat file if runcard explicitely given
311 if (m_runcard != "") {
312 FILE *file = fopen("Run.dat","w");
313 if (!file) {
314 ATH_MSG_ERROR("Cannot open Run.dat");
315 }
316 else {
317 fputs(m_runcard.value().c_str(),file);
318 fclose(file);
319 }
320 }
321
322 /***
323 Convert into Sherpas argc/argv arguments
324 ***/
325 argc = 1+params.size();
326 argv = new char * [ 1+params.size() ];
327 argv[0] = new char[7];
328 strcpy(argv[0], "Sherpa");
329
330 ATH_MSG_INFO("Sherpa_i using the following Arguments");
332 for(size_t i=0; i<params.size(); i++) {
333 ATH_MSG_INFO(" [ " << params[i] << " ] ");
334 argv[i+1] = new char[params[i].size()+1];
335 strcpy(argv[i+1], params[i].c_str());
336 }
337 ATH_MSG_INFO("End Sherpa_i Argument List");
338 ATH_MSG_INFO("Further Sherpa initialisation output will be redirected to the LOG_FILE specified above.");
339
340}
StringProperty m_runcard
FIXME unused?
Definition Sherpa_i.h:42

◆ getRandomEngine() [1/2]

CLHEP::HepRandomEngine * GenModule::getRandomEngine ( const std::string & streamName,
const EventContext & ctx ) const
protectedinherited

Definition at line 34 of file GenModule.cxx.

36{
37 ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
38 std::string rngName = name()+streamName;
39 rngWrapper->setSeed( rngName, ctx );
40 return rngWrapper->getEngine(ctx);
41}
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
ServiceHandle< IAthRNGSvc > m_rndmSvc
Data members.
Definition GenModule.h:99

◆ getRandomEngine() [2/2]

CLHEP::HepRandomEngine * GenModule::getRandomEngine ( const std::string & streamName,
unsigned long int randomSeedOffset,
const EventContext & ctx ) const
protectedinherited

Definition at line 44 of file GenModule.cxx.

46{
47 ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
48 rngWrapper->setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
49 return rngWrapper->getEngine(ctx);
50}

◆ getRandomEngineDuringInitialize()

CLHEP::HepRandomEngine * GenModule::getRandomEngineDuringInitialize ( const std::string & streamName,
unsigned long int randomSeedOffset,
unsigned int conditionsRun = 1,
unsigned int lbn = 1 ) const
protectedinherited

Definition at line 53 of file GenModule.cxx.

54{
55 const size_t slot=0;
56 EventContext ctx;
57 ctx.setSlot( slot );
58 ctx.setEventID (EventIDBase (conditionsRun,
59 EventIDBase::UNDEFEVT, // event
60 EventIDBase::UNDEFNUM, // timestamp
61 EventIDBase::UNDEFNUM, // timestamp ns
62 lbn));
64 Atlas::ExtendedEventContext( evtStore()->hiveProxyDict(),
65 conditionsRun) );
66 return getRandomEngine(streamName, randomSeedOffset, ctx);
67}
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, const EventContext &ctx) const
Definition GenModule.cxx:34
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.

◆ initialize()

StatusCode GenModule::initialize ( )
virtualinherited

Reimplemented from GenBase.

Definition at line 21 of file GenModule.cxx.

21 {
22 // Base class initializations
24 // Get the random number service
25 CHECK(m_rndmSvc.retrieve());
26 // Get the incident service
27 CHECK(m_incidentSvc.retrieve());
30 return StatusCode::SUCCESS;
31}
virtual StatusCode initialize() override
Definition GenBase.cxx:17
virtual StatusCode genuserInitialize()
For initialization of user code, if required. Called after genInitialize.
Definition GenModule.h:64
virtual StatusCode genInitialize()
For initializing the generator, if required.
Definition GenModule.h:62

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ particleData()

const HepPDT::ParticleData * GenBase::particleData ( int pid) const
inlineinherited

Access an element in the particle data table.

Definition at line 126 of file GenBase.h.

126 {
127 return pdt().particle(HepPDT::ParticleID(std::abs(pid)));
128 }
const HepPDT::ParticleDataTable & pdt() const
Shorter alias to get a particle data table.
Definition GenBase.h:123

◆ particleTable()

const HepPDT::ParticleDataTable & GenBase::particleTable ( ) const
inlineinherited

Get a particle data table.

Definition at line 118 of file GenBase.h.

118 {
119 return *(m_ppSvc->PDT());
120 }
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition GenBase.h:144

◆ partPropSvc()

const ServiceHandle< IPartPropSvc > GenBase::partPropSvc ( ) const
inlineinherited

Access the particle property service.

Definition at line 113 of file GenBase.h.

113 {
114 return m_ppSvc;
115 }

◆ pdt()

const HepPDT::ParticleDataTable & GenBase::pdt ( ) const
inlineinherited

Shorter alias to get a particle data table.

Definition at line 123 of file GenBase.h.

123{ return particleTable(); }
const HepPDT::ParticleDataTable & particleTable() const
Get a particle data table.
Definition GenBase.h:118

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, and PyAthena::Alg.

Definition at line 66 of file AthAlgorithm.cxx.

66 {
68
69 if (sc.isFailure()) {
70 return sc;
71 }
72 ServiceHandle<ICondSvc> cs("CondSvc",name());
73 for (auto h : outputHandles()) {
74 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75 // do this inside the loop so we don't create the CondSvc until needed
76 if ( cs.retrieve().isFailure() ) {
77 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78 return StatusCode::SUCCESS;
79 }
80 if (cs->regHandle(this,*h).isFailure()) {
81 sc = StatusCode::FAILURE;
82 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83 << " with CondSvc");
84 }
85 }
86 }
87 return sc;
88}
#define ATH_MSG_WARNING(x)
static Double_t sc
virtual StatusCode sysInitialize() override
Override sysInitialize.
AthCommonDataStore(const std::string &name, T... args)
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_basefragment

std::string Sherpa_i::m_basefragment
protected

Sherpa base settings (read from base fragment file)

Definition at line 39 of file Sherpa_i.h.

◆ m_cleanup

BooleanProperty Sherpa_i::m_cleanup {this, "CleanupGeneratedFiles", true}
protected

Definition at line 67 of file Sherpa_i.h.

67{this, "CleanupGeneratedFiles", true};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_dsid

IntegerProperty Sherpa_i::m_dsid {this, "Dsid", 999999, "Dataset ID number"}
protected

Definition at line 70 of file Sherpa_i.h.

70{this, "Dsid", 999999, "Dataset ID number"};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_extrafiles

StringArrayProperty Sherpa_i::m_extrafiles {this, "ExtraFiles", {} }
protected

List of any additional needed files, e.g. custom libraries, PDF sets (from JO file)

Definition at line 52 of file Sherpa_i.h.

52{this, "ExtraFiles", {} };

◆ m_incidentSvc

ServiceHandle<IIncidentSvc> GenModule::m_incidentSvc {this, "IncidentSvc", "IncidentSvc"}
privateinherited

Handle on the incident service.

Definition at line 101 of file GenModule.h.

101{this, "IncidentSvc", "IncidentSvc"};

◆ m_isAfterburner

BooleanProperty GenModule::m_isAfterburner {this, "IsAfterburner", false, "Set true if generator modifies existing events rather than creating new ones"}
protectedinherited

Flag for normal vs. afterburner generators.

Definition at line 87 of file GenModule.h.

87{this, "IsAfterburner", false, "Set true if generator modifies existing events rather than creating new ones"};

◆ m_mcEventKey

std::string GenBase::m_mcEventKey {}
protectedinherited

StoreGate key for the MC event collection (defaults to GEN_EVENT)

Definition at line 136 of file GenBase.h.

136{};

◆ m_mcevents_const

SG::ReadHandleKey<McEventCollection> GenBase::m_mcevents_const { this, "McEventKey", "GEN_EVENT", "StoreGate key of the MC event collection" }
privateinherited

Const handle to the MC event collection.

Definition at line 147 of file GenBase.h.

147{ this, "McEventKey", "GEN_EVENT", "StoreGate key of the MC event collection" };

◆ m_memorymb

DoubleProperty Sherpa_i::m_memorymb {this, "MemoryMB", 2500.}
protected

Memory required for integration/evgen.

Definition at line 58 of file Sherpa_i.h.

58{this, "MemoryMB", 2500.};

◆ m_mkMcEvent

BooleanProperty GenBase::m_mkMcEvent {this, "MakeMcEvent", false, "Create a new MC event collection if it doesn't exist"}
protectedinherited

Flag to determine if a new MC event collection should be made if it doesn't exist.

Definition at line 138 of file GenBase.h.

138{this, "MakeMcEvent", false, "Create a new MC event collection if it doesn't exist"};

◆ m_ncores

IntegerProperty Sherpa_i::m_ncores {this, "NCores", 1}
protected

Number of cores recommended for multi-core integration file.

Definition at line 55 of file Sherpa_i.h.

55{this, "NCores", 1};

◆ m_openloopslibs

StringArrayProperty Sherpa_i::m_openloopslibs {this, "OpenLoopsLibs", {} }
protected

List of needed OpenLoops process libraries (from JO file)

Definition at line 49 of file Sherpa_i.h.

49{this, "OpenLoopsLibs", {} };

◆ m_params

StringArrayProperty Sherpa_i::m_params {this, "Parameters", {} }
protected

List of additional Sherpa parameters beyond run card snippet (from JO file)

Definition at line 45 of file Sherpa_i.h.

45{this, "Parameters", {} };

◆ m_plugincode

StringProperty Sherpa_i::m_plugincode {this, "PluginCode", ""}
protected

Optional code for plugin library to compile and load at run time.

Definition at line 61 of file Sherpa_i.h.

61{this, "PluginCode", ""};

◆ m_ppSvc

ServiceHandle<IPartPropSvc> GenBase::m_ppSvc {this, "PartPropSvc", "PartPropSvc"}
privateinherited

Handle on the particle property service.

Definition at line 144 of file GenBase.h.

144{this, "PartPropSvc", "PartPropSvc"};

◆ m_randomSeed

IntegerProperty GenModule::m_randomSeed {this, "RandomSeed", 1234567, "Random seed for the built-in random engine"}
protectedinherited

Seed for random number engine.

Definition at line 84 of file GenModule.h.

84{this, "RandomSeed", 1234567, "Random seed for the built-in random engine"}; // FIXME make this into an unsigned long int?

◆ m_rndmSvc

ServiceHandle<IAthRNGSvc> GenModule::m_rndmSvc {this, "RndmSvc", "AthRNGSvc"}
privateinherited

Data members.

Definition at line 99 of file GenModule.h.

99{this, "RndmSvc", "AthRNGSvc"};

◆ m_runcard

StringProperty Sherpa_i::m_runcard {this, "RunCard", ""}
protected

FIXME unused?

Sherpa run card snippet (from JO file)

Definition at line 42 of file Sherpa_i.h.

42{this, "RunCard", ""};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_variation_weight_cap

DoubleProperty Sherpa_i::m_variation_weight_cap {this, "VariationWeightCap", 10.0}
protected

Variation weight cap factor.

Definition at line 64 of file Sherpa_i.h.

64{this, "VariationWeightCap", 10.0};

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ m_xsscale

DoubleProperty Sherpa_i::m_xsscale {this, "CrossSectionScaleFactor", 1.0}
protected

Definition at line 66 of file Sherpa_i.h.

66{this, "CrossSectionScaleFactor", 1.0};

◆ p_sherpa

SHERPA::Sherpa* Sherpa_i::p_sherpa {}
protected

Definition at line 32 of file Sherpa_i.h.

32{};

The documentation for this class was generated from the following files: