Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TFoam.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/foam:$Id$
0002 // Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl>
0003 
0004 #ifndef ROOT_TFoam
0005 #define ROOT_TFoam
0006 
0007 
0008 #include "TObject.h"
0009 #include "TString.h"
0010 
0011 #include <vector>
0012 
0013 class TH1D;
0014 class TMethodCall;
0015 class TRandom;
0016 class TFoamIntegrand;
0017 class TFoamMaxwt;
0018 class TFoamVect;
0019 class TFoamCell;
0020 
0021 class TFoam : public TObject {
0022 protected:
0023 
0024    TString fName;             ///< Name of a given instance of the FOAM class
0025    TString fVersion;          ///< Actual version of the FOAM like (1.01m)
0026    TString fDate;             ///< Release date of FOAM
0027    Int_t   fDim;              ///< Dimension of the integration/simulation space
0028    Int_t   fNCells;           ///< Maximum number of cells
0029    Int_t   fRNmax;            ///< Maximum No. of the rand. numb. requested at once
0030 
0031    Int_t   fOptDrive;         ///< Optimization switch =1,2 for variance or maximum weight optimization
0032    Int_t   fChat;             ///< Chat=0,1,2 chat level in output, Chat=1 normal level
0033    Int_t   fOptRej;           ///< Switch =0 for weighted events; =1 for unweighted events in MC
0034 
0035    Int_t   fNBin;             ///< No. of bins in the edge histogram for cell MC exploration
0036    Int_t   fNSampl;           ///< No. of MC events, when dividing (exploring) cell
0037    Int_t   fEvPerBin;         ///< Maximum number of effective (wt=1) events per bin
0038 
0039    Int_t  *fMaskDiv;          ///<! [fDim] Dynamic Mask for  cell division
0040    Int_t  *fInhiDiv;          ///<! [fDim] Flags for inhibiting cell division
0041    Int_t   fOptPRD;           ///<  Option switch for predefined division, for quick check
0042    TFoamVect **fXdivPRD;      ///<! Lists of division values encoded in one vector per direction
0043 
0044    Int_t   fNoAct;            ///< Number of active cells
0045    Int_t   fLastCe;           ///< Index of the last cell
0046    TFoamCell **fCells = nullptr; ///< [fNCells] Array of ALL cells
0047 
0048    TFoamMaxwt   *fMCMonit;    ///< Monitor of the MC weight for measuring MC efficiency
0049    Double_t   fMaxWtRej;      ///< Maximum weight in rejection for getting wt=1 events
0050    std::vector<Long_t> fCellsAct; ///< Index of active cells, constructed at the end of foam build-up
0051    Double_t  *fPrimAcu;       ///< [fNoAct] Array of cumulative probability of all active cells
0052    TObjArray *fHistEdg;       ///< Histograms of wt, one for each cell edge
0053    TObjArray *fHistDbg;       ///< Histograms of wt, for debug
0054    TH1D      *fHistWt;        ///< Histogram of the MC wt
0055 
0056    Double_t *fMCvect;         ///< [fDim] Generated MC vector for the outside user
0057    Double_t  fMCwt;           ///< MC weight
0058    Double_t *fRvec;           ///< [fRNmax] random number vector from r.n. generator fDim+1 maximum elements
0059 
0060    TFoamIntegrand *fRho;      ///<! Pointer to the user-defined integrand function/distribution
0061    TMethodCall *fMethodCall;  ///<! ROOT's pointer to user-defined global distribution function
0062    TRandom         *fPseRan;  ///< Pointer to user-defined generator of pseudorandom numbers
0063 
0064    Long_t   fNCalls;          ///< Total number of the function calls
0065    Long_t   fNEffev;          ///< Total number of effective events (wt=1) in the foam buildup
0066    Double_t fSumWt, fSumWt2;  ///< Total sum of wt and wt^2
0067    Double_t fSumOve;          ///< Total Sum of overweighted events
0068    Double_t fNevGen;          ///< Total number of the generated MC events
0069    Double_t fWtMax, fWtMin;   ///< Maximum/Minimum MC weight
0070    Double_t fPrime;           ///< Primary integral R' (R=R'`<wt>`)
0071    Double_t fMCresult;        ///< True Integral R from MC series
0072    Double_t fMCerror;         ///< and its error
0073 
0074    Double_t *fAlpha;          ///< [fDim] Internal parameters of the hyper-rectangle
0075 
0076 public:
0077    TFoam();                          // Default constructor (used only by ROOT streamer)
0078    TFoam(const Char_t*);             // Principal user-defined constructor
0079    ~TFoam() override;                 // Default destructor
0080    TFoam(const TFoam&);              // Copy Constructor  NOT USED
0081    // Initialization
0082    virtual void Initialize();                // Initialization of the FOAM (grid, cells, etc), mandatory!
0083    virtual void Initialize(TRandom *, TFoamIntegrand *); // Alternative initialization method, backward compatibility
0084    virtual void InitCells();                 // Initializes first cells inside original cube
0085    virtual Int_t  CellFill(Int_t, TFoamCell*);  // Allocates new empty cell and return its index
0086    virtual void Explore(TFoamCell *Cell);       // Exploration of the new cell, determine <wt>, wtMax etc.
0087    virtual void Carver(Int_t&,Double_t&,Double_t&);// Determines the best edge, wt_max reduction
0088    virtual void Varedu(Double_t [5], Int_t&, Double_t&,Double_t&); // Determines the best edge, variance reduction
0089    virtual void MakeAlpha();                 // Provides random point inside hyper-rectangle
0090    virtual void Grow();                      // Adds new cells to FOAM object until buffer is full
0091    virtual Long_t PeekMax();                 // Choose one active cell, used by Grow and also in MC generation
0092    virtual Int_t  Divide(TFoamCell *);       // Divide iCell into two daughters; iCell retained, tagged as inactive
0093    virtual void MakeActiveList();            // Creates table of active cells
0094    virtual void GenerCel2(TFoamCell *&);     // Chose an active cell the with probability ~ Primary integral
0095    // Generation
0096    virtual Double_t Eval(Double_t *);        // Evaluates value of the distribution function
0097    virtual void     MakeEvent();             // Makes (generates) single MC event
0098    virtual void     GetMCvect(Double_t *);   // Provides generated randomly MC vector
0099    virtual void     GetMCwt(Double_t &);     // Provides generated MC weight
0100    virtual Double_t GetMCwt();               // Provides generates MC weight
0101    virtual Double_t MCgenerate(Double_t *MCvect);// All three above function in one
0102    // Finalization
0103    virtual void GetIntegMC(Double_t&, Double_t&);// Provides Integrand and abs. error from MC run
0104    virtual void GetIntNorm(Double_t&, Double_t&);// Provides normalization Inegrand
0105    virtual void GetWtParams(Double_t, Double_t&, Double_t&, Double_t&);// Provides MC weight parameters
0106    virtual void Finalize(  Double_t&, Double_t&);  // Prints summary of MC integration
0107    virtual TFoamIntegrand  *GetRho(){return fRho;} // Gets pointer of the distribut. (after restoring from disk)
0108    virtual TRandom *GetPseRan() const {return fPseRan;}   // Gets pointer of r.n. generator (after restoring from disk)
0109    virtual void SetRhoInt(Double_t (*fun)(Int_t, Double_t *));    // Set new integrand distr. in compiled mode
0110    virtual void SetRho(TFoamIntegrand *Rho);       // Set new integrand distr. in compiled mode
0111    virtual void ResetRho(TFoamIntegrand *Rho);                // Set new distribution, delete old
0112    virtual void SetPseRan(TRandom *PseRan){fPseRan=PseRan;}   // Set new r.n. generator
0113    virtual void ResetPseRan(TRandom *PseRan);                 // Set new r.n.g, delete old
0114    // Getters and Setters
0115    virtual void SetkDim(Int_t kDim){fDim = kDim;}            // Sets dimension of cubical space
0116    virtual void SetnCells(Long_t nCells){fNCells =nCells;}  // Sets maximum number of cells
0117    virtual void SetnSampl(Long_t nSampl){fNSampl =nSampl;}  // Sets no of MC events in cell exploration
0118    virtual void SetnBin(Int_t nBin){fNBin = nBin;}          // Sets no of bins in histogs in cell exploration
0119    virtual void SetChat(Int_t Chat){fChat = Chat;}          // Sets option Chat, chat level
0120    virtual void SetOptRej(Int_t OptRej){fOptRej =OptRej;}   // Sets option for MC rejection
0121    virtual void SetOptDrive(Int_t OptDrive){fOptDrive =OptDrive;}  // Sets optimization switch
0122    virtual void SetEvPerBin(Int_t EvPerBin){fEvPerBin =EvPerBin;}  // Sets max. no. of effective events per bin
0123    virtual void SetMaxWtRej(Double_t MaxWtRej){fMaxWtRej=MaxWtRej;}  // Sets max. weight for rejection
0124    virtual void SetInhiDiv(Int_t, Int_t );            // Set inhibition of cell division along certain edge
0125    virtual void SetXdivPRD(Int_t, Int_t, Double_t[]); // Set predefined division points
0126    // Getters and Setters
0127    virtual const char *GetVersion() const {return fVersion.Data();}// Get version of the FOAM
0128    virtual Int_t    GetTotDim() const { return fDim;}              // Get total dimension
0129    virtual Double_t GetPrimary() const {return fPrime;}            // Get value of primary integral R'
0130    virtual void GetPrimary(Double_t &prime) {prime = fPrime;}      // Get value of primary integral R'
0131    virtual Long_t GetnCalls() const {return fNCalls;}            // Get total no. of the function calls
0132    virtual Long_t GetnEffev() const {return fNEffev;}            // Get total no. of effective wt=1 events
0133    // Debug
0134    virtual void CheckAll(Int_t);     // Checks correctness of the entire data structure in the FOAM object
0135    virtual void PrintCells();        // Prints content of all cells
0136    virtual void RootPlot2dim(Char_t*);   // Generates C++ code for drawing foam
0137    virtual void LinkCells(void);         // Void function for backward compatibility
0138    // Inline
0139 private:
0140    Double_t Sqr(Double_t x) const { return x*x;}      // Square function
0141    TFoamCell* getCell(std::size_t i) const;
0142 
0143    ClassDefOverride(TFoam,2);   // General purpose self-adapting Monte Carlo event generator
0144 };
0145 
0146 #endif