ThePEG  1.8.0
EventGenerator.h
1 // -*- C++ -*-
2 //
3 // EventGenerator.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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();
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 
248  void setSeed(long seed) { random().setSeed(seed); }
249 
253  void logWarning(const Exception &);
254 
258  long N() const { return theNumberOfEvents; }
259 
266 
272 
278 
282  double sumWeights() const { return weightSum; }
284 
296  string filename() const { return path() + "/" + runName(); }
297 
302  string runName() const { return theRunName.size()? theRunName: name(); }
303 
307  string path() const { return thePath; }
308 
313  bool useStdOut() const { return useStdout; }
314 
318  void openOutputFiles();
319 
323  void flushOutputFile();
324 
328  void closeOutputFiles();
329 
333  ofstream & outfile() { return theOutfile; }
334 
338  ofstream & logfile() { return theLogfile; }
339 
345  ofstream & reffile() { return theReffile; }
346 
355  ostream & out();
356 
362  ostream & log();
363 
369  ostream & misc() {
370  return theMiscStream;
371  }
372 
378  ostream & ref();
380 
386  const ObjectSet & objects() const { return theObjects; }
387 
388 
392  const ObjectMap & objectMap() const { return theObjectMap; }
393 
399  template <typename T>
400  typename Ptr<T>::pointer getPtr(const T &) const;
401 
406  IBPtr getPointer(string name) const;
407 
414  template <typename T>
415  typename Ptr<T>::pointer getObject(string name) const {
416  return dynamic_ptr_cast<typename Ptr<T>::pointer>(getPointer(name));
417  }
418 
423  template <typename T>
424  typename Ptr<T>::pointer getDefault() const;
425 
430  PPtr getParticle(PID id) const;
431 
436  PDPtr getParticleData(PID id) const;
437 
442  const MatcherSet & matchers() const { return theMatchers; }
443 
448  const ParticleMap & particles() const { return theParticles; }
449 
454  const ObjectSet & used() const { return usedObjects; }
456 
457 protected:
458 
463  void checkSignalState();
464 
469  RandomGenerator & random() const { return *theRandom; }
470 
476  void setup(string newRunName, ObjectSet & newObjects,
477  ParticleMap & newParticles, MatcherSet & newMatchers);
478 
484  virtual void doGo(long next, long maxevent, bool tics);
485 
489  virtual void doInitialize();
490 
494  virtual EventPtr doShoot();
495 
500  void tic(long currev = 0, long totev = 0) const;
501 
507 
514 
518  void printException(const Exception &);
519 
523  bool logException(const Exception &, tcEventPtr);
524 
528  void N(long n) { theNumberOfEvents = n; }
529 
533  void runName(string f) { theRunName = f; }
534 
535 public:
536 
540  void addTag(string tag) {
541  runName(runName() + tag);
542  }
543 
544 private:
545 
549  const vector<IPtr> & defaultObjects() const { return theDefaultObjects; }
550 
555  ParticleMap & localParticles() { return theLocalParticles; }
556 
561  const ParticleMap & localParticles() const { return theLocalParticles; }
562 
566  void path(string f) { thePath = f; }
567 
572  void strategy(StrategyPtr);
573 
577  string doSaveRun(string);
578 
582  string doMakeRun(string);
583 
584 public:
585 
608  bool preinitRegister(IPtr obj, string fullname);
609 
628  IPtr preinitCreate(string classname, string fullname, string libraries = "");
629 
630 
647  string preinitInterface(string fullname, string ifcname, string cmd,
648  string value);
649 
670  string preinitInterface(string fullname, string ifcname, int index,
671  string cmd, string value);
672 
688  string preinitInterface(IPtr obj, string ifcname, string cmd, string value);
689 
709  string preinitInterface(IPtr obj, string ifcname, int index,
710  string cmd, string value);
711 
716  tDMPtr findDecayMode(string tag) const;
717 
722  tDMPtr preinitCreateDecayMode(string tag);
723 
728  tPDPtr findParticle(string pdgname) const;
729 
734  tPMPtr findMatcher(string name) const;
735 
736 private:
737 
741  DMPtr constructDecayMode(string & tag);
742 
744 
745 public:
746 
747 
754  void persistentOutput(PersistentOStream & os) const;
755 
761  void persistentInput(PersistentIStream & is, int version);
762 
766  const vector<string> & globalLibraries() const {
767  return theGlobalLibraries;
768  }
769 
771 
775  static void Init();
776 
777 protected:
778 
785  virtual IBPtr clone() const;
786 
791  virtual IBPtr fullclone() const;
793 
794 protected:
795 
803  virtual void doinit();
804 
809  virtual void doinitrun();
810 
815  virtual void dofinish();
816 
821  void finally();
822 
824 
828  ObjectSet & objects() { return theObjects; }
829 
834  ObjectMap & objectMap() { return theObjectMap; }
835 
840  void generateReferences();
841 
845  int count(const Exception &);
846 
847 private:
848 
849 
853  vector<IPtr> theDefaultObjects;
854 
858  ParticleMap theLocalParticles;
859 
864 
870 
875 
881 
886 
892 
897 
901  string thePath;
902 
906  string theRunName;
907 
911  ofstream theOutfile;
912 
916  ofstream theLogfile;
917 
921  ofstream theReffile;
922 
928  ostringstream theMiscStream;
929 
937  ostringstream theOutStream;
938 
944 
949 
953  ObjectSet theObjects;
954 
958  ObjectMap theObjectMap;
959 
964  ParticleMap theParticles;
971 
977 
984 
988  MatcherSet theMatchers;
989 
993  ObjectSet usedObjects;
994 
995 protected:
996 
1000  long ieve;
1001 
1005  double weightSum;
1006 
1011 
1012 private:
1013 
1020 
1026 
1034 
1040 
1047 
1054 
1060  ExceptionMap theExceptions;
1061 
1062 private:
1063 
1067  void setLocalParticles(PDPtr pd, int);
1068 
1072  void insLocalParticles(PDPtr pd, int);
1073 
1077  void delLocalParticles(int place);
1078 
1082  vector<PDPtr> getLocalParticles() const;
1083 
1087  void setPath(string newPath);
1088 
1092  string defPath() const;
1093 
1101 
1109 
1114 
1119 
1120 
1125 
1129  vector<string> theGlobalLibraries;
1130 
1131 private:
1132 
1137 
1142 
1143 };
1144 
1149 template <>
1150 struct BaseClassTrait<EventGenerator,1>: public ClassTraitsType {
1152  typedef Interfaced NthBase;
1153 };
1154 
1157 template <>
1158 struct ClassTraits<EventGenerator>: public ClassTraitsBase<EventGenerator> {
1160  static string className() { return "ThePEG::EventGenerator"; }
1161 };
1162 
1165 }
1166 
1167 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1168 #include "EventGenerator.tcc"
1169 #endif
1170 
1171 #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.
virtual void doInitialize()
Initialize this generator.
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.
void addTag(string tag)
Append a tag to the run name.
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:681
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:509
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 setSeed(long seed)=0
Reset the underlying random engine with the given seed.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
int count(const Exception &)
Increase and return the count for the given exception.
string runName() const
Return the name assigned to this run.
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.
QTY< 0, 1, 0 >::Type Energy
Energy.
Definition: Unitsystem.h:34
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.
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...
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...
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.
This template class allows the compiler to check calculations with physical quantities for dimensiona...
Definition: PhysicalQty.h:81
void initialize()
Initialize this generator.
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
EventGenerator & operator=(const EventGenerator &)
Private and non-existent assignment operator.
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