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 |
|
---|
56 | ClassImp(MPedPhotCam);
|
---|
57 |
|
---|
58 | using namespace std;
|
---|
59 |
|
---|
60 | // --------------------------------------------------------------------------
|
---|
61 | //
|
---|
62 | // Default constructor. Creates a MPedPhotPix object for each pixel
|
---|
63 | //
|
---|
64 | MPedPhotCam::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 | //
|
---|
78 | MPedPhotCam::~MPedPhotCam()
|
---|
79 | {
|
---|
80 | delete fArray;
|
---|
81 | delete fAreas;
|
---|
82 | delete fSectors;
|
---|
83 | }
|
---|
84 |
|
---|
85 | // --------------------------------------------------------------------------
|
---|
86 | //
|
---|
87 | // Set the size of the camera
|
---|
88 | //
|
---|
89 | void MPedPhotCam::InitSize(const UInt_t i)
|
---|
90 | {
|
---|
91 | fArray->ExpandCreate(i);
|
---|
92 | }
|
---|
93 |
|
---|
94 | // -------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // Calls TClonesArray::ExpandCreate() for:
|
---|
97 | // - fAverageAreas
|
---|
98 | //
|
---|
99 | void MPedPhotCam::InitAreas(const UInt_t i)
|
---|
100 | {
|
---|
101 | fAreas->ExpandCreate(i);
|
---|
102 | }
|
---|
103 |
|
---|
104 | // -------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // Calls TClonesArray::ExpandCreate() for:
|
---|
107 | // - fAverageSectors
|
---|
108 | //
|
---|
109 | void MPedPhotCam::InitSectors(const UInt_t i)
|
---|
110 | {
|
---|
111 | fSectors->ExpandCreate(i);
|
---|
112 | }
|
---|
113 |
|
---|
114 | // -------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Calls:
|
---|
117 | // - InitSize()
|
---|
118 | // - InitAverageAreas()
|
---|
119 | // - InitAverageSectors()
|
---|
120 | //
|
---|
121 | void 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 | //
|
---|
133 | Int_t MPedPhotCam::GetSize() const
|
---|
134 | {
|
---|
135 | return fArray->GetEntriesFast();
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Get the size of the MPedPhotCam
|
---|
141 | //
|
---|
142 | Int_t MPedPhotCam::GetNumSectors() const
|
---|
143 | {
|
---|
144 | return fSectors->GetEntriesFast();
|
---|
145 | }
|
---|
146 |
|
---|
147 | // --------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // Get the size of the MPedPhotCam
|
---|
150 | //
|
---|
151 | Int_t MPedPhotCam::GetNumAreas() const
|
---|
152 | {
|
---|
153 | return fAreas->GetEntriesFast();
|
---|
154 | }
|
---|
155 |
|
---|
156 | // --------------------------------------------------------------------------
|
---|
157 | //
|
---|
158 | // Get i-th pixel (pixel number)
|
---|
159 | //
|
---|
160 | MPedPhotPix &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 | //
|
---|
169 | const 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 | //
|
---|
178 | MPedPhotPix &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 | //
|
---|
187 | MPedPhotPix &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 | //
|
---|
196 | const 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 | //
|
---|
205 | const 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 | //
|
---|
214 | void 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 | //
|
---|
229 | void MPedPhotCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad)
|
---|
230 | {
|
---|
231 |
|
---|
232 | const Int_t np = GetSize();
|
---|
233 | const Int_t ns = GetNumSectors();
|
---|
234 | const Int_t na = GetNumAreas();
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 | TArrayI acnt(na);
|
---|
239 | TArrayI scnt(ns);
|
---|
240 | TArrayD asumx(na);
|
---|
241 | TArrayD ssumx(ns);
|
---|
242 | TArrayD asumr(na);
|
---|
243 | TArrayD ssumr(ns);
|
---|
244 |
|
---|
245 |
|
---|
246 | for (int i=0; i<np; i++)
|
---|
247 | {
|
---|
248 |
|
---|
249 |
|
---|
250 | if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
|
---|
251 | continue; //was: .IsBad()
|
---|
252 |
|
---|
253 | // Create sums for areas and sectors
|
---|
254 | const UInt_t aidx = geom[i].GetAidx();
|
---|
255 | const UInt_t sect = geom[i].GetSector();
|
---|
256 |
|
---|
257 | const MPedPhotPix &pix = (*this)[i];
|
---|
258 |
|
---|
259 | const UInt_t ne = pix.GetNumEvents();
|
---|
260 | const Float_t mean = pix.GetMean();
|
---|
261 | const Float_t rms = pix.GetRms();
|
---|
262 |
|
---|
263 | asumx[aidx] += ne*mean;
|
---|
264 | asumr[aidx] += ne*rms;
|
---|
265 | acnt[aidx] += ne;
|
---|
266 |
|
---|
267 | ssumx[sect] += ne*mean;
|
---|
268 | ssumr[sect] += ne*rms;
|
---|
269 | scnt[sect] += ne;
|
---|
270 |
|
---|
271 |
|
---|
272 | }
|
---|
273 |
|
---|
274 | for (int i=0; i<ns; i++){
|
---|
275 | if (scnt[i]>0) GetSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], scnt[i]);
|
---|
276 | else GetSector(i).Set(-1., -1., 0);
|
---|
277 | }
|
---|
278 |
|
---|
279 | for (int i=0; i<na; i++){
|
---|
280 | if (acnt[i]>0) GetArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], acnt[i]);
|
---|
281 | else GetArea(i).Set(-1., -1., 0);
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | // --------------------------------------------------------------------------
|
---|
286 | //
|
---|
287 | // print contents
|
---|
288 | //
|
---|
289 | void MPedPhotCam::Print(Option_t *o) const
|
---|
290 | {
|
---|
291 | *fLog << all << GetDescriptor() << ":" << endl;
|
---|
292 | int id = 0;
|
---|
293 |
|
---|
294 | TIter Next(fArray);
|
---|
295 | MPedPhotPix *pix;
|
---|
296 | while ((pix=(MPedPhotPix*)Next()))
|
---|
297 | {
|
---|
298 | id++;
|
---|
299 |
|
---|
300 | if (!pix->IsValid())
|
---|
301 | continue;
|
---|
302 |
|
---|
303 | *fLog << id-1 << ": ";
|
---|
304 | *fLog << pix->GetMean() << " " << pix->GetRms() << endl;
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | // --------------------------------------------------------------------------
|
---|
309 | //
|
---|
310 | // See MCamEvent
|
---|
311 | //
|
---|
312 | Bool_t MPedPhotCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
313 | {
|
---|
314 |
|
---|
315 | const Float_t ped = (*this)[idx].GetMean();
|
---|
316 | const Float_t rms = (*this)[idx].GetRms();
|
---|
317 | const UInt_t nevt = (*this)[idx].GetNumEvents();
|
---|
318 |
|
---|
319 |
|
---|
320 | Float_t pederr;
|
---|
321 | Float_t rmserr;
|
---|
322 |
|
---|
323 | if (nevt>0)
|
---|
324 | {
|
---|
325 | pederr = rms/TMath::Sqrt((Float_t)nevt);
|
---|
326 | rmserr = rms/TMath::Sqrt((Float_t)nevt)/2.;
|
---|
327 | }
|
---|
328 | else
|
---|
329 | {
|
---|
330 | pederr = -1;
|
---|
331 | rmserr = -1;
|
---|
332 | }
|
---|
333 |
|
---|
334 | switch (type)
|
---|
335 | {
|
---|
336 | case 0:
|
---|
337 | val = ped;// (*this)[idx].GetMean();
|
---|
338 | break;
|
---|
339 | case 1:
|
---|
340 | val = rms; // (*this)[idx].GetRms();
|
---|
341 | break;
|
---|
342 | case 2:
|
---|
343 | val = pederr; // new
|
---|
344 | break;
|
---|
345 | case 3:
|
---|
346 | val = rmserr; // new
|
---|
347 | break;
|
---|
348 | default:
|
---|
349 | return kFALSE;
|
---|
350 | }
|
---|
351 | return val>=0;
|
---|
352 | }
|
---|
353 |
|
---|
354 | void MPedPhotCam::DrawPixelContent(Int_t num) const
|
---|
355 | {
|
---|
356 | *fLog << warn << "MPedPhotCam::DrawPixelContent - not available." << endl;
|
---|
357 | }
|
---|