source: trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc@ 5489

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