Logo ROOT  
Reference Guide
TFoam Class Reference

TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integrator) FOAM.

FOAM Version 1.02M

Authors
S. Jadach and P.Sawicki Institute of Nuclear Physics, Cracow, Poland Stanislaw. Jadac.nosp@m.h@if.nosp@m.j.edu.nosp@m..pl, Pawel.nosp@m..Saw.nosp@m.icki@.nosp@m.ifj..nosp@m.edu.p.nosp@m.l

What is FOAM for?

  • Suppose you want to generate randomly points (vectors) according to an arbitrary probability distribution in n dimensions, for which you supply your own method. FOAM can do it for you! Even if your distributions has quite strong peaks and is discontinuous!

FOAM generates random points with weight one or with variable weight.

  • FOAM is capable to integrate using efficient "adaptive" MC method. (The distribution does not need to be normalized to one.)

How does it work?

FOAM is the simplified version of the multi-dimensional general purpose Monte Carlo event generator (integrator) FOAM. It creates hyper-rectangular "foam of cells", which is more dense around its peaks. See the following 2-dim. example of the map of 1000 cells for doubly peaked distribution:

FOAM is now fully integrated with the ROOT package. The important bonus of the ROOT use is persistency of the FOAM objects!

For more sophisticated problems full version of FOAM may be more appropriate: See full version of FOAM

Simple example of the use of FOAM:

#include "Riostream.h"
#include "TFoam.h"
#include "TCanvas.h"
#include "TH2.h"
#include "TMath.h"
#include "TFoamIntegrand.h"
#include "TRandom3.h"
//_____________________________________________________________________________
return x*x;
}
//_____________________________________________________________________________
Double_t Camel2(Int_t nDim, Double_t *Xarg){
// 2-dimensional distribution for Foam, normalized to one (within 1e-5)
Double_t x=Xarg[0];
Double_t y=Xarg[1];
Double_t GamSq= sqr(0.100e0);
Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
return 0.5*Dist;
}
//_____________________________________________________________________________
Int_t foam_kanwa(){
cout<<"--- kanwa started ---"<<endl;
TH2D *hst_xy = new TH2D("hst_xy" , "x-y plot", 50,0,1.0, 50,0,1.0);
Double_t MCvect[2]; // 2-dim vector generated in the MC run
//
TRandom *PseRan = new TRandom3(); // Create random number generator
PseRan->SetSeed(4357);
TFoam *FoamX = new TFoam("FoamX"); // Create Simulator
FoamX->SetkDim(2); // No. of dimensions, obligatory!
FoamX->SetnCells(500); // Optionally No. of cells, default=2000
FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below
FoamX->SetPseRan(PseRan); // Set random number generator
FoamX->Initialize(); // Initialize simulator, may take time...
//
// visualising generated distribution
TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600);
cKanwa->cd();
// From now on FoamX is ready to generate events
int nshow=5000;
for(long loop=0; loop<100000; loop++){
FoamX->MakeEvent(); // generate MC event
FoamX->GetMCvect( MCvect); // get generated vector (x,y)
Double_t x=MCvect[0];
Double_t y=MCvect[1];
if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<<endl;
hst_xy->Fill(x,y);
// live plot
if(loop == nshow){
nshow += 5000;
hst_xy->Draw("lego2");
cKanwa->Update();
}
}// loop
//
hst_xy->Draw("lego2"); // final plot
cKanwa->Update();
//
Double_t MCresult, MCerror;
FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
cout<<"--- kanwa ended ---"<<endl;
return 0;
}

Canonical nine steering parameters of FOAM

