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 | // MRawEvtHeader
|
---|
28 | //
|
---|
29 | // One Event is a sample of FADC measurements of different Pixels
|
---|
30 | // (Photomultipliers) from the Camera of MAGIC. So all data (FADC) of the
|
---|
31 | // interesting pixels are the modules of an event. To describe pixels the
|
---|
32 | // class MRawPixel is used and the class MRawCrate to describe Crates.
|
---|
33 | // To define a single events some other data members are needed
|
---|
34 | // (Time of the events, tirgger pattern of event..)
|
---|
35 | //
|
---|
36 | // To describe one event on the level of FADC values the Class MRawEvtHeader is
|
---|
37 | // created. It has the following data members:
|
---|
38 | //
|
---|
39 | // UInt_t fDAQEvtNumber
|
---|
40 | // -----------------------
|
---|
41 | // This it the number of the Event in one
|
---|
42 | // data run. The first event in this run get
|
---|
43 | // the number zero. The next one is one bigger.
|
---|
44 | //
|
---|
45 | // Assuming that one run takes 1 hour and a
|
---|
46 | // triggerrate of 1kHz the number must be able
|
---|
47 | // to reach 3.6e6 Events. To reach this number
|
---|
48 | // you need at least 22 bits. This is the reason
|
---|
49 | // why we use an integer (of root type UInt_t)
|
---|
50 | // with a range to 4.2e9.
|
---|
51 | //
|
---|
52 | // MTime fRawEvtTime
|
---|
53 | // -------------------
|
---|
54 | // Time of the event.
|
---|
55 | // The start point of the time determination can be
|
---|
56 | // the millenium. From that start point the time is
|
---|
57 | // measured in 200ns-count. One day for example
|
---|
58 | // contains 432.e9 counts. An array of two unsigned Int is able to
|
---|
59 | // contain 1.8e19 200ns-counts. This corresponds to 41.e6
|
---|
60 | // days. This should be more than the livetime of MAGIC.
|
---|
61 | // Private member of MTime.h
|
---|
62 | //
|
---|
63 | // UInt_t fNumTrigLvl1
|
---|
64 | // --------------------
|
---|
65 | //
|
---|
66 | // Number of first level trigger
|
---|
67 | // This member counts the number of First Level Trigger
|
---|
68 | // between the last and this event. May be that due to
|
---|
69 | // dead time of the DAQ this number is different from 1.
|
---|
70 | // If the DAQ is fast enough, this value should be 1.
|
---|
71 | // This may be usefull in GammaRayBursts and if we
|
---|
72 | // apply a data reduction in the DAQ-chain, which selects
|
---|
73 | // only good events.
|
---|
74 | //
|
---|
75 | // UInt_t fNumTrigLvl2
|
---|
76 | // --------------------
|
---|
77 | //
|
---|
78 | // Number of second level trigger
|
---|
79 | // This member counts the number of Second Level Trigger
|
---|
80 | // between the last and this event.
|
---|
81 | //
|
---|
82 | // UInt_t fTrigPattern[2]
|
---|
83 | // -----------------------
|
---|
84 | // Trigger Pattern used for this event
|
---|
85 | // Each event triggers for a particular configuration and each
|
---|
86 | // configuration should have an ID (which is not fixed yet).
|
---|
87 | //
|
---|
88 | // UShort_t fAllLowGainOn
|
---|
89 | // ----------------------
|
---|
90 | // Type of Trigger.
|
---|
91 | // This is a Byte (8 bit) to indicated if any of the pixels
|
---|
92 | // have a non-negligible low gain (1) or not (0)
|
---|
93 | //
|
---|
94 | // UInt_t fCalibPattern
|
---|
95 | // --------------------
|
---|
96 | //
|
---|
97 | // Bits 1-16: Pulser slot pattern: 16 LEDs slots (see Diploma Thesis
|
---|
98 | // of Michele)
|
---|
99 | //
|
---|
100 | // Bits 17-24: Power of Continous light source: 256 level
|
---|
101 | //
|
---|
102 | // Bits 25-28: Farbe der Continuous Light: red-amber-green/blue-uv
|
---|
103 | //
|
---|
104 | // Bit 29: Calibration trigger On/off
|
---|
105 | // Bit 30: Pedestal trigger on/off
|
---|
106 | // Bit 31: PIN Diode calibration trigger on/off
|
---|
107 | //
|
---|
108 | //
|
---|
109 | // Class Version 2:
|
---|
110 | // ---------------
|
---|
111 | // - added fCalibPattern
|
---|
112 | //
|
---|
113 | /////////////////////////////////////////////////////////////////////////////
|
---|
114 | #include "MRawEvtHeader.h"
|
---|
115 |
|
---|
116 | #include <iomanip>
|
---|
117 | #include <fstream>
|
---|
118 |
|
---|
119 | #include "MLog.h"
|
---|
120 | #include "MLogManip.h"
|
---|
121 |
|
---|
122 | #include "MTime.h"
|
---|
123 | #include "MArrayB.h"
|
---|
124 | #include "MRawRunHeader.h"
|
---|
125 |
|
---|
126 | ClassImp(MRawEvtHeader);
|
---|
127 |
|
---|
128 | using namespace std;
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Default constructor. Create the array to store the data.
|
---|
133 | //
|
---|
134 | MRawEvtHeader::MRawEvtHeader(const char *name, const char *title)
|
---|
135 | {
|
---|
136 | fName = name ? name : "MRawEvtHeader";
|
---|
137 | fTitle = title ? title : "Raw Event Header Information";
|
---|
138 |
|
---|
139 | //
|
---|
140 | // set all member to zero, init the pointer to ClonesArray,
|
---|
141 | //
|
---|
142 | fPixLoGainOn = new MArrayB;
|
---|
143 |
|
---|
144 | Clear();
|
---|
145 | }
|
---|
146 |
|
---|
147 | // --------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // Destructor. Deletes the array to store pixlogainon
|
---|
150 | //
|
---|
151 | MRawEvtHeader::~MRawEvtHeader()
|
---|
152 | {
|
---|
153 | delete fPixLoGainOn;
|
---|
154 | }
|
---|
155 |
|
---|
156 | // --------------------------------------------------------------------------
|
---|
157 | //
|
---|
158 | // you have to init the conatainer before you can read from
|
---|
159 | // a raw binary file
|
---|
160 | //
|
---|
161 | void MRawEvtHeader::InitRead(MRawRunHeader *rh, MTime *t)
|
---|
162 | {
|
---|
163 | //
|
---|
164 | // this is the number of entries in the array like specification
|
---|
165 | //
|
---|
166 | UInt_t fN = (rh->GetNumCrates() * rh->GetNumPixInCrate() + 7) / 8;
|
---|
167 |
|
---|
168 | //
|
---|
169 | // initialize the array
|
---|
170 | //
|
---|
171 | fPixLoGainOn->Set(fN);
|
---|
172 |
|
---|
173 | //
|
---|
174 | // this is the conatiner where we have to store the time of the event we
|
---|
175 | // read from the input stream
|
---|
176 | //
|
---|
177 | fTime = t;
|
---|
178 | }
|
---|
179 |
|
---|
180 | // --------------------------------------------------------------------------
|
---|
181 | //
|
---|
182 | // Implementation of the Clear function
|
---|
183 | //
|
---|
184 | // Resets all members to zero, clear the list of Pixels
|
---|
185 | //
|
---|
186 | void MRawEvtHeader::Clear(Option_t *)
|
---|
187 | {
|
---|
188 | fDAQEvtNumber = 0;
|
---|
189 | fNumTrigLvl1 = 0;
|
---|
190 | fNumTrigLvl2 = 0;
|
---|
191 | fTrigPattern[0] = 0;
|
---|
192 | fTrigPattern[1] = 0;
|
---|
193 | fTrigType = 0;
|
---|
194 | fNumLoGainOn = 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 | // --------------------------------------------------------------------------
|
---|
198 | //
|
---|
199 | // This member function prints all Data of one Event to *fLog.
|
---|
200 | //
|
---|
201 | void MRawEvtHeader::Print(Option_t *o) const
|
---|
202 | {
|
---|
203 | *fLog << all;
|
---|
204 | *fLog << "DAQEvtNr: " << dec << fDAQEvtNumber << " (";
|
---|
205 | *fLog << "Trigger: ";
|
---|
206 | *fLog << "NumLvl1=" << fNumTrigLvl1 << " ";
|
---|
207 | *fLog << "NumLvl2=" << fNumTrigLvl2 << " ";
|
---|
208 | *fLog << "Pattern=" << hex << setfill('0');
|
---|
209 | *fLog << setw(2) << fTrigPattern[0];
|
---|
210 | *fLog << setw(2) << fTrigPattern[1] << " " << dec;
|
---|
211 |
|
---|
212 | *fLog << "Type=";
|
---|
213 | switch (fTrigType)
|
---|
214 | {
|
---|
215 | case 0:
|
---|
216 | *fLog << "Trigger";
|
---|
217 | break;
|
---|
218 | case 1:
|
---|
219 | *fLog << "Pedestal";
|
---|
220 | break;
|
---|
221 | case 2:
|
---|
222 | *fLog << "Calibration";
|
---|
223 | break;
|
---|
224 | }
|
---|
225 | *fLog << ")" << endl;
|
---|
226 | *fLog << "Number of Lo Gains On: " << fNumLoGainOn << endl;
|
---|
227 |
|
---|
228 | TString str(o);
|
---|
229 | str.ToLower();
|
---|
230 |
|
---|
231 | if (str.Contains("nogains"))
|
---|
232 | return;
|
---|
233 |
|
---|
234 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
---|
235 | {
|
---|
236 | for (int j=0; j<8; j++)
|
---|
237 | {
|
---|
238 | const UInt_t on = (*fPixLoGainOn)[i]&(1<<j) ? 1 : 0;
|
---|
239 | *fLog << on;
|
---|
240 | }
|
---|
241 | }
|
---|
242 | if (fPixLoGainOn->GetSize())
|
---|
243 | *fLog << endl;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // --------------------------------------------------------------------------
|
---|
247 | //
|
---|
248 | // Return the size in bytes of the event header.
|
---|
249 | //
|
---|
250 | Int_t MRawEvtHeader::GetNumBytes() const
|
---|
251 | {
|
---|
252 | return 36+fPixLoGainOn->GetSize();
|
---|
253 | }
|
---|
254 |
|
---|
255 | // --------------------------------------------------------------------------
|
---|
256 | //
|
---|
257 | // Used to set the header information. This is for MC only. NEVER, NEVER
|
---|
258 | // use this somewhere else!
|
---|
259 | //
|
---|
260 | void MRawEvtHeader::FillHeader(UInt_t uiN, Float_t ulTP)
|
---|
261 | {
|
---|
262 | fDAQEvtNumber = uiN;
|
---|
263 | fTrigPattern[0] = (UInt_t)(ulTP/4294967296.0) ;
|
---|
264 | fTrigPattern[1] = (UInt_t)(ulTP-fTrigPattern[0]*4294967296.0);
|
---|
265 | }
|
---|
266 |
|
---|
267 | // --------------------------------------------------------------------------
|
---|
268 | //
|
---|
269 | // Decode the binary Time Stamp. For more detailed information see the
|
---|
270 | // source code.
|
---|
271 | //
|
---|
272 | Bool_t MRawEvtHeader::DecodeTime(UInt_t abstime[2], UShort_t ver) const
|
---|
273 | {
|
---|
274 | //
|
---|
275 | // SuperSecond (20 bits giving hh:mm:ss)
|
---|
276 | // ------------
|
---|
277 | //
|
---|
278 | // Reading the hours:
|
---|
279 | // Swap bits: 23->16, 22->17, 21->16, 20->19
|
---|
280 | //
|
---|
281 | abstime[0] =
|
---|
282 | abstime[0]>>7 & 0x00010000 |
|
---|
283 | abstime[0]>>5 & 0x00020000 |
|
---|
284 | abstime[0]>>3 & 0x00040000 |
|
---|
285 | abstime[0]>>1 & 0x00080000 |
|
---|
286 | abstime[0] & 0xff00ffff;
|
---|
287 |
|
---|
288 | //
|
---|
289 | // SubSecond (24 bits giving number of clock ticks of a 5Mhz signal since
|
---|
290 | // the beginning of last second, i.e., number of ns with a precision of to
|
---|
291 | // 200 ns)
|
---|
292 | // ----------
|
---|
293 | //
|
---|
294 | // The last 8 bits must be flipped.
|
---|
295 | //
|
---|
296 | abstime[1] ^= 0x000000ff;
|
---|
297 |
|
---|
298 | //
|
---|
299 | // Due to a problem with one Digital Module, three of the less significant
|
---|
300 | // eight bits of the subsecond are corrupted. So, until new DM's arrive to
|
---|
301 | // La Palma, we won't use the eight first bits of the subsecond.
|
---|
302 | // This reduces the precision from 200 ns to of 51.2 us. (ver<5)
|
---|
303 | //
|
---|
304 | if (ver<5)
|
---|
305 | abstime[1] &= 0xffffff00;
|
---|
306 |
|
---|
307 | //
|
---|
308 | // Decode Time Stamp
|
---|
309 | //
|
---|
310 | const Byte_t h = (abstime[0]>>18 & 0x3)*10 + (abstime[0]>>14 & 0xf);
|
---|
311 | const Byte_t m = (abstime[0]>>11 & 0x7)*10 + (abstime[0]>> 7 & 0xf);
|
---|
312 | const Byte_t s = (abstime[0]>> 4 & 0x7)*10 + (abstime[0]>> 0 & 0xf);
|
---|
313 | const UInt_t ns = abstime[1]*200;
|
---|
314 |
|
---|
315 | //
|
---|
316 | // Update the time stamp with the current event time.
|
---|
317 | // Make sure, that the time stamp was initialized correctly
|
---|
318 | // with the start-date/time of the run (after reading the run header)
|
---|
319 | //
|
---|
320 | if (fTime->UpdMagicTime(h, m, s, ns))
|
---|
321 | return kTRUE;
|
---|
322 |
|
---|
323 | *fLog << warn << "WARNING - Time (" << Form("%2d:%02d:%02d,%09d", h, m, s, ns);
|
---|
324 | *fLog << ") in header of event #" << dec << fDAQEvtNumber << " invalid..." << endl;
|
---|
325 |
|
---|
326 | return kFALSE;
|
---|
327 | }
|
---|
328 |
|
---|
329 | // --------------------------------------------------------------------------
|
---|
330 | //
|
---|
331 | // read the EVENT HEADER information from the input stream
|
---|
332 | // return FALSE if there is now header anymore, else TRUE
|
---|
333 | //
|
---|
334 | // For version>2 we expect to have a valid time-stamp in the files.
|
---|
335 | //
|
---|
336 | // Updates the time stamp with the current event time.
|
---|
337 | // Make sure, that the time stamp was initialized correctly
|
---|
338 | // with the start-date/time of the run (after reading the run header)
|
---|
339 | //
|
---|
340 | // Remark: This 'feature' disallows single runs of more than 11h!
|
---|
341 | //
|
---|
342 | Int_t MRawEvtHeader::ReadEvt(istream &fin, UShort_t ver)
|
---|
343 | {
|
---|
344 | Bool_t rc = kTRUE;
|
---|
345 |
|
---|
346 | fin.read((char*)&fDAQEvtNumber, 4); // Total=4
|
---|
347 | if (!fin)
|
---|
348 | return kFALSE;
|
---|
349 |
|
---|
350 | UInt_t abstime[2];
|
---|
351 | fin.read((char*)abstime, 8); // Total=12
|
---|
352 |
|
---|
353 | if (ver>2)
|
---|
354 | if (!DecodeTime(abstime, ver))
|
---|
355 | rc = kCONTINUE;
|
---|
356 |
|
---|
357 | Byte_t dummy[4];
|
---|
358 | fin.read((char*)&fNumTrigLvl1, 4); // Total=16
|
---|
359 | fin.read((char*)&fNumTrigLvl2, 4); // Total=20
|
---|
360 | fin.read((char*)fTrigPattern, 8); // Total=28
|
---|
361 | fin.read((char*)&fTrigType, 2); // Total=30
|
---|
362 | fin.read((char*)dummy, 2); // Total=32, was fAllLoGainOn
|
---|
363 | fin.read((char*)fPixLoGainOn->GetArray(), fPixLoGainOn->GetSize());
|
---|
364 |
|
---|
365 | fNumLoGainOn = 0;
|
---|
366 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
---|
367 | for (int j=0; j<8; j++)
|
---|
368 | if ((*fPixLoGainOn)[i] & (1<<j))
|
---|
369 | fNumLoGainOn++;
|
---|
370 |
|
---|
371 | fin.read((char*)&dummy, 4);
|
---|
372 |
|
---|
373 | return fin.eof() ? kFALSE : rc;
|
---|
374 | }
|
---|
375 |
|
---|
376 | void MRawEvtHeader::SkipEvt(istream &fin, UShort_t ver)
|
---|
377 | {
|
---|
378 | fin.seekg(GetNumBytes(), ios::cur);
|
---|
379 | }
|
---|
380 |
|
---|
381 | // --------------------------------------------------------------------------
|
---|
382 | //
|
---|
383 | // Low level decoding of the trigger pattern.
|
---|
384 | // The trigger pattern consists of 16 bits (8+8 bits) generated by the
|
---|
385 | // trigger system.
|
---|
386 | // The first 8 bits correspond to the trigger configuration before the
|
---|
387 | // prescaling, the others after prescaling.
|
---|
388 | // The meaning of the configuration depends on the chosen trigger table
|
---|
389 | // (that is how the trigger has been programmed) and must be interpreted
|
---|
390 | // at higher level by the analysis.
|
---|
391 | // Bit structure:
|
---|
392 | // not prscd | prscaled
|
---|
393 | // xxxx xxxx xxxx xxxx <-- pattern (x=0,1)
|
---|
394 | // bit 7654 3210 7654 3210
|
---|
395 | // H L
|
---|
396 | //
|
---|
397 | // e.g. 1000 0000 1000 1000 (hex: 8080) is the pattern when no
|
---|
398 | // L2 trigger selection and no prescaling is applied.
|
---|
399 | //
|
---|
400 | // Up to now only fTrigPattern[0] is used.
|
---|
401 | //
|
---|
402 | UInt_t MRawEvtHeader::GetTriggerID() const
|
---|
403 | {
|
---|
404 | return fTrigPattern[0];
|
---|
405 | }
|
---|
406 |
|
---|
407 | UInt_t MRawEvtHeader::GetCalibrationPattern() const
|
---|
408 | {
|
---|
409 | return fTrigPattern[1];
|
---|
410 | }
|
---|
411 | /*
|
---|
412 | // --------------------------------------------------------------------------
|
---|
413 | //
|
---|
414 | // return pulser slot patter, see class reference
|
---|
415 | //
|
---|
416 | UShort_t MRawEvtHeader::GetPulserSlotPattern() const
|
---|
417 | {
|
---|
418 | return fTrigPattern[1] & 0xffff;
|
---|
419 | }
|
---|
420 |
|
---|
421 | // --------------------------------------------------------------------------
|
---|
422 | //
|
---|
423 | // return power of continous light, see class reference
|
---|
424 | //
|
---|
425 | Byte_t MRawEvtHeader::GetPowerOfContLight() const
|
---|
426 | {
|
---|
427 | return (fTrigPattern[1]<<16) & 0xff;
|
---|
428 | }
|
---|
429 |
|
---|
430 | // --------------------------------------------------------------------------
|
---|
431 | //
|
---|
432 | // return color of continous light, see class reference
|
---|
433 | //
|
---|
434 | MRawEvtHeader::CalibCol_t MRawEvtHeader::GetContLedColor() const
|
---|
435 | {
|
---|
436 | return (CalibCol_t)((fTrigPattern[1]<<24)&0xf);
|
---|
437 | }
|
---|
438 | */
|
---|