1 | // $Id: LOpticalSystem.cc 2849 2010-11-11 11:59:41Z biktem $ |
---|
2 | // Author: Dmitry V.Naumov 2007/11/13 |
---|
3 | |
---|
4 | /***************************************************************************** |
---|
5 | * ESAF: Euso Simulation and Analysis Framework * |
---|
6 | * * |
---|
7 | * Id: LOpticalSystem * |
---|
8 | * Package: Optics * |
---|
9 | * Coordinator: Alessandro.Thea * |
---|
10 | * * |
---|
11 | *****************************************************************************/ |
---|
12 | |
---|
13 | //_____________________________________________________________________________ |
---|
14 | // |
---|
15 | // LOpticalSystem |
---|
16 | // |
---|
17 | // <extensive class description> |
---|
18 | // |
---|
19 | // Config file parameters |
---|
20 | // ====================== |
---|
21 | // |
---|
22 | // <parameter name>: <parameter description> |
---|
23 | // -Valid options: <available options> |
---|
24 | // |
---|
25 | |
---|
26 | #include "LOpticalSystem.hh" |
---|
27 | #include "Ltrace_optF1v4.hh" |
---|
28 | #include "Config.hh" |
---|
29 | #include "EsafRandom.hh" |
---|
30 | #include "EEvent.hh" |
---|
31 | #include <TMath.h> |
---|
32 | |
---|
33 | #define CHECK_TIMING |
---|
34 | #ifdef CHECK_TIMING |
---|
35 | #include <TBenchmark.h> |
---|
36 | #include <TTree.h> |
---|
37 | #include <TFile.h> |
---|
38 | #include <TH1D.h> |
---|
39 | #endif |
---|
40 | |
---|
41 | using namespace sou; |
---|
42 | ClassImp(LOpticalSystem) |
---|
43 | tel_param fLOpticalSystemParam; |
---|
44 | |
---|
45 | //#define DEBUG |
---|
46 | // extern TBenchmark* theBenchMark; |
---|
47 | // extern TTree* theBenchTree; |
---|
48 | // extern double theTime; |
---|
49 | extern TH1D* theh; |
---|
50 | //_____________________________________________________________________________ |
---|
51 | LOpticalSystem::LOpticalSystem(): fLogFile(0) { |
---|
52 | // |
---|
53 | // Constructor |
---|
54 | // |
---|
55 | |
---|
56 | #ifdef CHECK_TIMING |
---|
57 | CreateHisto(); |
---|
58 | #endif |
---|
59 | |
---|
60 | if(Lread_tel_param("config/Optics/LOpticalSystem/telparm_F1v4.dat",&fLOpticalSystemParam,fLogFile)!=0) exit(-1); |
---|
61 | |
---|
62 | int code; |
---|
63 | cout<<"init"<<endl; |
---|
64 | if( (code=LReadLensData(&fLOpticalSystemParam,fLogFile))<0 ) { |
---|
65 | fprintf(stderr,"reading lens surface data files failed. Code %i\n", code); |
---|
66 | exit(code); |
---|
67 | } |
---|
68 | if( (code=LReadDiffractData(fLOpticalSystemParam.Llens_dir,fLogFile))<0 ) { |
---|
69 | fprintf(stderr,"reading diffractive opt. data files failed (%s). Code %i\n", fLOpticalSystemParam.Llens_dir,code); |
---|
70 | exit(code); |
---|
71 | } |
---|
72 | |
---|
73 | // take the size of the system from Ltrace |
---|
74 | fR=fLOpticalSystemParam.Lr_wall; |
---|
75 | fPos=EVector(0,0,Conf()->GetNum("LOpticalSystem.fPos.Z")*mm); |
---|
76 | |
---|
77 | fDZdown=1*mm;//1 |
---|
78 | fDZup=2072.*mm;//2073 |
---|
79 | //fFirstLensDZ=15*mm; |
---|
80 | //fFirstLensDZ=412.942*mm; |
---|
81 | fFirstLensDZ=412.942*mm; |
---|
82 | //fSecondLensDZ=10*mm; |
---|
83 | //fSecondLensDZ=210.469*mm; |
---|
84 | fSecondLensDZ=210.469*mm; |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | //_____________________________________________________________________________ |
---|
89 | LOpticalSystem::~LOpticalSystem() { |
---|
90 | // |
---|
91 | // Destructor |
---|
92 | // |
---|
93 | cout<<"Destructor ************************************"<<endl; |
---|
94 | #define CHECK_TIMING |
---|
95 | #ifdef CHECK_TIMING |
---|
96 | |
---|
97 | DeleteHisto(); |
---|
98 | #endif |
---|
99 | |
---|
100 | } |
---|
101 | //______________________________________________________________________________ |
---|
102 | Photon* LOpticalSystem::Transport(Photon *p) const { |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | Double_t ph_in[8]; |
---|
108 | Double_t ph_out[8]; |
---|
109 | EVector dummy=p->pos-fPos; |
---|
110 | ph_in[0]=dummy[X]/mm; |
---|
111 | ph_in[1]=dummy[Y]/mm; |
---|
112 | ph_in[2]=dummy[Z]/mm; |
---|
113 | |
---|
114 | ph_in[3]=p->dir[X]; |
---|
115 | ph_in[4]=p->dir[Y]; |
---|
116 | ph_in[5]=p->dir[Z]; |
---|
117 | |
---|
118 | ph_in[6]=p->wl/nm; |
---|
119 | ph_in[7]=p->time/ns; |
---|
120 | |
---|
121 | |
---|
122 | #ifdef DEBUG |
---|
123 | cout<<"LOpticalSystem"<<endl; |
---|
124 | cout<<"position = "<<p->pos<<endl; |
---|
125 | cout<<"direction = "<<p->dir<<endl; |
---|
126 | double theta=p->dir.Angle(EVector(0.,0.,1.)); |
---|
127 | cout<<"theta = "<<theta/deg<<endl; |
---|
128 | cout<<"wl = "<<p->wl/nm<<endl; |
---|
129 | cout<<"time = "<<p->time/ns<<endl; |
---|
130 | #endif /* DEBUG */ |
---|
131 | int flag = Ltrace_main(&fLOpticalSystemParam,ph_in, ph_out, fLogFile); |
---|
132 | |
---|
133 | // FIXME: add to ltrace possibility to save latest photon information, for cases when it's absorbed |
---|
134 | if ( !flag ) { |
---|
135 | dummy[X]=ph_out[0]*mm; |
---|
136 | dummy[Y]=ph_out[1]*mm; |
---|
137 | dummy[Z]=ph_out[2]*mm; |
---|
138 | p->pos=dummy+fPos; |
---|
139 | |
---|
140 | p->dir[X]=ph_out[3]; |
---|
141 | p->dir[Y]=ph_out[4]; |
---|
142 | p->dir[Z]=ph_out[5]; |
---|
143 | |
---|
144 | p->wl = ph_out[6]*nm; |
---|
145 | p->time = ph_out[7]*ns; |
---|
146 | } |
---|
147 | p->fate = flag; |
---|
148 | |
---|
149 | #ifdef DEBUG |
---|
150 | cout<<"LOpticalSystem OUT"<<endl; |
---|
151 | cout<<"position = "<<p->pos<<endl; |
---|
152 | cout<<"direction = "<<p->dir<<endl; |
---|
153 | theta=p->dir.Angle(EVector(0.,0.,1.)); |
---|
154 | cout<<"theta = "<<theta/deg<<endl; |
---|
155 | cout<<"wl = "<<p->wl/nm<<endl; |
---|
156 | cout<<"time = "<<p->time/ns<<endl; |
---|
157 | #endif |
---|
158 | if ( flag != 0 ) |
---|
159 | return 0; |
---|
160 | |
---|
161 | Double_t DL; |
---|
162 | // sometime ltrace returns photons out of the boundaries |
---|
163 | if (p->pos.Perp() > fLOpticalSystemParam.Lr_wall || p->pos[Z] > Top() || p->pos[Z] < Bottom() ){ |
---|
164 | // the photon is outside the cyl, trace it back to the borders |
---|
165 | EVector savedir = p->dir; |
---|
166 | p->dir = -p->dir; |
---|
167 | if ((DL = CylinderIntersection(p,kTRUE)) > 0){ |
---|
168 | p->pos+=p->dir.Unit()*DL; |
---|
169 | p->time-=DL/TMath::C(); |
---|
170 | } |
---|
171 | p->dir=savedir; |
---|
172 | } else if ((DL = CylinderIntersection(p,kTRUE)) > 0){ |
---|
173 | // all the photon must be returned on the boundaries of the optics |
---|
174 | |
---|
175 | p->pos+=p->dir.Unit()*DL; |
---|
176 | p->time+=DL/TMath::C(); |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | #ifdef DEBUG |
---|
181 | // cout<<"new position = "<<p->pos<<endl; |
---|
182 | // cout<<"new direction = "<<p->dir<<endl; |
---|
183 | // cout<<"new wl = "<<p->wl/nm<<endl; |
---|
184 | // cout<<"new time = "<<p->time/ns<<endl; |
---|
185 | #endif /* DEBUG */ |
---|
186 | |
---|
187 | if (IsGoingOut(p)) |
---|
188 | return p; |
---|
189 | else |
---|
190 | return 0; |
---|
191 | } |
---|
192 | |
---|
193 | //______________________________________________________________________________ |
---|
194 | Bool_t LOpticalSystem::IsGoingOut( Photon *p ) const { |
---|
195 | // |
---|
196 | // helper method to select outward going photons |
---|
197 | // |
---|
198 | |
---|
199 | Bool_t side, face; |
---|
200 | // check if photon is on the lat surface |
---|
201 | side = TMath::Abs((p->pos-fPos).Perp()-fR) < kTolerance && |
---|
202 | (p->pos-fPos).XYvector()*p->dir.XYvector() > 0 && |
---|
203 | ((p->pos[Z] < FirstLensTop() && p->pos[Z] > FirstLensBottom()) || |
---|
204 | (p->pos[Z] < SecondLensTop() && p->pos[Z] > SecondLensBottom()) ); |
---|
205 | // or if it's on the top/bottom face |
---|
206 | face = (TMath::Abs(p->pos[Z]-FirstLensBottom()) < kTolerance && p->dir[Z]<0) || |
---|
207 | (TMath::Abs(p->pos[Z]-SecondLensTop()) < kTolerance && p->dir[Z]>0); |
---|
208 | return side || face; |
---|
209 | } |
---|
210 | |
---|
211 | //______________________________________________________________________________ |
---|
212 | Bool_t LOpticalSystem::HitSide(Photon *p) const { |
---|
213 | // |
---|
214 | // Check if p hist the side of the Cylinder. |
---|
215 | // |
---|
216 | |
---|
217 | Double_t dt = CylinderIntersection( p, fR, SecondLensBottom(), FirstLensTop() ); |
---|
218 | if (dt < 0 || (p->pos+p->dir*dt)[Z]-SecondLensBottom() < kTolerance |
---|
219 | || (p->pos+p->dir*dt)[Z]-FirstLensTop() < kTolerance ) |
---|
220 | return kFALSE; |
---|
221 | return kTRUE; |
---|
222 | } |
---|