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