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-2008
|
---|
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 | // Version 8
|
---|
50 | // ------------------
|
---|
51 | // + MArrayS *fStartCell
|
---|
52 | //
|
---|
53 | // Version 7
|
---|
54 | // ------------------
|
---|
55 | // + UShort_t fNumBytesPerSample;
|
---|
56 | //
|
---|
57 | // Version 6
|
---|
58 | // ------------------
|
---|
59 | // - The data can now be stoe in a single array keeping he full
|
---|
60 | // compatibility
|
---|
61 | //
|
---|
62 | // Version 5 (0.8.5):
|
---|
63 | // ------------------
|
---|
64 | // - Changed type of ABFlags from TArrayC to MArrayB
|
---|
65 | //
|
---|
66 | // Version 4 (0.8.4):
|
---|
67 | // ------------------
|
---|
68 | // - Changed derivement from MCamEvent to MParContainer and MCamEvent
|
---|
69 | //
|
---|
70 | // Version 3 (0.8.4):
|
---|
71 | // ------------------
|
---|
72 | // - Added fABFlags
|
---|
73 | //
|
---|
74 | // Version 2:
|
---|
75 | // ----------
|
---|
76 | // - Derives from MCamEvent now
|
---|
77 | //
|
---|
78 | // Version 1:
|
---|
79 | // ----------
|
---|
80 | // - First implementation
|
---|
81 | //
|
---|
82 | /////////////////////////////////////////////////////////////////////////////
|
---|
83 | #include "MRawEvtData.h"
|
---|
84 |
|
---|
85 | #include <fstream>
|
---|
86 |
|
---|
87 | #include <TH1.h>
|
---|
88 | #include <TGraph.h>
|
---|
89 | #include <TArrayC.h>
|
---|
90 | #include <TVirtualPad.h>
|
---|
91 |
|
---|
92 | #include "MLog.h"
|
---|
93 | #include "MLogManip.h"
|
---|
94 |
|
---|
95 | #include "MArrayS.h"
|
---|
96 | #include "MArrayB.h"
|
---|
97 | #include "MArrayI.h"
|
---|
98 | #include "MGeomCam.h"
|
---|
99 |
|
---|
100 | #include "MRawCrateArray.h"
|
---|
101 | #include "MRawCrateData.h"
|
---|
102 |
|
---|
103 | #include "MRawRunHeader.h"
|
---|
104 | #include "MRawEvtPixelIter.h"
|
---|
105 |
|
---|
106 | ClassImp(MRawEvtData);
|
---|
107 |
|
---|
108 | using namespace std;
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | // Default constructor. It initializes all arrays with zero size.
|
---|
113 | //
|
---|
114 | MRawEvtData::MRawEvtData(const char *name, const char *title)
|
---|
115 | : fRunHeader(0), fNumBytesPerSample(1)
|
---|
116 | {
|
---|
117 | fName = name ? name : "MRawEvtData";
|
---|
118 | fTitle = title ? title : "Raw Event Data Information";
|
---|
119 |
|
---|
120 | InitArrays();
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // Destructor. Deletes all the arrays.
|
---|
126 | //
|
---|
127 | MRawEvtData::~MRawEvtData()
|
---|
128 | {
|
---|
129 | DeleteArrays();
|
---|
130 | }
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // reset all arrays
|
---|
135 | //
|
---|
136 | void MRawEvtData::Clear(Option_t *)
|
---|
137 | {
|
---|
138 | /*
|
---|
139 | FIXME:
|
---|
140 | Is Reset (set all entries to zero) what you want to do
|
---|
141 | or Set(0) (delete the array)
|
---|
142 | */
|
---|
143 | fHiGainPixId->Reset();
|
---|
144 | fLoGainPixId->Reset();
|
---|
145 | fHiGainFadcSamples->Reset();
|
---|
146 | fLoGainFadcSamples->Reset();
|
---|
147 | fABFlags->Reset();
|
---|
148 | }
|
---|
149 |
|
---|
150 | // --------------------------------------------------------------------------
|
---|
151 | //
|
---|
152 | // return the number of hi gain samples per pixel
|
---|
153 | //
|
---|
154 | UShort_t MRawEvtData::GetNumHiGainSamples() const
|
---|
155 | {
|
---|
156 | // If value<0 we are reading old MC files which don't have the
|
---|
157 | // value set so far. So we use the old methid to determin the
|
---|
158 | // numbers and calculate them from the length of the arrays.
|
---|
159 | return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/(fHiGainPixId->GetSize()*fNumBytesPerSample) : 0;
|
---|
160 | }
|
---|
161 |
|
---|
162 | // --------------------------------------------------------------------------
|
---|
163 | //
|
---|
164 | // return the number of lo gain samples per pixel
|
---|
165 | //
|
---|
166 | UShort_t MRawEvtData::GetNumLoGainSamples() const
|
---|
167 | {
|
---|
168 | // If value<0 we are reading old MC files which don't have the
|
---|
169 | // value set so far. So we use the old methid to determin the
|
---|
170 | // numbers and calculate them from the length of the arrays.
|
---|
171 | return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/(fLoGainPixId->GetSize()*fNumBytesPerSample) : 0;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // --------------------------------------------------------------------------
|
---|
175 | //
|
---|
176 | // return the number of stored pixel
|
---|
177 | //
|
---|
178 | UShort_t MRawEvtData::GetNumPixels() const
|
---|
179 | {
|
---|
180 | return fHiGainPixId ? fHiGainPixId->GetSize() : 0;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // --------------------------------------------------------------------------
|
---|
184 | //
|
---|
185 | // Print out the onformation to *fLog.
|
---|
186 | // Options:
|
---|
187 | // "hex" Prints the time slices hexadecimal (default)
|
---|
188 | // "dec" Prints the time slices decimal
|
---|
189 | //
|
---|
190 | void MRawEvtData::Print(Option_t *opt) const
|
---|
191 | {
|
---|
192 | //
|
---|
193 | // print fadc inforation to screen
|
---|
194 | // Possible Options:
|
---|
195 | // - DEC: Print values decimal instead of hexadecimal (default)
|
---|
196 | //
|
---|
197 | const UShort_t nHiSamp = GetNumHiGainSamples();
|
---|
198 | const UShort_t nLoSamp = GetNumLoGainSamples();
|
---|
199 |
|
---|
200 | const UShort_t bps = GetNumBytesPerSample();
|
---|
201 |
|
---|
202 | fLog->unsetf(ios::showbase);
|
---|
203 |
|
---|
204 | *fLog << dec << all;
|
---|
205 | *fLog << GetDescriptor() << ": " << endl;
|
---|
206 | *fLog << GetNumPixels() << " Pixels with " << (Int_t)nHiSamp << "/" << (Int_t)nLoSamp << " samples" << endl;
|
---|
207 |
|
---|
208 | TString str(opt);
|
---|
209 | Int_t manip = str.Contains("dec", TString::kIgnoreCase);
|
---|
210 |
|
---|
211 | MRawEvtPixelIter pixel(const_cast<MRawEvtData*>(this));
|
---|
212 | Int_t i = 0;
|
---|
213 | while (pixel.Next())
|
---|
214 | {
|
---|
215 | const UShort_t idx = pixel.GetPixelId();
|
---|
216 |
|
---|
217 | *fLog << endl << dec << setfill(' ');
|
---|
218 | *fLog << " " << setw(3) << i++ << " - " << setw(3) << idx << " ";
|
---|
219 |
|
---|
220 | if (pixel.IsABFlagValid())
|
---|
221 | *fLog << "<" << (pixel.HasABFlag()?"B":"A") << "> ";
|
---|
222 |
|
---|
223 | *fLog << (manip?dec:hex) << setfill(manip?' ':'0');
|
---|
224 |
|
---|
225 | const Byte_t *hi = (Byte_t*)pixel.GetHiGainSamples();
|
---|
226 | const Byte_t *lo = (Byte_t*)pixel.GetLoGainSamples();
|
---|
227 |
|
---|
228 | for (int j=0; j<nHiSamp*bps; j++)
|
---|
229 | {
|
---|
230 | *fLog << setw(manip?3:2);
|
---|
231 | *fLog << (hi[j]&0xff);
|
---|
232 | if (manip)
|
---|
233 | *fLog << ' ';
|
---|
234 | }
|
---|
235 |
|
---|
236 | for (int j=0; j<nLoSamp*bps; j++)
|
---|
237 | {
|
---|
238 | *fLog << setw(manip?3:2);
|
---|
239 | *fLog << ((UShort_t)lo[j]&0xff);
|
---|
240 | if (manip)
|
---|
241 | *fLog << ' ';
|
---|
242 | }
|
---|
243 | }
|
---|
244 | *fLog << dec << endl;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // --------------------------------------------------------------------------
|
---|
248 | //
|
---|
249 | // Draw a pixel. A Histogram or Graph is created and it's draw function is
|
---|
250 | // called.
|
---|
251 | // Options:
|
---|
252 | // "GRAPH" A graph is drawn
|
---|
253 | // "HIST" A histogram is drawn
|
---|
254 | // <index> The pixel with the given index is drawn
|
---|
255 | //
|
---|
256 | void MRawEvtData::Draw(Option_t *opt)
|
---|
257 | {
|
---|
258 | if (GetNumPixels()==0)
|
---|
259 | {
|
---|
260 | *fLog << warn << "Sorry, no pixel to draw!" << endl;
|
---|
261 | return;
|
---|
262 | }
|
---|
263 |
|
---|
264 | TString str(opt);
|
---|
265 | str.ToLower();
|
---|
266 |
|
---|
267 | UInt_t id = 0;
|
---|
268 |
|
---|
269 | if (str.BeginsWith("graph"))
|
---|
270 | sscanf(str.Data()+5, "%d", &id);
|
---|
271 | if (str.BeginsWith("hist"))
|
---|
272 | sscanf(str.Data()+4, "%d", &id);
|
---|
273 |
|
---|
274 | MRawEvtPixelIter pix(this);
|
---|
275 | if (!pix.Jump(id))
|
---|
276 | {
|
---|
277 | *fLog << warn << dec << "Pixel Idx #" << id << " doesn't exist!" << endl;
|
---|
278 | return;
|
---|
279 | }
|
---|
280 |
|
---|
281 | const void *higains = pix.GetHiGainSamples();
|
---|
282 | const void *logains = pix.GetLoGainSamples();
|
---|
283 |
|
---|
284 | const Int_t nh = GetNumHiGainSamples();
|
---|
285 | const Int_t nl = GetNumLoGainSamples();
|
---|
286 |
|
---|
287 | TString name = "Pixel Idx.";
|
---|
288 | name += pix.GetPixelId();
|
---|
289 |
|
---|
290 |
|
---|
291 | Bool_t same = str.Contains("same");
|
---|
292 |
|
---|
293 | if (str.BeginsWith("graph"))
|
---|
294 | {
|
---|
295 | *fLog << inf << "Drawing Graph: Pixel Idx #" << dec << pix.GetPixelId();
|
---|
296 | *fLog << " of " << (int)GetNumPixels() << "Pixels" << endl;
|
---|
297 |
|
---|
298 | TGraph *graphhi = new TGraph;
|
---|
299 |
|
---|
300 | for (int i=0; i<nh; i++)
|
---|
301 | graphhi->SetPoint(graphhi->GetN(), i, GetSample(higains, i));
|
---|
302 | for (int i=0; i<nl; i++)
|
---|
303 | graphhi->SetPoint(graphhi->GetN(), i+nh, GetSample(logains, i));
|
---|
304 |
|
---|
305 | graphhi->SetMaximum(GetMax()+0.5);
|
---|
306 | graphhi->SetMinimum(0);
|
---|
307 |
|
---|
308 | graphhi->SetBit(kCanDelete);
|
---|
309 | graphhi->Draw(same ? "C*" : "AC*");
|
---|
310 |
|
---|
311 | TH1F *histhi = graphhi->GetHistogram();
|
---|
312 | histhi->SetMinimum(0);
|
---|
313 | histhi->SetMaximum(GetMax()+0.5);
|
---|
314 |
|
---|
315 | histhi->SetXTitle("Time/FADC Slices");
|
---|
316 | histhi->SetYTitle("Signal/FADC Units");
|
---|
317 |
|
---|
318 | return;
|
---|
319 | }
|
---|
320 |
|
---|
321 | if (str.BeginsWith("hist"))
|
---|
322 | {
|
---|
323 | // FIXME: Add Legend
|
---|
324 | *fLog << inf << "Drawing Histogram of Pixel with Idx #" << dec << pix.GetPixelId() << " to " << gPad << endl;
|
---|
325 |
|
---|
326 | TH1F *histh = new TH1F(name, "FADC Samples", nh+nl, -0.5, nh+nl-.5);
|
---|
327 | histh->SetMinimum(0);
|
---|
328 | histh->SetMaximum(GetMax()+0.5);
|
---|
329 | histh->SetXTitle("Time [FADC Slices]");
|
---|
330 | histh->SetYTitle("Signal [FADC Units]");
|
---|
331 | histh->SetDirectory(NULL);
|
---|
332 | for (int i=0; i<nh; i++)
|
---|
333 | histh->Fill(i, GetSample(higains, i));
|
---|
334 | for (int i=0; i<nl; i++)
|
---|
335 | histh->Fill(i+nl, GetSample(logains, i));
|
---|
336 | histh->SetBit(kCanDelete);
|
---|
337 | histh->Draw(same ? "same" : "");
|
---|
338 |
|
---|
339 | return;
|
---|
340 | }
|
---|
341 |
|
---|
342 | *fLog << warn << dbginf << "WARNING - You must specify either 'GRAPH' or 'HIST'" << endl;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // --------------------------------------------------------------------------
|
---|
346 | //
|
---|
347 | // Deletes all the arrays
|
---|
348 | // The flag is for future usage.
|
---|
349 | //
|
---|
350 | void MRawEvtData::InitArrays(UShort_t numconnected, UShort_t maxid)
|
---|
351 | {
|
---|
352 | // fRunHeader should not be set only in the constructor!
|
---|
353 | const Int_t numhi = fRunHeader ? fRunHeader->GetNumSamplesHiGain() : 0;
|
---|
354 | const Int_t numlo = fRunHeader ? fRunHeader->GetNumSamplesLoGain() : 0;
|
---|
355 |
|
---|
356 | fNumBytesPerSample = fRunHeader ? fRunHeader->GetNumBytesPerSample() : 1;
|
---|
357 |
|
---|
358 | fHiGainPixId = new MArrayS(numconnected);
|
---|
359 | fLoGainPixId = new MArrayS(0);
|
---|
360 | fHiGainFadcSamples = new MArrayB(numconnected*(numhi+numlo)*fNumBytesPerSample);
|
---|
361 | fLoGainFadcSamples = new MArrayB(0);
|
---|
362 |
|
---|
363 | fABFlags = new MArrayB(maxid==0 ? 0 : maxid/8+1);
|
---|
364 | fStartCells = new MArrayS(0);
|
---|
365 |
|
---|
366 | fConnectedPixels = 0;
|
---|
367 | }
|
---|
368 |
|
---|
369 | void MRawEvtData::InitStartCells()
|
---|
370 | {
|
---|
371 | delete fStartCells;
|
---|
372 | fStartCells = new MArrayS(fHiGainPixId->GetSize());
|
---|
373 | }
|
---|
374 |
|
---|
375 | // --------------------------------------------------------------------------
|
---|
376 | //
|
---|
377 | // Deletes all the arrays
|
---|
378 | //
|
---|
379 | void MRawEvtData::DeleteArrays()
|
---|
380 | {
|
---|
381 | delete fHiGainPixId;
|
---|
382 | delete fLoGainPixId;
|
---|
383 | delete fHiGainFadcSamples;
|
---|
384 | delete fLoGainFadcSamples;
|
---|
385 | delete fABFlags;
|
---|
386 | delete fStartCells;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // --------------------------------------------------------------------------
|
---|
390 | //
|
---|
391 | // Deletes all arrays describing the pixel Id and Samples in pixels.
|
---|
392 | // The flag is for future usage.
|
---|
393 | //
|
---|
394 | void MRawEvtData::ResetPixels(UShort_t numconnected, UShort_t maxid)
|
---|
395 | {
|
---|
396 | //const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
|
---|
397 | if (fHiGainPixId && fHiGainPixId->GetSize()==numconnected && (UShort_t)fABFlags->GetSize()==(maxid/8+1))
|
---|
398 | {
|
---|
399 | fConnectedPixels = 0;
|
---|
400 | return;
|
---|
401 | }
|
---|
402 |
|
---|
403 | DeleteArrays();
|
---|
404 | InitArrays(numconnected, maxid);
|
---|
405 | }
|
---|
406 |
|
---|
407 | void MRawEvtData::ResetPixels()
|
---|
408 | {
|
---|
409 | if (!fRunHeader)
|
---|
410 | return;
|
---|
411 |
|
---|
412 | // FIXME: Better give NumNormalPixels if numconnected==0 ?
|
---|
413 |
|
---|
414 | ResetPixels(fRunHeader->GetNumNormalPixels(), fRunHeader->GetNumNormalPixels()-1);
|
---|
415 | }
|
---|
416 |
|
---|
417 | // --------------------------------------------------------------------------
|
---|
418 | //
|
---|
419 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
---|
420 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
---|
421 | //
|
---|
422 | void MRawEvtData::AddPixel(UShort_t nOfPixel, const TArrayC &data)
|
---|
423 | {
|
---|
424 | const Int_t n = fRunHeader->GetNumSamples();
|
---|
425 | if (data.GetSize()!=n)
|
---|
426 | {
|
---|
427 | *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
|
---|
428 | *fLog << "TArrayC " << data.GetSize() << " doesn't match current number " << n << endl;
|
---|
429 | return;
|
---|
430 | }
|
---|
431 |
|
---|
432 | //
|
---|
433 | // enhance pixel array by one
|
---|
434 | //
|
---|
435 | fHiGainPixId->Set(fHiGainPixId->GetSize()+1);
|
---|
436 |
|
---|
437 | //
|
---|
438 | // add the number of the new pixel to the array as last entry
|
---|
439 | //
|
---|
440 | fHiGainPixId->AddAt(nOfPixel, fHiGainPixId->GetSize()-1);
|
---|
441 |
|
---|
442 | //
|
---|
443 | // enhance the array by the number of new samples
|
---|
444 | //
|
---|
445 | fHiGainFadcSamples->Set(fHiGainFadcSamples->GetSize()+n);
|
---|
446 |
|
---|
447 | //
|
---|
448 | // add the new slices as last entries to array
|
---|
449 | //
|
---|
450 | fHiGainFadcSamples->AddAt((Byte_t*)data.GetArray(), fHiGainFadcSamples->GetSize()-n, n);
|
---|
451 | }
|
---|
452 |
|
---|
453 | // --------------------------------------------------------------------------
|
---|
454 | //
|
---|
455 | // Add the contents of the MArrayI to the fHiGainFadcSamples
|
---|
456 | // One Integer is added to one sample in the array.
|
---|
457 | //
|
---|
458 | void MRawEvtData::Set(const MArrayI &data)
|
---|
459 | {
|
---|
460 | fConnectedPixels = fHiGainPixId->GetSize();
|
---|
461 |
|
---|
462 | UInt_t n = fConnectedPixels*fRunHeader->GetNumSamplesHiGain();
|
---|
463 | if (n!=data.GetSize())
|
---|
464 | {
|
---|
465 | *fLog << err << "MRawEvtData::Set: Size mismatch." << endl;
|
---|
466 | *fLog << " fConnectedPixels=" << fConnectedPixels << endl;
|
---|
467 | *fLog << " NumHiGainSamples=" << fRunHeader->GetNumSamplesHiGain() << endl;
|
---|
468 | *fLog << " data.GetSize()=" << data.GetSize() << endl;
|
---|
469 | return;
|
---|
470 | }
|
---|
471 |
|
---|
472 | Byte_t *dest = fHiGainFadcSamples->GetArray();
|
---|
473 |
|
---|
474 | UInt_t *src = reinterpret_cast<UInt_t*>(data.GetArray());
|
---|
475 | UInt_t *end = reinterpret_cast<UInt_t*>(data.GetArray()) + n;
|
---|
476 |
|
---|
477 | switch (fNumBytesPerSample)
|
---|
478 | {
|
---|
479 | case 1:
|
---|
480 | {
|
---|
481 | Byte_t *ptr = reinterpret_cast<Byte_t*>(dest);
|
---|
482 | while (src<end)
|
---|
483 | *ptr++ = Byte_t(*src++);
|
---|
484 | }
|
---|
485 | return;
|
---|
486 |
|
---|
487 | case 2:
|
---|
488 | {
|
---|
489 | UShort_t *ptr = reinterpret_cast<UShort_t*>(dest);
|
---|
490 | while (src<end)
|
---|
491 | *ptr++ = UShort_t(*src++);
|
---|
492 | }
|
---|
493 | return;
|
---|
494 |
|
---|
495 | case 4:
|
---|
496 | memcpy(dest, data.GetArray(), n*4);
|
---|
497 | return;
|
---|
498 | }
|
---|
499 | }
|
---|
500 |
|
---|
501 | // --------------------------------------------------------------------------
|
---|
502 | //
|
---|
503 | // Set indices according to the given array. The array must have the same
|
---|
504 | // size as fHiGainPixId
|
---|
505 | //
|
---|
506 | void MRawEvtData::SetIndices(const MArrayS &idx)
|
---|
507 | {
|
---|
508 | if (idx.GetSize()!=fHiGainPixId->GetSize())
|
---|
509 | return;
|
---|
510 |
|
---|
511 | memcpy(fHiGainPixId->GetArray(), idx.GetArray(), idx.GetSize()*sizeof(UShort_t));
|
---|
512 | }
|
---|
513 |
|
---|
514 | // --------------------------------------------------------------------------
|
---|
515 | //
|
---|
516 | // Set indices according to the length of the array fHiGainPixId
|
---|
517 | // from 0 to n-1
|
---|
518 | //
|
---|
519 | void MRawEvtData::SetIndices()
|
---|
520 | {
|
---|
521 | for (UInt_t i=0; i<fHiGainPixId->GetSize(); i++)
|
---|
522 | (*fHiGainPixId)[i] = i;
|
---|
523 | }
|
---|
524 |
|
---|
525 | Byte_t *MRawEvtData::GetSamples() const { return fHiGainFadcSamples->GetArray(); }
|
---|
526 | UShort_t *MRawEvtData::GetStartCells() const { return fStartCells->GetArray(); }
|
---|
527 | UShort_t *MRawEvtData::GetPixelIds() const { return fHiGainPixId->GetArray(); }
|
---|
528 | Bool_t MRawEvtData::HasStartCells() const { return fStartCells->GetSize()==fHiGainPixId->GetSize(); }
|
---|
529 |
|
---|
530 | /*
|
---|
531 | void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
|
---|
532 | {
|
---|
533 | MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
|
---|
534 | MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
|
---|
535 |
|
---|
536 | //
|
---|
537 | // check whether we got the right number of new samples
|
---|
538 | // if there are no samples already stored: this is the new number of samples
|
---|
539 | //
|
---|
540 | const UShort_t ns = data->GetSize();
|
---|
541 | const UShort_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
|
---|
542 | if (nSamp && ns!=nSamp)
|
---|
543 | {
|
---|
544 | *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
|
---|
545 | *fLog << "TArrayC " << ns << " doesn't match current number " << nSamp << endl;
|
---|
546 | return;
|
---|
547 | }
|
---|
548 |
|
---|
549 | //
|
---|
550 | // enhance pixel array by one
|
---|
551 | //
|
---|
552 | arrpix->Set(arrpix->GetSize()+1);
|
---|
553 |
|
---|
554 | //
|
---|
555 | // add the number of the new pixel to the array as last entry
|
---|
556 | //
|
---|
557 | arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
|
---|
558 |
|
---|
559 | //
|
---|
560 | // enhance the array by the number of new samples
|
---|
561 | //
|
---|
562 | arrsam->Set(arrsam->GetSize()+ns);
|
---|
563 |
|
---|
564 | //
|
---|
565 | // add the new slices as last entries to array
|
---|
566 | //
|
---|
567 | arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
568 | }
|
---|
569 | */
|
---|
570 |
|
---|
571 | void MRawEvtData::ReadPixel(istream &fin, Int_t npix)
|
---|
572 | {
|
---|
573 | // number of samples
|
---|
574 | const UInt_t ns = fRunHeader->GetNumSamples();
|
---|
575 |
|
---|
576 | // bytes per sample
|
---|
577 | const Int_t bps = fRunHeader->GetNumBytesPerSample();
|
---|
578 |
|
---|
579 | // Number of bytes
|
---|
580 | const Int_t nb = ns*bps;
|
---|
581 |
|
---|
582 | // position in higain array
|
---|
583 | Byte_t *pos = fHiGainFadcSamples->GetArray() + fConnectedPixels*nb;
|
---|
584 |
|
---|
585 | // Set pixel index
|
---|
586 | fHiGainPixId->AddAt(npix, fConnectedPixels++);
|
---|
587 |
|
---|
588 | // Read data for one pixel
|
---|
589 | fin.read((char*)pos, nb);
|
---|
590 | }
|
---|
591 |
|
---|
592 | void MRawEvtData::SetABFlag(Int_t npix, Bool_t ab)
|
---|
593 | {
|
---|
594 | if (ab)
|
---|
595 | SETBIT((*fABFlags)[npix/8], npix%8);
|
---|
596 | else
|
---|
597 | CLRBIT((*fABFlags)[npix/8], npix%8);
|
---|
598 | }
|
---|
599 |
|
---|
600 | // --------------------------------------------------------------------------
|
---|
601 | //
|
---|
602 | // Fills members with information from a magic binary file.
|
---|
603 | // WARNING: you have to use Init() before you can do this
|
---|
604 | //
|
---|
605 | /*
|
---|
606 | void MRawEvtData::ReadEvt(istream &fin, Int_t posinarray)
|
---|
607 | {
|
---|
608 |
|
---|
609 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
---|
610 |
|
---|
611 | const UShort_t npos = npic*posinarray;
|
---|
612 |
|
---|
613 | //const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
|
---|
614 |
|
---|
615 | for (int i=npos; i<npic+npos; i++)
|
---|
616 | {
|
---|
617 | // calc the spiral hardware pixel number
|
---|
618 | const UShort_t ipos = i;
|
---|
619 |
|
---|
620 | // Get Hardware Id
|
---|
621 | const Short_t hwid = fRunHeader->GetPixAssignment(ipos);
|
---|
622 |
|
---|
623 | // Check whether the pixel is connected or not
|
---|
624 | if (hwid==0)
|
---|
625 | {
|
---|
626 | const UShort_t n = fRunHeader->GetNumSamplesLoGain()+fRunHeader->GetNumSamplesHiGain();
|
---|
627 | fin.seekg(n, ios::cur);
|
---|
628 | return;
|
---|
629 | }
|
---|
630 |
|
---|
631 | // -1 converts the hardware pixel Id into the software pixel index
|
---|
632 | const Int_t npix = (Int_t)hwid-1;
|
---|
633 |
|
---|
634 | const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
|
---|
635 | AddPixel(fin, npix, TESTBIT(ab, i-npos));
|
---|
636 | }
|
---|
637 | }
|
---|
638 | */
|
---|
639 |
|
---|
640 | // --------------------------------------------------------------------------
|
---|
641 | //
|
---|
642 | // Return the size in bytes of one event data block
|
---|
643 | //
|
---|
644 | Int_t MRawEvtData::GetNumBytes() const
|
---|
645 | {
|
---|
646 | const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
|
---|
647 | const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
|
---|
648 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
---|
649 | const UShort_t nbps = fRunHeader->GetNumBytesPerSample();
|
---|
650 |
|
---|
651 | return (nhi+nlo)*npic*nbps;
|
---|
652 | }
|
---|
653 |
|
---|
654 | // --------------------------------------------------------------------------
|
---|
655 | //
|
---|
656 | // Make sure, that you skip the whole event. This function only skips a part
|
---|
657 | // of the event - see MRawRead::SkipEvent
|
---|
658 | //
|
---|
659 | void MRawEvtData::SkipEvt(istream &fin)
|
---|
660 | {
|
---|
661 | fin.seekg(GetNumBytes(), ios::cur);
|
---|
662 | }
|
---|
663 |
|
---|
664 | Bool_t MRawEvtData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
665 | {
|
---|
666 | *fLog << warn << "WARNING - The use of MRawEvtData::GetPixelContent is deprecated!" << endl;
|
---|
667 |
|
---|
668 | /*
|
---|
669 | MRawEvtPixelIter Next(const_cast<MRawEvtData*>(this));
|
---|
670 | if (!Next.Jump(idx))
|
---|
671 | return kFALSE;
|
---|
672 |
|
---|
673 | switch (type)
|
---|
674 | {
|
---|
675 | case 0:
|
---|
676 | val = Next.GetSumHiGainSamples()-(float)GetNumHiGainSamples()*fHiGainFadcSamples->GetArray()[0];
|
---|
677 | val*= cam.GetPixRatio(idx);
|
---|
678 | break;
|
---|
679 | case 1:
|
---|
680 | val = Next.GetMaxHiGainSample();
|
---|
681 | break;
|
---|
682 | case 2:
|
---|
683 | val = Next.GetMaxLoGainSample();
|
---|
684 | break;
|
---|
685 | case 3:
|
---|
686 | val = Next.GetIdxMaxHiGainSample();
|
---|
687 | break;
|
---|
688 | case 4:
|
---|
689 | val = Next.GetIdxMaxLoGainSample();
|
---|
690 | break;
|
---|
691 | case 5:
|
---|
692 | val = Next.GetIdxMaxHiLoGainSample();
|
---|
693 | return val >= 0;
|
---|
694 | }
|
---|
695 | */
|
---|
696 | return kTRUE;
|
---|
697 | }
|
---|
698 |
|
---|
699 | void MRawEvtData::Copy(TObject &named)
|
---|
700 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
|
---|
701 | const
|
---|
702 | #endif
|
---|
703 | {
|
---|
704 | MRawEvtData &evt = (MRawEvtData &)named;
|
---|
705 |
|
---|
706 | *evt.fHiGainPixId = *fHiGainPixId;
|
---|
707 | *evt.fLoGainPixId = *fLoGainPixId;
|
---|
708 |
|
---|
709 | *evt.fHiGainFadcSamples = *fHiGainFadcSamples;
|
---|
710 | *evt.fLoGainFadcSamples = *fLoGainFadcSamples;
|
---|
711 |
|
---|
712 | *evt.fABFlags = *fABFlags;
|
---|
713 |
|
---|
714 | evt.fConnectedPixels = fConnectedPixels;
|
---|
715 |
|
---|
716 | evt.fNumBytesPerSample = fNumBytesPerSample;
|
---|
717 | }
|
---|