source: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc@ 7072

Last change on this file since 7072 was 7035, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.7 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, 02/2004 <mailto:tbretz@astro.uni.wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MBadPixelsCalc
28//
29//
30// The job of the task is to determin bad pixels event-wise. This must be
31// redone for each event. This particular task is for what is explained
32// below.
33// New algorithms may enter new tasks.
34//
35//
36// Check the pedestal RMS of every pixel with respect to the mean
37// pedestal RMS of the camera.
38//
39// The pixels can be set as blind if the pedestalRMS is too big or 0.
40//
41// If you don't want to use this option set the PedestalLevel<=0;
42//
43// MBadPixelsCalc calc;
44// calc.SetPedestalLevel(-1);
45//
46//
47// Input Containers:
48// [MPedPhotCam]
49// [MGeomCam]
50//
51// Output Containers:
52// MBadPixels
53//
54/////////////////////////////////////////////////////////////////////////////
55#include "MBadPixelsCalc.h"
56
57#include <TEnv.h>
58
59#include "MArrayI.h"
60#include "MArrayD.h"
61
62#include "MLog.h"
63#include "MLogManip.h"
64
65#include "MParList.h"
66
67#include "MGeomCam.h"
68#include "MGeomPix.h"
69
70#include "MPedPhotCam.h"
71#include "MPedPhotPix.h"
72
73#include "MBadPixelsCam.h"
74#include "MBadPixelsPix.h"
75
76ClassImp(MBadPixelsCalc);
77
78using namespace std;
79
80static const TString gsDefName = "MBadPixelsCalc";
81static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
82
83// --------------------------------------------------------------------------
84//
85// Default constructor.
86//
87MBadPixelsCalc::MBadPixelsCalc(const char *name, const char *title)
88 : fPedestalLevel(3), fPedestalLevelVariance(5), fNamePedPhotCam("MPedPhotCam")
89{
90 fName = name ? name : gsDefName.Data();
91 fTitle = title ? title : gsDefTitle.Data();
92}
93
94// --------------------------------------------------------------------------
95//
96//
97Int_t MBadPixelsCalc::PreProcess (MParList *pList)
98{
99 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
100 if (!fBadPixels)
101 return kFALSE;
102
103 if (fPedestalLevel>0)
104 {
105 fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
106 if (!fPedPhotCam)
107 {
108 *fLog << err << fNamePedPhotCam << "[MPedPhotCam] not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
113 if (!fGeomCam)
114 {
115 *fLog << err << "MGeomCam not found... aborting." << endl;
116 return kFALSE;
117 }
118 }
119
120 *fLog << inf << "Name of MPedPhotCam to get pedestal rms from: " << fNamePedPhotCam << endl;
121 if (fPedestalLevel)
122 *fLog << "Checking mean 'pedestal rms' against absolute value with level " << fPedestalLevel << endl;
123 if (fPedestalLevelVariance)
124 *fLog << "Checking mean 'pedestal rms' against its variance with level " << fPedestalLevelVariance << endl;
125
126 return kTRUE;
127}
128
129// --------------------------------------------------------------------------
130//
131// Check the pedestal RMS of every pixel with respect to the mean pedestal RMS
132// of the camera (Sigmabar).
133//
134// The pixels can be set as blind if the pedestalRMS is too big or 0.
135//
136// If you don't want to use this option set the PedestalLevel<=0;
137//
138// MBadPixelsCalc calc;
139// calc.SetPedestalLevel(-1);
140/*
141void MBadPixelsCalc::CheckPedestalRMS() const
142{
143 const Int_t entries = fPedPhotCam->GetSize();
144
145 const Float_t meanPedRMS = fSigmabar->GetSigmabar();
146
147 for (Int_t i=0; i<entries; i++)
148 {
149 //
150 // get pixel as entry from list
151 //
152 const Double_t nratio = fGeomCam->GetPixRatio(i);
153 const Double_t pixPedRms = (*fPedPhotCam)[i].GetRms();
154
155 if (pixPedRms*nratio > fPedestalLevel * meanPedRMS || pixPedRms == 0)
156 (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
157 }
158}
159*/
160
161// --------------------------------------------------------------------------
162//
163// Check the pedestal Rms of the pixels: compute with 2 iterations the mean
164// for inner and outer pixels. Set as blind the pixels with too small or
165// too high pedestal Rms with respect to the mean.
166//
167Bool_t MBadPixelsCalc::CheckPedestalRms() const
168{
169 const Int_t entries = fPedPhotCam->GetSize();
170
171 const Int_t na = fGeomCam->GetNumAreas();
172
173 MArrayD meanrms(na);
174 MArrayI npix(na);
175
176 for (Int_t i=0; i<entries; i++)
177 {
178 if ((*fBadPixels)[i].IsUnsuitable())
179 continue;
180
181 const Double_t rms = (*fPedPhotCam)[i].GetRms();
182
183 if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
184 continue;
185
186 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
187
188 meanrms[aidx] += rms;
189 npix[aidx]++;
190 }
191
192 //if no pixel has a minimum signal, return
193 for (int i=0; i<na; i++)
194 {
195 if (npix[i]==0 || meanrms[i]==0)
196 {
197 //fErrors[1]++; //no valid Pedestals Rms
198 return kFALSE;
199 }
200
201 meanrms[i] /= npix[i];
202 npix[i]=0;
203 }
204
205 MArrayD meanrms2(na);
206 MArrayD varrms2(na);
207 for (Int_t i=0; i<entries; i++)
208 {
209 if ((*fBadPixels)[i].IsUnsuitable())
210 continue;
211
212 const Double_t rms = (*fPedPhotCam)[i].GetRms();
213 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
214
215 //Calculate the corrected means:
216 if (rms<=meanrms[aidx]/1.5 || rms>=meanrms[aidx]*1.5)
217 continue;
218
219 meanrms2[aidx] += rms;
220 varrms2 [aidx] += rms*rms;
221 npix[aidx]++;
222 }
223
224 //if no pixel has a minimum signal, return
225 MArrayD lolim1(na), lolim2(na); // Precalcualtion of limits
226 MArrayD uplim1(na), uplim2(na); // for speeed reasons
227 for (int i=0; i<na; i++)
228 {
229 if (npix[i]==0 || meanrms2[i]==0)
230 {
231 //fErrors[1]++; //no valid Pedestals Rms
232 return kFALSE;
233 }
234
235 meanrms2[i] /= npix[i];
236
237 if (fPedestalLevel>0)
238 {
239 lolim1[i] = meanrms2[i]/fPedestalLevel;
240 uplim1[i] = meanrms2[i]*fPedestalLevel;
241 }
242
243 if (fPedestalLevelVariance>0)
244 {
245 varrms2[i] /= npix[i];
246 varrms2[i] = TMath::Sqrt(varrms2[i]-meanrms2[i]*meanrms2[i]);
247
248 lolim2[i] = meanrms2[i]-fPedestalLevelVariance*varrms2[i];
249 uplim2[i] = meanrms2[i]+fPedestalLevelVariance*varrms2[i];
250 }
251 }
252
253 Int_t bads = 0;
254
255 //Blind the Bad Pixels
256 for (Int_t i=0; i<entries; i++)
257 {
258 if ((*fBadPixels)[i].IsUnsuitable())
259 continue;
260
261 const Double_t rms = (*fPedPhotCam)[i].GetRms();
262 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
263
264 if ((fPedestalLevel<=0 || (rms>lolim1[aidx] && rms<=uplim1[aidx])) &&
265 (fPedestalLevelVariance<=0 || (rms>lolim2[aidx] && rms<=uplim2[aidx])))
266 continue;
267
268 (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
269 bads++;
270 }
271
272 // Check if the number of pixels to blind is > 60% of total number of pixels
273 //
274 // if (bads>0.6*entries)
275 // {
276 // fErrors[2]++;
277 // return kFALSE;
278 // }
279
280 return kTRUE;
281}
282
283
284// --------------------------------------------------------------------------
285//
286//
287Int_t MBadPixelsCalc::Process()
288{
289 if (fPedestalLevel>0 || fPedestalLevelVariance>0)
290 CheckPedestalRms();
291
292 return kTRUE;
293}
294
295// --------------------------------------------------------------------------
296//
297// Read the setup from a TEnv, eg:
298// MBadPixelsCalc.PedestalLevel: 3.0
299// MBadPixelsCalc.PedestalLevelVariance: 3.0
300//
301Int_t MBadPixelsCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
302{
303 Bool_t rc = kFALSE;
304 if (IsEnvDefined(env, prefix, "PedestalLevel", print))
305 {
306 rc = kTRUE;
307 SetPedestalLevel(GetEnvValue(env, prefix, "PedestalLevel", fPedestalLevel));
308 }
309
310 if (IsEnvDefined(env, prefix, "PedestalLevelVariance", print))
311 {
312 rc = kTRUE;
313 SetPedestalLevelVariance(GetEnvValue(env, prefix, "PedestalLevelVariance", fPedestalLevelVariance));
314 }
315 return rc;
316}
Note: See TracBrowser for help on using the repository browser.