Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TFoam.h"
15#include "TCanvas.h"
16#include "TH2.h"
17#include "TMath.h"
18#include "TFoamIntegrand.h"
19#include "TRandom3.h"
20
21#include <iostream>
22
23//_____________________________________________________________________________
25 return x*x;
26}
27//_____________________________________________________________________________
29 // 2-dimensional distribution for Foam, normalized to one (within 1e-5)
30 Double_t x=Xarg[0];
31 Double_t y=Xarg[1];
32 Double_t GamSq= sqr(0.100e0);
33 Double_t Dist= 0;
34 Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
35 Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
36 return 0.5*Dist;
37}
38//_____________________________________________________________________________
39
41 cout<<"--- kanwa started ---"<<endl;
42 TH2D *hst_xy = new TH2D("hst_xy" , "x-y plot", 50,0,1.0, 50,0,1.0);
43 Double_t MCvect[2]; // 2-dim vector generated in the MC run
44 //
45 TRandom *PseRan = new TRandom3(); // Create random number generator
46 PseRan->SetSeed(4357);
47 TFoam *FoamX = new TFoam("FoamX"); // Create Simulator
48 FoamX->SetkDim(2); // No. of dimensions, obligatory!
49 FoamX->SetnCells(500); // Optionally No. of cells, default=2000
50 FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below
51 FoamX->SetPseRan(PseRan); // Set random number generator
52 FoamX->Initialize(); // Initialize simulator, may take time...
53 //
54 // visualising generated distribution
55 TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600);
56 cKanwa->cd();
57 // From now on FoamX is ready to generate events
58 int nshow=5000;
59 for(long loop=0; loop<100000; loop++){
60 FoamX->MakeEvent(); // generate MC event
61 FoamX->GetMCvect( MCvect); // get generated vector (x,y)
62 Double_t x=MCvect[0];
63 Double_t y=MCvect[1];
64 if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<<endl;
65 hst_xy->Fill(x,y);
66 // live plot
67 if(loop == nshow){
68 nshow += 5000;
69 hst_xy->Draw("lego2");
70 cKanwa->Update();
71 }
72 }// loop
73 //
74 hst_xy->Draw("lego2"); // final plot
75 cKanwa->Update();
76 //
78 FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
79 cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
80 cout<<"--- kanwa ended ---"<<endl;
81
82 return 0;
83}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Canvas class.
Definition TCanvas.h:23
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
Definition TFoam.h:21
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:400
Random number generator class based on M.
Definition TRandom3.h:27
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
RVec< PromoteType< T > > exp(const RVec< T > &v)
Definition RVec.hxx:1817
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
double Dist(void *xp, void *yp)
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
constexpr Double_t Pi()
Definition TMath.h:40