Name default Description
kDim 0 Dimension of the integration space. Must be redefined!
nCells 1000 No of allocated number of cells,
nSampl 200 No. of MC events in the cell MC exploration
nBin 8 No. of bins in edge-histogram in cell exploration
OptRej 1 OptRej = 0, weighted; OptRej=1, wt=1 MC events
OptDrive 2 Maximum weight reduction, =1 for variance reduction
EvPerBin 25 Maximum number of the effective wt=1 events/bin,
EvPerBin=0 deactivates this option
Chat 1 =0,1,2 is the `‘chat level’' in the standard output
MaxWtRej 1.1 Maximum weight used to get w=1 MC events

The above can be redefined before calling Initialize() method, for instance FoamObject->SetkDim(15) sets dimension of the distribution to 15. Only kDim HAS TO BE redefined, the other parameters may be left at their defaults. nCell may be increased up to about million cells for wildly peaked distributions. Increasing nSampl sometimes helps, but it may cost CPU time. MaxWtRej may need to be increased for wild a distribution, while using OptRej=0.

Past versions of FOAM: August 2003, v.1.00; September 2003 v.1.01 Adopted starting from FOAM-2.06 by P. Sawicki

Users of FOAM are kindly requested to cite the following work: S. Jadach, Computer Physics Communications 152 (2003) 55.

Definition at line 21 of file TFoam.h.

Public Member Functions

 TFoam ()
 Default constructor for streamer, user should not use it. More...
 
 TFoam (const Char_t *)
 User constructor, to be employed by the user. More...
 
 TFoam (const TFoam &)
 Copy Constructor NOT IMPLEMENTED (NEVER USED) More...
 
virtual ~TFoam ()
 Default destructor. More...
 
virtual void Carver (Int_t &, Double_t &, Double_t &)
 Internal method used by Initialize. More...
 
virtual Int_t CellFill (Int_t, TFoamCell *)
 Internal method used by Initialize. More...
 
virtual void CheckAll (Int_t)
 User utility, miscellaneous and debug. More...
 
virtual Int_t Divide (TFoamCell *)
 Internal method used by Initialize. More...
 
virtual Double_t Eval (Double_t *)
 Internal method. More...
 
virtual void Explore (TFoamCell *Cell)
 Internal method used by Initialize. More...
 
virtual void Finalize (Double_t &, Double_t &)
 May be called optionally by the user after the MC run. More...
 
virtual void GenerCel2 (TFoamCell *&)
 Internal method. More...
 
virtual void GetIntegMC (Double_t &, Double_t &)
 User method. More...
 
virtual void GetIntNorm (Double_t &, Double_t &)
 User method. More...
 
virtual void GetMCvect (Double_t *)
 User may get generated MC point/vector with help of this method. More...
 
virtual Double_t GetMCwt ()
 User may get weight MC weight using this method. More...
 
virtual void GetMCwt (Double_t &)
 User may get weight MC weight using this method. More...
 
virtual Long_t GetnCalls () const
 
virtual Long_t GetnEffev () const
 
virtual Double_t GetPrimary () const
 
virtual void GetPrimary (Double_t &prime)
 
virtual TRandomGetPseRan () const
 
virtual TFoamIntegrandGetRho ()
 
virtual Int_t GetTotDim () const
 
virtual const char * GetVersion () const
 
virtual void GetWtParams (Double_t, Double_t &, Double_t &, Double_t &)
 May be called optionally after the MC run. More...
 
virtual void Grow ()
 Internal method used by Initialize. More...
 
virtual void InitCells ()
 Internal method used by Initialize. More...
 
virtual void Initialize ()
 Basic initialization of FOAM invoked by the user. More...
 
virtual void Initialize (TRandom *, TFoamIntegrand *)
 
virtual void LinkCells (void)
 
virtual void MakeActiveList ()
 Internal method used by Initialize. More...
 
virtual void MakeAlpha ()
 Internal method used by Initialize. More...
 
virtual void MakeEvent ()
 User method. More...
 
virtual Double_t MCgenerate (Double_t *MCvect)
 User method which generates MC event and returns MC weight. More...
 
virtual Long_t PeekMax ()
 Internal method used by Initialize. More...
 
virtual void PrintCells ()
 Prints geometry of ALL cells of the FOAM. More...
 
virtual void ResetPseRan (TRandom *PseRan)
 User may optionally reset random number generator using this method. More...
 
virtual void ResetRho (TFoamIntegrand *Rho)
 User may optionally reset the distribution using this method. More...
 
virtual void RootPlot2dim (Char_t *)
 Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root. More...
 
virtual void SetChat (Int_t Chat)
 
virtual void SetEvPerBin (Int_t EvPerBin)
 
virtual void SetInhiDiv (Int_t, Int_t)
 This can be called before Initialize, after setting kDim It defines which variables are excluded in the process of the cell division. More...
 
virtual void SetkDim (Int_t kDim)
 
virtual void SetMaxWtRej (Double_t MaxWtRej)
 
virtual void SetnBin (Int_t nBin)
 
virtual void SetnCells (Long_t nCells)
 
virtual void SetnSampl (Long_t nSampl)
 
virtual void SetOptDrive (Int_t OptDrive)
 
virtual void SetOptRej (Int_t OptRej)
 
virtual void SetPseRan (TRandom *PseRan)
 
virtual void SetRho (TFoamIntegrand *Rho)
 User may use this method to set the distribution object. More...
 
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 interpreted function). More...
 
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 for certain variable iDim. More...
 
virtual void Varedu (Double_t[], Int_t &, Double_t &, Double_t &)
 Internal method used by Initialize. More...
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor. More...
 
 TObject (const TObject &object)
 TObject copy ctor. More...
 
virtual ~TObject ()
 TObject destructor. More...
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract. More...
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad. More...
 
virtual void Browse (TBrowser *b)
 Browse object. May be overridden for another default action. More...
 
ULong_t CheckedHash ()
 Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. More...
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs. More...
 
virtual void Clear (Option_t *="")
 
virtual TObjectClone (const char *newname="") const
 Make a clone of an object using the Streamer facility. More...
 
virtual Int_t Compare (const TObject *obj) const
 Compare abstract method. More...
 
virtual void Copy (TObject &object) const
 Copy this to obj. More...
 
virtual void Delete (Option_t *option="")
 Delete this object. More...
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object. More...
 
virtual void Draw (Option_t *option="")
 Default Draw method for all objects. More...
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs. More...
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad). More...
 
virtual void Dump () const
 Dump contents of object on stdout. More...
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message. More...
 
virtual void Execute (const char *method, const char *params, Int_t *error=0)
 Execute method on this object with the given parameter string, e.g. More...
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 Execute method on this object with parameters stored in the TObjArray. More...
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py). More...
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message. More...
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes. More...
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes. More...
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object. More...
 
virtual const char * GetIconName () const
 Returns mime type name of object. More...
 
virtual const char * GetName () const
 Returns name of object. More...
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py). More...
 
virtual Option_tGetOption () const
 
virtual const char * GetTitle () const
 Returns title of object. More...
 
virtual UInt_t GetUniqueID () const
 Return the unique object id. More...
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out. More...
 
virtual ULong_t Hash () const
 Return hash value for this object. More...
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. More...
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message. More...
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname". More...
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl. More...
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas. More...
 
void InvertBit (UInt_t f)
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory). More...
 
virtual Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More...
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
virtual Bool_t IsSortable () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
virtual void ls (Option_t *option="") const
 The ls function lists the contents of a class on stdout. More...
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). More...
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification. More...
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete. More...
 
void operator delete (void *ptr)
 Operator delete. More...
 
void operator delete[] (void *ptr)
 Operator delete []. More...
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator. More...
 
virtual void Paint (Option_t *option="")
 This method must be overridden if a class wants to paint itself. More...
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list. More...
 
virtual void Print (Option_t *option="") const
 This method must be overridden when a class wants to print itself. More...
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory. More...
 
virtual void RecursiveRemove (TObject *obj)
 Recursively remove this object from a list. More...
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename. More...
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out". More...
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f. More...
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object. More...
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id. More...
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message. More...
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. More...
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 Write this object to the current directory. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 Write this object to the current directory. More...
 

Protected Attributes

Double_tfAlpha
 [fDim] Internal parameters of the hyper-rectangle More...
 
TFoamCell ** fCells
 [fNCells] Array of ALL cells More...
 
std::vector< Long_tfCellsAct
 Index of active cells, constructed at the end of foam build-up. More...
 
Int_t fChat
 Chat=0,1,2 chat level in output, Chat=1 normal level. More...
 
TString fDate
 Release date of FOAM. More...
 
Int_t fDim
 Dimension of the integration/simulation space. More...
 
Int_t fEvPerBin
 Maximum number of effective (wt=1) events per bin. More...
 
TObjArrayfHistDbg
 Histograms of wt, for debug. More...
 
TObjArrayfHistEdg
 Histograms of wt, one for each cell edge. More...
 
TH1DfHistWt
 Histogram of the MC wt. More...
 
Int_tfInhiDiv
 ! [fDim] Flags for inhibiting cell division More...
 
Int_t fLastCe
 Index of the last cell. More...
 
Int_tfMaskDiv
 ! [fDim] Dynamic Mask for cell division More...
 
Double_t fMaxWtRej
 Maximum weight in rejection for getting wt=1 events. More...
 
Double_t fMCerror
 and its error More...
 
TFoamMaxwtfMCMonit
 Monitor of the MC weight for measuring MC efficiency. More...
 
Double_t fMCresult
 True Integral R from MC series. More...
 
Double_tfMCvect
 [fDim] Generated MC vector for the outside user More...
 
Double_t fMCwt
 MC weight. More...
 
TMethodCallfMethodCall
 ! ROOT's pointer to user-defined global distribution function More...
 
TString fName
 Name of a given instance of the FOAM class. More...
 
Int_t fNBin
 No. of bins in the edge histogram for cell MC exploration. More...
 
Long_t fNCalls
 Total number of the function calls. More...
 
Int_t fNCells
 Maximum number of cells. More...
 
Long_t fNEffev
 Total number of effective events (wt=1) in the foam buildup. More...
 
Double_t fNevGen
 Total number of the generated MC events. More...
 
Int_t fNoAct
 Number of active cells. More...
 
Int_t fNSampl
 No. of MC events, when dividing (exploring) cell. More...
 
Int_t fOptDrive
 Optimization switch =1,2 for variance or maximum weight optimization. More...
 
Int_t fOptPRD
 Option switch for predefined division, for quick check. More...
 
Int_t fOptRej
 Switch =0 for weighted events; =1 for unweighted events in MC. More...
 
Double_tfPrimAcu
 [fNoAct] Array of cumulative probability of all active cells More...
 
Double_t fPrime
 Primary integral R' (R=R'<wt>) More...
 
TRandomfPseRan
 Pointer to user-defined generator of pseudorandom numbers. More...
 
TFoamIntegrandfRho
 ! Pointer to the user-defined integrand function/distribution More...
 
Int_t fRNmax
 Maximum No. of the rand. numb. requested at once. More...
 
Double_tfRvec
 [fRNmax] random number vector from r.n. generator fDim+1 maximum elements More...
 
Double_t fSumOve
 Total Sum of overweighted events. More...
 
Double_t fSumWt
 
Double_t fSumWt2
 Total sum of wt and wt^2. More...
 
TString fVersion
 Actual version of the FOAM like (1.01m) More...
 
Double_t fWtMax
 
Double_t fWtMin
 Maximum/Minimum MC weight. More...
 
TFoamVect ** fXdivPRD
 ! Lists of division values encoded in one vector per direction More...
 

Private Member Functions

Double_t Sqr (Double_t x) const
 

Additional Inherited Members

- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000, kNotDeleted = 0x02000000, kZombie = 0x04000000, kInconsistent = 0x08000000,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = BIT(0), kOverwrite = BIT(1), kWriteDelete = BIT(2) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = BIT(3) }
 
enum  EStatusBits {
  kCanDelete = BIT(0), kMustCleanup = BIT(3), kIsReferenced = BIT(4), kHasUUID = BIT(5),
  kCannotPick = BIT(6), kNoContextMenu = BIT(8), kInvalidObject = BIT(13)
}
 
- Static Public Member Functions inherited from TObject
static Long_t GetDtorOnly ()
 Return destructor only flag. More...
 
static Bool_t GetObjectStat ()
 Get status of object stat flag. More...
 
static void SetDtorOnly (void *obj)
 Set destructor only flag. More...
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable. More...
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected). More...
 
void MakeZombie ()
 

#include <TFoam.h>

Inheritance diagram for TFoam:
[legend]

Constructor & Destructor Documentation

◆ TFoam() [1/3]

TFoam::TFoam ( )

Default constructor for streamer, user should not use it.

Definition at line 146 of file TFoam.cxx.

◆ TFoam() [2/3]

TFoam::TFoam ( const Char_t Name)

User constructor, to be employed by the user.

Definition at line 167 of file TFoam.cxx.

◆ ~TFoam()

TFoam::~TFoam ( )
virtual

Default destructor.

Definition at line 230 of file TFoam.cxx.

◆ TFoam() [3/3]

TFoam::TFoam ( const TFoam From)

Copy Constructor NOT IMPLEMENTED (NEVER USED)

Definition at line 269 of file TFoam.cxx.

Member Function Documentation

◆ Carver()

void TFoam::Carver ( Int_t kBest,
Double_t xBest,
Double_t yBest 
)
virtual

Internal method used by Initialize.

Determines the best edge-candidate and the position of the division plane for the future cell division, in the case of the optimization of the maximum weight. It exploits results of the cell MC exploration run stored in fHistEdg.

Definition at line 751 of file TFoam.cxx.

◆ CellFill()

Int_t TFoam::CellFill ( Int_t  Status,
TFoamCell parent 
)
virtual

Internal method used by Initialize.

It initializes content of the newly allocated active cell.

Definition at line 479 of file TFoam.cxx.

◆ CheckAll()

void TFoam::CheckAll ( Int_t  level)
virtual

User utility, miscellaneous and debug.

Checks all pointers in the tree of cells. This is useful auto diagnostic.

  • level=0, no printout, failures causes STOP
  • level=1, printout, failures lead to WARNINGS only

Definition at line 1382 of file TFoam.cxx.

◆ Divide()

Int_t TFoam::Divide ( TFoamCell cell)
virtual

Internal method used by Initialize.

It divides cell iCell into two daughter cells. The iCell is retained and tagged as inactive, daughter cells are appended at the end of the buffer. New vertex is added to list of vertices. List of active cells is updated, iCell removed, two daughters added and their properties set with help of MC sampling (TFoam_Explore) Returns Code RC=-1 of buffer limit is reached, fLastCe=fnBuf.

Definition at line 936 of file TFoam.cxx.

◆ Eval()

Double_t TFoam::Eval ( Double_t xRand)
virtual

Internal method.

Evaluates distribution to be generated.

Definition at line 1066 of file TFoam.cxx.

◆ Explore()

void TFoam::Explore ( TFoamCell cell)
virtual

Internal method used by Initialize.

It explores newly defined cell with help of special short MC sampling. As a result, estimates of true and drive volume is defined/determined Average and dispersion of the weight distribution will is found along each edge and the best edge (minimum dispersion, best maximum weight) is memorized for future use.

The optimal division point for eventual future cell division is determined/recorded. Recorded are also minimum and maximum weight etc. The volume estimate in all (inactive) parent cells is updated. Note that links to parents and initial volume = 1/2 parent has to be already defined prior to calling this routine.

Definition at line 522 of file TFoam.cxx.

◆ Finalize()

void TFoam::Finalize ( Double_t IntNorm,
Double_t Errel 
)
virtual

May be called optionally by the user after the MC run.

It provides normalization and also prints some information/statistics on the MC run.

Definition at line 1260 of file TFoam.cxx.

◆ GenerCel2()

void TFoam::GenerCel2 ( TFoamCell *&  pCell)
virtual

Internal method.

Return randomly chosen active cell with probability equal to its contribution into total driver integral using interpolation search.

Definition at line 1088 of file TFoam.cxx.

◆ GetIntegMC()

void TFoam::GetIntegMC ( Double_t mcResult,
Double_t mcError 
)
virtual

User method.

It provides the value of the integral calculated from the averages of the MC run May be called after (or during) the MC run.

Definition at line 1211 of file TFoam.cxx.

◆ GetIntNorm()

void TFoam::GetIntNorm ( Double_t IntNorm,
Double_t Errel 
)
virtual

User method.

It returns NORMALIZATION integral to be combined with the average weights and content of the histograms in order to get proper absolute normalization of the integrand and distributions. It can be called after initialization, before or during the MC run.

Definition at line 1230 of file TFoam.cxx.

◆ GetMCvect()

void TFoam::GetMCvect ( Double_t MCvect)
virtual

User may get generated MC point/vector with help of this method.

Definition at line 1176 of file TFoam.cxx.

◆ GetMCwt() [1/2]

Double_t TFoam::GetMCwt ( void  )
virtual

User may get weight MC weight using this method.

Definition at line 1184 of file TFoam.cxx.

◆ GetMCwt() [2/2]

void TFoam::GetMCwt ( Double_t mcwt)
virtual

User may get weight MC weight using this method.

Definition at line 1191 of file TFoam.cxx.

◆ GetnCalls()

virtual Long_t TFoam::GetnCalls ( ) const
inlinevirtual

Definition at line 131 of file TFoam.h.

◆ GetnEffev()

virtual Long_t TFoam::GetnEffev ( ) const
inlinevirtual

Definition at line 132 of file TFoam.h.

◆ GetPrimary() [1/2]

virtual Double_t TFoam::GetPrimary ( ) const
inlinevirtual

Definition at line 129 of file TFoam.h.

◆ GetPrimary() [2/2]

virtual void TFoam::GetPrimary ( Double_t prime)
inlinevirtual

Definition at line 130 of file TFoam.h.

◆ GetPseRan()

virtual TRandom* TFoam::GetPseRan ( ) const
inlinevirtual

Definition at line 108 of file TFoam.h.

◆ GetRho()

virtual TFoamIntegrand* TFoam::GetRho ( )
inlinevirtual

Definition at line 107 of file TFoam.h.

◆ GetTotDim()

virtual Int_t TFoam::GetTotDim ( ) const
inlinevirtual

Definition at line 128 of file TFoam.h.

◆ GetVersion()

virtual const char* TFoam::GetVersion ( ) const
inlinevirtual

Definition at line 127 of file TFoam.h.

◆ GetWtParams()

void TFoam::GetWtParams ( Double_t  eps,
Double_t aveWt,
Double_t wtMax,
Double_t sigma 
)
virtual

May be called optionally after the MC run.

Returns various parameters of the MC weight for efficiency evaluation

Definition at line 1247 of file TFoam.cxx.

◆ Grow()

void TFoam::Grow ( )
virtual

Internal method used by Initialize.

It grow new cells by the binary division process.

Definition at line 864 of file TFoam.cxx.

◆ InitCells()

void TFoam::InitCells ( )
virtual

Internal method used by Initialize.

It initializes "root part" of the FOAM of the tree of cells.

Definition at line 447 of file TFoam.cxx.

◆ Initialize() [1/2]

void TFoam::Initialize ( )
virtual

Basic initialization of FOAM invoked by the user.

IMPORTANT: Random number generator and the distribution object has to be provided using SetPseRan and SetRho prior to invoking this initialiser!

Definition at line 323 of file TFoam.cxx.

◆ Initialize() [2/2]

void TFoam::Initialize ( TRandom PseRan,
TFoamIntegrand fun 
)
virtual

Basic initialization of FOAM invoked by the user. Mandatory!

This method starts the process of the cell build-up. User must invoke Initialize with two arguments or Initialize without arguments. This is done BEFORE generating first MC event and AFTER allocating FOAM object and reseting (optionally) its internal parameters/switches. The overall operational scheme of the FOAM is the following:

This method invokes several other methods:

InitCells initializes memory storage for cells and begins exploration process from the root cell. The empty cells are allocated/filled using CellFill. The procedure Grow which loops over cells, picks up the cell with the biggest `‘driver integral’', see Comp. Phys. Commun. 152 152 (2003) 55 for explanations, with the help of PeekMax procedure. The chosen cell is split using Divide. Subsequently, the procedure Explore called by the Divide (and by InitCells for the root cell) does the most important job in the FOAM object build-up: it performs a small MC run for each newly allocated daughter cell. Explore calculates how profitable the future split of the cell will be and defines the optimal cell division geometry with the help of Carver or Varedu procedures, for maximum weight or variance optimization respectively. All essential results of the exploration are written into the explored cell object. At the very end of the foam build-up, Finally, MakeActiveList is invoked to create a list of pointers to all active cells, for the purpose of the quick access during the MC generation. The procedure Explore employs MakeAlpha to generate random coordinates inside a given cell with the uniform distribution. The above sequence of the procedure calls is depicted in the following figure:

