foam_kanwa.C

Go to the documentation of this file.
00001 // This program can be execute from the command line as folows:
00002 //     
00003 //      root -l foam_kanwa.C
00004 //_____________________________________________________________________________
00005 
00006 Int_t foam_kanwa(){
00007   cout<<"--- kanwa started ---"<<endl;
00008   gSystem->Load("libFoam.so");
00009   TH2D  *hst_xy = new TH2D("hst_xy" ,  "x-y plot", 50,0,1.0, 50,0,1.0);
00010   Double_t *MCvect =new Double_t[2]; // 2-dim vector generated in the MC run
00011   //
00012   TRandom     *PseRan   = new TRandom3();  // Create random number generator
00013   PseRan->SetSeed(4357);
00014   TFoam   *FoamX    = new TFoam("FoamX");   // Create Simulator
00015   FoamX->SetkDim(2);         // No. of dimensions, obligatory!
00016   FoamX->SetnCells(500);     // Optionally No. of cells, default=2000
00017   FoamX->SetRhoInt(Camel2);  // Set 2-dim distribution, included below
00018   FoamX->SetPseRan(PseRan);  // Set random number generator
00019   FoamX->Initialize();       // Initialize simulator, may take time...
00020   //
00021   // visualising generated distribution
00022   TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600);
00023   cKanwa->cd();
00024   // From now on FoamX is ready to generate events
00025   int nshow=5000;
00026   for(long loop=0; loop<100000; loop++){
00027     FoamX->MakeEvent();            // generate MC event
00028     FoamX->GetMCvect( MCvect);     // get generated vector (x,y)
00029     Double_t x=MCvect[0];
00030     Double_t y=MCvect[1];
00031     if(loop<10) cout<<"(x,y) =  ( "<< x <<", "<< y <<" )"<<endl;
00032     hst_xy->Fill(x,y);
00033     // live plot
00034     if(loop == nshow){
00035       nshow += 5000;
00036       hst_xy->Draw("lego2");
00037       cKanwa->Update();
00038     }
00039   }// loop
00040   //
00041   hst_xy->Draw("lego2");  // final plot
00042   cKanwa->Update();
00043   //
00044   Double_t MCresult, MCerror;
00045   FoamX->GetIntegMC( MCresult, MCerror);  // get MC integral, should be one
00046   cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
00047   cout<<"--- kanwa ended ---"<<endl;
00048   
00049   return 0;
00050 }//kanwa
00051 
00052 //_____________________________________________________________________________
00053 Double_t sqr(Double_t x){return x*x;};
00054 //_____________________________________________________________________________
00055 Double_t Camel2(Int_t nDim, Double_t *Xarg){
00056 // 2-dimensional distribution for Foam, normalized to one (within 1e-5)
00057   Double_t x=Xarg[0];
00058   Double_t y=Xarg[1];
00059   Double_t GamSq= sqr(0.100e0);
00060   Double_t Dist= 0;
00061   Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
00062   Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
00063   return 0.5*Dist;
00064 }// Camel2
00065 //_____________________________________________________________________________

Generated on Tue Jul 5 15:44:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1