00001 // @(#)root/foam:$Id: TFoam.h 24840 2008-07-16 06:33:28Z brun $ 00002 // Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl> 00003 00004 #ifndef ROOT_TFoam 00005 #define ROOT_TFoam 00006 00007 ////////////////////////////////////////////////////////////////////////////// 00008 // // 00009 // TFoam is the main class of the multi-dimensional general purpose // 00010 // Monte Carlo event generator (integrator) FOAM. // 00011 // // 00012 ////////////////////////////////////////////////////////////////////////////// 00013 00014 #ifndef ROOT_TObject 00015 #include "TObject.h" 00016 #endif 00017 00018 #include "TString.h" 00019 00020 class TH1D; 00021 class TRefArray; 00022 class TMethodCall; 00023 class TRandom; 00024 class TFoamIntegrand; 00025 class TFoamMaxwt; 00026 class TFoamVect; 00027 class TFoamCell; 00028 00029 class TFoam : public TObject { 00030 protected: 00031 // COMPONENTS // 00032 //-------------- Input parameters 00033 TString fName; // Name of a given instance of the FOAM class 00034 TString fVersion; // Actual version of the FOAM like (1.01m) 00035 TString fDate; // Release date of FOAM 00036 Int_t fDim; // Dimension of the integration/simulation space 00037 Int_t fNCells; // Maximum number of cells 00038 Int_t fRNmax; // Maximum No. of the rand. numb. requested at once 00039 //------------------- 00040 Int_t fOptDrive; // Optimization switch =1,2 for variance or maximum weight optimization 00041 Int_t fChat; // Chat=0,1,2 chat level in output, Chat=1 normal level 00042 Int_t fOptRej; // Switch =0 for weighted events; =1 for unweighted events in MC 00043 //------------------- 00044 Int_t fNBin; // No. of bins in the edge histogram for cell MC exploration 00045 Int_t fNSampl; // No. of MC events, when dividing (exploring) cell 00046 Int_t fEvPerBin; // Maximum number of effective (wt=1) events per bin 00047 //------------------- MULTI-BRANCHING --------------------- 00048 Int_t *fMaskDiv; //! [fDim] Dynamic Mask for cell division 00049 Int_t *fInhiDiv; //! [fDim] Flags for inhibiting cell division 00050 Int_t fOptPRD; // Option switch for predefined division, for quick check 00051 TFoamVect **fXdivPRD; //! Lists of division values encoded in one vector per direction 00052 //------------------- GEOMETRY ---------------------------- 00053 Int_t fNoAct; // Number of active cells 00054 Int_t fLastCe; // Index of the last cell 00055 TFoamCell **fCells; // [fNCells] Array of ALL cells 00056 //------------------ M.C. generation---------------------------- 00057 TFoamMaxwt *fMCMonit; // Monitor of the MC weight for measuring MC efficiency 00058 Double_t fMaxWtRej; // Maximum weight in rejection for getting wt=1 events 00059 TRefArray *fCellsAct; // Array of pointers to active cells, constructed at the end of foam build-up 00060 Double_t *fPrimAcu; // [fNoAct] Array of cumulative probability of all active cells 00061 TObjArray *fHistEdg; // Histograms of wt, one for each cell edge 00062 TObjArray *fHistDbg; // Histograms of wt, for debug 00063 TH1D *fHistWt; // Histogram of the MC wt 00064 00065 Double_t *fMCvect; // [fDim] Generated MC vector for the outside user 00066 Double_t fMCwt; // MC weight 00067 Double_t *fRvec; // [fRNmax] random number vector from r.n. generator fDim+1 maximum elements 00068 //----------- Procedures 00069 TFoamIntegrand *fRho; //! Pointer to the user-defined integrand function/distribution 00070 TMethodCall *fMethodCall; //! ROOT's pointer to user-defined global distribution function 00071 TRandom *fPseRan; // Pointer to user-defined generator of pseudorandom numbers 00072 //----------- Statistics and MC results 00073 Long_t fNCalls; // Total number of the function calls 00074 Long_t fNEffev; // Total number of effective events (wt=1) in the foam buildup 00075 Double_t fSumWt, fSumWt2; // Total sum of wt and wt^2 00076 Double_t fSumOve; // Total Sum of overveighted events 00077 Double_t fNevGen; // Total number of the generated MC events 00078 Double_t fWtMax, fWtMin; // Maximum/Minimum MC weight 00079 Double_t fPrime; // Primary integral R' (R=R'<wt>) 00080 Double_t fMCresult; // True Integral R from MC series 00081 Double_t fMCerror; // and its error 00082 //---------- working space for CELL exploration ------------- 00083 Double_t *fAlpha; // [fDim] Internal parameters of the hyperrectangle 00084 ////////////////////////////////////////////////////////////////////////////////////////////// 00085 // METHODS // 00086 ////////////////////////////////////////////////////////////////////////////////////////////// 00087 public: 00088 TFoam(); // Default constructor (used only by ROOT streamer) 00089 TFoam(const Char_t*); // Principal user-defined constructor 00090 virtual ~TFoam(); // Default destructor 00091 TFoam(const TFoam&); // Copy Constructor NOT USED 00092 // Initialization 00093 virtual void Initialize(); // Initialization of the FOAM (grid, cells, etc), mandatory! 00094 virtual void Initialize(TRandom *, TFoamIntegrand *); // Alternative initialization method, backward compatibility 00095 virtual void InitCells(); // Initializes first cells inside original cube 00096 virtual Int_t CellFill(Int_t, TFoamCell*); // Allocates new empty cell and return its index 00097 virtual void Explore(TFoamCell *Cell); // Exploration of the new cell, determine <wt>, wtMax etc. 00098 virtual void Carver(Int_t&,Double_t&,Double_t&);// Determines the best edge, wt_max reduction 00099 virtual void Varedu(Double_t [], Int_t&, Double_t&,Double_t&); // Determines the best edge, variace reduction 00100 virtual void MakeAlpha(); // Provides random point inside hyperrectangle 00101 virtual void Grow(); // Adds new cells to FOAM object until buffer is full 00102 virtual Long_t PeekMax(); // Choose one active cell, used by Grow and also in MC generation 00103 virtual Int_t Divide(TFoamCell *); // Divide iCell into two daughters; iCell retained, taged as inactive 00104 virtual void MakeActiveList(); // Creates table of active cells 00105 virtual void GenerCel2(TFoamCell *&); // Chose an active cell the with probability ~ Primary integral 00106 // Generation 00107 virtual Double_t Eval(Double_t *); // Evaluates value of the distribution function 00108 virtual void MakeEvent(); // Makes (generates) single MC event 00109 virtual void GetMCvect(Double_t *); // Provides generated randomly MC vector 00110 virtual void GetMCwt(Double_t &); // Provides generated MC weight 00111 virtual Double_t GetMCwt(); // Provides generates MC weight 00112 virtual Double_t MCgenerate(Double_t *MCvect);// All three above function in one 00113 // Finalization 00114 virtual void GetIntegMC(Double_t&, Double_t&);// Provides Integrand and abs. error from MC run 00115 virtual void GetIntNorm(Double_t&, Double_t&);// Provides normalization Inegrand 00116 virtual void GetWtParams(Double_t, Double_t&, Double_t&, Double_t&);// Provides MC weight parameters 00117 virtual void Finalize( Double_t&, Double_t&); // Prints summary of MC integration 00118 virtual TFoamIntegrand *GetRho(){return fRho;} // Gets pointer of the distribut. (after restoring from disk) 00119 virtual TRandom *GetPseRan() const {return fPseRan;} // Gets pointer of r.n. generator (after restoring from disk) 00120 virtual void SetRhoInt(void *Rho); // Set new integrand distr. in interactive mode 00121 virtual void SetRho(TFoamIntegrand *Rho); // Set new integrand distr. in compiled mode 00122 virtual void ResetRho(TFoamIntegrand *Rho); // Set new distribution, delete old 00123 virtual void SetPseRan(TRandom *PseRan){fPseRan=PseRan;} // Set new r.n. generator 00124 virtual void ResetPseRan(TRandom *PseRan); // Set new r.n.g, delete old 00125 // Getters and Setters 00126 virtual void SetkDim(Int_t kDim){fDim = kDim;} // Sets dimension of cubical space 00127 virtual void SetnCells(Long_t nCells){fNCells =nCells;} // Sets maximum number of cells 00128 virtual void SetnSampl(Long_t nSampl){fNSampl =nSampl;} // Sets no of MC events in cell exploration 00129 virtual void SetnBin(Int_t nBin){fNBin = nBin;} // Sets no of bins in histogs in cell exploration 00130 virtual void SetChat(Int_t Chat){fChat = Chat;} // Sets option Chat, chat level 00131 virtual void SetOptRej(Int_t OptRej){fOptRej =OptRej;} // Sets option for MC rejection 00132 virtual void SetOptDrive(Int_t OptDrive){fOptDrive =OptDrive;} // Sets optimization switch 00133 virtual void SetEvPerBin(Int_t EvPerBin){fEvPerBin =EvPerBin;} // Sets max. no. of effective events per bin 00134 virtual void SetMaxWtRej(Double_t MaxWtRej){fMaxWtRej=MaxWtRej;} // Sets max. weight for rejection 00135 virtual void SetInhiDiv(Int_t, Int_t ); // Set inhibition of cell division along certain edge 00136 virtual void SetXdivPRD(Int_t, Int_t, Double_t[]); // Set predefined division points 00137 // Getters and Setters 00138 virtual const char *GetVersion() const {return fVersion.Data();}// Get version of the FOAM 00139 virtual Int_t GetTotDim() const { return fDim;} // Get total dimension 00140 virtual Double_t GetPrimary() const {return fPrime;} // Get value of primary integral R' 00141 virtual void GetPrimary(Double_t &prime) {prime = fPrime;} // Get value of primary integral R' 00142 virtual Long_t GetnCalls() const {return fNCalls;} // Get total no. of the function calls 00143 virtual Long_t GetnEffev() const {return fNEffev;} // Get total no. of effective wt=1 events 00144 // Debug 00145 virtual void CheckAll(Int_t); // Checks correctness of the entire data structure in the FOAM object 00146 virtual void PrintCells(); // Prints content of all cells 00147 virtual void RootPlot2dim(Char_t*); // Generates C++ code for drawing foam 00148 virtual void LinkCells(void); // Void function for backward compatibility 00149 // Inline 00150 private: 00151 Double_t Sqr(Double_t x) const { return x*x;} // Square function 00152 ////////////////////////////////////////////////////////////////////////////////////////////// 00153 ClassDef(TFoam,1); // General purpose self-adapting Monte Carlo event generator 00154 }; 00155 00156 #endif