Definition at line 309 of file TFoam.cxx.

◆ LinkCells()

void TFoam::LinkCells ( void  )
virtual

Definition at line 1521 of file TFoam.cxx.

◆ MakeActiveList()

void TFoam::MakeActiveList ( )
virtual

Internal method used by Initialize.

It finds out number of active cells fNoAct, creates list of active cell fCellsAct and primary cumulative fPrimAcu. They are used during the MC generation to choose randomly an active cell.

Definition at line 969 of file TFoam.cxx.

◆ MakeAlpha()

void TFoam::MakeAlpha ( )
virtual

Internal method used by Initialize.

Provides random vector Alpha 0< Alpha(i) < 1

Definition at line 849 of file TFoam.cxx.

◆ MakeEvent()

void TFoam::MakeEvent ( void  )
virtual

User method.

It generates randomly point/vector according to user-defined distribution. Prior initialization with help of Initialize() is mandatory. Generated MC point/vector is available using GetMCvect and the MC weight with GetMCwt. MC point is generated with wt=1 or with variable weight, see OptRej switch.

Definition at line 1126 of file TFoam.cxx.

◆ MCgenerate()

Double_t TFoam::MCgenerate ( Double_t MCvect)
virtual

User method which generates MC event and returns MC weight.

Definition at line 1199 of file TFoam.cxx.

