source: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc@ 9205

Last change on this file since 9205 was 9186, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.5 KB
Line 
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
120ClassImp(MCorsikaRunHeader);
121
122using namespace std;
123
124// --------------------------------------------------------------------------
125//
126// Default constructor. Creates array which stores the pixel assignment.
127//
128//
129MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
130 : fNumObsLevel(0),
131 fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
132fViewConeInnerAngle(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//
142Bool_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 char evth[4];
175 fin.read(evth, 4);
176 if (memcmp(evth, "EVTH", 4))
177 {
178 *fLog << err << "ERROR - Wrong identifier: EVTH expected." << endl;
179 return kFALSE;
180 }
181
182 Float_t g[273];
183 fin.read((char*)&g, 273*4);
184 if (fin.eof())
185 return kFALSE;
186
187 fin.seekg(-274*4, ios::cur);
188
189 const Int_t n = TMath::Nint(g[96]);
190 if (n!=1)
191 {
192 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
193 return kFALSE;
194 }
195
196 //fImpactMax = g[86];
197
198 fZdMin = g[79];
199 fZdMax = g[80];
200 fAzMin = 180-g[81];
201 fAzMax = 180-g[82];
202
203 fViewConeInnerAngle = g[151];
204 fViewConeOuterAngle = g[152];
205
206 return kTRUE;;
207}
208
209Bool_t MCorsikaRunHeader::ReadEvtEnd(istream& fin)
210{
211 char runh[4];
212 fin.read(runh, 4);
213 if (memcmp(runh, "RUNE", 4))
214 {
215 *fLog << err << "ERROR - Wrong identifier: RUNE expected." << endl;
216 return kFALSE;
217 }
218
219 Float_t f[2];
220 fin.read((char*)f, 2*4);
221
222 const UInt_t runnum = TMath::Nint(f[0]);
223 if (runnum!=fRunNumber)
224 {
225 *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
226 *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
227 return kFALSE;
228 }
229
230 fNumEvents = TMath::Nint(f[1]);
231
232 fin.seekg(270*4, ios::cur); // skip the remaining data of this block
233
234 return kTRUE;
235}
236
237Bool_t MCorsikaRunHeader::SeekEvtEnd(istream &fin)
238{
239 // Search subblockwise backward (Block: 5733*4 = 21*273*4)
240 for (int i=1; i<22; i++)
241 {
242 fin.seekg(-i*273*4, ios::end);
243
244 char runh[4];
245 fin.read(runh, 4);
246
247 if (!memcmp(runh, "RUNE", 4))
248 {
249 fin.seekg(-4, ios::cur);
250 return kTRUE;
251 }
252 }
253
254 return kFALSE;
255}
256
257// --------------------------------------------------------------------------
258//
259// print run header information on *fLog. The option 'header' supresses
260// the pixel index translation table.
261//
262void MCorsikaRunHeader::Print(Option_t *t) const
263{
264 *fLog << all << endl;
265 *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
266 if (fNumEvents>0)
267 *fLog << "Num Events: " << fNumEvents << endl;
268 *fLog << "Obs Level: ";
269 for (Byte_t i=0; i<fNumObsLevel; i++)
270 *fLog << " " << fObsLevel[i]/100. << "m";
271 *fLog << endl;
272 *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
273
274 if (fViewConeOuterAngle>0)
275 *fLog << "ViewCone: " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
276
277 if (fZdMax>=0)
278 {
279 *fLog << "Zd/Az: " << fZdMin << "deg";
280 if (fZdMin==fZdMax)
281 *fLog << " (fixed)";
282 else
283 *fLog << "-" << fZdMax << "deg";
284 *fLog << " / " << fAzMin << "deg";
285 if (fAzMin==fAzMax)
286 *fLog << " (fixed)";
287 else
288 *fLog << "-" << fAzMax << "deg";
289 *fLog << endl;
290 }
291}
292
Note: See TracBrowser for help on using the repository browser.