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 
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 
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 */