source: JEM-EUSO/esaf_cc_at_lal/packages/simulation/detector/optics/src/MOpticalSystem.cc @ 114

Last change on this file since 114 was 114, checked in by moretto, 11 years ago

actual version of ESAF at CCin2p3

File size: 6.2 KB
Line 
1// $Id: MOpticalSystem.cc 2828 2009-04-01 14:29:16Z biktem $
2// Author: Dmitry V.Naumov   2007/11/13
3
4/*****************************************************************************
5 * ESAF: Euso Simulation and Analysis Framework                              *
6 *                                                                           *
7 *  Id: MOpticalSystem                                                       *
8 *  Package: Optics                                                          *
9 *  Coordinator: Alessandro.Thea                                             *
10 *                                                                           *
11 *****************************************************************************/
12
13//_____________________________________________________________________________
14//
15// MOpticalSystem
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 <TMath.h>
27#include "EEvent.hh"
28
29#include "Config.hh"
30#include "EsafRandom.hh"
31
32#include "MOpticalSystem.hh"
33#include "Mtrace_optF1v4.hh"
34#include "Ntrace_optics.hh"
35using namespace sou;
36
37Mtel_param  fMOpticalSystemParam;
38
39ClassImp(MOpticalSystem)
40//_____________________________________________________________________________
41MOpticalSystem::MOpticalSystem(): fLogFile(0) {
42    //
43    // Constructor
44    //
45
46    if(Mread_tel_param("config/Optics/MOpticalSystem/telparm_F1v6.dat",&fMOpticalSystemParam,fLogFile)!=0) exit(-1);
47
48    if(ReadLensData(&fMOpticalSystemParam,fLogFile)<0) {
49       fprintf(stderr,"reading lens surface data files failed\n");
50       exit(-2);
51    }
52    if(ReadDiffractData(fMOpticalSystemParam.Mlens_dir,fLogFile)<0) {
53       fprintf(stderr,"reading diffractive opt. data files failed\n");
54       exit(-2);
55    }
56//Below fOpticalSystemParam for MOpics is filled
57    const char* lens_dir = "config/Optics/NOpticalSystem/";
58    const char* tel_par = "CPC_2007";
59    ReadTelParm(lens_dir,tel_par);
60
61    fDZdown=1*mm;
62    fDZup=2197*mm;
63
64    // take the size of the system from Ltrace
65    fR=fMOpticalSystemParam.Mr_wall;
66    fPos=EVector(0,0,Conf()->GetNum("MOpticalSystem.fPos.Z")*mm);
67
68    //fFirstLensDZ=15.9*mm;
69    //fFirstLensDZ=437.784*mm;
70    fFirstLensDZ=437.784*mm;
71    //fSecondLensDZ=10.6*mm;
72    fSecondLensDZ=223.217*mm;
73
74}
75
76//_____________________________________________________________________________
77MOpticalSystem::~MOpticalSystem() {
78    //
79    // Destructor
80    //
81}
82//______________________________________________________________________________
83Photon* MOpticalSystem::Transport(Photon *p) const {
84    Double_t ph_in[8];
85    Double_t ph_out[8];
86    EVector dummy=p->pos-fPos;
87    ph_in[0]=dummy[X]/mm;
88    ph_in[1]=dummy[Y]/mm;
89    ph_in[2]=dummy[Z]/mm;
90
91    ph_in[3]=p->dir[X];
92    ph_in[4]=p->dir[Y];
93    ph_in[5]=p->dir[Z];
94
95    ph_in[6]=p->wl/nm;
96    ph_in[7]=p->time/ns;
97
98
99#ifdef DEBUG
100    cout<<"MOpticalSystem"<<endl;
101    cout<<"position = "<<p->pos<<endl;
102    cout<<"direction = "<<p->dir<<endl;
103    double theta=p->dir.Angle(EVector(0.,0.,1.));
104    cout<<"theta = "<<theta/deg<<endl;
105    cout<<"wl = "<<p->wl/nm<<endl;
106    cout<<"time = "<<p->time/ns<<endl;
107#endif /* DEBUG */
108    int flag = Mtrace_main(&fMOpticalSystemParam,ph_in, ph_out, fLogFile);
109#ifdef DEBUG
110#endif /* DEBUG */
111
112    // FIXME: add to mtrace possibility to save latest photon information, for cases when it's absorbed
113    if ( !flag ) {
114        dummy[X]=ph_out[0]*mm;
115        dummy[Y]=ph_out[1]*mm;
116        dummy[Z]=ph_out[2]*mm;
117        p->pos=dummy+fPos;
118
119        p->dir[X]=ph_out[3];
120        p->dir[Y]=ph_out[4];
121        p->dir[Z]=ph_out[5];
122
123        p->wl   = ph_out[6]*nm;
124        p->time = ph_out[7]*ns;
125    }
126    p->fate = flag;
127#ifdef DEBUG
128    cout<<"MOpticalSystem OUT"<<endl;
129    cout<<"position = "<<p->pos<<endl;
130    cout<<"direction = "<<p->dir<<endl;
131    theta=p->dir.Angle(EVector(0.,0.,1.));
132    cout<<"theta = "<<theta/deg<<endl;
133    cout<<"wl = "<<p->wl/nm<<endl;
134    cout<<"time = "<<p->time/ns<<endl;
135#endif
136    if ( flag != 0 ) return 0;
137
138    Double_t DL;
139    // sometime Ktrace returns photons out of the boundaries
140    if (p->pos.Perp() > fMOpticalSystemParam.Mr_wall || p->pos[Z] > Top() || p->pos[Z] < Bottom() ){
141        // the photon is outside the cyl, trace it back to the borders
142        EVector savedir = p->dir;
143        p->dir = -p->dir;
144        if ((DL = CylinderIntersection(p,kTRUE)) > 0){
145            p->pos+=p->dir.Unit()*DL;
146            p->time-=DL/TMath::C();
147        }
148        p->dir=savedir;
149    } else if ((DL = CylinderIntersection(p,kTRUE)) > 0){
150    // all the photon must be returned on the boundaries of the optics
151
152        p->pos+=p->dir.Unit()*DL;
153        p->time+=DL/TMath::C();
154    }
155
156#ifdef DEBUG
157        cout<<"new position = "<<p->pos<<endl;
158        cout<<"new direction = "<<p->dir<<endl;
159        cout<<"new wl = "<<p->wl/nm<<endl;
160        cout<<"new time = "<<p->time/ns<<endl;
161#endif /* DEBUG */
162
163    if (IsGoingOut(p))
164        return p;
165    else
166        return 0;
167}
168
169//______________________________________________________________________________
170Bool_t MOpticalSystem::IsGoingOut( Photon *p ) const {
171    //
172    // helper method to select outward going photons
173    //
174
175    Bool_t side, face;
176    // check if photon is on the lat surface
177    side = TMath::Abs((p->pos-fPos).Perp()-fR) < kTolerance  &&
178        (p->pos-fPos).XYvector()*p->dir.XYvector() > 0 &&
179        ((p->pos[Z] < FirstLensTop() && p->pos[Z] > FirstLensBottom()) ||
180         (p->pos[Z] < SecondLensTop() && p->pos[Z] > SecondLensBottom()) );
181    // or if it's on the top/bottom face
182    face = (TMath::Abs(p->pos[Z]-FirstLensBottom()) < kTolerance && p->dir[Z]<0) ||
183        (TMath::Abs(p->pos[Z]-SecondLensTop()) < kTolerance && p->dir[Z]>0);
184    return side || face;
185}
186
187//______________________________________________________________________________
188Bool_t MOpticalSystem::HitSide(Photon *p) const {
189    //
190    // Check if p hist the side of the Cylinder.
191    //
192
193    Double_t dt = CylinderIntersection( p, fR, SecondLensBottom(), FirstLensTop() );
194    if (dt < 0 || (p->pos+p->dir*dt)[Z]-SecondLensBottom() < kTolerance
195               || (p->pos+p->dir*dt)[Z]-FirstLensTop() < kTolerance )
196        return kFALSE;
197    return kTRUE;
198}
Note: See TracBrowser for help on using the repository browser.