Logo ROOT  
Reference Guide
foam_demopers.C File Reference

Detailed Description

View in nbviewer Open in SWAN 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

#include "Riostream.h"
#include "TFile.h"
#include "TFoam.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TFoamIntegrand.h"
Int_t foam_demopers()
{
// 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()));
//******************************************
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;
//*******************************************
TFoam *FoamX = (TFoam*)fileA.Get("FoamX");
//*******************************************
// FoamX->PrintCells();
FoamX->CheckAll(1);
//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
//
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;
}
//_____________________________________________________________________________
//
Author
Stascek Jadach

Definition in file foam_demopers.C.

TFoam::GetIntegMC
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1211
TString::Data
const char * Data() const
Definition: TString.h:369
TFoam::MakeEvent
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1126
TFoam::CheckAll
virtual void CheckAll(Int_t)
User utility, miscellaneous and debug.
Definition: TFoam.cxx:1382
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TString::Format
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:2311
TString
Definition: TString.h:136
TFile.h
TFoam.h
TROOT.h
TFoamIntegrand.h
TFoam::Finalize
virtual void Finalize(Double_t &, Double_t &)
May be called optionally by the user after the MC run.
Definition: TFoam.cxx:1260
TFoam
Definition: TFoam.h:21
TSystem.h
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TFoamIntegrand
Definition: TFoamIntegrand.h:9
TFoam::GetMCvect
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1176
y
Double_t y[n]
Definition: legend1.C:17
TFile
Definition: TFile.h:54
Double_t
double Double_t
Definition: RtypesCore.h:59
TFoam::SetRho
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1022
Riostream.h
gROOT
#define gROOT
Definition: TROOT.h:406