Logo ROOT  
Reference Guide
foam_kanwa.C File Reference

Detailed Description

View in nbviewer Open in SWAN This program can be execute from the command line as folows:

root -l foam_kanwa.C
#include "Riostream.h"
#include "TFoam.h"
#include "TCanvas.h"
#include "TH2.h"
#include "TMath.h"
#include "TFoamIntegrand.h"
#include "TRandom3.h"
//_____________________________________________________________________________
return x*x;
}
//_____________________________________________________________________________
Double_t Camel2(Int_t nDim, Double_t *Xarg){
// 2-dimensional distribution for Foam, normalized to one (within 1e-5)
Double_t x=Xarg[0];
Double_t y=Xarg[1];
Double_t GamSq= sqr(0.100e0);
Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
return 0.5*Dist;
}
//_____________________________________________________________________________
Int_t foam_kanwa(){
cout<<"--- kanwa started ---"<<endl;
TH2D *hst_xy = new TH2D("hst_xy" , "x-y plot", 50,0,1.0, 50,0,1.0);
Double_t MCvect[2]; // 2-dim vector generated in the MC run
//
TRandom *PseRan = new TRandom3(); // Create random number generator
PseRan->SetSeed(4357);
TFoam *FoamX = new TFoam("FoamX"); // Create Simulator
FoamX->SetkDim(2); // No. of dimensions, obligatory!
FoamX->SetnCells(500); // Optionally No. of cells, default=2000
FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below
FoamX->SetPseRan(PseRan); // Set random number generator
FoamX->Initialize(); // Initialize simulator, may take time...
//
// visualising generated distribution
TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600);
cKanwa->cd();
// From now on FoamX is ready to generate events
int nshow=5000;
for(long loop=0; loop<100000; 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;
hst_xy->Fill(x,y);
// live plot
if(loop == nshow){
nshow += 5000;
hst_xy->Draw("lego2");
cKanwa->Update();
}
}// loop
//
hst_xy->Draw("lego2"); // final plot
cKanwa->Update();
//
Double_t MCresult, MCerror;
FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one
cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
cout<<"--- kanwa ended ---"<<endl;
return 0;
}
Author
Stascek Jadach

Definition in file foam_kanwa.C.

l
auto * l
Definition: textangle.C:4
TFoam::GetIntegMC
virtual void GetIntegMC(Double_t &, Double_t &)
User method.
Definition: TFoam.cxx:1211
TFoam::SetRhoInt
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:1033
TFoam::MakeEvent
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1126
exp
double exp(double)
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TCanvas.h
TFoam.h
TFoamIntegrand.h
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:43
TFoam
Definition: TFoam.h:21
TRandom
Definition: TRandom.h:27
TRandom3
Definition: TRandom3.h:27
TCanvas::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:704
TH2D
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:292
TRandom::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
TFoam::GetMCvect
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1176
TRandom3.h
y
Double_t y[n]
Definition: legend1.C:17
TFoam::Initialize
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:323
TH2.h
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
ROOT::Math::GSLSimAn::Dist
double Dist(void *xp, void *yp)
Definition: GSLSimAnnealing.cxx:139
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
Definition: TCanvas.h:23
ROOT::Math::sqr
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:206
TCanvas::Update
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2500
TFoam::SetkDim
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:115
TFoam::SetnCells
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:116
TFoam::SetPseRan
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:112
Riostream.h
TMath.h
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997