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

Last change on this file since 6461 was 5558, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 15.1 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 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->ForEach(TObject, Clear)(); }
272 { fAverageAreas->ForEach(TObject, Clear)(); }
273 { fAverageSectors->ForEach(TObject, Clear)(); }
274
275 fTotalEntries = 0;
276}
277
278void MPedestalCam::Print(Option_t *o) const
279{
280 *fLog << all << GetDescriptor() << ":" << endl;
281 int id = 0;
282
283 TIter Next(fArray);
284 MPedestalPix *pix;
285 while ((pix=(MPedestalPix*)Next()))
286 {
287 id++;
288
289 if (!pix->IsValid())
290 continue;
291
292 *fLog << id-1 << ": ";
293 *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
294 }
295}
296
297Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
298{
299 if (fArray->GetEntries() <= 0)
300 return 50.;
301
302 Float_t minval = (*this)[0].GetPedestalRms();
303
304 for (Int_t i=1; i<fArray->GetEntries(); i++)
305 {
306 const MPedestalPix &pix = (*this)[i];
307
308 Float_t testval = pix.GetPedestalRms();
309
310 if (geom)
311 testval *= geom->GetPixRatio(i);
312
313 if (testval < minval)
314 minval = testval;
315 }
316 return minval;
317}
318
319Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
320{
321 if (fArray->GetEntries() <= 0)
322 return 50.;
323
324 Float_t maxval = (*this)[0].GetPedestalRms();
325
326 for (Int_t i=1; i<fArray->GetEntries(); i++)
327 {
328 const MPedestalPix &pix = (*this)[i];
329
330 Float_t testval = pix.GetPedestalRms();
331
332 if (geom)
333 testval *= geom->GetPixRatio(i);
334
335 if (testval > maxval)
336 maxval = testval;
337 }
338 return maxval;
339}
340
341// --------------------------------------------------------------------------
342//
343// Calculates the average pedestal for pixel sizes.
344// The geometry container is used to get the necessary
345// geometry information (area index) If the bad pixel
346// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
347// in the calculation of the size average.
348//
349// Returns a TArrayF of dimension 2:
350// arr[0]: averaged pedestal (default: -1.)
351// arr[1]: Error (rms) of averaged pedestal (default: 0.)
352//
353TArrayF MPedestalCam::GetAveragedPedPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
354{
355
356 const Int_t np = GetSize();
357
358 Double_t mean = 0.;
359 Double_t mean2 = 0.;
360 Int_t nr = 0;
361
362 for (int i=0; i<np; i++)
363 {
364 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
365 continue;
366
367 const UInt_t aidx = geom[i].GetAidx();
368
369 if (ai != aidx)
370 continue;
371
372 const MPedestalPix &pix = (*this)[i];
373
374 mean += pix.GetPedestal();
375 mean2 += pix.GetPedestal()*pix.GetPedestal();
376 nr ++;
377
378 }
379
380 TArrayF arr(2);
381 arr[0] = nr ? mean/nr : -1.;
382 arr[1] = nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0;
383 return arr;
384}
385
386// --------------------------------------------------------------------------
387//
388// Calculates the average pedestal rms for pixel sizes.
389// The geometry container is used to get the necessary
390// geometry information (area index) If the bad pixel
391// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
392// in the calculation of the size average.
393//
394// Returns a TArrayF of dimension 2:
395// arr[0]: averaged pedestal RMS (default: -1.)
396// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
397//
398TArrayF MPedestalCam::GetAveragedRmsPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
399{
400
401 const Int_t np = GetSize();
402
403 Double_t rms = 0.;
404 Double_t rms2 = 0.;
405 Int_t nr = 0;
406
407 for (int i=0; i<np; i++)
408 {
409 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
410 continue;
411
412 const UInt_t aidx = geom[i].GetAidx();
413
414 if (ai != aidx)
415 continue;
416
417 const MPedestalPix &pix = (*this)[i];
418
419 rms += pix.GetPedestalRms();
420 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
421 nr ++;
422 }
423
424 TArrayF arr(2);
425 arr[0] = nr ? rms/nr : -1;
426 arr[1] = nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0;
427 return arr;
428}
429
430// --------------------------------------------------------------------------
431//
432// Calculates the average pedestal for camera sectors.
433// The geometry container is used to get the necessary
434// geometry information (area index) If the bad pixel
435// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
436// in the calculation of the size average.
437//
438// Returns a TArrayF of dimension 2:
439// arr[0]: averaged pedestal (default: -1.)
440// arr[1]: Error (rms) of averaged pedestal (default: 0.)
441//
442TArrayF MPedestalCam::GetAveragedPedPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
443{
444
445 const Int_t np = GetSize();
446
447 Double_t mean = 0.;
448 Double_t mean2 = 0.;
449 Int_t nr = 0;
450
451 for (int i=0; i<np; i++)
452 {
453 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
454 continue;
455
456 const UInt_t sector = geom[i].GetSector();
457
458 if (sec != sector)
459 continue;
460
461 const MPedestalPix &pix = (*this)[i];
462
463 mean += pix.GetPedestal();
464 mean2 += pix.GetPedestal()*pix.GetPedestal();
465 nr ++;
466
467 }
468
469 TArrayF arr(2);
470 arr[0] = nr ? mean/nr : -1;
471 arr[1] = nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0;
472 return arr;
473}
474
475// --------------------------------------------------------------------------
476//
477// Calculates the average pedestal rms for camera sectors.
478// The geometry container is used to get the necessary
479// geometry information (area index) If the bad pixel
480// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
481// in the calculation of the size average.
482//
483// Returns a TArrayF of dimension 2:
484// arr[0]: averaged pedestal RMS (default: -1.)
485// arr[1]: Error (rms) of averaged pedestal RMS (default: 0.)
486//
487TArrayF MPedestalCam::GetAveragedRmsPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
488{
489
490 const Int_t np = GetSize();
491
492 Double_t rms = 0.;
493 Double_t rms2 = 0.;
494 Int_t nr = 0;
495
496 for (int i=0; i<np; i++)
497 {
498 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
499 continue;
500
501 const UInt_t sector = geom[i].GetSector();
502
503 if (sec != sector)
504 continue;
505
506 const MPedestalPix &pix = (*this)[i];
507
508 rms += pix.GetPedestalRms();
509 rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
510 nr ++;
511
512 }
513
514 TArrayF arr(2);
515 arr[0] = nr ? rms/nr : -1;
516 arr[1] = nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0;
517 return arr;
518
519}
520
521
522Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
523{
524 if (GetSize() <= idx)
525 return kFALSE;
526
527 if (!(*this)[idx].IsValid())
528 return kFALSE;
529
530 const Float_t ped = (*this)[idx].GetPedestal();
531 const Float_t rms = (*this)[idx].GetPedestalRms();
532
533 switch (type)
534 {
535 case 0:
536 val = ped;
537 break;
538 case 1:
539 val = fTotalEntries > 0 ?
540 rms/TMath::Sqrt((Float_t)fTotalEntries)
541 : (*this)[idx].GetPedestalError();
542 break;
543 case 2:
544 val = rms;
545 break;
546 case 3:
547 val = fTotalEntries > 0 ?
548 rms/TMath::Sqrt((Float_t)fTotalEntries*2.)
549 : (*this)[idx].GetPedestalRmsError();
550 break;
551 default:
552 return kFALSE;
553 }
554 return kTRUE;
555}
556
557void MPedestalCam::DrawPixelContent(Int_t idx) const
558{
559 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
560}
Note: See TracBrowser for help on using the repository browser.