◆ PeekMax()

Long_t TFoam::PeekMax ( )
virtual

Internal method used by Initialize.

It finds cell with maximal driver integral for the purpose of the division.

Definition at line 902 of file TFoam.cxx.

◆ PrintCells()

void TFoam::PrintCells ( void  )
virtual

Prints geometry of ALL cells of the FOAM.

Definition at line 1450 of file TFoam.cxx.

◆ ResetPseRan()

void TFoam::ResetPseRan ( TRandom PseRan)
virtual

User may optionally reset random number generator using this method.

Usually it is done when FOAM object is restored from the disk. IMPORTANT: this method deletes existing random number generator registered in the FOAM object. In particular such an object is created by the streamer during the disk-read operation.

Definition at line 1010 of file TFoam.cxx.

◆ ResetRho()

void TFoam::ResetRho ( TFoamIntegrand fun)
virtual

User may optionally reset the distribution using this method.

Usually it is done when FOAM object is restored from the disk. IMPORTANT: this method deletes existing distribution object registered in the FOAM object. In particular such an object is created by the streamer diring the disk-read operation. This method is used only in very special cases, because the distribution in most cases should be "owned" by the FOAM object and should not be replaced by another one after initialization.

Definition at line 1053 of file TFoam.cxx.

◆ RootPlot2dim()

