Logo ROOT  
Reference Guide
foam_demopers.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_FOAM
3/// \notebook -nodraw
4/// This simple macro demonstrates persistency of FOAM object.
5/// First run macro foam_demo.C to create file foam_demo.root with FOAM object.
6///
7/// Next type `root -l foam_demopers.C` from shell command line
8///
9/// \macro_code
10///
11/// \author Stascek Jadach
12
13#include "Riostream.h"
14#include "TFile.h"
15#include "TFoam.h"
16#include "TROOT.h"
17#include "TSystem.h"
18#include "TFoamIntegrand.h"
19
20
21Int_t foam_demopers()
22{
23
24 // need to load the foam_demo tutorial for the definition of the function
25 TString macroName = gROOT->GetTutorialDir();
26 macroName.Append("/foam/foam_demo.C");
27 gROOT->ProcessLine(TString::Format(".L %s+",macroName.Data()));
28
29 //******************************************
30 cout<<"====================== TestVector ================================"<<endl;
31 TFile fileA("foam_demo.root");
32 fileA.cd();
33 cout<<"------------------------------------------------------------------"<<endl;
34 fileA.ls();
35 cout<<"------------------------------------------------------------------"<<endl;
36 fileA.Map();
37 cout<<"------------------------------------------------------------------"<<endl;
38 fileA.ShowStreamerInfo();
39 cout<<"------------------------------------------------------------------"<<endl;
40 fileA.GetListOfKeys()->Print();
41 cout<<"------------------------------------------------------------------"<<endl;
42 //*******************************************
43 TFoam *FoamX = (TFoam*)fileA.Get("FoamX");
44 //*******************************************
45 // FoamX->PrintCells();
46 FoamX->CheckAll(1);
47
48 //N.B. the integrand functions need to be reset
49 // because cannot be made persistent
50 TFoamIntegrand * rho = (TFoamIntegrand*) gROOT->ProcessLine("return new TFDISTR();");
51 FoamX->SetRho(rho);
52
53 Double_t MCvect[2]; // 2-dim vector generated in the MC run
54
55 for(long loop=0; loop<50000; loop++){
56 FoamX->MakeEvent(); // generate MC event
57 FoamX->GetMCvect( MCvect); // get generated vector (x,y)
58 Double_t x=MCvect[0];
59 Double_t y=MCvect[1];
60 if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<<endl;
61 }// loop
62 //
63 Double_t IntNorm, Errel;
64 FoamX->Finalize( IntNorm, Errel); // final printout
65 Double_t MCresult, MCerror;
66 FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
67 cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
68 cout<<"===================== TestPers FINISHED ======================="<<endl;
69 return 0;
70}
71//_____________________________________________________________________________
72//
73
int Int_t
Definition: RtypesCore.h:45
double Double_t
Definition: RtypesCore.h:59
#define gROOT
Definition: TROOT.h:404
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
Abstract class representing n-dimensional real positive integrand function.
Definition: TFoamIntegrand.h:9
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
Definition: TFoam.h:21
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition: TFoam.cxx:1380
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1174
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1124
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1209
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1020
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1258
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
TString & Append(const char *cs)
Definition: TString.h:564
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2341
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17