Logo ROOT  
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 #include "TObject.h"
9 #include "TString.h"
10 
11 #include <vector>
12 
13 class TH1D;
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  std::vector<Long_t> fCellsAct; ///< Index of 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,2); // General purpose self-adapting Monte Carlo event generator
143 };
144 
145 #endif
TFoam::GetIntegMC
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1211
TFoam::MCgenerate
virtual Double_t MCgenerate(Double_t *MCvect)
User method which generates MC event and returns MC weight.
Definition: TFoam.cxx:1199
TFoam::fNevGen
Double_t fNevGen
Total number of the generated MC events.
Definition: TFoam.h:68
TFoam::fVersion
TString fVersion
Actual version of the FOAM like (1.01m)
Definition: TFoam.h:25
TFoam::PeekMax
virtual Long_t PeekMax()
Internal method used by Initialize.
Definition: TFoam.cxx:902
TFoam::~TFoam
virtual ~TFoam()
Default destructor.
Definition: TFoam.cxx:230
TObjArray
Definition: TObjArray.h:37
TFoam::fSumWt2
Double_t fSumWt2
Total sum of wt and wt^2.
Definition: TFoam.h:66
TFoam::SetRhoInt
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:1033
TFoam::fMCvect
Double_t * fMCvect
[fDim] Generated MC vector for the outside user
Definition: TFoam.h:56
TFoam::GenerCel2
virtual void GenerCel2(TFoamCell *&)
Internal method.
Definition: TFoam.cxx:1088
TFoam::GetVersion
virtual const char * GetVersion() const
Definition: TFoam.h:127
TString::Data
const char * Data() const
Definition: TString.h:369
TFoam::fMaxWtRej
Double_t fMaxWtRej
Maximum weight in rejection for getting wt=1 events.
Definition: TFoam.h:49
TFoam::TFoam
TFoam()
Default constructor for streamer, user should not use it.
Definition: TFoam.cxx:146
TFoam::fNCells
Int_t fNCells
Maximum number of cells.
Definition: TFoam.h:28
TFoam::MakeEvent
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1126
TFoam::CheckAll
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition: TFoam.cxx:1382
TFoam::fLastCe
Int_t fLastCe
Index of the last cell.
Definition: TFoam.h:45
TFoam::fCells
TFoamCell ** fCells
[fNCells] Array of ALL cells
Definition: TFoam.h:46
TFoam::ResetRho
virtual void ResetRho(TFoamIntegrand *Rho)
User may optionally reset the distribution using this method.
Definition: TFoam.cxx:1053
TFoam::fXdivPRD
TFoamVect ** fXdivPRD
! Lists of division values encoded in one vector per direction
Definition: TFoam.h:42
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:615
TFoam::fMCerror
Double_t fMCerror
and its error
Definition: TFoam.h:72
TFoam::PrintCells
virtual void PrintCells()
Prints geometry of ALL cells of the FOAM.
Definition: TFoam.cxx:1450
TFoam::fMCwt
Double_t fMCwt
MC weight.
Definition: TFoam.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TFoam::fNBin
Int_t fNBin
No. of bins in the edge histogram for cell MC exploration.
Definition: TFoam.h:35
TFoam::SetnBin
virtual void SetnBin(Int_t nBin)
Definition: TFoam.h:118
TFoam::LinkCells
virtual void LinkCells(void)
Definition: TFoam.cxx:1521
x
Double_t x[n]
Definition: legend1.C:17
TFoamMaxwt
Definition: TFoamMaxwt.h:12
TFoam::GetWtParams
virtual void GetWtParams(Double_t, Double_t &, Double_t &, Double_t &)
May be called optionally after the MC run.
Definition: TFoam.cxx:1247
TFoam::fMethodCall
TMethodCall * fMethodCall
! ROOT's pointer to user-defined global distribution function
Definition: TFoam.h:61
TString
Definition: TString.h:136
TFoam::Grow
virtual void Grow()
Internal method used by Initialize.
Definition: TFoam.cxx:864
TFoam::fRvec
Double_t * fRvec
[fRNmax] random number vector from r.n. generator fDim+1 maximum elements
Definition: TFoam.h:58
TString.h
TFoam::MakeAlpha
virtual void MakeAlpha()
Internal method used by Initialize.
Definition: TFoam.cxx:849
TFoam::fChat
Int_t fChat
Chat=0,1,2 chat level in output, Chat=1 normal level.
Definition: TFoam.h:32
TFoam::SetChat
virtual void SetChat(Int_t Chat)
Definition: TFoam.h:119
TFoam::fRho
TFoamIntegrand * fRho
! Pointer to the user-defined integrand function/distribution
Definition: TFoam.h:60
TFoam::GetRho
virtual TFoamIntegrand * GetRho()
Definition: TFoam.h:107
TFoam::MakeActiveList
virtual void MakeActiveList()
Internal method used by Initialize.
Definition: TFoam.cxx:969
TFoam::Finalize
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1260
TFoam::fWtMin
Double_t fWtMin
Maximum/Minimum MC weight.
Definition: TFoam.h:69
TFoam::fMCresult
Double_t fMCresult
True Integral R from MC series.
Definition: TFoam.h:71
TFoam::fNEffev
Long_t fNEffev
Total number of effective events (wt=1) in the foam buildup.
Definition: TFoam.h:65
TFoam::fOptRej
Int_t fOptRej
Switch =0 for weighted events; =1 for unweighted events in MC.
Definition: TFoam.h:33
TFoam::SetOptRej
virtual void SetOptRej(Int_t OptRej)
Definition: TFoam.h:120
TFoam::SetXdivPRD
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:1342
TFoam::GetMCwt
virtual Double_t GetMCwt()
User may get weight MC weight using this method.
Definition: TFoam.cxx:1184
TFoam
Definition: TFoam.h:21
TRandom
Definition: TRandom.h:27
TFoam::fHistEdg
TObjArray * fHistEdg
Histograms of wt, one for each cell edge.
Definition: TFoam.h:52
TFoam::fWtMax
Double_t fWtMax
Definition: TFoam.h:69
TFoam::fMaskDiv
Int_t * fMaskDiv
! [fDim] Dynamic Mask for cell division
Definition: TFoam.h:39
TFoamVect
Definition: TFoamVect.h:10
TFoam::Sqr
Double_t Sqr(Double_t x) const
Definition: TFoam.h:140
Long_t
long Long_t
Definition: RtypesCore.h:54
TFoamIntegrand
Definition: TFoamIntegrand.h:9
TFoam::SetnSampl
virtual void SetnSampl(Long_t nSampl)
Definition: TFoam.h:117
TFoam::GetPrimary
virtual void GetPrimary(Double_t &prime)
Definition: TFoam.h:130
TFoam::GetPrimary
virtual Double_t GetPrimary() const
Definition: TFoam.h:129
TFoam::GetMCvect
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1176
TFoam::fAlpha
Double_t * fAlpha
[fDim] Internal parameters of the hyper-rectangle
Definition: TFoam.h:74
TFoam::fEvPerBin
Int_t fEvPerBin
Maximum number of effective (wt=1) events per bin.
Definition: TFoam.h:37
TFoam::fDim
Int_t fDim
Dimension of the integration/simulation space.
Definition: TFoam.h:27
TFoam::fRNmax
Int_t fRNmax
Maximum No. of the rand. numb. requested at once.
Definition: TFoam.h:29
TFoam::Initialize
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:323
TFoam::SetOptDrive
virtual void SetOptDrive(Int_t OptDrive)
Definition: TFoam.h:121
TFoam::GetIntNorm
virtual void GetIntNorm(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1230
TFoam::Explore
virtual void Explore(TFoamCell *Cell)
Internal method used by Initialize.
Definition: TFoam.cxx:522
TFoam::fPrimAcu
Double_t * fPrimAcu
[fNoAct] Array of cumulative probability of all active cells
Definition: TFoam.h:51
TFoam::fSumOve
Double_t fSumOve
Total Sum of overweighted events.
Definition: TFoam.h:67
TFoam::SetInhiDiv
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:1312
TFoam::GetPseRan
virtual TRandom * GetPseRan() const
Definition: TFoam.h:108
Double_t
double Double_t
Definition: RtypesCore.h:59
TFoam::Eval
virtual Double_t Eval(Double_t *)
Internal method.
Definition: TFoam.cxx:1066
TObject.h
TFoam::Divide
virtual Int_t Divide(TFoamCell *)
Internal method used by Initialize.
Definition: TFoam.cxx:936
TFoam::fName
TString fName
Name of a given instance of the FOAM class.
Definition: TFoam.h:24
TFoam::Varedu
virtual void Varedu(Double_t[], Int_t &, Double_t &, Double_t &)
Internal method used by Initialize.
Definition: TFoam.cxx:674
TFoam::fHistDbg
TObjArray * fHistDbg
Histograms of wt, for debug.
Definition: TFoam.h:53
TObject
Definition: TObject.h:37
TFoam::fPrime
Double_t fPrime
Primary integral R' (R=R'<wt>)
Definition: TFoam.h:70
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TFoam::ResetPseRan
virtual void ResetPseRan(TRandom *PseRan)
User may optionally reset random number generator using this method.
Definition: TFoam.cxx:1010
TFoam::InitCells
virtual void InitCells()
Internal method used by Initialize.
Definition: TFoam.cxx:447
TFoam::SetkDim
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:115
TFoam::fOptDrive
Int_t fOptDrive
Optimization switch =1,2 for variance or maximum weight optimization.
Definition: TFoam.h:31
TFoam::SetnCells
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:116
TFoam::SetMaxWtRej
virtual void SetMaxWtRej(Double_t MaxWtRej)
Definition: TFoam.h:123
TFoam::Carver
virtual void Carver(Int_t &, Double_t &, Double_t &)
Internal method used by Initialize.
Definition: TFoam.cxx:751
TMethodCall
Definition: TMethodCall.h:37
TFoam::fInhiDiv
Int_t * fInhiDiv
! [fDim] Flags for inhibiting cell division
Definition: TFoam.h:40
TFoamCell
Definition: TFoamCell.h:12
TFoam::fDate
TString fDate
Release date of FOAM.
Definition: TFoam.h:26
TFoam::fSumWt
Double_t fSumWt
Definition: TFoam.h:66
TFoam::SetRho
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1022
TFoam::SetPseRan
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:112
TFoam::fNCalls
Long_t fNCalls
Total number of the function calls.
Definition: TFoam.h:64
TFoam::fCellsAct
std::vector< Long_t > fCellsAct
Index of active cells, constructed at the end of foam build-up.
Definition: TFoam.h:50
Char_t
char Char_t
Definition: RtypesCore.h:33
TFoam::GetnEffev
virtual Long_t GetnEffev() const
Definition: TFoam.h:132
TFoam::fNSampl
Int_t fNSampl
No. of MC events, when dividing (exploring) cell.
Definition: TFoam.h:36
TFoam::fMCMonit
TFoamMaxwt * fMCMonit
Monitor of the MC weight for measuring MC efficiency.
Definition: TFoam.h:48
TFoam::fPseRan
TRandom * fPseRan
Pointer to user-defined generator of pseudorandom numbers.
Definition: TFoam.h:62
TFoam::GetnCalls
virtual Long_t GetnCalls() const
Definition: TFoam.h:131
TFoam::SetEvPerBin
virtual void SetEvPerBin(Int_t EvPerBin)
Definition: TFoam.h:122
TFoam::GetTotDim
virtual Int_t GetTotDim() const
Definition: TFoam.h:128
TFoam::fHistWt
TH1D * fHistWt
Histogram of the MC wt.
Definition: TFoam.h:54
TFoam::fNoAct
Int_t fNoAct
Number of active cells.
Definition: TFoam.h:44
TFoam::CellFill
virtual Int_t CellFill(Int_t, TFoamCell *)
Internal method used by Initialize.
Definition: TFoam.cxx:479
TFoam::RootPlot2dim
virtual void RootPlot2dim(Char_t *)
Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root.
Definition: TFoam.cxx:1467
TFoam::fOptPRD
Int_t fOptPRD
Option switch for predefined division, for quick check.
Definition: TFoam.h:41
int