00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_EventGenerator_H
00010 #define ThePEG_EventGenerator_H
00011
00012
00013 #include "ThePEG/Config/ThePEG.h"
00014 #include "ThePEG/Utilities/Named.h"
00015 #include "EventGenerator.fh"
00016 #include "RandomGenerator.h"
00017 #include "ThePEG/Repository/UseRandom.h"
00018 #include "ThePEG/Repository/Strategy.h"
00019 #include "ThePEG/Repository/CurrentGenerator.fh"
00020 #include "ThePEG/Utilities/ClassDescription.h"
00021 #include "ThePEG/Handlers/EventHandler.fh"
00022 #include "ThePEG/Analysis/FactoryBase.fh"
00023 #include <fstream>
00024 #include "EventGenerator.xh"
00025
00026 namespace ThePEG {
00027
00068 class EventGenerator: public Interfaced {
00069
00071 friend class Repository;
00072
00073 public:
00074
00077
00078
00079 typedef map<pair<string, Exception::Severity>, int> ExceptionMap;
00080
00081 public:
00082
00088 EventGenerator();
00089
00093 EventGenerator(const EventGenerator &);
00094
00098 virtual ~EventGenerator();
00100
00101 public:
00102
00108 tSMPtr standardModel() const { return theStandardModel; }
00109
00114 tStrategyPtr strategy() const { return theStrategy; }
00115
00119 tEHPtr currentEventHandler() const { return theCurrentEventHandler; }
00120
00124 void currentEventHandler(tEHPtr eh) { theCurrentEventHandler = eh; }
00125
00129 tStepHdlPtr currentStepHandler() const { return theCurrentStepHandler; }
00130
00134 void currentStepHandler(tStepHdlPtr sh) { theCurrentStepHandler = sh; }
00135
00139 tEHPtr eventHandler() const { return theEventHandler; }
00140
00144 AnalysisVector & analysisHandlers() { return theAnalysisHandlers; }
00145
00150 tHistFacPtr histogramFactory() const { return theHistogramFactory; }
00151
00155 tEvtManipPtr manipulator() const { return theEventManipulator; }
00157
00158 public:
00159
00166 void initialize();
00167
00180 void go(long next = 1, long maxevent = -1, bool tics = false);
00181
00185 EventPtr shoot();
00186
00192 EventPtr generateEvent(Event & event);
00193
00199 EventPtr generateEvent(Step & step);
00200
00206 void finalize();
00207
00214 bool loadMain(string file);
00215
00221 virtual Energy maximumCMEnergy() const;
00222
00226 long currentEventNumber() const { return ieve; }
00227
00231 tcEventPtr currentEvent() const;
00232
00237 virtual void dump() const;
00238
00243 void use(const Interfaced & i);
00244
00248 void setSeed(long seed) { random().setSeed(seed); }
00249
00253 void logWarning(const Exception &);
00254
00258 long N() const { return theNumberOfEvents; }
00259
00265 CrossSection histogramScale() const;
00266
00271 CrossSection integratedXSec() const;
00272
00277 CrossSection integratedXSecErr() const;
00278
00282 double sumWeights() const { return weightSum; }
00284
00296 string filename() const { return path() + "/" + runName(); }
00297
00302 string runName() const { return theRunName.size()? theRunName: name(); }
00303
00307 string path() const { return thePath; }
00308
00313 bool useStdOut() const { return useStdout; }
00314
00318 void openOutputFiles();
00319
00323 void closeOutputFiles();
00324
00328 ofstream & outfile() { return theOutfile; }
00329
00333 ofstream & logfile() { return theLogfile; }
00334
00340 ofstream & reffile() { return theReffile; }
00341
00347 ostream & out();
00348
00354 ostream & log();
00355
00361 ostream & misc() {
00362 return theMiscStream;
00363 }
00364
00370 ostream & ref();
00372
00378 const ObjectSet & objects() const { return theObjects; }
00379
00380
00384 const ObjectMap & objectMap() const { return theObjectMap; }
00385
00391 template <typename T>
00392 typename Ptr<T>::pointer getPtr(const T &) const;
00393
00398 IBPtr getPointer(string name) const;
00399
00406 template <typename T>
00407 typename Ptr<T>::pointer getObject(string name) const {
00408 return dynamic_ptr_cast<typename Ptr<T>::pointer>(getPointer(name));
00409 }
00410
00415 template <typename T>
00416 typename Ptr<T>::pointer getDefault() const;
00417
00422 PPtr getParticle(long id) const;
00423
00428 PDPtr getParticleData(long id) const;
00429
00434 const MatcherSet & matchers() const { return theMatchers; }
00435
00440 const ParticleMap & particles() const { return theParticles; }
00441
00446 const ObjectSet & used() const { return usedObjects; }
00448
00449 protected:
00450
00455 void checkSignalState();
00456
00461 RandomGenerator & random() const { return *theRandom; }
00462
00468 void setup(string newRunName, ObjectSet & newObjects,
00469 ParticleMap & newParticles, MatcherSet & newMatchers);
00470
00476 virtual void doGo(long next, long maxevent, bool tics);
00477
00481 virtual void doInitialize();
00482
00486 virtual EventPtr doShoot();
00487
00492 void tic(long currev = 0, long totev = 0) const;
00493
00498 virtual EventPtr doGenerateEvent(tEventPtr);
00499
00504 virtual EventPtr doGenerateEvent(tStepPtr);
00506
00510 void printException(const Exception &);
00511
00515 bool logException(const Exception &, tcEventPtr);
00516
00520 void N(long n) { theNumberOfEvents = n; }
00521
00525 void runName(string f) { theRunName = f; }
00526
00527 private:
00528
00532 const vector<IPtr> & defaultObjects() const { return theDefaultObjects; }
00533
00538 ParticleMap & localParticles() { return theLocalParticles; }
00539
00544 const ParticleMap & localParticles() const { return theLocalParticles; }
00545
00549 void path(string f) { thePath = f; }
00550
00555 void strategy(StrategyPtr);
00556
00560 string doSaveRun(string);
00561
00565 string doMakeRun(string);
00566
00567 public:
00568
00591 bool preinitRegister(IPtr obj, string fullname);
00592
00611 IPtr preinitCreate(string classname, string fullname, string libraries = "");
00612
00613
00630 string preinitInterface(string fullname, string ifcname, string cmd,
00631 string value);
00632
00653 string preinitInterface(string fullname, string ifcname, int index,
00654 string cmd, string value);
00655
00671 string preinitInterface(IPtr obj, string ifcname, string cmd, string value);
00672
00692 string preinitInterface(IPtr obj, string ifcname, int index,
00693 string cmd, string value);
00694
00699 tDMPtr findDecayMode(string tag) const;
00700
00705 tDMPtr preinitCreateDecayMode(string tag);
00706
00711 tPDPtr findParticle(string pdgname) const;
00712
00717 tPMPtr findMatcher(string name) const;
00718
00719 private:
00720
00724 DMPtr constructDecayMode(string & tag);
00725
00727
00728 public:
00729
00730
00737 void persistentOutput(PersistentOStream & os) const;
00738
00744 void persistentInput(PersistentIStream & is, int version);
00746
00750 static void Init();
00751
00752 protected:
00753
00760 virtual IBPtr clone() const;
00761
00766 virtual IBPtr fullclone() const;
00768
00769 protected:
00770
00778 virtual void doinit();
00779
00784 virtual void doinitrun();
00785
00790 virtual void dofinish();
00791
00796 void finally();
00797
00799
00803 ObjectSet & objects() { return theObjects; }
00804
00809 ObjectMap & objectMap() { return theObjectMap; }
00810
00815 void generateReferences();
00816
00820 int count(const Exception &);
00821
00822 private:
00823
00824
00828 vector<IPtr> theDefaultObjects;
00829
00833 ParticleMap theLocalParticles;
00834
00838 SMPtr theStandardModel;
00839
00844 StrategyPtr theStrategy;
00845
00849 RanGenPtr theRandom;
00850
00855 EHPtr theEventHandler;
00856
00860 AnalysisVector theAnalysisHandlers;
00861
00866 HistFacPtr theHistogramFactory;
00867
00871 EvtManipPtr theEventManipulator;
00872
00876 string thePath;
00877
00881 string theRunName;
00882
00886 ofstream theOutfile;
00887
00891 ofstream theLogfile;
00892
00896 ofstream theReffile;
00897
00903 ostringstream theMiscStream;
00904
00908 long theNumberOfEvents;
00909
00913 ObjectSet theObjects;
00914
00918 ObjectMap theObjectMap;
00919
00924 ParticleMap theParticles;
00930 PDVector theQuickParticles;
00931
00936 int theQuickSize;
00937
00943 bool preinitializing;
00944
00948 MatcherSet theMatchers;
00949
00953 ObjectSet usedObjects;
00954
00955 protected:
00956
00960 long ieve;
00961
00965 double weightSum;
00966
00970 int theDebugLevel;
00971
00972 private:
00973
00978 int printEvent;
00979
00986 long dumpPeriod;
00987
00992 long debugEvent;
00993
00999 int maxWarnings;
01000
01006 int maxErrors;
01007
01013 ExceptionMap theExceptions;
01014
01015 private:
01016
01020 void setLocalParticles(PDPtr pd, int);
01021
01025 void insLocalParticles(PDPtr pd, int);
01026
01030 void delLocalParticles(int place);
01031
01035 vector<PDPtr> getLocalParticles() const;
01036
01040 void setPath(string newPath);
01041
01045 string defPath() const;
01046
01053 UseRandom * theCurrentRandom;
01054
01061 CurrentGenerator * theCurrentGenerator;
01062
01066 tEHPtr theCurrentEventHandler;
01067
01071 tStepHdlPtr theCurrentStepHandler;
01072
01073
01077 bool useStdout;
01078
01079
01080 private:
01081
01085 static ClassDescription<EventGenerator> initEventGenerator;
01086
01090 EventGenerator & operator=(const EventGenerator &);
01091
01092 };
01093
01098 template <>
01099 struct BaseClassTrait<EventGenerator,1>: public ClassTraitsType {
01101 typedef Interfaced NthBase;
01102 };
01103
01106 template <>
01107 struct ClassTraits<EventGenerator>: public ClassTraitsBase<EventGenerator> {
01109 static string className() { return "ThePEG::EventGenerator"; }
01110 };
01111
01114 }
01115
01116 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
01117 #include "EventGenerator.tcc"
01118 #endif
01119
01120 #endif