Logo ROOT   6.10/09
Reference Guide
foam_kanwa.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_FOAM
3 /// \notebook -js
4 /// This program can be execute from the command line as folows:
5 ///
6 /// ~~~{.cpp}
7 /// root -l foam_kanwa.C
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Stascek Jadach
13 
14 #include "Riostream.h"
15 #include "TFoam.h"
16 #include "TCanvas.h"
17 #include "TH2.h"
18 #include "TMath.h"
19 #include "TFoamIntegrand.h"
20 #include "TRandom3.h"
21 
22 //_____________________________________________________________________________
24  return x*x;
25 }
26 //_____________________________________________________________________________
27 Double_t Camel2(Int_t nDim, Double_t *Xarg){
28  // 2-dimensional distribution for Foam, normalized to one (within 1e-5)
29  Double_t x=Xarg[0];
30  Double_t y=Xarg[1];
31  Double_t GamSq= sqr(0.100e0);
32  Double_t Dist= 0;
33  Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
34  Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
35  return 0.5*Dist;
36 }
37 //_____________________________________________________________________________
38 
39 Int_t foam_kanwa(){
40  cout<<"--- kanwa started ---"<<endl;
41  TH2D *hst_xy = new TH2D("hst_xy" , "x-y plot", 50,0,1.0, 50,0,1.0);
42  Double_t *MCvect =new Double_t[2]; // 2-dim vector generated in the MC run
43  //
44  TRandom *PseRan = new TRandom3(); // Create random number generator
45  PseRan->SetSeed(4357);
46  TFoam *FoamX = new TFoam("FoamX"); // Create Simulator
47  FoamX->SetkDim(2); // No. of dimensions, obligatory!
48  FoamX->SetnCells(500); // Optionally No. of cells, default=2000
49  FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below
50  FoamX->SetPseRan(PseRan); // Set random number generator
51  FoamX->Initialize(); // Initialize simulator, may take time...
52  //
53  // visualising generated distribution
54  TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600);
55  cKanwa->cd();
56  // From now on FoamX is ready to generate events
57  int nshow=5000;
58  for(long loop=0; loop<100000; loop++){
59  FoamX->MakeEvent(); // generate MC event
60  FoamX->GetMCvect( MCvect); // get generated vector (x,y)
61  Double_t x=MCvect[0];
62  Double_t y=MCvect[1];
63  if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<<endl;
64  hst_xy->Fill(x,y);
65  // live plot
66  if(loop == nshow){
67  nshow += 5000;
68  hst_xy->Draw("lego2");
69  cKanwa->Update();
70  }
71  }// loop
72  //
73  hst_xy->Draw("lego2"); // final plot
74  cKanwa->Update();
75  //
76  Double_t MCresult, MCerror;
77  FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
78  cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
79  cout<<"--- kanwa ended ---"<<endl;
80 
81  return 0;
82 }
Random number generator class based on M.
Definition: TRandom3.h:27
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
int Int_t
Definition: RtypesCore.h:41
virtual void MakeEvent()
User subprogram.
Definition: TFoam.cxx:1152
virtual void SetRhoInt(Double_t(*fun)(Int_t, Double_t *))
User may use this method to set the distribution object as a global function pointer (and not as an i...
Definition: TFoam.cxx:1060
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
constexpr Double_t Pi()
Definition: TMath.h:40
double Dist(void *xp, void *yp)
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1202
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:357
The Canvas class.
Definition: TCanvas.h:31
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:125
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:121
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:316
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2208
double exp(double)
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
virtual void GetIntegMC(Double_t &, Double_t &)
User subprogram.
Definition: TFoam.cxx:1237
Definition: TFoam.h:27
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:124
tomato 2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:290