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

Last change on this file since 4692 was 4609, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 11.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@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 avarage pedestal and pedestal rms for all sectors
323// and pixel sizes. The geometry container is used to get the necessary
324// geometry information (sector number, size index) If the bad pixel
325// container is given all pixels which have the flag 'bad' are ignored
326// in the calculation of the sector and size average.
327//
328void MPedestalCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad)
329{
330 const Int_t np = GetSize();
331 const Int_t ns = geom.GetNumSectors();
332 const Int_t na = geom.GetNumAreas();
333
334 TArrayI acnt(na);
335 TArrayI scnt(ns);
336 TArrayD asumx(na);
337 TArrayD ssumx(ns);
338 TArrayD asumr(na);
339 TArrayD ssumr(ns);
340
341 for (int i=0; i<np; i++)
342 {
343 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
344 continue; //was: .IsBad()
345
346 // Create sums for areas and sectors
347 const UInt_t aidx = geom[i].GetAidx();
348 const UInt_t sect = geom[i].GetSector();
349
350 const MPedestalPix &pix = (*this)[i];
351
352 const UInt_t ne = pix.GetNumEvents();
353 const Float_t mean = pix.GetPedestal();
354 const Float_t rms = pix.GetPedestalRms();
355
356 asumx[aidx] += ne*mean;
357 asumr[aidx] += ne*rms;
358 acnt[aidx] += ne;
359
360 ssumx[sect] += ne*mean;
361 ssumr[sect] += ne*rms;
362 scnt[sect] += ne;
363 }
364
365 for (int i=0; i<ns; i++)
366 if (scnt[i]>0)
367 GetAverageSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], 0, scnt[i]);
368 else
369 GetAverageSector(i).Clear();
370
371 for (int i=0; i<na; i++)
372 if (acnt[i]>0)
373 GetAverageArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], 0, acnt[i]);
374 else
375 GetAverageArea(i).Clear();
376}
377
378Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
379{
380 if (GetSize() <= idx)
381 return kFALSE;
382
383 if (!(*this)[idx].IsValid())
384 return kFALSE;
385
386 switch (type)
387 {
388 case 0:
389 val = (*this)[idx].GetPedestal();
390 break;
391 case 1:
392 val = fTotalEntries > 0 ?
393 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)
394 : (*this)[idx].GetPedestalError();
395 break;
396 case 2:
397 val = (*this)[idx].GetPedestalRms();
398 break;
399 case 3:
400 val = fTotalEntries > 0 ?
401 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)/2.
402 : (*this)[idx].GetPedestalRmsError();
403 break;
404 default:
405 return kFALSE;
406 }
407 return kTRUE;
408}
409
410void MPedestalCam::DrawPixelContent(Int_t idx) const
411{
412 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
413}
Note: See TracBrowser for help on using the repository browser.