ROOT  6.06/09
Reference Guide
TFoam.h
Go to the documentation of this file.
1 // @(#)root/foam:$Id$
2 // Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl>
3 
4 #ifndef ROOT_TFoam
5 #define ROOT_TFoam
6 
7 //////////////////////////////////////////////////////////////////////////////
8 // //
9 // TFoam is the main class of the multi-dimensional general purpose //
10 // Monte Carlo event generator (integrator) FOAM. //
11 // //
12 //////////////////////////////////////////////////////////////////////////////
13 
14 #ifndef ROOT_TObject
15 #include "TObject.h"
16 #endif
17 
18 #include "TString.h"
19 
20 class TH1D;
21 class TRefArray;
22 class TMethodCall;
23 class TRandom;
24 class TFoamIntegrand;
25 class TFoamMaxwt;
26 class TFoamVect;
27 class TFoamCell;
28 
29 class TFoam : public TObject {
30 protected:
31  // COMPONENTS //
32  //-------------- Input parameters
33  TString fName; // Name of a given instance of the FOAM class
34  TString fVersion; // Actual version of the FOAM like (1.01m)
35  TString fDate; // Release date of FOAM
36  Int_t fDim; // Dimension of the integration/simulation space
37  Int_t fNCells; // Maximum number of cells
38  Int_t fRNmax; // Maximum No. of the rand. numb. requested at once
39  //-------------------
40  Int_t fOptDrive; // Optimization switch =1,2 for variance or maximum weight optimization
41  Int_t fChat; // Chat=0,1,2 chat level in output, Chat=1 normal level
42  Int_t fOptRej; // Switch =0 for weighted events; =1 for unweighted events in MC
43  //-------------------
44  Int_t fNBin; // No. of bins in the edge histogram for cell MC exploration
45  Int_t fNSampl; // No. of MC events, when dividing (exploring) cell
46  Int_t fEvPerBin; // Maximum number of effective (wt=1) events per bin
47  //------------------- MULTI-BRANCHING ---------------------
48  Int_t *fMaskDiv; //! [fDim] Dynamic Mask for cell division
49  Int_t *fInhiDiv; //! [fDim] Flags for inhibiting cell division
50  Int_t fOptPRD; // Option switch for predefined division, for quick check
51  TFoamVect **fXdivPRD; //! Lists of division values encoded in one vector per direction
52  //------------------- GEOMETRY ----------------------------
53  Int_t fNoAct; // Number of active cells
54  Int_t fLastCe; // Index of the last cell
55  TFoamCell **fCells; // [fNCells] Array of ALL cells
56  //------------------ M.C. generation----------------------------
57  TFoamMaxwt *fMCMonit; // Monitor of the MC weight for measuring MC efficiency
58  Double_t fMaxWtRej; // Maximum weight in rejection for getting wt=1 events
59  TRefArray *fCellsAct; // Array of pointers to active cells, constructed at the end of foam build-up
60  Double_t *fPrimAcu; // [fNoAct] Array of cumulative probability of all active cells
61  TObjArray *fHistEdg; // Histograms of wt, one for each cell edge
62  TObjArray *fHistDbg; // Histograms of wt, for debug
63  TH1D *fHistWt; // Histogram of the MC wt
64 
65  Double_t *fMCvect; // [fDim] Generated MC vector for the outside user
66  Double_t fMCwt; // MC weight
67  Double_t *fRvec; // [fRNmax] random number vector from r.n. generator fDim+1 maximum elements
68  //----------- Procedures
69  TFoamIntegrand *fRho; //! Pointer to the user-defined integrand function/distribution
70  TMethodCall *fMethodCall; //! ROOT's pointer to user-defined global distribution function
71  TRandom *fPseRan; // Pointer to user-defined generator of pseudorandom numbers
72  //----------- Statistics and MC results
73  Long_t fNCalls; // Total number of the function calls
74  Long_t fNEffev; // Total number of effective events (wt=1) in the foam buildup
75  Double_t fSumWt, fSumWt2; // Total sum of wt and wt^2
76  Double_t fSumOve; // Total Sum of overveighted events
77  Double_t fNevGen; // Total number of the generated MC events
78  Double_t fWtMax, fWtMin; // Maximum/Minimum MC weight
79  Double_t fPrime; // Primary integral R' (R=R'<wt>)
80  Double_t fMCresult; // True Integral R from MC series
81  Double_t fMCerror; // and its error
82  //---------- working space for CELL exploration -------------
83  Double_t *fAlpha; // [fDim] Internal parameters of the hyperrectangle
84  //////////////////////////////////////////////////////////////////////////////////////////////
85  // METHODS //
86  //////////////////////////////////////////////////////////////////////////////////////////////
87 public:
88  TFoam(); // Default constructor (used only by ROOT streamer)
89  TFoam(const Char_t*); // Principal user-defined constructor
90  virtual ~TFoam(); // Default destructor
91  TFoam(const TFoam&); // Copy Constructor NOT USED
92  // Initialization
93  virtual void Initialize(); // Initialization of the FOAM (grid, cells, etc), mandatory!
94  virtual void Initialize(TRandom *, TFoamIntegrand *); // Alternative initialization method, backward compatibility
95  virtual void InitCells(); // Initializes first cells inside original cube
96  virtual Int_t CellFill(Int_t, TFoamCell*); // Allocates new empty cell and return its index
97  virtual void Explore(TFoamCell *Cell); // Exploration of the new cell, determine <wt>, wtMax etc.
98  virtual void Carver(Int_t&,Double_t&,Double_t&);// Determines the best edge, wt_max reduction
99  virtual void Varedu(Double_t [], Int_t&, Double_t&,Double_t&); // Determines the best edge, variace reduction
100  virtual void MakeAlpha(); // Provides random point inside hyperrectangle
101  virtual void Grow(); // Adds new cells to FOAM object until buffer is full
102  virtual Long_t PeekMax(); // Choose one active cell, used by Grow and also in MC generation
103  virtual Int_t Divide(TFoamCell *); // Divide iCell into two daughters; iCell retained, taged as inactive
104  virtual void MakeActiveList(); // Creates table of active cells
105  virtual void GenerCel2(TFoamCell *&); // Chose an active cell the with probability ~ Primary integral
106  // Generation
107  virtual Double_t Eval(Double_t *); // Evaluates value of the distribution function
108  virtual void MakeEvent(); // Makes (generates) single MC event
109  virtual void GetMCvect(Double_t *); // Provides generated randomly MC vector
110  virtual void GetMCwt(Double_t &); // Provides generated MC weight
111  virtual Double_t GetMCwt(); // Provides generates MC weight
112  virtual Double_t MCgenerate(Double_t *MCvect);// All three above function in one
113  // Finalization
114  virtual void GetIntegMC(Double_t&, Double_t&);// Provides Integrand and abs. error from MC run
115  virtual void GetIntNorm(Double_t&, Double_t&);// Provides normalization Inegrand
116  virtual void GetWtParams(Double_t, Double_t&, Double_t&, Double_t&);// Provides MC weight parameters
117  virtual void Finalize( Double_t&, Double_t&); // Prints summary of MC integration
118  virtual TFoamIntegrand *GetRho(){return fRho;} // Gets pointer of the distribut. (after restoring from disk)
119  virtual TRandom *GetPseRan() const {return fPseRan;} // Gets pointer of r.n. generator (after restoring from disk)
120  virtual void SetRhoInt(void *Rho); // Set new integrand distr. in interactive mode
121  virtual void SetRhoInt(Double_t (*fun)(Int_t, Double_t *)); // Set new integrand distr. in compiled mode
122  virtual void SetRho(TFoamIntegrand *Rho); // Set new integrand distr. in compiled mode
123  virtual void ResetRho(TFoamIntegrand *Rho); // Set new distribution, delete old
124  virtual void SetPseRan(TRandom *PseRan){fPseRan=PseRan;} // Set new r.n. generator
125  virtual void ResetPseRan(TRandom *PseRan); // Set new r.n.g, delete old
126  // Getters and Setters
127  virtual void SetkDim(Int_t kDim){fDim = kDim;} // Sets dimension of cubical space
128  virtual void SetnCells(Long_t nCells){fNCells =nCells;} // Sets maximum number of cells
129  virtual void SetnSampl(Long_t nSampl){fNSampl =nSampl;} // Sets no of MC events in cell exploration
130  virtual void SetnBin(Int_t nBin){fNBin = nBin;} // Sets no of bins in histogs in cell exploration
131  virtual void SetChat(Int_t Chat){fChat = Chat;} // Sets option Chat, chat level
132  virtual void SetOptRej(Int_t OptRej){fOptRej =OptRej;} // Sets option for MC rejection
133  virtual void SetOptDrive(Int_t OptDrive){fOptDrive =OptDrive;} // Sets optimization switch
134  virtual void SetEvPerBin(Int_t EvPerBin){fEvPerBin =EvPerBin;} // Sets max. no. of effective events per bin
135  virtual void SetMaxWtRej(Double_t MaxWtRej){fMaxWtRej=MaxWtRej;} // Sets max. weight for rejection
136  virtual void SetInhiDiv(Int_t, Int_t ); // Set inhibition of cell division along certain edge
137  virtual void SetXdivPRD(Int_t, Int_t, Double_t[]); // Set predefined division points
138  // Getters and Setters
139  virtual const char *GetVersion() const {return fVersion.Data();}// Get version of the FOAM
140  virtual Int_t GetTotDim() const { return fDim;} // Get total dimension
141  virtual Double_t GetPrimary() const {return fPrime;} // Get value of primary integral R'
142  virtual void GetPrimary(Double_t &prime) {prime = fPrime;} // Get value of primary integral R'
143  virtual Long_t GetnCalls() const {return fNCalls;} // Get total no. of the function calls
144  virtual Long_t GetnEffev() const {return fNEffev;} // Get total no. of effective wt=1 events
145  // Debug
146  virtual void CheckAll(Int_t); // Checks correctness of the entire data structure in the FOAM object
147  virtual void PrintCells(); // Prints content of all cells
148  virtual void RootPlot2dim(Char_t*); // Generates C++ code for drawing foam
149  virtual void LinkCells(void); // Void function for backward compatibility
150  // Inline
151 private:
152  Double_t Sqr(Double_t x) const { return x*x;} // Square function
153  //////////////////////////////////////////////////////////////////////////////////////////////
154  ClassDef(TFoam,1); // General purpose self-adapting Monte Carlo event generator
155 };
156 
157 #endif
TRefArray * fCellsAct
Definition: TFoam.h:59
Int_t fNCells
Definition: TFoam.h:37
Int_t fNoAct
Lists of division values encoded in one vector per direction.
Definition: TFoam.h:53
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition: TFoam.cxx:1441
virtual void RootPlot2dim(Char_t *)
Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root...
Definition: TFoam.cxx:1526
Int_t fLastCe
Definition: TFoam.h:54
Double_t * fMCvect
Definition: TFoam.h:65
An array of TObjects.
Definition: TObjArray.h:39
Double_t fSumWt
Definition: TFoam.h:75
virtual void LinkCells(void)
Definition: TFoam.cxx:1580
virtual Long_t PeekMax()
Internal subprogram used by Initialize.
Definition: TFoam.cxx:942
virtual void GetWtParams(Double_t, Double_t &, Double_t &, Double_t &)
May be called optionally after the MC run.
Definition: TFoam.cxx:1304
TFoamCell ** fCells
Definition: TFoam.h:55
Int_t fOptPRD
[fDim] Flags for inhibiting cell division
Definition: TFoam.h:50
virtual Double_t MCgenerate(Double_t *MCvect)
User subprogram which generates MC event and returns MC weight.
Definition: TFoam.cxx:1256
Double_t fMCwt
Definition: TFoam.h:66
Double_t * fRvec
Definition: TFoam.h:67
Int_t fNBin
Definition: TFoam.h:44
Double_t fMaxWtRej
Definition: TFoam.h:58
Double_t fNevGen
Definition: TFoam.h:77
TString fVersion
Definition: TFoam.h:34
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
virtual void MakeEvent()
User subprogram.
Definition: TFoam.cxx:1183
Int_t fChat
Definition: TFoam.h:41
virtual ~TFoam()
Default destructor std::cout<<" DESTRUCTOR entered "<
Definition: TFoam.cxx:271
Double_t fSumWt2
Definition: TFoam.h:75
virtual void SetChat(Int_t Chat)
Definition: TFoam.h:131
TFoamIntegrand * fRho
Definition: TFoam.h:69
An array of references to TObjects.
Definition: TRefArray.h:43
TFoamVect ** fXdivPRD
Definition: TFoam.h:51
virtual void GenerCel2(TFoamCell *&)
Internal subprogram.
Definition: TFoam.cxx:1145
Double_t fMCerror
Definition: TFoam.h:81
virtual void MakeActiveList()
Internal subrogram used by Initialize.
Definition: TFoam.cxx:1007
Double_t fWtMin
Definition: TFoam.h:78
Double_t fMCresult
Definition: TFoam.h:80
virtual void Grow()
Internal subrogram used by Initialize.
Definition: TFoam.cxx:907
virtual TRandom * GetPseRan() const
Definition: TFoam.h:119
virtual Long_t GetnEffev() const
Definition: TFoam.h:144
virtual void SetXdivPRD(Int_t, Int_t, Double_t[])
This should be called before Initialize, after setting kDim It predefines values of the cell division...
Definition: TFoam.cxx:1396
virtual Double_t GetMCwt()
User may get weight MC weight using this method.
Definition: TFoam.cxx:1241
const char * Data() const
Definition: TString.h:349
virtual void ResetRho(TFoamIntegrand *Rho)
User may optionally reset the distribution using this method Usually it is done when FOAM object is r...
Definition: TFoam.cxx:1092
Double_t x[n]
Definition: legend1.C:17
TMethodCall * fMethodCall
Pointer to the user-defined integrand function/distribution.
Definition: TFoam.h:70
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
virtual void PrintCells()
Prints geometry of ALL cells of the FOAM.
Definition: TFoam.cxx:1509
Long_t fNEffev
Definition: TFoam.h:74
Int_t fOptRej
Definition: TFoam.h:42
Double_t Sqr(Double_t x) const
Definition: TFoam.h:152
virtual void SetOptRej(Int_t OptRej)
Definition: TFoam.h:132
virtual void SetnBin(Int_t nBin)
Definition: TFoam.h:130
virtual Double_t GetPrimary() const
Definition: TFoam.h:141
TObjArray * fHistEdg
Definition: TFoam.h:61
Method or function calling interface.
Definition: TMethodCall.h:41
virtual TFoamIntegrand * GetRho()
Definition: TFoam.h:118
virtual Int_t GetTotDim() const
Definition: TFoam.h:140
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1317
virtual const char * GetVersion() const
Definition: TFoam.h:139
Double_t * fPrimAcu
Definition: TFoam.h:60
virtual void MakeAlpha()
Internal subrogram used by Initialize.
Definition: TFoam.cxx:892
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1233
Double_t * fAlpha
Definition: TFoam.h:83
Int_t fEvPerBin
Definition: TFoam.h:46
virtual void SetInhiDiv(Int_t, Int_t)
This can be called before Initialize, after setting kDim It defines which variables are excluded in t...
Definition: TFoam.cxx:1368
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:370
Int_t * fMaskDiv
Definition: TFoam.h:48
virtual Long_t GetnCalls() const
Definition: TFoam.h:143
virtual void SetRhoInt(void *Rho)
User may use this to set pointer to the global function (not descending from TFoamIntegrand) serving ...
Definition: TFoam.cxx:1108
TString fName
Definition: TFoam.h:33
virtual void SetnSampl(Long_t nSampl)
Definition: TFoam.h:129
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
Double_t fWtMax
Definition: TFoam.h:78
Int_t fDim
Definition: TFoam.h:36
ClassDef(TFoam, 1)
long Long_t
Definition: RtypesCore.h:50
Int_t fRNmax
Definition: TFoam.h:38
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:128
virtual void Carver(Int_t &, Double_t &, Double_t &)
Internal subrogram used by Initialize.
Definition: TFoam.cxx:794
double Double_t
Definition: RtypesCore.h:55
virtual void GetPrimary(Double_t &prime)
Definition: TFoam.h:142
Double_t fSumOve
Definition: TFoam.h:76
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:124
virtual void InitCells()
Internal subprogram used by Initialize.
Definition: TFoam.cxx:494
Int_t fOptDrive
Definition: TFoam.h:40
virtual void SetMaxWtRej(Double_t MaxWtRej)
Definition: TFoam.h:135
Mother of all ROOT objects.
Definition: TObject.h:58
char Char_t
Definition: RtypesCore.h:29
virtual Int_t CellFill(Int_t, TFoamCell *)
Internal subprogram used by Initialize.
Definition: TFoam.cxx:526
virtual void SetOptDrive(Int_t OptDrive)
Definition: TFoam.h:133
virtual void GetIntNorm(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1287
virtual void Varedu(Double_t[], Int_t &, Double_t &, Double_t &)
Internal subrogram used by Initialize.
Definition: TFoam.cxx:718
virtual void Explore(TFoamCell *Cell)
Internal subprogram used by Initialize.
Definition: TFoam.cxx:567
TString fDate
Definition: TFoam.h:35
TObjArray * fHistDbg
Definition: TFoam.h:62
Double_t fPrime
Definition: TFoam.h:79
virtual void ResetPseRan(TRandom *PseRan)
User may optionally reset random number generator using this method Usually it is done when FOAM obje...
Definition: TFoam.cxx:1050
TFoamMaxwt * fMCMonit
Definition: TFoam.h:57
virtual void SetEvPerBin(Int_t EvPerBin)
Definition: TFoam.h:134
virtual Double_t Eval(Double_t *)
Internal subprogram.
Definition: TFoam.cxx:1123
virtual Int_t Divide(TFoamCell *)
Internal subrogram used by Initialize.
Definition: TFoam.cxx:975
TH1D * fHistWt
Definition: TFoam.h:63
Int_t * fInhiDiv
[fDim] Dynamic Mask for cell division
Definition: TFoam.h:49
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1062
Long_t fNCalls
Definition: TFoam.h:73
virtual void GetIntegMC(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1268
Definition: TFoam.h:29
Int_t fNSampl
Definition: TFoam.h:45
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:127
TFoam()
Default constructor for streamer, user should not use it.
Definition: TFoam.cxx:185
TRandom * fPseRan
ROOT's pointer to user-defined global distribution function.
Definition: TFoam.h:71