Subversion Repositories f9daq

Rev

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