1 | // ESAF : Euso Simulation and Analysis Framework |
---|
2 | // class KOpticalSystem |
---|
3 | // $Id: KOpticalSystem.cc 2836 2009-07-16 08:22:02Z biktem $ |
---|
4 | // J.Watts created , Sep 21 2003 |
---|
5 | // |
---|
6 | |
---|
7 | #include "Ktrace_optF1v1.hh" |
---|
8 | #include "KEUSO_optF1v1.hh" |
---|
9 | #include "KOpticalSystem.hh" |
---|
10 | #include "Config.hh" |
---|
11 | #include "EsafRandom.hh" |
---|
12 | #include "EEvent.hh" |
---|
13 | #include <TMath.h> |
---|
14 | using namespace sou; |
---|
15 | |
---|
16 | ClassImp(KOpticalSystem) |
---|
17 | |
---|
18 | Int_t Kread_para(char*); |
---|
19 | Int_t KReadSD(char*); |
---|
20 | int Ktrace(double*, double*); |
---|
21 | |
---|
22 | //______________________________________________________________________________ |
---|
23 | KOpticalSystem::KOpticalSystem(): OpticalSystem() { |
---|
24 | // |
---|
25 | // Constructor |
---|
26 | // |
---|
27 | |
---|
28 | fDZdown=0*mm; |
---|
29 | fDZup=2002*mm; |
---|
30 | |
---|
31 | // take the size of the system from Ktrace |
---|
32 | fR=R_WALL; |
---|
33 | fPos=EVector(0,0,Conf()->GetNum("KOpticalSystem.fPos.Z")*mm); |
---|
34 | |
---|
35 | fFirstLensDZ=169*mm; |
---|
36 | fSecondLensDZ=226*mm; |
---|
37 | |
---|
38 | #ifdef DEBUG |
---|
39 | /* cout << "FirstLensTop() "<< FirstLensTop() << endl; |
---|
40 | cout << "FirstLensBottom() "<< FirstLensBottom() << endl; |
---|
41 | cout << "SecondLensTop() "<< SecondLensTop() << endl; |
---|
42 | cout << "SecondLensBottom() "<< SecondLensBottom() << endl;*/ |
---|
43 | #endif /* DEBUG */ |
---|
44 | |
---|
45 | if(Kread_para("config/Optics/KOpticalSystem")<0){ |
---|
46 | cout<<"reading surface data files failed\n"<<endl; |
---|
47 | exit(-2); |
---|
48 | } |
---|
49 | if(KReadSD("config/Optics/KOpticalSystem")<0){ |
---|
50 | cout<<"reading diffractive data files failed\n"<<endl; |
---|
51 | exit(-2); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | //______________________________________________________________________________ |
---|
56 | Photon *KOpticalSystem::Transport(Photon *p) const { |
---|
57 | double ph_in[8]; |
---|
58 | double ph_out[8]; |
---|
59 | |
---|
60 | EVector dummy=p->pos-fPos; |
---|
61 | ph_in[0]=dummy[X]/mm; |
---|
62 | ph_in[1]=dummy[Y]/mm; |
---|
63 | ph_in[2]=dummy[Z]/mm; |
---|
64 | |
---|
65 | ph_in[3]=p->dir[X]; |
---|
66 | ph_in[4]=p->dir[Y]; |
---|
67 | ph_in[5]=p->dir[Z]; |
---|
68 | |
---|
69 | ph_in[6]=p->wl/nm; |
---|
70 | ph_in[7]=p->time/ns; |
---|
71 | |
---|
72 | |
---|
73 | #ifdef DEBUG/* |
---|
74 | cout<<"KOpticalSystem"<<endl; |
---|
75 | cout<<"position = "<<p->pos<<endl; |
---|
76 | cout<<"direction = "<<p->dir<<endl; |
---|
77 | double theta=p->dir.Angle(EVector(0.,0.,1.)); |
---|
78 | cout<<"theta = "<<theta/deg<<endl; |
---|
79 | cout<<"wl = "<<p->wl/nm<<endl; |
---|
80 | cout<<"time = "<<p->time/ns<<endl;*/ |
---|
81 | #endif /* DEBUG */ |
---|
82 | int flag=Ktrace(ph_in, ph_out); |
---|
83 | #ifdef DEBUG |
---|
84 | //cout << flag << endl; |
---|
85 | #endif /* DEBUG */ |
---|
86 | |
---|
87 | // FIXME: add to ktrace possibility to save latest photon information, for cases when it's absorbed |
---|
88 | if ( !flag ) { |
---|
89 | dummy[X]=ph_out[0]*mm; |
---|
90 | dummy[Y]=ph_out[1]*mm; |
---|
91 | dummy[Z]=ph_out[2]*mm; |
---|
92 | p->pos=dummy+fPos; |
---|
93 | |
---|
94 | p->dir[X]=ph_out[3]; |
---|
95 | p->dir[Y]=ph_out[4]; |
---|
96 | p->dir[Z]=ph_out[5]; |
---|
97 | |
---|
98 | p->wl = ph_out[6]*nm; |
---|
99 | p->time = ph_out[7]*ns; |
---|
100 | } |
---|
101 | p->fate = flag; |
---|
102 | |
---|
103 | if ( flag != 0 ) |
---|
104 | return 0; |
---|
105 | |
---|
106 | Double_t DL; |
---|
107 | // sometime Ktrace returns photons out of the boundaries |
---|
108 | if (p->pos.Perp() > R_WALL || p->pos[Z] > Top() || p->pos[Z] < Bottom() ){ |
---|
109 | // the photon is outside the cyl, trace it back to the borders |
---|
110 | EVector savedir = p->dir; |
---|
111 | p->dir = -p->dir; |
---|
112 | if ((DL = CylinderIntersection(p,kTRUE)) > 0){ |
---|
113 | p->pos+=p->dir.Unit()*DL; |
---|
114 | p->time-=DL/TMath::C(); |
---|
115 | } |
---|
116 | p->dir=savedir; |
---|
117 | } else if ((DL = CylinderIntersection(p,kTRUE)) > 0){ |
---|
118 | // all the photon must be returned on the boundaries of the optics |
---|
119 | |
---|
120 | p->pos+=p->dir.Unit()*DL; |
---|
121 | p->time+=DL/TMath::C(); |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | #ifdef DEBUG |
---|
126 | // cout<<"new position = "<<p->pos<<endl; |
---|
127 | // cout<<"new direction = "<<p->dir<<endl; |
---|
128 | // cout<<"new wl = "<<p->wl/nm<<endl; |
---|
129 | // cout<<"new time = "<<p->time/ns<<endl; |
---|
130 | #endif /* DEBUG */ |
---|
131 | |
---|
132 | if (IsGoingOut(p)) |
---|
133 | return p; |
---|
134 | else |
---|
135 | return 0; |
---|
136 | } |
---|
137 | |
---|
138 | //______________________________________________________________________________ |
---|
139 | Bool_t KOpticalSystem::IsGoingOut( Photon *p ) const { |
---|
140 | // |
---|
141 | // helper method to select outward going photons |
---|
142 | // |
---|
143 | |
---|
144 | Bool_t side, face; |
---|
145 | // check if photon is on the lat surface |
---|
146 | side = TMath::Abs((p->pos-fPos).Perp()-fR) < kTolerance && |
---|
147 | (p->pos-fPos).XYvector()*p->dir.XYvector() > 0 && |
---|
148 | ((p->pos[Z] < FirstLensTop() && p->pos[Z] > FirstLensBottom()) || |
---|
149 | (p->pos[Z] < SecondLensTop() && p->pos[Z] > SecondLensBottom()) ); |
---|
150 | // or if it's on the top/bottom face |
---|
151 | face = (TMath::Abs(p->pos[Z]-FirstLensBottom()) < kTolerance && p->dir[Z]<0) || |
---|
152 | (TMath::Abs(p->pos[Z]-SecondLensTop()) < kTolerance && p->dir[Z]>0); |
---|
153 | return side || face; |
---|
154 | } |
---|
155 | |
---|
156 | //______________________________________________________________________________ |
---|
157 | Bool_t KOpticalSystem::HitSide(Photon *p) const { |
---|
158 | // |
---|
159 | // Check if p hist the side of the Cylinder. |
---|
160 | // |
---|
161 | |
---|
162 | Double_t dt = CylinderIntersection( p, fR, SecondLensBottom(), FirstLensTop() ); |
---|
163 | if (dt < 0 || (p->pos+p->dir*dt)[Z]-SecondLensBottom() < kTolerance |
---|
164 | || (p->pos+p->dir*dt)[Z]-FirstLensTop() < kTolerance ) |
---|
165 | return kFALSE; |
---|
166 | return kTRUE; |
---|
167 | } |
---|