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

Last change on this file since 5563 was 5431, checked in by wittek, 20 years ago
*** empty log message ***
File size: 7.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#include <TArrayD.h>
59
60#include "MLog.h"
61#include "MLogManip.h"
62
63#include "MParList.h"
64
65#include "MGeomCam.h"
66#include "MGeomPix.h"
67
68//#include "MSigmabar.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), fNamePedPhotContainer("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(fNamePedPhotContainer), "MPedPhotCam");
106 if (!fPedPhotCam)
107 {
108 *fLog << err << fNamePedPhotContainer << "[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 container : " << fNamePedPhotContainer
121 << endl;
122
123 return kTRUE;
124}
125
126// --------------------------------------------------------------------------
127//
128// Check the pedestal RMS of every pixel with respect to the mean pedestal RMS
129// of the camera (Sigmabar).
130//
131// The pixels can be set as blind if the pedestalRMS is too big or 0.
132//
133// If you don't want to use this option set the PedestalLevel<=0;
134//
135// MBadPixelsCalc calc;
136// calc.SetPedestalLevel(-1);
137/*
138void MBadPixelsCalc::CheckPedestalRMS() const
139{
140 const Int_t entries = fPedPhotCam->GetSize();
141
142 const Float_t meanPedRMS = fSigmabar->GetSigmabar();
143
144 for (Int_t i=0; i<entries; i++)
145 {
146 //
147 // get pixel as entry from list
148 //
149 const Double_t nratio = fGeomCam->GetPixRatio(i);
150 const Double_t pixPedRms = (*fPedPhotCam)[i].GetRms();
151
152 if (pixPedRms*nratio > fPedestalLevel * meanPedRMS || pixPedRms == 0)
153 (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
154 }
155}
156*/
157
158// --------------------------------------------------------------------------
159//
160// Check the pedestal Rms of the pixels: compute with 2 iterations the mean
161// for inner and outer pixels. Set as blind the pixels with too small or
162// too high pedestal Rms with respect to the mean.
163//
164Bool_t MBadPixelsCalc::CheckPedestalRms() const
165{
166 const Int_t entries = fPedPhotCam->GetSize();
167
168 const Int_t na = fGeomCam->GetNumAreas();
169
170 TArrayD meanrms(na);
171 TArrayI npix(na);
172
173 for (Int_t i=0; i<entries; i++)
174 {
175 const Double_t rms = (*fPedPhotCam)[i].GetRms();
176
177 if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
178 continue;
179
180 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
181
182 meanrms[aidx] += rms;
183 npix[aidx]++;
184 }
185
186 //if no pixel has a minimum signal, return
187 for (int i=0; i<na; i++)
188 {
189 if (npix[i]==0 || meanrms[i]==0)
190 {
191 //fErrors[1]++; //no valid Pedestals Rms
192 return kFALSE;
193 }
194
195 meanrms[i] /= npix[i];
196 npix[i]=0;
197 }
198
199 TArrayD meanrms2(na);
200 for (Int_t i=0; i<entries; i++)
201 {
202 const Double_t rms = (*fPedPhotCam)[i].GetRms();
203 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
204
205 //Calculate the corrected means:
206
207 if (rms<=0.5*meanrms[aidx] || rms>=1.5*meanrms[aidx])
208 continue;
209
210 meanrms2[aidx] += rms;
211 npix[aidx]++;
212 }
213
214 //if no pixel has a minimum signal, return
215 for (int i=0; i<na; i++)
216 {
217 if (npix[i]==0 || meanrms2[i]==0)
218 {
219 //fErrors[1]++; //no valid Pedestals Rms
220 return kFALSE;
221 }
222
223 meanrms2[i] /= npix[i];
224 }
225
226 Int_t bads = 0;
227
228 //Blind the Bad Pixels
229 for (Int_t i=0; i<entries; i++)
230 {
231 const Double_t rms = (*fPedPhotCam)[i].GetRms();
232 const Byte_t aidx = (*fGeomCam)[i].GetAidx();
233
234 if (rms>meanrms2[aidx]/fPedestalLevel && rms<=meanrms2[aidx]*fPedestalLevel)
235 continue;
236
237 (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
238 bads++;
239 }
240
241 // Check if the number of pixels to blind is > 60% of total number of pixels
242 //
243 // if (bads>0.6*entries)
244 // {
245 // fErrors[2]++;
246 // return kFALSE;
247 // }
248
249 return kTRUE;
250}
251
252
253// --------------------------------------------------------------------------
254//
255//
256Int_t MBadPixelsCalc::Process()
257{
258 if (fPedestalLevel>0)
259 {
260 CheckPedestalRms();
261 fPedPhotCam->ReCalc(*fGeomCam, fBadPixels);
262 }
263
264 return kTRUE;
265}
266
267// --------------------------------------------------------------------------
268//
269// Read the setup from a TEnv, eg:
270// MBadPixelsCalc.PedestalLevel: 3.0
271//
272Int_t MBadPixelsCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
273{
274 Bool_t rc = kFALSE;
275 if (IsEnvDefined(env, prefix, "PedestalLevel", print))
276 {
277 rc = kTRUE;
278 SetPedestalLevel(GetEnvValue(env, prefix, "PedestalLevel", fPedestalLevel));
279 }
280 return rc;
281}
Note: See TracBrowser for help on using the repository browser.