Rev 73 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
25 | f9daq | 1 | // own include |
2 | //#include "include/raySimulator.h" |
||
3 | #include "include/RTUtil.h" |
||
4 | #include "include/guide.h" |
||
5 | |||
6 | // general include |
||
7 | #include "TROOT.h" |
||
8 | #include "TSystem.h" |
||
9 | #include "TStyle.h" |
||
10 | #include "TCanvas.h" |
||
11 | #include "TMath.h" |
||
12 | #include "TView3D.h" |
||
13 | #include "TH1F.h" |
||
14 | #include "TH2F.h" |
||
15 | #include "TBenchmark.h" |
||
16 | #include "TPolyMarker.h" |
||
17 | #include "TGraph.h" |
||
18 | #include "TF1.h" |
||
19 | |||
20 | //================================================================================= |
||
21 | TCanvas *c3dview; |
||
22 | TCanvas *cacc; |
||
23 | int show_3d = 0, show_data = 0; |
||
24 | int draw_width = 2; |
||
25 | |||
73 | f9daq | 26 | // calls default constructor CVodnik.cpp |
25 | f9daq | 27 | |
28 | //void SetCenter(double x = -2.0, double y = 0.0, double z = 0.0) |
||
73 | f9daq | 29 | //{center.SetXYZ(x,y,z); detector = new CDetector(center);} |
25 | f9daq | 30 | |
31 | |||
32 | //void SetLGType(int in = 1, int side = 1, int out = 0) |
||
73 | f9daq | 33 | //{detector->SetLGType(in, side, out);} |
25 | f9daq | 34 | |
35 | //void SetLG(double SiPM0 = 3.0, double M0 = 1.666, double d0 = 3.0, double n10 = 1.0, double n20 = 1.48, double n30 = 1.48, double R0 = 0.96) |
||
73 | f9daq | 36 | //{detector->SetLG(SiPM0, M0, d0, n10, n20, n30, R0);} |
37 | |||
25 | f9daq | 38 | //void SetR(double R0) {detector->SetR(R0);} |
73 | f9daq | 39 | /* |
25 | f9daq | 40 | void SetGlass(int glass_on0 = 0, double glass_d0 = 0.3) |
41 | {detector->SetGlass(glass_on0, glass_d0);} |
||
42 | |||
43 | void SetGap(double x_gap0 = 0.3, double y_gap0 = 0.0, double z_gap0 = 0.0) |
||
44 | {detector->SetGap(x_gap0 , y_gap0, z_gap0);} |
||
73 | f9daq | 45 | |
25 | f9daq | 46 | void SetRCol(int in = 2, int lg = 8, int out = 4, int gla = 6) |
47 | {detector->SetRCol(in, lg, out, gla);}; |
||
48 | void SetDCol(int LG0 = 1, int glass0 = 2, int active0 = 3) |
||
49 | {detector->SetDCol(LG0, glass0, active0);}; |
||
50 | |||
73 | f9daq | 51 | |
25 | f9daq | 52 | void SetDWidth(int w = 1) {draw_width = w;} |
53 | |||
54 | void SetFresnel(int b = 1) {detector->SetFresnel(b);} |
||
55 | void SetAbsorb(int b = 0, double A0 = 1e4) {detector->SetAbsorption(b, A0);} |
||
56 | |||
57 | void SetGuideOn(int b = 0) {detector->SetGuideOn(b);} |
||
58 | |||
59 | void SetTypeU() {SetGlass(1, 0.3);SetGap(0.7);} |
||
60 | void SetTypeC() {SetGlass(0, 0.3);SetGap(1.03);} |
||
73 | f9daq | 61 | */ |
25 | f9daq | 62 | //----------------------------------------------------------------------------- |
73 | f9daq | 63 | void Init(double rsys_scale = 10.0) |
25 | f9daq | 64 | { |
73 | f9daq | 65 | RTSetStyle(gStyle); |
66 | gStyle->SetOptStat(10); |
||
67 | |||
68 | if(show_3d) { |
||
69 | double rsys0[]={-rsys_scale,-rsys_scale,-rsys_scale}; |
||
70 | double rsys1[]={ rsys_scale, rsys_scale, rsys_scale}; |
||
71 | |||
72 | c3dview = (TCanvas*)gROOT->FindObject("c3dview"); |
||
73 | if(!c3dview) {c3dview = new TCanvas("c3dview", "3D View", 0, 0, 700, 723); |
||
74 | c3dview->SetFillColor(0);} |
||
75 | else c3dview->Clear(); |
||
76 | |||
77 | TView3D *view = new TView3D(1, rsys0, rsys1); |
||
78 | view->SetRange(rsys0[0], rsys0[1], rsys0[2], rsys1[0], rsys1[1], rsys1[2]); |
||
79 | //view->SetPerspective(); |
||
80 | view->SetParallel(); |
||
81 | view->FrontView(); |
||
82 | view->Zoom();view->Zoom();view->Zoom();//view->Zoom(); |
||
83 | //view->ToggleRulers(); |
||
84 | } |
||
25 | f9daq | 85 | } |
86 | //----------------------------------------------------------------------------- |
||
87 | void DrawData(CDetector *detector, DetectorParameters& parameters, double theta = 0.0, double acc = 0.0, int only2d = 0) |
||
88 | { |
||
73 | f9daq | 89 | if(show_data) { |
90 | char sbuff[256]; |
||
91 | sprintf(sbuff, "SiPM = %.1lf, L.y. = %.2lf, d = %.1lf | gap = (%.1lf, %.1lf, %.1lf), #theta = %.1lf | acceptance = %.3lf", |
||
92 | parameters.getA(), parameters.getLightYield()*acc, parameters.getD(), |
||
93 | parameters.getGap().x(), parameters.getGap().y(), parameters.getGap().z(), theta, acc); |
||
94 | |||
95 | if(!only2d) { |
||
96 | RTCanvas *cdata = new RTCanvas((char*)"Data", sbuff, 350, 0, 950, 950); |
||
97 | cdata->Divide(3,3); |
||
98 | int cpc = 1; |
||
84 | f9daq | 99 | cdata->cd(cpc++); |
100 | TH2F* generated = detector->GetGenerated(); |
||
101 | int nGenerated = generated->GetEntries(); |
||
102 | int minimum = generated->GetBinContent(generated->GetMinimumBin()); |
||
103 | int maximum = generated->GetBinContent(generated->GetMaximumBin()); |
||
104 | generated->GetZaxis()->SetRangeUser(0, 1.05*maximum); |
||
105 | double variation = (maximum-minimum)/(double)nGenerated; |
||
106 | printf("Statistical variation (max-min)/all = %f perc. \n", variation*100); |
||
107 | generated->SetTitle("Generated"); |
||
108 | generated->Draw("colz"); |
||
109 | cdata->cd(cpc++); //((detector->GetLG())->GetHIn())->Draw("COLZ"); |
||
110 | TH2F* histoPlate = detector->GetHPlate(); |
||
111 | histoPlate->Draw("COLZ"); |
||
73 | f9daq | 112 | cdata->cd(cpc++); //((detector->GetLG())->GetHOut())->Draw("COLZ"); |
84 | f9daq | 113 | TH2F* histoGlass = (detector->GetHGlass()); |
114 | histoGlass->Draw("COLZ"); |
||
73 | f9daq | 115 | |
84 | f9daq | 116 | cdata->cd(cpc++); |
117 | TH2F* histoActive = (detector->GetHActive()); |
||
118 | histoActive->Draw("COLZ"); |
||
119 | cdata->cd(cpc++); |
||
120 | TH2F* histoLaser = (detector->GetHLaser()); |
||
121 | histoLaser->Draw("COLZ"); |
||
122 | cdata->cd(cpc++); |
||
123 | TH2F* histoDetector = (detector->GetHDetector()); |
||
124 | histoDetector->Draw("COLZ"); |
||
73 | f9daq | 125 | |
84 | f9daq | 126 | cdata->cd(cpc++); |
127 | TH1F* fate=((detector->GetLG())->GetHFate()); |
||
128 | fate->Draw(); |
||
129 | cdata->cd(cpc++); |
||
130 | TH1F* reflections = ((detector->GetLG())->GetHNOdb_all()); |
||
131 | reflections->Draw(); |
||
132 | cdata->cd(cpc++); |
||
133 | TH1F *reflectedExit = ((detector->GetLG())->GetHNOdb_exit()); |
||
134 | reflectedExit->Draw(); |
||
73 | f9daq | 135 | }else{ |
136 | RTCanvas *cdata = new RTCanvas((char*)"Data", sbuff, 350, 0, 500, 500); |
||
137 | cdata->cd(0); (detector->GetHLaser())->Draw("COLZ"); |
||
138 | cdata->SaveAs("cdata.gif"); |
||
139 | } |
||
140 | } |
||
25 | f9daq | 141 | } |
142 | //----------------------------------------------------------------------------- |
||
143 | void DrawAcc(int n, double *x, double *y, char *htitle = (char*)";;Acceptance", |
||
73 | f9daq | 144 | double xmin = 1.0, double xmax = 0.0, double ymin = 0.0, double ymax = 1.0) |
25 | f9daq | 145 | { |
73 | f9daq | 146 | |
147 | cacc = new TCanvas((char*)"Acceptance", (char*)"Acceptance", 0, 0, 700, 480); |
||
148 | |||
149 | (cacc->cd(0))->SetRightMargin(0.05); |
||
150 | (cacc->cd(0))->SetLeftMargin(0.13); |
||
151 | (cacc->cd(0))->SetTopMargin(0.08); |
||
152 | |||
153 | TGraph *gacceptance = new TGraph(n, x, y); |
||
154 | gacceptance->SetTitle(htitle); |
||
155 | gacceptance->SetMarkerStyle(8); |
||
156 | gacceptance->SetLineColor(12); |
||
157 | gacceptance->SetLineWidth(1); |
||
158 | if(xmin < xmax) |
||
159 | (gacceptance->GetXaxis())->SetRangeUser(xmin, xmax); |
||
160 | (gacceptance->GetYaxis())->SetRangeUser(ymin, ymax); |
||
161 | |||
162 | gacceptance->Draw("ACP"); |
||
163 | //cacc->Print("acceptance.pdf"); |
||
164 | //delete gacceptance; |
||
165 | //delete cacc; |
||
25 | f9daq | 166 | } |
167 | //----------------------------------------------------------------------------- |
||
168 | void PrintGlassStat(CDetector *detector) |
||
169 | { |
||
73 | f9daq | 170 | int glass_in = ((detector->GetLG())->GetHOut())->GetEntries(); |
171 | int glass_out = (detector->GetHGlass())->GetEntries(); |
||
172 | printf("glass_in = %d, glass_out = %d, frac = %.3lf\n", glass_in, glass_out, glass_out/(double)glass_in); |
||
25 | f9daq | 173 | } |
174 | //----------------------------------------------------------------------------- |
||
175 | void PrintGuideHead() |
||
176 | { |
||
73 | f9daq | 177 | //printf(" gap (x,y,z) | theta phi | Back | Loss | Total| Miss | Exit | Acceptance\n"); |
178 | printf("Acceptance\n"); |
||
25 | f9daq | 179 | } |
180 | //----------------------------------------------------------------------------- |
||
54 | f9daq | 181 | void PrintGuideStat(double acceptance) |
25 | f9daq | 182 | { |
73 | f9daq | 183 | /*int n_active = (detector->GetHActive())->GetEntries(); |
25 | f9daq | 184 | int n_enter = (detector->GetLG())->GetEnteranceHits(); |
185 | double izkoristek = n_active/(double)n_enter; |
||
186 | int fates[7]; (detector->GetLG())->GetVFate(fates); |
||
73 | f9daq | 187 | |
25 | f9daq | 188 | // printf(" gap (x,y,z) | theta phi | Back | Loss | Total| Miss | Exit | Acceptance\n"); |
73 | f9daq | 189 | |
25 | f9daq | 190 | printf("%4.1lf,%4.1lf,%4.1lf | %4.1lf,%6.1lf |", |
191 | (detector->GetVGap()).x(), (detector->GetVGap()).y(), (detector->GetVGap()).z(), theta, phi); |
||
192 | for(int i=0;i<5;i++) printf("%5.1lf |", 100.0*fates[i]/(double)n_enter); |
||
73 | f9daq | 193 | |
25 | f9daq | 194 | printf("%5.1lf\n", 100.0*izkoristek);*/ |
73 | f9daq | 195 | |
196 | //double n_active = (detector->GetHActive())->GetEntries(); |
||
197 | //double r_acc = 100.0 * n_active / n_in; |
||
198 | double r_acc = 100.0 * acceptance; |
||
199 | printf("%7.3lf\n", r_acc); |
||
25 | f9daq | 200 | } |
201 | //----------------------------------------------------------------------------- |
||
73 | f9daq | 202 | |
25 | f9daq | 203 | //----------------------------------------------------------------------------- |
204 | // en zarek |
||
73 | f9daq | 205 | double Single(CDetector *detector, DetectorParameters& parameters, |
84 | f9daq | 206 | TVector3 hit = TVector3(0.0, 0.0, 0.0), double theta = 0.0, double phi = 0.0) |
25 | f9daq | 207 | { |
73 | f9daq | 208 | theta = Pi()*theta/180.0; |
209 | if(theta < 1e-6) theta = 1e-6; |
||
210 | phi = phi*Pi()/180.0; |
||
211 | if(phi < 1e-6) phi = 1e-6; |
||
212 | |||
213 | double offset = (parameters._plateOn ? parameters._plateWidth : 0); |
||
214 | |||
215 | //detector->Init(); |
||
216 | if(show_3d) detector->Draw(draw_width); |
||
217 | |||
218 | CRay *ray0 = new CRay(hit.x() - offset, hit.y(), hit.z(), |
||
219 | TMath::Cos(theta), TMath::Sin(theta)*TMath::Sin(phi), |
||
220 | TMath::Sin(theta)*TMath::Cos(phi)); |
||
84 | f9daq | 221 | // Set y-polarization == vertical |
222 | TVector3 k(ray0->GetK()); |
||
223 | TVector3 polarization(k.Orthogonal()); |
||
224 | polarization.Unit(); |
||
225 | polarization.Rotate(phi, k); |
||
226 | if (polarization.Dot(ray0->GetK()) > 1e-2) printf("ERROR: pol not perep\n"); |
||
73 | f9daq | 227 | ray0->setPolarization(polarization); |
84 | f9daq | 228 | CRay ray1; |
73 | f9daq | 229 | |
230 | detector->Propagate(*ray0, ray1, show_3d); |
||
231 | |||
232 | CRay *incidentPolarization = new CRay; |
||
233 | incidentPolarization->SetColor(kGreen); |
||
234 | TVector3 drawPosition = ray0->GetR(); |
||
235 | drawPosition.SetX(drawPosition.X() - 5); |
||
236 | incidentPolarization->Set(drawPosition, polarization); |
||
237 | incidentPolarization->DrawS(drawPosition.X(), 1); |
||
238 | |||
84 | f9daq | 239 | TVector3 outPolarization = ray1.GetP(); |
240 | drawPosition = ray1.GetR(); |
||
73 | f9daq | 241 | drawPosition.SetX(drawPosition.X() + 5); |
242 | CRay* rayPol = new CRay(drawPosition, outPolarization); |
||
243 | rayPol->SetColor(kBlack); |
||
244 | rayPol->DrawS(drawPosition.X(), 1); |
||
245 | |||
246 | delete ray0; |
||
84 | f9daq | 247 | //delete ray1; |
73 | f9daq | 248 | |
249 | return (detector->GetHActive())->GetEntries() / (double)(1); |
||
25 | f9daq | 250 | } |
251 | //----------------------------------------------------------------------------- |
||
252 | // zarki, razporejeni v mrezi |
||
73 | f9daq | 253 | double Grid(CDetector *detector, DetectorParameters& parameters, |
84 | f9daq | 254 | int NN = 10, double theta = 0.0) |
25 | f9daq | 255 | { |
73 | f9daq | 256 | //CDetector *detector = new CDetector(center, 3, 1.666, 3, 3, 1, 1.48, 1.48); |
257 | theta = Pi()*theta/180.0; |
||
258 | if(theta < 1e-6) theta = 1e-6; |
||
25 | f9daq | 259 | |
73 | f9daq | 260 | //detector->Init(); |
261 | if(show_3d) detector->Draw(draw_width); |
||
262 | |||
263 | const double b = parameters.getB(); |
||
84 | f9daq | 264 | double simulated = 0; |
73 | f9daq | 265 | |
266 | double offset = (parameters._plateOn ? parameters._plateWidth : 0); |
||
84 | f9daq | 267 | const int GRID = 100; |
268 | for(int i = 0; i < GRID; i++) { |
||
269 | for(int j = 0; j < GRID; j++) { |
||
270 | for(int jk = 0; jk<NN; jk++){ |
||
271 | CRay *ray0 = new CRay(CENTER.x() - offset, |
||
272 | (i*b/GRID + b/(2.0*GRID) - b/2.0), |
||
273 | (j*b/GRID + b/(2.0*GRID) - b/2.0), |
||
274 | TMath::Cos(theta), |
||
275 | 0.0, |
||
276 | TMath::Sin(theta)); |
||
277 | TVector3 k(ray0->GetK()); |
||
278 | TVector3 polarization(k.Orthogonal()); |
||
279 | polarization.Unit(); |
||
280 | ray0->setPolarization(polarization); |
||
281 | CRay ray1; |
||
282 | if(i == (GRID/2) and jk == 0) |
||
283 | detector->Propagate(*ray0, ray1, show_3d); |
||
284 | else |
||
285 | detector->Propagate(*ray0, ray1, 0); |
||
286 | delete ray0; |
||
287 | simulated++; |
||
288 | //delete ray1; |
||
289 | } |
||
73 | f9daq | 290 | } |
291 | |||
292 | } |
||
293 | double acceptance = 0.0; |
||
294 | /* |
||
70 | f9daq | 295 | if( !(parameters.getPlateOn()) ) |
296 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN*NN; |
||
297 | else |
||
298 | acceptance = (detector->GetHActive())->GetEntries() / (detector->GetHPlate())->GetEntries(); |
||
73 | f9daq | 299 | */ |
84 | f9daq | 300 | acceptance = (detector->GetHActive())->GetEntries() / simulated; |
73 | f9daq | 301 | return acceptance; |
25 | f9daq | 302 | } |
303 | //----------------------------------------------------------------------------- |
||
304 | // zarki z nakljucnim polozajem vpada (na vstopni pov. vodnika) |
||
305 | // vsi pod kotom (theta, phi) |
||
73 | f9daq | 306 | double RandYZ(CDetector *detector, DetectorParameters& parameters, |
84 | f9daq | 307 | int NN, double theta, double phi, int show_rays) |
25 | f9daq | 308 | { |
73 | f9daq | 309 | //CDetector *detector = new CDetector(center, 3, 1.666, 3, 3, 1, 1.48, 1.48); |
310 | theta = theta*3.14159265358979312/180.0; |
||
311 | if(theta < MARGIN) theta = MARGIN; |
||
312 | phi = phi*3.14159265358979312/180.0; |
||
313 | if(phi < MARGIN) phi = MARGIN; |
||
314 | |||
315 | TDatime now; |
||
84 | f9daq | 316 | TRandom2 rand; |
73 | f9daq | 317 | rand.SetSeed(now.Get()); |
318 | |||
319 | //detector->Init(); |
||
320 | if(show_3d) detector->Draw(draw_width); |
||
321 | |||
84 | f9daq | 322 | double b = parameters.getB(); |
73 | f9daq | 323 | double offset = (parameters._plateOn ? parameters._plateWidth : 0); |
324 | |||
325 | for(int i = 0; i < NN; i++) { |
||
326 | |||
327 | double rx = CENTER.x() - offset; |
||
84 | f9daq | 328 | double ry = rand.Uniform(-b/2.0, b/2.0); |
329 | double rz = rand.Uniform(-b/2.0, b/2.0); |
||
73 | f9daq | 330 | |
331 | double rl = TMath::Cos(theta); |
||
332 | double rm = TMath::Sin(theta)*TMath::Sin(phi); |
||
333 | double rn = TMath::Sin(theta)*TMath::Cos(phi); |
||
334 | |||
335 | CRay *ray0 = new CRay(rx, ry, rz, rl, rm, rn); |
||
84 | f9daq | 336 | TVector3 k(ray0->GetK()); |
337 | TVector3 polarization(k.Orthogonal()); |
||
338 | polarization.Unit(); |
||
339 | polarization.Rotate(phi, k); |
||
73 | f9daq | 340 | ray0->setPolarization(polarization); |
84 | f9daq | 341 | CRay ray1; |
73 | f9daq | 342 | |
343 | if(i < show_rays) |
||
344 | detector->Propagate(*ray0, ray1, show_3d); |
||
345 | else |
||
346 | detector->Propagate(*ray0, ray1, 0); |
||
84 | f9daq | 347 | //delete ray1; |
73 | f9daq | 348 | delete ray0; |
349 | } |
||
350 | |||
351 | double acceptance = 0.0; |
||
352 | /* |
||
70 | f9daq | 353 | if( !(parameters.getPlateOn()) ) |
354 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN; |
||
355 | else |
||
356 | acceptance = (detector->GetHActive())->GetEntries() / (detector->GetHPlate())->GetEntries(); |
||
357 | //return (detector->GetHActive())->GetEntries() / (double)((NN)*(NN));*/ |
||
73 | f9daq | 358 | acceptance = (detector->GetHActive())->GetEntries() / (double) NN; |
359 | return acceptance; |
||
25 | f9daq | 360 | } |
361 | //----------------------------------------------------------------------------- |
||
362 | // zarki, izotropno porazdeljeni znotraj kota theta |
||
363 | // = nakljucni vstopni polozaj in kot |
||
70 | f9daq | 364 | // NN - number of rays to be simulated with angles theta distributed uniformly |
365 | // in cos theta and phi uniformly: |
||
366 | // theta [0, theta] |
||
367 | // phi [0,360] |
||
73 | f9daq | 368 | double RandIso(CDetector *detector, DetectorParameters& parameters, |
84 | f9daq | 369 | int NN = 1e3, double thetaMin=0.0, double thetaMax = 30.0, int show_rays = 30, int show_rand = 0) |
25 | f9daq | 370 | { |
73 | f9daq | 371 | //CDetector *detector = new CDetector(center, 3, 1.666, 3, 3, 1, 1.48, 1.48); |
372 | double pi = 3.14159265358979312; |
||
84 | f9daq | 373 | thetaMax = thetaMax*pi/180.0; |
374 | thetaMin = thetaMin*pi/180.0; |
||
375 | if(thetaMin < MARGIN) thetaMin = MARGIN; |
||
376 | if(thetaMax < MARGIN) thetaMax = MARGIN; |
||
25 | f9daq | 377 | |
73 | f9daq | 378 | TDatime now; |
84 | f9daq | 379 | TRandom2 rand; |
73 | f9daq | 380 | rand.SetSeed(now.Get()); |
381 | //double theta_min_rad = TMath::Power(TMath::Cos(theta), 2); |
||
84 | f9daq | 382 | double theta_min_rad = TMath::Cos(thetaMax); |
73 | f9daq | 383 | double theta_max_rad = TMath::Cos(thetaMin); |
25 | f9daq | 384 | |
73 | f9daq | 385 | TH1F *hphi, *htheta, *hcostheta, *hl, *hm, *hn; |
386 | hphi = (TH1F*)gROOT->FindObject("hphi"); if(hphi) delete hphi; |
||
387 | hphi = new TH1F("hphi", "hphi", 100, 0.0, 2.0*pi); |
||
388 | htheta = (TH1F*)gROOT->FindObject("htheta"); if(htheta) delete htheta; |
||
389 | htheta = new TH1F("htheta", "htheta", 100, 0.0, pi/2.0); |
||
390 | hcostheta = (TH1F*)gROOT->FindObject("hcostheta"); if(hcostheta) delete hcostheta; |
||
391 | hcostheta = new TH1F("hcostheta", "hcostheta", 100, 0.0, 1.0); |
||
392 | hl = (TH1F*)gROOT->FindObject("hl"); if(hl) delete hl; |
||
393 | hl = new TH1F("hl", "hl", 100, 0.0, 1.0); |
||
394 | hm = (TH1F*)gROOT->FindObject("hm"); if(hm) delete hm; |
||
395 | hm = new TH1F("hm", "hm", 100, 0.0, 1.0); |
||
396 | hn = (TH1F*)gROOT->FindObject("hn"); if(hn) delete hn; |
||
397 | hn = new TH1F("hn", "hn", 100, 0.0, 1.0); |
||
25 | f9daq | 398 | |
73 | f9daq | 399 | |
400 | //detector->Init(); |
||
401 | if (show_3d) detector->Draw(draw_width); |
||
402 | |||
84 | f9daq | 403 | double b = parameters.getB(); |
73 | f9daq | 404 | double offset = (parameters._plateOn ? parameters._plateWidth : 0); |
405 | |||
406 | for(int i = 0; i < NN; i++) { |
||
407 | |||
84 | f9daq | 408 | double rx = CENTER.x() - offset; |
409 | double ry = rand.Uniform(-b/2.0, b/2.0); |
||
410 | double rz = rand.Uniform(-b/2.0, b/2.0); |
||
73 | f9daq | 411 | |
84 | f9daq | 412 | double phi = rand.Uniform(0.0, 2.0*pi); |
73 | f9daq | 413 | //double theta_max_rad = TMath::Cos(17.0*pi/180.0); |
414 | //rtheta = TMath::ACos((rand.Uniform(theta_min_rad, 1.0))); |
||
84 | f9daq | 415 | double theta = TMath::ACos((rand.Uniform(theta_min_rad, theta_max_rad))); |
73 | f9daq | 416 | |
84 | f9daq | 417 | double rl = TMath::Cos(theta); |
418 | double rm = TMath::Sin(theta)*TMath::Sin(phi); |
||
419 | double rn = TMath::Sin(theta)*TMath::Cos(phi); |
||
73 | f9daq | 420 | |
421 | if(show_rand) { |
||
84 | f9daq | 422 | htheta->Fill(theta); |
423 | hcostheta->Fill( TMath::Cos(theta) ); |
||
424 | hphi->Fill(phi); |
||
425 | hl->Fill(rl); |
||
426 | hm->Fill(rm); |
||
427 | hn->Fill(rn); |
||
73 | f9daq | 428 | } |
429 | |||
430 | CRay *ray0 = new CRay(rx, ry, rz, rl, rm, rn); |
||
84 | f9daq | 431 | TVector3 k(ray0->GetK()); |
432 | TVector3 polarization(k.Orthogonal()); |
||
433 | polarization.Unit(); |
||
434 | polarization.Rotate(phi, k); |
||
435 | ray0->setPolarization(polarization); |
||
436 | CRay ray1; |
||
73 | f9daq | 437 | |
438 | if(i < show_rays) { |
||
439 | detector->Propagate(*ray0, ray1, show_3d); |
||
440 | } |
||
441 | else { |
||
442 | detector->Propagate(*ray0, ray1, 0); |
||
443 | } |
||
444 | |||
84 | f9daq | 445 | //delete ray1; |
73 | f9daq | 446 | delete ray0; |
447 | } |
||
448 | |||
449 | if(show_rand) { |
||
450 | TCanvas *c2rand = (TCanvas*)gROOT->FindObject("c2rand"); |
||
451 | if(!c2rand) c2rand = new TCanvas("c2rand", "Random", 750, 550, 700, 700); |
||
452 | else c2rand->Clear(); |
||
453 | c2rand->Divide(2,3); |
||
454 | |||
455 | c2rand->cd(1); hphi->Draw(); |
||
456 | c2rand->cd(3); htheta->Draw(); |
||
457 | c2rand->cd(5); hcostheta->Draw(); |
||
458 | c2rand->cd(2); hl->Draw(); |
||
459 | c2rand->cd(4); hm->Draw(); |
||
460 | c2rand->cd(6); hn->Draw(); |
||
461 | } |
||
462 | |||
463 | double acceptance = 0.0; |
||
464 | /* |
||
70 | f9daq | 465 | if( !(parameters.getPlateOn()) ) |
466 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN; |
||
467 | else |
||
468 | acceptance = (detector->GetHActive())->GetEntries() / (detector->GetHPlate())->GetEntries(); |
||
73 | f9daq | 469 | */ |
70 | f9daq | 470 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN; |
73 | f9daq | 471 | return acceptance; |
70 | f9daq | 472 | } |
473 | |||
474 | // Beamtest distribution |
||
475 | // with fixed theta and phi in interval phiMin, phiMax |
||
73 | f9daq | 476 | double beamtest(CDetector *detector, DetectorParameters& parameters, |
84 | f9daq | 477 | int NN, double theta, double phiMin, double phiMax, int show_rays, int show_rand) |
70 | f9daq | 478 | { |
73 | f9daq | 479 | double pi = 3.14159265358979312; |
480 | theta *= pi/180.0; |
||
481 | if(theta < MARGIN) theta = MARGIN; |
||
482 | phiMin *= pi/180.0; |
||
483 | phiMax *= pi/180.0; |
||
70 | f9daq | 484 | |
73 | f9daq | 485 | TDatime now; |
84 | f9daq | 486 | TRandom2 rand; |
73 | f9daq | 487 | rand.SetSeed(now.Get()); |
488 | double rx, ry, rz, rl, rm, rn; |
||
84 | f9daq | 489 | double phi; |
70 | f9daq | 490 | |
73 | f9daq | 491 | TH1F *hphi, *htheta, *hcostheta, *hl, *hm, *hn; |
492 | hphi = (TH1F*)gROOT->FindObject("hphi"); if(hphi) delete hphi; |
||
493 | hphi = new TH1F("hphi", "hphi", 100, -pi, pi); |
||
494 | htheta = (TH1F*)gROOT->FindObject("htheta"); if(htheta) delete htheta; |
||
495 | htheta = new TH1F("htheta", "htheta", 100, 0.0, pi/2.0); |
||
496 | hcostheta = (TH1F*)gROOT->FindObject("hcostheta"); if(hcostheta) delete hcostheta; |
||
497 | hcostheta = new TH1F("hcostheta", "hcostheta", 100, 0.0, 1.0); |
||
498 | hl = (TH1F*)gROOT->FindObject("hl"); if(hl) delete hl; |
||
499 | hl = new TH1F("hl", "hl", 100, 0.0, 1.0); |
||
500 | hm = (TH1F*)gROOT->FindObject("hm"); if(hm) delete hm; |
||
501 | hm = new TH1F("hm", "hm", 100, 0.0, 1.0); |
||
502 | hn = (TH1F*)gROOT->FindObject("hn"); if(hn) delete hn; |
||
503 | hn = new TH1F("hn", "hn", 100, 0.0, 1.0); |
||
504 | |||
505 | //detector->Init(); |
||
506 | if (show_3d) detector->Draw(draw_width); |
||
507 | |||
508 | double b = parameters.getB(); |
||
509 | double offset = (parameters._plateOn ? parameters._plateWidth : 0); |
||
510 | |||
511 | for(int i = 0; i < NN; i++) { |
||
512 | |||
513 | rx = CENTER.x() - offset; |
||
514 | ry = rand.Uniform(-b/2.0, b/2.0); |
||
515 | rz = rand.Uniform(-b/2.0, b/2.0); |
||
516 | |||
84 | f9daq | 517 | phi = rand.Uniform(phiMin, phiMax); |
73 | f9daq | 518 | //double theta_max_rad = TMath::Cos(17.0*pi/180.0); |
519 | //rtheta = TMath::ACos((rand.Uniform(theta_min_rad, 1.0))); |
||
520 | //rtheta = TMath::ACos((rand.Uniform(theta_min_rad, theta_max_rad))); |
||
521 | |||
522 | rl = TMath::Cos(theta); |
||
84 | f9daq | 523 | rm = TMath::Sin(theta)*TMath::Sin(phi); |
524 | rn = TMath::Sin(theta)*TMath::Cos(phi); |
||
73 | f9daq | 525 | |
526 | if(show_rand) { |
||
527 | //htheta->Fill(rtheta); |
||
528 | //hcostheta->Fill( TMath::Cos(rtheta) ); |
||
84 | f9daq | 529 | hphi->Fill(phi); |
73 | f9daq | 530 | hl->Fill(rl); |
531 | hm->Fill(rm); |
||
532 | hn->Fill(rn); |
||
533 | } |
||
534 | |||
535 | CRay *ray0 = new CRay(rx, ry, rz, rl, rm, rn); |
||
536 | // inital polarizaton |
||
84 | f9daq | 537 | TVector3 k(ray0->GetK()); |
538 | TVector3 polarization(k.Orthogonal()); |
||
539 | polarization.Unit(); |
||
540 | polarization.Rotate(phi, k); |
||
73 | f9daq | 541 | ray0->setPolarization(polarization); |
84 | f9daq | 542 | CRay ray1; |
73 | f9daq | 543 | |
544 | if(i < show_rays) { |
||
545 | detector->Propagate(*ray0, ray1, show_3d); |
||
546 | } |
||
547 | else { |
||
548 | detector->Propagate(*ray0, ray1, 0); |
||
549 | } |
||
550 | |||
84 | f9daq | 551 | //delete ray1; |
73 | f9daq | 552 | delete ray0; |
553 | } |
||
554 | |||
555 | if(show_rand) { |
||
556 | TCanvas *c2rand = (TCanvas*)gROOT->FindObject("c2rand"); |
||
557 | if(!c2rand) c2rand = new TCanvas("c2rand", "Random", 750, 550, 700, 700); |
||
558 | else c2rand->Clear(); |
||
559 | c2rand->Divide(2,3); |
||
560 | |||
561 | c2rand->cd(1); hphi->Draw(); |
||
562 | c2rand->cd(3); htheta->Draw(); |
||
563 | c2rand->cd(5); hcostheta->Draw(); |
||
564 | c2rand->cd(2); hl->Draw(); |
||
565 | c2rand->cd(4); hm->Draw(); |
||
566 | c2rand->cd(6); hn->Draw(); |
||
567 | } |
||
568 | |||
569 | double acceptance = 0.0; |
||
570 | /* |
||
70 | f9daq | 571 | if( !(parameters.getPlateOn()) ) |
572 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN; |
||
573 | else |
||
574 | acceptance = (detector->GetHActive())->GetEntries() / (detector->GetHPlate())->GetEntries(); |
||
73 | f9daq | 575 | */ |
70 | f9daq | 576 | acceptance = (detector->GetHActive())->GetEntries() / (double)NN; |
73 | f9daq | 577 | return acceptance; |
25 | f9daq | 578 | } |