ROOT logo
// @(#)root/eg:$Id: TGenerator.h 20882 2007-11-19 11:31:26Z rdm $
// Author: Ola Nordmann   21/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGenerator                                                           //
//                                                                      //
// Is an base class, that defines the interface of ROOT to various    	//
// event generators. Every event generator should inherit from       	//
// TGenerator or its subclasses.                                        //
//                                                                      //
// Derived class can overload the member  function GenerateEvent        //
// to do the actual event generation (e.g., call PYEVNT or similar).    //
//                                                                      //
// The derived class should overload the member function                //
// ImportParticles (both types) to read the internal storage of the     //
// generated event into either the internal TObjArray or the passed     //
// TClonesArray of TParticles.                                          //
//                                                                      //
// If the generator code stores event data in the /HEPEVT/ common block //
// Then the default implementation of ImportParticles should suffice.   //
// The common block /HEPEVT/ is structed like                           //
//                                                                      //
//   /* C */                                                            //
//   typedef struct {                                                   //
//      Int_t    nevhep;                                                //
//      Int_t    nhep;                                                  //
//      Int_t    isthep[4000];                                          //
//      Int_t    idhep[4000];                                           //
//      Int_t    jmohep[4000][2];                                       //
//      Int_t    jdahep[4000][2];                                       //
//      Double_t phep[4000][5];                                         //
//      Double_t vhep[4000][4];                                         //
//   } HEPEVT_DEF;                                                      //
//                                                                      //
//                                                                      //
//   C Fortran                                                          //
//         COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(4000),IDHEP(4000),          //
//       +    JMOHEP(2,4000),JDAHEP(2,4000),PHEP(5,4000),VHEP(4,4000)   //
//         INTEGER NEVHEP,NHEP,ISTHEP,IDHEP,JMOHEP,JDAHEP               //
//         DOUBLE PRECISION PHEP,VHEP                                   //
//                                                                      //
// The generic member functions SetParameter and GetParameter can be    //
// overloaded to set and get parameters of the event generator.         //
//                                                                      //
// Note, if the derived class interfaces a (set of) Fortran common      //
// blocks (like TPythia, TVenus does), one better make the derived      //
// class a singleton.  That is, something like                          //
//                                                                      //
//     class MyGenerator : public TGenerator                            //
//     {                                                                //
//     public:                                                          //
//       static MyGenerator* Instance()                                 //
//       {                                                              //
//         if (!fgInstance) fgInstance = new MyGenerator;               //
//         return fgInstance;                                           //
//       }                                                              //
//       void  GenerateEvent() { ... }                                  //
//       void  ImportParticles(TClonesArray* a, Option_t opt="") {...}  //
//       Int_t ImportParticles(Option_t opt="") { ... }                 //
//       Int_t    SetParameter(const char* name, Double_t val) { ... }  //
//       Double_t GetParameter(const char* name) { ... }                //
//       virtual ~MyGenerator() { ... }                                 //
//     protected:                                                       //
//       MyGenerator() { ... }                                          //
//       MyGenerator(const MyGenerator& o) { ... }                      //
//       MyGenerator& operator=(const MyGenerator& o) { ... }           //
//       static MyGenerator* fgInstance;                                //
//       ClassDef(MyGenerator,0);                                       //
//     };                                                               //
//                                                                      //
// Having multiple objects accessing the same common blocks is not      //
// safe.                                                                //
//                                                                      //
// concrete TGenerator classes can be loaded in scripts and subseqent-  //
// ly used in compiled code:                                            //
//                                                                      //
//     // MyRun.h                                                       //
//     class MyRun : public TObject                                     //
//     {                                                                //
//     public:                                                          //
//       static MyRun* Instance() { ... }                               //
//       void SetGenerator(TGenerator* g) { fGenerator = g; }           //
//       void Run(Int_t n, Option_t* option="")                         //
//       {                                                              //
//         TFile*        file = TFile::Open("file.root","RECREATE");    //
//         TTree*        tree = new TTree("T","T");                     //
//         TClonesArray* p    = new TClonesArray("TParticles");         //
//         tree->Branch("particles", &p);                               //
//         for (Int_t event = 0; event < n; event++) {                  //
//           fGenerator->GenerateEvent();                               //
//           fGenerator->ImportParticles(p,option);                     //
//           tree->Fill();                                              //
//         }                                                            //
//         file->Write();                                               //
//         file->Close();                                               //
//       }                                                              //
//       ...                                                            //
//     protected:                                                       //
//       TGenerator* fGenerator;                                        //
//       ClassDef(MyRun,0);                                             //
//     };                                                               //
//                                                                      //
//     // Config.C                                                      //
//     void Config()                                                    //
//     {                                                                //
//        MyRun* run = MyRun::Instance();                               //
//        run->SetGenerator(MyGenerator::Instance());                   //
//     }                                                                //
//                                                                      //
//     // main.cxx                                                      //
//     int                                                              //
//     main(int argc, char** argv)                                      //
//     {                                                                //
//       TApplication app("", 0, 0);                                    //
//       gSystem->ProcessLine(".x Config.C");                           //
//       MyRun::Instance()->Run(10);                                    //
//       return 0;                                                      //
//     }                                                                //
//                                                                      //
// This is especially useful for example with TVirtualMC or similar.    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGenerator
#define ROOT_TGenerator

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif

