1 |
buchmann |
1.1 |
#include <iostream>
|
2 |
|
|
#include <iomanip>
|
3 |
|
|
#include <TRandom.h>
|
4 |
|
|
#include <TF1.h>
|
5 |
|
|
#include <TH1.h>
|
6 |
|
|
#include <TCanvas.h>
|
7 |
|
|
#include <TMath.h>
|
8 |
|
|
#include <sstream>
|
9 |
|
|
using namespace std;
|
10 |
|
|
|
11 |
|
|
void find68(TH1F* histo, long N, int rounds)
|
12 |
|
|
{
|
13 |
|
|
float max = histo->GetBinCenter(histo->GetMaximumBin());
|
14 |
|
|
int startbin=histo->GetMaximumBin();
|
15 |
|
|
int left=startbin;
|
16 |
|
|
int right=startbin;
|
17 |
|
|
float want=(float)N * 0.68*rounds;
|
18 |
|
|
float have=histo->GetBinContent(startbin);
|
19 |
|
|
cout << "found maximum at " << max << " ( this is bin " << startbin << ")" << endl;
|
20 |
|
|
while(have<want)
|
21 |
|
|
{
|
22 |
|
|
if(histo->GetBinContent(left-1)>histo->GetBinContent(right+1))
|
23 |
|
|
{
|
24 |
|
|
have+=histo->GetBinContent(left-1);
|
25 |
|
|
left--;
|
26 |
|
|
}
|
27 |
|
|
else
|
28 |
|
|
{
|
29 |
|
|
have+=histo->GetBinContent(right+1);
|
30 |
|
|
right++;
|
31 |
|
|
}
|
32 |
|
|
}
|
33 |
|
|
float loweredge=histo->GetBinCenter(left);
|
34 |
|
|
float upperedge=histo->GetBinCenter(right);
|
35 |
|
|
cout << "we now have " << have << " and we wanted at least " << want << endl;
|
36 |
|
|
cout << "the range is " << loweredge << " to " << upperedge<< " corresponding to :" << endl;
|
37 |
|
|
|
38 |
|
|
cout << "\033[1;34m " << max << "+ " << (upperedge-max) << " - " << (max-loweredge) << " \033[0m" << endl;
|
39 |
|
|
|
40 |
|
|
// cout << max << "+ " << (upperedge-max) << " - " << (max-loweredge) << endl;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
void combine_dists(TH1F *combineddist,float *x1,float *x2,float *x3, long N)
|
45 |
|
|
{
|
46 |
|
|
float temp=-99;
|
47 |
|
|
for (int i=0;i<N;i++)
|
48 |
|
|
{
|
49 |
|
|
temp = x1[i]+x2[i]-x3[i];
|
50 |
|
|
combineddist->Fill(temp);
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
void megagenerate(TH1F *histo, unsigned int N, unsigned int rounds)
|
54 |
|
|
{
|
55 |
|
|
float lambda=5;
|
56 |
|
|
stringstream function1,function2, function3;
|
57 |
|
|
function1 << "(TMath::Power(" << lambda << ",x)*TMath::Exp(-" << lambda << "))/(TMath::Gamma(x+1))";
|
58 |
|
|
lambda=4;
|
59 |
|
|
function2 << "(TMath::Power(" << lambda << ",x)*TMath::Exp(-" << lambda << "))/(TMath::Gamma(x+1))";
|
60 |
|
|
lambda=1;
|
61 |
|
|
function3 << "(TMath::Power(" << lambda << ",x)*TMath::Exp(-" << lambda << "))/(TMath::Gamma(x+1))";
|
62 |
|
|
|
63 |
|
|
TF1 *f1 = new TF1("f1",function1.str().c_str(),0,10);
|
64 |
|
|
TF1 *f2 = new TF1("f2",function2.str().c_str(),0,10);
|
65 |
|
|
TF1 *f3 = new TF1("f3",function3.str().c_str(),0,10);
|
66 |
|
|
|
67 |
|
|
for (int iround=0; iround<rounds;iround++)
|
68 |
|
|
{
|
69 |
|
|
for (int i=0;i<N;i++)
|
70 |
|
|
{
|
71 |
|
|
histo->Fill(f1->GetRandom()+f2->GetRandom()-f3->GetRandom());
|
72 |
|
|
}//for i
|
73 |
|
|
cout << "we now have " << histo->GetEntries() << endl;
|
74 |
|
|
}// for rounds
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
void generate(float *x1, int lambda,long N,TH1F* histo)
|
80 |
|
|
{
|
81 |
|
|
stringstream function;
|
82 |
|
|
function << "(TMath::Power(" << lambda << ",x)*TMath::Exp(-" << lambda << "))/(TMath::Gamma(x+1))";
|
83 |
|
|
//TF1 *f1 = new TF1("f1","(TMath::Power(1,x)*TMath::Exp(-1))/(TMath::Gamma(x+1))",0,10);
|
84 |
|
|
TF1 *f1 = new TF1("f1",function.str().c_str(),0,10);
|
85 |
|
|
for(int i=0;i<N;i++)
|
86 |
|
|
{
|
87 |
|
|
x1[i]=f1->GetRandom();
|
88 |
|
|
histo->Fill(x1[i]);
|
89 |
|
|
}//end of for
|
90 |
|
|
}//end of generate_x1
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
int main()
|
94 |
|
|
{
|
95 |
|
|
long N=1000000;
|
96 |
|
|
int rounds=1000;
|
97 |
|
|
cout << "generating the distributions with N= " << N << " and rounds = " << rounds << endl;
|
98 |
|
|
|
99 |
|
|
TH1F *summary = new TH1F("summary","summary",1000,0,20);
|
100 |
|
|
TCanvas *c1 = new TCanvas("c1","c1");
|
101 |
|
|
|
102 |
|
|
megagenerate(summary,N,rounds);
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
cout << "Currently there are " << summary->GetEntries() << " entries" << endl;
|
106 |
|
|
|
107 |
|
|
// combine_dists(combineddist2,x1,x2,x3,N);
|
108 |
|
|
|
109 |
|
|
summary->Draw();
|
110 |
|
|
c1->SaveAs("MegaCanvas.png");
|
111 |
|
|
|
112 |
|
|
find68(summary,N,rounds);
|
113 |
|
|
|
114 |
|
|
return 0;
|
115 |
|
|
}
|
116 |
|
|
|