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 |
|
---|
76 | ClassImp(MBadPixelsCalc);
|
---|
77 |
|
---|
78 | using namespace std;
|
---|
79 |
|
---|
80 | static const TString gsDefName = "MBadPixelsCalc";
|
---|
81 | static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
|
---|
82 |
|
---|
83 | // --------------------------------------------------------------------------
|
---|
84 | //
|
---|
85 | // Default constructor.
|
---|
86 | //
|
---|
87 | MBadPixelsCalc::MBadPixelsCalc(const char *name, const char *title)
|
---|
88 | : fPedestalLevel(3), fNamePedPhotCam("MPedPhotCam")
|
---|
89 | {
|
---|
90 | fName = name ? name : gsDefName.Data();
|
---|
91 | fTitle = title ? title : gsDefTitle.Data();
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | //
|
---|
97 | Int_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 used: " << fNamePedPhotCam << endl;
|
---|
121 |
|
---|
122 | return kTRUE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | // --------------------------------------------------------------------------
|
---|
126 | //
|
---|
127 | // Check the pedestal RMS of every pixel with respect to the mean pedestal RMS
|
---|
128 | // of the camera (Sigmabar).
|
---|
129 | //
|
---|
130 | // The pixels can be set as blind if the pedestalRMS is too big or 0.
|
---|
131 | //
|
---|
132 | // If you don't want to use this option set the PedestalLevel<=0;
|
---|
133 | //
|
---|
134 | // MBadPixelsCalc calc;
|
---|
135 | // calc.SetPedestalLevel(-1);
|
---|
136 | /*
|
---|
137 | void MBadPixelsCalc::CheckPedestalRMS() const
|
---|
138 | {
|
---|
139 | const Int_t entries = fPedPhotCam->GetSize();
|
---|
140 |
|
---|
141 | const Float_t meanPedRMS = fSigmabar->GetSigmabar();
|
---|
142 |
|
---|
143 | for (Int_t i=0; i<entries; i++)
|
---|
144 | {
|
---|
145 | //
|
---|
146 | // get pixel as entry from list
|
---|
147 | //
|
---|
148 | const Double_t nratio = fGeomCam->GetPixRatio(i);
|
---|
149 | const Double_t pixPedRms = (*fPedPhotCam)[i].GetRms();
|
---|
150 |
|
---|
151 | if (pixPedRms*nratio > fPedestalLevel * meanPedRMS || pixPedRms == 0)
|
---|
152 | (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | */
|
---|
156 |
|
---|
157 | // --------------------------------------------------------------------------
|
---|
158 | //
|
---|
159 | // Check the pedestal Rms of the pixels: compute with 2 iterations the mean
|
---|
160 | // for inner and outer pixels. Set as blind the pixels with too small or
|
---|
161 | // too high pedestal Rms with respect to the mean.
|
---|
162 | //
|
---|
163 | Bool_t MBadPixelsCalc::CheckPedestalRms() const
|
---|
164 | {
|
---|
165 | const Int_t entries = fPedPhotCam->GetSize();
|
---|
166 |
|
---|
167 | const Int_t na = fGeomCam->GetNumAreas();
|
---|
168 |
|
---|
169 | TArrayD meanrms(na);
|
---|
170 | TArrayI npix(na);
|
---|
171 |
|
---|
172 | for (Int_t i=0; i<entries; i++)
|
---|
173 | {
|
---|
174 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
175 |
|
---|
176 | if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
|
---|
177 | continue;
|
---|
178 |
|
---|
179 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
180 |
|
---|
181 | meanrms[aidx] += rms;
|
---|
182 | npix[aidx]++;
|
---|
183 | }
|
---|
184 |
|
---|
185 | //if no pixel has a minimum signal, return
|
---|
186 | for (int i=0; i<na; i++)
|
---|
187 | {
|
---|
188 | if (npix[i]==0 || meanrms[i]==0)
|
---|
189 | {
|
---|
190 | //fErrors[1]++; //no valid Pedestals Rms
|
---|
191 | return kFALSE;
|
---|
192 | }
|
---|
193 |
|
---|
194 | meanrms[i] /= npix[i];
|
---|
195 | npix[i]=0;
|
---|
196 | }
|
---|
197 |
|
---|
198 | TArrayD meanrms2(na);
|
---|
199 | for (Int_t i=0; i<entries; i++)
|
---|
200 | {
|
---|
201 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
202 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
203 |
|
---|
204 | //Calculate the corrected means:
|
---|
205 |
|
---|
206 | if (rms<=0.5*meanrms[aidx] || rms>=1.5*meanrms[aidx])
|
---|
207 | continue;
|
---|
208 |
|
---|
209 | meanrms2[aidx] += rms;
|
---|
210 | npix[aidx]++;
|
---|
211 | }
|
---|
212 |
|
---|
213 | //if no pixel has a minimum signal, return
|
---|
214 | for (int i=0; i<na; i++)
|
---|
215 | {
|
---|
216 | if (npix[i]==0 || meanrms2[i]==0)
|
---|
217 | {
|
---|
218 | //fErrors[1]++; //no valid Pedestals Rms
|
---|
219 | return kFALSE;
|
---|
220 | }
|
---|
221 |
|
---|
222 | meanrms2[i] /= npix[i];
|
---|
223 | }
|
---|
224 |
|
---|
225 | Int_t bads = 0;
|
---|
226 |
|
---|
227 | //Blind the Bad Pixels
|
---|
228 | for (Int_t i=0; i<entries; i++)
|
---|
229 | {
|
---|
230 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
231 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
232 |
|
---|
233 | if (rms>meanrms2[aidx]/fPedestalLevel && rms<=meanrms2[aidx]*fPedestalLevel)
|
---|
234 | continue;
|
---|
235 |
|
---|
236 | (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
|
---|
237 | bads++;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // Check if the number of pixels to blind is > 60% of total number of pixels
|
---|
241 | //
|
---|
242 | // if (bads>0.6*entries)
|
---|
243 | // {
|
---|
244 | // fErrors[2]++;
|
---|
245 | // return kFALSE;
|
---|
246 | // }
|
---|
247 |
|
---|
248 | return kTRUE;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | // --------------------------------------------------------------------------
|
---|
253 | //
|
---|
254 | //
|
---|
255 | Int_t MBadPixelsCalc::Process()
|
---|
256 | {
|
---|
257 | if (fPedestalLevel>0)
|
---|
258 | {
|
---|
259 | CheckPedestalRms();
|
---|
260 | fPedPhotCam->ReCalc(*fGeomCam, fBadPixels);
|
---|
261 | }
|
---|
262 |
|
---|
263 | return kTRUE;
|
---|
264 | }
|
---|
265 |
|
---|
266 | // --------------------------------------------------------------------------
|
---|
267 | //
|
---|
268 | // Read the setup from a TEnv, eg:
|
---|
269 | // MBadPixelsCalc.PedestalLevel: 3.0
|
---|
270 | //
|
---|
271 | Int_t MBadPixelsCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
272 | {
|
---|
273 | Bool_t rc = kFALSE;
|
---|
274 | if (IsEnvDefined(env, prefix, "PedestalLevel", print))
|
---|
275 | {
|
---|
276 | rc = kTRUE;
|
---|
277 | SetPedestalLevel(GetEnvValue(env, prefix, "PedestalLevel", fPedestalLevel));
|
---|
278 | }
|
---|
279 | return rc;
|
---|
280 | }
|
---|