void TFoam::RootPlot2dim ( Char_t filename)
virtual

Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root.

Definition at line 1467 of file TFoam.cxx.

◆ SetChat()

virtual void TFoam::SetChat ( Int_t  Chat)
inlinevirtual

Definition at line 119 of file TFoam.h.

◆ SetEvPerBin()

virtual void TFoam::SetEvPerBin ( Int_t  EvPerBin)
inlinevirtual

Definition at line 122 of file TFoam.h.

◆ SetInhiDiv()

void TFoam::SetInhiDiv ( Int_t  iDim,
Int_t  InhiDiv 
)
virtual

This can be called before Initialize, after setting kDim It defines which variables are excluded in the process of the cell division.

For example 'FoamX->SetInhiDiv(1, 1);' inhibits division of y-variable. The resulting map of cells in 2-dim. case will look as follows:

Definition at line 1312 of file TFoam.cxx.

◆ SetkDim()

virtual void TFoam::SetkDim ( Int_t  kDim)
inlinevirtual

Definition at line 115 of file TFoam.h.

◆ SetMaxWtRej()

virtual void TFoam::SetMaxWtRej ( Double_t  MaxWtRej)
inlinevirtual

Definition at line 123 of file TFoam.h.

◆ SetnBin()

virtual void TFoam::SetnBin ( Int_t  nBin)
inlinevirtual

