thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
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
26namespace ThePEG {
27
69
71 friend class Repository;
72
73public:
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
81public:
82
89
94
98 virtual ~EventGenerator();
100
101public:
102
109
115
120
125
130
135
140
145
150 tHistFacPtr histogramFactory() const { return theHistogramFactory; }
151
157
158public:
159
166 void initialize(bool initOnly = false);
167
180 void go(long next = 1, long maxevent = -1, bool tics = false);
181
186
193
200
206 void finalize();
207
214 bool loadMain(string file);
215
221 virtual Energy maximumCMEnergy() const;
222
226 long currentEventNumber() const { return ieve; }
227
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
320
325
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
432
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
458protected:
459
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
520
525
529 void N(long n) { theNumberOfEvents = n; }
530
534 void runName(string f) { theRunName = f; }
535
536public:
537
542 virtual void addTag(string tag) {
543 runName(runName() + tag);
544 }
545
546private:
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
575
579 string doSaveRun(string);
580
584 string doMakeRun(string);
585
586public:
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
718
723 tDMPtr findDecayMode(string tag) const;
724
730
735 tPDPtr findParticle(string pdgname) const;
736
741 tPMPtr findMatcher(string name) const;
742
743private:
744
749
751
752public:
753
754
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
784protected:
785
792 virtual IBPtr clone() const;
793
798 virtual IBPtr fullclone() const;
800
801protected:
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
848
852 int count(const Exception &);
853
854private:
855
856
860 vector<IPtr> theDefaultObjects;
861
865 ParticleMap theLocalParticles;
866
871
877
882
888
893
899
904
908 string thePath;
909
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
1002protected:
1003
1007 long ieve;
1008
1013
1018
1019private:
1020
1027
1033
1041
1047
1053
1060
1067
1074
1075private:
1076
1081
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
1149private:
1150
1155
1160
1161};
1162
1167template <>
1170 typedef Interfaced NthBase;
1171};
1172
1175template <>
1176struct 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 */
This is the main config header file for ThePEG.
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data.
This CurrentGenerator class keeps a static stack of EventGenerators which can be used anywhere by any...
The EventGenerator class manages a whole event generator run.
vector< string > theGlobalLibraries
The global libraries needed for objects used in this EventGenerator.
void flushOutputFile()
Flush the content of the internal output string stream to the .out file.
long N() const
The number of events to be generated in this run.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
SMPtr theStandardModel
Pointer to an object containing standard model parameters.
MatcherSet theMatchers
The set of all matchers to be used in this run.
virtual IBPtr clone() const
Make a simple clone of this object.
int theDebugLevel
The debug level.
string theRunName
The name of this run.
tPMPtr findMatcher(string name) const
Find a matcher in this run given its name.
static ClassDescription< EventGenerator > initEventGenerator
Describe an abstract class with persistent data.
const ObjectSet & used() const
Return a reference to the set of objects which have been registered as used during the current run.
void openOutputFiles()
Open all ouput files.
void generateReferences()
Print out the .tex file with descriptions of and references to all models used in the run.
EHPtr theEventHandler
Pointer to the event handler used to generate the indivudual events.
Ptr< T >::pointer getPtr(const T &) const
Return a garbage collected pointer to a given object.
UseRandom * theCurrentRandom
The UseRandom object constructed for the duration of an EventGenerator run so that the default random...
ofstream theLogfile
A reference to the log file stream.
string runName() const
Return the name assigned to this run.
tEHPtr currentEventHandler() const
Get the currently active EventHandler.
vector< IPtr > theDefaultObjects
A vector of default objects.
EventPtr shoot()
Generate one event.
ofstream theReffile
A reference to the reference file stream.
EventGenerator & operator=(const EventGenerator &)=delete
Private and non-existent assignment operator.
string doSaveRun(string)
Isolate, initialize and save this generator to a file.
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.
EvtManipPtr theEventManipulator
A pointer to an optional event manipulator object.
bool useStdOut() const
Has the generator been asked to redirect everything to standard output?
ParticleMap theParticles
The map of all particles to be used in this run, indexed by the id number.
ostringstream theMiscStream
A stream to be used to redirect cout for external modules which prints out messages there.
virtual EventPtr doGenerateEvent(tEventPtr)
Finish generating an event constructed from the outside.
DMPtr constructDecayMode(string &tag)
Used internally by preinitCreateDecayMode();.
tStepHdlPtr currentStepHandler() const
Get the currently active step handler.
tStepHdlPtr theCurrentStepHandler
The currently active step handler.
const vector< IPtr > & defaultObjects() const
Return the vector of default objects.
ObjectSet usedObjects
The set of objects which have actually been used in this run.
void finalize()
Indicate that the run has ended and call finish() for all objects including this one.
tDMPtr preinitCreateDecayMode(string tag)
Create a decay mode according to the given tag.
const ParticleMap & particles() const
Return a reference to the complete map of particle data objects in this generator,...
RandomGenerator & random() const
Return a reference to the default RandomGenerator object in this run.
void currentEventHandler(tEHPtr eh)
Set the currently active EventHandler.
long theNumberOfEvents
Number of events to be generated in this run.
string filename() const
The base filename used in this run.
virtual void doGo(long next, long maxevent, bool tics)
Run this EventGenerator session.
int logNonDefault
List all modified interfaces in the log file.
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.
long theQuickSize
Only particles with id number less than theQuickSize are available in theQuickParticles.
void path(string f)
Set the directory where the output files will be stored.
ObjectMap theObjectMap
All objects to be used in this run mapped to their name.
bool useStdout
Whether to use files or stdout for logging and output.
string defPath() const
Utility function for the interface.
virtual void dump() const
Dump the full state of the current run - including the number of generated events,...
void setLocalParticles(PDPtr pd, int)
Utility function for the interface.
ExceptionMap theExceptions
A map of all Exceptions which have been caught by the event generator and the number of time each exc...
string preinitInterface(string fullname, string ifcname, string cmd, string value)
Manipulate an interface of an Interfaced object.
bool logException(const Exception &, tcEventPtr)
Log a given exception.
void setSeed(long seed)
Set the random seed for the global random number generator.
virtual void doinitrun()
Initialize this object.
double sumWeights() const
The sum of all weight of the events generated so far.
void N(long n)
Set number of events to be generated.
virtual ~EventGenerator()
Destructor.
void runName(string f)
Set the name of this run.
string preinitInterface(string fullname, string ifcname, int index, string cmd, string value)
Manipulate an interface of vector type (RefVector or ParVector) of an Interfaced object.
void delLocalParticles(int place)
Utility function for the interface.
EventGenerator()
Default constructor.
vector< PDPtr > getLocalParticles() const
Utility function for the interface.
Ptr< T >::pointer getObject(string name) const
Return a pointer to an object of type T present in this run given its full name.
int maxWarnings
The maximum number of warnings reported of each type.
void tic(long currev=0, long totev=0) const
Write out the number of events generated and the elapsed time in suitable periods.
tEHPtr eventHandler() const
Return a pointer to the EventHandler.
HistFacPtr theHistogramFactory
A pointer to an associated factory objects for handling histograms to be used by AnalysisHandlers.
ostream & out()
This stream should be used for output of information and statistics of an EventGenerator run in the f...
string preinitInterface(IPtr obj, string ifcname, int index, string cmd, string value)
Manipulate an interface of vector type (RefVector or ParVector) of an Interfaced object.
ostream & ref()
Return a reference to the stream connected to the filea for references from used objects.
int maxErrors
The maximum number of warnings and errors reported of each type.
tEvtManipPtr manipulator() const
Return the EventManipulator used in the run.
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.
virtual void dofinish()
Finalize this object.
bool preinitRemove(IPtr obj)
Remove the object.
PPtr getParticle(PID id) const
Create a particle instance corresponding to the given id number.
CrossSection histogramScale() const
Histogram scale.
const ObjectSet & objects() const
Return the set of objects used in this run.
EventPtr generateEvent(Step &step)
Finish generating an event starting from a step which has already been partially constructed from the...
IBPtr getPointer(string name) const
Return a pointer to an object present in this run given its full name.
void currentStepHandler(tStepHdlPtr sh)
Set the currently active step handler.
ObjectMap & objectMap()
Return the map of all objects to be used in this run indexed by their name.
ostream & misc()
Return a reference to a stream to be used to redirect cout for external modules which prints out mess...
ObjectSet theObjects
The set of all objects to be used in this run.
IPtr preinitCreate(string classname, string fullname, string libraries="")
Create a new Interfaced object to be used in the run being initialized.
void insLocalParticles(PDPtr pd, int)
Utility function for the interface.
const MatcherSet & matchers() const
Return a reference to the complete list of matchers in this generator.
ofstream & outfile()
Return a reference to the output file stream.
ostringstream theOutStream
A string stream used as a buffer for messages written to the .out file.
tSMPtr standardModel() const
Return a pointer to the standard model parameters.
void strategy(StrategyPtr)
Set a pointer to the strategy object containing a set of non-default particles to use.
Ptr< T >::pointer getDefault() const
Return the default object for class T.
ParticleMap & localParticles()
Access the special particles used in this generator.
ofstream & reffile()
Return a reference to the reference file stream.
bool keepAllDumps
If this flag is true, keep all dump files of the run, labelled by event number.
double weightSum
The sum of the weights of the events produced so far.
const ObjectMap & objectMap() const
Return the map of objects used in this run indexed by their name.
virtual EventPtr doGenerateEvent(tStepPtr)
Finish generating an event starting from a Step constructed from the outside.
AnalysisVector & analysisHandlers()
Return the vector of analysis objects to be used in the run.
AnalysisVector theAnalysisHandlers
A vector of all analysis handlers to be called after each event.
void use(const Interfaced &i)
Register a given object as used.
PDPtr getParticleData(PID id) const
Return a pointer to the ParticleData object corresponding to the given id number.
bool loadMain(string file)
Dynamically load the Main class in the given file, making it run its Init() method where it may use t...
void initialize(bool initOnly=false)
Initialize this generator.
virtual void doInitialize(bool initOnly=false)
Initialize this generator.
string theOutFileName
Remember the name of the file where the output should be sent.
virtual Energy maximumCMEnergy() const
Return the maximum center of mass energy possible for an event.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
static void Init()
Standard Init function used to initialize the interface.
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
string thePath
The directory where the input and output files resides.
tDMPtr findDecayMode(string tag) const
Find a decaymode given a decay tag.
bool preinitializing
A flag to tell if we are in the pre-initialization phase where objects with preInitialize() functions...
int count(const Exception &)
Increase and return the count for the given exception.
tEHPtr theCurrentEventHandler
The currently active EventHandler.
long currentEventNumber() const
The number of the event currently being generated.
long debugEvent
If the debug level is higher than 0, step up to the highest debug level just before the event with nu...
CrossSection integratedXSec() const
The total integrated cross section of the processes generated in this run.
bool preinitRegister(IPtr obj, string fullname)
Register a new object to be included in the run currently being initialized.
ParticleMap theLocalParticles
Map of non-default particles used in this EventGenerator.
bool theIntermediateOutput
Whether to use a modified event number count.
void printException(const Exception &)
Print the message of an exception to the log file.
PDVector theQuickParticles
A vector of particles indexed by the id number for quick access.
void checkSignalState()
Check if there has been an interrupt signal from the OS.
CrossSection integratedXSecErr() const
The error estimate for the total integrated cross section of the processes generated in this run.
string doMakeRun(string)
Isolate and initialize this generator.
const vector< string > & globalLibraries() const
The global libraries needed for objects used in this EventGenerator.
EventGenerator(const EventGenerator &)
Copy-constructor.
CurrentGenerator * theCurrentGenerator
The CurrentGenerator object constructed for the duration of an EventGenerator run so that the default...
ObjectSet & objects()
Return the set of all objects to be used in this run.
int printEvent
If the debug level is higher than 0, print the first 'printEvent' events to the logfile.
const ParticleMap & localParticles() const
Access the special particles used in this generator.
ostream & log()
Return a reference to the stream connected to the file for logging information.
virtual EventPtr doShoot()
Generate one event.
EventPtr generateEvent(Event &event)
Finish generating an event which has already been partially constructed from the outside.
void setup(string newRunName, ObjectSet &newObjects, ParticleMap &newParticles, MatcherSet &newMatchers)
Finish the setup of an event generator run.
void setPath(string newPath)
Utility function for the interface.
void logWarning(const Exception &)
Log a given exception.
void closeOutputFiles()
Close all ouput files.
long dumpPeriod
If the debug level is higher than 0, dump the complete state of this run to the default dump file eve...
long ieve
The current event number;.
string preinitInterface(IPtr obj, string ifcname, string cmd, string value)
Manipulate an interface of an Interfaced object.
tcEventPtr currentEvent() const
Return the event being generated.
ofstream & logfile()
Return a reference to the log file stream.
ofstream theOutfile
A reference to the output file stream.
StrategyPtr theStrategy
Pointer to a strategy object with other non-default particles to be used in this EventGenerator.
string path() const
The directory in which the filename() is located.
RanGenPtr theRandom
Pointer to the default RandomGenerator to be used in this run.
tHistFacPtr histogramFactory() const
Return a pointer to an associated factory objects for handling histograms to be used by AnalysisHandl...
The Event class contains all Particles produced in the generation of an event.
Definition: Event.h:37
Exception is the base class for all exceptions to be used in ThePEG.
Definition: Exception.h:44
string name() const
Returns the name of this object, without the path.
The Interfaced class is derived from the InterfacedBase class adding a couple of things particular to...
Definition: Interfaced.h:38
PID is a helper class implementing the type of PDG particle ids.
Definition: PID.h:23
PersistentIStream is used to read persistent objects from a stream where they were previously written...
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
Repository inherits from the BaseRepository class.
Definition: Repository.h:45
The Step class contains information of all particles present after certain step in the event generati...
Definition: Step.h:34
This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by an...
Definition: UseRandom.h:33
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
vector< PDPtr > PDVector
A vector of pointers to ParticleData objects.
Definition: Containers.h:33
vector< AnaPtr > AnalysisVector
A vector of pointers to AnalysisHandler objects.
Definition: Containers.h:112
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
static string className()
Return the name of class T.
Definition: ClassTraits.h:66
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30