26 class TFDISTR:
public TFoamIntegrand {
29 Double_t Density(
int nDim, Double_t *Xarg){
31 Double_t Fun1,Fun2,R1,R2;
32 Double_t pos1=1e0/3e0;
33 Double_t pos2=2e0/3e0;
34 Double_t Gam1= 0.100e0;
35 Double_t Gam2= 0.100e0;
36 Double_t sPi = sqrt(TMath::Pi());
42 for(i = 0 ; i<nDim ; i++){
43 R1=R1+(Xarg[i] -pos1)*(Xarg[i] -pos1);
44 R2=R2+(Xarg[i] -pos2)*(Xarg[i] -pos2);
50 Fun1 = exp(-(R1*R1)/(Gam1*Gam1))/xn1;
51 Fun2 = exp(-(R2*R2)/(Gam2*Gam2))/xn2;
52 return 0.5e0*(Fun1+ Fun2);
60 TFile RootFile(
"foam_demo.root",
"RECREATE",
"histograms");
62 Double_t MCresult,MCerror,MCwt;
74 TRandom *PseRan =
new TRandom3();
75 TFoam *FoamX =
new TFoam(
"FoamX");
76 TFoamIntegrand *rho=
new TFDISTR();
77 PseRan->SetSeed(4357);
79 cout<<
"***** Demonstration Program for Foam version "<<FoamX->GetVersion()<<
" *****"<<endl;
80 FoamX->SetkDim( kDim);
81 FoamX->SetnCells( nCells);
82 FoamX->SetnSampl( nSampl);
83 FoamX->SetnBin( nBin);
84 FoamX->SetOptRej( OptRej);
85 FoamX->SetOptDrive( OptDrive);
86 FoamX->SetEvPerBin( EvPerBin);
87 FoamX->SetChat( Chat);
90 FoamX->SetPseRan(PseRan);
92 FoamX->Write(
"FoamX");
94 long nCalls=FoamX->GetnCalls();
95 cout <<
"====== Initialization done, entering MC loop" << endl;
98 Double_t *MCvect =
new Double_t[kDim];
100 TH1D *hst_Wt =
new TH1D(
"hst_Wt" ,
"Main weight of Foam",25,0,1.25);
103 for(loop=0; loop<NevTot; loop++){
107 FoamX->GetMCvect( MCvect);
108 MCwt=FoamX->GetMCwt();
109 hst_Wt->Fill(MCwt,1.0);
111 cout<<
"MCwt= "<<MCwt<<
", ";
113 for ( Int_t k=0 ; k<kDim ; k++) cout<<MCvect[k]<<
" "; cout<< endl;
115 if( ((loop)%100000)==0 ){
116 cout<<
" loop= "<<loop<<endl;
122 cout <<
"====== Events generated, entering Finalize" << endl;
124 hst_Wt->Print(
"all");
125 Double_t eps = 0.0005;
126 Double_t Effic, WtMax, AveWt, Sigma;
127 Double_t IntNorm, Errel;
128 FoamX->Finalize( IntNorm, Errel);
129 FoamX->GetIntegMC( MCresult, MCerror);
130 FoamX->GetWtParams(eps, AveWt, WtMax, Sigma);
131 Effic=0;
if(WtMax>0) Effic=AveWt/WtMax;
132 cout <<
"================================================================" << endl;
133 cout <<
" MCresult= " << MCresult <<
" +- " << MCerror <<
" RelErr= "<< MCerror/MCresult << endl;
134 cout <<
" Dispersion/<wt>= " << Sigma/AveWt << endl;
135 cout <<
" <wt>/WtMax= " << Effic <<
", for epsilon = "<<eps << endl;
136 cout <<
" nCalls (initialization only) = " << nCalls << endl;
137 cout <<
"================================================================" << endl;
144 cout <<
"***** End of Demonstration Program *****" << endl;