Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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  // 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 =new Double_t[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