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

Last change on this file since 7095 was 7094, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.3 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 fCheckInProcess(kTRUE), fCheckInPostProcess(kFALSE)
90{
91 fName = name ? name : gsDefName.Data();
92 fTitle = title ? title : gsDefTitle.Data();
93}
94
95// --------------------------------------------------------------------------
96//
97//
98Int_t MBadPixelsCalc::PreProcess (MParList *pList)
99{
100 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
101 if (!fBadPixels)
102 return kFALSE;
103
104 if (fPedestalLevel>0)
105 {
106 fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
107 if (!fPedPhotCam)
108 {
109 *fLog << err << fNamePedPhotCam << "[MPedPhotCam] not found... aborting." << endl;
110 return kFALSE;
111 }
112
113 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
114 if (!fGeomCam)
115 {
116 *fLog << err << "MGeomCam not found... aborting." << endl;
117 return kFALSE;
118 }
119 }
120
121 *fLog << inf << "Name of MPedPhotCam to get pedestal rms from: " << fNamePedPhotCam << endl;
122 if (fPedestalLevel)
123 *fLog << "Checking mean 'pedestal rms' against absolute value with level " << fPedestalLevel << endl;
124 if (fPedestalLevelVariance)
125 *fLog << "Checking mean 'pedestal rms' against its variance with level " << fPedestalLevelVariance << endl;
126
127 return kTRUE;
128}
129
130// --------------------------------------------------------------------------
131//
132// Check the pedestal Rms of the pixels: compute with 2 iterations the mean
133// for inner and outer pixels. Set as blind the pixels with too small or
134// too high pedestal Rms with respect to the mean.
135//
136Bool_t MBadPixelsCalc::CheckPedestalRms(MBadPixelsPix::UnsuitableType_t type) const
137{
138 if (fPedestalLevel<=0 && fPedestalLevelVariance<=0)
139 return kTRUE;
140
141 const Int_t entries = fPedPhotCam->GetSize();
142
143 const Int_t na = fGeomCam->GetNumAreas();
144
145 MArrayD meanrms(na);
146 MArrayI npix(na);
147
148 for (Int_t i=0; i<entries; i++)
149 {
150 if ((*fBadPixels)[i].IsUnsuitable())
151 continue;
152
153 const Double_t rms = (*fPedPhotCam)[i].GetRms();
154
155 if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
156 continue;
157
158 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
159
160 meanrms[aidx] += rms;
161 npix[aidx]++;
162 }
163
164 //if no pixel has a minimum signal, return
165 for (int i=0; i<na; i++)
166 {
167 if (npix[i]==0 || meanrms[i]==0)
168 {
169 //fErrors[1]++; //no valid Pedestals Rms
170 return kFALSE;
171 }
172
173 meanrms[i] /= npix[i];
174 npix[i]=0;
175 }
176
177 MArrayD meanrms2(na);
178 MArrayD varrms2(na);
179 for (Int_t i=0; i<entries; i++)
180 {
181 if ((*fBadPixels)[i].IsUnsuitable())
182 continue;
183
184 const Double_t rms = (*fPedPhotCam)[i].GetRms();
185 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
186
187 //Calculate the corrected means:
188 if (rms<=meanrms[aidx]/1.5 || rms>=meanrms[aidx]*1.5)
189 continue;
190
191 meanrms2[aidx] += rms;
192 varrms2 [aidx] += rms*rms;
193 npix[aidx]++;
194 }
195
196 //if no pixel has a minimum signal, return
197 MArrayD lolim1(na), lolim2(na); // Precalcualtion of limits
198 MArrayD uplim1(na), uplim2(na); // for speeed reasons
199 for (int i=0; i<na; i++)
200 {
201 if (npix[i]==0 || meanrms2[i]==0)
202 {
203 //fErrors[1]++; //no valid Pedestals Rms
204 return kFALSE;
205 }
206
207 meanrms2[i] /= npix[i];
208
209 if (fPedestalLevel>0)
210 {
211 lolim1[i] = meanrms2[i]/fPedestalLevel;
212 uplim1[i] = meanrms2[i]*fPedestalLevel;
213 }
214
215 if (fPedestalLevelVariance>0)
216 {
217 varrms2[i] /= npix[i];
218 varrms2[i] = TMath::Sqrt(varrms2[i]-meanrms2[i]*meanrms2[i]);
219
220 lolim2[i] = meanrms2[i]-fPedestalLevelVariance*varrms2[i];
221 uplim2[i] = meanrms2[i]+fPedestalLevelVariance*varrms2[i];
222 }
223 }
224
225 Int_t bads = 0;
226
227 //Blind the Bad Pixels
228 for (Int_t i=0; i<entries; i++)
229 {
230 if ((*fBadPixels)[i].IsUnsuitable())
231 continue;
232
233 const Double_t rms = (*fPedPhotCam)[i].GetRms();
234 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
235
236 if ((fPedestalLevel<=0 || (rms>lolim1[aidx] && rms<=uplim1[aidx])) &&
237 (fPedestalLevelVariance<=0 || (rms>lolim2[aidx] && rms<=uplim2[aidx])))
238 continue;
239
240 (*fBadPixels)[i].SetUnsuitable(type);
241 if (type==MBadPixelsPix::kUnsuitableRun)
242 (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kDeadPedestalRms);
243
244 bads++;
245 }
246
247 // Check if the number of pixels to blind is > 60% of total number of pixels
248 //
249 // if (bads>0.6*entries)
250 // {
251 // fErrors[2]++;
252 // return kFALSE;
253 // }
254
255 return kTRUE;
256}
257
258// --------------------------------------------------------------------------
259//
260//
261Int_t MBadPixelsCalc::Process()
262{
263 return fCheckInProcess ? CheckPedestalRms(MBadPixelsPix::kUnsuitableEvt) : kTRUE;
264}
265
266// --------------------------------------------------------------------------
267//
268//
269Int_t MBadPixelsCalc::PostProcess()
270{
271 return fCheckInPostProcess ? CheckPedestalRms(MBadPixelsPix::kUnsuitableRun) : kTRUE;
272}
273
274// --------------------------------------------------------------------------
275//
276// Read the setup from a TEnv, eg:
277// MBadPixelsCalc.PedestalLevel: 3.0
278// MBadPixelsCalc.PedestalLevelVariance: 3.0
279//
280Int_t MBadPixelsCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
281{
282 Bool_t rc = kFALSE;
283 if (IsEnvDefined(env, prefix, "PedestalLevel", print))
284 {
285 rc = kTRUE;
286 SetPedestalLevel(GetEnvValue(env, prefix, "PedestalLevel", fPedestalLevel));
287 }
288
289 if (IsEnvDefined(env, prefix, "PedestalLevelVariance", print))
290 {
291 rc = kTRUE;
292 SetPedestalLevelVariance(GetEnvValue(env, prefix, "PedestalLevelVariance", fPedestalLevelVariance));
293 }
294 return rc;
295}
Note: See TracBrowser for help on using the repository browser.