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

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