00001 // @(#)root/eg:$Id: TGenerator.h 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Ola Nordmann 21/09/95 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 00013 ////////////////////////////////////////////////////////////////////////// 00014 // // 00015 // TGenerator // 00016 // // 00017 // Is an base class, that defines the interface of ROOT to various // 00018 // event generators. Every event generator should inherit from // 00019 // TGenerator or its subclasses. // 00020 // // 00021 // Derived class can overload the member function GenerateEvent // 00022 // to do the actual event generation (e.g., call PYEVNT or similar). // 00023 // // 00024 // The derived class should overload the member function // 00025 // ImportParticles (both types) to read the internal storage of the // 00026 // generated event into either the internal TObjArray or the passed // 00027 // TClonesArray of TParticles. // 00028 // // 00029 // If the generator code stores event data in the /HEPEVT/ common block // 00030 // Then the default implementation of ImportParticles should suffice. // 00031 // The common block /HEPEVT/ is structed like // 00032 // // 00033 // /* C */ // 00034 // typedef struct { // 00035 // Int_t nevhep; // 00036 // Int_t nhep; // 00037 // Int_t isthep[4000]; // 00038 // Int_t idhep[4000]; // 00039 // Int_t jmohep[4000][2]; // 00040 // Int_t jdahep[4000][2]; // 00041 // Double_t phep[4000][5]; // 00042 // Double_t vhep[4000][4]; // 00043 // } HEPEVT_DEF; // 00044 // // 00045 // // 00046 // C Fortran // 00047 // COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(4000),IDHEP(4000), // 00048 // + JMOHEP(2,4000),JDAHEP(2,4000),PHEP(5,4000),VHEP(4,4000) // 00049 // INTEGER NEVHEP,NHEP,ISTHEP,IDHEP,JMOHEP,JDAHEP // 00050 // DOUBLE PRECISION PHEP,VHEP // 00051 // // 00052 // The generic member functions SetParameter and GetParameter can be // 00053 // overloaded to set and get parameters of the event generator. // 00054 // // 00055 // Note, if the derived class interfaces a (set of) Fortran common // 00056 // blocks (like TPythia, TVenus does), one better make the derived // 00057 // class a singleton. That is, something like // 00058 // // 00059 // class MyGenerator : public TGenerator // 00060 // { // 00061 // public: // 00062 // static MyGenerator* Instance() // 00063 // { // 00064 // if (!fgInstance) fgInstance = new MyGenerator; // 00065 // return fgInstance; // 00066 // } // 00067 // void GenerateEvent() { ... } // 00068 // void ImportParticles(TClonesArray* a, Option_t opt="") {...} // 00069 // Int_t ImportParticles(Option_t opt="") { ... } // 00070 // Int_t SetParameter(const char* name, Double_t val) { ... } // 00071 // Double_t GetParameter(const char* name) { ... } // 00072 // virtual ~MyGenerator() { ... } // 00073 // protected: // 00074 // MyGenerator() { ... } // 00075 // MyGenerator(const MyGenerator& o) { ... } // 00076 // MyGenerator& operator=(const MyGenerator& o) { ... } // 00077 // static MyGenerator* fgInstance; // 00078 // ClassDef(MyGenerator,0); // 00079 // }; // 00080 // // 00081 // Having multiple objects accessing the same common blocks is not // 00082 // safe. // 00083 // // 00084 // concrete TGenerator classes can be loaded in scripts and subseqent- // 00085 // ly used in compiled code: // 00086 // // 00087 // // MyRun.h // 00088 // class MyRun : public TObject // 00089 // { // 00090 // public: // 00091 // static MyRun* Instance() { ... } // 00092 // void SetGenerator(TGenerator* g) { fGenerator = g; } // 00093 // void Run(Int_t n, Option_t* option="") // 00094 // { // 00095 // TFile* file = TFile::Open("file.root","RECREATE"); // 00096 // TTree* tree = new TTree("T","T"); // 00097 // TClonesArray* p = new TClonesArray("TParticles"); // 00098 // tree->Branch("particles", &p); // 00099 // for (Int_t event = 0; event < n; event++) { // 00100 // fGenerator->GenerateEvent(); // 00101 // fGenerator->ImportParticles(p,option); // 00102 // tree->Fill(); // 00103 // } // 00104 // file->Write(); // 00105 // file->Close(); // 00106 // } // 00107 // ... // 00108 // protected: // 00109 // TGenerator* fGenerator; // 00110 // ClassDef(MyRun,0); // 00111 // }; // 00112 // // 00113 // // Config.C // 00114 // void Config() // 00115 // { // 00116 // MyRun* run = MyRun::Instance(); // 00117 // run->SetGenerator(MyGenerator::Instance()); // 00118 // } // 00119 // // 00120 // // main.cxx // 00121 // int // 00122 // main(int argc, char** argv) // 00123 // { // 00124 // TApplication app("", 0, 0); // 00125 // gSystem->ProcessLine(".x Config.C"); // 00126 // MyRun::Instance()->Run(10); // 00127 // return 0; // 00128 // } // 00129 // // 00130 // This is especially useful for example with TVirtualMC or similar. // 00131 // // 00132 ////////////////////////////////////////////////////////////////////////// 00133 00134 #ifndef ROOT_TGenerator 00135 #define ROOT_TGenerator 00136 00137 #ifndef ROOT_TNamed 00138 #include "TNamed.h" 00139 #endif 00140 00141 class TBrowser; 00142 class TParticle; 00143 class TClonesArray; 00144 class TObjArray; 00145 00146 class TGenerator : public TNamed { 00147 00148 protected: 00149 Float_t fPtCut; //!Pt cut. Do not show primaries below 00150 Bool_t fShowNeutrons; //!display neutrons if true 00151 TObjArray *fParticles; //->static container of the primary particles 00152 00153 TGenerator(const TGenerator& tg) : 00154 TNamed(tg), fPtCut(tg.fPtCut), fShowNeutrons(tg.fShowNeutrons),fParticles(tg.fParticles) { } 00155 TGenerator& operator=(const TGenerator& tg) { 00156 if(this!=&tg) { 00157 TNamed::operator=(tg); fPtCut=tg.fPtCut; fShowNeutrons=tg.fShowNeutrons; 00158 fParticles=tg.fParticles; 00159 } 00160 return *this; 00161 } 00162 00163 public: 00164 00165 TGenerator(): fPtCut(0), fShowNeutrons(kTRUE), fParticles(0) { } //Used by Dictionary 00166 TGenerator(const char *name, const char *title="Generator class"); 00167 virtual ~TGenerator(); 00168 virtual void Browse(TBrowser *b); 00169 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py); 00170 virtual void Draw(Option_t *option=""); 00171 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py); 00172 virtual void GenerateEvent(); 00173 virtual Double_t GetParameter(const char* /*name*/) const { return 0.; } 00174 virtual Int_t ImportParticles(TClonesArray *particles, Option_t *option=""); 00175 virtual TObjArray *ImportParticles(Option_t *option=""); 00176 virtual TParticle *GetParticle(Int_t i) const; 00177 Int_t GetNumberOfParticles() const; 00178 virtual TObjArray *GetListOfParticles() const {return fParticles;} 00179 virtual TObjArray *GetPrimaries(Option_t *option="") {return ImportParticles(option);} 00180 Float_t GetPtCut() const {return fPtCut;} 00181 virtual void Paint(Option_t *option=""); 00182 virtual void SetParameter(const char* /*name*/,Double_t /*val*/){} 00183 virtual void SetPtCut(Float_t ptcut=0); // *MENU* 00184 virtual void SetViewRadius(Float_t rbox = 1000); // *MENU* 00185 virtual void SetViewRange(Float_t xmin=-10000,Float_t ymin=-10000,Float_t zmin=-10000 00186 ,Float_t xmax=10000,Float_t ymax=10000,Float_t zmax=10000); // *MENU* 00187 virtual void ShowNeutrons(Bool_t show=1); // *MENU* 00188 00189 ClassDef(TGenerator,1) //Event generator interface abstract baseclass 00190 }; 00191 00192 #endif