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@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
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 shoul 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 | /////////////////////////////////////////////////////////////////////////////
|
---|
95 | #include "MRawEvtHeader.h"
|
---|
96 |
|
---|
97 | #include <iomanip>
|
---|
98 | #include <fstream>
|
---|
99 |
|
---|
100 | #include "MLog.h"
|
---|
101 | #include "MLogManip.h"
|
---|
102 |
|
---|
103 | #include "MTime.h"
|
---|
104 | #include "MArrayB.h"
|
---|
105 | #include "MRawRunHeader.h"
|
---|
106 |
|
---|
107 | ClassImp(MRawEvtHeader);
|
---|
108 |
|
---|
109 | using namespace std;
|
---|
110 |
|
---|
111 | // --------------------------------------------------------------------------
|
---|
112 | //
|
---|
113 | // Default constructor. Create the array to store the data.
|
---|
114 | //
|
---|
115 | MRawEvtHeader::MRawEvtHeader(const char *name, const char *title)
|
---|
116 | {
|
---|
117 | fName = name ? name : "MRawEvtHeader";
|
---|
118 | fTitle = title ? title : "Raw Event Header Information";
|
---|
119 |
|
---|
120 | //
|
---|
121 | // set all member to zero, init the pointer to ClonesArray,
|
---|
122 | //
|
---|
123 | fPixLoGainOn = new MArrayB;
|
---|
124 |
|
---|
125 | Clear();
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | // --------------------------------------------------------------------------
|
---|
130 | //
|
---|
131 | // Destructor. Deletes the array to store pixlogainon
|
---|
132 | //
|
---|
133 | MRawEvtHeader::~MRawEvtHeader()
|
---|
134 | {
|
---|
135 | delete fPixLoGainOn;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // you have to init the conatainer before you can read from
|
---|
141 | // a raw binary file
|
---|
142 | //
|
---|
143 | void MRawEvtHeader::Init(MRawRunHeader *rh, MTime *t)
|
---|
144 | {
|
---|
145 | //
|
---|
146 | // this is the number of entries in the array like specification
|
---|
147 | //
|
---|
148 | UInt_t fN = (rh->GetNumCrates() * rh->GetNumPixInCrate() + 7) / 8;
|
---|
149 |
|
---|
150 | //
|
---|
151 | // initialize the array
|
---|
152 | //
|
---|
153 | fPixLoGainOn->Set(fN);
|
---|
154 |
|
---|
155 | //
|
---|
156 | // this is the conatiner where we have to store the time of the event we
|
---|
157 | // read from the input stream
|
---|
158 | //
|
---|
159 | fTime = t;
|
---|
160 | }
|
---|
161 |
|
---|
162 | // --------------------------------------------------------------------------
|
---|
163 | //
|
---|
164 | // Implementation of the Clear function
|
---|
165 | //
|
---|
166 | // Resets all members to zero, clear the list of Pixels
|
---|
167 | //
|
---|
168 | void MRawEvtHeader::Clear(Option_t *)
|
---|
169 | {
|
---|
170 | fDAQEvtNumber = 0;
|
---|
171 | fNumTrigLvl1 = 0;
|
---|
172 | fNumTrigLvl2 = 0;
|
---|
173 | fTrigPattern[0] = 0;
|
---|
174 | fTrigPattern[1] = 0;
|
---|
175 | fTrigType = 0;
|
---|
176 | fNumLoGainOn = 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // --------------------------------------------------------------------------
|
---|
180 | //
|
---|
181 | // This member function prints all Data of one Event to *fLog.
|
---|
182 | //
|
---|
183 | void MRawEvtHeader::Print(Option_t *o) const
|
---|
184 | {
|
---|
185 | *fLog << all;
|
---|
186 | *fLog << "DAQEvtNr: " << dec << fDAQEvtNumber << " (";
|
---|
187 | *fLog << "Trigger: ";
|
---|
188 | *fLog << "NumLvl1=" << fNumTrigLvl1 << " ";
|
---|
189 | *fLog << "NumLvl2=" << fNumTrigLvl2 << " ";
|
---|
190 | *fLog << "Pattern=" << hex << setfill('0');
|
---|
191 | *fLog << setw(2) << fTrigPattern[0];
|
---|
192 | *fLog << setw(2) << fTrigPattern[1] << " " << dec;
|
---|
193 |
|
---|
194 | *fLog << "Type=";
|
---|
195 | switch (fTrigType)
|
---|
196 | {
|
---|
197 | case 0:
|
---|
198 | *fLog << "Trigger";
|
---|
199 | break;
|
---|
200 | case 1:
|
---|
201 | *fLog << "Pedestal";
|
---|
202 | break;
|
---|
203 | case 2:
|
---|
204 | *fLog << "Calibration";
|
---|
205 | break;
|
---|
206 | }
|
---|
207 | *fLog << ")" << endl;
|
---|
208 | *fLog << "Number of Lo Gains On: " << fNumLoGainOn << endl;
|
---|
209 |
|
---|
210 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
---|
211 | {
|
---|
212 | for (int j=0; j<8; j++)
|
---|
213 | {
|
---|
214 | const UInt_t on = (*fPixLoGainOn)[i]&(1<<j) ? 1 : 0;
|
---|
215 | *fLog << on;
|
---|
216 | }
|
---|
217 | }
|
---|
218 | *fLog << endl;
|
---|
219 | }
|
---|
220 |
|
---|
221 | // --------------------------------------------------------------------------
|
---|
222 | //
|
---|
223 | // used to set the header information (eg. from MC)
|
---|
224 | //
|
---|
225 | void MRawEvtHeader::FillHeader(UInt_t uiN, Float_t ulTP)
|
---|
226 | {
|
---|
227 | fDAQEvtNumber = uiN;
|
---|
228 | fTrigPattern[0] = (UInt_t) (ulTP/4294967296.0) ;
|
---|
229 | fTrigPattern[1] = (UInt_t) (ulTP-fTrigPattern[0]*4294967296.0);
|
---|
230 | }
|
---|
231 |
|
---|
232 | // --------------------------------------------------------------------------
|
---|
233 | //
|
---|
234 | // read the EVENT HEADER information from the input stream
|
---|
235 | // return FALSE if there is now header anymore, else TRUE
|
---|
236 | //
|
---|
237 | int MRawEvtHeader::ReadEvt(istream &fin)
|
---|
238 | {
|
---|
239 | fin.read((char*)&fDAQEvtNumber, 4);
|
---|
240 |
|
---|
241 | UInt_t fAbsTime[2];
|
---|
242 | fin.read((char*)fAbsTime, 8);
|
---|
243 |
|
---|
244 | //
|
---|
245 | // store the time of the event in the corresponding container
|
---|
246 | //
|
---|
247 | const Double_t mhz = 9.375; // [1e6 ticks/s]
|
---|
248 | const Double_t t = (Double_t)fAbsTime[0]/mhz*1e-3; // [ns]
|
---|
249 | const Double_t ns = (UShort_t)fmod(t, 1e9);
|
---|
250 | const Double_t s = (Byte_t)fmod(t/1e9, 60);
|
---|
251 | const Double_t m = (Byte_t)fmod(t/60e9, 60);
|
---|
252 | const Double_t h = (Byte_t)(t/3600e9);
|
---|
253 |
|
---|
254 | fTime->SetTime(h, m, s, ns);
|
---|
255 | fTime->SetTime(fAbsTime[0], fAbsTime[1]);
|
---|
256 |
|
---|
257 | Byte_t dummy[4];
|
---|
258 |
|
---|
259 | fin.read((char*)&fNumTrigLvl1, 4);
|
---|
260 | fin.read((char*)&fNumTrigLvl2, 4);
|
---|
261 | fin.read((char*)fTrigPattern, 8);
|
---|
262 | fin.read((char*)&fTrigType, 2);
|
---|
263 | fin.read((char*)dummy, 2); // was fAllLoGainOn
|
---|
264 | fin.read((char*)fPixLoGainOn->GetArray(), fPixLoGainOn->GetSize());
|
---|
265 |
|
---|
266 | fNumLoGainOn = 0;
|
---|
267 | for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
|
---|
268 | for (int j=0; j<8; j++)
|
---|
269 | if ((*fPixLoGainOn)[i] & (1<<j))
|
---|
270 | fNumLoGainOn++;
|
---|
271 |
|
---|
272 | fin.read((char*)&dummy, 4);
|
---|
273 |
|
---|
274 | return !fin.eof();
|
---|
275 | }
|
---|