source: trunk/Mars/mpedestal/MPedPhotCam.cc@ 13449

Last change on this file since 13449 was 9374, checked in by tbretz, 16 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/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Hendrik Bartko, 07/2003 <mailto:hbartko@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MPedPhotCam
29//
30// Hold the Pedestal information for all pixels in the camera (in usints
31// of photons)
32//
33// Version 2:
34// ----------
35// - added fAreas
36// - added fSectors
37//
38/////////////////////////////////////////////////////////////////////////////
39#include "MPedPhotCam.h"
40
41#include <TClonesArray.h>
42
43#include "MArrayI.h"
44#include "MArrayD.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MPedPhotPix.h"
50
51#include "MGeomCam.h"
52#include "MGeom.h"
53
54#include "MBadPixelsCam.h"
55#include "MBadPixelsPix.h"
56
57#include "MPedestalCam.h"
58#include "MPedestalPix.h"
59
60ClassImp(MPedPhotCam);
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Contains the default constructor. Creates a MPedPhotPix object
67// for each pixel
68//
69void MPedPhotCam::InitArrays(const char *name, const char *title)
70{
71 fName = name ? name : "MPedPhotCam";
72 fTitle = title ? title : "Storage container for all Pedestal Information in the camera (in units of photons)";
73
74 fArray = new TClonesArray("MPedPhotPix", 1);
75 fAreas = new TClonesArray("MPedPhotPix", 1);
76 fSectors = new TClonesArray("MPedPhotPix", 1);
77}
78
79// --------------------------------------------------------------------------
80//
81// Default constructor. Creates a MPedPhotPix object for each pixel
82//
83MPedPhotCam::MPedPhotCam(const char *name, const char *title)
84{
85 InitArrays(name, title);
86}
87
88// --------------------------------------------------------------------------
89//
90// Initialize the mean, rms and number of events with the values from
91// the MPedestalCam converted 1:1
92//
93MPedPhotCam::MPedPhotCam(const MPedestalCam &p)
94{
95 const Int_t n = p.GetSize();
96
97 InitArrays();
98 InitSize(n);
99
100 for (int i=0; i<n; i++)
101 (*this)[i].Set(p[i].GetPedestal(), p[i].GetPedestalRms(), p[i].GetNumEvents());
102}
103
104// --------------------------------------------------------------------------
105//
106// Delete the array conatining the pixel pedest information
107//
108MPedPhotCam::~MPedPhotCam()
109{
110 delete fArray;
111 delete fAreas;
112 delete fSectors;
113}
114
115// --------------------------------------------------------------------------
116//
117// Set the size of the camera
118//
119void MPedPhotCam::InitSize(const UInt_t i)
120{
121 fArray->ExpandCreate(i);
122}
123
124// -------------------------------------------------------------------
125//
126// Calls TClonesArray::ExpandCreate() for:
127// - fAverageAreas
128//
129void MPedPhotCam::InitAreas(const UInt_t i)
130{
131 fAreas->ExpandCreate(i);
132}
133
134// -------------------------------------------------------------------
135//
136// Calls TClonesArray::ExpandCreate() for:
137// - fAverageSectors
138//
139void MPedPhotCam::InitSectors(const UInt_t i)
140{
141 fSectors->ExpandCreate(i);
142}
143
144// -------------------------------------------------------------------
145//
146// Calls:
147// - InitSize()
148// - InitAverageAreas()
149// - InitAverageSectors()
150//
151void MPedPhotCam::Init(const MGeomCam &geom)
152{
153 InitSize(geom.GetNumPixels());
154 InitAreas(geom.GetNumAreas());
155 InitSectors(geom.GetNumSectors());
156}
157
158
159// --------------------------------------------------------------------------
160//
161// Get the size of the MPedPhotCam
162//
163Int_t MPedPhotCam::GetSize() const
164{
165 return fArray->GetEntriesFast();
166}
167
168// --------------------------------------------------------------------------
169//
170// Get the size of the MPedPhotCam
171//
172Int_t MPedPhotCam::GetNumSectors() const
173{
174 return fSectors->GetEntriesFast();
175}
176
177// --------------------------------------------------------------------------
178//
179// Get the size of the MPedPhotCam
180//
181Int_t MPedPhotCam::GetNumAreas() const
182{
183 return fAreas->GetEntriesFast();
184}
185
186// --------------------------------------------------------------------------
187//
188// Get i-th pixel (pixel number)
189//
190MPedPhotPix &MPedPhotCam::operator[](Int_t i)
191{
192 return *static_cast<MPedPhotPix*>(fArray->UncheckedAt(i));
193}
194
195// --------------------------------------------------------------------------
196//
197// Get i-th pixel (pixel number)
198//
199const MPedPhotPix &MPedPhotCam::operator[](Int_t i) const
200{
201 return *static_cast<MPedPhotPix*>(fArray->UncheckedAt(i));
202}
203
204// --------------------------------------------------------------------------
205//
206// Get i-th average pixel (area number)
207//
208MPedPhotPix &MPedPhotCam::GetArea(UInt_t i)
209{
210 return *static_cast<MPedPhotPix*>(fAreas->UncheckedAt(i));
211}
212
213// --------------------------------------------------------------------------
214//
215// Get i-th average pixel (sector number)
216//
217MPedPhotPix &MPedPhotCam::GetSector(UInt_t i)
218{
219 return *static_cast<MPedPhotPix*>(fSectors->UncheckedAt(i));
220}
221
222// --------------------------------------------------------------------------
223//
224// Get i-th average pixel (area number)
225//
226const MPedPhotPix &MPedPhotCam::GetArea(UInt_t i)const
227{
228 return *static_cast<MPedPhotPix*>(fAreas->UncheckedAt(i));
229}
230
231// --------------------------------------------------------------------------
232//
233// Get i-th average pixel (sector number)
234//
235const MPedPhotPix &MPedPhotCam::GetSector(UInt_t i) const
236{
237 return *static_cast<MPedPhotPix*>(fSectors->UncheckedAt(i));
238}
239
240// --------------------------------------------------------------------------
241//
242// Call clear of all three TClonesArray
243//
244void MPedPhotCam::Clear(Option_t *o)
245{
246 { fArray->R__FOR_EACH(TObject, Clear)(); }
247 { fAreas->R__FOR_EACH(TObject, Clear)(); }
248 { fSectors->R__FOR_EACH(TObject, Clear)(); }
249}
250
251// --------------------------------------------------------------------------
252//
253// Calculates the avarage pedestal and pedestal rms for all sectors
254// and pixel sizes. The geometry container is used to get the necessary
255// geometry information (sector number, size index) If the bad pixel
256// container is given all pixels which have the flag 'bad' are ignored
257// in the calculation of the sector and size average.
258//
259void MPedPhotCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad)
260{
261 const Int_t np = GetSize();
262 const Int_t ns = GetNumSectors();
263 const Int_t na = GetNumAreas();
264
265 // Using MArray instead of TArray because they don't do range checks
266 MArrayI acnt(na);
267 MArrayI scnt(ns);
268 MArrayD asumx(na);
269 MArrayD ssumx(ns);
270 MArrayD asumr(na);
271 MArrayD ssumr(ns);
272
273 for (int i=0; i<np; i++)
274 {
275 if (bad && (*bad)[i].IsUnsuitable())
276 continue;
277
278 // Create sums for areas and sectors
279 const MPedPhotPix &pix = (*this)[i];
280
281 const UInt_t ne = pix.GetNumEvents();
282 const Float_t mean = ne*pix.GetMean();
283 const Float_t rms = ne*pix.GetRms();
284
285 const UInt_t aidx = geom[i].GetAidx();
286 asumx[aidx] += mean;
287 asumr[aidx] += rms;
288 acnt[aidx] += ne;
289
290 const UInt_t sect = geom[i].GetSector();
291 ssumx[sect] += mean;
292 ssumr[sect] += rms;
293 scnt[sect] += ne;
294 }
295
296 for (int i=0; i<ns; i++)
297 if (scnt[i]>0)
298 GetSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], scnt[i]);
299 else
300 GetSector(i).Clear();
301
302 for (int i=0; i<na; i++)
303 if (acnt[i]>0)
304 GetArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], acnt[i]);
305 else
306 GetArea(i).Clear();
307}
308
309// --------------------------------------------------------------------------
310//
311// print contents
312//
313void MPedPhotCam::Print(Option_t *o) const
314{
315 *fLog << all << GetDescriptor() << ":" << endl;
316 int id = 0;
317
318 TIter Next(fArray);
319 MPedPhotPix *pix;
320 while ((pix=(MPedPhotPix*)Next()))
321 {
322 id++;
323
324 if (!pix->IsValid())
325 continue;
326
327 *fLog << id-1 << ": ";
328 *fLog << pix->GetMean() << " " << pix->GetRms() << endl;
329 }
330}
331
332// --------------------------------------------------------------------------
333//
334// See MCamEvent
335//
336Bool_t MPedPhotCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
337{
338 if (idx>=GetSize())
339 return kFALSE;
340
341 switch (type)
342 {
343 case 0:
344 val = (*this)[idx].GetMean();
345 break;
346 case 1:
347 val = (*this)[idx].GetRms();
348 break;
349 case 2:
350 val = (*this)[idx].GetNumEvents()>0 ? (*this)[idx].GetRms()/TMath::Sqrt((Float_t)(*this)[idx].GetNumEvents()) : -1;
351 break;
352 case 3:
353 val = (*this)[idx].GetNumEvents()>0 ? (*this)[idx].GetRms()/TMath::Sqrt((Float_t)(*this)[idx].GetNumEvents())/2. : -1;
354 break;
355 case 4:
356 val = (*this)[idx].GetMean()*cam.GetPixRatio(idx);
357 break;
358 case 5:
359 val = (*this)[idx].GetRms()*cam.GetPixRatioSqrt(idx);
360 break;
361 default:
362 return kFALSE;
363 }
364 return val>=0;
365}
366
367void MPedPhotCam::DrawPixelContent(Int_t num) const
368{
369 *fLog << warn << "MPedPhotCam::DrawPixelContent - not available." << endl;
370}
Note: See TracBrowser for help on using the repository browser.