source: trunk/Mars/msim/MPhotonData.cc@ 9942

Last change on this file since 9942 was 9941, checked in by tbretz, 14 years ago
Implemented reading of a single telescope from an eventio file.
File size: 9.7 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, 12/2000 <mailto:thomas.bretz@epfl.ch>
19! Author(s): Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
20!
21! Copyright: CheObs Software Development, 2000-2010
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MPhotonData
29//
30// Storage container to store Corsika events
31//
32// For details on the coordinate systems see our Wiki.
33//
34// Version 1:
35// ----------
36// * First implementation
37//
38// Version 2:
39// ----------
40// - fNumPhotons
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MPhotonData.h"
44
45#include <fstream>
46#include <iostream>
47
48#include <TMath.h>
49#include <TRandom.h>
50
51#include "MLog.h"
52#include "MLogManip.h"
53
54ClassImp(MPhotonData);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62MPhotonData::MPhotonData(/*const char *name, const char *title*/)
63 : fPosX(0), fPosY(0), fCosU(0), fCosV(0), fTime(0), fWavelength(0),
64 /*fNumPhotons(1),*/ fProductionHeight(0), fPrimary(MMcEvtBasic::kUNDEFINED),
65 fTag(-1), fWeight(1)
66{
67 // fName = name ? name : "MPhotonData";
68 // fTitle = title ? title : "Corsika Event Data Information";
69}
70
71/*
72MPhotonData::MPhotonData(const MPhotonData &ph)
73: fPosX(ph.fPosX), fPosY(ph.fPosY), fCosU(ph.fCosU), fCosV(ph.fCosV),
74fTime(ph.fTime), fWavelength(ph.fWavelength), fNumPhotons(ph.fNumPhotons),
75fProductionHeight(ph.fProductionHeight), fPrimary(ph.fPrimary),
76fTag(ph.fTag), fWeight(ph.fWeight)
77{
78}
79*/
80
81// --------------------------------------------------------------------------
82//
83// Copy function. Copy all data members into obj.
84//
85void MPhotonData::Copy(TObject &obj) const
86{
87 MPhotonData &d = static_cast<MPhotonData&>(obj);
88
89// d.fNumPhotons = fNumPhotons;
90 d.fPosX = fPosX;
91 d.fPosY = fPosY;
92 d.fCosU = fCosU;
93 d.fCosV = fCosV;
94 d.fWavelength = fWavelength;
95 d.fPrimary = fPrimary;
96 d.fTime = fTime;
97 d.fTag = fTag;
98 d.fWeight = fWeight;
99 d.fProductionHeight = fProductionHeight;
100
101 TObject::Copy(obj);
102}
103
104// --------------------------------------------------------------------------
105//
106// Return the square cosine of the Theta-angle == 1-CosU^2-CosV^2
107//
108Double_t MPhotonData::GetCosW2() const
109{
110 return 1 - GetSinW2();
111}
112
113// --------------------------------------------------------------------------
114//
115// Return the square sine of the Theta-angle == CosU^2+CosV^2
116//
117Double_t MPhotonData::GetSinW2() const
118{
119 return fCosU*fCosU + fCosV*fCosV;
120}
121
122// --------------------------------------------------------------------------
123//
124// return the cosine of the Theta-angle == sqrt(1-CosU^2-CosV^2)
125//
126Double_t MPhotonData::GetCosW() const
127{
128 return TMath::Sqrt(GetCosW2());
129}
130
131// --------------------------------------------------------------------------
132//
133// return the sine of the Theta-angle == sqrt(CosU^2+CosV^2)
134//
135Double_t MPhotonData::GetSinW() const
136{
137 return TMath::Sqrt(GetSinW2());
138}
139
140// --------------------------------------------------------------------------
141//
142// Return the theta angle in radians
143//
144Double_t MPhotonData::GetTheta() const
145{
146 return TMath::ASin(GetSinW());
147}
148
149// --------------------------------------------------------------------------
150//
151// Return a TQuaternion with the first three components x, y, and z
152// and the fourth component the time.
153//
154TQuaternion MPhotonData::GetPosQ() const
155{
156 return TQuaternion(GetPos3(), fTime);
157}
158
159// --------------------------------------------------------------------------
160//
161// return a TQuaternion with the first three components the direction
162// moving in space (GetDir3()) and the fourth component is the
163// one devided by the speed of light (converted to cm/ns)
164//
165// FIXME: v in air!
166//
167TQuaternion MPhotonData::GetDirQ() const
168{
169 return TQuaternion(GetDir3(), 1./(TMath::C()*100/1e9));
170}
171
172// --------------------------------------------------------------------------
173//
174// Set the wavelength to a random lambda^-2 distributed value
175// between wmin and wmax.
176//
177void MPhotonData::SimWavelength(Float_t wmin, Float_t wmax)
178{
179 const Double_t w = gRandom->Uniform(wmin, wmax);
180
181 fWavelength = TMath::Nint(wmin*wmax / w);
182}
183
184
185// --------------------------------------------------------------------------
186//
187// Set the data member according to the 8 floats read from a reflector-file.
188// This function MUST reset all data-members, no matter whether these are
189// contained in the input stream.
190//
191Int_t MPhotonData::FillRfl(Float_t f[8])
192{
193 // Check coordinate system!!!!
194 fWavelength = TMath::Nint(f[0]);
195 fPosX = f[1]; // [cm]
196 fPosY = f[2]; // [cm]
197 fCosU = f[3]; // cos to x
198 fCosV = f[4]; // cos to y
199 fTime = f[5]; // [ns]
200 fProductionHeight = f[6];
201
202 // f[7]: Camera inclination angle
203
204 fPrimary = MMcEvtBasic::kUNDEFINED;
205// fNumPhotons = 1;
206 fTag = -1;
207 fWeight = 1;
208
209 return kTRUE;
210}
211
212// --------------------------------------------------------------------------
213//
214// Set the data member according to the 7 floats read from a corsika-file.
215// This function MUST reset all data-members, no matter whether these are
216// contained in the input stream.
217//
218// Currently we exchange x and y and set y=-y to convert Corsikas coordinate
219// system intpo our own.
220//
221Int_t MPhotonData::FillCorsika(Float_t f[7], Int_t i)
222{
223 const UInt_t n = TMath::Nint(f[0]);
224 if (n==0)
225 // FIXME: Do we need to decode the rest anyway?
226 return kCONTINUE;
227
228 // Check reuse
229 const Int_t reuse = (n/1000)%100; // Force this to be 1!
230 if (reuse!=i)
231 return kCONTINUE;
232
233 // This seems to be special to mmcs
234 fWavelength = n%1000;
235 fPrimary = MMcEvtBasic::ParticleId_t(n/100000);
236
237 // x=north, y=west
238 //fPosX = f[1]; // [cm]
239 //fPosY = f[2]; // [cm]
240 //fCosU = f[3]; // cos to x
241 //fCosV = f[4]; // cos to y
242 // x=west, y=south
243 fPosX = f[2]; // [cm]
244 fPosY = -f[1]; // [cm]
245
246 fCosU = f[4]; // cos to x
247 fCosV = -f[3]; // cos to y
248
249 fTime = f[5]; // [ns]
250
251 fProductionHeight = f[6]; // [cm]
252
253 // Now reset all data members which are not in the stream
254 fTag = -1;
255 fWeight = 1;
256
257 return kTRUE;
258}
259
260// --------------------------------------------------------------------------
261//
262// Set the data member according to the 8 floats read from a eventio-file.
263// This function MUST reset all data-members, no matter whether these are
264// contained in the input stream.
265//
266// Currently we exchange x and y and set y=-y to convert Corsikas coordinate
267// system into our own.
268//
269Int_t MPhotonData::FillEventIO(Float_t f[8])
270{
271 // photons in this bunch
272 const UInt_t n = TMath::Nint(f[6]);
273 if (n==0)
274 return 0;
275
276 f[6] = n-1;
277
278 fPosX = f[1]; // xpos relative to telescope [cm]
279 fPosY = -f[0]; // ypos relative to telescope [cm]
280 fCosU = f[3]; // cos to x
281 fCosV = -f[2]; // cos to y
282 fTime = f[4]; // a relative arival time [ns]
283 fProductionHeight = f[5]; // altitude of emission [cm]
284 fWavelength = TMath::Nint(f[7]); // so far always zeor = unspec. [nm]
285
286 // Now reset all data members which are not in the stream
287 fPrimary = MMcEvtBasic::kUNDEFINED;
288 fTag = -1;
289 fWeight = 1;
290
291 return n;
292}
293
294/*
295// --------------------------------------------------------------------------
296//
297// Read seven floats from the stream and call FillCorsika for them.
298//
299Int_t MPhotonData::ReadCorsikaEvt(istream &fin)
300{
301 Float_t f[7];
302 fin.read((char*)&f, 7*4);
303
304 const Int_t rc = FillCorsika(f);
305
306 return rc==kTRUE ? !fin.eof() : rc;
307}
308
309// --------------------------------------------------------------------------
310//
311// Read eight floats from the stream and call FillRfl for them.
312//
313Int_t MPhotonData::ReadRflEvt(istream &fin)
314{
315 Float_t f[8];
316 fin.read((char*)&f, 8*4);
317
318 const Int_t rc = FillRfl(f);
319
320 return rc==kTRUE ? !fin.eof() : rc;
321}
322*/
323
324// --------------------------------------------------------------------------
325//
326// Print contents. The tag and Weight are only printed if they are different
327// from the default.
328//
329void MPhotonData::Print(Option_t *) const
330{
331 gLog << inf << endl;
332// gLog << "Num Photons: " << fNumPhotons << " from " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
333 gLog << "Origin: " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
334 gLog << "Wavelength: " << fWavelength << "nm" << endl;
335 gLog << "Pos X/Y Cos U/V: " << fPosX << "/" << fPosY << " " << fCosU << "/" << fCosV << endl;
336 gLog << "Time/Prod.Height: " << fTime << "ns/" << fProductionHeight << "cm" << endl;
337 if (fTag>=0)
338 gLog << "Tag: " << fTag << endl;
339 if (fWeight!=1)
340 gLog << "Weight: " << fWeight << endl;
341}
Note: See TracBrowser for help on using the repository browser.