Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
13class TH1D;
14class TMethodCall;
15class TRandom;
16class TFoamIntegrand;
17class TFoamMaxwt;
18class TFoamVect;
19class TFoamCell;
20
21class TFoam : public TObject {
22protected:
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 = nullptr; ///< [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
76public:
77 TFoam(); // Default constructor (used only by ROOT streamer)
78 TFoam(const Char_t*); // Principal user-defined constructor
79 ~TFoam() override; // 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 [5], 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, tagged 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
139private:
140 Double_t Sqr(Double_t x) const { return x*x;} // Square function
141 TFoamCell* getCell(std::size_t i) const;
142
143 ClassDefOverride(TFoam,2); // General purpose self-adapting Monte Carlo event generator
144};
145
146#endif
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
long Long_t
Definition RtypesCore.h:54
double Double_t
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Used by TFoam.
Definition TFoamCell.h:12
Abstract class representing n-dimensional real positive integrand function.
Small auxiliary class for controlling MC weight.
Definition TFoamMaxwt.h:12
Auxiliary class TFoamVect of n-dimensional vector, with dynamic allocation used for the cartesian geo...
Definition TFoamVect.h:10
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
Definition TFoam.h:21
TFoamCell * getCell(std::size_t i) const
Definition TFoam.cxx:1527
virtual void MakeActiveList()
Internal method used by Initialize.
Definition TFoam.cxx:965
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition TFoam.cxx:1380
TString fName
Name of a given instance of the FOAM class.
Definition TFoam.h:24
Double_t fMCwt
MC weight.
Definition TFoam.h:57
virtual Int_t Divide(TFoamCell *)
Internal method used by Initialize.
Definition TFoam.cxx:932
virtual void PrintCells()
Prints geometry of ALL cells of the FOAM.
Definition TFoam.cxx:1448
TH1D * fHistWt
Histogram of the MC wt.
Definition TFoam.h:54
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition TFoam.cxx:1172
TFoamIntegrand * fRho
! Pointer to the user-defined integrand function/distribution
Definition TFoam.h:60
TRandom * fPseRan
Pointer to user-defined generator of pseudorandom numbers.
Definition TFoam.h:62
Double_t fMCerror
and its error
Definition TFoam.h:72
Double_t fPrime
Primary integral R' (R=R'<wt>)
Definition TFoam.h:70
Int_t fChat
Chat=0,1,2 chat level in output, Chat=1 normal level.
Definition TFoam.h:32
virtual void InitCells()
Internal method used by Initialize.
Definition TFoam.cxx:445
Double_t fNevGen
Total number of the generated MC events.
Definition TFoam.h:68
virtual void MakeEvent()
User method.
Definition TFoam.cxx:1122
Double_t fSumWt2
Total sum of wt and wt^2.
Definition TFoam.h:66
Double_t fSumWt
Definition TFoam.h:66
TFoamVect ** fXdivPRD
! Lists of division values encoded in one vector per direction
Definition TFoam.h:42
~TFoam() override
Default destructor.
Definition TFoam.cxx:228
virtual Int_t GetTotDim() const
Definition TFoam.h:128
virtual Long_t PeekMax()
Internal method used by Initialize.
Definition TFoam.cxx:898
virtual void GenerCel2(TFoamCell *&)
Internal method.
Definition TFoam.cxx:1084
virtual void SetEvPerBin(Int_t EvPerBin)
Definition TFoam.h:122
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition TFoam.cxx:321
virtual void Varedu(Double_t[5], Int_t &, Double_t &, Double_t &)
Internal method used by Initialize.
Definition TFoam.cxx:672
virtual void GetIntNorm(Double_t &, Double_t &)
User method.
Definition TFoam.cxx:1228
TFoamMaxwt * fMCMonit
Monitor of the MC weight for measuring MC efficiency.
Definition TFoam.h:48
Int_t fRNmax
Maximum No. of the rand. numb. requested at once.
Definition TFoam.h:29
Int_t * fInhiDiv
! [fDim] Flags for inhibiting cell division
Definition TFoam.h:40
Long_t fNCalls
Total number of the function calls.
Definition TFoam.h:64
virtual Double_t GetMCwt()
User may get weight MC weight using this method.
Definition TFoam.cxx:1180
virtual void SetnSampl(Long_t nSampl)
Definition TFoam.h:117
Double_t fWtMin
Maximum/Minimum MC weight.
Definition TFoam.h:69
virtual void ResetRho(TFoamIntegrand *Rho)
User may optionally reset the distribution using this method.
Definition TFoam.cxx:1049
Int_t fEvPerBin
Maximum number of effective (wt=1) events per bin.
Definition TFoam.h:37
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition TFoam.cxx:1207
Double_t fMaxWtRej
Maximum weight in rejection for getting wt=1 events.
Definition TFoam.h:49
Int_t fNCells
Maximum number of cells.
Definition TFoam.h:28
Double_t * fRvec
[fRNmax] random number vector from r.n. generator fDim+1 maximum elements
Definition TFoam.h:58
virtual void RootPlot2dim(Char_t *)
Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root.
Definition TFoam.cxx:1465
Double_t * fAlpha
[fDim] Internal parameters of the hyper-rectangle
Definition TFoam.h:74
Int_t fOptDrive
Optimization switch =1,2 for variance or maximum weight optimization.
Definition TFoam.h:31
virtual void Explore(TFoamCell *Cell)
Internal method used by Initialize.
Definition TFoam.cxx:520
virtual const char * GetVersion() const
Definition TFoam.h:127
virtual Long_t GetnEffev() const
Definition TFoam.h:132
virtual Double_t Eval(Double_t *)
Internal method.
Definition TFoam.cxx:1062
virtual void SetMaxWtRej(Double_t MaxWtRej)
Definition TFoam.h:123
virtual void MakeAlpha()
Internal method used by Initialize.
Definition TFoam.cxx:845
virtual void ResetPseRan(TRandom *PseRan)
User may optionally reset random number generator using this method.
Definition TFoam.cxx:1006
TMethodCall * fMethodCall
! ROOT's pointer to user-defined global distribution function
Definition TFoam.h:61
Double_t Sqr(Double_t x) const
Definition TFoam.h:140
virtual TRandom * GetPseRan() const
Definition TFoam.h:108
Int_t fLastCe
Index of the last cell.
Definition TFoam.h:45
Int_t fOptPRD
Option switch for predefined division, for quick check.
Definition TFoam.h:41
TObjArray * fHistDbg
Histograms of wt, for debug.
Definition TFoam.h:53
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:1340
Double_t fSumOve
Total Sum of overweighted events.
Definition TFoam.h:67
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:1310
virtual void SetChat(Int_t Chat)
Definition TFoam.h:119
Double_t fWtMax
Definition TFoam.h:69
std::vector< Long_t > fCellsAct
Index of active cells, constructed at the end of foam build-up.
Definition TFoam.h:50
virtual void SetOptDrive(Int_t OptDrive)
Definition TFoam.h:121
virtual void SetnCells(Long_t nCells)
Definition TFoam.h:116
virtual Long_t GetnCalls() const
Definition TFoam.h:131
virtual TFoamIntegrand * GetRho()
Definition TFoam.h:107
Int_t * fMaskDiv
! [fDim] Dynamic Mask for cell division
Definition TFoam.h:39
virtual void GetPrimary(Double_t &prime)
Definition TFoam.h:130
virtual void LinkCells(void)
Definition TFoam.cxx:1519
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition TFoam.cxx:1018
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:1029
Int_t fNoAct
Number of active cells.
Definition TFoam.h:44
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition TFoam.cxx:1258
Long_t fNEffev
Total number of effective events (wt=1) in the foam buildup.
Definition TFoam.h:65
Int_t fOptRej
Switch =0 for weighted events; =1 for unweighted events in MC.
Definition TFoam.h:33
virtual Double_t GetPrimary() const
Definition TFoam.h:129
Double_t * fPrimAcu
[fNoAct] Array of cumulative probability of all active cells
Definition TFoam.h:51
virtual Double_t MCgenerate(Double_t *MCvect)
User method which generates MC event and returns MC weight.
Definition TFoam.cxx:1195
Double_t * fMCvect
[fDim] Generated MC vector for the outside user
Definition TFoam.h:56
TString fVersion
Actual version of the FOAM like (1.01m)
Definition TFoam.h:25
virtual void SetOptRej(Int_t OptRej)
Definition TFoam.h:120
virtual Int_t CellFill(Int_t, TFoamCell *)
Internal method used by Initialize.
Definition TFoam.cxx:477
Int_t fDim
Dimension of the integration/simulation space.
Definition TFoam.h:27
Int_t fNSampl
No. of MC events, when dividing (exploring) cell.
Definition TFoam.h:36
TString fDate
Release date of FOAM.
Definition TFoam.h:26
TFoamCell ** fCells
[fNCells] Array of ALL cells
Definition TFoam.h:46
virtual void SetPseRan(TRandom *PseRan)
Definition TFoam.h:112
virtual void SetnBin(Int_t nBin)
Definition TFoam.h:118
virtual void SetkDim(Int_t kDim)
Definition TFoam.h:115
TObjArray * fHistEdg
Histograms of wt, one for each cell edge.
Definition TFoam.h:52
Double_t fMCresult
True Integral R from MC series.
Definition TFoam.h:71
virtual void GetWtParams(Double_t, Double_t &, Double_t &, Double_t &)
May be called optionally after the MC run.
Definition TFoam.cxx:1245
Int_t fNBin
No. of bins in the edge histogram for cell MC exploration.
Definition TFoam.h:35
virtual void Grow()
Internal method used by Initialize.
Definition TFoam.cxx:860
TFoam()
Default constructor for streamer, user should not use it.
Definition TFoam.cxx:145
virtual void Carver(Int_t &, Double_t &, Double_t &)
Internal method used by Initialize.
Definition TFoam.cxx:749
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:669
Method or function calling interface.
Definition TMethodCall.h:37
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
Double_t x[n]
Definition legend1.C:17