This simple macro demonstrates persistency of FOAM object. First run macro foam_demo.C to create file foam_demo.root with FOAM object.
Next type root -l foam_demopers.C
from shell command line
Author: Stascek Jadach
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:10 AM.
need to load the foam_demo tutorial for the definition of the function
TString macroName = gROOT->GetTutorialDir();
macroName.Append("/foam/foam_demo.C");
gROOT->ProcessLine(TString::Format(".L %s+",macroName.Data()));
Info in <TUnixSystem::ACLiC>: creating shared library /home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/src/master.build/tutorials/foam/foam_demo_C.so
cout<<"====================== TestVector ================================"<<endl;
TFile fileA("foam_demo.root");
fileA.cd();
cout<<"------------------------------------------------------------------"<<endl;
fileA.ls();
cout<<"------------------------------------------------------------------"<<endl;
fileA.Map();
cout<<"------------------------------------------------------------------"<<endl;
fileA.ShowStreamerInfo();
cout<<"------------------------------------------------------------------"<<endl;
fileA.GetListOfKeys()->Print();
cout<<"------------------------------------------------------------------"<<endl;
====================== TestVector ================================ ------------------------------------------------------------------ TFile** foam_demo.root histograms TFile* foam_demo.root histograms KEY: TFoam FoamX;1 General purpose self-adapting Monte Carlo event generator KEY: TProcessID ProcessID0;1 36942e60-fcaa-11ee-bab1-942c8a89beef KEY: TH1D hst_Wt;1 Main weight of Foam ------------------------------------------------------------------ 20240417/110411 At:100 N=144 TFile 20240417/110412 At:244 N=155 TProcessID 20240417/110412 At:399 N=27811 TFoam CX = 3.29 20240417/110413 At:28210 N=332 TH1D CX = 3.13 20240417/110413 At:28542 N=301 KeysList 20240417/110413 At:28843 N=6080 StreamerInfo CX = 3.16 20240417/110413 At:34923 N=68 FreeSegments 20240417/110413 At:34991 N=1 END ------------------------------------------------------------------ OBJ: TList TList Doubly linked list : 0 StreamerInfo for class: TNamed, version=1, checksum=0xdfb74a3c TObject BASE offset= 0 type=66 Basic ROOT object TString fName offset= 0 type=65 object identifier TString fTitle offset= 0 type=65 object title StreamerInfo for class: TObject, version=1, checksum=0x901bc02d unsigned int fUniqueID offset= 0 type=13 object unique identifier unsigned int fBits offset= 0 type=15 bit field status word StreamerInfo for class: THashList, version=0, checksum=0xcc7e49c1 TList BASE offset= 0 type= 0 Doubly linked list StreamerInfo for class: TList, version=5, checksum=0x69c5c3bb TSeqCollection BASE offset= 0 type= 0 Sequenceable collection ABC StreamerInfo for class: TSeqCollection, version=0, checksum=0xfc6c3bc6 TCollection BASE offset= 0 type= 0 Collection abstract base class StreamerInfo for class: TCollection, version=3, checksum=0x57e3cb9c TObject BASE offset= 0 type=66 Basic ROOT object TString fName offset= 0 type=65 name of the collection int fSize offset= 0 type= 3 number of elements in collection StreamerInfo for class: TFoam, version=2, checksum=0x231190da TObject BASE offset= 0 type=66 Basic ROOT object TString fName offset= 0 type=65 Name of a given instance of the FOAM class TString fVersion offset= 0 type=65 Actual version of the FOAM like (1.01m) TString fDate offset= 0 type=65 Release date of FOAM int fDim offset= 0 type= 6 Dimension of the integration/simulation space int fNCells offset= 0 type= 6 Maximum number of cells int fRNmax offset= 0 type= 6 Maximum No. of the rand. numb. requested at once int fOptDrive offset= 0 type= 3 Optimization switch =1,2 for variance or maximum weight optimization int fChat offset= 0 type= 3 Chat=0,1,2 chat level in output, Chat=1 normal level int fOptRej offset= 0 type= 3 Switch =0 for weighted events; =1 for unweighted events in MC int fNBin offset= 0 type= 3 No. of bins in the edge histogram for cell MC exploration int fNSampl offset= 0 type= 3 No. of MC events, when dividing (exploring) cell int fEvPerBin offset= 0 type= 3 Maximum number of effective (wt=1) events per bin int fOptPRD offset= 0 type= 3 Option switch for predefined division, for quick check int fNoAct offset= 0 type= 6 Number of active cells int fLastCe offset= 0 type= 3 Index of the last cell TFoamCell** fCells offset= 0 type=501 [fNCells] Array of ALL cells TFoamMaxwt* fMCMonit offset= 0 type=64 Monitor of the MC weight for measuring MC efficiency double fMaxWtRej offset= 0 type= 8 Maximum weight in rejection for getting wt=1 events vector<long> fCellsAct offset= 0 type=300 ,stl=1, ctype=4, Index of active cells, constructed at the end of foam build-up double* fPrimAcu offset= 0 type=48 [fNoAct] Array of cumulative probability of all active cells TObjArray* fHistEdg offset= 0 type=64 Histograms of wt, one for each cell edge TObjArray* fHistDbg offset= 0 type=64 Histograms of wt, for debug TH1D* fHistWt offset= 0 type=64 Histogram of the MC wt double* fMCvect offset= 0 type=48 [fDim] Generated MC vector for the outside user double fMCwt offset= 0 type= 8 MC weight double* fRvec offset= 0 type=48 [fRNmax] random number vector from r.n. generator fDim+1 maximum elements TRandom* fPseRan offset= 0 type=64 Pointer to user-defined generator of pseudorandom numbers long fNCalls offset= 0 type= 4 Total number of the function calls long fNEffev offset= 0 type= 4 Total number of effective events (wt=1) in the foam buildup double fSumWt offset= 0 type= 8 Total sum of wt and wt^2 double fSumWt2 offset= 0 type= 8 Total sum of wt and wt^2 double fSumOve offset= 0 type= 8 Total Sum of overweighted events double fNevGen offset= 0 type= 8 Total number of the generated MC events double fWtMax offset= 0 type= 8 Maximum/Minimum MC weight double fWtMin offset= 0 type= 8 Maximum/Minimum MC weight double fPrime offset= 0 type= 8 Primary integral R' (R=R'`<wt>`) double fMCresult offset= 0 type= 8 True Integral R from MC series double fMCerror offset= 0 type= 8 and its error double* fAlpha offset= 0 type=48 [fDim] Internal parameters of the hyper-rectangle StreamerInfo for class: TFoamCell, version=2, checksum=0x743666eb TObject BASE offset= 0 type=66 Basic ROOT object short fDim offset= 0 type= 2 Dimension of the vector space int fSerial offset= 0 type= 3 Serial number int fStatus offset= 0 type= 3 Status (active, inactive) TRef fParent offset= 0 type=61 Pointer to parent cell TRef fDaught0 offset= 0 type=61 Pointer to daughter 1 TRef fDaught1 offset= 0 type=61 Pointer to daughter 2 int fParentIdx offset= 0 type= 3 Serial number of parent cell int fDaught0Idx offset= 0 type= 3 Serial number of daughter 1 int fDaught1Idx offset= 0 type= 3 Serial number of daughter 2 double fXdiv offset= 0 type= 8 Factor for division int fBest offset= 0 type= 3 Best Edge for division double fVolume offset= 0 type= 8 Cartesian Volume of cell double fIntegral offset= 0 type= 8 Integral over cell (estimate from exploration) double fDrive offset= 0 type= 8 Driver integral, only for cell build-up double fPrimary offset= 0 type= 8 Primary integral, only for MC generation StreamerInfo for class: TProcessID, version=1, checksum=0x2b7ef579 TNamed BASE offset= 0 type=67 The basis for a named object (name, title) StreamerInfo for class: TFoamMaxwt, version=1, checksum=0x75617bf1 TObject BASE offset= 0 type=66 Basic ROOT object double fNent offset= 0 type= 8 No. of MC events int fnBin offset= 0 type= 3 No. of bins on the weight distribution double fwmax offset= 0 type= 8 Maximum analyzed weight TH1D* fWtHst1 offset= 0 type=64 Histogram of the weight wt TH1D* fWtHst2 offset= 0 type=64 Histogram of wt filled with wt StreamerInfo for class: TH1D, version=3, checksum=0xf9b1569f TH1 BASE offset= 0 type= 0 1-Dim histogram base class TArrayD BASE offset= 0 type= 0 Array of doubles StreamerInfo for class: TH1, version=8, checksum=0x1c3740c4 TNamed BASE offset= 0 type=67 The basis for a named object (name, title) TAttLine BASE offset= 0 type= 0 Line attributes TAttFill BASE offset= 0 type= 0 Fill area attributes TAttMarker BASE offset= 0 type= 0 Marker attributes int fNcells offset= 0 type= 3 Number of bins(1D), cells (2D) +U/Overflows TAxis fXaxis offset= 0 type=61 X axis descriptor TAxis fYaxis offset= 0 type=61 Y axis descriptor TAxis fZaxis offset= 0 type=61 Z axis descriptor short fBarOffset offset= 0 type= 2 (1000*offset) for bar charts or legos short fBarWidth offset= 0 type= 2 (1000*width) for bar charts or legos double fEntries offset= 0 type= 8 Number of entries double fTsumw offset= 0 type= 8 Total Sum of weights double fTsumw2 offset= 0 type= 8 Total Sum of squares of weights double fTsumwx offset= 0 type= 8 Total Sum of weight*X double fTsumwx2 offset= 0 type= 8 Total Sum of weight*X*X double fMaximum offset= 0 type= 8 Maximum value for plotting double fMinimum offset= 0 type= 8 Minimum value for plotting double fNormFactor offset= 0 type= 8 Normalization factor TArrayD fContour offset= 0 type=62 Array to display contour levels TArrayD fSumw2 offset= 0 type=62 Array of sum of squares of weights TString fOption offset= 0 type=65 Histogram options TList* fFunctions offset= 0 type=63 ->Pointer to list of functions (fits and user) int fBufferSize offset= 0 type= 6 fBuffer size double* fBuffer offset= 0 type=48 [fBufferSize] entry buffer TH1::EBinErrorOpt fBinStatErrOpt offset= 0 type= 3 Option for bin statistical errors TH1::EStatOverflows fStatOverflows offset= 0 type= 3 Per object flag to use under/overflows in statistics StreamerInfo for class: TAttLine, version=2, checksum=0x94074549 short fLineColor offset= 0 type= 2 Line color short fLineStyle offset= 0 type= 2 Line style short fLineWidth offset= 0 type= 2 Line width StreamerInfo for class: TAttFill, version=2, checksum=0xffd92a92 short fFillColor offset= 0 type= 2 Fill area color short fFillStyle offset= 0 type= 2 Fill area style StreamerInfo for class: TAttMarker, version=3, checksum=0x291d8bec short fMarkerColor offset= 0 type= 2 Marker color short fMarkerStyle offset= 0 type= 2 Marker style float fMarkerSize offset= 0 type= 5 Marker size StreamerInfo for class: TAxis, version=10, checksum=0x5a496e70 TNamed BASE offset= 0 type=67 The basis for a named object (name, title) TAttAxis BASE offset= 0 type= 0 Axis attributes int fNbins offset= 0 type= 3 Number of bins double fXmin offset= 0 type= 8 Low edge of first bin double fXmax offset= 0 type= 8 Upper edge of last bin TArrayD fXbins offset= 0 type=62 Bin edges array in X int fFirst offset= 0 type= 3 First bin to display int fLast offset= 0 type= 3 Last bin to display unsigned short fBits2 offset= 0 type=12 Second bit status word bool fTimeDisplay offset= 0 type=18 On/off displaying time values instead of numerics TString fTimeFormat offset= 0 type=65 Date&time format, ex: 09/12/99 12:34:00 THashList* fLabels offset= 0 type=64 List of labels TList* fModLabs offset= 0 type=64 List of modified labels StreamerInfo for class: TAttAxis, version=4, checksum=0x5c6fff3e int fNdivisions offset= 0 type= 3 Number of divisions(10000*n3 + 100*n2 + n1) short fAxisColor offset= 0 type= 2 Color of the line axis short fLabelColor offset= 0 type= 2 Color of labels short fLabelFont offset= 0 type= 2 Font for labels float fLabelOffset offset= 0 type= 5 Offset of labels float fLabelSize offset= 0 type= 5 Size of labels float fTickLength offset= 0 type= 5 Length of tick marks float fTitleOffset offset= 0 type= 5 Offset of axis title float fTitleSize offset= 0 type= 5 Size of axis title short fTitleColor offset= 0 type= 2 Color of axis title short fTitleFont offset= 0 type= 2 Font for axis title StreamerInfo for class: TString, version=2, checksum=0x17419 StreamerInfo for class: TRandom3, version=2, checksum=0x824af0bb TRandom BASE offset= 0 type= 0 Simple Random number generator (periodicity = 10**9) unsigned int fMt[624] offset= 0 type=33 int fCount624 offset= 0 type= 3 StreamerInfo for class: TRandom, version=3, checksum=0xe0f3fab TNamed BASE offset= 0 type=67 The basis for a named object (name, title) ROOT::Math::TRandomEngine BASE offset= 0 type= 0 unsigned int fSeed offset= 0 type=13 Random number generator seed StreamerInfo for class: ROOT::Math::TRandomEngine, version=1, checksum=0xdbdd9943 OBJ: TList listOfRules Doubly linked list : 0 OBJ: TObjString type=read sourceClass="TFoam" targetClass="TFoam" version="[1]" source="Int_t fNCells; TFoamCell **fCells; TRefArray *fCellsAct" target="fNCells,fCells,fCellsAct" include="TRefArray.h" code="{fNCells = onfile.fNCells; \n fCells = onfile.fCells; \n onfile.fCells = nullptr; \n fCellsAct.clear(); \n for (Int_t i=0; i < onfile.fCellsAct->GetEntries(); ++i) { \n const TObject* cellp = onfile.fCellsAct->At(i); \n for (Int_t j=0; j < fNCells; ++j) { \n if (cellp == fCells[j]) { \n fCellsAct.push_back(j); \n break; \n } \n } \n }}" Collectable string class : 0 at: 0x7f4ff712dbd0 ------------------------------------------------------------------ Collection name='THashList', class='THashList', size=3 TKey Name = FoamX, Title = General purpose self-adapting Monte Carlo event generator, Cycle = 1 TKey Name = ProcessID0, Title = 36942e60-fcaa-11ee-bab1-942c8a89beef, Cycle = 1 TKey Name = hst_Wt, Title = Main weight of Foam, Cycle = 1 ------------------------------------------------------------------
TFoam *FoamX = (TFoam*)fileA.Get("FoamX");
FoamX->PrintCells();
FoamX->CheckAll(1);
///////////////////////////// FOAM_Checks /////////////////////////////////
Info in <TFoam::CheckAll>: Check has found 0 errors and 0 warnings
N.B. the integrand functions need to be reset because cannot be made persistent
TFoamIntegrand * rho = (TFoamIntegrand*) gROOT->ProcessLine("return new TFDISTR();");
FoamX->SetRho(rho);
Double_t MCvect[2]; // 2-dim vector generated in the MC run
for(long loop=0; loop<50000; 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;
}// loop
(x,y) = ( 0.68054, 0.692506 ) (x,y) = ( 0.39744, 0.223474 ) (x,y) = ( 0.418624, 0.372684 ) (x,y) = ( 0.332212, 0.378017 ) (x,y) = ( 0.322215, 0.25438 ) (x,y) = ( 0.614446, 0.605205 ) (x,y) = ( 0.300181, 0.38244 ) (x,y) = ( 0.76522, 0.777539 ) (x,y) = ( 0.784071, 0.693017 ) (x,y) = ( 0.720282, 0.660879 )
Double_t IntNorm, Errel;
FoamX->Finalize( IntNorm, Errel); // final printout
Double_t MCresult, MCerror;
FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
cout<<"===================== TestPers FINISHED ======================="<<endl;
return 0;
TH1.Print Name = TFoamMaxwt_hst_Wt1, Entries= 76619, Total sum= 76619 TH1.Print Name = TFoamMaxwt_hst_Wt2, Entries= 76619, Total sum= 54981.3 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF F F F **************************************** F F ****** TFoam::Finalize ****** F F **************************************** F F NevGen = 76619 = Number of generated events in the MC generation F F nCalls = 176419 = Total number of function calls F F ---------------------------------------- F F AveWt = 0.71759331 = Average MC weight F F WtMin = 1.472245e-19 = Minimum MC weight (absolute) F F WtMax = 4.1676265 = Maximum MC weight (absolute) F F ---------------------------------------- F F XPrime = 1.3929609 = Primary total integral, R_prime F F XDiver = 0.39362177 = Driver total integral, R_loss F F ---------------------------------------- F F IntMC = 0.99957943 +- 0.00115528 = Result of the MC Integral F F mCerelat = 0.0011557661 = Relative error of the MC integral F F <w>/WtMax = 0.7211993 = MC efficiency, acceptance rate F F Sigma/<w> = 0.31991763 = MC efficiency, variance/ave_wt F F WtMax = 0.995 = WtMax(esp= 0.0005) F F Sigma = 0.22957075 = variance of MC weight F F <OveW>/<W> = 0.00018763091 = Contrib. of events wt>MaxWtRej F F F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF MCresult= 0.99957943 +- 0.00115528 ===================== TestPers FINISHED =======================