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 | // MRawEvtData
|
---|
28 | //
|
---|
29 | // Storage container to store the raw FADC values.
|
---|
30 | //
|
---|
31 | // MArrayS fHiGainPixId
|
---|
32 | // ---------------------
|
---|
33 | // Array of Pixel Numbers for their high voltage channel in the order the
|
---|
34 | // FADC values are stored in fHiGainFadcSamples
|
---|
35 | //
|
---|
36 | // MArrayB fHiGainFadcSaples
|
---|
37 | // -------------------------
|
---|
38 | // FADC samples (hi gain) of all pixels
|
---|
39 | //
|
---|
40 | // MArrayS fLoGainPixId
|
---|
41 | // --------------------
|
---|
42 | // see fHiGainPixId
|
---|
43 | //
|
---|
44 | // MArrayB fLoGainFadcSamples
|
---|
45 | // --------------------------
|
---|
46 | // see fHiGainFadcSaples
|
---|
47 | //
|
---|
48 | /////////////////////////////////////////////////////////////////////////////
|
---|
49 |
|
---|
50 | #include "MRawEvtData.h"
|
---|
51 |
|
---|
52 | #include <fstream.h>
|
---|
53 |
|
---|
54 | #include <TH1.h>
|
---|
55 | #include <TGraph.h>
|
---|
56 | #include <TArrayC.h>
|
---|
57 |
|
---|
58 | #include "MLog.h"
|
---|
59 | #include "MLogManip.h"
|
---|
60 |
|
---|
61 | #include "MArrayS.h"
|
---|
62 | #include "MArrayB.h"
|
---|
63 | #include "MRawRunHeader.h"
|
---|
64 |
|
---|
65 | ClassImp(MRawEvtData);
|
---|
66 |
|
---|
67 | // --------------------------------------------------------------------------
|
---|
68 | //
|
---|
69 | // Default constructor. It initializes all arrays with zero size.
|
---|
70 | //
|
---|
71 | MRawEvtData::MRawEvtData(const char *name, const char *title)
|
---|
72 | {
|
---|
73 | fName = name ? name : "MRawEvtData";
|
---|
74 | fTitle = title ? title : "Raw Event Data Information";
|
---|
75 |
|
---|
76 | InitArrays();
|
---|
77 | }
|
---|
78 |
|
---|
79 | // --------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // Destructor. Deletes all the arrays.
|
---|
82 | //
|
---|
83 | MRawEvtData::~MRawEvtData()
|
---|
84 | {
|
---|
85 | DeleteArrays();
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | // reset all arrays
|
---|
91 | //
|
---|
92 | void MRawEvtData::Clear(Option_t *)
|
---|
93 | {
|
---|
94 | /*
|
---|
95 | FIXME:
|
---|
96 | Is Reset (set all entries to zero) what you want to do
|
---|
97 | or Set(0) (delete the array)
|
---|
98 | */
|
---|
99 | fHiGainPixId->Reset();
|
---|
100 | fLoGainPixId->Reset();
|
---|
101 | fHiGainFadcSamples->Reset();
|
---|
102 | fLoGainFadcSamples->Reset();
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // return the number of hi gain samples per pixel
|
---|
108 | //
|
---|
109 | Byte_t MRawEvtData::GetNumHiGainSamples() const
|
---|
110 | {
|
---|
111 | return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // return the number of lo gain samples per pixel
|
---|
117 | //
|
---|
118 | Byte_t MRawEvtData::GetNumLoGainSamples() const
|
---|
119 | {
|
---|
120 | return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // return the number of stored pixel
|
---|
126 | //
|
---|
127 | UShort_t MRawEvtData::GetNumPixels() const
|
---|
128 | {
|
---|
129 | return fHiGainPixId->GetSize();
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | // --------------------------------------------------------------------------
|
---|
134 | //
|
---|
135 | // Print out the onformation to *fLog.
|
---|
136 | // Options:
|
---|
137 | // "hex" Prints the time slices hexadecimal (default)
|
---|
138 | // "dec" Prints the time slices decimal
|
---|
139 | //
|
---|
140 | void MRawEvtData::Print(Option_t *opt) const
|
---|
141 | {
|
---|
142 | //
|
---|
143 | // print fadc inforation to screen
|
---|
144 | // Possible Options:
|
---|
145 | // - DEC: Print values decimal instead of hexadecimal (default)
|
---|
146 | //
|
---|
147 | const Byte_t nHiSamp = GetNumHiGainSamples();
|
---|
148 | const Byte_t nLoSamp = GetNumLoGainSamples();
|
---|
149 |
|
---|
150 | const UShort_t nHiPix = fHiGainPixId->GetSize();;
|
---|
151 | const UShort_t nLoPix = fLoGainPixId->GetSize();;
|
---|
152 |
|
---|
153 | fLog->unsetf(ios::showbase);
|
---|
154 |
|
---|
155 | *fLog << dec << all;
|
---|
156 | *fLog << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
|
---|
157 | *fLog << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples";;
|
---|
158 |
|
---|
159 | TString str(opt);
|
---|
160 | Int_t manip = str.Contains("dec", TString::kIgnoreCase);
|
---|
161 |
|
---|
162 | Int_t l=0;
|
---|
163 | for (int i=0; i<nHiPix; i++)
|
---|
164 | {
|
---|
165 | *fLog << endl;
|
---|
166 | *fLog << " " << setfill(' ') << setw(3) << dec << i << ": ";
|
---|
167 | *fLog << (manip?dec:hex) << flush;
|
---|
168 |
|
---|
169 | if (!manip)
|
---|
170 | *fLog << setfill('0');
|
---|
171 |
|
---|
172 | for (int j=0; j<nHiSamp; j++)
|
---|
173 | {
|
---|
174 | *fLog << setw(manip?3:2);
|
---|
175 | *fLog << ((UShort_t)(*fHiGainFadcSamples)[j+i*nHiSamp]&0xff);
|
---|
176 | if (manip)
|
---|
177 | *fLog << ' ';
|
---|
178 | *fLog << flush;
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (!(l<nLoPix && (*fLoGainPixId)[l]==(*fHiGainPixId)[i]))
|
---|
182 | continue;
|
---|
183 |
|
---|
184 | if (manip)
|
---|
185 | *fLog << "/ ";
|
---|
186 |
|
---|
187 | for (int j=0; j<nLoSamp; j++)
|
---|
188 | {
|
---|
189 | *fLog << setw(manip?3:2);
|
---|
190 | *fLog << ((UShort_t)(*fLoGainFadcSamples)[j+i*nLoSamp]&0xff);
|
---|
191 | if (manip)
|
---|
192 | *fLog << ' ';
|
---|
193 | *fLog << flush;
|
---|
194 | }
|
---|
195 | l++;
|
---|
196 | }
|
---|
197 | *fLog << endl;
|
---|
198 | }
|
---|
199 |
|
---|
200 | // --------------------------------------------------------------------------
|
---|
201 | //
|
---|
202 | // Draw a pixel. A Histogram or Graph is created and it's draw function is
|
---|
203 | // called.
|
---|
204 | // Options:
|
---|
205 | // "GRAPH" A graph is drawn
|
---|
206 | // "HIST" A histogram is drawn
|
---|
207 | // number The pixel with the given number is drawn
|
---|
208 | //
|
---|
209 | void MRawEvtData::Draw(Option_t *opt)
|
---|
210 | {
|
---|
211 | if (GetNumPixels()==0)
|
---|
212 | {
|
---|
213 | *fLog << warn << "Sorry, no pixel to draw!" << endl;
|
---|
214 | return;
|
---|
215 | }
|
---|
216 |
|
---|
217 | TString str(opt);
|
---|
218 |
|
---|
219 | UInt_t num = 0;
|
---|
220 |
|
---|
221 | if (str.BeginsWith("GRAPH", TString::kIgnoreCase))
|
---|
222 | {
|
---|
223 | if (str.Length()>5)
|
---|
224 | sscanf(&str[5], "%d", &num);
|
---|
225 |
|
---|
226 | if (num>=GetNumPixels())
|
---|
227 | num= GetNumPixels();
|
---|
228 |
|
---|
229 | *fLog << inf << "Drawing Graph: Pixel #" << num << " of " << (int)GetNumPixels() << endl;
|
---|
230 |
|
---|
231 | const Int_t n = GetNumHiGainSamples();
|
---|
232 |
|
---|
233 | Float_t *x = new Float_t[n];
|
---|
234 | Float_t *y = new Float_t[n];
|
---|
235 |
|
---|
236 | for (int i=0; i<n; i++)
|
---|
237 | {
|
---|
238 | x[i] = i;
|
---|
239 | y[i] = (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()];
|
---|
240 | }
|
---|
241 |
|
---|
242 | TGraph *graph = new TGraph(n, x, y);
|
---|
243 | graph->SetMaximum(256);
|
---|
244 | graph->SetMinimum(0);
|
---|
245 |
|
---|
246 | graph->SetBit(kCanDelete);
|
---|
247 | graph->Draw("AC*");
|
---|
248 |
|
---|
249 | TH1F *hist = graph->GetHistogram();
|
---|
250 |
|
---|
251 | hist->SetXTitle("Time/FADC Slices");
|
---|
252 | hist->SetYTitle("Signal/FADC Units");
|
---|
253 |
|
---|
254 | return;
|
---|
255 | }
|
---|
256 |
|
---|
257 | if (str.BeginsWith("HIST", TString::kIgnoreCase))
|
---|
258 | {
|
---|
259 | *fLog << "Length: " << str.Length() << endl;
|
---|
260 |
|
---|
261 | if (str.Length()>4)
|
---|
262 | sscanf(&str[4], "%d", &num);
|
---|
263 |
|
---|
264 | if (num>=GetNumPixels())
|
---|
265 | num= GetNumPixels();
|
---|
266 |
|
---|
267 | *fLog << "Drawing Histogram of Pixel " << num << endl;
|
---|
268 |
|
---|
269 | const Int_t n = GetNumHiGainSamples();
|
---|
270 |
|
---|
271 | char *name = new char[16];
|
---|
272 |
|
---|
273 | sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
|
---|
274 |
|
---|
275 | TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
|
---|
276 | hist->SetXTitle("Time/FADC Slices");
|
---|
277 | hist->SetYTitle("Signal/FADC Units");
|
---|
278 |
|
---|
279 | for (int i=0; i<n; i++)
|
---|
280 | hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
|
---|
281 |
|
---|
282 | hist->SetBit(kCanDelete);
|
---|
283 | hist->Draw();
|
---|
284 |
|
---|
285 | return;
|
---|
286 | }
|
---|
287 |
|
---|
288 | *fLog << warn << dbginf << "Warning - You must specify either 'GRAPH' or 'HIST'" << endl;
|
---|
289 | }
|
---|
290 |
|
---|
291 | // --------------------------------------------------------------------------
|
---|
292 | //
|
---|
293 | // Deletes all arrays describing the pixel Id and Samples in pixels.
|
---|
294 | // The flag is for future usage.
|
---|
295 | //
|
---|
296 | void MRawEvtData::DeletePixels(Bool_t flag)
|
---|
297 | {
|
---|
298 | if (fRunHeader && flag)
|
---|
299 | {
|
---|
300 | const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
|
---|
301 |
|
---|
302 | if (fArraySize == npix)
|
---|
303 | {
|
---|
304 | fPosInArray = 0;
|
---|
305 | return;
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | DeleteArrays();
|
---|
310 | InitArrays(flag);
|
---|
311 | }
|
---|
312 |
|
---|
313 | // --------------------------------------------------------------------------
|
---|
314 | //
|
---|
315 | // Deletes all the arrays
|
---|
316 | //
|
---|
317 | void MRawEvtData::DeleteArrays()
|
---|
318 | {
|
---|
319 | delete fHiGainPixId;
|
---|
320 | delete fLoGainPixId;
|
---|
321 | delete fHiGainFadcSamples;
|
---|
322 | delete fLoGainFadcSamples;
|
---|
323 | }
|
---|
324 |
|
---|
325 | // --------------------------------------------------------------------------
|
---|
326 | //
|
---|
327 | // Deletes all the arrays
|
---|
328 | // The flag is for future usage.
|
---|
329 | //
|
---|
330 | void MRawEvtData::InitArrays(Bool_t flag)
|
---|
331 | {
|
---|
332 | if (flag && fRunHeader)
|
---|
333 | {
|
---|
334 | const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
|
---|
335 |
|
---|
336 | fHiGainPixId = new MArrayS(npix);
|
---|
337 | fLoGainPixId = new MArrayS(npix);
|
---|
338 | fHiGainFadcSamples = new MArrayB(npix*fRunHeader->GetNumSamplesHiGain());
|
---|
339 | fLoGainFadcSamples = new MArrayB(npix*fRunHeader->GetNumSamplesLoGain());
|
---|
340 |
|
---|
341 | fArraySize = npix;
|
---|
342 | }
|
---|
343 | else
|
---|
344 | {
|
---|
345 | fHiGainPixId = new MArrayS(0);
|
---|
346 | fLoGainPixId = new MArrayS(0);
|
---|
347 | fHiGainFadcSamples = new MArrayB(0);
|
---|
348 | fLoGainFadcSamples = new MArrayB(0);
|
---|
349 |
|
---|
350 | fArraySize = 0;
|
---|
351 | }
|
---|
352 |
|
---|
353 | fPosInArray = 0;
|
---|
354 | }
|
---|
355 |
|
---|
356 | // --------------------------------------------------------------------------
|
---|
357 | //
|
---|
358 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
---|
359 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
---|
360 | // Add to lo gains if lflag = 1
|
---|
361 | //
|
---|
362 | void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
|
---|
363 | {
|
---|
364 | MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
|
---|
365 | MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
|
---|
366 |
|
---|
367 | //
|
---|
368 | // check whether we got the right number of new samples
|
---|
369 | // if there are no samples already stored: this is the new number of samples
|
---|
370 | //
|
---|
371 | const Byte_t ns = data->GetSize();
|
---|
372 | const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
|
---|
373 | if (nSamp && ns!=nSamp)
|
---|
374 | {
|
---|
375 | *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
|
---|
376 | *fLog << "TArrayC doesn't match actual number" << endl;
|
---|
377 | return;
|
---|
378 | }
|
---|
379 |
|
---|
380 | //
|
---|
381 | // enhance pixel array by one
|
---|
382 | //
|
---|
383 | arrpix->Set(arrpix->GetSize()+1);
|
---|
384 |
|
---|
385 | //
|
---|
386 | // add the number of the new pixel to the array as last entry
|
---|
387 | //
|
---|
388 | arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
|
---|
389 |
|
---|
390 | //
|
---|
391 | // enhance the array by the number of new samples
|
---|
392 | //
|
---|
393 | arrsam->Set(arrsam->GetSize()+ns);
|
---|
394 |
|
---|
395 | //
|
---|
396 | // add the new slices as last entries to array
|
---|
397 | //
|
---|
398 | arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
399 | }
|
---|
400 |
|
---|
401 | // --------------------------------------------------------------------------
|
---|
402 | //
|
---|
403 | // Fills members with information from a magic binary file.
|
---|
404 | // WARNING: you have to use Init() before you can do this
|
---|
405 | //
|
---|
406 | void MRawEvtData::ReadEvt(istream &fin)
|
---|
407 | {
|
---|
408 | const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
|
---|
409 | const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
|
---|
410 |
|
---|
411 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
---|
412 |
|
---|
413 | const UShort_t npos = npic*fPosInArray;
|
---|
414 |
|
---|
415 | Byte_t *higainsam = fHiGainFadcSamples->GetArray()+nhi*npos;
|
---|
416 | Byte_t *logainsam = fLoGainFadcSamples->GetArray()+nlo*npos;
|
---|
417 |
|
---|
418 | // UShort_t *hipixid = (UShort_t*)fHiGainPixId->GetArray()+npos;
|
---|
419 | // UShort_t *lopixid = (UShort_t*)fLoGainPixId->GetArray()+npos;
|
---|
420 |
|
---|
421 | for (int i=0; i<npic; i++)
|
---|
422 | {
|
---|
423 | //
|
---|
424 | // get the spiral pixel number from the run header
|
---|
425 | //
|
---|
426 | const UShort_t npix = fRunHeader->GetPixAssignment(i);
|
---|
427 |
|
---|
428 | const UShort_t ipos = npos+i;
|
---|
429 | //
|
---|
430 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
---|
431 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
---|
432 | // Add to lo gains if lflag = 1
|
---|
433 | //
|
---|
434 | fHiGainPixId->AddAt(npix, ipos);
|
---|
435 | fin.read(higainsam, nhi);
|
---|
436 | higainsam += nhi;
|
---|
437 |
|
---|
438 | // FIXME: Not implemented in the raw files yet
|
---|
439 | //if (IsLoGainOn(i, j))
|
---|
440 | //{
|
---|
441 | fLoGainPixId->AddAt(npix, ipos);
|
---|
442 | fin.read(logainsam, nlo);
|
---|
443 | logainsam += nlo;
|
---|
444 | //}
|
---|
445 | }
|
---|
446 | }
|
---|
447 |
|
---|