Rev 70 | Rev 72 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
25 | f9daq | 1 | #ifndef CVODNIK_H |
2 | #define CVODNIK_H |
||
3 | |||
4 | #include "TROOT.h" |
||
5 | #include "TVector3.h" |
||
6 | #include "TMath.h" |
||
7 | #include "TPolyLine3D.h" |
||
8 | #include "TRandom.h" |
||
9 | #include "TDatime.h" |
||
10 | #include "TH1F.h" |
||
11 | #include "TH2F.h" |
||
12 | #include "TColor.h" |
||
13 | |||
14 | |||
15 | |||
16 | #define MARGIN 1.0e-6 |
||
17 | #define DEGREE 180.0/3.14159265358979312 |
||
54 | f9daq | 18 | #define MAX_REFLECTIONS 19 |
25 | f9daq | 19 | |
54 | f9daq | 20 | |
25 | f9daq | 21 | using namespace TMath; |
22 | |||
23 | const double c_reflectivity = 0.96; |
||
24 | const int REFRACTION = 1; |
||
25 | const int REFLECTION = 2; |
||
26 | const int TOTAL = 3; |
||
54 | f9daq | 27 | const int ABSORBED = -2; |
25 | f9daq | 28 | const TVector3 CENTER(-2.0, 0.0, 0.0); |
29 | const int nch = 50; // number of "channels" used as number of bins in histograms |
||
30 | |||
54 | f9daq | 31 | enum Fate {missed=0, hitExit=1, refracted=-1, enter=2, noreflection=-2, backreflected=-3, rays=3, absorbed=4}; |
25 | f9daq | 32 | |
33 | int dbg = 0; |
||
34 | |||
35 | //================================================================================= |
||
36 | // zarek (premica) |
||
37 | class CRay |
||
38 | { |
||
39 | public: |
||
40 | CRay() : |
||
41 | r(TVector3(0,0,0)), |
||
42 | n(TVector3(1,0,0)), |
||
43 | p(TVector3(0,1,0)), |
||
44 | color(1) |
||
45 | {}; |
||
46 | CRay(TVector3 r0, TVector3 n0) : |
||
47 | r(r0), |
||
48 | n(n0.Unit()), |
||
49 | p(TVector3(0,1,0)), |
||
50 | color(1) |
||
51 | {}; |
||
52 | CRay(double x0, double y0, double z0, double l0, double m0, double n0) : |
||
53 | r(TVector3(x0,y0,z0)), |
||
54 | n(TVector3(l0,m0,n0).Unit()), |
||
55 | p(TVector3(0,1,0)), |
||
56 | color(1) |
||
57 | {}; |
||
58 | |||
59 | void Set(TVector3 r0, TVector3 n0); |
||
60 | //void Set(double x0, double y0, double z0, double l0, double m0, double n0); |
||
61 | void SetColor(int c){color = c;}; |
||
62 | void SetPolarization(TVector3 p0) {p = p0.Unit();}; |
||
63 | |||
64 | //inline CRay & operator = (const CRay &); |
||
65 | |||
66 | TVector3 GetR() const {return r;}; |
||
67 | TVector3 GetN() const {return n;}; |
||
68 | TVector3 GetP() const {return p;}; |
||
69 | |||
70 | void Print(); |
||
71 | void Draw(); |
||
72 | void Draw(double x_from, double x_to); |
||
73 | void DrawS(double x_from, double t); |
||
74 | |||
75 | private: |
||
76 | TVector3 r; |
||
77 | TVector3 n; |
||
78 | TVector3 p; //r = point on line, n = normal, p = polarization |
||
79 | int color; |
||
80 | }; |
||
81 | //================================================================================= |
||
82 | |||
83 | |||
84 | //================================================================================= |
||
85 | // ravnina, definirana in omejena s 4 tockami na njej (stirikotni poligon) |
||
86 | // zanasam se na taksno definicijo: (normala kaze noter) |
||
87 | // r1----->r2 |
||
88 | // ^ | |
||
89 | // | | |
||
90 | // | | |
||
91 | // | � |
||
92 | // r0<-----r3 |
||
93 | class CPlane4 |
||
94 | { |
||
95 | |||
96 | public: |
||
97 | CPlane4(); |
||
98 | CPlane4(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4); |
||
99 | CPlane4(TVector3 *vr); |
||
100 | void Set(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4); |
||
101 | void Set(TVector3 *vr) {Set(vr[0], vr[1], vr[2], vr[3]);}; |
||
102 | void FlipN(){n = -n;}; |
||
103 | |||
104 | int GetIntersection(TVector3 *vec, CRay ray); |
||
105 | int IsInTri(TVector3 vec, TVector3 e1, TVector3 e2, double); |
||
106 | int IsVectorIn(TVector3 vec); |
||
107 | int TestIntersection(CRay in); // ray in & ??? plane |
||
108 | int TestIntersection(TVector3 *vec, CRay in); // plane defined with normal vec and ray in |
||
109 | |||
110 | TVector3 GetN() {return n;}; |
||
111 | |||
112 | void Print(); |
||
113 | void Draw(int color = 1, int width = 1); |
||
114 | |||
115 | private: |
||
116 | TVector3 r[4], n; |
||
117 | double A, B, C, D; |
||
118 | TVector3 edge[4]; // vektorji stranic |
||
119 | double angle_r[4]; // koti ob posameznem vogalu |
||
120 | }; |
||
121 | //================================================================================= |
||
122 | |||
123 | |||
124 | //================================================================================= |
||
125 | // ravna opticna povrsina: refractor, zrcalo ali povrsina s totalnim odbojem |
||
126 | #define SURF_DUMMY 0 |
||
127 | #define SURF_REFRA 1 |
||
128 | #define SURF_REFLE 2 |
||
129 | #define SURF_TOTAL 3 |
||
130 | //#define SURF_TOTAL 1 |
||
131 | #define SURF_IMPER 4 |
||
132 | //#define SURF_DIFUS 5 |
||
133 | |||
134 | class CSurface : public CPlane4 |
||
135 | { |
||
136 | |||
137 | public: |
||
138 | CSurface(int type0 = 0); |
||
139 | CSurface(int type0, TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4, |
||
140 | double n10, double n20, double reflectivity); |
||
141 | CSurface(int type0, TVector3 *vr, double n10, double n20, double reflectivity); |
||
142 | |||
143 | void SetV(TVector3 *vr){CPlane4::Set(vr);}; |
||
144 | void SetType(int type0){type = type0;}; |
||
145 | void SetIndex(double n10, double n20); |
||
146 | void SetReflection(double reflectivity){reflection = reflectivity;}; |
||
147 | void SetFresnel(int f = 1) {fresnel = f;}; |
||
148 | |||
149 | void Set(int type0, TVector3 *vr, double n10, double n20, double reflectivity) |
||
150 | {type = type0; CPlane4::Set(vr); SetIndex(n10, n20); reflection = reflectivity;}; |
||
151 | void Set(int type0, TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4, double n10, double n20, double reflectivity) |
||
152 | {type = type0; CPlane4::Set(r1, r2, r3, r4); SetIndex(n10, n20); reflection = reflectivity;}; |
||
153 | |||
154 | int PropagateRay(CRay in, CRay *out, TVector3 *intersection); |
||
155 | |||
156 | double N1_N2(int sign) { return ((sign > 0) ? n1/n2 : n2/n1);}; |
||
157 | |||
158 | void Print(){printf("Type = %d\n", type); CPlane4::Print();}; |
||
159 | |||
160 | private: |
||
161 | int type; //0 = dummy; 1 = refractor; 2 = reflector; 3 = total reflection |
||
162 | double n1, n2, n1_n2; //index of refraction, n1 @ +normal, n2 @ -normal |
||
163 | double reflection; // odbojnost stranic |
||
164 | TRandom rand; // za racunanje verjetnosti odboja od zrcala |
||
165 | double cosTtotal; //cosinus mejnega kota totalnega odboja za dana n1 in n2 |
||
166 | |||
167 | int fresnel; // ali naj uposteva Fresnelove enacbe |
||
168 | }; |
||
169 | //================================================================================= |
||
170 | |||
171 | |||
172 | //================================================================================= |
||
173 | // +------- n1 |
||
174 | // | ------- |
||
175 | // | n2 ----+ |
||
176 | // | | |
||
177 | // 0| M*SiPM | SiPM |
||
178 | // | | |
||
179 | // | ----+ |
||
180 | // | ------R |
||
181 | // +------- |
||
182 | // <-------- d -------> |
||
183 | // |
||
184 | |||
185 | |||
54 | f9daq | 186 | |
25 | f9daq | 187 | int RCol(int col, int solid); |
188 | |||
189 | |||
190 | class DetectorParameters |
||
191 | { |
||
192 | public: |
||
193 | DetectorParameters(double a, double b, double d, double active, double n1, double n2, double n3, TVector3 gap): |
||
194 | _a(a), |
||
195 | _b(b), |
||
196 | _d(d), |
||
197 | _active(active), |
||
198 | _n1(n1), |
||
199 | _n2(n2), |
||
200 | _n3(n3), |
||
201 | _gap(gap), |
||
70 | f9daq | 202 | _fresnel(1), |
203 | _guideOn(1), |
||
204 | offsetY(b/2.0), |
||
205 | offsetZ(b/2.0), |
||
206 | _plateOn(1), |
||
25 | f9daq | 207 | _plateWidth(1), |
208 | _glassOn(0), |
||
70 | f9daq | 209 | _glassD(0) |
25 | f9daq | 210 | {}; |
211 | DetectorParameters(double a, double b, double d): |
||
212 | _a(a), |
||
213 | _b(b), |
||
214 | _d(d), |
||
215 | _active(a), |
||
216 | _n1(1.0), |
||
70 | f9daq | 217 | _n2(1.53), |
218 | _n3(1.46), |
||
25 | f9daq | 219 | _gap(TVector3(0,0,0)), |
220 | _fresnel(1), |
||
221 | _guideOn(1), |
||
70 | f9daq | 222 | offsetY(b/2.0), |
223 | offsetZ(b/2.0), |
||
54 | f9daq | 224 | _plateOn(1), |
70 | f9daq | 225 | _plateWidth(1), |
226 | _glassOn(0), |
||
227 | _glassD(0) |
||
25 | f9daq | 228 | {}; |
229 | ~DetectorParameters() {}; |
||
230 | |||
70 | f9daq | 231 | void setGuide(double a, double b, double d) { |
25 | f9daq | 232 | _a = a; |
233 | _b = b; |
||
70 | f9daq | 234 | //_M = b/a; |
25 | f9daq | 235 | _d = d; |
236 | }; |
||
237 | void setGap(double x, double y, double z) { _gap = TVector3(x,y,z); }; |
||
238 | void setFresnel(int fresnel) { _fresnel = fresnel; }; |
||
239 | void setGlass(int glassOn, double glassD) { _glassOn = glassOn; _glassD = glassD; }; |
||
240 | void setGuideOn(int guideOn) { _guideOn = guideOn; }; |
||
241 | void setPlate(int plateOn, double plateWidth) { _plateOn = plateOn; _plateWidth = plateWidth; }; |
||
70 | f9daq | 242 | void setIndices(double n1, double n2, double n3) { _n1 = n1; _n2 = n2; _n3 = n3; }; |
25 | f9daq | 243 | |
70 | f9daq | 244 | double getLightYield() { return ( Power(_b,2)/Power(_active,2)); }; |
245 | double getM() { return (_b/_a); }; |
||
25 | f9daq | 246 | double getA() {return _a;}; |
247 | double getB() {return _b;}; |
||
248 | double getD() {return _d;}; |
||
249 | double getN1() {return _n1; }; |
||
250 | double getN2() {return _n2;}; |
||
251 | double getN3() {return _n3;}; |
||
252 | double getActive() {return _active;}; |
||
253 | TVector3 getGap() {return _gap;}; |
||
254 | double getPlateWidth() {return _plateWidth; }; |
||
255 | int getFresnel() { return _fresnel; }; |
||
256 | int getGlassOn() { return _glassOn; }; |
||
257 | double getGlassD() { return _glassD; }; |
||
258 | int getGuideOn() { return _guideOn; }; |
||
259 | int getPlateOn() { return _plateOn; }; |
||
54 | f9daq | 260 | double getOffsetY() { return offsetY; }; |
261 | double getOffsetZ() { return offsetZ; }; |
||
25 | f9daq | 262 | |
263 | private: |
||
264 | double _a; |
||
265 | double _b; |
||
266 | double _d; |
||
267 | double _active; |
||
268 | double _n1; |
||
269 | double _n2; |
||
270 | double _n3; |
||
271 | TVector3 _gap; |
||
70 | f9daq | 272 | |
273 | int _fresnel; |
||
274 | |||
275 | int _guideOn; |
||
54 | f9daq | 276 | double offsetY; |
277 | double offsetZ; |
||
25 | f9daq | 278 | |
70 | f9daq | 279 | int _plateOn; |
280 | double _plateWidth; |
||
281 | |||
25 | f9daq | 282 | int _glassOn; |
283 | double _glassD; |
||
284 | |||
285 | }; |
||
286 | |||
287 | class Guide |
||
288 | { |
||
289 | public: |
||
290 | Guide(TVector3 center0, DetectorParameters& parameters); |
||
291 | ~Guide() { |
||
54 | f9daq | 292 | for (int jk=0; jk<6; jk++) delete s_side[jk]; |
293 | delete hfate; |
||
294 | delete hnodb_all; |
||
295 | delete hnodb_exit; |
||
296 | delete hin; |
||
297 | delete hout; |
||
25 | f9daq | 298 | } |
299 | |||
300 | Fate PropagateRay(CRay in, CRay *out, int *n_points, TVector3 *points); |
||
301 | |||
302 | double getD() { return _d; } |
||
303 | double getN1() { return n1; }; |
||
304 | double getN2() { return n2; }; |
||
305 | double getN3() { return n3; }; |
||
306 | TH1F* GetHFate() const {return hfate;}; |
||
307 | TH1F* GetHNOdb_all() const {return hnodb_all;}; |
||
308 | TH1F* GetHNOdb_exit() const {return hnodb_exit;}; |
||
309 | TH2F* GetHIn() const {return hin;}; |
||
310 | TH2F* GetHOut() const {return hout;}; |
||
311 | int GetExitHits() {return (int)hfate->GetBinContent(5);}; |
||
312 | int GetEnteranceHits() {return (int)hfate->GetBinContent(6);}; |
||
313 | void GetVFate(int *out); |
||
54 | f9daq | 314 | int GetMAXODB() const {return MAX_REFLECTIONS;}; |
25 | f9daq | 315 | |
316 | void Draw(int color = 1, int width = 1); |
||
317 | void DrawSkel(int color = 1, int width = 1); |
||
318 | |||
319 | private: |
||
320 | Fate fate; |
||
321 | double _d; // parameters |
||
322 | double n1, n2, n3; // refractive index: n1 above entry surface, n2 inside, n3 after exit |
||
323 | double _r; |
||
324 | double absorption; |
||
325 | double A; |
||
326 | TRandom rand; // for material absorption |
||
327 | CSurface *s_side[6]; |
||
328 | TVector3 center, vodnik_edge[8]; |
||
329 | |||
330 | TH1F *hfate, *hnodb_all, *hnodb_exit; |
||
331 | TH2F *hin, *hout; |
||
332 | }; |
||
333 | //================================================================================= |
||
334 | |||
335 | //=============================================================================================================================== <<<<<<<< |
||
336 | // ravnina - krog |
||
337 | class CPlaneR |
||
338 | { |
||
339 | |||
340 | public: |
||
341 | CPlaneR(TVector3 c, TVector3 n0, double R0) |
||
342 | {center = c; n = n0; _r = R0;}; |
||
343 | |||
344 | void Set(TVector3 c, TVector3 n0, double R0) |
||
345 | {center = c; n = n0; _r = R0;}; |
||
346 | |||
347 | int TestIntersection(TVector3 *vec, CRay in); |
||
348 | |||
349 | void Draw(int color = 1, int NN = 32); |
||
350 | |||
351 | private: |
||
352 | TVector3 n, center; |
||
353 | double _r; |
||
354 | }; |
||
355 | //================================================================================= |
||
356 | |||
357 | class Plate |
||
358 | { |
||
359 | public: |
||
360 | Plate(DetectorParameters& parameters); |
||
54 | f9daq | 361 | ~Plate() { |
362 | for (int jk=0; jk<6; jk++) delete sides[jk]; // the same, needs solution |
||
25 | f9daq | 363 | }; |
364 | |||
365 | void draw(int color, int width); |
||
366 | void drawSkel(int color, int width); |
||
54 | f9daq | 367 | Fate propagateRay(CRay, CRay*, int*, TVector3*); |
25 | f9daq | 368 | |
369 | private: |
||
370 | TVector3 plate_edge[8]; |
||
371 | CSurface *sides[6]; |
||
372 | }; |
||
373 | |||
374 | // ================================================================================ |
||
375 | |||
376 | class CDetector |
||
377 | { |
||
378 | public: |
||
379 | CDetector(TVector3 center0, DetectorParameters& parameters); |
||
380 | ~CDetector() { |
||
381 | delete glass; |
||
382 | delete glass_circle; |
||
383 | delete hglass; |
||
384 | delete active; |
||
385 | delete hactive; |
||
386 | delete hlaser; |
||
387 | delete detector; |
||
388 | delete hdetector; |
||
389 | delete guide; |
||
390 | delete plate; |
||
391 | delete histoPlate; |
||
392 | //delete window; |
||
393 | //delete window_circle; |
||
394 | //delete hwindow; |
||
395 | } |
||
396 | |||
397 | //void SetLGType(int in = SURF_REFRA, int side = SURF_REFRA, int out = SURF_REFRA) |
||
398 | // {type_in = in; type_side = side; type_out = out;}; |
||
399 | |||
400 | /* void SetLG(double SiPM0, double M0, double d0, double n10, double n20, double n30, double R0) |
||
401 | { SiPM=SiPM0; |
||
402 | M=M0; |
||
403 | d=d0; |
||
404 | n1=n10; |
||
405 | n2=n20; |
||
406 | n3=n30; |
||
407 | R=R0; |
||
408 | }; */ |
||
409 | //void SetR(double R0) {R = R0;}; |
||
410 | //void SetGlass(int glass_on0, double glass_d0) |
||
411 | //{glass_on = glass_on0; glass_d = glass_d0;}; |
||
412 | //void SetGap(double x_gap0, double y_gap0, double z_gap0) |
||
413 | //{x_gap = x_gap0; y_gap = y_gap0; z_gap = z_gap0;}; |
||
414 | void SetRCol(int in, int lg, int out, int gla) |
||
415 | {col_in = in; col_lg = lg; col_out = out; col_rgla = gla;}; |
||
416 | void SetDCol(int LG0, int glass0, int active0) |
||
417 | {col_LG = LG0; col_glass = glass0; col_active = active0;}; |
||
418 | //void SetFresnel(int b) |
||
419 | //{fresnel = b;}; |
||
420 | //void SetAbsorption(int b, double A0) |
||
421 | //{absorption = b; A = A0;}; |
||
422 | //void SetWindow(double wR, double d0) {window_R = wR; window_d = d0;}; |
||
423 | //void SetGuideOn(int b) |
||
424 | //{guide_on = b;}; |
||
425 | |||
426 | //void Init(); |
||
427 | |||
428 | int Propagate(CRay, CRay*, int); |
||
429 | |||
430 | Guide* GetLG() const {return guide;}; |
||
431 | //TH2F* GetHWindow() const {return hwindow;}; |
||
432 | TH2F* GetHGlass() const {return hglass;}; |
||
433 | TH2F* GetHActive() const {return hactive;}; |
||
434 | TH2F* GetHLaser() const {return hlaser;}; |
||
435 | TH2F* GetHDetector() const {return hdetector;}; |
||
70 | f9daq | 436 | TH2F* GetHPlate() const {return histoPlate;}; |
25 | f9daq | 437 | |
438 | //double GetSiPM() const {return SiPM;}; |
||
439 | //double GetM() const {return M;}; |
||
440 | //double GetD() const {return d;}; |
||
441 | //double GetR() const {return R;}; |
||
442 | //TVector3 GetVGap() const {return (TVector3(x_gap, y_gap, z_gap));}; |
||
443 | //int IsGlass() {return glass_on;}; |
||
71 | f9daq | 444 | //double getGlassWidth() {return glass_d;}; |
25 | f9daq | 445 | //double GetWindowR() {return window_R;}; |
446 | //double GetWindowD() {return window_d;}; |
||
447 | |||
448 | void Draw(int width = 2); |
||
449 | |||
450 | private: |
||
451 | Fate fate; |
||
452 | TVector3 center; |
||
453 | |||
454 | //int type_in, type_side, type_out; |
||
455 | //double SiPM, M, d, n1, n2, n3, R; |
||
456 | //double detectorActive; |
||
457 | |||
458 | |||
459 | int glass_on; |
||
460 | double glass_d; |
||
461 | CSurface *glass; |
||
462 | CPlaneR *glass_circle; |
||
463 | TH2F *hglass; |
||
464 | |||
465 | //double x_gap, y_gap, z_gap; |
||
466 | CPlane4 *active; |
||
467 | TH2F *hactive, *hlaser; |
||
468 | |||
469 | CPlane4 *detector; |
||
470 | TH2F *hdetector; |
||
471 | |||
472 | int col_in, col_lg, col_out, col_rgla; |
||
473 | int col_LG, col_glass, col_active; |
||
474 | |||
475 | //int fresnel, absorption; |
||
476 | //double A; |
||
477 | |||
478 | int guide_on; |
||
479 | |||
480 | //double window_R, window_d; |
||
481 | //CSurface *window; |
||
482 | //CPlaneR *window_circle; |
||
483 | //TH2F *hwindow; |
||
484 | |||
485 | Guide *guide; |
||
486 | Plate *plate; |
||
487 | |||
488 | double _plateWidth; |
||
489 | int _plateOn; |
||
490 | |||
491 | TH2F *histoPlate; |
||
54 | f9daq | 492 | |
493 | double offsetY; |
||
494 | double offsetZ; |
||
25 | f9daq | 495 | }; |
496 | |||
497 | |||
498 | |||
499 | //================================================================================= |
||
500 | #endif |