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 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MRawRunHeader
|
---|
28 | //
|
---|
29 | // Root storage container for the RUN HEADER information
|
---|
30 | //
|
---|
31 | //
|
---|
32 | // RAW DATA FORMAT VERSION
|
---|
33 | // =======================
|
---|
34 | //
|
---|
35 | // Format Version 9:
|
---|
36 | // -----------------
|
---|
37 | // + fNumEventsRead;
|
---|
38 | //
|
---|
39 | // Format Version 8:
|
---|
40 | // -----------------
|
---|
41 | // + fNumBytesPerSample;
|
---|
42 | // + fFreqSampling;
|
---|
43 | // + fNumSignificantBits;
|
---|
44 | // * changes in MRawCrateHeader
|
---|
45 | //
|
---|
46 | // Format Version 7:
|
---|
47 | // -----------------
|
---|
48 | // - unused
|
---|
49 | //
|
---|
50 | // Format Version 6:
|
---|
51 | // -----------------
|
---|
52 | // + added CameraVersion
|
---|
53 | // + added TelescopeNumber
|
---|
54 | // + added ObservationMode
|
---|
55 | // + added dummies for TelescopeRa/Dec
|
---|
56 | //
|
---|
57 | // Format Version 5:
|
---|
58 | // -----------------
|
---|
59 | // - now the sub millisecond information of the time is valid and decoded
|
---|
60 | // which enhances the precision from 51.2us to 200ns
|
---|
61 | //
|
---|
62 | // Format Version 4:
|
---|
63 | // -----------------
|
---|
64 | // - added support for pixels with negative IDs
|
---|
65 | //
|
---|
66 | // Format Version 3:
|
---|
67 | // -----------------
|
---|
68 | // - ???
|
---|
69 | //
|
---|
70 | // Format Version 2:
|
---|
71 | // -----------------
|
---|
72 | // - removed mjd from data
|
---|
73 | // - added start time
|
---|
74 | // - added stop time
|
---|
75 | //
|
---|
76 | //
|
---|
77 | // MRawRunHeader CLASS VERSION
|
---|
78 | // ===========================
|
---|
79 | //
|
---|
80 | // Format Version 7:
|
---|
81 | // -----------------
|
---|
82 | // - added fNumEventsRead;
|
---|
83 | //
|
---|
84 | // Format Version 6:
|
---|
85 | // -----------------
|
---|
86 | // - added fNumBytesPerSample;
|
---|
87 | // - added fFreqSampling;
|
---|
88 | // - added fNumSignificantBits;
|
---|
89 | //
|
---|
90 | // Class Version 5:
|
---|
91 | // -----------------
|
---|
92 | // - for compatibility with newer camera versions
|
---|
93 | //
|
---|
94 | // Class Version 4:
|
---|
95 | // -----------------
|
---|
96 | // - added fCameraVersion
|
---|
97 | // - added fTelescopeNumber
|
---|
98 | // - changed length of fProjectName to 101
|
---|
99 | // - changed length of fSourceName to 81
|
---|
100 | //
|
---|
101 | // Class Version 3:
|
---|
102 | // ----------------
|
---|
103 | // - enhanced SourceName and ProjectName by one character, because
|
---|
104 | // without telling us the guranteed trailing \0-character has
|
---|
105 | // skipped
|
---|
106 | //
|
---|
107 | // Class Version 2:
|
---|
108 | // ----------------
|
---|
109 | // - removed fMJD, fYear, fMonth, fDay
|
---|
110 | // - added fRunStart
|
---|
111 | // - added fRunStop
|
---|
112 | //
|
---|
113 | // Class Version 1:
|
---|
114 | // ----------------
|
---|
115 | // - first implementation
|
---|
116 | //
|
---|
117 | ////////////////////////////////////////////////////////////////////////////
|
---|
118 | #include "MRawRunHeader.h"
|
---|
119 |
|
---|
120 | #include <fstream>
|
---|
121 | #include <iomanip>
|
---|
122 |
|
---|
123 | #include "MLog.h"
|
---|
124 | #include "MLogManip.h"
|
---|
125 |
|
---|
126 | #include "MArrayS.h"
|
---|
127 |
|
---|
128 | ClassImp(MRawRunHeader);
|
---|
129 |
|
---|
130 | using namespace std;
|
---|
131 |
|
---|
132 | const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
|
---|
133 | const Byte_t MRawRunHeader::kMaxFormatVersion = 9;
|
---|
134 |
|
---|
135 | // --------------------------------------------------------------------------
|
---|
136 | //
|
---|
137 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
138 | //
|
---|
139 | //
|
---|
140 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
---|
141 | {
|
---|
142 | fName = name ? name : "MRawRunHeader";
|
---|
143 | fTitle = title ? title : "Raw Run Header Information";
|
---|
144 |
|
---|
145 | fPixAssignment = new MArrayS(0);
|
---|
146 |
|
---|
147 | // Remark: If we read old MC data from a root file which do not
|
---|
148 | // yet contain one of these variable, the value given here is
|
---|
149 | // the default. Do not mix files with and without a value if the
|
---|
150 | // files with the value do not match the default!
|
---|
151 | fFormatVersion=0;
|
---|
152 | fSoftVersion=0;
|
---|
153 | fTelescopeNumber=1;
|
---|
154 | fCameraVersion=1;
|
---|
155 | fFadcType=0;
|
---|
156 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
---|
157 | fRunNumber=0;
|
---|
158 | memset(fProjectName, 0, 101);
|
---|
159 | memset(fSourceName, 0, 81);
|
---|
160 | memset(fObservationMode, 0, 61);
|
---|
161 | fSourceEpochChar[0]=0;
|
---|
162 | fSourceEpochDate=0;
|
---|
163 | fNumCrates=0;
|
---|
164 | fNumPixInCrate=0;
|
---|
165 | fNumSamplesLoGain=0;
|
---|
166 | fNumSamplesHiGain=0;
|
---|
167 | fNumEvents=0;
|
---|
168 | fNumBytesPerSample=1;
|
---|
169 | fFreqSampling=300;
|
---|
170 | fNumSignificantBits=8;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // --------------------------------------------------------------------------
|
---|
174 | //
|
---|
175 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
176 | //
|
---|
177 | MRawRunHeader::~MRawRunHeader()
|
---|
178 | {
|
---|
179 | delete fPixAssignment;
|
---|
180 | }
|
---|
181 |
|
---|
182 | // --------------------------------------------------------------------------
|
---|
183 | //
|
---|
184 | // Swap the assignment of the pixels with hardware id id0 and id1
|
---|
185 | //
|
---|
186 | Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
|
---|
187 | {
|
---|
188 | const Int_t n = fPixAssignment->GetSize();
|
---|
189 |
|
---|
190 | // Look-up-table
|
---|
191 | UShort_t *lut = fPixAssignment->GetArray();
|
---|
192 |
|
---|
193 | // Search for one of the hardware indices to get exchanged
|
---|
194 | int i;
|
---|
195 | for (i=0; i<n; i++)
|
---|
196 | if (lut[i]==id0 || lut[i]==id1)
|
---|
197 | break;
|
---|
198 |
|
---|
199 | // Check if one of the two pixels were found
|
---|
200 | if (i==n)
|
---|
201 | {
|
---|
202 | *fLog << warn << "WARNING - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
203 | *fLog << " should be exchanged, but none were found." << endl;
|
---|
204 | return kTRUE;
|
---|
205 | }
|
---|
206 |
|
---|
207 | // Store first index
|
---|
208 | const Int_t idx0 = i;
|
---|
209 |
|
---|
210 | // Search for the other hardware indices to get exchanged
|
---|
211 | for (i++; i<n; i++)
|
---|
212 | if (lut[i]==id0 || lut[i]==id1)
|
---|
213 | break;
|
---|
214 |
|
---|
215 | // Check if the second pixel was found
|
---|
216 | if (i==n)
|
---|
217 | {
|
---|
218 | *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
219 | *fLog << " should be exchanged, but only one was found." << endl;
|
---|
220 | return kFALSE;
|
---|
221 | }
|
---|
222 |
|
---|
223 | const Int_t idx1 = i;
|
---|
224 |
|
---|
225 | const Short_t p0 = lut[idx0];
|
---|
226 | const Short_t p1 = lut[idx1];
|
---|
227 |
|
---|
228 | lut[idx0] = p1;
|
---|
229 | lut[idx1] = p0;
|
---|
230 |
|
---|
231 | *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
|
---|
232 |
|
---|
233 | return kTRUE;
|
---|
234 | }
|
---|
235 |
|
---|
236 | // --------------------------------------------------------------------------
|
---|
237 | //
|
---|
238 | // This implements a fix of the pixel assignment before 25.9.2005
|
---|
239 | //
|
---|
240 | // From magic_online (the pixel numbers are hardware indices):
|
---|
241 | // --------------------------------------------------------------------------
|
---|
242 | // From: Florian Goebel <fgoebel@mppmu.mpg.de>
|
---|
243 | // Date: Sun Sep 25 2005 - 05:13:19 CEST
|
---|
244 | //
|
---|
245 | // [...]
|
---|
246 | // - problem 2: pixels were swaped
|
---|
247 | // - cause: opical fibers were wrongly connected to receiver board
|
---|
248 | // 554 <-> 559
|
---|
249 | // 555 <-> 558
|
---|
250 | // 556 <-> 557
|
---|
251 | // - action: reconnect correctly
|
---|
252 | // - result: ok now
|
---|
253 | // - comment: I don't know when this error was introduced, so backward
|
---|
254 | // correction of the data is difficult.
|
---|
255 | // Fortunately the effect is not too large since the affected 6 pixels are
|
---|
256 | // on the outermost edge of the camera
|
---|
257 | // Since this board has special pixels the optical fibers have been
|
---|
258 | // unplugged several times.
|
---|
259 | // !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
|
---|
260 | // !!!!! sure you connect them back correctly. !!!!!
|
---|
261 | // !!!!! Always contact me before you do so and if you have any doubts !!!!!
|
---|
262 | // !!!!! how to reconnect the fibers ask me. !!!!!
|
---|
263 | // These swapped pixels have only been found by chance when doing the
|
---|
264 | // flatfielding.
|
---|
265 | // [...]
|
---|
266 | //
|
---|
267 | // --------------------------------------------------------------------------
|
---|
268 | //
|
---|
269 | // MAGIC runbook CC_2006_04_22_22_28_52.rbk
|
---|
270 | //
|
---|
271 | // [2006-04-22 23:14:13]
|
---|
272 | //
|
---|
273 | // [...]
|
---|
274 | // Found 2 pairs of swapped pixels.
|
---|
275 | // We corrected swapped pixels 54<->55 in the receiver boards. We probably
|
---|
276 | // swapped today in the camera.
|
---|
277 | // We did not correct 92<-<93 which are likely swapped. Will check and correct
|
---|
278 | // tomorrow.
|
---|
279 | //
|
---|
280 | // ---
|
---|
281 | //
|
---|
282 | // comments:
|
---|
283 | // - 54<->55 were corrected but have not been swapped, hence they are swapped
|
---|
284 | // since then (run 88560 ok, run 88669 swapped; between them mostly dummy and
|
---|
285 | // test runs)
|
---|
286 | // - 92<->93 are never swapped, always ok.
|
---|
287 | //
|
---|
288 | // --------------------------------------------------------------------------
|
---|
289 | //
|
---|
290 | // MAGIC runbook CC_2006_08_28_19_40_18.rbk
|
---|
291 | //
|
---|
292 | // [2006-08-28 23:09:07]
|
---|
293 | // While doing a flatfielding we have found out that the signals for pixels
|
---|
294 | // 119 and 120 were swapped. We have fixed it by exchanging the corresponding
|
---|
295 | // fibers at the input of the receivers (not before the splitters!).
|
---|
296 | //
|
---|
297 | // ---
|
---|
298 | //
|
---|
299 | // MAGIC runbook CC_2006_08_29_15_19_14.rbk
|
---|
300 | //
|
---|
301 | // [2006-08-29 16:43:09]
|
---|
302 | // In the last hours we have found out and fixed a good number of pixels which
|
---|
303 | // were swapped: 119-120, 160-161-162 and 210-263. According to Florian,
|
---|
304 | // 160-161-162 and 210-263 were swapped since November 2005.
|
---|
305 | //
|
---|
306 | // ---
|
---|
307 | //
|
---|
308 | // mail Florian Goebel (08/30/2006 03:13 PM):
|
---|
309 | //
|
---|
310 | // As far as I can tell pixels 161 and 162 as well as 263 and 210 were
|
---|
311 | // swapped in the trigger. This leads to some inefficiency of the trigger.
|
---|
312 | // However, they were not swapped in the readout. So, you don't have to
|
---|
313 | // correct anything in the data for these pixels.
|
---|
314 | //
|
---|
315 | // ---
|
---|
316 | //
|
---|
317 | // comments:
|
---|
318 | // - 119-120 swapped between run 93251 (not swapped) and 93283 (swapped)
|
---|
319 | // (only testruns between these runs)
|
---|
320 | // corrected since run 99354 (== runbook [2006-08-28 23:09:07])
|
---|
321 | // - 160 never swapped
|
---|
322 | // - 161-162 were only swapped in the trigger, but nevertheless were
|
---|
323 | // "corrected" also in the signal. Hence signal swapped since 99354
|
---|
324 | //
|
---|
325 | // --------------------------------------------------------------------------
|
---|
326 |
|
---|
327 | Bool_t MRawRunHeader::FixAssignment()
|
---|
328 | {
|
---|
329 | if (fRunNumber>=53300 && fRunNumber<=68754)
|
---|
330 | {
|
---|
331 | if (!SwapAssignment(554, 559))
|
---|
332 | return kFALSE;
|
---|
333 | if (!SwapAssignment(555, 558))
|
---|
334 | return kFALSE;
|
---|
335 | if (!SwapAssignment(556, 557))
|
---|
336 | return kFALSE;
|
---|
337 | }
|
---|
338 |
|
---|
339 | if (fRunNumber>=93283 && fRunNumber<99354)
|
---|
340 | {
|
---|
341 | if (!SwapAssignment(119, 120))
|
---|
342 | return kFALSE;
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (fRunNumber>=99354 && fRunNumber<=101789)
|
---|
346 | {
|
---|
347 | if (!SwapAssignment(161, 162))
|
---|
348 | return kFALSE;
|
---|
349 | if (!SwapAssignment(210, 263))
|
---|
350 | return kFALSE;
|
---|
351 | }
|
---|
352 |
|
---|
353 | if (fRunNumber>=88669)
|
---|
354 | {
|
---|
355 | if (!SwapAssignment(54, 55))
|
---|
356 | return kFALSE;
|
---|
357 | }
|
---|
358 |
|
---|
359 | if (fRunNumber>=200000)
|
---|
360 | {
|
---|
361 | if (!SwapAssignment(428, 429))
|
---|
362 | return kFALSE;
|
---|
363 | }
|
---|
364 |
|
---|
365 | return kTRUE;
|
---|
366 | }
|
---|
367 |
|
---|
368 | // --------------------------------------------------------------------------
|
---|
369 | //
|
---|
370 | // Read in one run header from the binary file
|
---|
371 | //
|
---|
372 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
373 | {
|
---|
374 | //
|
---|
375 | // read one RUN HEADER from the input stream
|
---|
376 | //
|
---|
377 | fMagicNumber = 0;
|
---|
378 |
|
---|
379 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
380 |
|
---|
381 | //
|
---|
382 | // check whether the the file has the right file type or not
|
---|
383 | //
|
---|
384 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
385 | {
|
---|
386 | *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
387 | return kFALSE;
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (fMagicNumber == kMagicNumber+1)
|
---|
391 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
392 |
|
---|
393 | Byte_t dummy[16];
|
---|
394 |
|
---|
395 | // ----- File format version -----
|
---|
396 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
397 | if (fFormatVersion>kMaxFormatVersion)
|
---|
398 | {
|
---|
399 | *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
|
---|
400 | return kFALSE;
|
---|
401 | }
|
---|
402 |
|
---|
403 | if (fFormatVersion==7)
|
---|
404 | {
|
---|
405 | *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
|
---|
406 | return kFALSE;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // ----- DAQ software format version -----
|
---|
410 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
411 |
|
---|
412 |
|
---|
413 | fFadcType = 0;
|
---|
414 | if (fFormatVersion>7)
|
---|
415 | fin.read((char*)&fFadcType, 2);
|
---|
416 |
|
---|
417 | // ----- Camera geometry and telescope number -----
|
---|
418 | fCameraVersion = 1;
|
---|
419 | fTelescopeNumber = 1;
|
---|
420 | if (fFormatVersion>5)
|
---|
421 | {
|
---|
422 | fin.read((char*)&fCameraVersion, 2); // (+2)
|
---|
423 | fin.read((char*)&fTelescopeNumber, 2); // (+2)
|
---|
424 | }
|
---|
425 |
|
---|
426 | // ----- Run information -----
|
---|
427 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
428 |
|
---|
429 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
430 | fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
|
---|
431 | fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
|
---|
432 |
|
---|
433 | if (fFormatVersion>5)
|
---|
434 | fin.read((char*)fObservationMode, 60); // (+60)
|
---|
435 | // Maybe we should set fObservationMode to something
|
---|
436 | // in case of fFormatVersion<6
|
---|
437 |
|
---|
438 | // ----- Source position -----
|
---|
439 | fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
|
---|
440 | /*
|
---|
441 | if (fFormatVersion>5)
|
---|
442 | {
|
---|
443 | fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
|
---|
444 | fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
|
---|
445 | }
|
---|
446 | fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
|
---|
447 | fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
|
---|
448 | */
|
---|
449 |
|
---|
450 | // Maybe we should set these to something
|
---|
451 | // in case of fFormatVersion<6
|
---|
452 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
453 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
454 |
|
---|
455 | // ----- Old Start time -----
|
---|
456 | if (fFormatVersion<2) // Total += 10
|
---|
457 | {
|
---|
458 | UShort_t y, m, d;
|
---|
459 | fin.seekg(4, ios::cur); // Former fMJD[4],
|
---|
460 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
461 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
462 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
463 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
464 | }
|
---|
465 |
|
---|
466 | // ----- Data Geometry -----
|
---|
467 |
|
---|
468 | fin.read((char*)&fNumCrates, 2); // MUX: number of channels
|
---|
469 | fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
|
---|
470 | fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
|
---|
471 | fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
|
---|
472 |
|
---|
473 | if (fFormatVersion>8)
|
---|
474 | fin.read((char*)dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
|
---|
475 |
|
---|
476 | // ----- Number of events -----
|
---|
477 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
478 |
|
---|
479 | if (fFormatVersion>8)
|
---|
480 | fin.read((char*)&fNumEventsRead, 4); // Total=70
|
---|
481 |
|
---|
482 | // New in general features: (should they be included in new MAGIC1 formats, too?)
|
---|
483 | fNumBytesPerSample = 1; // 2 for MUX DATA
|
---|
484 | fFreqSampling = 300;
|
---|
485 | fNumSignificantBits = 8;
|
---|
486 | if (fFormatVersion>7)
|
---|
487 | {
|
---|
488 | fin.read((char*)&fNumBytesPerSample, 2);
|
---|
489 | fin.read((char*)&fFreqSampling, 2); // [MHz], 2000 for MuxFadc
|
---|
490 | fin.read((char*)&fNumSignificantBits, 1); // nominal resolution [# Bits], 10 for MuxFadc
|
---|
491 |
|
---|
492 | if (fNumBytesPerSample!=2)
|
---|
493 | {
|
---|
494 | *fLog << err << "ERROR - " << fNumBytesPerSample << " bytes per sample are not supported!" << endl;
|
---|
495 | return kFALSE;
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | // ----- Start/Stop time -----
|
---|
500 | if (fFormatVersion>1)
|
---|
501 | {
|
---|
502 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
503 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
504 | }
|
---|
505 |
|
---|
506 | //
|
---|
507 | // calculate size of array, create it and fill it
|
---|
508 | //
|
---|
509 | const Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
510 | fPixAssignment->Set(nPixel);
|
---|
511 |
|
---|
512 | // ----- Pixel Assignement -----
|
---|
513 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
514 |
|
---|
515 | if (fFormatVersion<7)
|
---|
516 | fin.read((char*)&dummy, 16);
|
---|
517 |
|
---|
518 | return FixAssignment();
|
---|
519 | }
|
---|
520 |
|
---|
521 | // --------------------------------------------------------------------------
|
---|
522 | //
|
---|
523 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
524 | // to print it as readable text.
|
---|
525 | //
|
---|
526 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
527 | {
|
---|
528 | switch (fRunType)
|
---|
529 | {
|
---|
530 | case kRTData:
|
---|
531 | return "Data";
|
---|
532 | case kRTPedestal:
|
---|
533 | return "Pedestal";
|
---|
534 | case kRTCalibration:
|
---|
535 | return "Calibration";
|
---|
536 | case kRTPointRun:
|
---|
537 | return "Point-Run";
|
---|
538 | case kRTMonteCarlo:
|
---|
539 | return "Monte Carlo";
|
---|
540 | case kRTNone:
|
---|
541 | return "<none>";
|
---|
542 | default:
|
---|
543 | return "<unknown>";
|
---|
544 | }
|
---|
545 | }
|
---|
546 |
|
---|
547 | // --------------------------------------------------------------------------
|
---|
548 | //
|
---|
549 | // print run header information on *fLog. The option 'header' supresses
|
---|
550 | // the pixel index translation table.
|
---|
551 | //
|
---|
552 | void MRawRunHeader::Print(Option_t *t) const
|
---|
553 | {
|
---|
554 | *fLog << all << endl;
|
---|
555 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
556 | switch (fMagicNumber)
|
---|
557 | {
|
---|
558 | case kMagicNumber: *fLog << "OK"; break;
|
---|
559 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
560 | default: *fLog << "Wrong!"; break;
|
---|
561 | }
|
---|
562 | *fLog << endl;
|
---|
563 | *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
|
---|
564 | *fLog << "Software=" << fSoftVersion << " ";
|
---|
565 | if (fFormatVersion>5)
|
---|
566 | *fLog << "Camera=" << fCameraVersion;
|
---|
567 | *fLog << endl;
|
---|
568 | if (fFormatVersion>5)
|
---|
569 | *fLog << "Telescope: " << fTelescopeNumber << endl;
|
---|
570 | if (fFormatVersion>7)
|
---|
571 | *fLog << "FadcType: " << fFadcType << endl;
|
---|
572 | *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
573 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
574 | if (fFormatVersion>5)
|
---|
575 | *fLog << "Observation: '" << fObservationMode << "'" << endl;
|
---|
576 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
577 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
578 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
579 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
580 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
581 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
---|
582 | if (fFormatVersion>6)
|
---|
583 | *fLog << "Sampling: " << fFreqSampling << "MHz with " << (int)fNumSignificantBits << " significant bits" << endl;
|
---|
584 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
|
---|
585 | *fLog << "Evt Counter: " << fNumEvents;
|
---|
586 | if (fFormatVersion>8)
|
---|
587 | *fLog << " (read=" << fNumEventsRead << ")";
|
---|
588 | *fLog << endl;
|
---|
589 |
|
---|
590 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
---|
591 | return;
|
---|
592 |
|
---|
593 | *fLog << inf << "Assignment:" << hex << endl;
|
---|
594 | for (int i=0; i<GetNumPixel(); i++)
|
---|
595 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
596 |
|
---|
597 | *fLog << dec << setfill(' ') << endl;
|
---|
598 | }
|
---|
599 |
|
---|
600 | // --------------------------------------------------------------------------
|
---|
601 | //
|
---|
602 | // Return the assigned pixel number for the given FADC channel
|
---|
603 | //
|
---|
604 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
605 | {
|
---|
606 | // FIXME: Do we need a range check here?
|
---|
607 | return (Short_t)(*fPixAssignment)[i];
|
---|
608 | }
|
---|
609 |
|
---|
610 | // --------------------------------------------------------------------------
|
---|
611 | //
|
---|
612 | // Return the number of pixel which are markes as connected in the
|
---|
613 | // pix assignment (!=0)
|
---|
614 | //
|
---|
615 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
616 | {
|
---|
617 | const Int_t num = fPixAssignment->GetSize();
|
---|
618 |
|
---|
619 | UShort_t rc = 0;
|
---|
620 | for (int i=0; i<num; i++)
|
---|
621 | {
|
---|
622 | if (GetPixAssignment(i)!=0)
|
---|
623 | rc++;
|
---|
624 | }
|
---|
625 | return rc;
|
---|
626 | }
|
---|
627 |
|
---|
628 | // --------------------------------------------------------------------------
|
---|
629 | //
|
---|
630 | // Return the number of pixel which are markes as connected and so-called
|
---|
631 | // 'normal' pixels in the pix assignment (>0)
|
---|
632 | //
|
---|
633 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
---|
634 | {
|
---|
635 | const Int_t num = fPixAssignment->GetSize();
|
---|
636 |
|
---|
637 | UShort_t rc = 0;
|
---|
638 | for (int i=0; i<num; i++)
|
---|
639 | {
|
---|
640 | if (GetPixAssignment(i)>0)
|
---|
641 | rc++;
|
---|
642 | }
|
---|
643 | return rc;
|
---|
644 | }
|
---|
645 |
|
---|
646 | // --------------------------------------------------------------------------
|
---|
647 | //
|
---|
648 | // Return the number of pixel which are markes as connected and so-called
|
---|
649 | // 'special' pixels in the pix assignment (<0)
|
---|
650 | //
|
---|
651 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
---|
652 | {
|
---|
653 | const Int_t num = fPixAssignment->GetSize();
|
---|
654 |
|
---|
655 | UShort_t rc = 0;
|
---|
656 | for (int i=0; i<num; i++)
|
---|
657 | {
|
---|
658 | if (GetPixAssignment(i)<0)
|
---|
659 | rc++;
|
---|
660 | }
|
---|
661 | return rc;
|
---|
662 | }
|
---|
663 |
|
---|
664 | // --------------------------------------------------------------------------
|
---|
665 | //
|
---|
666 | // Return the maximum id which exists in the pix assignment
|
---|
667 | //
|
---|
668 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
669 | {
|
---|
670 | const Int_t num = fPixAssignment->GetSize();
|
---|
671 |
|
---|
672 | Short_t rc = 0;
|
---|
673 | for (int i=0; i<num; i++)
|
---|
674 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
675 |
|
---|
676 | return rc;
|
---|
677 | }
|
---|
678 |
|
---|
679 | // --------------------------------------------------------------------------
|
---|
680 | //
|
---|
681 | // Return minus th minimum id which exists in the pix assignment
|
---|
682 | //
|
---|
683 | UShort_t MRawRunHeader::GetMinPixId() const
|
---|
684 | {
|
---|
685 | const Int_t num = fPixAssignment->GetSize();
|
---|
686 |
|
---|
687 | Short_t rc = 0;
|
---|
688 | for (int i=0; i<num; i++)
|
---|
689 | rc = TMath::Min(GetPixAssignment(i), rc);
|
---|
690 |
|
---|
691 | return (UShort_t)-rc;
|
---|
692 | }
|
---|
693 |
|
---|
694 | // --------------------------------------------------------------------------
|
---|
695 | //
|
---|
696 | // Return the number of pixel in this event.
|
---|
697 | //
|
---|
698 | // WARNING: This is the number of pixels stored in this file which is
|
---|
699 | // a multiple of the number of pixels per crate and in general
|
---|
700 | // a number which is larger than the camera size!
|
---|
701 | //
|
---|
702 | // To know the range of the pixel indices please use the geometry
|
---|
703 | // container!
|
---|
704 | //
|
---|
705 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
706 | {
|
---|
707 | return fPixAssignment->GetSize();
|
---|
708 | }
|
---|
709 |
|
---|
710 | // --------------------------------------------------------------------------
|
---|
711 | //
|
---|
712 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
713 | // This must be done _after_ the header is read, because the header doesn't
|
---|
714 | // have a fixed size (used in MRawSocketRead)
|
---|
715 | //
|
---|
716 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
717 | {
|
---|
718 | switch (fFormatVersion)
|
---|
719 | {
|
---|
720 | case 1:
|
---|
721 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
722 | case 2:
|
---|
723 | case 3:
|
---|
724 | case 4:
|
---|
725 | case 5:
|
---|
726 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
727 | case 6:
|
---|
728 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
|
---|
729 | case 7:
|
---|
730 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
|
---|
731 | }
|
---|
732 | return 0;
|
---|
733 | }
|
---|