class TBrowser;
class TParticle;
class TClonesArray;
class TObjArray;

class TGenerator : public TNamed {

protected:
   Float_t       fPtCut;        //!Pt cut. Do not show primaries below
   Bool_t        fShowNeutrons; //!display neutrons if true
   TObjArray    *fParticles;    //->static container of the primary particles

   TGenerator(const TGenerator& tg) :
   TNamed(tg), fPtCut(tg.fPtCut), fShowNeutrons(tg.fShowNeutrons),fParticles(tg.fParticles) { }
   TGenerator& operator=(const TGenerator& tg) {
      if(this!=&tg) {
         TNamed::operator=(tg); fPtCut=tg.fPtCut; fShowNeutrons=tg.fShowNeutrons;
         fParticles=tg.fParticles;
      }
      return *this;
   }

public:

   TGenerator(): fPtCut(0), fShowNeutrons(kTRUE), fParticles(0) { } //Used by Dictionary
   TGenerator(const char *name, const char *title="Generator class");
   virtual ~TGenerator();
   virtual void            Browse(TBrowser *b);
   virtual Int_t           DistancetoPrimitive(Int_t px, Int_t py);
   virtual void            Draw(Option_t *option="");
   virtual void            ExecuteEvent(Int_t event, Int_t px, Int_t py);
   virtual void            GenerateEvent();
   virtual Double_t        GetParameter(const char* /*name*/) const { return 0.; }
   virtual Int_t           ImportParticles(TClonesArray *particles, Option_t *option="");
   virtual TObjArray      *ImportParticles(Option_t *option="");
   virtual TParticle      *GetParticle(Int_t i) const;
   Int_t                   GetNumberOfParticles() const;
   virtual TObjArray      *GetListOfParticles() const {return fParticles;}
   virtual TObjArray      *GetPrimaries(Option_t *option="") {return ImportParticles(option);}
   Float_t                 GetPtCut() const {return fPtCut;}
   virtual void            Paint(Option_t *option="");
   virtual void            SetParameter(const char* /*name*/,Double_t /*val*/){}
   virtual void            SetPtCut(Float_t ptcut=0); // *MENU*
   virtual void            SetViewRadius(Float_t rbox = 1000); // *MENU*
   virtual void            SetViewRange(Float_t xmin=-10000,Float_t ymin=-10000,Float_t zmin=-10000
                                       ,Float_t xmax=10000,Float_t ymax=10000,Float_t zmax=10000);  // *MENU*
   virtual void            ShowNeutrons(Bool_t show=1); // *MENU*

   ClassDef(TGenerator,1)  //Event generator interface abstract baseclass
};

