-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimulatore.C
More file actions
229 lines (161 loc) · 5.76 KB
/
Simulatore.C
File metadata and controls
229 lines (161 loc) · 5.76 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//#if !defined(__CINT__) || defined(__MAKECINT__))
#include <Riostream.h>
#include <TObject.h>
#include <TSystem.h>
#include "TStopwatch.h"
#include "TMath.h"
#include "TAxis.h"
#include "TFile.h"
#include "TH1.h"
#include "TH1D.h"
#include "TCanvas.h"
#include <TTree.h>
#include <TBranch.h>
#include "TClonesArray.h"
#include "TRandom3.h"
#include "Punto.h"
#include "Retta.h"
#include "Neutron.h"
#include "Propagatore.h"
#include "Generatore.h"
#include "Rivelatore.h"
void Simulatore(){
TFile *f0=new TFile("CrossSections/Cabs.root","READ");
TFile *f1=new TFile("CrossSections/Habs.root","READ");
TFile *f2=new TFile("CrossSections/Cscat.root","READ");
TFile *f3=new TFile("CrossSections/Hscat.root","READ");
TH1F *h_Cabs=dynamic_cast<TH1F*>(f0->Get("C_absorption"));
TH1F *h_Habs=dynamic_cast<TH1F*>(f1->Get("H_absorption"));
TH1F *h_Cscatt=dynamic_cast<TH1F*>(f2->Get("C_scattering"));
TH1F *h_Hscatt=dynamic_cast<TH1F*>(f3->Get("H_scattering"));
const double hydrogen_density=8e22;
const double carbon_density=4e22;
double Estart;
double Nstart;
double lateral_size;
double thick;
double beam_size;
double y_start=0;// y_start e x_start sono le posizioni del centro del fascio, che per ora lascio a zero
double x_start=0;
double radius;
double shield_sphere_dist;
double seed=0.1;
gRandom->SetSeed(seed); //questo chiaramente non sta funzionando ...
cout << "Initial Beam Energy (eV)" << endl;
cin >> Estart;
cout << "Number of neutrons " << endl;
cin >> Nstart;
cout << "Shield lateral size (mm) " << endl;
cin >> lateral_size;
cout << "Shield thickness (mm) " << endl;
cin >> thick;
cout << "Beam lateral size (mm) " << endl;
cin >> beam_size;
cout << "Radius of the spherical detector (mm) " << endl;
cin >> radius;
cout << "Distance shield-sphere centre (mm) " << endl;
cin >> shield_sphere_dist;
Propagatore *prop=new Propagatore(h_Cscatt,h_Hscatt,h_Cabs,h_Habs,lateral_size,thick,hydrogen_density,carbon_density);
Generatore *gen=new Generatore(Nstart,Estart,beam_size,beam_size,x_start,y_start);
Rivelatore *riv=new Rivelatore(radius,0,0,shield_sphere_dist+prop->GetTargetThick());
double x_vec[461];// vettore di bin energetici di diverse dimensioni
for(int i=0;i<=100;i++){
x_vec[i]=i;
}
for(int j=1;j<=90;j++){
x_vec[j+100]=100+j*10;
}
for(int j=1;j<=90;j++){
x_vec[j+190]=1000+j*100;
}
for(int j=1;j<=90;j++){
x_vec[j+280]=10000+j*1000;
}
for(int j=1;j<=90;j++){
x_vec[j+370]=100000+j*10000;
}
Neutron *n_in=new Neutron();
Neutron *n_out=new Neutron();
TFile *outFile=new TFile("neutronTree.root","RECREATE");
TTree *tree=new TTree("tree","tree di neutroni uscenti");
ifstream myReadFile;
myReadFile.open("hist_k");
//double k_coeff[461]; //i k_coeff son in pSv*mm^2 (Valeria ce li ha dati in pSv*cm^2)
double x_energy[41];
double y_kcoeff[41];
for(int i=0; i<41;i++){
double x;
double y;
myReadFile >> x >> y;
x_energy[i]= x;
y_kcoeff[i]=y*100; //passo da pSv*cm^2 a pSv*mm^2
}
TH1D *hist_k=new TH1D("hist_k","hist_k",40,x_energy); //41
for(int i=0;i<40;i++){
hist_k->Fill(x_energy[i],y_kcoeff[i]);
}
tree->Branch("n_in",n_in,32000,2);
tree->Branch("n_out",&n_out,32000,2);
TH1D *spectrum=new TH1D("spectrum","spectrum",460,x_vec); //x_vec deve avere dimensione nbins+1 !!!!
TH1D *abs_spectrum=new TH1D("abs_spectrum","abs_spectrum",460,x_vec);
TStopwatch *watch=new TStopwatch();
double time=0;
watch->Start();
double dose=0;
for(int i=0;i<gen->GetParticles();i++){
gen->Genera_neutrone(n_in);
*n_out=Neutron(n_in);
prop->Propagation(n_out);
double length=riv->Intersezione(n_out);
if(n_out->GetAbsorption() && (n_out->GetEnergy()>0) ) abs_spectrum->Fill(n_out->GetEnergy());
if((n_out->GetEnergy()>0) && !(n_out->GetAbsorption()) && length!=0 ) {
int bin=spectrum->FindBin(n_out->GetEnergy());
int bin2=hist_k->FindBin(n_out->GetEnergy());
double deltaE=spectrum->GetBinWidth(bin);
double kc=hist_k->GetBinContent(bin2);
//cout<<kc<<endl;
spectrum->Fill(n_out->GetEnergy(),((length/riv->GetVolume())/deltaE)/Nstart); //fluence spectrum per starting particle
dose += (((length/riv->GetVolume()))/Nstart)*kc;
}
//tree->Fill();
n_in->Reset();
}
watch->Stop();
time=watch->RealTime();
/* double dose;
for(int i=0;i<461;i++){
dose +=k_coeff[i]*spectrum->GetBinContent(i)*spectrum->GetBinWidth(i);
}*/
//tree->Write();
TCanvas *c1=new TCanvas("c1","c1",1200,800);
c1->cd();
spectrum->GetXaxis()->SetTitle("Energy (eV)");
spectrum->GetYaxis()->SetTitle("Fluence Spectrum #Delta#phi/#Delta E");
spectrum->Draw("HIST");
//hist_k->Draw("HIST");
// c1->Close();
TCanvas *c2=new TCanvas("c2","c2",1200,800);
c2->cd();
abs_spectrum->SetTitle("Energy Spectrum of Neutrons Absorbed in PE");
abs_spectrum->GetXaxis()->SetTitle("Energy (eV)");
abs_spectrum->GetYaxis()->SetTitle("# counts");
abs_spectrum->Draw("HIST");
// c1->Close();
delete n_in;
delete n_out;
//myReadFile.close();
//outFile->Close();
cout<<" "<<endl;
cout<<"Fluence per Starting Particle: "<<riv->GetFluence()/Nstart<<endl;
cout<<" "<<endl;
cout<<"Dose: "<<dose<<endl;
cout<<" "<<endl;
cout<<"Mean number of collisions: "<<prop->GetNcoll()/Nstart<<endl;
cout<<" "<<endl;
cout<<"Mean number of collisions before Absorption: "<<prop->GetAbscoll()/prop->GetAssorbiti()<<endl;
cout<<" "<<endl;
cout<<"Mean CPU time per neutron: "<<time/Nstart<<endl;
cout<<" "<<endl;
}
//DA AGGIUNGERE: K_coeff per la dose da sistemare, aggiungere le uncertainties
//Deadline: 10 Febbraio (report con nostri risultati)