|
|
|||
File indexing completed on 2026-08-06 09:38:31
0001 // -*- C++ -*- 0002 // 0003 // EventGenerator.h is a part of ThePEG - Toolkit for HEP Event Generation 0004 // Copyright (C) 1999-2019 Leif Lonnblad 0005 // 0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details. 0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 0008 // 0009 #ifndef ThePEG_EventGenerator_H 0010 #define ThePEG_EventGenerator_H 0011 // This is the declaration of the EventGenerator class. 0012 0013 #include "ThePEG/Config/ThePEG.h" 0014 #include "ThePEG/Utilities/Named.h" 0015 #include "EventGenerator.fh" 0016 #include "RandomGenerator.h" 0017 #include "ThePEG/Repository/UseRandom.h" 0018 #include "ThePEG/Repository/Strategy.h" 0019 #include "ThePEG/Repository/CurrentGenerator.fh" 0020 #include "ThePEG/Utilities/ClassDescription.h" 0021 #include "ThePEG/Handlers/EventHandler.fh" 0022 #include "ThePEG/Analysis/FactoryBase.fh" 0023 #include <fstream> 0024 #include "EventGenerator.xh" 0025 0026 namespace ThePEG { 0027 0028 /** 0029 * The EventGenerator class manages a whole event generator run. It 0030 * keeps a list of all Interfaced objects which are needed for a 0031 * particular run (these objects each have a pointer back to the 0032 * EventGenerator). Some objects are special, such as a default 0033 * RandomGenerator object, a StandardModelBase object and a Strategy 0034 * object and lists of ParticleData and MatcherBase objects used in 0035 * the run. 0036 * 0037 * The <code>EventGenerator</code> also manages information about the 0038 * run such as the exceptions being thrown, files to write output and 0039 * error messages to, etc. 0040 * 0041 * There are three main external member functions:<BR> 0042 * go() generates a specified number of events and exits.<BR> 0043 * 0044 * shoot() generates one Event and returns it.<BR> 0045 * 0046 * generateEvent() takes an initial Step or a partially generated 0047 * Event as argument and generates subsequent steps defined in the 0048 * generator.<BR> 0049 * 0050 * doShoot() is a virtual function called by shoot() and may be 0051 * overridden in sub-classes.<BR> 0052 * 0053 * doGenrateEvent() is a virtual function called by generateEvent() and 0054 * may to be overridden in sub-classes. 0055 * 0056 * @see \ref EventGeneratorInterfaces "The interfaces" 0057 * defined for EventGenerator. 0058 * @see Interfaced 0059 * @see RandomGenerator 0060 * @see StandardModelBase 0061 * @see Strategy 0062 * @see ParticleData 0063 * @see Event 0064 * @see Step 0065 * @see FullEventGenerator 0066 * 0067 */ 0068 class EventGenerator: public Interfaced { 0069 0070 /** The Repository is a friend. */ 0071 friend class Repository; 0072 0073 public: 0074 0075 /** A map of integers giving the number of times an exception of the 0076 * key type has been thrown. */ 0077 //typedef map<const type_info *, int> ExceptionMap; 0078 //typedef map<Exception, int, ExceptionComparison > ExceptionMap; 0079 typedef map<pair<string, Exception::Severity>, int> ExceptionMap; 0080 0081 public: 0082 0083 /** @name Standard constructors and destructors. */ 0084 //@{ 0085 /** 0086 * Default constructor. 0087 */ 0088 EventGenerator(); 0089 0090 /** 0091 * Copy-constructor. 0092 */ 0093 EventGenerator(const EventGenerator &); 0094 0095 /** 0096 * Destructor. 0097 */ 0098 virtual ~EventGenerator(); 0099 //@} 0100 0101 public: 0102 0103 /** @name Access special objects in the run. */ 0104 //@{ 0105 /** 0106 * Return a pointer to the standard model parameters. 0107 */ 0108 tSMPtr standardModel() const { return theStandardModel; } 0109 0110 /** 0111 * Return a pointer to the strategy object containing a set of 0112 * non-default particles to use. 0113 */ 0114 tStrategyPtr strategy() const { return theStrategy; } 0115 0116 /** 0117 * Get the currently active EventHandler. 0118 */ 0119 tEHPtr currentEventHandler() const { return theCurrentEventHandler; } 0120 0121 /** 0122 * Set the currently active EventHandler. 0123 */ 0124 void currentEventHandler(tEHPtr eh) { theCurrentEventHandler = eh; } 0125 0126 /** 0127 * Get the currently active step handler. 0128 */ 0129 tStepHdlPtr currentStepHandler() const { return theCurrentStepHandler; } 0130 0131 /** 0132 * Set the currently active step handler. 0133 */ 0134 void currentStepHandler(tStepHdlPtr sh) { theCurrentStepHandler = sh; } 0135 0136 /** 0137 * Return a pointer to the EventHandler. 0138 */ 0139 tEHPtr eventHandler() const { return theEventHandler; } 0140 0141 /** 0142 * Return the vector of analysis objects to be used in the run. 0143 */ 0144 AnalysisVector & analysisHandlers() { return theAnalysisHandlers; } 0145 0146 /** 0147 * Return a pointer to an associated factory objects for handling 0148 * histograms to be used by <code>AnalysisHandler</code>s. 0149 */ 0150 tHistFacPtr histogramFactory() const { return theHistogramFactory; } 0151 0152 /** 0153 * Return the EventManipulator used in the run. 0154 */ 0155 tEvtManipPtr manipulator() const { return theEventManipulator; } 0156 //@} 0157 0158 public: 0159 0160 /** @name Main functions to controll the run. */ 0161 //@{ 0162 /** 0163 * Initialize this generator. This is done automatically if 'go()' 0164 * is used. Calls the virtual method doInitialize(). 0165 */ 0166 void initialize(bool initOnly = false); 0167 0168 /** 0169 * Run this EventGenerator session. Calls the virtual method doGo(). 0170 * 0171 * @param next the number of the firts event to be generated. If 0172 * negative it is assumed that this generator was previously 0173 * interrupted (or dumped to a file) and the execution will resume 0174 * from where it started. Default is 1. 0175 * @param maxevent the maximum number of events to be generated. If negative 0176 * the N() is used instead. Default is -1. 0177 * @param tics if true information the number of events generated 0178 * and elapsed time will be written to std::cerr after each event. 0179 */ 0180 void go(long next = 1, long maxevent = -1, bool tics = false); 0181 0182 /** 0183 * Generate one event. Calls the virtual method doShoot(); 0184 */ 0185 EventPtr shoot(); 0186 0187 /** 0188 * Finish generating an \a event which has already been partially 0189 * constructed from the outside. Calls the virtual method do 0190 * doGenerateEvent(). 0191 */ 0192 EventPtr generateEvent(Event & event); 0193 0194 /** 0195 * Finish generating an event starting from a \a step which has 0196 * already been partially constructed from the outside. Calls the 0197 * virtual method do doGenerateEvent(). 0198 */ 0199 EventPtr generateEvent(Step & step); 0200 0201 /** 0202 * Indicate that the run has ended and call finish() for all objects 0203 * including this one. Note that finish() should not be called 0204 * directly. 0205 */ 0206 void finalize(); 0207 0208 /** 0209 * Dynamically load the Main class in the given \a file, making it 0210 * run its Init() method where it may use this EventGenerator. Also 0211 * call the initialize function before and the finish() function 0212 * afterwards. 0213 */ 0214 bool loadMain(string file); 0215 0216 /** 0217 * Return the maximum center of mass energy possible for an 0218 * event. Return zero if the assigned EventHander is not able to 0219 * generatr full events. 0220 */ 0221 virtual Energy maximumCMEnergy() const; 0222 0223 /** 0224 * The number of the event currently being generated. 0225 */ 0226 long currentEventNumber() const { return ieve; } 0227 0228 /** 0229 * Return the event being generated. 0230 */ 0231 tcEventPtr currentEvent() const; 0232 0233 /** 0234 * Dump the full state of the current run - including the number of 0235 * generated events, so that it can be fully continued from this point. 0236 */ 0237 virtual void dump() const; 0238 0239 /** 0240 * Register a given object as used. Only objects registered in this 0241 * way will be included in the file with model references. 0242 */ 0243 void use(const Interfaced & i); 0244 0245 /** 0246 * Set the random seed for the global random number generator. Also 0247 * set the interfaced member variable. 0248 */ 0249 void setSeed(long seed); 0250 0251 /** 0252 * Log a given exception. 0253 */ 0254 void logWarning(const Exception &); 0255 0256 /** 0257 * The number of events to be generated in this run. 0258 */ 0259 long N() const { return theNumberOfEvents; } 0260 0261 /** 0262 * Histogram scale. A histogram bin which has been filled with the 0263 * weights associated with the Event objects should be scaled by 0264 * this factor to give the correct cross section. 0265 */ 0266 CrossSection histogramScale() const; 0267 0268 /** 0269 * The total integrated cross section of the processes generated in 0270 * this run. 0271 */ 0272 CrossSection integratedXSec() const; 0273 0274 /** 0275 * The error estimate for the total integrated cross section of the 0276 * processes generated in this run. 0277 */ 0278 CrossSection integratedXSecErr() const; 0279 0280 /** 0281 * The sum of all weight of the events generated so far. 0282 */ 0283 double sumWeights() const { return weightSum; } 0284 //@} 0285 0286 /** @name Functions for accessing output files. */ 0287 //@{ 0288 /** 0289 * The base filename used in this run. The actual files are called 0290 * <code>filename.run</code>, <code>filename.dump</code>, 0291 * <code>filename.out</code>, <code>filename.log</code> and 0292 * <code>filename.tex</code> for the input configuration file, 0293 * output dump file, output file, log file, and reference 0294 * file respectively. The filename is constructed from the path() 0295 * and runName(). 0296 */ 0297 string filename() const { return path() + "/" + runName(); } 0298 0299 /** 0300 * Return the name assigned to this run. If no name is given, the 0301 * name of the EventGenerator object is returned. 0302 */ 0303 string runName() const { return theRunName.size()? theRunName: name(); } 0304 0305 /** 0306 * The directory in which the filename() is located 0307 */ 0308 string path() const { return thePath; } 0309 0310 /** 0311 * Has the generator been asked to redirect everything to standard 0312 * output? 0313 */ 0314 bool useStdOut() const { return useStdout; } 0315 0316 /** 0317 * Open all ouput files. 0318 */ 0319 void openOutputFiles(); 0320 0321 /** 0322 * Flush the content of the internal output string stream to the .out file. 0323 */ 0324 void flushOutputFile(); 0325 0326 /** 0327 * Close all ouput files. 0328 */ 0329 void closeOutputFiles(); 0330 0331 /** 0332 * Return a reference to the output file stream. 0333 */ 0334 ofstream & outfile() { return theOutfile; } 0335 0336 /** 0337 * Return a reference to the log file stream. 0338 */ 0339 ofstream & logfile() { return theLogfile; } 0340 0341 /** 0342 * Return a reference to the reference file stream. This file is 0343 * used to output LaTeX text with information about the models used 0344 * in the run. 0345 */ 0346 ofstream & reffile() { return theReffile; } 0347 0348 /** 0349 * This stream should be used for output of information and 0350 * statistics of an EventGenerator run in the finish() phase, after 0351 * the actual generation has finished. When used at other times, the 0352 * output will be cashed internally before written out in the 0353 * finish() phase. This is then written to the .out file, or if 0354 * useStdOut() is true, to BaseRepository::cout(). 0355 */ 0356 ostream & out(); 0357 0358 /** 0359 * Return a reference to the stream connected to the file for logging 0360 * information. If no file is connected, BaseRepository::cout() will 0361 * be used instead. 0362 */ 0363 ostream & log(); 0364 0365 /** 0366 * Return a reference to a stream to be used to redirect cout for 0367 * external modules which prints out messages there. The output will 0368 * instead be appended to the log() stream at the end of the run. 0369 */ 0370 ostream & misc() { 0371 return theMiscStream; 0372 } 0373 0374 /** 0375 * Return a reference to the stream connected to the filea for 0376 * references from used objects. If no file is connected, 0377 * BaseRepository::cout() will be used instead. 0378 */ 0379 ostream & ref(); 0380 //@} 0381 0382 /** @name Access objects included in this run. */ 0383 //@{ 0384 /** 0385 * Return the set of objects used in this run. 0386 */ 0387 const ObjectSet & objects() const { return theObjects; } 0388 0389 0390 /** 0391 * Return the map of objects used in this run indexed by their name. 0392 */ 0393 const ObjectMap & objectMap() const { return theObjectMap; } 0394 0395 /** 0396 * Return a garbage collected pointer to a given object. If the 0397 * object is not included in the run, a null pointer will be 0398 * returned. 0399 */ 0400 template <typename T> 0401 typename Ptr<T>::pointer getPtr(const T &) const; 0402 0403 /** 0404 * Return a pointer to an object present in this run given its full 0405 * name. Return the null pointer if non-existent. 0406 */ 0407 IBPtr getPointer(string name) const; 0408 0409 /** 0410 * Return a pointer to an object of type T present in this run given 0411 * its full name. Return the null pointer if non-existent. Calls 0412 * getPointer(string) and dynamically casts the result to the 0413 * requested pointer type. 0414 */ 0415 template <typename T> 0416 typename Ptr<T>::pointer getObject(string name) const { 0417 return dynamic_ptr_cast<typename Ptr<T>::pointer>(getPointer(name)); 0418 } 0419 0420 /** 0421 * Return the default object for class T. Returns the null pointer 0422 * if non-existent. 0423 */ 0424 template <typename T> 0425 typename Ptr<T>::pointer getDefault() const; 0426 0427 /** 0428 * Create a particle instance corresponding to the given \a id 0429 * number. 0430 */ 0431 PPtr getParticle(PID id) const; 0432 0433 /** 0434 * Return a pointer to the ParticleData object corresponding to the 0435 * given \a id number. 0436 */ 0437 PDPtr getParticleData(PID id) const; 0438 0439 /** 0440 * Return a reference to the complete list of matchers in this 0441 * generator. 0442 */ 0443 const MatcherSet & matchers() const { return theMatchers; } 0444 0445 /** 0446 * Return a reference to the complete map of particle data objects 0447 * in this generator, indexed by their id numbers. 0448 */ 0449 const ParticleMap & particles() const { return theParticles; } 0450 0451 /** 0452 * Return a reference to the set of objects which have been 0453 * registered as used during the current run. 0454 */ 0455 const ObjectSet & used() const { return usedObjects; } 0456 //@} 0457 0458 protected: 0459 0460 /** 0461 * Check if there has been an interrupt signal from the OS. 0462 * If that's the case, finalize() is called 0463 */ 0464 void checkSignalState(); 0465 0466 /** 0467 * Return a reference to the default RandomGenerator object in this 0468 * run. 0469 */ 0470 RandomGenerator & random() const { return *theRandom; } 0471 0472 /** 0473 * Finish the setup of an event generator run. Set run name, all 0474 * particles, matchers and other objects to be used. Is used by the 0475 * Repository when isolating an EventGenerator. 0476 */ 0477 void setup(string newRunName, ObjectSet & newObjects, 0478 ParticleMap & newParticles, MatcherSet & newMatchers); 0479 0480 /** @name Main virtual functions to be overridden by sub-classes. */ 0481 //@{ 0482 /** 0483 * Run this EventGenerator session. Is called from go(long,long,bool). 0484 */ 0485 virtual void doGo(long next, long maxevent, bool tics); 0486 0487 /** 0488 * Initialize this generator. Is called from initialize(). 0489 */ 0490 virtual void doInitialize(bool initOnly = false); 0491 0492 /** 0493 * Generate one event. Is called from shoot(). 0494 */ 0495 virtual EventPtr doShoot(); 0496 0497 /** 0498 * Write out the number of events generated and the elapsed time in 0499 * suitable periods. 0500 */ 0501 void tic(long currev = 0, long totev = 0) const; 0502 0503 /** 0504 * Finish generating an event constructed from the outside. Is 0505 * called by generateEvent(tEventPtr). 0506 */ 0507 virtual EventPtr doGenerateEvent(tEventPtr); 0508 0509 /** 0510 * Finish generating an event starting from a Step constructed from 0511 * the outside. Is called by generateEvent(tStepPtr). 0512 */ 0513 virtual EventPtr doGenerateEvent(tStepPtr); 0514 //@} 0515 0516 /** 0517 * Print the message of an exception to the log file. 0518 */ 0519 void printException(const Exception &); 0520 0521 /** 0522 * Log a given exception. 0523 */ 0524 bool logException(const Exception &, tcEventPtr); 0525 0526 /** 0527 * Set number of events to be generated. 0528 */ 0529 void N(long n) { theNumberOfEvents = n; } 0530 0531 /** 0532 * Set the name of this run 0533 */ 0534 void runName(string f) { theRunName = f; } 0535 0536 public: 0537 0538 /** 0539 * Append a tag to the run name. Derived classes may put special 0540 * meaning to the tags. 0541 */ 0542 virtual void addTag(string tag) { 0543 runName(runName() + tag); 0544 } 0545 0546 private: 0547 0548 /** 0549 * Return the vector of default objects. 0550 */ 0551 const vector<IPtr> & defaultObjects() const { return theDefaultObjects; } 0552 0553 /** 0554 * Access the special particles used in this generator. Not relevant 0555 * in the run phase. 0556 */ 0557 ParticleMap & localParticles() { return theLocalParticles; } 0558 0559 /** 0560 * Access the special particles used in this generator. Not relevant 0561 * in the run phase. 0562 */ 0563 const ParticleMap & localParticles() const { return theLocalParticles; } 0564 0565 /** 0566 * Set the directory where the output files will be stored. 0567 */ 0568 void path(string f) { thePath = f; } 0569 0570 /** 0571 * Set a pointer to the strategy object containing a set of 0572 * non-default particles to use. 0573 */ 0574 void strategy(StrategyPtr); 0575 0576 /** 0577 * Isolate, initialize and save this generator to a file. 0578 */ 0579 string doSaveRun(string); 0580 0581 /** 0582 * Isolate and initialize this generator. 0583 */ 0584 string doMakeRun(string); 0585 0586 public: 0587 0588 /** @name The following functions may be called by objects belonging 0589 to this event generator during the initialization phase (in the 0590 doinit() function). It is typically used by objects which need 0591 to introduce other Interfaced objects depending the parameters 0592 of the StandardModel object used. Note that objects which use 0593 these functions <b>MUST</b> override the preInitialize() 0594 function to return true, otherwize the whole initialization 0595 procedure may be corrupted. */ 0596 //@{ 0597 /** 0598 * Register a new object to be included in the run currently being 0599 * initialized. 0600 * 0601 * @param obj (pointer to) the object being registered. 0602 * 0603 * @param fullname the full name including the directory path. Note 0604 * that although the full path is given the object will not be 0605 * inserted in the Repository, but only in this current 0606 * EventGenerator. 0607 * 0608 * @return false if another object of that name already exists. 0609 */ 0610 bool preinitRegister(IPtr obj, string fullname); 0611 0612 /** 0613 * Create a new Interfaced object to be used in the run being 0614 * initialized. 0615 * 0616 * @param classname the class name of the object being created. 0617 * 0618 * @param fullname the full name including the directory path. Note 0619 * that although the full path is given the object will not be 0620 * inserted in the Repository, but only in this current 0621 * EventGenerator. 0622 * 0623 * @param libraries an optional list of shared libraries to be 0624 * loaded to be able to create an object of the specified class. 0625 * 0626 * @return the created object if the it was successfully 0627 * created. Return null if the object could not be created or if 0628 * another object of that name already exists. 0629 */ 0630 IPtr preinitCreate(string classname, string fullname, string libraries = ""); 0631 0632 0633 /** 0634 * Manipulate an interface of an Interfaced object. 0635 * 0636 * @param fullname the name including the full path of an object to 0637 * be manipulated. 0638 * 0639 * @param ifcname the name of the interface to be used. 0640 * 0641 * @param cmd the operation to be performed on the interface (set or 0642 * get). 0643 * 0644 * @param value Optional value to be passed to the interface. 0645 * 0646 * @return a string containing the result of the operation. If this 0647 * string starts with "Error: " then something went wrong. 0648 */ 0649 string preinitInterface(string fullname, string ifcname, string cmd, 0650 string value); 0651 0652 /** 0653 * Manipulate an interface of vector type (RefVector or ParVector) 0654 * of an Interfaced object. 0655 * 0656 * @param fullname the name including the full path of an object to 0657 * be manipulated. 0658 * 0659 * @param ifcname the name of the interface to be used. 0660 * 0661 * @param index the vector index corresponding to the element to be 0662 * manipulated. 0663 * 0664 * @param cmd the operation to be performed on the interface (set, 0665 * get, insert or erase). 0666 * 0667 * @param value Optional value to be passed to the interface. 0668 * 0669 * @return a string containing the result of the operation. If this 0670 * string starts with "Error: " then something went wrong. 0671 */ 0672 string preinitInterface(string fullname, string ifcname, int index, 0673 string cmd, string value); 0674 0675 /** 0676 * Manipulate an interface of an Interfaced object. 0677 * 0678 * @param obj the object to be manipulated. 0679 * 0680 * @param ifcname the name of the interface to be used. 0681 * 0682 * @param cmd the operation to be performed on the interface (set or 0683 * get). 0684 * 0685 * @param value Optional value to be passed to the interface. 0686 * 0687 * @return a string containing the result of the operation. If this 0688 * string starts with "Error: " then something went wrong. 0689 */ 0690 string preinitInterface(IPtr obj, string ifcname, string cmd, string value); 0691 0692 /** 0693 * Manipulate an interface of vector type (RefVector or ParVector) 0694 * of an Interfaced object. 0695 * 0696 * @param obj the object to be manipulated. 0697 * 0698 * @param ifcname the name of the interface to be used. 0699 * 0700 * @param index the vector index corresponding to the element to be 0701 * manipulated. 0702 * 0703 * @param cmd the operation to be performed on the interface (set, 0704 * get, insert or erase). 0705 * 0706 * @param value Optional value to be passed to the interface. 0707 * 0708 * @return a string containing the result of the operation. If this 0709 * string starts with "Error: " then something went wrong. 0710 */ 0711 string preinitInterface(IPtr obj, string ifcname, int index, 0712 string cmd, string value); 0713 0714 /** 0715 * Remove the object 0716 */ 0717 bool preinitRemove(IPtr obj); 0718 0719 /** 0720 * Find a decaymode given a decay \a tag. 0721 * @return null if no decay mode was found. 0722 */ 0723 tDMPtr findDecayMode(string tag) const; 0724 0725 /** 0726 * Create a decay mode according to the given tag. 0727 * @return null if no decay mode could be created. 0728 */ 0729 tDMPtr preinitCreateDecayMode(string tag); 0730 0731 /** 0732 * Find a particle in this run, using its PDG name. 0733 * @return null if no particle is found. 0734 */ 0735 tPDPtr findParticle(string pdgname) const; 0736 0737 /** 0738 * Find a matcher in this run given its \a name. 0739 * @return null if no mather is found. 0740 */ 0741 tPMPtr findMatcher(string name) const; 0742 0743 private: 0744 0745 /** 0746 * Used internally by preinitCreateDecayMode(); 0747 */ 0748 DMPtr constructDecayMode(string & tag); 0749 0750 //@} 0751 0752 public: 0753 0754 0755 /** @name Functions used by the persistent I/O system. */ 0756 //@{ 0757 /** 0758 * Function used to write out object persistently. 0759 * @param os the persistent output stream written to. 0760 */ 0761 void persistentOutput(PersistentOStream & os) const; 0762 0763 /** 0764 * Function used to read in object persistently. 0765 * @param is the persistent input stream read from. 0766 * @param version the version number of the object when written. 0767 */ 0768 void persistentInput(PersistentIStream & is, int version); 0769 0770 /** 0771 * The global libraries needed for objects used in this EventGenerator. 0772 */ 0773 const vector<string> & globalLibraries() const { 0774 return theGlobalLibraries; 0775 } 0776 0777 //@} 0778 0779 /** 0780 * Standard Init function used to initialize the interface. 0781 */ 0782 static void Init(); 0783 0784 protected: 0785 0786 /** @name Clone Methods. */ 0787 //@{ 0788 /** 0789 * Make a simple clone of this object. 0790 * @return a pointer to the new object. 0791 */ 0792 virtual IBPtr clone() const; 0793 0794 /** Make a clone of this object, possibly modifying the cloned object 0795 * to make it sane. 0796 * @return a pointer to the new object. 0797 */ 0798 virtual IBPtr fullclone() const; 0799 //@} 0800 0801 protected: 0802 0803 /** @name Standard Interfaced functions. */ 0804 //@{ 0805 /** 0806 * Initialize this object after the setup phase before saving an 0807 * EventGenerator to disk. 0808 * @throws InitException if object could not be initialized properly. 0809 */ 0810 virtual void doinit(); 0811 0812 /** 0813 * Initialize this object. Called in the run phase just before 0814 * a run begins. 0815 */ 0816 virtual void doinitrun(); 0817 0818 /** 0819 * Finalize this object. Called in the run phase just after a 0820 * run has ended. Used eg. to write out statistics. 0821 */ 0822 virtual void dofinish(); 0823 0824 /** 0825 * Additional things to do at the very end after the (do)finish(), 0826 * such as closing output files etc. 0827 */ 0828 void finally(); 0829 0830 //@} 0831 0832 /** 0833 * Return the set of all objects to be used in this run. 0834 */ 0835 ObjectSet & objects() { return theObjects; } 0836 0837 /** 0838 * Return the map of all objects to be used in this run indexed by 0839 * their name. 0840 */ 0841 ObjectMap & objectMap() { return theObjectMap; } 0842 0843 /** 0844 * Print out the .tex file with descriptions of and references to 0845 * all models used in the run. 0846 */ 0847 void generateReferences(); 0848 0849 /** 0850 * Increase and return the count for the given exception. 0851 */ 0852 int count(const Exception &); 0853 0854 private: 0855 0856 0857 /** 0858 * A vector of default objects. 0859 */ 0860 vector<IPtr> theDefaultObjects; 0861 0862 /** 0863 * Map of non-default particles used in this EventGenerator. 0864 */ 0865 ParticleMap theLocalParticles; 0866 0867 /** 0868 * Pointer to an object containing standard model parameters. 0869 */ 0870 SMPtr theStandardModel; 0871 0872 /** 0873 * Pointer to a strategy object with other non-default particles to 0874 * be used in this EventGenerator. 0875 */ 0876 StrategyPtr theStrategy; 0877 0878 /** 0879 * Pointer to the default RandomGenerator to be used in this run. 0880 */ 0881 RanGenPtr theRandom; 0882 0883 /** 0884 * Pointer to the event handler used to generate the indivudual 0885 * events. 0886 */ 0887 EHPtr theEventHandler; 0888 0889 /** 0890 * A vector of all analysis handlers to be called after each event. 0891 */ 0892 AnalysisVector theAnalysisHandlers; 0893 0894 /** 0895 * A pointer to an associated factory objects for handling 0896 * histograms to be used by <code>AnalysisHandler</code>s. 0897 */ 0898 HistFacPtr theHistogramFactory; 0899 0900 /** 0901 * A pointer to an optional event manipulator object. 0902 */ 0903 EvtManipPtr theEventManipulator; 0904 0905 /** 0906 * The directory where the input and output files resides. 0907 */ 0908 string thePath; 0909 0910 /** 0911 * The name of this run. 0912 */ 0913 string theRunName; 0914 0915 /** 0916 * A reference to the output file stream. 0917 */ 0918 ofstream theOutfile; 0919 0920 /** 0921 * A reference to the log file stream. 0922 */ 0923 ofstream theLogfile; 0924 0925 /** 0926 * A reference to the reference file stream. 0927 */ 0928 ofstream theReffile; 0929 0930 /** 0931 * A stream to be used to redirect cout for external modules which 0932 * prints out messages there. The output will instead be appended to 0933 * the log() stream at the end of the run. 0934 */ 0935 ostringstream theMiscStream; 0936 0937 /** 0938 * A string stream used as a buffer for messages written to the .out 0939 * file. The .out file should in rinciple only be written to in the 0940 * end of a run, during the finish() phase, but if anything is 0941 * written before that, it will be cashed in this string stream 0942 * before written out properly in the end of the run. 0943 */ 0944 ostringstream theOutStream; 0945 0946 /** 0947 * Remember the name of the file where the output should be 0948 * sent. This is set int openOutputFiles(). 0949 */ 0950 string theOutFileName; 0951 0952 /** 0953 * Number of events to be generated in this run. 0954 */ 0955 long theNumberOfEvents; 0956 0957 /** 0958 * The set of all objects to be used in this run. 0959 */ 0960 ObjectSet theObjects; 0961 0962 /** 0963 * All objects to be used in this run mapped to their name. 0964 */ 0965 ObjectMap theObjectMap; 0966 0967 /** 0968 * The map of all particles to be used in this run, indexed by the 0969 * id number. 0970 */ 0971 ParticleMap theParticles; 0972 /** 0973 * A vector of particles indexed by the id number for quick access. 0974 * Only particles with id number less than theQuickSize are 0975 * available. 0976 */ 0977 PDVector theQuickParticles; 0978 0979 /** 0980 * Only particles with id number less than theQuickSize are 0981 * available in theQuickParticles. 0982 */ 0983 long theQuickSize; 0984 0985 /** 0986 * A flag to tell if we are in the pre-initialization phase where 0987 * objects with preInitialize() functions returning true are 0988 * initialized before others. 0989 */ 0990 bool preinitializing; 0991 0992 /** 0993 * The set of all matchers to be used in this run. 0994 */ 0995 MatcherSet theMatchers; 0996 0997 /** 0998 * The set of objects which have actually been used in this run. 0999 */ 1000 ObjectSet usedObjects; 1001 1002 protected: 1003 1004 /** 1005 * The current event number; 1006 */ 1007 long ieve; 1008 1009 /** 1010 * The sum of the weights of the events produced so far. 1011 */ 1012 double weightSum; 1013 1014 /** 1015 * The debug level. 1016 */ 1017 int theDebugLevel; 1018 1019 private: 1020 1021 /** 1022 * List all modified interfaces in the log file. If positive always 1023 * do this, if negative never do it. If zero, only do it if 1024 * debugging is turned on. 1025 */ 1026 int logNonDefault; 1027 1028 /** 1029 * If the debug level is higher than 0, print the first 'printEvent' 1030 * events to the logfile. 1031 */ 1032 int printEvent; 1033 1034 /** 1035 * If the debug level is higher than 0, dump the complete state of 1036 * this run to the default dump file every 'dumpPeriod' events. 1037 * If 'dumpPeriod' is -1, dumping is disabled completely, 1038 * even when runs are aborted. 1039 */ 1040 long dumpPeriod; 1041 1042 /** 1043 * If this flag is true, keep all dump files of the run, 1044 * labelled by event number. 1045 */ 1046 bool keepAllDumps; 1047 1048 /** 1049 * If the debug level is higher than 0, step up to the highest debug 1050 * level just before the event with number debugEvent is performed. 1051 */ 1052 long debugEvent; 1053 1054 /** 1055 * The maximum number of warnings reported of each type. If more 1056 * than maxWarnings warnings of one type is issued, the generation 1057 * will continue without reporting this warning. 1058 */ 1059 int maxWarnings; 1060 1061 /** 1062 * The maximum number of warnings and errors reported of each 1063 * type. If more than maxErrors errors is reported for one type the 1064 * run will be aborted. Disable the check by setting to -1. 1065 */ 1066 int maxErrors; 1067 1068 /** 1069 * A map of all Exceptions which have been caught by the event 1070 * generator and the number of time each exception type has been 1071 * caught. 1072 */ 1073 ExceptionMap theExceptions; 1074 1075 private: 1076 1077 /** 1078 * Utility function for the interface. 1079 */ 1080 void setLocalParticles(PDPtr pd, int); 1081 1082 /** 1083 * Utility function for the interface. 1084 */ 1085 void insLocalParticles(PDPtr pd, int); 1086 1087 /** 1088 * Utility function for the interface. 1089 */ 1090 void delLocalParticles(int place); 1091 1092 /** 1093 * Utility function for the interface. 1094 */ 1095 vector<PDPtr> getLocalParticles() const; 1096 1097 /** 1098 * Utility function for the interface. 1099 */ 1100 void setPath(string newPath); 1101 1102 /** 1103 * Utility function for the interface. 1104 */ 1105 string defPath() const; 1106 1107 /** 1108 * The UseRandom object constructed for the duration of an 1109 * EventGenerator run so that the default random number generator 1110 * always can be accessed through the static methods of the 1111 * UseRandom class. 1112 */ 1113 UseRandom * theCurrentRandom; 1114 1115 /** 1116 * The CurrentGenerator object constructed for the duration of an 1117 * EventGenerator run so that the default event generator always can 1118 * be accessed through the static methods of the CurrentGenerator 1119 * class. 1120 */ 1121 CurrentGenerator * theCurrentGenerator; 1122 1123 /** 1124 * The currently active EventHandler. 1125 */ 1126 tEHPtr theCurrentEventHandler; 1127 1128 /** 1129 * The currently active step handler. 1130 */ 1131 tStepHdlPtr theCurrentStepHandler; 1132 1133 1134 /** 1135 * Whether to use files or stdout for logging and output. 1136 */ 1137 bool useStdout; 1138 1139 /** 1140 * Whether to use a modified event number count. 1141 */ 1142 bool theIntermediateOutput; 1143 1144 /** 1145 * The global libraries needed for objects used in this EventGenerator. 1146 */ 1147 vector<string> theGlobalLibraries; 1148 1149 private: 1150 1151 /** 1152 * Describe an abstract class with persistent data. 1153 */ 1154 static ClassDescription<EventGenerator> initEventGenerator; 1155 1156 /** 1157 * Private and non-existent assignment operator. 1158 */ 1159 EventGenerator & operator=(const EventGenerator &) = delete; 1160 1161 }; 1162 1163 /** @cond TRAITSPECIALIZATIONS */ 1164 1165 /** This template specialization informs ThePEG about the base classes 1166 * of EventGenerator. */ 1167 template <> 1168 struct BaseClassTrait<EventGenerator,1>: public ClassTraitsType { 1169 /** Typedef of the first base class of EventGenerator. */ 1170 typedef Interfaced NthBase; 1171 }; 1172 1173 /** This template specialization informs ThePEG about the name of the 1174 * EventGenerator class. */ 1175 template <> 1176 struct ClassTraits<EventGenerator>: public ClassTraitsBase<EventGenerator> { 1177 /** Return a platform-independent class name */ 1178 static string className() { return "ThePEG::EventGenerator"; } 1179 }; 1180 1181 /** @endcond */ 1182 1183 } 1184 1185 #ifndef ThePEG_TEMPLATES_IN_CC_FILE 1186 #include "EventGenerator.tcc" 1187 #endif 1188 1189 #endif /* ThePEG_EventGenerator_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|