Hi dear experts,
Please help.
I have plotted a 2D histogram from .txt file and now I have to generate a random cosine angle…
void CDF()
{
TRandom2 *rand = new TRandom2(1);
TCanvas *c1 = new TCanvas();
TH1F *histogram = new TH1F("histogram ", " ", 10001, -1, 1);
TH2F *hist = new TH2F("hist"," Histogram ", 10001, -1.05, 1.1, 10001, 0.0000003, 1.);
const int length = 10001;
double mu[length], f[length];
double rr = 0;
double indm = f[length];
double M = mu[length];
fstream file;
file.open ("dSigma-dOmega.txt", ios::in);
int loop=0;
while(!file.eof())
{
file >> mu[loop] >> f[loop];
rr= rand-> Rndm();
//hist->Fill(mu, f);
// cout<<loop<<" "<<mu[loop]<<" "<<f[loop]<<" "<<rr<<endl;
loop++;
histogram->Fill(rr);
}
hist->GetXaxis()->SetTitle("mu");
hist->GetXaxis()->CenterTitle(true);
hist->GetYaxis()->SetTitle("f");
hist->GetYaxis()->CenterTitle(true);
c1->SetLogy();
hist->SetMarkerColor(35);
hist->Draw();
histogram->Draw();
file.close();
}
To complete my code I must write Wolfram Mathematica code for C++
Wolfram Mathematica code here …
While[(M = Quotient[M, 10]) != 0, While[f[[indm -= M]] > rr];
indm += M];
fi = f[[indm - 1]];
[mu]i = [mu][[indm - 1]];
m = (rr - fi) ([mu][[indm]] - [mu]i)/(f[[indm]] - fi) + [mu]i
Best regards,
ROOT Version: 6
Platform: Ubuntu20.10
Compiler: Not Provided