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

Last change on this file since 5032 was 4838, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 12.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!
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 "MCerPhotEvt.h"
48#include "MCerPhotPix.h"
49
50#include "MSigmabar.h"
51#include "MArrivalTime.h"
52
53ClassImp(MCameraData);
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59// Creates a MCerPhotPix 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 MCerPhotEvt &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 i=0; i<entries; i++)
117 {
118 const MCerPhotPix &pix = evt[i];
119
120 const Int_t idx = pix.GetPixId();
121 const Float_t noise = cam[idx].GetRms();
122
123 if (noise<=0) // fData[idx]=0, fValidity[idx]=0
124 continue;
125
126 //
127 // We calculate a correction factor which accounts for the
128 // fact that pixels have different size (see TDAS 02-14).
129 //
130 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
131 fValidity[idx] = 1;
132 }
133}
134
135// --------------------------------------------------------------------------
136//
137// Function to calculate the cleaning level for all pixels in a given event
138// as the ratio between the measured photons and the pedestal rms.
139// In order to do the image cleaning on average in the same photon flux
140// (reconstructed photons per pixel area) for the inner and outer pixels,
141// a correction factor is applied to the outer pixels (see TDAS 02-14).
142// The correction factor takes the actual average pedestal RMS of the
143// inner and outer pixels into account.
144//
145// FIXME: Should the check noise<=0 be replaced by MBadPixels?
146//
147void MCameraData::CalcCleaningLevel2(const MCerPhotEvt &evt, const MPedPhotCam &cam,
148 const MGeomCam &geom)
149{
150 const Int_t n = geom.GetNumPixels();
151
152 // reset arrays
153 fData.Set(n);
154 fData.Reset();
155
156 fValidity.Set(n);
157 fValidity.Reset();
158
159 // check validity of rms with area index 0
160 const Float_t anoise0 = cam.GetArea(0).GetRms();
161 if (anoise0<=0)
162 return;
163
164 // calculate cleaning levels
165 const Int_t entries = evt.GetNumPixels();
166 for (Int_t i=0; i<entries; i++)
167 {
168 const MCerPhotPix &pix = evt[i];
169
170 const Int_t idx = pix.GetPixId();
171 const Float_t noise = cam[idx].GetRms();
172
173 if (noise<=0) // fData[idx]=0, fValidity[idx]=0
174 continue;
175
176 //
177 // We calculate a correction factor which accounts for the
178 // fact that pixels have different size (see TDAS 02-14).
179 // We also take into account that the RMS does not scale
180 // with the square root of the pixel area.
181 //
182 const UInt_t aidx = geom[idx].GetAidx();
183 const Float_t ratio = cam.GetArea(aidx).GetRms()/anoise0;
184
185 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / noise;
186 fValidity[idx] = 1;
187 }
188}
189
190
191void MCameraData::CalcCleaningLevel(const MCerPhotEvt &evt, const MSigmabar &sgb,
192 const MGeomCam &geom)
193{
194 CalcCleaningLevel(evt, sgb.GetSigmabarInner(), geom);
195}
196
197void MCameraData::CalcCleaningLevel(const MCerPhotEvt &evt, Double_t noise,
198 const MGeomCam &geom)
199{
200 const Int_t n = geom.GetNumPixels();
201
202 // reset arrays
203 fData.Set(n);
204 fData.Reset();
205
206 fValidity.Set(n);
207 fValidity.Reset();
208
209 // check validity of noise
210 if (noise<=0)
211 return;
212
213 // calculate cleaning levels
214 const Int_t entries = evt.GetNumPixels();
215 for (Int_t i=0; i<entries; i++)
216 {
217 const MCerPhotPix &pix = evt[i];
218
219 const Int_t idx = pix.GetPixId();
220
221 //
222 // We calculate a correction factor which accounts for the
223 // fact that pixels have different size (see TDAS 02-14).
224 //
225 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise;
226 fValidity[idx] = 1;
227 }
228}
229
230// --------------------------------------------------------------------------
231//
232// Function to calculate the cleaning level for all pixels in a given event
233// as the ratio between the reconstructed number of photons per area of an
234// inner pixel and the average pedestal RMS of the inner pixels (democratic
235// image cleaning, see TDAS 02-14).
236//
237// FIXME: Should the check noise<=0 be replaced by MBadPixels?
238//
239void MCameraData::CalcCleaningLevelDemocratic(const MCerPhotEvt &evt, const MPedPhotCam &cam,
240 const MGeomCam &geom)
241{
242 const Int_t n = geom.GetNumPixels();
243
244 // reset arrays
245 fData.Set(n);
246 fData.Reset();
247
248 fValidity.Set(n);
249 fValidity.Reset();
250
251 // check validity of rms with area index 0
252 const Float_t noise0 = cam.GetArea(0).GetRms();
253 if (noise0<=0)
254 return;
255
256 // calculate cleaning levels
257 const Int_t entries = evt.GetNumPixels();
258 for (Int_t i=0; i<entries; i++)
259 {
260 const MCerPhotPix &pix = evt[i];
261
262 const Int_t idx = pix.GetPixId();
263 const Float_t noise = cam[idx].GetRms();
264
265 if (noise<=0)
266 continue;
267
268 //
269 // We calculate a correction factor which accounts for the
270 // fact that pixels have different size (see TDAS 02-14).
271 //
272 fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise0;
273 fValidity[idx] = 1;
274 }
275}
276
277// --------------------------------------------------------------------------
278//
279// Function to calculate the cleaning level for all pixels in a given event.
280// The level is the probability that the signal is a real signal (taking
281// the signal height and the fluctuation of the background into account)
282// times one minus the probability that the signal is a background
283// fluctuation (calculated from the time spread of arrival times
284// around the pixel with the highest signal)
285//
286// FIXME: Should the check noise<=0 be replaced by MBadPixels?
287//
288void MCameraData::CalcCleaningProbability(const MCerPhotEvt &evt, const MPedPhotCam &pcam,
289 const MGeomCam &geom, const MArrivalTime *tcam)
290{
291 const Int_t n = geom.GetNumPixels();
292
293 // Reset arrays
294 fData.Set(n);
295 fData.Reset();
296
297 fValidity.Set(n);
298 fValidity.Reset();
299
300 // check validity of noise
301 const Float_t anoise0 = pcam.GetArea(0).GetRms();
302 if (anoise0<=0)
303 return;
304
305 const Int_t entries = evt.GetNumPixels();
306
307 // Find pixel with max signal
308 Int_t maxidx = 0;
309 if (tcam)
310 {
311 // Find pixel enty with maximum signal
312 for (Int_t i=0; i<entries; i++)
313 {
314 const Double_t s0 = evt[i].GetNumPhotons() * geom.GetPixRatio(i);
315 const Double_t s1 = evt[maxidx].GetNumPhotons() * geom.GetPixRatio(maxidx);
316 if (s0>s1)
317 maxidx = i;
318 }
319
320 // Get software index of pixel
321 maxidx = evt[maxidx].GetPixId();
322 }
323
324 const Double_t timemean = tcam ? (*tcam)[maxidx] : 0;
325 const Double_t timerms = 0.75; //[slices] rms time spread around highest pixel
326
327 // calculate cleaning levels
328 for (Int_t i=0; i<entries; i++)
329 {
330 const MCerPhotPix &spix = evt[i];
331
332 const Int_t idx = spix.GetPixId();
333 const Float_t rms = pcam[idx].GetRms();
334 if (rms<=0) // fData[idx]=0, fValidity[idx]=0
335 continue;
336
337 fValidity[idx]=1;
338
339 // get signal and arrival time
340 const UInt_t aidx = geom[idx].GetAidx();
341 const Float_t ratio = pcam.GetArea(aidx).GetRms()/anoise0;
342
343 const Double_t signal = spix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / rms;
344 const Double_t time = tcam ? (*tcam)[idx] : 1;
345
346 // if signal<0 the probability is equal 0
347 if (signal<0)
348 continue;
349
350 // Just for convinience for easy readybility
351 const Double_t means = 0;
352 const Double_t meant = timemean;
353
354 const Double_t sigmas = rms;
355 const Double_t sigmat = timerms;
356
357 // Get probabilities
358 const Double_t psignal = MMath::GaussProb(signal, sigmas, means);
359 const Double_t pbckgnd = MMath::GaussProb(time, sigmat, meant);
360
361 // Set probability
362 fData[idx] = psignal*(1-pbckgnd);
363 fValidity[idx] = 1;
364
365 // Make sure, that we don't run into trouble because of
366 // a little numerical uncertanty
367 if (fData[idx]>1)
368 fData[idx]=1;
369 if (fData[idx]<0)
370 fData[idx]=0;
371 }
372}
373
374// --------------------------------------------------------------------------
375//
376// Function to calculate the cleaning level for all pixels in a given event.
377// The level is the absolute number of photons times the area-ratio.
378//
379void MCameraData::CalcCleaningAbsolute(const MCerPhotEvt &evt, const MGeomCam &geom)
380{
381 const Int_t n = geom.GetNumPixels();
382
383 // Reset arrays
384 fData.Set(n);
385 fData.Reset();
386
387 fValidity.Set(n);
388 fValidity.Reset();
389
390 const Int_t entries = evt.GetNumPixels();
391
392 // calculate cleaning levels
393 for (Int_t i=0; i<entries; i++)
394 {
395 const MCerPhotPix &spix = evt[i];
396
397 const Int_t idx = spix.GetPixId();
398
399 // Set probability
400 fData[idx] = spix.GetNumPhotons() * geom.GetPixRatio(idx);
401 fValidity[idx] = 1;
402 }
403}
404
405// --------------------------------------------------------------------------
406//
407// Returns the contents of the pixel.
408//
409Bool_t MCameraData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
410{
411 if (idx<0 || idx>=fData.GetSize())
412 return kFALSE;
413
414 val = fData[idx];
415 return fValidity[idx];
416}
417
418void MCameraData::DrawPixelContent(Int_t num) const
419{
420 *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
421}
Note: See TracBrowser for help on using the repository browser.