Definition at line 118 of file TFoam.h.

◆ SetnCells()

virtual void TFoam::SetnCells ( Long_t  nCells)
inlinevirtual

Definition at line 116 of file TFoam.h.

◆ SetnSampl()

virtual void TFoam::SetnSampl ( Long_t  nSampl)
inlinevirtual

Definition at line 117 of file TFoam.h.

◆ SetOptDrive()

virtual void TFoam::SetOptDrive ( Int_t  OptDrive)
inlinevirtual

Definition at line 121 of file TFoam.h.

◆ SetOptRej()

virtual void TFoam::SetOptRej ( Int_t  OptRej)
inlinevirtual

Definition at line 120 of file TFoam.h.

◆ SetPseRan()

virtual void TFoam::SetPseRan ( TRandom PseRan)
inlinevirtual

Definition at line 112 of file TFoam.h.

◆ SetRho()

void TFoam::SetRho ( TFoamIntegrand Rho)
virtual

User may use this method to set the distribution object.

Definition at line 1022 of file TFoam.cxx.

◆ SetRhoInt()

void TFoam::SetRhoInt ( Double_t(*)(Int_t, Double_t *)  fun)
virtual

User may use this method to set the distribution object as a global function pointer (and not as an interpreted function).

Definition at line 1033 of file TFoam.cxx.

