1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC 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 appear 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 | Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
|
---|
20 |
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MCorsikaRunHeader
|
---|
29 | //
|
---|
30 | // Root storage container for the RUN HEADER information
|
---|
31 | //
|
---|
32 | //
|
---|
33 | // RAW DATA FORMAT VERSION
|
---|
34 | // =======================
|
---|
35 | //
|
---|
36 | // Format Version 8:
|
---|
37 | // -----------------
|
---|
38 | // + fNumBytesPerSample;
|
---|
39 | // + fFreqSampling;
|
---|
40 | // + fNumSignificantBits;
|
---|
41 | // * changes in MRawCrateHeader
|
---|
42 | //
|
---|
43 | // Format Version 7:
|
---|
44 | // -----------------
|
---|
45 | // - unused
|
---|
46 | //
|
---|
47 | // Format Version 6:
|
---|
48 | // -----------------
|
---|
49 | // + added CameraVersion
|
---|
50 | // + added TelescopeNumber
|
---|
51 | // + added ObservationMode
|
---|
52 | // + added dummies for TelescopeRa/Dec
|
---|
53 | //
|
---|
54 | // Format Version 5:
|
---|
55 | // -----------------
|
---|
56 | // - now the sub millisecond information of the time is valid and decoded
|
---|
57 | // which enhances the precision from 51.2us to 200ns
|
---|
58 | //
|
---|
59 | // Format Version 4:
|
---|
60 | // -----------------
|
---|
61 | // - added support for pixels with negative IDs
|
---|
62 | //
|
---|
63 | // Format Version 3:
|
---|
64 | // -----------------
|
---|
65 | // - ???
|
---|
66 | //
|
---|
67 | // Format Version 2:
|
---|
68 | // -----------------
|
---|
69 | // - removed mjd from data
|
---|
70 | // - added start time
|
---|
71 | // - added stop time
|
---|
72 | //
|
---|
73 | //
|
---|
74 | // MCorsikaRunHeader CLASS VERSION
|
---|
75 | // ===========================
|
---|
76 | //
|
---|
77 | // Format Version 6:
|
---|
78 | // -----------------
|
---|
79 | // - added fNumBytesPerSample;
|
---|
80 | // - added fFreqSampling;
|
---|
81 | // - added fNumSignificantBits;
|
---|
82 | //
|
---|
83 | // Class Version 5:
|
---|
84 | // -----------------
|
---|
85 | // - for compatibility with newer camera versions
|
---|
86 | //
|
---|
87 | // Class Version 4:
|
---|
88 | // -----------------
|
---|
89 | // - added fCameraVersion
|
---|
90 | // - added fTelescopeNumber
|
---|
91 | // - changed length of fProjectName to 101
|
---|
92 | // - changed length of fSourceName to 81
|
---|
93 | //
|
---|
94 | // Class Version 3:
|
---|
95 | // ----------------
|
---|
96 | // - enhanced SourceName and ProjectName by one character, because
|
---|
97 | // without telling us the guranteed trailing \0-character has
|
---|
98 | // skipped
|
---|
99 | //
|
---|
100 | // Class Version 2:
|
---|
101 | // ----------------
|
---|
102 | // - removed fMJD, fYear, fMonth, fDay
|
---|
103 | // - added fRunStart
|
---|
104 | // - added fRunStop
|
---|
105 | //
|
---|
106 | // Class Version 1:
|
---|
107 | // ----------------
|
---|
108 | // - first implementation
|
---|
109 | //
|
---|
110 | ////////////////////////////////////////////////////////////////////////////
|
---|
111 |
|
---|
112 | #include "MCorsikaRunHeader.h"
|
---|
113 |
|
---|
114 | #include <fstream>
|
---|
115 | #include <iomanip>
|
---|
116 |
|
---|
117 | #include "MLog.h"
|
---|
118 | #include "MLogManip.h"
|
---|
119 |
|
---|
120 | ClassImp(MCorsikaRunHeader);
|
---|
121 |
|
---|
122 | using namespace std;
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
127 | //
|
---|
128 | //
|
---|
129 | MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
|
---|
130 | : fNumObsLevel(0),
|
---|
131 | fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
|
---|
132 | fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
|
---|
133 | {
|
---|
134 | fName = name ? name : "MCorsikaRunHeader";
|
---|
135 | fTitle = title ? title : "Raw Run Header Information";
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Read in one run header from the binary file
|
---|
141 | //
|
---|
142 | Bool_t MCorsikaRunHeader::ReadEvt(istream& fin)
|
---|
143 | {
|
---|
144 | char runh[4];
|
---|
145 | fin.read(runh, 4);
|
---|
146 | if (memcmp(runh, "RUNH", 4))
|
---|
147 | {
|
---|
148 | *fLog << err << "ERROR - Wrong identifier: RUNH expected." << endl;
|
---|
149 | return kFALSE;
|
---|
150 | }
|
---|
151 |
|
---|
152 | Float_t f[68];
|
---|
153 | fin.read((char*)f, 68);
|
---|
154 |
|
---|
155 | fRunNumber = TMath::Nint(f[0]);
|
---|
156 | fNumEvents = 0;
|
---|
157 |
|
---|
158 | fRunStart.SetCorsikaTime(f[1]);
|
---|
159 |
|
---|
160 | fProgramVersion = f[2]; //FIXME: INT???
|
---|
161 | fNumObsLevel = TMath::Nint(f[3]);
|
---|
162 |
|
---|
163 | memset(fObsLevel, 0, 10*4);
|
---|
164 | memcpy(fObsLevel, f+4, fNumObsLevel*4);
|
---|
165 |
|
---|
166 | fSlopeSpectrum = f[14];
|
---|
167 | fEnergyMin = f[15];
|
---|
168 | fEnergyMax = f[16];
|
---|
169 |
|
---|
170 | fin.seekg(1020, ios::cur); // skip the remaining data of this block
|
---|
171 |
|
---|
172 | // -------------------- Read first event header -------------------
|
---|
173 |
|
---|
174 | // f[76] Cherenkov flag:
|
---|
175 | // bit(1) : CERENKOV option compiled in
|
---|
176 | // bit(2) : IACT option compiled in
|
---|
177 | // bit(3) : CEFFIC option compiled in
|
---|
178 | // bit(4) : ATMEXT option compiled in
|
---|
179 | // bit(5) : ATMEXT option used with refaction enabled
|
---|
180 | // bit(6) : VOLUMEDET option compiled in
|
---|
181 | // bit(7) : CURVED option compiled in
|
---|
182 | // bit(9) : SLATN option compiled in
|
---|
183 | // 11-21 : table number for externam athmosphere (but<1024)
|
---|
184 | // f[78] Curved athmosphere? (0=flat, 1=curved)
|
---|
185 |
|
---|
186 | // f[80] lower edge of theta in °
|
---|
187 | // f[81] upper edge of theta in °
|
---|
188 | // f[82] lower edge of phi in °
|
---|
189 | // f[83] upper edge of phi in °
|
---|
190 | // f[84] cherenkov bunch size
|
---|
191 |
|
---|
192 | // f[93] flag for additinal muon information of particle output file
|
---|
193 |
|
---|
194 | // f[95] Cherenkov bandwidth lower end in nm
|
---|
195 | // f[96] Cherenkov bandwidth upper end in nm
|
---|
196 |
|
---|
197 | // f[97] Numbr i of uses of each cherenkov event
|
---|
198 | // f[145] Muon multiple scattering flag
|
---|
199 | // f[152] !! inner angle of view cone (°)
|
---|
200 | // f[153] !! outer angle of view cone (°)
|
---|
201 | // f[156] altitude of horizontal shower axis
|
---|
202 |
|
---|
203 | char evth[4];
|
---|
204 | fin.read(evth, 4);
|
---|
205 | if (memcmp(evth, "EVTH", 4))
|
---|
206 | {
|
---|
207 | *fLog << err << "ERROR - Wrong identifier: EVTH expected." << endl;
|
---|
208 | return kFALSE;
|
---|
209 | }
|
---|
210 |
|
---|
211 | Float_t g[273];
|
---|
212 | fin.read((char*)&g, 273*4);
|
---|
213 | if (fin.eof())
|
---|
214 | return kFALSE;
|
---|
215 |
|
---|
216 | fin.seekg(-274*4, ios::cur);
|
---|
217 |
|
---|
218 | const Int_t n = TMath::Nint(g[96]);
|
---|
219 | if (n!=1)
|
---|
220 | {
|
---|
221 | *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
|
---|
222 | return kFALSE;
|
---|
223 | }
|
---|
224 |
|
---|
225 | //fImpactMax = g[86];
|
---|
226 |
|
---|
227 | fZdMin = g[79];
|
---|
228 | fZdMax = g[80];
|
---|
229 | fAzMin = 180-g[81];
|
---|
230 | fAzMax = 180-g[82];
|
---|
231 |
|
---|
232 | fWavelengthMin = g[95];
|
---|
233 | fWavelengthMax = g[96];
|
---|
234 |
|
---|
235 | fViewConeInnerAngle = g[151];
|
---|
236 | fViewConeOuterAngle = g[152];
|
---|
237 |
|
---|
238 | return kTRUE;;
|
---|
239 | }
|
---|
240 |
|
---|
241 | Bool_t MCorsikaRunHeader::ReadEvtEnd(istream& fin)
|
---|
242 | {
|
---|
243 | char runh[4];
|
---|
244 | fin.read(runh, 4);
|
---|
245 | if (memcmp(runh, "RUNE", 4))
|
---|
246 | {
|
---|
247 | *fLog << err << "ERROR - Wrong identifier: RUNE expected." << endl;
|
---|
248 | return kFALSE;
|
---|
249 | }
|
---|
250 |
|
---|
251 | Float_t f[2];
|
---|
252 | fin.read((char*)f, 2*4);
|
---|
253 |
|
---|
254 | const UInt_t runnum = TMath::Nint(f[0]);
|
---|
255 | if (runnum!=fRunNumber)
|
---|
256 | {
|
---|
257 | *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
|
---|
258 | *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
|
---|
259 | return kFALSE;
|
---|
260 | }
|
---|
261 |
|
---|
262 | fNumEvents = TMath::Nint(f[1]);
|
---|
263 |
|
---|
264 | fin.seekg(270*4, ios::cur); // skip the remaining data of this block
|
---|
265 |
|
---|
266 | return kTRUE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | Bool_t MCorsikaRunHeader::SeekEvtEnd(istream &fin)
|
---|
270 | {
|
---|
271 | // Search subblockwise backward (Block: 5733*4 = 21*273*4)
|
---|
272 | for (int i=1; i<22; i++)
|
---|
273 | {
|
---|
274 | fin.seekg(-i*273*4, ios::end);
|
---|
275 |
|
---|
276 | char runh[4];
|
---|
277 | fin.read(runh, 4);
|
---|
278 |
|
---|
279 | if (!memcmp(runh, "RUNE", 4))
|
---|
280 | {
|
---|
281 | fin.seekg(-4, ios::cur);
|
---|
282 | return kTRUE;
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | return kFALSE;
|
---|
287 | }
|
---|
288 |
|
---|
289 | // --------------------------------------------------------------------------
|
---|
290 | //
|
---|
291 | // print run header information on *fLog. The option 'header' supresses
|
---|
292 | // the pixel index translation table.
|
---|
293 | //
|
---|
294 | void MCorsikaRunHeader::Print(Option_t *t) const
|
---|
295 | {
|
---|
296 | *fLog << all << endl;
|
---|
297 | *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
|
---|
298 | if (fNumEvents>0)
|
---|
299 | *fLog << "Num Events: " << fNumEvents << endl;
|
---|
300 | *fLog << "Obs Level: ";
|
---|
301 | for (Byte_t i=0; i<fNumObsLevel; i++)
|
---|
302 | *fLog << " " << fObsLevel[i]/100. << "m";
|
---|
303 | *fLog << endl;
|
---|
304 | *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
|
---|
305 |
|
---|
306 | if (fViewConeOuterAngle>0)
|
---|
307 | *fLog << "ViewCone: " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
|
---|
308 |
|
---|
309 | if (fZdMax>=0)
|
---|
310 | {
|
---|
311 | *fLog << "Zd/Az: " << fZdMin << "deg";
|
---|
312 | if (fZdMin==fZdMax)
|
---|
313 | *fLog << " (fixed)";
|
---|
314 | else
|
---|
315 | *fLog << "-" << fZdMax << "deg";
|
---|
316 | *fLog << " / " << fAzMin << "deg";
|
---|
317 | if (fAzMin==fAzMax)
|
---|
318 | *fLog << " (fixed)";
|
---|
319 | else
|
---|
320 | *fLog << "-" << fAzMax << "deg";
|
---|
321 | *fLog << endl;
|
---|
322 | }
|
---|
323 | }
|
---|
324 |
|
---|