-
Notifications
You must be signed in to change notification settings - Fork 0
/
testRandom.cpp
executable file
·150 lines (130 loc) · 3.69 KB
/
testRandom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// created by Vitor Jose Shen
// at Uppsala University
// --------------------------
#include <iostream>
#include "TLorentzVector.h"
#include "TVector3.h"
#include "TMath.h"
// void testRandom(Int_t nrEvents=500000000)
void testRandom(Int_t nrEvents=100000000)
{
Double_t use, uuse, uuuse;
TRandom *r1=new TRandom();
TRandom2 *r2=new TRandom2();
TRandom3 *r3=new TRandom3();
r3->SetSeed(time(NULL));
// TH1D *h1=new TH1D("h1","TRandom",500,0,1);
// TH1D *h2=new TH1D("h2","TRandom2",500,0,1);
// TH1D *h3=new TH1D("h3","TRandom3",500,0,1);
// TH1D *h1=new TH1D("h1","TRandom",100,0,360);
// TH1D *h2=new TH1D("h2","TRandom2",100,0,360);
TH1D *h3=new TH1D("PhiTRandom3","PhiAngle",100,0,360);
// TH1D *h4=new TH1D("h4","TRandom",100,0,180);
// TH1D *h5=new TH1D("h5","TRandom2",100,0,180);
// TH1D *h6=new TH1D("ThTRandom3","ThetaAngle",100,-90,90);
TH1D *h6=new TH1D("ThTRandom3","ThetaAngle",100,0,180);
TH1D *hc=new TH1D("CosThTRandom3","Cos(Theta)",100,-1,1);
TH1D *ht=new TH1D("TestCosThTRandom3","Cos(Theta)",100,-1,1);
TH1D *htt=new TH1D("TestThTRandom3","ThetaAngle",100,0,180);
TH1D *test=new TH1D("","",100,0,360);;
TH1D *ttest=new TH1D("","",100,0,180);
TH1D *tttest=new TH1D("","",100,-1,1);
test->SetStats(0);
ttest->SetStats(0);
tttest->SetStats(0);
TStopwatch *st=new TStopwatch();
// [0,360]
// st->Start();
// for (Int_t i=0; i<nrEvents; i++) {
// // h1->Fill(r1->Uniform(0,1));
// h1->Fill(r1->Uniform(0,360));
// }
// st->Stop();
// cout << "Random: " << st->CpuTime() << endl;
// TCanvas *c1=new TCanvas;
// h1->Draw();
// st->Start();
// for (Int_t i=0; i<nrEvents; i++) {
// // h2->Fill(r2->Uniform(0,1));
// h2->Fill(r2->Uniform(0,360));
// }
// st->Stop();
// cout << "Random2: " << st->CpuTime() << endl;
// TCanvas *c2=new TCanvas;
// h2->Draw();
st->Start();
for (Int_t i=0; i<nrEvents; i++) {
// h3->Fill(r3->Uniform(0,1));
use = r3->Uniform(0,360);
h3->Fill(use);
test->Fill(use);
}
st->Stop();
cout << "CPU Time of Random3 for phi: " << st->CpuTime() << endl;
TCanvas *c3=new TCanvas;
// TPad *p3=new TPad;
h3->Draw();
c3->SetLogy();
TPad *subpad1 = new TPad("subpad","",0.6,0.3,0.95,0.65);
subpad1->Draw();
subpad1->cd();
test->Draw();
// [0,180]
// st->Start();
// for (Int_t i=0; i<nrEvents; i++) {
// // h1->Fill(r1->Uniform(0,1));
// h4->Fill(r1->Uniform(0,180));
// }
// st->Stop();
// cout << "Random: " << st->CpuTime() << endl;
// TCanvas *c4=new TCanvas;
// h4->Draw();
// TMath::Cos(h4)->Draw();
// st->Start();
// for (Int_t i=0; i<nrEvents; i++) {
// // h2->Fill(r2->Uniform(0,1));
// h5->Fill(r2->Uniform(0,180));
// }
// st->Stop();
// cout << "Random2: " << st->CpuTime() << endl;
// TCanvas *c5=new TCanvas;
// h5->Draw();
// TMath::Cos(h5)->Draw();
st->Start();
for (Int_t i=0; i<nrEvents; i++) {
// h3->Fill(r3->Uniform(0,1));
// use = r3->Uniform(-90,90);
uuse = r3->Uniform(0,180);
h6->Fill(uuse);
ttest->Fill(uuse);
hc->Fill(TMath::Cos((uuse)*2*TMath::Pi()/360));
uuuse = r3->Uniform(-1,1);
ht->Fill(uuuse);
tttest->Fill(uuuse);
htt->Fill(TMath::RadToDeg()*TMath::ACos(uuuse));
//TMath::DegToRad()
//TMath::RadToDeg()
}
st->Stop();
cout << "CPU Time of Random3 for theta and cos(theta): " << st->CpuTime() << endl;
TCanvas *c6=new TCanvas;
// TPad *p6 = new TPad;
h6->Draw();
c6->SetLogy();
TPad *subpad2 = new TPad("subpad","",0.6,0.3,0.95,0.65);
subpad2->Draw();
subpad2->cd();
ttest->Draw();
TCanvas *cc=new TCanvas;
hc->Draw();
TCanvas *ct=new TCanvas;
// TPad *pt = new TPad;
ht->Draw();
ct->SetLogy();
TPad *subpad3 = new TPad("subpad","",0.6,0.3,0.95,0.65);
subpad3->Draw();
subpad3->cd();
tttest->Draw();
TCanvas *ctt=new TCanvas;
htt->Draw();
}