Subversion Repositories f9daq

Rev

Rev 25 | Rev 70 | 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),
202
  _plateWidth(1),
203
  _fresnel(1),
204
  _glassOn(0),
205
  _glassD(0),
206
  _guideOn(1),
54 f9daq 207
  _plateOn(1),
208
  offsetY(2.5),
209
  offsetZ(2.5)
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),
217
  _n2(1.50),
218
  _n3(1.50),
219
  _gap(TVector3(0,0,0)),
220
  _plateWidth(1),
221
  _fresnel(1),
222
  _glassOn(0),
223
  _glassD(0),
224
  _guideOn(1),
54 f9daq 225
  _plateOn(1),
226
  offsetY(2.5),
227
  offsetZ(2.5)
25 f9daq 228
  {};
229
  ~DetectorParameters() {};
230
 
231
  void setGuide(double a, double b, double d, double n1, double n2, double n3) {
232
    _a = a;
233
    _b = b;
234
    _d = d;
235
    _n1 = n1;
236
    _n2 = n2;
237
    _n3 = n3;
238
    };
239
  void setGuide(double a, double M, double d) {
240
    _a = a;
241
    _b = M*a;
242
    _d = d;
243
    };
244
  void setGap(double x, double y, double z) { _gap = TVector3(x,y,z); };
245
  void setFresnel(int fresnel) { _fresnel = fresnel; };
246
  void setGlass(int glassOn, double glassD) { _glassOn = glassOn; _glassD = glassD; };
247
  void setGuideOn(int guideOn) { _guideOn = guideOn; };
248
  void setPlate(int plateOn, double plateWidth) { _plateOn = plateOn; _plateWidth = plateWidth; };
249
 
250
  double getM() { return _b/_a; };
251
  double getA() {return _a;};
252
  double getB() {return _b;};
253
  double getD() {return _d;};
254
  double getN1() {return _n1; };
255
  double getN2() {return _n2;};
256
  double getN3() {return _n3;};
257
  double getActive() {return _active;};
258
  TVector3 getGap() {return _gap;};
259
  double getPlateWidth() {return _plateWidth; };
260
  int getFresnel() { return _fresnel; };
261
  int getGlassOn() { return _glassOn; };
262
  double getGlassD() { return _glassD; };
263
  int getGuideOn() { return _guideOn; };
264
  int getPlateOn() { return _plateOn; };
54 f9daq 265
  double getOffsetY() { return offsetY; };
266
  double getOffsetZ() { return offsetZ; };
25 f9daq 267
 
268
private:
269
  double _a;
270
  double _b;
271
  double _d;
272
  double _active;
273
  double _n1;
274
  double _n2;
275
  double _n3;
276
  TVector3 _gap;
277
  double _plateWidth;
54 f9daq 278
  double offsetY;
279
  double offsetZ;
25 f9daq 280
 
281
  int _fresnel;
282
  int _glassOn;
283
  double _glassD;
284
  int _guideOn;
285
  int _plateOn;
286
 
287
};
288
 
289
class Guide
290
{
291
public:
292
        Guide(TVector3 center0, DetectorParameters& parameters);
293
        ~Guide() {
54 f9daq 294
          for (int jk=0; jk<6; jk++) delete s_side[jk];
295
          delete hfate;
296
          delete hnodb_all;
297
          delete hnodb_exit;
298
          delete hin;
299
          delete hout;
25 f9daq 300
        }
301
 
302
        Fate PropagateRay(CRay in, CRay *out, int *n_points, TVector3 *points);
303
 
304
        double getD() { return _d; }
305
        double getN1() { return n1; };
306
        double getN2() { return n2; };
307
        double getN3() { return n3; };
308
        TH1F* GetHFate() const {return hfate;};
309
        TH1F* GetHNOdb_all() const {return hnodb_all;};
310
        TH1F* GetHNOdb_exit() const {return hnodb_exit;};
311
        TH2F* GetHIn() const {return hin;};
312
        TH2F* GetHOut() const {return hout;};
313
        int GetExitHits() {return (int)hfate->GetBinContent(5);};
314
        int GetEnteranceHits() {return (int)hfate->GetBinContent(6);};
315
        void GetVFate(int *out);
54 f9daq 316
        int GetMAXODB() const {return MAX_REFLECTIONS;};
25 f9daq 317
 
318
        void Draw(int color = 1, int width = 1);
319
        void DrawSkel(int color = 1, int width = 1);
320
 
321
private:
322
  Fate fate;
323
        double _d; // parameters
324
        double n1, n2, n3; // refractive index: n1 above entry surface, n2 inside, n3 after exit
325
        double _r;
326
        double absorption;
327
        double A;
328
        TRandom rand; // for material absorption
329
        CSurface *s_side[6];
330
        TVector3 center, vodnik_edge[8];
331
 
332
        TH1F *hfate, *hnodb_all, *hnodb_exit;
333
        TH2F *hin, *hout;
334
};
335
//=================================================================================
336
 
337
//=============================================================================================================================== <<<<<<<<
338
// ravnina - krog
339
class CPlaneR
340
{
341
 
342
        public:
343
                CPlaneR(TVector3 c, TVector3 n0, double R0)
344
                {center = c; n = n0; _r = R0;};
345
 
346
                void Set(TVector3 c, TVector3 n0, double R0)
347
                {center = c; n = n0; _r = R0;};
348
 
349
                int TestIntersection(TVector3 *vec, CRay in);
350
 
351
                void Draw(int color = 1, int NN = 32);
352
 
353
        private:
354
                TVector3 n, center;
355
                double _r;
356
};
357
//=================================================================================
358
 
