Hi,rooters,
What I want to obtain is the random number (u,phi), which obey custom function g2.
My code is
#include <TMath.h>
#include <TGraph2D.h>
#include <TRandom.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TF2.h>
#include <TH1.h>
#include "TStopwatch.h"
Double_t g2(Double_t *x, Double_t *par)
{
Double_t r1 = par[0]*(1+(1+x[0])*(1+x[0]))-4*x[0]/par[0]*(1+x[0])*(par[0]-x[0])*(1-par[1]*TMath::Cos(2*(x[1]-par[2])));
Double_t r2 = par[3]*x[0]*(x[0]+2)*(par[0]-2*x[0]);
Double_t r3 = par[4]*2*x[0]*TMath::Sqrt(x[0]*(par[0]-x[0]))*TMath::Sin(x[1]);
Double_t r4 = par[0]*par[0]*((1+x[0])*(1+x[0])*(1+x[0]));
Double_t result = (r1 + r2 + r3)/r4;
return result;
}
void originalcode()
{
TStopwatch timer;
timer.Start();
gStyle->SetOptStat(1);
// Define some parameters
Double_t x, y, u, phi;
Double_t E0 = 45.5*1e9;
Double_t w0 = 1.24;
Double_t me = 0.511*1e6;
Double_t gamma = E0/me;
Double_t kappa = 4*E0*w0/(me*me);
Double_t L1 = 60;
Double_t L2 = 40;
Double_t theta0 = 3.4467*1e-3;
// Create a histogram and fill it randomly with f2
Double_t umin = 0;
Double_t umax = kappa;
Double_t phimin = 0;
Double_t phimax = 2*TMath::Pi();
Double_t npar = 5;
TF2 *f2 = new TF2("f2",g2,umin,umax,phimin,phimax,npar);
f2->SetParameter(0,kappa);
f2->SetParameter(1,0);
f2->SetParameter(2,0);
f2->SetParameter(3,0);
f2->SetParameter(4,1);
// Fill the 2D histogram
Int_t nd = 1*20; // MC events
for (Int_t N=0; N<nd; N++)
{
f2->GetRandom2(u,phi);
cout<<"parameter u is "<< u << endl;
cout<<"parameter phi is "<< phi << endl;
}
Quetions: the print u and phi are always the same per run of my code. I don’t know what’ going on. And I don’t know the relationship between the result and setseed~