source: trunk/MagicSoft/Mars/manalysis/MCameraData.cc@ 8809

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