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

Last change on this file since 7194 was 7082, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 12.1 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!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MCameraData
29//
30// This is a generalized class storing camera data. For example the cleaning
31// level for the image cleaning is one possibility.
32//
33/////////////////////////////////////////////////////////////////////////////
34#include "MCameraData.h"
35
36#include "MMath.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MGeomCam.h"
42#include "MGeomPix.h"
43
44#include "MPedPhotCam.h"
45#include "MPedPhotPix.h"
46
47#include "MSignalCam.h"
48#include "MSignalPix.h"
49
50ClassImp(MCameraData);
51
52using namespace std;
53
54// --------------------------------------------------------------------------
55//
56// Creates a MSignalPix object for each pixel in the event
57//
58MCameraData::MCameraData(const char *name, const char *title)
59{
60 fName = name ? name : "MCameraData";
61 fTitle = title ? title : "Generalized storage container for camera contents";
62}
63
64/*
65// --------------------------------------------------------------------------
66//
67// This is not yet implemented like it should.
68//
69
70void MCameraData::Draw(Option_t* option)
71{
72 //
73 // FIXME!!! Here the Draw function of the CamDisplay
74 // should be called to add the CamDisplay to the Pad.
75 // The drawing should be done in MCamDisplay::Paint
76 //
77
78 // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
79 // MCamDisplay *disp = new MCamDisplay(geom);
80 // delete geom;
81 // disp->DrawPhotNum(this);
82}
83*/
84
85
86// --------------------------------------------------------------------------
87//
88// Function to calculate the cleaning level for all pixels in a given event
89// as the ratio between the measured photons and the pedestal rms.
90// In order to do the image cleaning on average in the same photon flux
91// (reconstructed photons per pixel area) for the inner and outer pixels,
92// a correction factor is applied to the outer pixels (see TDAS 02-14).
93// The correction factor assumes the ideal case that the pedestal rms
94// scales with the inverse square root of the pixel area.
95//
96// FIXME: Should the check noise<=0 be replaced by MBadPixels?
97//
98void MCameraData::CalcCleaningLevel(const MSignalCam &evt, const MPedPhotCam &cam,
99 const MGeomCam &geom)
100{
101 const Int_t n = geom.GetNumPixels();
102
103 // Reset arrays
104 fData.Set(n);
105 fData.Reset();
106
107 fValidity.Set(n);
108 fValidity.Reset();
109
110 const Int_t entries = evt.GetNumPixels();
111
112 // calculate cleaning levels
113 for (Int_t idx=0; idx<entries; idx++)
114 {
115 const MSignalPix &pix = evt[idx];
116
117 const Float_t noise = cam[idx].GetRms();
118
119 if (noise<=0) // fData[idx]=0, fValidity[idx]=0
120 continue;
121
122 //
123 // We calculate a correction factor which accounts for the
124 // fact that pixels have different size (see TDAS 02-14).
125 //
126 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
127 fValidity[idx] = 1;
128 }
129}
130
131// --------------------------------------------------------------------------
132//
133// Function to calculate the cleaning level for all pixels in a given event
134// as the ratio between the measured photons and the pedestal rms.
135// In order to do the image cleaning on average in the same photon flux
136// (reconstructed photons per pixel area) for the inner and outer pixels,
137// a correction factor is applied to the outer pixels (see TDAS 02-14).
138// The correction factor takes the actual average pedestal RMS of the
139// inner and outer pixels into account.
140//
141// FIXME: Should the check noise<=0 be replaced by MBadPixels?
142//
143void MCameraData::CalcCleaningLevel2(const MSignalCam &evt, const MPedPhotCam &cam,
144 const MGeomCam &geom)
145{
146 const Int_t n = geom.GetNumPixels();
147
148 // reset arrays
149 fData.Set(n);
150 fData.Reset();
151
152 fValidity.Set(n);
153 fValidity.Reset();
154
155 // check validity of rms with area index 0
156 const Float_t anoise0 = cam.GetArea(0).GetRms();
157 if (anoise0<=0)
158 return;
159
160 // calculate cleaning levels
161 const Int_t entries = evt.GetNumPixels();
162 for (Int_t idx=0; idx<entries; idx++)
163 {
164 const MSignalPix &pix = evt[idx];
165
166 const Float_t noise = cam[idx].GetRms();
167
168 if (noise<=0) // fData[idx]=0, fValidity[idx]=0
169 continue;
170
171 //
172 // We calculate a correction factor which accounts for the
173 // fact that pixels have different size (see TDAS 02-14).
174 // We also take into account that the RMS does not scale
175 // with the square root of the pixel area.
176 //
177 const UInt_t aidx = geom[idx].GetAidx();
178 const Float_t ratio = cam.GetArea(aidx).GetRms()/anoise0;
179
180 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / noise;
181 fValidity[idx] = 1;
182 }
183}
184
185void MCameraData::CalcCleaningLevel(const MSignalCam &evt, Double_t noise,
186 const MGeomCam &geom)
187{
188 const Int_t n = geom.GetNumPixels();
189
190 // reset arrays
191 fData.Set(n);
192 fData.Reset();
193
194 fValidity.Set(n);
195 fValidity.Reset();
196
197 // check validity of noise
198 if (noise<=0)
199 return;
200
201 // calculate cleaning levels
202 const Int_t entries = evt.GetNumPixels();
203 for (Int_t idx=0; idx<entries; idx++)
204 {
205 const MSignalPix &pix = evt[idx];
206
207 //
208 // We calculate a correction factor which accounts for the
209 // fact that pixels have different size (see TDAS 02-14).
210 //
211 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise;
212 fValidity[idx] = 1;
213 }
214}
215
216// --------------------------------------------------------------------------
217//
218// Function to calculate the cleaning level for all pixels in a given event
219// as the ratio between the reconstructed number of photons per area of an
220// inner pixel and the average pedestal RMS of the inner pixels (democratic
221// image cleaning, see TDAS 02-14).
222//
223// FIXME: Should the check noise<=0 be replaced by MBadPixels?
224//
225void MCameraData::CalcCleaningLevelDemocratic(const MSignalCam &evt, const MPedPhotCam &cam,
226 const MGeomCam &geom)
227{
228 const Int_t n = geom.GetNumPixels();
229
230 // reset arrays
231 fData.Set(n);
232 fData.Reset();
233
234 fValidity.Set(n);
235 fValidity.Reset();
236
237 // check validity of rms with area index 0
238 const Float_t noise0 = cam.GetArea(0).GetRms();
239 if (noise0<=0)
240 return;
241
242 // calculate cleaning levels
243 const Int_t entries = evt.GetNumPixels();
244 for (Int_t idx=0; idx<entries; idx++)
245 {
246 const MSignalPix &pix = evt[idx];
247
248 const Float_t noise = cam[idx].GetRms();
249
250 if (noise<=0)
251 continue;
252
253 //
254 // We calculate a correction factor which accounts for the
255 // fact that pixels have different size (see TDAS 02-14).
256 //
257 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise0;
258 fValidity[idx] = 1;
259 }
260}
261
262// --------------------------------------------------------------------------
263//
264// Function to calculate the cleaning level for all pixels in a given event.
265// The level is the probability that the signal is a real signal (taking
266// the signal height and the fluctuation of the background into account)
267// times one minus the probability that the signal is a background
268// fluctuation (calculated from the time spread of arrival times
269// around the pixel with the highest signal)
270//
271// FIXME: Should the check noise<=0 be replaced by MBadPixels?
272//
273void MCameraData::CalcCleaningProbability(const MSignalCam &evt, const MPedPhotCam &pcam,
274 const MGeomCam &geom)
275{
276 const Int_t n = geom.GetNumPixels();
277
278 // Reset arrays
279 fData.Set(n);
280 fData.Reset();
281
282 fValidity.Set(n);
283 fValidity.Reset();
284
285 // check validity of noise
286 const Float_t anoise0 = pcam.GetArea(0).GetRms();
287 if (anoise0<=0)
288 return;
289
290 const Int_t entries = evt.GetNumPixels();
291
292 // Find pixel with max signal
293 Int_t maxidx = 0;
294
295 // Find pixel entry with maximum signal
296 for (Int_t i=0; i<entries; i++)
297 {
298 const Double_t s0 = evt[i].GetNumPhotons() * geom.GetPixRatio(i);
299 const Double_t s1 = evt[maxidx].GetNumPhotons() * geom.GetPixRatio(maxidx);
300 if (s0>s1)
301 maxidx = i;
302 }
303
304 const Double_t timemean = evt[maxidx].GetArrivalTime();
305 const Double_t timerms = 0.75; //[slices] rms time spread around highest pixel
306
307 // calculate cleaning levels
308 for (Int_t idx=0; idx<entries; idx++)
309 {
310 const MSignalPix &spix = evt[idx];
311
312 const Float_t rms = pcam[idx].GetRms();
313 if (rms<=0) // fData[idx]=0, fValidity[idx]=0
314 continue;
315
316 fValidity[idx]=1;
317
318 // get signal and arrival time
319 const UInt_t aidx = geom[idx].GetAidx();
320 const Float_t ratio = pcam.GetArea(aidx).GetRms()/anoise0;
321
322 const Double_t signal = spix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / rms;
323 const Double_t time = evt[idx].GetArrivalTime();
324
325 // if signal<0 the probability is equal 0
326 if (signal<0)
327 continue;
328
329 // Just for convinience for easy readybility
330 const Double_t means = 0;
331 const Double_t meant = timemean;
332
333 const Double_t sigmas = rms;
334 const Double_t sigmat = timerms;
335
336 // Get probabilities
337 const Double_t psignal = MMath::GaussProb(signal, sigmas, means);
338 const Double_t pbckgnd = MMath::GaussProb(time, sigmat, meant);
339
340 // Set probability
341 fData[idx] = psignal*(1-pbckgnd);
342 fValidity[idx] = 1;
343
344 // Make sure, that we don't run into trouble because of
345 // a little numerical uncertanty
346 if (fData[idx]>1)
347 fData[idx]=1;
348 if (fData[idx]<0)
349 fData[idx]=0;
350 }
351}
352
353// --------------------------------------------------------------------------
354//
355// Function to calculate the cleaning level for all pixels in a given event.
356// The level is the absolute number of photons times the area-ratio.
357//
358void MCameraData::CalcCleaningAbsolute(const MSignalCam &evt, const MGeomCam &geom)
359{
360 const Int_t n = geom.GetNumPixels();
361
362 // Reset arrays
363 fData.Set(n);
364 fData.Reset();
365
366 fValidity.Set(n);
367 fValidity.Reset();
368
369 const Int_t entries = evt.GetNumPixels();
370
371 // calculate cleaning levels
372 for (Int_t idx=0; idx<entries; idx++)
373 {
374 const MSignalPix &spix = evt[idx];
375
376 // Set probability
377 fData[idx] = spix.GetNumPhotons() * geom.GetPixRatio(idx);
378 fValidity[idx] = 1;
379 }
380}
381
382// --------------------------------------------------------------------------
383//
384// Returns the contents of the pixel.
385//
386Bool_t MCameraData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
387{
388 if (idx<0 || idx>=fData.GetSize())
389 return kFALSE;
390
391 val = fData[idx];
392 return fValidity[idx];
393}
394
395void MCameraData::DrawPixelContent(Int_t num) const
396{
397 *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
398}
399
400void MCameraData::Print(Option_t *o) const
401{
402 MParContainer::Print(o);
403 *fLog << "Size = " << fData.GetSize() << endl;
404 for (int i=0; i<fData.GetSize(); i++)
405 cout << i << ": " << fData[i] << endl;
406}
Note: See TracBrowser for help on using the repository browser.