source: trunk/Mars/msimreflector/MSimRays.cc@ 9912

Last change on this file since 9912 was 9910, checked in by tbretz, 14 years ago
Fixed a problem with the compilation of ReadEnv
File size: 6.9 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appears in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/2009 <mailto:thomas.bretz@epfl.ch>
19!
20! Copyright: CheObs Software Development, 2000-2010
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSimRays
28//
29// Task to produce rays from a light source at either infinity or a given
30// height from a given local sky position.
31//
32// The sky position is defined by an MPointingPos object in the parameter
33// list (if none exists, the source is at the reflector axis). Its
34// default name is "MPointingPos".
35//
36// The height of the light/point source is set by SetHeight in units of km.
37// A value <= 0 means infinity.
38//
39// The number of rays produced per event is defined by SetNumPhotons(n).
40// The default is 1000.
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MSimRays.h"
44
45#include <TRandom.h>
46#include <TRotation.h>
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51#include "MParList.h"
52
53#include "MQuaternion.h"
54
55#include "MPhotonEvent.h"
56#include "MPhotonData.h"
57
58#include "MReflector.h"
59#include "MPointingPos.h"
60
61ClassImp(MSimRays);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default Constructor.
68//
69MSimRays::MSimRays(const char* name, const char *title)
70 : fEvt(0), fReflector(0), fPointPos(0), fSource(0),
71 fNumPhotons(1000), fHeight(-1),
72 fNameReflector("MReflector"), fNamePointPos("MPointingPos"),
73 fNameSource("Source")
74{
75 fName = name ? name : "MSimRays";
76 fTitle = title ? title : "Task to calculate reflection os a mirror";
77}
78
79// --------------------------------------------------------------------------
80//
81// Search for the necessary parameter containers.
82//
83Int_t MSimRays::PreProcess(MParList *pList)
84{
85 fEvt = (MPhotonEvent*)pList->FindCreateObj("MPhotonEvent");
86 if (!fEvt)
87 return kFALSE;
88
89 if (!pList->FindCreateObj("MCorsikaEvtHeader"))
90 return kFALSE;
91
92 fReflector = (MReflector*)pList->FindObject(fNameReflector, "MReflector");
93 if (!fReflector)
94 {
95 *fLog << inf << fNameReflector << " [MReflector] not found..." << endl;
96 return kFALSE;
97 }
98
99 fSource = (MPointingPos*)pList->FindObject(fNameSource, "MPointingPos");
100 if (!fSource)
101 {
102// *fLog << inf << fNameSource << " [MPointingPos] not found..." << endl;
103// return kFALSE;
104 }
105
106 fPointPos = (MPointingPos*)pList->FindObject(fNamePointPos, "MPointingPos");
107 if (!fPointPos)
108 {
109 *fLog << inf << fNamePointPos << " [MPointingPos] not found..." << endl;
110 return kFALSE;
111 }
112
113 return kTRUE;
114}
115
116// --------------------------------------------------------------------------
117//
118// Converts the photons into the telscope coordinate frame using the
119// pointing position from MPointingPos.
120//
121// Reflects all photons on all mirrors and stores the final photons on
122// the focal plane. Also intermediate photons are stored for debugging.
123//
124Int_t MSimRays::Process()
125{
126 // Get arrays from event container
127 fEvt->Resize(fNumPhotons);
128
129 TClonesArray &arr = fEvt->GetArray();
130
131 const Int_t num = arr.GetEntriesFast();
132
133 const Double_t maxr = fReflector->GetMaxR();
134
135 const Double_t deltazd = fSource ? fSource->GetZdRad() : 0;
136 const Double_t deltaaz = fSource ? fSource->GetAzRad() : 0;
137
138 const Double_t zd = fPointPos->GetZdRad() + deltazd;
139 const Double_t az = fPointPos->GetAzRad() + deltaaz;
140
141
142 // cm -> m
143 // s -> ns
144 // length -> time
145 const Double_t conv = 1./(TMath::C()*100/1e9);
146
147 // Local sky coordinates (direction of telescope axis)
148 //const Double_t zd = fPointing->GetZdRad(); // x==north
149 //const Double_t az = fPointing->GetAzRad();
150
151 // Height of point source [cm] (0 means infinity)
152 const Double_t h = fHeight * 100000;
153
154 // Rotation matrix to derotate sky
155 // For the new coordinate system see the Wiki
156 TRotation rot; // The signs are positive because we align the incident point on ground to the telescope axis
157 rot.RotateX( zd); // Rotate point on ground to align it with the telescope axis
158 rot.RotateZ(-az); // tilt the point from ground to make it parallel to the mirror plane
159
160 Int_t idx = 0;
161 while (idx<num)
162 {
163 MPhotonData &dat = *static_cast<MPhotonData*>(arr.UncheckedAt(idx));
164
165 const Double_t x = gRandom->Uniform(-maxr, maxr);
166 const Double_t y = gRandom->Uniform(-maxr, maxr);
167
168 if (x*x + y*y > maxr*maxr)
169 continue;
170
171 // h==0 means infinitiy
172 const TVector3 u = fHeight>0 ? TVector3(x, y, -h).Unit() : TVector3(0, 0, -1);
173
174 // w is pointing away from the direction the photon comes from
175 // CORSIKA-orig: x(north), y(west), z(up), t(time)
176 // NOW: x(east), y(north), z(up), t(time)
177 MQuaternion p(TVector3(x, y, 0));
178 MQuaternion w(u, conv);
179
180 // Rotate the coordinates into the reflector's coordinate system.
181 // It is assumed that the z-plane is parallel to the focal plane.
182 // (The reflector coordinate system is defined by the telescope orientation)
183 p *= rot;
184 w *= rot;
185
186 // Now propagate the photon to the z-plane in the new coordinate system
187 p.PropagateZ0(w);
188
189 // Shift the coordinate system to the telescope. Corsika's
190 // coordinate system is always w.r.t. to the particle axis
191 //p += impact;
192
193 // Store new position and direction in the reflector's coordinate frame
194 dat.SetPosition(p);
195 dat.SetDirection(w);
196
197 idx++;
198 }
199
200 // Doesn't seem to be too time consuming. But we could also sort later!
201 // (after cones, inside the camera)
202 // fEvt->Sort(kTRUE);
203
204 return kTRUE;
205}
206
207// --------------------------------------------------------------------------
208//
209// Height: -1
210// NumPhotons: 1000
211//
212Int_t MSimRays::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
213{
214 Bool_t rc = kFALSE;
215 if (IsEnvDefined(env, prefix, "Height", print))
216 {
217 rc = kTRUE;
218 fHeight = GetEnvValue(env, prefix, "Height", fHeight);
219 }
220 if (IsEnvDefined(env, prefix, "NumPhotons", print))
221 {
222 rc = kTRUE;
223 fNumPhotons = GetEnvValue(env, prefix, "NumPhotons", (Int_t)fNumPhotons);
224 }
225
226 return rc;
227}
Note: See TracBrowser for help on using the repository browser.