ROOT logo
ROOT » MONTECARLO » EG » TGenerator

class TGenerator: public TNamed


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;           // Event number
Int_t    nhep;             // # of particles
Int_t    isthep[4000];     // Status flag of i'th particle
Int_t    idhep[4000];      // PDG # of particle
Int_t    jmohep[4000][2];  // 1st & 2nd mother particle #	
Int_t    jdahep[4000][2];  // 1st & 2nd daughter particle #
Double_t phep[4000][5];    // 4-momentum and 1 word
Double_t vhep[4000][4];    // 4-position of production
} 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.


Function Members (Methods)

public:
TGenerator()
TGenerator(const char* name, const char* title = "Generator class")
virtual~TGenerator()
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidBrowse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidTNamed::Copy(TObject& named) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tDistancetoPrimitive(Int_t px, Int_t py)
virtual voidDraw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual voidGenerateEvent()
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual TObjArray*GetListOfParticles() const
virtual const char*TNamed::GetName() const
Int_tGetNumberOfParticles() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual Double_tGetParameter(const char*) const
virtual TParticle*GetParticle(Int_t i) const
virtual TObjArray*GetPrimaries(Option_t* option = "")
Float_tGetPtCut() const
virtual const char*TNamed::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
virtual TObjArray*ImportParticles(Option_t* option = "")
virtual Int_tImportParticles(TClonesArray* particles, Option_t* option = "")
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTNamed::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
virtual voidPaint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTNamed::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidSetParameter(const char*, Double_t)
virtual voidSetPtCut(Float_t ptcut = 0)MENU
virtual voidTNamed::SetTitle(const char* title = "")MENU
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidSetViewRadius(Float_t rbox = 1000)MENU
virtual voidSetViewRange(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 voidShowMembers(TMemberInspector& insp)
virtual voidShowNeutrons(Bool_t show = 1)MENU
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
TGenerator(const TGenerator& tg)
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()
TGenerator&operator=(const TGenerator& tg)

Data Members

protected:
TStringTNamed::fNameobject identifier
TObjArray*fParticles->static container of the primary particles
Float_tfPtCut!Pt cut. Do not show primaries below
Bool_tfShowNeutrons!display neutrons if true
TStringTNamed::fTitleobject title

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TGenerator(const char* name, const char* title = "Generator class")
  Event generator default constructor

~TGenerator()
  Event generator default destructor

void GenerateEvent()
 must be implemented in concrete class (see eg TPythia6)
TObjArray* ImportParticles(Option_t* option = "")
  It reads the /HEPEVT/ common block which has been filled by the
  GenerateEvent method. If the event generator does not use the
  HEPEVT common block, This routine has to be overloaded by the
  subclasses.

  The default action is to store only the stable particles (ISTHEP =
  1) This can be demanded explicitly by setting the option = "Final"
  If the option = "All", all the particles are stored.

Int_t ImportParticles(TClonesArray* particles, Option_t* option = "")
  It reads the /HEPEVT/ common block which has been filled by the
  GenerateEvent method. If the event generator does not use the
  HEPEVT common block, This routine has to be overloaded by the
  subclasses.

  The function loops on the generated particles and store them in
  the TClonesArray pointed by the argument particles.  The default
  action is to store only the stable particles (ISTHEP = 1) This can
  be demanded explicitly by setting the option = "Final" If the
  option = "All", all the particles are stored.

void Browse(TBrowser* b)
browse generator
Int_t DistancetoPrimitive(Int_t px, Int_t py)
-*-*-*-*Compute distance from point px,py to objects in event
*-*            =====================================================
-
void Draw(Option_t* option = "")
  Insert one event in the pad list

void ExecuteEvent(Int_t event, Int_t px, Int_t py)
-*-*-*-*-*-*-*Execute action corresponding to one event
*-*                  =========================================
Int_t GetNumberOfParticles() const
 Return the number of particles in the stack
TParticle * GetParticle(Int_t i) const
  Returns pointer to primary number i;

void Paint(Option_t* option = "")
  Paint one event

void SetPtCut(Float_t ptcut = 0)
  Set Pt threshold below which primaries are not drawn

void SetViewRadius(Float_t rbox = 1000)
  Set lower and upper values of the view range

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)
  Set lower and upper values of the view range

void ShowNeutrons(Bool_t show = 1)
  Set flag to display or not neutrons

TGenerator(const TGenerator& tg)
{ }
TGenerator& operator=(const TGenerator& tg)
TGenerator()
{ }
Double_t GetParameter(const char* ) const
{ return 0.; }
TObjArray * GetListOfParticles() const
{return fParticles;}
TObjArray * GetPrimaries(Option_t* option = "")
{return ImportParticles(option);}
Float_t GetPtCut() const
{return fPtCut;}
void SetParameter(const char* , Double_t )
{}