Logo ROOT   6.08/07
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  R__DEPRECATED(6,10, "CINT remnant; not used anymore");
122  virtual void SetRhoInt(Double_t (*fun)(Int_t, Double_t *)); // Set new integrand distr. in compiled mode
123  virtual void SetRho(TFoamIntegrand *Rho); // Set new integrand distr. in compiled mode
124  virtual void ResetRho(TFoamIntegrand *Rho); // Set new distribution, delete old
125  virtual void SetPseRan(TRandom *PseRan){fPseRan=PseRan;} // Set new r.n. generator
126  virtual void ResetPseRan(TRandom *PseRan); // Set new r.n.g, delete old
127  // Getters and Setters
128  virtual void SetkDim(Int_t kDim){fDim = kDim;} // Sets dimension of cubical space
129  virtual void SetnCells(Long_t nCells){fNCells =nCells;} // Sets maximum number of cells
130  virtual void SetnSampl(Long_t nSampl){fNSampl =nSampl;} // Sets no of MC events in cell exploration
131  virtual void SetnBin(Int_t nBin){fNBin = nBin;} // Sets no of bins in histogs in cell exploration
132  virtual void SetChat(Int_t Chat){fChat = Chat;} // Sets option Chat, chat level
133  virtual void SetOptRej(Int_t OptRej){fOptRej =OptRej;} // Sets option for MC rejection
134  virtual void SetOptDrive(Int_t OptDrive){fOptDrive =OptDrive;} // Sets optimization switch
135  virtual void SetEvPerBin(Int_t EvPerBin){fEvPerBin =EvPerBin;} // Sets max. no. of effective events per bin
136  virtual void SetMaxWtRej(Double_t MaxWtRej){fMaxWtRej=MaxWtRej;} // Sets max. weight for rejection
137  virtual void SetInhiDiv(Int_t, Int_t ); // Set inhibition of cell division along certain edge
138  virtual void SetXdivPRD(Int_t, Int_t, Double_t[]); // Set predefined division points
139  // Getters and Setters
140  virtual const char *GetVersion() const {return fVersion.Data();}// Get version of the FOAM
141  virtual Int_t GetTotDim() const { return fDim;} // Get total dimension
142  virtual Double_t GetPrimary() const {return fPrime;} // Get value of primary integral R'
143  virtual void GetPrimary(Double_t &prime) {prime = fPrime;} // Get value of primary integral R'
144  virtual Long_t GetnCalls() const {return fNCalls;} // Get total no. of the function calls
145  virtual Long_t GetnEffev() const {return fNEffev;} // Get total no. of effective wt=1 events
146  // Debug
147  virtual void CheckAll(Int_t); // Checks correctness of the entire data structure in the FOAM object
148  virtual void PrintCells(); // Prints content of all cells
149  virtual void RootPlot2dim(Char_t*); // Generates C++ code for drawing foam
150  virtual void LinkCells(void); // Void function for backward compatibility
151  // Inline
152 private:
153  Double_t Sqr(Double_t x) const { return x*x;} // Square function
154  //////////////////////////////////////////////////////////////////////////////////////////////
155  ClassDef(TFoam,1); // General purpose self-adapting Monte Carlo event generator
156 };
157 
158 #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:1423
virtual void RootPlot2dim(Char_t *)
Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root...
Definition: TFoam.cxx:1508
Int_t fLastCe
Definition: TFoam.h:54
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition: RConfig.h:499
Double_t * fMCvect
Definition: TFoam.h:65
An array of TObjects.
Definition: TObjArray.h:39
Double_t fSumWt
Definition: TFoam.h:75
virtual Long_t GetnEffev() const
Definition: TFoam.h:145
virtual void LinkCells(void)
Definition: TFoam.cxx:1562
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:1293
TFoamCell ** fCells
Definition: TFoam.h:55
Int_t fOptPRD
[fDim] Flags for inhibiting cell division
Definition: TFoam.h:50
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:1245
virtual const char * GetVersion() const
Definition: TFoam.h:140
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
not used anymore
Definition: TFoam.h:121
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:1172
Int_t fChat
Definition: TFoam.h:41
virtual ~TFoam()
Default destructor.
Definition: TFoam.cxx:263
Double_t fSumWt2
Definition: TFoam.h:75
virtual void SetChat(Int_t Chat)
Definition: TFoam.h:132
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:1134
Double_t fMCerror
Definition: TFoam.h:81
virtual void MakeActiveList()
Internal subrogram used by Initialize.
Definition: TFoam.cxx:994
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: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:1383
virtual Double_t GetMCwt()
User may get weight MC weight using this method.
Definition: TFoam.cxx:1230
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:254
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:31
virtual void PrintCells()
Prints geometry of ALL cells of the FOAM.
Definition: TFoam.cxx:1491
Long_t fNEffev
Definition: TFoam.h:74
Int_t fOptRej
Definition: TFoam.h:42
virtual void SetRhoInt(void *Rho) R__DEPRECATED(6
User may use this to set pointer to the global function (not descending from TFoamIntegrand) serving ...
Definition: TFoam.cxx:1095
virtual void SetOptRej(Int_t OptRej)
Definition: TFoam.h:133
virtual void SetnBin(Int_t nBin)
Definition: TFoam.h:131
Double_t Sqr(Double_t x) const
Definition: TFoam.h:153
TObjArray * fHistEdg
Definition: TFoam.h:61
Method or function calling interface.
Definition: TMethodCall.h:41
virtual Double_t GetPrimary() const
Definition: TFoam.h:142
virtual TFoamIntegrand * GetRho()
Definition: TFoam.h:118
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1306
Double_t * fPrimAcu
Definition: TFoam.h:60
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:1222
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:1358
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:357
Int_t * fMaskDiv
Definition: TFoam.h:48
TString fName
Definition: TFoam.h:33
virtual void SetnSampl(Long_t nSampl)
Definition: TFoam.h:130
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
Double_t fWtMax
Definition: TFoam.h:78
Int_t fDim
Definition: TFoam.h:36
long Long_t
Definition: RtypesCore.h:50
Int_t fRNmax
Definition: TFoam.h:38
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:129
virtual void Carver(Int_t &, Double_t &, Double_t &)
Internal subrogram used by Initialize.
Definition: TFoam.cxx:781
virtual void CINT remnant
Definition: TFoam.h:121
double Double_t
Definition: RtypesCore.h:55
virtual void GetPrimary(Double_t &prime)
Definition: TFoam.h:143
Double_t fSumOve
Definition: TFoam.h:76
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:125
virtual TRandom * GetPseRan() const
Definition: TFoam.h:119
virtual void InitCells()
Internal subprogram used by Initialize.
Definition: TFoam.cxx:481
Int_t fOptDrive
Definition: TFoam.h:40
virtual void SetMaxWtRej(Double_t MaxWtRej)
Definition: TFoam.h:136
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Int_t GetTotDim() const
Definition: TFoam.h:141
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:134
virtual void GetIntNorm(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1276
virtual void Explore(TFoamCell *Cell)
Internal subprogram used by Initialize.
Definition: TFoam.cxx:554
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:1037
TFoamMaxwt * fMCMonit
Definition: TFoam.h:57
virtual Long_t GetnCalls() const
Definition: TFoam.h:144
virtual void SetEvPerBin(Int_t EvPerBin)
Definition: TFoam.h:135
virtual Double_t Eval(Double_t *)
Internal subprogram.
Definition: TFoam.cxx:1112
virtual Int_t Divide(TFoamCell *)
Internal subrogram used by Initialize.
Definition: TFoam.cxx:962
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:1049
Long_t fNCalls
Definition: TFoam.h:73
virtual void GetIntegMC(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1257
Definition: TFoam.h:29
Int_t fNSampl
Definition: TFoam.h:45
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:128
const char * Data() const
Definition: TString.h:349
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:71