source: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc@ 5866

Last change on this file since 5866 was 5678, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.3 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!
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[0]
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// UInt_t fCalibPattern == fTrigPattern[1]
89// -----------------------
90// Calibration Pattern used for this event
91// Each (calibration) event uses a particular LEDs configuration and
92// particular strength and colour of the continunous light.
93// Bits 1-16: Pulser slot pattern: 16 LEDs slots.
94// Bits 17: CT1 Pulser
95// Bits 21-24: Colour of Continous light source:
96// Bits 25-32: Strength of continuous light source: 256 level
97//
98// UShort_t fAllLowGainOn
99// ----------------------
100// Type of Trigger.
101// This is a Byte (8 bit) to indicated if any of the pixels
102// have a non-negligible low gain (1) or not (0)
103//
104// Class Version 2:
105// ---------------
106// - added fCalibPattern
107//
108/////////////////////////////////////////////////////////////////////////////
109#include "MRawEvtHeader.h"
110
111#include <iomanip>
112#include <fstream>
113
114#include "MLog.h"
115#include "MLogManip.h"
116
117#include "MTime.h"
118#include "MArrayB.h"
119#include "MRawRunHeader.h"
120
121ClassImp(MRawEvtHeader);
122
123using namespace std;
124
125// --------------------------------------------------------------------------
126//
127// Default constructor. Create the array to store the data.
128//
129MRawEvtHeader::MRawEvtHeader(const char *name, const char *title)
130{
131 fName = name ? name : "MRawEvtHeader";
132 fTitle = title ? title : "Raw Event Header Information";
133
134 //
135 // set all member to zero, init the pointer to ClonesArray,
136 //
137 fPixLoGainOn = new MArrayB;
138
139 Clear();
140}
141
142// --------------------------------------------------------------------------
143//
144// Destructor. Deletes the array to store pixlogainon
145//
146MRawEvtHeader::~MRawEvtHeader()
147{
148 delete fPixLoGainOn;
149}
150
151// --------------------------------------------------------------------------
152//
153// you have to init the conatainer before you can read from
154// a raw binary file
155//
156void MRawEvtHeader::InitRead(MRawRunHeader *rh, MTime *t)
157{
158 //
159 // this is the number of entries in the array like specification
160 //
161 UInt_t fN = (rh->GetNumCrates() * rh->GetNumPixInCrate() + 7) / 8;
162
163 //
164 // initialize the array
165 //
166 fPixLoGainOn->Set(fN);
167
168 //
169 // this is the conatiner where we have to store the time of the event we
170 // read from the input stream
171 //
172 fTime = t;
173}
174
175// --------------------------------------------------------------------------
176//
177// Implementation of the Clear function
178//
179// Resets all members to zero, clear the list of Pixels
180//
181void MRawEvtHeader::Clear(Option_t *)
182{
183 fDAQEvtNumber = 0;
184 fNumTrigLvl1 = 0;
185 fNumTrigLvl2 = 0;
186 fTrigPattern[0] = 0;
187 fTrigPattern[1] = 0;
188 fTrigType = 0;
189 fNumLoGainOn = 0;
190}
191
192// --------------------------------------------------------------------------
193//
194// This member function prints all Data of one Event to *fLog.
195//
196void MRawEvtHeader::Print(Option_t *o) const
197{
198 *fLog << all;
199 *fLog << "DAQEvtNr: " << dec << fDAQEvtNumber << " (";
200 *fLog << "Trigger: ";
201 *fLog << "NumLvl1=" << fNumTrigLvl1 << " ";
202 *fLog << "NumLvl2=" << fNumTrigLvl2 << " ";
203 *fLog << "Pattern=" << hex << setfill('0');
204 *fLog << setw(2) << fTrigPattern[0];
205 *fLog << setw(2) << fTrigPattern[1] << " " << dec;
206
207 *fLog << "Type=";
208 switch (fTrigType)
209 {
210 case 0:
211 *fLog << "Trigger";
212 break;
213 case 1:
214 *fLog << "Pedestal";
215 break;
216 case 2:
217 *fLog << "Calibration";
218 break;
219 case 3:
220 *fLog << "PinDiode";
221 break;
222 }
223 *fLog << ")" << endl;
224 *fLog << "Number of Lo Gains On: " << fNumLoGainOn << endl;
225
226 TString str(o);
227 str.ToLower();
228
229 if (str.Contains("nogains"))
230 return;
231
232 for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
233 {
234 for (int j=0; j<8; j++)
235 {
236 const UInt_t on = (*fPixLoGainOn)[i]&(1<<j) ? 1 : 0;
237 *fLog << on;
238 }
239 }
240 if (fPixLoGainOn->GetSize())
241 *fLog << endl;
242}
243
244// --------------------------------------------------------------------------
245//
246// Return the size in bytes of the event header.
247//
248Int_t MRawEvtHeader::GetNumBytes() const
249{
250 return 36+fPixLoGainOn->GetSize();
251}
252
253// --------------------------------------------------------------------------
254//
255// Used to set the header information. This is for MC only. NEVER, NEVER
256// use this somewhere else!
257//
258void MRawEvtHeader::FillHeader(UInt_t uiN, Float_t ulTP)
259{
260 fDAQEvtNumber = uiN;
261 fTrigPattern[0] = (UInt_t)(ulTP/4294967296.0) ;
262 fTrigPattern[1] = (UInt_t)(ulTP-fTrigPattern[0]*4294967296.0);
263}
264
265// --------------------------------------------------------------------------
266//
267// Decode the binary Time Stamp. For more detailed information see the
268// source code.
269//
270Bool_t MRawEvtHeader::DecodeTime(UInt_t abstime[2], UShort_t ver) const
271{
272 //
273 // SuperSecond (20 bits giving hh:mm:ss)
274 // ------------
275 //
276 // Reading the hours:
277 // Swap bits: 23->16, 22->17, 21->16, 20->19
278 //
279 abstime[0] =
280 abstime[0]>>7 & 0x00010000 |
281 abstime[0]>>5 & 0x00020000 |
282 abstime[0]>>3 & 0x00040000 |
283 abstime[0]>>1 & 0x00080000 |
284 abstime[0] & 0xff00ffff;
285
286 //
287 // SubSecond (24 bits giving number of clock ticks of a 5Mhz signal since
288 // the beginning of last second, i.e., number of ns with a precision of to
289 // 200 ns)
290 // ----------
291 //
292 // The last 8 bits must be flipped.
293 //
294 abstime[1] ^= 0x000000ff;
295
296 //
297 // Due to a problem with one Digital Module, three of the less significant
298 // eight bits of the subsecond are corrupted. So, until new DM's arrive to
299 // La Palma, we won't use the eight first bits of the subsecond.
300 // This reduces the precision from 200 ns to of 51.2 us. (ver<5)
301 //
302 if (ver<5)
303 abstime[1] &= 0xffffff00;
304
305 //
306 // Decode Time Stamp
307 //
308 const Byte_t h = (abstime[0]>>18 & 0x3)*10 + (abstime[0]>>14 & 0xf);
309 const Byte_t m = (abstime[0]>>11 & 0x7)*10 + (abstime[0]>> 7 & 0xf);
310 const Byte_t s = (abstime[0]>> 4 & 0x7)*10 + (abstime[0]>> 0 & 0xf);
311 const UInt_t ns = abstime[1]*200;
312
313 //
314 // Update the time stamp with the current event time.
315 // Make sure, that the time stamp was initialized correctly
316 // with the start-date/time of the run (after reading the run header)
317 //
318 if (fTime->UpdMagicTime(h, m, s, ns))
319 return kTRUE;
320
321 *fLog << warn << "WARNING - Time (" << Form("%2d:%02d:%02d,%09d", h, m, s, ns);
322 *fLog << ") in header of event #" << dec << fDAQEvtNumber << " invalid..." << endl;
323
324 return kFALSE;
325}
326
327// --------------------------------------------------------------------------
328//
329// read the EVENT HEADER information from the input stream
330// return FALSE if there is now header anymore, else TRUE
331//
332// For version>2 we expect to have a valid time-stamp in the files.
333//
334// Updates the time stamp with the current event time.
335// Make sure, that the time stamp was initialized correctly
336// with the start-date/time of the run (after reading the run header)
337//
338// Remark: This 'feature' disallows single runs of more than 11h!
339//
340Int_t MRawEvtHeader::ReadEvt(istream &fin, UShort_t ver)
341{
342 Bool_t rc = kTRUE;
343
344 fin.read((char*)&fDAQEvtNumber, 4); // Total=4
345 if (!fin)
346 return kFALSE;
347
348 UInt_t abstime[2];
349 fin.read((char*)abstime, 8); // Total=12
350
351 if (ver>2)
352 if (!DecodeTime(abstime, ver))
353 rc = kCONTINUE;
354
355 Byte_t dummy[4];
356 fin.read((char*)&fNumTrigLvl1, 4); // Total=16
357 fin.read((char*)&fNumTrigLvl2, 4); // Total=20
358 fin.read((char*)fTrigPattern, 8); // Total=28
359 fin.read((char*)&fTrigType, 2); // Total=30
360 fin.read((char*)dummy, 2); // Total=32, was fAllLoGainOn
361 fin.read((char*)fPixLoGainOn->GetArray(), fPixLoGainOn->GetSize());
362
363 fNumLoGainOn = 0;
364 for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
365 for (int j=0; j<8; j++)
366 if ((*fPixLoGainOn)[i] & (1<<j))
367 fNumLoGainOn++;
368
369 fin.read((char*)&dummy, 4);
370
371 return fin.eof() ? kFALSE : rc;
372}
373
374void MRawEvtHeader::SkipEvt(istream &fin, UShort_t ver)
375{
376 fin.seekg(GetNumBytes(), ios::cur);
377}
378
379// --------------------------------------------------------------------------
380//
381// Low level decoding of the trigger pattern.
382// The trigger pattern consists of 16 bits (8+8 bits) generated by the
383// trigger system.
384// The first 8 bits correspond to the trigger configuration before the
385// prescaling, the others after prescaling.
386// The meaning of the configuration depends on the chosen trigger table
387// (that is how the trigger has been programmed) and must be interpreted
388// at higher level by the analysis.
389// Bit structure:
390// not prscd | prscaled
391// xxxx xxxx xxxx xxxx <-- pattern (x=0,1)
392// bit 7654 3210 7654 3210
393// H L
394//
395// e.g. 1000 0000 1000 1000 (hex: 8080) is the pattern when no
396// L2 trigger selection and no prescaling is applied.
397//
398// Up to now only fTrigPattern[0] is used.
399//
400UInt_t MRawEvtHeader::GetTriggerID() const
401{
402 return fTrigPattern[0];
403}
404
405UInt_t MRawEvtHeader::GetCalibrationPattern() const
406{
407 return fTrigPattern[1];
408}
409
410// --------------------------------------------------------------------------
411//
412// return power of continous light, see class reference
413//
414UShort_t MRawEvtHeader::GetPowerOfContLight() const
415{
416 return fTrigPattern[1] & 0xff;
417}
418
419// --------------------------------------------------------------------------
420//
421// return pulser slot patter as a 17-bit-field
422//
423UInt_t MRawEvtHeader::GetPulserSlotPattern() const
424{
425 return (fTrigPattern[1] >> 16) & 0x1ffff;
426}
427
428// --------------------------------------------------------------------------
429//
430// return colour of the pulsed light as an MCalibrationCam::PulserColor_t
431// ATTENTION: In case of mulitple colours, kNONE is returned
432//
433const MCalibrationCam::PulserColor_t MRawEvtHeader::GetPulserColor() const
434{
435
436 const UInt_t pattern = GetPulserSlotPattern();
437
438 if ((pattern & kGreenAndBlue) || (pattern & kBlueAndUV) || (pattern & kGreenAndUV))
439 return MCalibrationCam::kNONE;
440
441 if (pattern & kCT1Pulser)
442 return MCalibrationCam::kCT1;
443 if (pattern & kAnyUV)
444 return MCalibrationCam::kUV;
445 if (pattern & kAnyGreen)
446 return MCalibrationCam::kGREEN;
447 if (pattern & kAnyBlue)
448 return MCalibrationCam::kBLUE;
449
450 return MCalibrationCam::kNONE;
451}
452
453
454// --------------------------------------------------------------------------
455//
456// return strength of the pulsed light
457// ATTENTION: In case of mulitple colours, kNONE is returned
458//
459Float_t MRawEvtHeader::GetPulserStrength() const
460{
461
462 const MCalibrationCam::PulserColor_t col = GetPulserColor();
463 const UInt_t pattern = GetPulserSlotPattern();
464
465 Float_t strength = 0.;
466
467 switch (col)
468 {
469 case MCalibrationCam::kNONE:
470 break;
471 case MCalibrationCam::kGREEN:
472 if (pattern & kSlot1Green)
473 strength += 5.;
474 if (pattern & kSlot2Green)
475 strength += 2.;
476 if (pattern & kSlot15Green)
477 strength += 1.;
478 if (pattern & kSlot16AttGreen)
479 strength += 0.2;
480 break;
481 case MCalibrationCam::kBLUE:
482 if (pattern & kSlot3Blue)
483 strength += 5.;
484 if (pattern & kSlot6Blue)
485 strength += 5.;
486 if (pattern & kSlot7Blue)
487 strength += 5.;
488 if (pattern & kSlot8Blue)
489 strength += 2.;
490 if (pattern & kSlot9AttBlue)
491 strength += 0.2;
492 if (pattern & kSlot10Blue)
493 strength += 0.;
494 if (pattern & kSlot11Blue)
495 strength += 1.;
496 if (pattern & kSlot14Blue)
497 strength += 5.;
498 break;
499 case MCalibrationCam::kUV:
500 if (pattern & kSlot4UV)
501 strength += 1.;
502 if (pattern & kSlot5UV)
503 strength += 2.;
504 if (pattern & kSlot12UV)
505 strength += 5.;
506 if (pattern & kSlot13UV)
507 strength += 5.;
508 break;
509 case MCalibrationCam::kCT1:
510 strength = 20.;
511 break;
512 }
513
514 return strength;
515}
516
517// --------------------------------------------------------------------------
518//
519// return color of continous light
520//
521MRawEvtHeader::CLColor_t MRawEvtHeader::GetContLightColor() const
522{
523 return (CLColor_t)((fTrigPattern[1]>>8)&0xf);
524}
Note: See TracBrowser for help on using the repository browser.