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

Last change on this file since 4789 was 4784, checked in by gaug, 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 <TArrayD.h>
39
40#include <TClonesArray.h>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MParList.h"
46
47#include "MGeomCam.h"
48#include "MGeomPix.h"
49
50#include "MBadPixelsCam.h"
51#include "MBadPixelsPix.h"
52
53ClassImp(MPedestalCam);
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59// Default constructor.
60//
61// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
62// to hold one container per pixel. Later, a call to MPedestalCam::InitSize()
63// has to be performed (in MGeomApply).
64//
65// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
66// to hold one container per pixel AREA. Later, a call to MPedestalCam::InitAreas()
67// has to be performed (in MGeomApply).
68//
69// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
70// to hold one container per camera SECTOR. Later, a call to MPedestalCam::InitSectors()
71// has to be performed (in MGeomApply).
72//
73MPedestalCam::MPedestalCam(const char *name, const char *title)
74 : fTotalEntries(0)
75{
76 fName = name ? name : "MPedestalCam";
77 fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
78
79 fArray = new TClonesArray("MPedestalPix", 1);
80 fAverageAreas = new TClonesArray("MPedestalPix", 1);
81 fAverageSectors = new TClonesArray("MPedestalPix", 1);
82}
83
84// --------------------------------------------------------------------------
85//
86// Deletes the following TClonesArray's of MPedestalPix containers (if exist):
87// - fArray
88// - fAverageAreas
89// - fAverageSectors
90//
91MPedestalCam::~MPedestalCam()
92{
93 delete fArray;
94 delete fAverageAreas;
95 delete fAverageSectors;
96}
97
98// --------------------------------------------------------------------------
99//
100// Set the size of the camera
101//
102void MPedestalCam::InitSize(const UInt_t i)
103{
104 fArray->ExpandCreate(i);
105}
106
107// -------------------------------------------------------------------
108//
109// Calls TClonesArray::ExpandCreate() for:
110// - fAverageAreas
111//
112void MPedestalCam::InitAverageAreas(const UInt_t i)
113{
114 fAverageAreas->ExpandCreate(i);
115}
116
117// -------------------------------------------------------------------
118//
119// Calls TClonesArray::ExpandCreate() for:
120// - fAverageSectors
121//
122void MPedestalCam::InitAverageSectors(const UInt_t i)
123{
124 fAverageSectors->ExpandCreate(i);
125}
126
127// -------------------------------------------------------------------
128//
129// Calls:
130// - InitSize()
131// - InitAverageAreas()
132// - InitAverageSectors()
133//
134void MPedestalCam::Init(const MGeomCam &geom)
135{
136 InitSize (geom.GetNumPixels() );
137 InitAverageAreas (geom.GetNumAreas() );
138 InitAverageSectors(geom.GetNumSectors());
139}
140
141// --------------------------------------------------------------------------
142//
143// This function returns the current size of the TClonesArray
144// independently if the MPedestalPix is filled with values or not.
145//
146// Get the size of the MPedestalCam
147//
148Int_t MPedestalCam::GetSize() const
149{
150 return fArray->GetEntriesFast();
151}
152
153// --------------------------------------------------------------------------
154//
155// Returns the current size of the TClonesArray fAverageAreas
156// independently if the MPedestalPix is filled with values or not.
157//
158const Int_t MPedestalCam::GetAverageAreas() const
159{
160 return fAverageAreas->GetEntriesFast();
161}
162
163// --------------------------------------------------------------------------
164//
165// Returns the current size of the TClonesArray fAverageSectors
166// independently if the MPedestalPix is filled with values or not.
167//
168const Int_t MPedestalCam::GetAverageSectors() const
169{
170 return fAverageSectors->GetEntriesFast();
171}
172
173// --------------------------------------------------------------------------
174//
175// Get i-th pixel (pixel number)
176//
177MPedestalPix &MPedestalCam::operator[](Int_t i)
178{
179 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
180}
181
182// --------------------------------------------------------------------------
183//
184// Get i-th pixel (pixel number)
185//
186const MPedestalPix &MPedestalCam::operator[](Int_t i) const
187{
188 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
189}
190
191// --------------------------------------------------------------------------
192//
193// Get i-th average pixel (area number)
194//
195MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
196{
197 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
198}
199
200// --------------------------------------------------------------------------
201//
202// Get i-th average pixel (area number)
203//
204const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const
205{
206 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
207}
208
209// --------------------------------------------------------------------------
210//
211// Get i-th average pixel (sector number)
212//
213MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
214{
215 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
216}
217
218// --------------------------------------------------------------------------
219//
220// Get i-th average pixel (sector number)
221//
222const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const
223{
224 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
225}
226
227// --------------------------------------
228//
229// Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
230//
231// Loops over the fAverageAreas, calling the function Clear() for
232// every entry in fAverageAreas
233//
234// Loops over the fAverageSectors, calling the function Clear() for
235// every entry in fAverageSectors
236//
237void MPedestalCam::Clear(Option_t *o)
238{
239 fArray->ForEach(TObject, Clear)();
240
241 //
242 // another ForEach does not compile, thus have to do the loop ourselves:
243 //
244 for (Int_t i=0;i<GetAverageAreas();i++)
245 fAverageAreas[i].Clear();
246
247
248 //
249 // another ForEach does not compile, thus have to do the loop ourselves:
250 //
251 for (Int_t i=0;i<GetAverageSectors();i++)
252 fAverageSectors[i].Clear();
253
254 fTotalEntries = 0;
255}
256
257void MPedestalCam::Print(Option_t *o) const
258{
259 *fLog << all << GetDescriptor() << ":" << endl;
260 int id = 0;
261
262 TIter Next(fArray);
263 MPedestalPix *pix;
264 while ((pix=(MPedestalPix*)Next()))
265 {
266 id++;
267
268 if (!pix->IsValid())
269 continue;
270
271 *fLog << id-1 << ": ";
272 *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
273 }
274}
275
276Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
277{
278 if (fArray->GetEntries() <= 0)
279 return 50.;
280
281 Float_t minval = (*this)[0].GetPedestalRms();
282
283 for (Int_t i=1; i<fArray->GetEntries(); i++)
284 {
285 const MPedestalPix &pix = (*this)[i];
286
287 Float_t testval = pix.GetPedestalRms();
288
289 if (geom)
290 testval *= geom->GetPixRatio(i);
291
292 if (testval < minval)
293 minval = testval;
294 }
295 return minval;
296}
297
298Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
299{
300 if (fArray->GetEntries() <= 0)
301 return 50.;
302
303 Float_t maxval = (*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 > maxval)
315 maxval = testval;
316 }
317 return maxval;
318}
319
320// --------------------------------------------------------------------------
321//
322// Calculates the average pedestal for pixel sizes.
323// The geometry container is used to get the necessary
324// geometry information (area index) If the bad pixel
325// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
326// in the calculation of the size average.
327//
328Float_t MPedestalCam::GetAveragedPedPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
329{
330
331 const Int_t np = GetSize();
332
333 Double_t mean = 0.;
334 Int_t nr = 0;
335
336 for (int i=0; i<np; i++)
337 {
338 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
339 continue;
340
341 const UInt_t aidx = geom[i].GetAidx();
342
343 if (ai != aidx)
344 continue;
345
346 const MPedestalPix &pix = (*this)[i];
347
348 mean += pix.GetPedestal();
349 nr ++;
350
351 }
352
353 return mean/nr;
354}
355
356// --------------------------------------------------------------------------
357//
358// Calculates the average pedestal rms for pixel sizes.
359// The geometry container is used to get the necessary
360// geometry information (area index) If the bad pixel
361// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
362// in the calculation of the size average.
363//
364Float_t MPedestalCam::GetAveragedRmsPerArea(const MGeomCam &geom, const UInt_t ai, MBadPixelsCam *bad)
365{
366
367 const Int_t np = GetSize();
368
369 Double_t rms = 0.;
370 Int_t nr = 0;
371
372 for (int i=0; i<np; i++)
373 {
374 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
375 continue;
376
377 const UInt_t aidx = geom[i].GetAidx();
378
379 if (ai != aidx)
380 continue;
381
382 const MPedestalPix &pix = (*this)[i];
383
384 rms += pix.GetPedestalRms();
385 nr ++;
386 }
387
388 return rms/nr;
389}
390
391// --------------------------------------------------------------------------
392//
393// Calculates the average pedestal for camera sectors.
394// The geometry container is used to get the necessary
395// geometry information (area index) If the bad pixel
396// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
397// in the calculation of the size average.
398//
399Float_t MPedestalCam::GetAveragedPedPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
400{
401
402 const Int_t np = GetSize();
403
404 Double_t mean = 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 sector = geom[i].GetSector();
413
414 if (sec != sector)
415 continue;
416
417 const MPedestalPix &pix = (*this)[i];
418
419 mean += pix.GetPedestal();
420 nr ++;
421
422 }
423
424 return mean/nr;
425}
426
427// --------------------------------------------------------------------------
428//
429// Calculates the average pedestal rms for camera sectors.
430// The geometry container is used to get the necessary
431// geometry information (area index) If the bad pixel
432// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
433// in the calculation of the size average.
434//
435Float_t MPedestalCam::GetAveragedRmsPerSector(const MGeomCam &geom, const UInt_t sec, MBadPixelsCam *bad)
436{
437
438 const Int_t np = GetSize();
439
440 Double_t rms = 0.;
441 Int_t nr = 0;
442
443 for (int i=0; i<np; i++)
444 {
445 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
446 continue;
447
448 const UInt_t sector = geom[i].GetSector();
449
450 if (sec != sector)
451 continue;
452
453 const MPedestalPix &pix = (*this)[i];
454
455 rms += pix.GetPedestalRms();
456 nr ++;
457
458 }
459
460 return rms/nr;
461}
462
463
464// --------------------------------------------------------------------------
465//
466// Calculates the avarage pedestal and pedestal rms for all sectors
467// and pixel sizes. The geometry container is used to get the necessary
468// geometry information (sector number, size index) If the bad pixel
469// container is given all pixels which have the flag 'kUnsuitableRun' are ignored
470// in the calculation of the sector and size average.
471//
472void MPedestalCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad)
473{
474 const Int_t np = GetSize();
475 const Int_t ns = geom.GetNumSectors();
476 const Int_t na = geom.GetNumAreas();
477
478 TArrayI acnt(na);
479 TArrayI scnt(ns);
480 TArrayD asumx(na);
481 TArrayD ssumx(ns);
482 TArrayD asumr(na);
483 TArrayD ssumr(ns);
484
485 for (int i=0; i<np; i++)
486 {
487 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
488 continue; //was: .IsBad()
489
490 // Create sums for areas and sectors
491 const UInt_t aidx = geom[i].GetAidx();
492 const UInt_t sect = geom[i].GetSector();
493
494 const MPedestalPix &pix = (*this)[i];
495
496 const UInt_t ne = pix.GetNumEvents();
497 const Float_t mean = pix.GetPedestal();
498 const Float_t rms = pix.GetPedestalRms();
499
500 asumx[aidx] += ne*mean;
501 asumr[aidx] += ne*rms;
502 acnt[aidx] += ne;
503
504 ssumx[sect] += ne*mean;
505 ssumr[sect] += ne*rms;
506 scnt[sect] += ne;
507 }
508
509 for (int i=0; i<ns; i++)
510 if (scnt[i]>0)
511 GetAverageSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], 0, scnt[i]);
512 else
513 GetAverageSector(i).Clear();
514
515 for (int i=0; i<na; i++)
516 if (acnt[i]>0)
517 GetAverageArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], 0, acnt[i]);
518 else
519 GetAverageArea(i).Clear();
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.