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

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