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, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Hendrik Bartko, 08/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
20 | ! Author(s): Stefan Ruegamer, 03/2006 <mailto:snruegam@astro.uni-wuerzburg.de>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MCameraData
|
---|
30 | //
|
---|
31 | // This is a generalized class storing camera data. For example the cleaning
|
---|
32 | // level for the image cleaning is one possibility.
|
---|
33 | //
|
---|
34 | /////////////////////////////////////////////////////////////////////////////
|
---|
35 | #include "MCameraData.h"
|
---|
36 |
|
---|
37 | #include "MMath.h"
|
---|
38 |
|
---|
39 | #include "MLog.h"
|
---|
40 | #include "MLogManip.h"
|
---|
41 |
|
---|
42 | #include "MGeomCam.h"
|
---|
43 | #include "MGeomPix.h"
|
---|
44 |
|
---|
45 | #include "MPedPhotCam.h"
|
---|
46 | #include "MPedPhotPix.h"
|
---|
47 |
|
---|
48 | #include "MSignalCam.h"
|
---|
49 | #include "MSignalPix.h"
|
---|
50 |
|
---|
51 | ClassImp(MCameraData);
|
---|
52 |
|
---|
53 | using namespace std;
|
---|
54 |
|
---|
55 | // --------------------------------------------------------------------------
|
---|
56 | //
|
---|
57 | // Creates a MSignalPix object for each pixel in the event
|
---|
58 | //
|
---|
59 | MCameraData::MCameraData(const char *name, const char *title)
|
---|
60 | {
|
---|
61 | fName = name ? name : "MCameraData";
|
---|
62 | fTitle = title ? title : "Generalized storage container for camera contents";
|
---|
63 | }
|
---|
64 |
|
---|
65 | /*
|
---|
66 | // --------------------------------------------------------------------------
|
---|
67 | //
|
---|
68 | // This is not yet implemented like it should.
|
---|
69 | //
|
---|
70 |
|
---|
71 | void MCameraData::Draw(Option_t* option)
|
---|
72 | {
|
---|
73 | //
|
---|
74 | // FIXME!!! Here the Draw function of the CamDisplay
|
---|
75 | // should be called to add the CamDisplay to the Pad.
|
---|
76 | // The drawing should be done in MCamDisplay::Paint
|
---|
77 | //
|
---|
78 |
|
---|
79 | // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
|
---|
80 | // MCamDisplay *disp = new MCamDisplay(geom);
|
---|
81 | // delete geom;
|
---|
82 | // disp->DrawPhotNum(this);
|
---|
83 | }
|
---|
84 | */
|
---|
85 |
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Function to calculate the cleaning level for all pixels in a given event
|
---|
90 | // as the ratio between the measured photons and the pedestal rms.
|
---|
91 | // In order to do the image cleaning on average in the same photon flux
|
---|
92 | // (reconstructed photons per pixel area) for the inner and outer pixels,
|
---|
93 | // a correction factor is applied to the outer pixels (see TDAS 02-14).
|
---|
94 | // The correction factor assumes the ideal case that the pedestal rms
|
---|
95 | // scales with the inverse square root of the pixel area.
|
---|
96 | //
|
---|
97 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
---|
98 | //
|
---|
99 | void MCameraData::CalcCleaningLevel(const MSignalCam &evt, const MPedPhotCam &cam,
|
---|
100 | const MGeomCam &geom)
|
---|
101 | {
|
---|
102 | const Int_t n = geom.GetNumPixels();
|
---|
103 |
|
---|
104 | // Reset arrays
|
---|
105 | fData.Set(n);
|
---|
106 | fData.Reset();
|
---|
107 |
|
---|
108 | fValidity.Set(n);
|
---|
109 | fValidity.Reset();
|
---|
110 |
|
---|
111 | const Int_t entries = evt.GetNumPixels();
|
---|
112 |
|
---|
113 | // calculate cleaning levels
|
---|
114 | for (Int_t idx=0; idx<entries; idx++)
|
---|
115 | {
|
---|
116 | const MSignalPix &pix = evt[idx];
|
---|
117 |
|
---|
118 | const Float_t noise = cam[idx].GetRms();
|
---|
119 |
|
---|
120 | if (noise<=0) // fData[idx]=0, fValidity[idx]=0
|
---|
121 | continue;
|
---|
122 |
|
---|
123 | //
|
---|
124 | // We calculate a correction factor which accounts for the
|
---|
125 | // fact that pixels have different size (see TDAS 02-14).
|
---|
126 | //
|
---|
127 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
|
---|
128 | fValidity[idx] = 1;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // Function to calculate the cleaning level for all pixels in a given event
|
---|
135 | // as the ratio between the measured photons and the pedestal rms.
|
---|
136 | // In order to do the image cleaning on average in the same photon flux
|
---|
137 | // (reconstructed photons per pixel area) for the inner and outer pixels,
|
---|
138 | // a correction factor is applied to the outer pixels (see TDAS 02-14).
|
---|
139 | // The correction factor takes the actual average pedestal RMS of the
|
---|
140 | // inner and outer pixels into account.
|
---|
141 | //
|
---|
142 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
---|
143 | //
|
---|
144 | void MCameraData::CalcCleaningLevel2(const MSignalCam &evt, const MPedPhotCam &cam,
|
---|
145 | const MGeomCam &geom)
|
---|
146 | {
|
---|
147 | const Int_t n = geom.GetNumPixels();
|
---|
148 |
|
---|
149 | // reset arrays
|
---|
150 | fData.Set(n);
|
---|
151 | fData.Reset();
|
---|
152 |
|
---|
153 | fValidity.Set(n);
|
---|
154 | fValidity.Reset();
|
---|
155 |
|
---|
156 | // check validity of rms with area index 0
|
---|
157 | const Float_t anoise0 = cam.GetArea(0).GetRms();
|
---|
158 | if (anoise0<=0)
|
---|
159 | return;
|
---|
160 |
|
---|
161 | // calculate cleaning levels
|
---|
162 | const Int_t entries = evt.GetNumPixels();
|
---|
163 | for (Int_t idx=0; idx<entries; idx++)
|
---|
164 | {
|
---|
165 | const MSignalPix &pix = evt[idx];
|
---|
166 |
|
---|
167 | const Float_t noise = cam[idx].GetRms();
|
---|
168 |
|
---|
169 | if (noise<=0) // fData[idx]=0, fValidity[idx]=0
|
---|
170 | continue;
|
---|
171 |
|
---|
172 | //
|
---|
173 | // We calculate a correction factor which accounts for the
|
---|
174 | // fact that pixels have different size (see TDAS 02-14).
|
---|
175 | // We also take into account that the RMS does not scale
|
---|
176 | // with the square root of the pixel area.
|
---|
177 | //
|
---|
178 | const UInt_t aidx = geom[idx].GetAidx();
|
---|
179 | const Float_t ratio = cam.GetArea(aidx).GetRms()/anoise0;
|
---|
180 |
|
---|
181 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / noise;
|
---|
182 | fValidity[idx] = 1;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | void MCameraData::CalcCleaningLevel(const MSignalCam &evt, Double_t noise,
|
---|
187 | const MGeomCam &geom)
|
---|
188 | {
|
---|
189 | const Int_t n = geom.GetNumPixels();
|
---|
190 |
|
---|
191 | // reset arrays
|
---|
192 | fData.Set(n);
|
---|
193 | fData.Reset();
|
---|
194 |
|
---|
195 | fValidity.Set(n);
|
---|
196 | fValidity.Reset();
|
---|
197 |
|
---|
198 | // check validity of noise
|
---|
199 | if (noise<=0)
|
---|
200 | return;
|
---|
201 |
|
---|
202 | // calculate cleaning levels
|
---|
203 | const Int_t entries = evt.GetNumPixels();
|
---|
204 | for (Int_t idx=0; idx<entries; idx++)
|
---|
205 | {
|
---|
206 | const MSignalPix &pix = evt[idx];
|
---|
207 |
|
---|
208 | //
|
---|
209 | // We calculate a correction factor which accounts for the
|
---|
210 | // fact that pixels have different size (see TDAS 02-14).
|
---|
211 | //
|
---|
212 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise;
|
---|
213 | fValidity[idx] = 1;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | // --------------------------------------------------------------------------
|
---|
218 | //
|
---|
219 | // Function to calculate the cleaning level for all pixels in a given event
|
---|
220 | // as the ratio between the reconstructed number of photons per area of an
|
---|
221 | // inner pixel and the average pedestal RMS of the inner pixels (democratic
|
---|
222 | // image cleaning, see TDAS 02-14).
|
---|
223 | //
|
---|
224 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
---|
225 | //
|
---|
226 | void MCameraData::CalcCleaningLevelDemocratic(const MSignalCam &evt, const MPedPhotCam &cam,
|
---|
227 | const MGeomCam &geom)
|
---|
228 | {
|
---|
229 | const Int_t n = geom.GetNumPixels();
|
---|
230 |
|
---|
231 | // reset arrays
|
---|
232 | fData.Set(n);
|
---|
233 | fData.Reset();
|
---|
234 |
|
---|
235 | fValidity.Set(n);
|
---|
236 | fValidity.Reset();
|
---|
237 |
|
---|
238 | // check validity of rms with area index 0
|
---|
239 | const Float_t noise0 = cam.GetArea(0).GetRms();
|
---|
240 | if (noise0<=0)
|
---|
241 | return;
|
---|
242 |
|
---|
243 | // calculate cleaning levels
|
---|
244 | const Int_t entries = evt.GetNumPixels();
|
---|
245 | for (Int_t idx=0; idx<entries; idx++)
|
---|
246 | {
|
---|
247 | const MSignalPix &pix = evt[idx];
|
---|
248 |
|
---|
249 | const Float_t noise = cam[idx].GetRms();
|
---|
250 |
|
---|
251 | if (noise<=0)
|
---|
252 | continue;
|
---|
253 |
|
---|
254 | //
|
---|
255 | // We calculate a correction factor which accounts for the
|
---|
256 | // fact that pixels have different size (see TDAS 02-14).
|
---|
257 | //
|
---|
258 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise0;
|
---|
259 | fValidity[idx] = 1;
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // Function to calculate the cleaning level for all pixels in a given event.
|
---|
266 | // The level is the probability that the signal is a real signal (taking
|
---|
267 | // the signal height and the fluctuation of the background into account)
|
---|
268 | // times one minus the probability that the signal is a background
|
---|
269 | // fluctuation (calculated from the time spread of arrival times
|
---|
270 | // around the pixel with the highest signal)
|
---|
271 | //
|
---|
272 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
---|
273 | //
|
---|
274 | void MCameraData::CalcCleaningProbability(const MSignalCam &evt, const MPedPhotCam &pcam,
|
---|
275 | const MGeomCam &geom)
|
---|
276 | {
|
---|
277 | const Int_t n = geom.GetNumPixels();
|
---|
278 |
|
---|
279 | // Reset arrays
|
---|
280 | fData.Set(n);
|
---|
281 | fData.Reset();
|
---|
282 |
|
---|
283 | fValidity.Set(n);
|
---|
284 | fValidity.Reset();
|
---|
285 |
|
---|
286 | // check validity of noise
|
---|
287 | const Float_t anoise0 = pcam.GetArea(0).GetRms();
|
---|
288 | if (anoise0<=0)
|
---|
289 | return;
|
---|
290 |
|
---|
291 | const Int_t entries = evt.GetNumPixels();
|
---|
292 |
|
---|
293 | // Find pixel with max signal
|
---|
294 | Int_t maxidx = 0;
|
---|
295 |
|
---|
296 | // Find pixel entry with maximum signal
|
---|
297 | for (Int_t i=0; i<entries; i++)
|
---|
298 | {
|
---|
299 | const Double_t s0 = evt[i].GetNumPhotons() * geom.GetPixRatio(i);
|
---|
300 | const Double_t s1 = evt[maxidx].GetNumPhotons() * geom.GetPixRatio(maxidx);
|
---|
301 | if (s0>s1)
|
---|
302 | maxidx = i;
|
---|
303 | }
|
---|
304 |
|
---|
305 | const Double_t timemean = evt[maxidx].GetArrivalTime();
|
---|
306 | const Double_t timerms = 0.75; //[slices] rms time spread around highest pixel
|
---|
307 |
|
---|
308 | // calculate cleaning levels
|
---|
309 | for (Int_t idx=0; idx<entries; idx++)
|
---|
310 | {
|
---|
311 | const MSignalPix &spix = evt[idx];
|
---|
312 |
|
---|
313 | const Float_t rms = pcam[idx].GetRms();
|
---|
314 | if (rms<=0) // fData[idx]=0, fValidity[idx]=0
|
---|
315 | continue;
|
---|
316 |
|
---|
317 | fValidity[idx]=1;
|
---|
318 |
|
---|
319 | // get signal and arrival time
|
---|
320 | const UInt_t aidx = geom[idx].GetAidx();
|
---|
321 | const Float_t ratio = pcam.GetArea(aidx).GetRms()/anoise0;
|
---|
322 |
|
---|
323 | const Double_t signal = spix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / rms;
|
---|
324 | const Double_t time = evt[idx].GetArrivalTime();
|
---|
325 |
|
---|
326 | // if signal<0 the probability is equal 0
|
---|
327 | if (signal<0)
|
---|
328 | continue;
|
---|
329 |
|
---|
330 | // Just for convinience for easy readybility
|
---|
331 | const Double_t means = 0;
|
---|
332 | const Double_t meant = timemean;
|
---|
333 |
|
---|
334 | const Double_t sigmas = rms;
|
---|
335 | const Double_t sigmat = timerms;
|
---|
336 |
|
---|
337 | // Get probabilities
|
---|
338 | const Double_t psignal = MMath::GaussProb(signal, sigmas, means);
|
---|
339 | const Double_t pbckgnd = MMath::GaussProb(time, sigmat, meant);
|
---|
340 |
|
---|
341 | // Set probability
|
---|
342 | fData[idx] = psignal*(1-pbckgnd);
|
---|
343 | fValidity[idx] = 1;
|
---|
344 |
|
---|
345 | // Make sure, that we don't run into trouble because of
|
---|
346 | // a little numerical uncertanty
|
---|
347 | if (fData[idx]>1)
|
---|
348 | fData[idx]=1;
|
---|
349 | if (fData[idx]<0)
|
---|
350 | fData[idx]=0;
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | // --------------------------------------------------------------------------
|
---|
355 | //
|
---|
356 | // Function to calculate the cleaning level for all pixels in a given event.
|
---|
357 | // The level is the absolute number of photons times the area-ratio.
|
---|
358 | //
|
---|
359 | void MCameraData::CalcCleaningAbsolute(const MSignalCam &evt, const MGeomCam &geom)
|
---|
360 | {
|
---|
361 | const Int_t n = geom.GetNumPixels();
|
---|
362 |
|
---|
363 | // Reset arrays
|
---|
364 | fData.Set(n);
|
---|
365 | fData.Reset();
|
---|
366 |
|
---|
367 | fValidity.Set(n);
|
---|
368 | fValidity.Reset();
|
---|
369 |
|
---|
370 | const Int_t entries = evt.GetNumPixels();
|
---|
371 |
|
---|
372 | // calculate cleaning levels
|
---|
373 | for (Int_t idx=0; idx<entries; idx++)
|
---|
374 | {
|
---|
375 | const MSignalPix &spix = evt[idx];
|
---|
376 |
|
---|
377 | // Set probability
|
---|
378 | fData[idx] = spix.GetNumPhotons() * geom.GetPixRatio(idx);
|
---|
379 | fValidity[idx] = 1;
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | void MCameraData::CalcCleaningArrivalTime(const MSignalCam &evt, const MGeomCam &geom)
|
---|
384 | {
|
---|
385 | const Int_t n = geom.GetNumPixels();
|
---|
386 |
|
---|
387 | // Reset arrays
|
---|
388 | fData.Set(n);
|
---|
389 | fData.Reset();
|
---|
390 |
|
---|
391 | fValidity.Set(n);
|
---|
392 | fValidity.Reset();
|
---|
393 |
|
---|
394 | // check validity of noise
|
---|
395 | const Int_t entries = evt.GetNumPixels();
|
---|
396 | TArrayD u(6), w(6);
|
---|
397 | TArrayI ii(6);
|
---|
398 |
|
---|
399 | for (int i=0; i<entries; i++)
|
---|
400 | {
|
---|
401 | if (evt[i].IsPixelUnmapped())
|
---|
402 | continue;
|
---|
403 |
|
---|
404 | const Double_t t0 = evt[i].GetArrivalTime();
|
---|
405 | const Double_t s0 = evt[i].GetNumPhotons();
|
---|
406 | const Double_t r0 = geom.GetPixRatio(i);
|
---|
407 | const Double_t x0 = geom[i].GetX();
|
---|
408 | const Double_t y0 = geom[i].GetY();
|
---|
409 |
|
---|
410 | const Double_t e0 = s0<0.01 ? 100 : 1./s0;
|
---|
411 |
|
---|
412 | const Int_t n2 = geom[i].GetNumNeighbors();
|
---|
413 |
|
---|
414 | Int_t cnt2=0;
|
---|
415 | for (int j=0; j<n2; j++)
|
---|
416 | {
|
---|
417 | Int_t idx = geom[i].GetNeighbor(j);
|
---|
418 |
|
---|
419 | if (evt[idx].IsPixelUnmapped())
|
---|
420 | continue;
|
---|
421 |
|
---|
422 | const Double_t tj = evt[idx].GetArrivalTime()-t0;
|
---|
423 | const Double_t sj = evt[idx].GetNumPhotons();
|
---|
424 | const Double_t rj = geom.GetPixRatio(idx)+r0;
|
---|
425 | const Double_t xj = geom[idx].GetX()-x0;
|
---|
426 | const Double_t yj = geom[idx].GetY()-y0;
|
---|
427 |
|
---|
428 | const Double_t d2 = xj*xj+yj*yj;
|
---|
429 |
|
---|
430 | const Double_t ej = sj<0.01 ? 100 : 1./sj;
|
---|
431 |
|
---|
432 | u[cnt2] = tj*tj/rj;
|
---|
433 | w[cnt2] = 1./(e0+ej)/d2; // TYPE I+II
|
---|
434 | cnt2++;
|
---|
435 | }
|
---|
436 |
|
---|
437 | TMath::Sort(cnt2, u.GetArray(), ii.GetArray(), kFALSE);
|
---|
438 |
|
---|
439 | Double_t sumt = 0;
|
---|
440 | Double_t sumw = 0;
|
---|
441 | for (int j=0; j<TMath::Min(cnt2, 3); j++)
|
---|
442 | {
|
---|
443 | sumt += u[ii[j]]*w[ii[j]];
|
---|
444 | sumw += w[ii[j]];
|
---|
445 | }
|
---|
446 |
|
---|
447 | const Double_t wuz = TMath::Sqrt(sumt/sumw);
|
---|
448 |
|
---|
449 | if (TMath::IsNaN(wuz))
|
---|
450 | *fLog << warn << "WARNING - MCameraData " << sumt << " " << sumw << endl;
|
---|
451 |
|
---|
452 | Double_t val = s0<0 || TMath::IsNaN(wuz) || wuz<1e-200 ? 0 : s0*r0/wuz;
|
---|
453 |
|
---|
454 | if ((s0>0 && wuz<1e-200) || val>100)
|
---|
455 | val=100;
|
---|
456 |
|
---|
457 | fData[i] = TMath::Log10(val+1)*5;
|
---|
458 |
|
---|
459 | if (TMath::IsNaN(fData[i]))
|
---|
460 | // 0 1e-6 0 NaN
|
---|
461 | *fLog << warn << "WARNING - MCameraData " << sumt << " " << sumw << " " << wuz << " " << val << endl;
|
---|
462 |
|
---|
463 | fValidity[i] = 1;
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | // --------------------------------------------------------------------------
|
---|
468 | //
|
---|
469 | // Returns the contents of the pixel.
|
---|
470 | //
|
---|
471 | Bool_t MCameraData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
472 | {
|
---|
473 | if (idx<0 || idx>=fData.GetSize())
|
---|
474 | return kFALSE;
|
---|
475 |
|
---|
476 | val = fData[idx];
|
---|
477 | return fValidity[idx];
|
---|
478 | }
|
---|
479 |
|
---|
480 | void MCameraData::DrawPixelContent(Int_t num) const
|
---|
481 | {
|
---|
482 | *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
|
---|
483 | }
|
---|
484 |
|
---|
485 | void MCameraData::Print(Option_t *o) const
|
---|
486 | {
|
---|
487 | MParContainer::Print(o);
|
---|
488 | *fLog << "Size = " << fData.GetSize() << endl;
|
---|
489 | for (int i=0; i<fData.GetSize(); i++)
|
---|
490 | cout << i << ": " << fData[i] << endl;
|
---|
491 | }
|
---|