Logo ROOT   6.10/09
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 
21 Int_t foam_demopers()
22 {
23 
24  gSystem->Load("libFoam");
25 
26  // need to load the foam_demo tutorial for the definition of the function
27  TString macroName = gROOT->GetTutorialDir();
28  macroName.Append("/foam/foam_demo.C");
29  gROOT->ProcessLine(TString::Format(".L %s+",macroName.Data()));
30 
31  //******************************************
32  cout<<"====================== TestVector ================================"<<endl;
33  TFile fileA("foam_demo.root");
34  fileA.cd();
35  cout<<"------------------------------------------------------------------"<<endl;
36  fileA.ls();
37  cout<<"------------------------------------------------------------------"<<endl;
38  fileA.Map();
39  cout<<"------------------------------------------------------------------"<<endl;
40  fileA.ShowStreamerInfo();
41  cout<<"------------------------------------------------------------------"<<endl;
42  fileA.GetListOfKeys()->Print();
43  cout<<"------------------------------------------------------------------"<<endl;
44  //*******************************************
45  TFoam *FoamX = (TFoam*)fileA.Get("FoamX");
46  //*******************************************
47  // FoamX->PrintCells();
48  FoamX->CheckAll(1);
49 
50  //N.B. the integrand functions need to be reset
51  // because cannot be made persistent
52  TFoamIntegrand * rho = (TFoamIntegrand*) gROOT->ProcessLine("return new TFDISTR();");
53  FoamX->SetRho(rho);
54 
55  Double_t *MCvect =new Double_t[2]; // 2-dim vector generated in the MC run
56 
57  for(long loop=0; loop<50000; loop++){
58  FoamX->MakeEvent(); // generate MC event
59  FoamX->GetMCvect( MCvect); // get generated vector (x,y)
60  Double_t x=MCvect[0];
61  Double_t y=MCvect[1];
62  if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<<endl;
63  }// loop
64  //
65  Double_t IntNorm, Errel;
66  FoamX->Finalize( IntNorm, Errel); // final printout
67  Double_t MCresult, MCerror;
68  FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
69  cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
70  cout<<"===================== TestPers FINISHED ======================="<<endl;
71  return 0;
72 }
73 //_____________________________________________________________________________
74 //
75 
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition: TFoam.cxx:1403
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
#define gROOT
Definition: TROOT.h:375
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1825
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
virtual void MakeEvent()
User subprogram.
Definition: TFoam.cxx:1152
Double_t x[n]
Definition: legend1.C:17
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:2345
TString & Append(const char *cs)
Definition: TString.h:497
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1286
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1202
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1049
virtual void GetIntegMC(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1237
Definition: TFoam.h:27
const char * Data() const
Definition: TString.h:347