source: trunk/MagicSoft/Mars/mpedestal/MPedPhotCam.cc@ 4693

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