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

Last change on this file since 4454 was 4404, checked in by fgoebel, 20 years ago
*** empty log message ***
File size: 9.6 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 <TClonesArray.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MParList.h"
43
44#include "MGeomCam.h"
45
46ClassImp(MPedestalCam);
47
48using namespace std;
49
50// --------------------------------------------------------------------------
51//
52// Default constructor.
53//
54// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
55// to hold one container per pixel. Later, a call to MPedestalCam::InitSize()
56// has to be performed (in MGeomApply).
57//
58// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
59// to hold one container per pixel AREA. Later, a call to MPedestalCam::InitAreas()
60// has to be performed (in MGeomApply).
61//
62// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
63// to hold one container per camera SECTOR. Later, a call to MPedestalCam::InitSectors()
64// has to be performed (in MGeomApply).
65//
66MPedestalCam::MPedestalCam(const char *name, const char *title)
67 : fTotalEntries(0)
68{
69 fName = name ? name : "MPedestalCam";
70 fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
71
72 fArray = new TClonesArray("MPedestalPix", 1);
73 fAverageAreas = new TClonesArray("MPedestalPix", 1);
74 fAverageSectors = new TClonesArray("MPedestalPix", 1);
75}
76
77// --------------------------------------------------------------------------
78//
79// Deletes the following TClonesArray's of MPedestalPix containers (if exist):
80// - fArray
81// - fAverageAreas
82// - fAverageSectors
83//
84MPedestalCam::~MPedestalCam()
85{
86 delete fArray;
87 delete fAverageAreas;
88 delete fAverageSectors;
89}
90
91// --------------------------------------------------------------------------
92//
93// Set the size of the camera
94//
95void MPedestalCam::InitSize(const UInt_t i)
96{
97 fArray->ExpandCreate(i);
98}
99
100// -------------------------------------------------------------------
101//
102// Calls TClonesArray::ExpandCreate() for:
103// - fAverageAreas
104//
105void MPedestalCam::InitAverageAreas(const UInt_t i)
106{
107 fAverageAreas->ExpandCreate(i);
108}
109
110// -------------------------------------------------------------------
111//
112// Calls TClonesArray::ExpandCreate() for:
113// - fAverageSectors
114//
115void MPedestalCam::InitAverageSectors(const UInt_t i)
116{
117 fAverageSectors->ExpandCreate(i);
118}
119
120// -------------------------------------------------------------------
121//
122// Calls:
123// - InitSize()
124// - InitAverageAreas()
125// - InitAverageSectors()
126//
127void MPedestalCam::Init(const MGeomCam &geom)
128{
129 InitSize (geom.GetNumPixels() );
130 InitAverageAreas (geom.GetNumAreas() );
131 InitAverageSectors(geom.GetNumSectors());
132}
133
134// --------------------------------------------------------------------------
135//
136// This function returns the current size of the TClonesArray
137// independently if the MPedestalPix is filled with values or not.
138//
139// Get the size of the MPedestalCam
140//
141Int_t MPedestalCam::GetSize() const
142{
143 return fArray->GetEntriesFast();
144}
145
146// --------------------------------------------------------------------------
147//
148// Returns the current size of the TClonesArray fAverageAreas
149// independently if the MPedestalPix is filled with values or not.
150//
151const Int_t MPedestalCam::GetAverageAreas() const
152{
153 return fAverageAreas->GetEntriesFast();
154}
155
156// --------------------------------------------------------------------------
157//
158// Returns the current size of the TClonesArray fAverageSectors
159// independently if the MPedestalPix is filled with values or not.
160//
161const Int_t MPedestalCam::GetAverageSectors() const
162{
163 return fAverageSectors->GetEntriesFast();
164}
165
166// --------------------------------------------------------------------------
167//
168// Get i-th pixel (pixel number)
169//
170MPedestalPix &MPedestalCam::operator[](Int_t i)
171{
172 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
173}
174
175// --------------------------------------------------------------------------
176//
177// Get i-th pixel (pixel number)
178//
179const MPedestalPix &MPedestalCam::operator[](Int_t i) const
180{
181 return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
182}
183
184// --------------------------------------------------------------------------
185//
186// Get i-th average pixel (area number)
187//
188MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
189{
190 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
191}
192
193// --------------------------------------------------------------------------
194//
195// Get i-th average pixel (area number)
196//
197const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const
198{
199 return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
200}
201
202// --------------------------------------------------------------------------
203//
204// Get i-th average pixel (sector number)
205//
206MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
207{
208 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
209}
210
211// --------------------------------------------------------------------------
212//
213// Get i-th average pixel (sector number)
214//
215const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const
216{
217 return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
218}
219
220// --------------------------------------
221//
222// Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
223//
224// Loops over the fAverageAreas, calling the function Clear() for
225// every entry in fAverageAreas
226//
227// Loops over the fAverageSectors, calling the function Clear() for
228// every entry in fAverageSectors
229//
230void MPedestalCam::Clear(Option_t *o)
231{
232 fArray->ForEach(TObject, Clear)();
233
234 //
235 // another ForEach does not compile, thus have to do the loop ourselves:
236 //
237 for (Int_t i=0;i<GetAverageAreas();i++)
238 fAverageAreas[i].Clear();
239
240
241 //
242 // another ForEach does not compile, thus have to do the loop ourselves:
243 //
244 for (Int_t i=0;i<GetAverageSectors();i++)
245 fAverageSectors[i].Clear();
246
247 fTotalEntries = 0;
248}
249
250void MPedestalCam::Print(Option_t *o) const
251{
252 *fLog << all << GetDescriptor() << ":" << endl;
253 int id = 0;
254
255 TIter Next(fArray);
256 MPedestalPix *pix;
257 while ((pix=(MPedestalPix*)Next()))
258 {
259 id++;
260
261 if (!pix->IsValid())
262 continue;
263
264 *fLog << id-1 << ": ";
265 *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
266 }
267}
268
269Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
270{
271 if (fArray->GetEntries() <= 0)
272 return 50.;
273
274 Float_t minval = (*this)[0].GetPedestalRms();
275
276 for (Int_t i=1; i<fArray->GetEntries(); i++)
277 {
278 const MPedestalPix &pix = (*this)[i];
279
280 Float_t testval = pix.GetPedestalRms();
281
282 if (geom)
283 testval *= geom->GetPixRatio(i);
284
285 if (testval < minval)
286 minval = testval;
287 }
288 return minval;
289}
290
291Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
292{
293 if (fArray->GetEntries() <= 0)
294 return 50.;
295
296 Float_t maxval = (*this)[0].GetPedestalRms();
297
298 for (Int_t i=1; i<fArray->GetEntries(); i++)
299 {
300 const MPedestalPix &pix = (*this)[i];
301
302 Float_t testval = pix.GetPedestalRms();
303
304 if (geom)
305 testval *= geom->GetPixRatio(i);
306
307 if (testval > maxval)
308 maxval = testval;
309 }
310 return maxval;
311}
312
313Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const {
314
315 if (GetSize() <= idx)
316 return kFALSE;
317
318 if (!(*this)[idx].IsValid())
319 return kFALSE;
320
321 switch (type) {
322 case 0:
323 val = (*this)[idx].GetPedestal();
324 break;
325 case 1:
326 val = fTotalEntries > 0 ?
327 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)
328 : (*this)[idx].GetPedestalError();
329 break;
330 case 2:
331 val = (*this)[idx].GetPedestalRms();
332 break;
333 case 3:
334 val = fTotalEntries > 0 ?
335 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)/2.
336 : (*this)[idx].GetPedestalRmsError();
337 break;
338 default:
339 return kFALSE;
340 }
341 return kTRUE;
342}
343
344void MPedestalCam::DrawPixelContent(Int_t idx) const
345{
346 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
347}
Note: See TracBrowser for help on using the repository browser.