source: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc@ 1978

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