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:
}
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;
}
cout<<"--- kanwa started ---"<<endl;
TH2D *hst_xy =
new TH2D(
"hst_xy" ,
"x-y plot", 50,0,1.0, 50,0,1.0);
TCanvas *cKanwa =
new TCanvas(
"cKanwa",
"Canvas for plotting",600,600);
int nshow=5000;
for(long loop=0; loop<100000; loop++){
if(loop<10) cout<<
"(x,y) = ( "<<
x <<
", "<<
y <<
" )"<<endl;
if(loop == nshow){
nshow += 5000;
}
}
cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
cout<<"--- kanwa ended ---"<<endl;
return 0;
}
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
void Update() override
Update canvas pad buffers.
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
virtual void MakeEvent()
User method.
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
virtual void SetnCells(Long_t nCells)
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...
virtual void SetPseRan(TRandom *PseRan)
virtual void SetkDim(Int_t kDim)
TFoam()
Default constructor for streamer, user should not use it.
void Draw(Option_t *option="") override
Draw this histogram with options.
2-D histogram with a double per channel (see TH1 documentation)
Int_t Fill(Double_t) override
Invalid Fill method.
Random number generator class based on M.
This is the base class for the ROOT Random number generators.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
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.
|
| TFoam () |
| Default constructor for streamer, user should not use it.
|
|
| TFoam (const Char_t *) |
| User constructor, to be employed by the user.
|
|
| TFoam (const TFoam &) |
| Copy Constructor NOT IMPLEMENTED (NEVER USED)
|
|
| ~TFoam () override |
| Default destructor.
|
|
virtual void | Carver (Int_t &, Double_t &, Double_t &) |
| Internal method used by Initialize.
|
|
virtual Int_t | CellFill (Int_t, TFoamCell *) |
| Internal method used by Initialize.
|
|
virtual void | CheckAll (Int_t) |
| User utility, miscellaneous and debug.
|
|
virtual Int_t | Divide (TFoamCell *) |
| Internal method used by Initialize.
|
|
virtual Double_t | Eval (Double_t *) |
| Internal method.
|
|
virtual void | Explore (TFoamCell *Cell) |
| Internal method used by Initialize.
|
|
virtual void | Finalize (Double_t &, Double_t &) |
| May be called optionally by the user after the MC run.
|
|
virtual void | GenerCel2 (TFoamCell *&) |
| Internal method.
|
|
virtual void | GetIntegMC (Double_t &, Double_t &) |
| User method.
|
|
virtual void | GetIntNorm (Double_t &, Double_t &) |
| User method.
|
|
virtual void | GetMCvect (Double_t *) |
| User may get generated MC point/vector with help of this method.
|
|
virtual Double_t | GetMCwt () |
| User may get weight MC weight using this method.
|
|
virtual void | GetMCwt (Double_t &) |
| User may get weight MC weight using this method.
|
|
virtual Long_t | GetnCalls () const |
|
virtual Long_t | GetnEffev () const |
|
virtual Double_t | GetPrimary () const |
|
virtual void | GetPrimary (Double_t &prime) |
|
virtual TRandom * | GetPseRan () const |
|
virtual TFoamIntegrand * | GetRho () |
|
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.
|
|
virtual void | Grow () |
| Internal method used by Initialize.
|
|
virtual void | InitCells () |
| Internal method used by Initialize.
|
|
virtual void | Initialize () |
| Basic initialization of FOAM invoked by the user.
|
|
virtual void | Initialize (TRandom *, TFoamIntegrand *) |
|
TClass * | IsA () const override |
|
virtual void | LinkCells (void) |
|
virtual void | MakeActiveList () |
| Internal method used by Initialize.
|
|
virtual void | MakeAlpha () |
| Internal method used by Initialize.
|
|
virtual void | MakeEvent () |
| User method.
|
|
virtual Double_t | MCgenerate (Double_t *MCvect) |
| User method which generates MC event and returns MC weight.
|
|
virtual Long_t | PeekMax () |
| Internal method used by Initialize.
|
|
virtual void | PrintCells () |
| Prints geometry of ALL cells of the FOAM.
|
|
virtual void | ResetPseRan (TRandom *PseRan) |
| User may optionally reset random number generator using this method.
|
|
virtual void | ResetRho (TFoamIntegrand *Rho) |
| User may optionally reset the distribution using this method.
|
|
virtual void | RootPlot2dim (Char_t *) |
| Debugging tool which plots 2-dimensional cells as rectangles in C++ format readable for root.
|
|
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.
|
|
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.
|
|
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).
|
|
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.
|
|
void | Streamer (TBuffer &) override |
| Stream an object of class TObject.
|
|
void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
|
virtual void | Varedu (Double_t[5], Int_t &, Double_t &, Double_t &) |
| Internal method used by Initialize.
|
|
| TObject () |
| TObject constructor.
|
|
| TObject (const TObject &object) |
| TObject copy ctor.
|
|
virtual | ~TObject () |
| TObject destructor.
|
|
void | AbstractMethod (const char *method) const |
| Use this method to implement an "abstract" method that you don't want to leave purely abstract.
|
|
virtual void | AppendPad (Option_t *option="") |
| Append graphics object to current pad.
|
|
virtual void | Browse (TBrowser *b) |
| Browse object. May be overridden for another default action.
|
|
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.
|
|
virtual const char * | ClassName () const |
| Returns name of class to which the object belongs.
|
|
virtual void | Clear (Option_t *="") |
|
virtual TObject * | Clone (const char *newname="") const |
| Make a clone of an object using the Streamer facility.
|
|
virtual Int_t | Compare (const TObject *obj) const |
| Compare abstract method.
|
|
virtual void | Copy (TObject &object) const |
| Copy this to obj.
|
|
virtual void | Delete (Option_t *option="") |
| Delete this object.
|
|
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
| Computes distance from point (px,py) to the object.
|
|
virtual void | Draw (Option_t *option="") |
| Default Draw method for all objects.
|
|
virtual void | DrawClass () const |
| Draw class inheritance tree of the class to which this object belongs.
|
|
virtual TObject * | DrawClone (Option_t *option="") const |
| Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1) .
|
|
virtual void | Dump () const |
| Dump contents of object on stdout.
|
|
virtual void | Error (const char *method, const char *msgfmt,...) const |
| Issue error message.
|
|
virtual void | Execute (const char *method, const char *params, Int_t *error=nullptr) |
| Execute method on this object with the given parameter string, e.g.
|
|
virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr) |
| Execute method on this object with parameters stored in the TObjArray.
|
|
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
| Execute action corresponding to an event at (px,py).
|
|
virtual void | Fatal (const char *method, const char *msgfmt,...) const |
| Issue fatal error message.
|
|
virtual TObject * | FindObject (const char *name) const |
| Must be redefined in derived classes.
|
|
virtual TObject * | FindObject (const TObject *obj) const |
| Must be redefined in derived classes.
|
|
virtual Option_t * | GetDrawOption () const |
| Get option used by the graphics system to draw this object.
|
|
virtual const char * | GetIconName () const |
| Returns mime type name of object.
|
|
virtual const char * | GetName () const |
| Returns name of object.
|
|
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
| Returns string containing info about the object at position (px,py).
|
|
virtual Option_t * | GetOption () const |
|
virtual const char * | GetTitle () const |
| Returns title of object.
|
|
virtual UInt_t | GetUniqueID () const |
| Return the unique object id.
|
|
virtual Bool_t | HandleTimer (TTimer *timer) |
| Execute action in response of a timer timing out.
|
|
virtual ULong_t | Hash () const |
| Return hash value for this object.
|
|
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.
|
|
virtual void | Info (const char *method, const char *msgfmt,...) const |
| Issue info message.
|
|
virtual Bool_t | InheritsFrom (const char *classname) const |
| Returns kTRUE if object inherits from class "classname".
|
|
virtual Bool_t | InheritsFrom (const TClass *cl) const |
| Returns kTRUE if object inherits from TClass cl.
|
|
virtual void | Inspect () const |
| Dump contents of this object in a graphics canvas.
|
|
void | InvertBit (UInt_t f) |
|
Bool_t | IsDestructed () const |
| IsDestructed.
|
|
virtual Bool_t | IsEqual (const TObject *obj) const |
| Default equal comparison (objects are equal if they have the same address in memory).
|
|
virtual Bool_t | IsFolder () const |
| Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
|
|
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.
|
|
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).
|
|
virtual Bool_t | Notify () |
| This method must be overridden to handle object notification (the base implementation is no-op).
|
|
void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
| Use this method to declare a method obsolete.
|
|
void | operator delete (void *ptr) |
| Operator delete.
|
|
void | operator delete (void *ptr, void *vp) |
| Only called by placement new when throwing an exception.
|
|
void | operator delete[] (void *ptr) |
| Operator delete [].
|
|
void | operator delete[] (void *ptr, void *vp) |
| Only called by placement new[] when throwing an exception.
|
|
void * | operator new (size_t sz) |
|
void * | operator new (size_t sz, void *vp) |
|
void * | operator new[] (size_t sz) |
|
void * | operator new[] (size_t sz, void *vp) |
|
TObject & | operator= (const TObject &rhs) |
| TObject assignment operator.
|
|
virtual void | Paint (Option_t *option="") |
| This method must be overridden if a class wants to paint itself.
|
|
virtual void | Pop () |
| Pop on object drawn in a pad to the top of the display list.
|
|
virtual void | Print (Option_t *option="") const |
| This method must be overridden when a class wants to print itself.
|
|
virtual Int_t | Read (const char *name) |
| Read contents of object with specified name from the current directory.
|
|
virtual void | RecursiveRemove (TObject *obj) |
| Recursively remove this object from a list.
|
|
void | ResetBit (UInt_t f) |
|
virtual void | SaveAs (const char *filename="", Option_t *option="") const |
| Save this object in the file specified by filename.
|
|
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
| Save a primitive as a C++ statement(s) on output stream "out".
|
|
void | SetBit (UInt_t f) |
|
void | SetBit (UInt_t f, Bool_t set) |
| Set or unset the user status bits as specified in f.
|
|
virtual void | SetDrawOption (Option_t *option="") |
| Set drawing option for object.
|
|
virtual void | SetUniqueID (UInt_t uid) |
| Set the unique object id.
|
|
void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
|
virtual void | SysError (const char *method, const char *msgfmt,...) const |
| Issue system error message.
|
|
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.
|
|
virtual void | Warning (const char *method, const char *msgfmt,...) const |
| Issue warning message.
|
|
virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) |
| Write this object to the current directory.
|
|
virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const |
| Write this object to the current directory.
|
|