source: tags/Mars-V1.2/mpedestal/MPedestalCam.cc

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