source: branches/AddingGoogleTestEnvironment/mpedestal/MPedestalCam.cc@ 18179

Last change on this file since 18179 was 17066, checked in by tbretz, 11 years ago
Removed obsolete const qualifier
File size: 15.6 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! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
20! Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2008
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MPedestalCam
30//
31// Hold the Pedestal information for all pixels in the camera
32//
33// Class Version 2:
34// ----------------
35// + fNumSlices
36// - fTotalEntries
37//
38// Class Version 3:
39// ----------------
40// + fNumEvents
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MPedestalCam.h"
44#include "MPedestalPix.h"
45
46#include <TMath.h>
47
48#include <TArrayI.h>
49#include <TArrayF.h>
50#include <TArrayD.h>
51
52#include <TClonesArray.h>
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57#include "MParList.h"
58
59#include "MGeomCam.h"
60#include "MGeom.h"
61
62#include "MBadPixelsCam.h"
63#include "MBadPixelsPix.h"
64
65ClassImp(MPedestalCam);
66
67using namespace std;
68
69// --------------------------------------------------------------------------
70//
71// Default constructor.
72//
73// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
74// to hold one container per pixel. Later, a call to MPedestalCam::InitSize()
75// has to be performed (in MGeomApply).
76//
77// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
78// to hold one container per pixel AREA. Later, a call to MPedestalCam::InitAreas()
79// has to be performed (in MGeomApply).
80//
81// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
82// to hold one container per camera SECTOR. Later, a call to MPedestalCam::InitSectors()
83// has to be performed (in MGeomApply).
84//
85MPedestalCam::MPedestalCam(const char *name, const char *title)
86 : fNumSlices(0), fNumEvents(0)
87{
88 fName = name ? name : "MPedestalCam";
89 fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
90
91 fArray = new TClonesArray("MPedestalPix", 1);
92 fAverageAreas = new TClonesArray("MPedestalPix", 1);
93 fAverageSectors = new TClonesArray("MPedestalPix", 1);
94}
95
96// --------------------------------------------------------------------------
97//
98// Deletes the following TClonesArray's of MPedestalPix containers (if exist):
99// - fArray
100// - fAverageAreas
101// - fAverageSectors
102//
103MPedestalCam::~MPedestalCam()
104{
105 delete fArray;
106 delete fAverageAreas;
107 delete fAverageSectors;
108}
109
110// --------------------------------------------------------------------------
111//
112// Copy 'constructor'
113//
114void MPedestalCam::Copy(TObject &obj) const
115{
116
117 MParContainer::Copy(obj);
118
119 MPedestalCam &cam = (MPedestalCam&)obj;
120
121 Int_t n = GetSize();
122
123 if (n==0)
124 return;
125
126 cam.InitSize(n);
127 for (int i=0; i<n; i++)
128 (*this)[i].Copy(cam[i]);
129
130 cam.fNumEvents = fNumEvents;
131 cam.fNumSlices = fNumSlices;
132
133 n = GetNumAverageArea();
134 cam.InitAverageAreas(n);
135 for (int i=0; i<n; i++)
136 GetAverageArea(i).Copy(cam.GetAverageArea(i));
137
138 n = GetNumAverageSector();
139 cam.InitAverageSectors(n);
140 for (int i=0; i<n; i++)
141 GetAverageSector(i).Copy(cam.GetAverageSector(i));
142}
143
144// --------------------------------------------------------------------------
145//
146// Set the size of the camera
147//
148void MPedestalCam::InitSize(const UInt_t i)
149{
150 fArray->ExpandCreate(i);
151}
152
153// -------------------------------------------------------------------
154//
155// Calls TClonesArray::ExpandCreate() for:
156// - fAverageAreas
157//
158void MPedestalCam::InitAverageAreas(const UInt_t i)
159{
160 fAverageAreas->ExpandCreate(i);
161}
162
163// -------------------------------------------------------------------
164//
165// Calls TClonesArray::ExpandCreate() for:
166// - fAverageSectors
167//
168void MPedestalCam::InitAverageSectors(const UInt_t i)
169{
170 fAverageSectors->ExpandCreate(i);
171}
172
173// -------------------------------------------------------------------
174//
175// Calls:
176// - InitSize()
177// - InitAverageAreas()
178// - InitAverageSectors()
179//
180void MPedestalCam::Init(const MGeomCam &geom)
181{
182 InitSize (geom.GetNumPixels() );
183 InitAverageAreas (geom.GetNumAreas() );
184 InitAverageSectors(geom.GetNumSectors());
185}
186
187// --------------------------------------------------------------------------
188//
189// This function returns the current size of the TClonesArray
190// independently if the MPedestalPix is filled with values or not.
191//
192// Get the size of the MPedestalCam
193//
194Int_t MPedestalCam::GetSize() const
195{
196 return fArray->GetEntriesFast();
197}
198
199// --------------------------------------------------------------------------
200//
201// Returns the current size of the TClonesArray fAverageAreas
202// independently if the MPedestalPix is filled with values or not.
203//
204Int_t MPedestalCam::GetNumAverageArea() const
205{
206 return fAverageAreas->GetEntriesFast();
207}
208
209// --------------------------------------------------------------------------
210//
211// Returns the current size of the TClonesArray fAverageSectors
212// independently if the MPedestalPix is filled with values or not.
213//
214Int_t MPedestalCam::GetNumAverageSector() const
215{
216 return fAverageSectors->GetEntriesFast();
217}
218
219// --------------------------------------------------------------------------
220//
221// Get i-th pixel (pixel number)
222//
223MPedestalPix &MPedestalCam::operator[](Int_t i)
224{
225 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
226}
227
228// --------------------------------------------------------------------------
229//
230// Get i-th pixel (pixel number)
231//
232const MPedestalPix &MPedestalCam::operator[](Int_t i) const
233{
234 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
235}
236
237// --------------------------------------------------------------------------
238//
239// Get i-th average pixel (area number)
240//
241MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
242{
243 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
244}
245
246// --------------------------------------------------------------------------
247//
248// Get i-th average pixel (area number)
249//
250const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const
251{
252 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
253}
254
255// --------------------------------------------------------------------------
256//
257// Get i-th average pixel (sector number)
258//
259MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
260{
261 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
262}
263
264// --------------------------------------------------------------------------
265//
266// Get i-th average pixel (sector number)
267//
268const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const
269{
270 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
271}
272
273// --------------------------------------
274//
275// Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
276//
277// Loops over the fAverageAreas, calling the function Clear() for
278// every entry in fAverageAreas
279//
280// Loops over the fAverageSectors, calling the function Clear() for
281// every entry in fAverageSectors
282//
283void MPedestalCam::Clear(Option_t *o)
284{
285 { fArray->R__FOR_EACH(TObject, Clear)(); }
286 { fAverageAreas->R__FOR_EACH(TObject, Clear)(); }
287 { fAverageSectors->R__FOR_EACH(TObject, Clear)(); }
288
289 fNumSlices = 0;
290}
291
292void MPedestalCam::PrintArr(const TCollection &list) const
293{
294 Int_t id = 0;
295
296 TIter Next(&list);
297 MPedestalPix *pix = 0;
298
299 while ((pix=(MPedestalPix*)Next()))
300 *fLog << Form("Nr.: %4i Pedestal: %5.2f RMS: %5.2f ABOffset: %5.2f ",
301 id++, pix->GetPedestal(), pix->GetPedestalRms(), pix->GetPedestalABoffset()) << endl;
302}
303
304void MPedestalCam::Print(Option_t *option) const
305{
306 *fLog << all << GetDescriptor();
307 *fLog << " - Events=" << fNumEvents << ", Slices=" << fNumSlices << ":" << endl;
308
309 *fLog << endl;
310 *fLog << "Event-by-event averaged areas:" << endl;
311 PrintArr(*fAverageAreas);
312
313 *fLog << endl;
314 *fLog << "Event-by-event averaged sectors:" << endl;
315 PrintArr(*fAverageSectors);
316
317 if (TString(option).Contains("all", TString::kIgnoreCase))
318 {
319 *fLog << endl;
320 *fLog << "Pixels:" << endl;
321 PrintArr(*fArray);
322 }
323}
324
325/*
326Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
327{
328 if (fArray->GetEntries() <= 0)
329 return 50.;
330
331 Float_t minval = (*this)[0].GetPedestalRms();
332
333 for (Int_t i=1; i<fArray->GetEntries(); i++)
334 {
335 const MPedestalPix &pix = (*this)[i];
336
337 Float_t testval = pix.GetPedestalRms();
338
339 if (geom)
340 testval *= geom->GetPixRatio(i);
341
342 if (testval < minval)
343 minval = testval;
344 }
345 return minval;
346}
347
348Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
349{
350 if (fArray->GetEntries() <= 0)
351 return 50.;
352
353 Float_t maxval = (*this)[0].GetPedestalRms();
354
355 for (Int_t i=1; i<fArray->GetEntries(); i++)
356 {
357 const MPedestalPix &pix = (*this)[i];
358
359 Float_t testval = pix.GetPedestalRms();
360
361 if (geom)
362 testval *= geom->GetPixRatio(i);
363
364 if (testval > maxval)
365 maxval = testval;
366 }
367 return maxval;
368}
369*/
370
371// --------------------------------------------------------------------------
372//
373// Calculates the average pedestal for pixel sizes.
374// The geometry container is used to get the necessary
375// geometry information (area index) If the bad pixel
376// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
377// in the calculation of the size average.
378//
379// Returns a TArrayF of dimension 2:
380// arr[0]: averaged pedestal (default: -1.)
381// arr[1]: Error (rms) of averaged pedestal (default: 0.)
382//
383TArrayF MPedestalCam::GetAveragedPedPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
384{
385
386 const Int_t np = GetSize();
387
388 Double_t mean = 0.;
389 Double_t mean2 = 0.;
390 Int_t nr = 0;
391
392 for (int i=0; i<np; i++)
393 {
394 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
395 continue;
396
397 const UInt_t aidx = geom[i].GetAidx();
398
399 if (ai != aidx)
400 continue;
401
402 const MPedestalPix &pix = (*this)[i];
403
404 mean += pix.GetPedestal();
405 mean2 += pix.GetPedestal()*pix.GetPedestal();
406 nr ++;
407
408 }
409
410 TArrayF arr(2);
411 arr[0] = nr ? mean/nr : -1.;
412 arr[1] = nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0;
413 return arr;
414}
415
416// --------------------------------------------------------------------------
417//
418// Calculates the average pedestal rms for pixel sizes.
419// The geometry container is used to get the necessary
420// geometry information (area index) If the bad pixel
421// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
422// in the calculation of the size average.
423//
424// Returns a TArrayF of dimension 2:
425// arr[0]: averaged pedestal RMS (default: -1.)
426// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
427//
428TArrayF MPedestalCam::GetAveragedRmsPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
429{
430
431 const Int_t np = GetSize();
432
433 Double_t rms = 0.;
434 Double_t rms2 = 0.;
435 Int_t nr = 0;
436
437 for (int i=0; i<np; i++)
438 {
439 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
440 continue;
441
442 const UInt_t aidx = geom[i].GetAidx();
443
444 if (ai != aidx)
445 continue;
446
447 const MPedestalPix &pix = (*this)[i];
448
449 rms += pix.GetPedestalRms();
450 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
451 nr ++;
452 }
453
454 TArrayF arr(2);
455 arr[0] = nr ? rms/nr : -1;
456 arr[1] = nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0;
457 return arr;
458}
459
460// --------------------------------------------------------------------------
461//
462// Calculates the average pedestal for camera sectors.
463// The geometry container is used to get the necessary
464// geometry information (area index) If the bad pixel
465// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
466// in the calculation of the size average.
467//
468// Returns a TArrayF of dimension 2:
469// arr[0]: averaged pedestal (default: -1.)
470// arr[1]: Error (rms) of averaged pedestal (default: 0.)
471//
472TArrayF MPedestalCam::GetAveragedPedPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
473{
474
475 const Int_t np = GetSize();
476
477 Double_t mean = 0.;
478 Double_t mean2 = 0.;
479 Int_t nr = 0;
480
481 for (int i=0; i<np; i++)
482 {
483 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
484 continue;
485
486 const UInt_t sector = geom[i].GetSector();
487
488 if (sec != sector)
489 continue;
490
491 const MPedestalPix &pix = (*this)[i];
492
493 mean += pix.GetPedestal();
494 mean2 += pix.GetPedestal()*pix.GetPedestal();
495 nr ++;
496
497 }
498
499 TArrayF arr(2);
500 arr[0] = nr ? mean/nr : -1;
501 arr[1] = nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0;
502 return arr;
503}
504
505// --------------------------------------------------------------------------
506//
507// Calculates the average pedestal rms for camera sectors.
508// The geometry container is used to get the necessary
509// geometry information (area index) If the bad pixel
510// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
511// in the calculation of the size average.
512//
513// Returns a TArrayF of dimension 2:
514// arr[0]: averaged pedestal RMS (default: -1.)
515// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
516//
517TArrayF MPedestalCam::GetAveragedRmsPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
518{
519
520 const Int_t np = GetSize();
521
522 Double_t rms = 0.;
523 Double_t rms2 = 0.;
524 Int_t nr = 0;
525
526 for (int i=0; i<np; i++)
527 {
528 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
529 continue;
530
531 const UInt_t sector = geom[i].GetSector();
532
533 if (sec != sector)
534 continue;
535
536 const MPedestalPix &pix = (*this)[i];
537
538 rms += pix.GetPedestalRms();
539 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
540 nr ++;
541
542 }
543
544 TArrayF arr(2);
545 arr[0] = nr ? rms/nr : -1;
546 arr[1] = nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0;
547 return arr;
548}
549
550
551Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
552{
553 if (GetSize() <= idx)
554 return kFALSE;
555
556 if (!(*this)[idx].IsValid())
557 return kFALSE;
558
559 const Float_t ped = (*this)[idx].GetPedestal();
560 const Float_t rms = (*this)[idx].GetPedestalRms();
561 const UInt_t num = (*this)[idx].GetNumEvents()*fNumSlices;
562
563 switch (type)
564 {
565 case 0:
566 val = ped;
567 break;
568 case 1:
569 val = fNumSlices>0 ? rms/TMath::Sqrt((Float_t)num)
570 : (*this)[idx].GetPedestalError();
571 break;
572 case 2:
573 val = rms;
574 break;
575 case 3:
576 val = fNumSlices>0 ? rms/TMath::Sqrt((Float_t)num*2.)
577 : (*this)[idx].GetPedestalRmsError();
578 break;
579 case 4:
580 val = rms;
581 break;
582 default:
583 return kFALSE;
584 }
585 return kTRUE;
586}
587
588void MPedestalCam::DrawPixelContent(Int_t idx) const
589{
590 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
591}
Note: See TracBrowser for help on using the repository browser.