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