#endif
 TGenerator.h:1
 TGenerator.h:2
 TGenerator.h:3
 TGenerator.h:4
 TGenerator.h:5
 TGenerator.h:6
 TGenerator.h:7
 TGenerator.h:8
 TGenerator.h:9
 TGenerator.h:10
 TGenerator.h:11
 TGenerator.h:12
 TGenerator.h:13
 TGenerator.h:14
 TGenerator.h:15
 TGenerator.h:16
 TGenerator.h:17
 TGenerator.h:18
 TGenerator.h:19
 TGenerator.h:20
 TGenerator.h:21
 TGenerator.h:22
 TGenerator.h:23
 TGenerator.h:24
 TGenerator.h:25
 TGenerator.h:26
 TGenerator.h:27
 TGenerator.h:28
 TGenerator.h:29
 TGenerator.h:30
 TGenerator.h:31
 TGenerator.h:32
 TGenerator.h:33
 TGenerator.h:34
 TGenerator.h:35
 TGenerator.h:36
 TGenerator.h:37
 TGenerator.h:38
 TGenerator.h:39
 TGenerator.h:40
 TGenerator.h:41
 TGenerator.h:42
 TGenerator.h:43
 TGenerator.h:44
 TGenerator.h:45
 TGenerator.h:46
 TGenerator.h:47
 TGenerator.h:48
 TGenerator.h:49
 TGenerator.h:50
 TGenerator.h:51
 TGenerator.h:52
 TGenerator.h:53
 TGenerator.h:54
 TGenerator.h:55
 TGenerator.h:56
 TGenerator.h:57
 TGenerator.h:58
 TGenerator.h:59
 TGenerator.h:60
 TGenerator.h:61
 TGenerator.h:62
 TGenerator.h:63
 TGenerator.h:64
 TGenerator.h:65
 TGenerator.h:66
 TGenerator.h:67
 TGenerator.h:68
 TGenerator.h:69
 TGenerator.h:70
 TGenerator.h:71
 TGenerator.h:72
 TGenerator.h:73
 TGenerator.h:74
 TGenerator.h:75
 TGenerator.h:76
 TGenerator.h:77
 TGenerator.h:78
 TGenerator.h:79
 TGenerator.h:80
 TGenerator.h:81
 TGenerator.h:82
 TGenerator.h:83
 TGenerator.h:84
 TGenerator.h:85
 TGenerator.h:86
 TGenerator.h:87
 TGenerator.h:88
 TGenerator.h:89
 TGenerator.h:90
 TGenerator.h:91
 TGenerator.h:92
 TGenerator.h:93
 TGenerator.h:94
 TGenerator.h:95
 TGenerator.h:96
 TGenerator.h:97
 TGenerator.h:98
 TGenerator.h:99
 TGenerator.h:100
 TGenerator.h:101
 TGenerator.h:102
 TGenerator.h:103
 TGenerator.h:104
 TGenerator.h:105
 TGenerator.h:106
 TGenerator.h:107
 TGenerator.h:108
 TGenerator.h:109
 TGenerator.h:110
 TGenerator.h:111
 TGenerator.h:112
 TGenerator.h:113
 TGenerator.h:114
 TGenerator.h:115
 TGenerator.h:116
 TGenerator.h:117
 TGenerator.h:118
 TGenerator.h:119
 TGenerator.h:120
 TGenerator.h:121
 TGenerator.h:122
 TGenerator.h:123
 TGenerator.h:124
 TGenerator.h:125
 TGenerator.h:126
 TGenerator.h:127
 TGenerator.h:128
 TGenerator.h:129
 TGenerator.h:130
 TGenerator.h:131
 TGenerator.h:132
 TGenerator.h:133
 TGenerator.h:134
 TGenerator.h:135
 TGenerator.h:136
 TGenerator.h:137
 TGenerator.h:138
 TGenerator.h:139
 TGenerator.h:140
 TGenerator.h:141
 TGenerator.h:142
 TGenerator.h:143
 TGenerator.h:144
 TGenerator.h:145
 TGenerator.h:146
 TGenerator.h:147
 TGenerator.h:148
 TGenerator.h:149
 TGenerator.h:150
 TGenerator.h:151
 TGenerator.h:152
 TGenerator.h:153
 TGenerator.h:154
 TGenerator.h:155
 TGenerator.h:156
 TGenerator.h:157
 TGenerator.h:158
 TGenerator.h:159
 TGenerator.h:160
 TGenerator.h:161
 TGenerator.h:162
 TGenerator.h:163
 TGenerator.h:164
 TGenerator.h:165
 TGenerator.h:166
 TGenerator.h:167
 TGenerator.h:168
 TGenerator.h:169
 TGenerator.h:170
 TGenerator.h:171
 TGenerator.h:172
 TGenerator.h:173
 TGenerator.h:174
 TGenerator.h:175
 TGenerator.h:176
 TGenerator.h:177
 TGenerator.h:178
 TGenerator.h:179
 TGenerator.h:180
 TGenerator.h:181
 TGenerator.h:182
 TGenerator.h:183
 TGenerator.h:184
 TGenerator.h:185
 TGenerator.h:186
 TGenerator.h:187
 TGenerator.h:188
 TGenerator.h:189
 TGenerator.h:190
 TGenerator.h:191
 TGenerator.h:192