◆ SetXdivPRD()

void TFoam::SetXdivPRD ( Int_t  iDim,
Int_t  len,
Double_t  xDiv[] 
)
virtual

This should be called before Initialize, after setting kDim It predefines values of the cell division for certain variable iDim.

For example setting 3 predefined division lines using:

xDiv[0]=0.30; xDiv[1]=0.40; xDiv[2]=0.65;
FoamX->SetXdivPRD(0,3,xDiv);

results in the following 2-dim. pattern of the cells:

Definition at line 1342 of file TFoam.cxx.

◆ Sqr()

Double_t TFoam::Sqr ( Double_t  x) const
inlineprivate

Definition at line 140 of file TFoam.h.

◆ Varedu()

void TFoam::Varedu ( Double_t  [],
Int_t ,
Double_t ,
Double_t  
)
virtual

Internal method used by Initialize.

It determines the best edge candidate and the position of the cell division plane in case of the variance reduction for future cell division, using results of the MC exploration run stored in fHistEdg

Definition at line 674 of file TFoam.cxx.

Member Data Documentation

◆ fAlpha

Double_t* TFoam::fAlpha
protected

[fDim] Internal parameters of the hyper-rectangle

Definition at line 74 of file TFoam.h.

◆ fCells

TFoamCell** TFoam::fCells
protected

[fNCells] Array of ALL cells

Definition at line 46 of file TFoam.h.

◆ fCellsAct

std::vector<Long_t> TFoam::fCellsAct
protected

Index of active cells, constructed at the end of foam build-up.

Definition at line 50 of file TFoam.h.

◆ fChat

Int_t TFoam::fChat
protected

Chat=0,1,2 chat level in output, Chat=1 normal level.

Definition at line 32 of file TFoam.h.

◆ fDate

TString TFoam::fDate
protected

Release date of FOAM.

Definition at line 26 of file TFoam.h.

◆ fDim

Int_t TFoam::fDim
protected

Dimension of the integration/simulation space.

Definition at line 27 of file TFoam.h.

◆ fEvPerBin

Int_t TFoam::fEvPerBin
protected

Maximum number of effective (wt=1) events per bin.

Definition at line 37 of file TFoam.h.

◆ fHistDbg

TObjArray* TFoam::fHistDbg
protected

Histograms of wt, for debug.

Definition at line 53 of file TFoam.h.

◆ fHistEdg

TObjArray* TFoam::fHistEdg
protected

Histograms of wt, one for each cell edge.

Definition at line 52 of file TFoam.h.

◆ fHistWt

TH1D* TFoam::fHistWt
protected

Histogram of the MC wt.

Definition at line 54 of file TFoam.h.

◆ fInhiDiv

Int_t* TFoam::fInhiDiv
protected

! [fDim] Flags for inhibiting cell division

Definition at line 40 of file TFoam.h.

◆ fLastCe

Int_t TFoam::fLastCe
protected

Index of the last cell.

Definition at line 45 of file TFoam.h.

◆ fMaskDiv

Int_t* TFoam::fMaskDiv
protected

! [fDim] Dynamic Mask for cell division

Definition at line 39 of file TFoam.h.

◆ fMaxWtRej

Double_t TFoam::fMaxWtRej
protected

Maximum weight in rejection for getting wt=1 events.

Definition at line 49 of file TFoam.h.

◆ fMCerror

Double_t TFoam::fMCerror
protected

and its error

Definition at line 72 of file TFoam.h.

◆ fMCMonit

TFoamMaxwt* TFoam::fMCMonit
protected

Monitor of the MC weight for measuring MC efficiency.

Definition at line 48 of file TFoam.h.

◆ fMCresult

Double_t TFoam::fMCresult
protected

True Integral R from MC series.

Definition at line 71 of file TFoam.h.

◆ fMCvect

Double_t* TFoam::fMCvect
protected

[fDim] Generated MC vector for the outside user

Definition at line 56 of file TFoam.h.

◆ fMCwt

Double_t TFoam::fMCwt
protected

MC weight.

Definition at line 57 of file TFoam.h.

◆ fMethodCall

TMethodCall* TFoam::fMethodCall
protected

! ROOT's pointer to user-defined global distribution function

