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

Last change on this file since 5532 was 5516, checked in by gaug, 22 years ago
*** empty log message ***
File size: 15.4 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 &obj) const
104{
105
106 MParContainer::Copy(obj);
107
108 MPedestalCam &cam = (MPedestalCam&)obj;
109
110 const Int_t n = GetSize();
111
112 if (n==0)
113 return;
114
115 cam.InitSize(n);
116 for (int i=0; i<n; i++)
117 (*this)[i].Copy(cam[i]);
118}
119
120// --------------------------------------------------------------------------
121//
122// Set the size of the camera
123//
124void MPedestalCam::InitSize(const UInt_t i)
125{
126 fArray->ExpandCreate(i);
127}
128
129// -------------------------------------------------------------------
130//
131// Calls TClonesArray::ExpandCreate() for:
132// - fAverageAreas
133//
134void MPedestalCam::InitAverageAreas(const UInt_t i)
135{
136 fAverageAreas->ExpandCreate(i);
137}
138
139// -------------------------------------------------------------------
140//
141// Calls TClonesArray::ExpandCreate() for:
142// - fAverageSectors
143//
144void MPedestalCam::InitAverageSectors(const UInt_t i)
145{
146 fAverageSectors->ExpandCreate(i);
147}
148
149// -------------------------------------------------------------------
150//
151// Calls:
152// - InitSize()
153// - InitAverageAreas()
154// - InitAverageSectors()
155//
156void MPedestalCam::Init(const MGeomCam &geom)
157{
158 InitSize (geom.GetNumPixels() );
159 InitAverageAreas (geom.GetNumAreas() );
160 InitAverageSectors(geom.GetNumSectors());
161}
162
163// --------------------------------------------------------------------------
164//
165// This function returns the current size of the TClonesArray
166// independently if the MPedestalPix is filled with values or not.
167//
168// Get the size of the MPedestalCam
169//
170Int_t MPedestalCam::GetSize() const
171{
172 return fArray->GetEntriesFast();
173}
174
175// --------------------------------------------------------------------------
176//
177// Returns the current size of the TClonesArray fAverageAreas
178// independently if the MPedestalPix is filled with values or not.
179//
180const Int_t MPedestalCam::GetAverageAreas() const
181{
182 return fAverageAreas->GetEntriesFast();
183}
184
185// --------------------------------------------------------------------------
186//
187// Returns the current size of the TClonesArray fAverageSectors
188// independently if the MPedestalPix is filled with values or not.
189//
190const Int_t MPedestalCam::GetAverageSectors() const
191{
192 return fAverageSectors->GetEntriesFast();
193}
194
195// --------------------------------------------------------------------------
196//
197// Get i-th pixel (pixel number)
198//
199MPedestalPix &MPedestalCam::operator[](Int_t i)
200{
201 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
202}
203
204// --------------------------------------------------------------------------
205//
206// Get i-th pixel (pixel number)
207//
208const MPedestalPix &MPedestalCam::operator[](Int_t i) const
209{
210 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
211}
212
213// --------------------------------------------------------------------------
214//
215// Get i-th average pixel (area number)
216//
217MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
218{
219 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
220}
221
222// --------------------------------------------------------------------------
223//
224// Get i-th average pixel (area number)
225//
226const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const
227{
228 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
229}
230
231// --------------------------------------------------------------------------
232//
233// Get i-th average pixel (sector number)
234//
235MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
236{
237 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
238}
239
240// --------------------------------------------------------------------------
241//
242// Get i-th average pixel (sector number)
243//
244const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const
245{
246 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
247}
248
249// --------------------------------------
250//
251// Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
252//
253// Loops over the fAverageAreas, calling the function Clear() for
254// every entry in fAverageAreas
255//
256// Loops over the fAverageSectors, calling the function Clear() for
257// every entry in fAverageSectors
258//
259void MPedestalCam::Clear(Option_t *o)
260{
261 fArray->ForEach(TObject, Clear)();
262
263 //
264 // another ForEach does not compile, thus have to do the loop ourselves:
265 //
266 for (Int_t i=0;i<GetAverageAreas();i++)
267 fAverageAreas[i].Clear();
268
269
270 //
271 // another ForEach does not compile, thus have to do the loop ourselves:
272 //
273 for (Int_t i=0;i<GetAverageSectors();i++)
274 fAverageSectors[i].Clear();
275
276 fTotalEntries = 0;
277}
278
279void MPedestalCam::Print(Option_t *o) const
280{
281 *fLog << all << GetDescriptor() << ":" << endl;
282 int id = 0;
283
284 TIter Next(fArray);
285 MPedestalPix *pix;
286 while ((pix=(MPedestalPix*)Next()))
287 {
288 id++;
289
290 if (!pix->IsValid())
291 continue;
292
293 *fLog << id-1 << ": ";
294 *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
295 }
296}
297
298Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
299{
300 if (fArray->GetEntries() <= 0)
301 return 50.;
302
303 Float_t minval = (*this)[0].GetPedestalRms();
304
305 for (Int_t i=1; i<fArray->GetEntries(); i++)
306 {
307 const MPedestalPix &pix = (*this)[i];
308
309 Float_t testval = pix.GetPedestalRms();
310
311 if (geom)
312 testval *= geom->GetPixRatio(i);
313
314 if (testval < minval)
315 minval = testval;
316 }
317 return minval;
318}
319
320Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
321{
322 if (fArray->GetEntries() <= 0)
323 return 50.;
324
325 Float_t maxval = (*this)[0].GetPedestalRms();
326
327 for (Int_t i=1; i<fArray->GetEntries(); i++)
328 {
329 const MPedestalPix &pix = (*this)[i];
330
331 Float_t testval = pix.GetPedestalRms();
332
333 if (geom)
334 testval *= geom->GetPixRatio(i);
335
336 if (testval > maxval)
337 maxval = testval;
338 }
339 return maxval;
340}
341
342// --------------------------------------------------------------------------
343//
344// Calculates the average pedestal for pixel sizes.
345// The geometry container is used to get the necessary
346// geometry information (area index) If the bad pixel
347// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
348// in the calculation of the size average.
349//
350// Returns a TArrayF of dimension 2:
351// arr[0]: averaged pedestal (default: -1.)
352// arr[1]: Error (rms) of averaged pedestal (default: 0.)
353//
354// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
355//
356TArrayF *MPedestalCam::GetAveragedPedPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
357{
358
359 const Int_t np = GetSize();
360
361 Double_t mean = 0.;
362 Double_t mean2 = 0.;
363 Int_t nr = 0;
364
365 for (int i=0; i<np; i++)
366 {
367 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
368 continue;
369
370 const UInt_t aidx = geom[i].GetAidx();
371
372 if (ai != aidx)
373 continue;
374
375 const MPedestalPix &pix = (*this)[i];
376
377 mean += pix.GetPedestal();
378 mean2 += pix.GetPedestal()*pix.GetPedestal();
379 nr ++;
380
381 }
382
383 TArrayF *arr = new TArrayF(2);
384 arr->AddAt(nr ? mean/nr : -1.,0);
385 arr->AddAt(nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0. ,1);
386
387 return arr;
388}
389
390// --------------------------------------------------------------------------
391//
392// Calculates the average pedestal rms for pixel sizes.
393// The geometry container is used to get the necessary
394// geometry information (area index) If the bad pixel
395// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
396// in the calculation of the size average.
397//
398// Returns a TArrayF of dimension 2:
399// arr[0]: averaged pedestal RMS (default: -1.)
400// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
401//
402// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
403//
404TArrayF *MPedestalCam::GetAveragedRmsPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
405{
406
407 const Int_t np = GetSize();
408
409 Double_t rms = 0.;
410 Double_t rms2 = 0.;
411 Int_t nr = 0;
412
413 for (int i=0; i<np; i++)
414 {
415 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
416 continue;
417
418 const UInt_t aidx = geom[i].GetAidx();
419
420 if (ai != aidx)
421 continue;
422
423 const MPedestalPix &pix = (*this)[i];
424
425 rms += pix.GetPedestalRms();
426 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
427 nr ++;
428 }
429
430 TArrayF *arr = new TArrayF(2);
431 arr->AddAt(nr ? rms/nr : -1.,0);
432 arr->AddAt(nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0. ,1);
433
434 return arr;
435}
436
437// --------------------------------------------------------------------------
438//
439// Calculates the average pedestal for camera sectors.
440// The geometry container is used to get the necessary
441// geometry information (area index) If the bad pixel
442// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
443// in the calculation of the size average.
444//
445// Returns a TArrayF of dimension 2:
446// arr[0]: averaged pedestal (default: -1.)
447// arr[1]: Error (rms) of averaged pedestal (default: 0.)
448//
449// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
450//
451TArrayF *MPedestalCam::GetAveragedPedPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
452{
453
454 const Int_t np = GetSize();
455
456 Double_t mean = 0.;
457 Double_t mean2 = 0.;
458 Int_t nr = 0;
459
460 for (int i=0; i<np; i++)
461 {
462 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
463 continue;
464
465 const UInt_t sector = geom[i].GetSector();
466
467 if (sec != sector)
468 continue;
469
470 const MPedestalPix &pix = (*this)[i];
471
472 mean += pix.GetPedestal();
473 mean2 += pix.GetPedestal()*pix.GetPedestal();
474 nr ++;
475
476 }
477
478 TArrayF *arr = new TArrayF(2);
479 arr->AddAt(nr ? mean/nr : -1.,0);
480 arr->AddAt(nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0. ,1);
481
482 return arr;
483}
484
485// --------------------------------------------------------------------------
486//
487// Calculates the average pedestal rms for camera sectors.
488// The geometry container is used to get the necessary
489// geometry information (area index) If the bad pixel
490// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
491// in the calculation of the size average.
492//
493// Returns a TArrayF of dimension 2:
494// arr[0]: averaged pedestal RMS (default: -1.)
495// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
496//
497// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
498//
499TArrayF *MPedestalCam::GetAveragedRmsPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
500{
501
502 const Int_t np = GetSize();
503
504 Double_t rms = 0.;
505 Double_t rms2 = 0.;
506 Int_t nr = 0;
507
508 for (int i=0; i<np; i++)
509 {
510 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
511 continue;
512
513 const UInt_t sector = geom[i].GetSector();
514
515 if (sec != sector)
516 continue;
517
518 const MPedestalPix &pix = (*this)[i];
519
520 rms += pix.GetPedestalRms();
521 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
522 nr ++;
523
524 }
525
526 TArrayF *arr = new TArrayF(2);
527 arr->AddAt(nr ? rms/nr : -1.,0);
528 arr->AddAt(nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0. ,1);
529
530 return arr;
531
532}
533
534
535Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
536{
537 if (GetSize() <= idx)
538 return kFALSE;
539
540 if (!(*this)[idx].IsValid())
541 return kFALSE;
542
543 const Float_t ped = (*this)[idx].GetPedestal();
544 const Float_t rms = (*this)[idx].GetPedestalRms();
545
546 switch (type)
547 {
548 case 0:
549 val = ped;
550 break;
551 case 1:
552 val = fTotalEntries > 0 ?
553 rms/TMath::Sqrt((Float_t)fTotalEntries)
554 : (*this)[idx].GetPedestalError();
555 break;
556 case 2:
557 val = rms;
558 break;
559 case 3:
560 val = fTotalEntries > 0 ?
561 rms/TMath::Sqrt((Float_t)fTotalEntries*2.)
562 : (*this)[idx].GetPedestalRmsError();
563 break;
564 default:
565 return kFALSE;
566 }
567 return kTRUE;
568}
569
570void MPedestalCam::DrawPixelContent(Int_t idx) const
571{
572 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
573}
Note: See TracBrowser for help on using the repository browser.