359
class Plate
360
{
361
public:
362
  Plate(DetectorParameters& parameters);
54 f9daq 363
  ~Plate() {
364
    for (int jk=0; jk<6; jk++) delete sides[jk]; // the same, needs solution
25 f9daq 365
  };
366
 
367
  void draw(int color, int width);
368
  void drawSkel(int color, int width);
54 f9daq 369
  Fate propagateRay(CRay, CRay*, int*, TVector3*);
25 f9daq 370
 
371
private:
372
        TVector3 plate_edge[8];
373
        CSurface *sides[6];
374
};
375
 
376
// ================================================================================
377
 
378
class CDetector
379
{
380
public:
381
        CDetector(TVector3 center0, DetectorParameters& parameters);
382
        ~CDetector() {
383
          delete glass;
384
          delete glass_circle;
385
          delete hglass;
386
    delete active;
387
          delete hactive;
388
          delete hlaser;
389
          delete detector;
390
          delete hdetector;
391
          delete guide;
392
          delete plate;
393
          delete histoPlate;
394
          //delete window;
395
          //delete window_circle;
396
          //delete hwindow;
397
        }
398
 
399
        //void SetLGType(int in = SURF_REFRA, int side = SURF_REFRA, int out = SURF_REFRA)
400
        //      {type_in = in; type_side = side; type_out = out;};
401
 
402
/*      void SetLG(double SiPM0, double M0, double d0, double n10, double n20, double n30, double R0)
403
        { SiPM=SiPM0;
404
                M=M0;
405
                d=d0;
406
                n1=n10;
407
                n2=n20;
408
                n3=n30;
409
                R=R0;
410
                }; */
411
        //void SetR(double R0) {R = R0;};
412
        //void SetGlass(int glass_on0, double glass_d0)
413
                //{glass_on = glass_on0; glass_d = glass_d0;};
414
        //void SetGap(double x_gap0, double y_gap0, double z_gap0)
415
                //{x_gap = x_gap0; y_gap = y_gap0; z_gap = z_gap0;};    
416
        void SetRCol(int in, int lg, int out, int gla)
417
                {col_in = in; col_lg = lg; col_out = out; col_rgla = gla;};
418
        void SetDCol(int LG0, int glass0, int active0)
419
                {col_LG = LG0; col_glass = glass0; col_active = active0;};
420
        //void SetFresnel(int b)
421
                //{fresnel = b;};
422
        //void SetAbsorption(int b, double A0)
423
                //{absorption = b; A = A0;};
424
        //void SetWindow(double wR, double d0) {window_R = wR; window_d = d0;}; 
425
        //void SetGuideOn(int b)
426
                //{guide_on = b;};
427
 
428
        //void Init();
429
 
430
        int Propagate(CRay, CRay*, int);
431
 
432
        Guide* GetLG() const {return guide;};
433
        //TH2F* GetHWindow() const {return hwindow;};
434
        TH2F* GetHGlass() const {return hglass;};
435
        TH2F* GetHActive() const {return hactive;};
436
        TH2F* GetHLaser() const {return hlaser;};
437
        TH2F* GetHDetector() const {return hdetector;};
438
 
439
        //double GetSiPM() const {return SiPM;};
440
        //double GetM() const {return M;};
441
        //double GetD() const {return d;};
442
        //double GetR() const {return R;};
443
        //TVector3 GetVGap() const {return (TVector3(x_gap, y_gap, z_gap));};
444
        //int IsGlass() {return glass_on;};
445
        //double GetGlass() {return glass_d;};
446
        //double GetWindowR() {return window_R;};
447
        //double GetWindowD() {return window_d;};
448
 
449
        void Draw(int width = 2);
450
 
451
        private:
452
        Fate fate;
453
        TVector3 center;
454
 
455
        //int type_in, type_side, type_out;
456
        //double SiPM, M, d, n1, n2, n3, R;
457
        //double detectorActive; 
458
 
459
 
460
        int glass_on;
461
        double glass_d;
462
        CSurface *glass;
463
        CPlaneR *glass_circle;
464
        TH2F *hglass;
465
 
466
        //double x_gap, y_gap, z_gap;
467
        CPlane4 *active;
468
        TH2F *hactive, *hlaser;
469
 
470
        CPlane4 *detector;
471
        TH2F *hdetector;
472
 
473
        int col_in, col_lg, col_out, col_rgla;
474
        int col_LG, col_glass, col_active;
475
 
476
        //int fresnel, absorption;
477
        //double A;
478
 
479
        int guide_on;
480
 
481
        //double window_R, window_d;
482
        //CSurface *window;
483
        //CPlaneR *window_circle;
484
        //TH2F *hwindow;
485
 
486
        Guide *guide;
487
        Plate *plate;
488
 
489
        double _plateWidth;
490
        int _plateOn;
491
 
492
        TH2F *histoPlate;
54 f9daq 493
 
494
        double offsetY;
495
        double offsetZ;
25 f9daq 496
};
497
 
498
 
499
 
500
//=================================================================================
501
#endif