source: trunk/MagicSoft/Mars/msim/MPhotonData.cc@ 9249

Last change on this file since 9249 was 9243, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.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// Version 1:
33// ----------
34// - First implementation
35//
36/////////////////////////////////////////////////////////////////////////////
37#include "MPhotonData.h"
38
39#include <fstream>
40#include <iostream>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45ClassImp(MPhotonData);
46
47using namespace std;
48
49// --------------------------------------------------------------------------
50//
51// Default constructor.
52//
53MPhotonData::MPhotonData(/*const char *name, const char *title*/)
54 : fPosX(0), fPosY(0), fCosU(0), fCosV(0), fTime(0), fWavelength(0),
55 fNumPhotons(1), fProductionHeight(0), fPrimary(MMcEvtBasic::kUNDEFINED),
56 fTag(-1), fWeight(1)
57{
58 // fName = name ? name : "MPhotonData";
59 // fTitle = title ? title : "Corsika Event Data Information";
60}
61
62/*
63MPhotonData::MPhotonData(const MPhotonData &ph)
64: fPosX(ph.fPosX), fPosY(ph.fPosY), fCosU(ph.fCosU), fCosV(ph.fCosV),
65fTime(ph.fTime), fWavelength(ph.fWavelength), fNumPhotons(ph.fNumPhotons),
66fProductionHeight(ph.fProductionHeight), fPrimary(ph.fPrimary),
67fTag(ph.fTag), fWeight(ph.fWeight)
68{
69}
70*/
71
72// --------------------------------------------------------------------------
73//
74// Copy function. Copy all data members into obj.
75//
76void MPhotonData::Copy(TObject &obj) const
77{
78 MPhotonData &d = static_cast<MPhotonData&>(obj);
79
80 d.fNumPhotons = fNumPhotons;
81 d.fPosX = fPosX;
82 d.fPosY = fPosY;
83 d.fCosU = fCosU;
84 d.fCosV = fCosV;
85 d.fWavelength = fWavelength;
86 d.fPrimary = fPrimary;
87 d.fTime = fTime;
88 d.fTag = fTag;
89 d.fWeight = fWeight;
90 d.fProductionHeight = fProductionHeight;
91
92 TObject::Copy(obj);
93}
94
95// --------------------------------------------------------------------------
96//
97// Set the data member according to the 8 floats read from a reflector-file.
98// This function MUST reset all data-members, no matter whether these are
99// contained in the input stream.
100//
101Int_t MPhotonData::FillRfl(Float_t f[8])
102{
103 // Check coordinate system!!!!
104 fWavelength = TMath::Nint(f[0]);
105 fPosX = f[1]; // [cm]
106 fPosY = f[2]; // [cm]
107 fCosU = f[3]; // cos to x
108 fCosV = f[4]; // cos to y
109 fTime = f[5]; // [ns]
110 fProductionHeight = f[6];
111
112 // f[7]: Camera inclination angle
113
114 fPrimary = MMcEvtBasic::kUNDEFINED;
115 fNumPhotons = 1;
116 fTag = -1;
117 fWeight = 1;
118
119 return kTRUE;
120}
121
122// --------------------------------------------------------------------------
123//
124// Set the data member according to the 7 floats read from a corsika-file.
125// This function MUST reset all data-members, no matter whether these are
126// contained in the input stream.
127//
128// Currently we exchange x and y and set y=-y to convert Corsikas coordinate
129// system intpo our own.
130//
131Int_t MPhotonData::FillCorsika(Float_t f[7])
132{
133 const UInt_t n = TMath::Nint(f[0]);
134 if (n==0)
135 return kCONTINUE;
136
137 // This seems to be special to mmcs
138 fWavelength = n%1000;
139 fPrimary = MMcEvtBasic::ParticleId_t(n/100000);
140 fNumPhotons = (n/1000)%100; // Force this to be 1!
141
142 if (fNumPhotons!=1)
143 {
144 // FIXME: Could be done in MPhotonEvent::ReadCorsikaEvent
145 gLog << err << "ERROR - MPhotonData::FillCorsika: fNummPhotons not 1, but " << fNumPhotons << endl;
146 gLog << " This is not yet supported." << endl;
147 return kERROR;
148 }
149
150 // x=north, y=west
151 //fPosX = f[1]; // [cm]
152 //fPosY = f[2]; // [cm]
153 //fCosU = f[3]; // cos to x
154 //fCosV = f[4]; // cos to y
155 // x=east, y=north
156 fPosX = f[2]; // [cm]
157 fPosY = -f[1]; // [cm]
158
159 fCosU = -f[4]; // cos to x
160 fCosV = f[3]; // cos to y
161
162 fTime = f[5]; // [ns]
163
164 fProductionHeight = f[6]; // [cm]
165
166 // Now reset all data members which are not in the stream
167 fTag = -1;
168 fWeight = 1;
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Read seven floats from the stream and call FillCorsika for them.
176//
177Int_t MPhotonData::ReadCorsikaEvt(istream &fin)
178{
179 Float_t f[7];
180 fin.read((char*)&f, 7*4);
181
182 const Int_t rc = FillCorsika(f);
183
184 return rc==kTRUE ? !fin.eof() : rc;
185}
186
187// --------------------------------------------------------------------------
188//
189// Read eight floats from the stream and call FillRfl for them.
190//
191Int_t MPhotonData::ReadRflEvt(istream &fin)
192{
193 Float_t f[8];
194 fin.read((char*)&f, 8*4);
195
196 const Int_t rc = FillRfl(f);
197
198 return rc==kTRUE ? !fin.eof() : rc;
199}
200
201// --------------------------------------------------------------------------
202//
203// Print contents. The tag and Weight are only printed if they are different
204// from the default.
205//
206void MPhotonData::Print(Option_t *) const
207{
208 gLog << inf << endl;
209 gLog << "Num Photons: " << fNumPhotons << " from " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
210 gLog << "Wavelength: " << fWavelength << "nm" << endl;
211 gLog << "Pos X/Y Cos U/V: " << fPosX << "/" << fPosY << " " << fCosU << "/" << fCosV << endl;
212 gLog << "Time/Prod.Height: " << fTime << "ns/" << fProductionHeight << "cm" << endl;
213 if (fTag>=0)
214 gLog << "Tag: " << fTag << endl;
215 if (fWeight!=1)
216 gLog << "Weight: " << fWeight << endl;
217}
Note: See TracBrowser for help on using the repository browser.