#if !defined(__CINT__) || defined(__MAKECINT__) #include #include #include "MyRandom.h" #include "TF1.h" #include "TFile.h" #include "TH1F.h" #include "TMath.h" #include "TStopwatch.h" #endif void testrand(Float_t alpha = 0.5,Int_t nbins = 500, Float_t notrials=500000){ Bool_t debug = kFALSE; delete gRandom; gRandom = 0; MyRandom *mior = new MyRandom(); gRandom = mior; Float_t high = 2.*TMath::Pi(); TH1F *funz = new TH1F("funz","(sin(theta)**2+alpha*cos(theta)**2)**(-1)",nbins,0.,high); TH1F *inv = new TH1F("inv","Inversion technique",nbins,0.,high); TH1F *rej = new TH1F("rej","Rejection technique",nbins,0.,high); char testo[50]; sprintf(testo,"1./(sin(x)*sin(x)+%7.3f *cos(x)*cos(x))",alpha); cout<SetLineColor(2); rej->SetLineColor(4); standroot->SetLineColor(3); Float_t step = high/nbins; cout<<"Pararameter alpha = "<Fill(xx,fu); xx+=step; inte+=fu; } inte=inte*step; if(debug)cout<<"Integral = "<Fill(mior->Funct1RndmByInversion(alpha),norm); } timer.Stop(); Double_t time1 = timer.CpuTime(); timer.Start(kTRUE); for(Int_t i=0;iFill(mior->Funct1RndmByRejection(alpha),norm); } timer.Stop(); Double_t time2 = timer.CpuTime(); timer.Start(kTRUE); for(Int_t i=0;iFill(fun->GetRandom(),norm); } timer.Stop(); Double_t time3 = timer.CpuTime(); Double_t relative1,relative2,relative3; relative2 = 1.; relative1 = time1/time2; relative3 = time3/time2; cout<<"Tempo di CPU per il metodo dell'inversione (assoluto e relativo) "<Write(); inv->Write(); rej->Write(); fun->Write(); standroot->Write(); fout->Close(); }