thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
EventGenerator.h
1 // -*- C++ -*-
2 //
3 // EventGenerator.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_EventGenerator_H
10 #define ThePEG_EventGenerator_H
11 // This is the declaration of the EventGenerator class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "ThePEG/Utilities/Named.h"
15 #include "EventGenerator.fh"
16 #include "RandomGenerator.h"
17 #include "ThePEG/Repository/UseRandom.h"
18 #include "ThePEG/Repository/Strategy.h"
19 #include "ThePEG/Repository/CurrentGenerator.fh"
20 #include "ThePEG/Utilities/ClassDescription.h"
21 #include "ThePEG/Handlers/EventHandler.fh"
22 #include "ThePEG/Analysis/FactoryBase.fh"
23 #include <fstream>
24 #include "EventGenerator.xh"
25 
26 namespace ThePEG {
27 
68 class EventGenerator: public Interfaced {
69 
71  friend class Repository;
72 
73 public:
74 
77  //typedef map<const type_info *, int> ExceptionMap;
78  //typedef map<Exception, int, ExceptionComparison > ExceptionMap;
79  typedef map<pair<string, Exception::Severity>, int> ExceptionMap;
80 
81 public:
82 
89 
94 
98  virtual ~EventGenerator();
100 
101 public:
102 
109 
114  tStrategyPtr strategy() const { return theStrategy; }
115 
120 
125 
130 
135 
139  tEHPtr eventHandler() const { return theEventHandler; }
140 
145 
150  tHistFacPtr histogramFactory() const { return theHistogramFactory; }
151 
157 
158 public:
159 
166  void initialize(bool initOnly = false);
167 
180  void go(long next = 1, long maxevent = -1, bool tics = false);
181 
185  EventPtr shoot();
186 
192  EventPtr generateEvent(Event & event);
193 
199  EventPtr generateEvent(Step & step);
200 
206  void finalize();
207 
214  bool loadMain(string file);
215 
221  virtual Energy maximumCMEnergy() const;
222 
226  long currentEventNumber() const { return ieve; }
227 
231  tcEventPtr currentEvent() const;
232 
237  virtual void dump() const;
238 
243  void use(const Interfaced & i);
244 
249  void setSeed(long seed);
250 
254  void logWarning(const Exception &);
255 
259  long N() const { return theNumberOfEvents; }
260 
267 
273 
279 
283  double sumWeights() const { return weightSum; }
285 
297  string filename() const { return path() + "/" + runName(); }
298 
303  string runName() const { return theRunName.size()? theRunName: name(); }
304 
308  string path() const { return thePath; }
309 
314  bool useStdOut() const { return useStdout; }
315 
319  void openOutputFiles();
320 
324  void flushOutputFile();
325 
329  void closeOutputFiles();
330 
334  ofstream & outfile() { return theOutfile; }
335 
339  ofstream & logfile() { return theLogfile; }
340 
346  ofstream & reffile() { return theReffile; }
347 
356  ostream & out();
357 
363  ostream & log();
364 
370  ostream & misc() {
371  return theMiscStream;
372  }
373 
379  ostream & ref();
381 
387  const ObjectSet & objects() const { return theObjects; }
388 
389 
393  const ObjectMap & objectMap() const { return theObjectMap; }
394 
400  template <typename T>
401  typename Ptr<T>::pointer getPtr(const T &) const;
402 
407  IBPtr getPointer(string name) const;
408 
415  template <typename T>
416  typename Ptr<T>::pointer getObject(string name) const {
417  return dynamic_ptr_cast<typename Ptr<T>::pointer>(getPointer(name));
418  }
419 
424  template <typename T>
425  typename Ptr<T>::pointer getDefault() const;
426 
431  PPtr getParticle(PID id) const;
432 
437  PDPtr getParticleData(PID id) const;
438 
443  const MatcherSet & matchers() const { return theMatchers; }
444 
449  const ParticleMap & particles() const { return theParticles; }
450 
455  const ObjectSet & used() const { return usedObjects; }
457 
458 protected:
459 
464  void checkSignalState();
465 
470  RandomGenerator & random() const { return *theRandom; }
471 
477  void setup(string newRunName, ObjectSet & newObjects,
478  ParticleMap & newParticles, MatcherSet & newMatchers);
479 
485  virtual void doGo(long next, long maxevent, bool tics);
486 
490  virtual void doInitialize(bool initOnly = false);
491 
495  virtual EventPtr doShoot();
496 
501  void tic(long currev = 0, long totev = 0) const;
502 
508 
515 
519  void printException(const Exception &);
520 
524  bool logException(const Exception &, tcEventPtr);
525 
529  void N(long n) { theNumberOfEvents = n; }
530 
534  void runName(string f) { theRunName = f; }
535 
536 public:
537 
542  virtual void addTag(string tag) {
543  runName(runName() + tag);
544  }
545 
546 private:
547 
551  const vector<IPtr> & defaultObjects() const { return theDefaultObjects; }
552 
557  ParticleMap & localParticles() { return theLocalParticles; }
558 
563  const ParticleMap & localParticles() const { return theLocalParticles; }
564 
568  void path(string f) { thePath = f; }
569 
574  void strategy(StrategyPtr);
575 
579  string doSaveRun(string);
580 
584  string doMakeRun(string);
585 
586 public:
587 
610  bool preinitRegister(IPtr obj, string fullname);
611 
630  IPtr preinitCreate(string classname, string fullname, string libraries = "");
631 
632 
649  string preinitInterface(string fullname, string ifcname, string cmd,
650  string value);
651 
672  string preinitInterface(string fullname, string ifcname, int index,
673  string cmd, string value);
674 
690  string preinitInterface(IPtr obj, string ifcname, string cmd, string value);
691 
711  string preinitInterface(IPtr obj, string ifcname, int index,
712  string cmd, string value);
713 
717  bool preinitRemove(IPtr obj);
718 
723  tDMPtr findDecayMode(string tag) const;
724 
729  tDMPtr preinitCreateDecayMode(string tag);
730 
735  tPDPtr findParticle(string pdgname) const;
736 
741  tPMPtr findMatcher(string name) const;
742 
743 private:
744 
748  DMPtr constructDecayMode(string & tag);
749 
751 
752 public:
753 
754 
761  void persistentOutput(PersistentOStream & os) const;
762 
768  void persistentInput(PersistentIStream & is, int version);
769 
773  const vector<string> & globalLibraries() const {
774  return theGlobalLibraries;
775  }
776 
778 
782  static void Init();
783 
784 protected:
785 
792  virtual IBPtr clone() const;
793 
798  virtual IBPtr fullclone() const;
800 
801 protected:
802 
810  virtual void doinit();
811 
816  virtual void doinitrun();
817 
822  virtual void dofinish();
823 
828  void finally();
829 
831 
835  ObjectSet & objects() { return theObjects; }
836 
841  ObjectMap & objectMap() { return theObjectMap; }
842 
847  void generateReferences();
848 
852  int count(const Exception &);
853 
854 private:
855 
856 
860  vector<IPtr> theDefaultObjects;
861 
865  ParticleMap theLocalParticles;
866 
871 
877 
882 
888 
893 
899 
904 
908  string thePath;
909 
913  string theRunName;
914 
918  ofstream theOutfile;
919 
923  ofstream theLogfile;
924 
928  ofstream theReffile;
929 
935  ostringstream theMiscStream;
936 
944  ostringstream theOutStream;
945 
951 
956 
960  ObjectSet theObjects;
961 
965  ObjectMap theObjectMap;
966 
971  ParticleMap theParticles;
978 
984 
991 
995  MatcherSet theMatchers;
996 
1000  ObjectSet usedObjects;
1001 
1002 protected:
1003 
1007  long ieve;
1008 
1012  double weightSum;
1013 
1018 
1019 private:
1020 
1027 
1033 
1041 
1047 
1053 
1060 
1067 
1073  ExceptionMap theExceptions;
1074 
1075 private:
1076 
1080  void setLocalParticles(PDPtr pd, int);
1081 
1085  void insLocalParticles(PDPtr pd, int);
1086 
1090  void delLocalParticles(int place);
1091 
1095  vector<PDPtr> getLocalParticles() const;
1096 
1100  void setPath(string newPath);
1101 
1105  string defPath() const;
1106 
1114 
1122 
1127 
1132 
1133 
1138 
1143 
1147  vector<string> theGlobalLibraries;
1148 
1149 private:
1150 
1155 
1159  EventGenerator & operator=(const EventGenerator &) = delete;
1160 
1161 };
1162 
1167 template <>
1168 struct BaseClassTrait<EventGenerator,1>: public ClassTraitsType {
1170  typedef Interfaced NthBase;
1171 };
1172 
1175 template <>
1176 struct ClassTraits<EventGenerator>: public ClassTraitsBase<EventGenerator> {
1178  static string className() { return "ThePEG::EventGenerator"; }
1179 };
1180 
1183 }
1184 
1185 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1186 #include "EventGenerator.tcc"
1187 #endif
1188 
1189 #endif /* ThePEG_EventGenerator_H */
bool loadMain(string file)
Dynamically load the Main class in the given file, making it run its Init() method where it may use t...
virtual ~EventGenerator()
Destructor.
int maxWarnings
The maximum number of warnings reported of each type.
virtual IBPtr clone() const
Make a simple clone of this object.
void currentEventHandler(tEHPtr eh)
Set the currently active EventHandler.
PID is a helper class implementing the type of PDG particle ids.
Definition: PID.h:23
PDVector theQuickParticles
A vector of particles indexed by the id number for quick access.
tEHPtr eventHandler() const
Return a pointer to the EventHandler.
virtual EventPtr doGenerateEvent(tEventPtr)
Finish generating an event constructed from the outside.
PersistentIStream is used to read persistent objects from a stream where they were previously written...
static void Init()
Standard Init function used to initialize the interface.
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
vector< string > theGlobalLibraries
The global libraries needed for objects used in this EventGenerator.
void setup(string newRunName, ObjectSet &newObjects, ParticleMap &newParticles, MatcherSet &newMatchers)
Finish the setup of an event generator run.
Ptr< T >::pointer getObject(string name) const
Return a pointer to an object of type T present in this run given its full name.
double weightSum
The sum of the weights of the events produced so far.
RandomGenerator & random() const
Return a reference to the default RandomGenerator object in this run.
ostream & out()
This stream should be used for output of information and statistics of an EventGenerator run in the f...
void finalize()
Indicate that the run has ended and call finish() for all objects including this one.
void flushOutputFile()
Flush the content of the internal output string stream to the .out file.
SMPtr theStandardModel
Pointer to an object containing standard model parameters.
long theNumberOfEvents
Number of events to be generated in this run.
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
DMPtr constructDecayMode(string &tag)
Used internally by preinitCreateDecayMode();.
virtual void doinitrun()
Initialize this object.
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
void currentStepHandler(tStepHdlPtr sh)
Set the currently active step handler.
ostringstream theOutStream
A string stream used as a buffer for messages written to the .out file.
The Event class contains all Particles produced in the generation of an event.
Definition: Event.h:36
EHPtr theEventHandler
Pointer to the event handler used to generate the indivudual events.
vector< IPtr > theDefaultObjects
A vector of default objects.
bool preinitRegister(IPtr obj, string fullname)
Register a new object to be included in the run currently being initialized.
long ieve
The current event number;.
ostringstream theMiscStream
A stream to be used to redirect cout for external modules which prints out messages there...
string theRunName
The name of this run.
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data...
CurrentGenerator * theCurrentGenerator
The CurrentGenerator object constructed for the duration of an EventGenerator run so that the default...
bool useStdOut() const
Has the generator been asked to redirect everything to standard output?
tEHPtr currentEventHandler() const
Get the currently active EventHandler.
ExceptionMap theExceptions
A map of all Exceptions which have been caught by the event generator and the number of time each exc...
ObjectSet usedObjects
The set of objects which have actually been used in this run.
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
void N(long n)
Set number of events to be generated.
void setLocalParticles(PDPtr pd, int)
Utility function for the interface.
This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by an...
Definition: UseRandom.h:33
EvtManipPtr theEventManipulator
A pointer to an optional event manipulator object.
ObjectSet & objects()
Return the set of all objects to be used in this run.
bool logException(const Exception &, tcEventPtr)
Log a given exception.
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
ofstream & logfile()
Return a reference to the log file stream.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
ostream & log()
Return a reference to the stream connected to the file for logging information.
string path() const
The directory in which the filename() is located.
void use(const Interfaced &i)
Register a given object as used.
void setSeed(long seed)
Set the random seed for the global random number generator.
ObjectMap theObjectMap
All objects to be used in this run mapped to their name.
Repository inherits from the BaseRepository class.
Definition: Repository.h:45
int logNonDefault
List all modified interfaces in the log file.
tDMPtr preinitCreateDecayMode(string tag)
Create a decay mode according to the given tag.
tcEventPtr currentEvent() const
Return the event being generated.
const ParticleMap & localParticles() const
Access the special particles used in this generator.
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition: PtrTraits.h:168
ObjectMap & objectMap()
Return the map of all objects to be used in this run indexed by their name.
virtual void doInitialize(bool initOnly=false)
Initialize this generator.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
bool theIntermediateOutput
Whether to use a modified event number count.
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
EventGenerator & operator=(const EventGenerator &)=delete
Private and non-existent assignment operator.
int count(const Exception &)
Increase and return the count for the given exception.
string runName() const
Return the name assigned to this run.
This is the main config header file for ThePEG.
bool preinitRemove(IPtr obj)
Remove the object.
void logWarning(const Exception &)
Log a given exception.
tDMPtr findDecayMode(string tag) const
Find a decaymode given a decay tag.
const MatcherSet & matchers() const
Return a reference to the complete list of matchers in this generator.
ParticleMap theLocalParticles
Map of non-default particles used in this EventGenerator.
HistFacPtr theHistogramFactory
A pointer to an associated factory objects for handling histograms to be used by AnalysisHandlers.
const vector< IPtr > & defaultObjects() const
Return the vector of default objects.
tEHPtr theCurrentEventHandler
The currently active EventHandler.
int printEvent
If the debug level is higher than 0, print the first &#39;printEvent&#39; events to the logfile.
ofstream theReffile
A reference to the reference file stream.
virtual void doGo(long next, long maxevent, bool tics)
Run this EventGenerator session.
void delLocalParticles(int place)
Utility function for the interface.
void insLocalParticles(PDPtr pd, int)
Utility function for the interface.
ostream & ref()
Return a reference to the stream connected to the filea for references from used objects.
void openOutputFiles()
Open all ouput files.
void path(string f)
Set the directory where the output files will be stored.
tPDPtr findParticle(string pdgname) const
Find a particle in this run, using its PDG name.
void go(long next=1, long maxevent=-1, bool tics=false)
Run this EventGenerator session.
ostream & misc()
Return a reference to a stream to be used to redirect cout for external modules which prints out mess...
IPtr preinitCreate(string classname, string fullname, string libraries="")
Create a new Interfaced object to be used in the run being initialized.
long debugEvent
If the debug level is higher than 0, step up to the highest debug level just before the event with nu...
void printException(const Exception &)
Print the message of an exception to the log file.
AnalysisVector theAnalysisHandlers
A vector of all analysis handlers to be called after each event.
IBPtr getPointer(string name) const
Return a pointer to an object present in this run given its full name.
const ObjectSet & used() const
Return a reference to the set of objects which have been registered as used during the current run...
PPtr getParticle(PID id) const
Create a particle instance corresponding to the given id number.
EventPtr shoot()
Generate one event.
MatcherSet theMatchers
The set of all matchers to be used in this run.
void initialize(bool initOnly=false)
Initialize this generator.
UseRandom * theCurrentRandom
The UseRandom object constructed for the duration of an EventGenerator run so that the default random...
PDPtr getParticleData(PID id) const
Return a pointer to the ParticleData object corresponding to the given id number. ...
void setPath(string newPath)
Utility function for the interface.
string filename() const
The base filename used in this run.
virtual void dump() const
Dump the full state of the current run - including the number of generated events, so that it can be fully continued from this point.
void tic(long currev=0, long totev=0) const
Write out the number of events generated and the elapsed time in suitable periods.
bool preinitializing
A flag to tell if we are in the pre-initialization phase where objects with preInitialize() functions...
bool keepAllDumps
If this flag is true, keep all dump files of the run, labelled by event number.
void checkSignalState()
Check if there has been an interrupt signal from the OS.
int maxErrors
The maximum number of warnings and errors reported of each type.
ParticleMap theParticles
The map of all particles to be used in this run, indexed by the id number.
CrossSection integratedXSec() const
The total integrated cross section of the processes generated in this run.
CrossSection integratedXSecErr() const
The error estimate for the total integrated cross section of the processes generated in this run...
long theQuickSize
Only particles with id number less than theQuickSize are available in theQuickParticles.
const vector< string > & globalLibraries() const
The global libraries needed for objects used in this EventGenerator.
tPMPtr findMatcher(string name) const
Find a matcher in this run given its name.
ofstream & reffile()
Return a reference to the reference file stream.
long dumpPeriod
If the debug level is higher than 0, dump the complete state of this run to the default dump file eve...
const ParticleMap & particles() const
Return a reference to the complete map of particle data objects in this generator, indexed by their id numbers.
virtual Energy maximumCMEnergy() const
Return the maximum center of mass energy possible for an event.
string thePath
The directory where the input and output files resides.
string doSaveRun(string)
Isolate, initialize and save this generator to a file.
tStrategyPtr strategy() const
Return a pointer to the strategy object containing a set of non-default particles to use...
virtual void addTag(string tag)
Append a tag to the run name.
string doMakeRun(string)
Isolate and initialize this generator.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
const ObjectSet & objects() const
Return the set of objects used in this run.
bool useStdout
Whether to use files or stdout for logging and output.
string defPath() const
Utility function for the interface.
The Interfaced class is derived from the InterfacedBase class adding a couple of things particular to...
Definition: Interfaced.h:38
static ClassDescription< EventGenerator > initEventGenerator
Describe an abstract class with persistent data.
tStepHdlPtr currentStepHandler() const
Get the currently active step handler.
virtual void dofinish()
Finalize this object.
EventPtr generateEvent(Event &event)
Finish generating an event which has already been partially constructed from the outside.
Exception is the base class for all exceptions to be used in ThePEG.
Definition: Exception.h:44
ofstream & outfile()
Return a reference to the output file stream.
tStepHdlPtr theCurrentStepHandler
The currently active step handler.
Ptr< T >::pointer getDefault() const
Return the default object for class T.
const ObjectMap & objectMap() const
Return the map of objects used in this run indexed by their name.
vector< PDPtr > getLocalParticles() const
Utility function for the interface.
ParticleMap & localParticles()
Access the special particles used in this generator.
This CurrentGenerator class keeps a static stack of EventGenerators which can be used anywhere by any...
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
Ptr< T >::pointer getPtr(const T &) const
Return a garbage collected pointer to a given object.
StrategyPtr theStrategy
Pointer to a strategy object with other non-default particles to be used in this EventGenerator.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
ObjectSet theObjects
The set of all objects to be used in this run.
void runName(string f)
Set the name of this run.
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
string theOutFileName
Remember the name of the file where the output should be sent.
vector< PDPtr > PDVector
A vector of pointers to ParticleData objects.
Definition: Containers.h:33
void generateReferences()
Print out the .tex file with descriptions of and references to all models used in the run...
string name() const
Returns the name of this object, without the path.
virtual EventPtr doShoot()
Generate one event.
void closeOutputFiles()
Close all ouput files.
map< pair< string, Exception::Severity >, int > ExceptionMap
A map of integers giving the number of times an exception of the key type has been thrown...
long N() const
The number of events to be generated in this run.
AnalysisVector & analysisHandlers()
Return the vector of analysis objects to be used in the run.
ofstream theOutfile
A reference to the output file stream.
ofstream theLogfile
A reference to the log file stream.
double sumWeights() const
The sum of all weight of the events generated so far.
CrossSection histogramScale() const
Histogram scale.
tSMPtr standardModel() const
Return a pointer to the standard model parameters.
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
RanGenPtr theRandom
Pointer to the default RandomGenerator to be used in this run.
tEvtManipPtr manipulator() const
Return the EventManipulator used in the run.
int theDebugLevel
The debug level.
EventGenerator()
Default constructor.
tHistFacPtr histogramFactory() const
Return a pointer to an associated factory objects for handling histograms to be used by AnalysisHandl...
long currentEventNumber() const
The number of the event currently being generated.
The EventGenerator class manages a whole event generator run.
vector< AnaPtr > AnalysisVector
A vector of pointers to AnalysisHandler objects.
Definition: Containers.h:112
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition: ClassTraits.h:52
string preinitInterface(string fullname, string ifcname, string cmd, string value)
Manipulate an interface of an Interfaced object.
The Step class contains information of all particles present after certain step in the event generati...
Definition: Step.h:34