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

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