Definition at line 61 of file TFoam.h.

◆ fName

TString TFoam::fName
protected

Name of a given instance of the FOAM class.

Definition at line 24 of file TFoam.h.

◆ fNBin

Int_t TFoam::fNBin
protected

No. of bins in the edge histogram for cell MC exploration.

Definition at line 35 of file TFoam.h.

◆ fNCalls

Long_t TFoam::fNCalls
protected

Total number of the function calls.

Definition at line 64 of file TFoam.h.

◆ fNCells

Int_t TFoam::fNCells
protected

Maximum number of cells.

Definition at line 28 of file TFoam.h.

◆ fNEffev

Long_t TFoam::fNEffev
protected

Total number of effective events (wt=1) in the foam buildup.

Definition at line 65 of file TFoam.h.

◆ fNevGen

Double_t TFoam::fNevGen
protected

Total number of the generated MC events.

Definition at line 68 of file TFoam.h.

◆ fNoAct

Int_t TFoam::fNoAct
protected

Number of active cells.

Definition at line 44 of file TFoam.h.

◆ fNSampl

Int_t TFoam::fNSampl
protected

No. of MC events, when dividing (exploring) cell.

Definition at line 36 of file TFoam.h.

◆ fOptDrive

Int_t TFoam::fOptDrive
protected

Optimization switch =1,2 for variance or maximum weight optimization.

Definition at line 31 of file TFoam.h.

◆ fOptPRD

Int_t TFoam::fOptPRD
protected

Option switch for predefined division, for quick check.

Definition at line 41 of file TFoam.h.

◆ fOptRej

Int_t TFoam::fOptRej
protected

Switch =0 for weighted events; =1 for unweighted events in MC.

Definition at line 33 of file TFoam.h.

◆ fPrimAcu

Double_t* TFoam::fPrimAcu
protected

[fNoAct] Array of cumulative probability of all active cells

Definition at line 51 of file TFoam.h.

◆ fPrime

Double_t TFoam::fPrime
protected

Primary integral R' (R=R'<wt>)

Definition at line 70 of file TFoam.h.

◆ fPseRan

TRandom* TFoam::fPseRan
protected

Pointer to user-defined generator of pseudorandom numbers.

Definition at line 62 of file TFoam.h.

◆ fRho

TFoamIntegrand* TFoam::fRho
protected

! Pointer to the user-defined integrand function/distribution

Definition at line 60 of file TFoam.h.

◆ fRNmax

Int_t TFoam::fRNmax
protected

Maximum No. of the rand. numb. requested at once.

Definition at line 29 of file TFoam.h.

◆ fRvec

Double_t* TFoam::fRvec
protected

[fRNmax] random number vector from r.n. generator fDim+1 maximum elements

Definition at line 58 of file TFoam.h.

◆ fSumOve

Double_t TFoam::fSumOve
protected

Total Sum of overweighted events.

Definition at line 67 of file TFoam.h.

◆ fSumWt

Double_t TFoam::fSumWt
protected

Definition at line 66 of file TFoam.h.

◆ fSumWt2

Double_t TFoam::fSumWt2
protected

Total sum of wt and wt^2.

Definition at line 66 of file TFoam.h.

◆ fVersion

TString TFoam::fVersion
protected

Actual version of the FOAM like (1.01m)

Definition at line 25 of file TFoam.h.

◆ fWtMax

Double_t TFoam::fWtMax
protected

Definition at line 69 of file TFoam.h.

◆ fWtMin

Double_t TFoam::fWtMin
protected

Maximum/Minimum MC weight.

Definition at line 69 of file TFoam.h.

◆ fXdivPRD

TFoamVect** TFoam::fXdivPRD
protected

! Lists of division values encoded in one vector per direction

Definition at line 42 of file TFoam.h.

Libraries for TFoam:
[legend]

The documentation for this class was generated from the following files:
TFoam::GetIntegMC
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1211
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::TFoam
TFoam()
Default constructor for streamer, user should not use it.
Definition: TFoam.cxx:146
TFoam::MakeEvent
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1126
exp
double exp(double)
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TCanvas.h
TFoam.h
TFoamIntegrand.h
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:37
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
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
Definition: TFoam.h:21
TRandom
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
TRandom3
Random number generator class based on M.
Definition: TRandom3.h:27
TCanvas::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:708
TH2D
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:292
TRandom::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:608
TFoam::GetMCvect
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1176
TRandom3.h
y
Double_t y[n]
Definition: legend1.C:17
TFoam::Initialize
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:323
TH2.h
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
ROOT::Math::GSLSimAn::Dist
double Dist(void *xp, void *yp)
Definition: GSLSimAnnealing.cxx:129
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
The Canvas class.
Definition: TCanvas.h:23
ROOT::Math::sqr
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:206
TCanvas::Update
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2504
TFoam::SetkDim
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:115
TFoam::SetnCells
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:116
TFoam::SetPseRan
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:112
Riostream.h
TMath.h
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050