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 <TArrayD.h>
|
---|
58 |
|
---|
59 | #include "MLog.h"
|
---|
60 | #include "MLogManip.h"
|
---|
61 |
|
---|
62 | #include "MParList.h"
|
---|
63 |
|
---|
64 | #include "MGeomCam.h"
|
---|
65 | #include "MGeomPix.h"
|
---|
66 |
|
---|
67 | //#include "MSigmabar.h"
|
---|
68 |
|
---|
69 | #include "MPedPhotCam.h"
|
---|
70 | #include "MPedPhotPix.h"
|
---|
71 |
|
---|
72 | #include "MBadPixelsCam.h"
|
---|
73 | #include "MBadPixelsPix.h"
|
---|
74 |
|
---|
75 | ClassImp(MBadPixelsCalc);
|
---|
76 |
|
---|
77 | using namespace std;
|
---|
78 |
|
---|
79 | static const TString gsDefName = "MBadPixelsCalc";
|
---|
80 | static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
|
---|
81 |
|
---|
82 | // --------------------------------------------------------------------------
|
---|
83 | //
|
---|
84 | // Default constructor.
|
---|
85 | //
|
---|
86 | MBadPixelsCalc::MBadPixelsCalc(const char *name, const char *title)
|
---|
87 | : fPedestalLevel(3)
|
---|
88 | {
|
---|
89 | fName = name ? name : gsDefName.Data();
|
---|
90 | fTitle = title ? title : gsDefTitle.Data();
|
---|
91 | }
|
---|
92 |
|
---|
93 | // --------------------------------------------------------------------------
|
---|
94 | //
|
---|
95 | //
|
---|
96 | Int_t MBadPixelsCalc::PreProcess (MParList *pList)
|
---|
97 | {
|
---|
98 | fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
|
---|
99 | if (!fBadPixels)
|
---|
100 | return kFALSE;
|
---|
101 |
|
---|
102 | if (fPedestalLevel>0)
|
---|
103 | {
|
---|
104 | fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber("MPedPhotCam"));
|
---|
105 | if (!fPedPhotCam)
|
---|
106 | {
|
---|
107 | *fLog << err << "MPedPhotCam not found... aborting." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
112 | if (!fGeomCam)
|
---|
113 | {
|
---|
114 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
115 | return kFALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /* fSigmabar = (MSigmabar*)pList->FindObject(AddSerialNumber("MSigmabar"));
|
---|
119 | if (!fSigmabar)
|
---|
120 | {
|
---|
121 | *fLog << err << "MSigmabar not found... aborting." << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 | */
|
---|
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 | /*
|
---|
141 | void 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 | // Check the pedestal Rms of the pixels: compute with 2 iterations the mean
|
---|
162 | // for inner and outer pixels. Set as blind the pixels with too small or
|
---|
163 | // too high pedestal Rms with respect to the mean.
|
---|
164 | //
|
---|
165 | Bool_t MBadPixelsCalc::CheckPedestalRms() const
|
---|
166 | {
|
---|
167 | const Int_t entries = fPedPhotCam->GetSize();
|
---|
168 |
|
---|
169 | const Int_t na = fGeomCam->GetNumAreas();
|
---|
170 |
|
---|
171 | TArrayD meanrms(na);
|
---|
172 | TArrayI npix(na);
|
---|
173 |
|
---|
174 | for (Int_t i=0; i<entries; i++)
|
---|
175 | {
|
---|
176 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
177 |
|
---|
178 | if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
|
---|
179 | continue;
|
---|
180 |
|
---|
181 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
182 |
|
---|
183 | meanrms[aidx] += rms;
|
---|
184 | npix[aidx]++;
|
---|
185 | }
|
---|
186 |
|
---|
187 | //if no pixel has a minimum signal, return
|
---|
188 | for (int i=0; i<na; i++)
|
---|
189 | {
|
---|
190 | if (npix[i]==0 || meanrms[i]==0)
|
---|
191 | {
|
---|
192 | //fErrors[1]++; //no valid Pedestals Rms
|
---|
193 | return kFALSE;
|
---|
194 | }
|
---|
195 |
|
---|
196 | meanrms[i] /= npix[i];
|
---|
197 | npix[i]=0;
|
---|
198 | }
|
---|
199 |
|
---|
200 | TArrayD meanrms2(na);
|
---|
201 | for (Int_t i=0; i<entries; i++)
|
---|
202 | {
|
---|
203 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
204 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
205 |
|
---|
206 | //Calculate the corrected means:
|
---|
207 |
|
---|
208 | if (rms<=0.5*meanrms[aidx] || rms>=1.5*meanrms[aidx])
|
---|
209 | continue;
|
---|
210 |
|
---|
211 | meanrms2[aidx] += rms;
|
---|
212 | npix[aidx]++;
|
---|
213 | }
|
---|
214 |
|
---|
215 | //if no pixel has a minimum signal, return
|
---|
216 | for (int i=0; i<na; i++)
|
---|
217 | {
|
---|
218 | if (npix[i]==0 || meanrms2[i]==0)
|
---|
219 | {
|
---|
220 | //fErrors[1]++; //no valid Pedestals Rms
|
---|
221 | return kFALSE;
|
---|
222 | }
|
---|
223 |
|
---|
224 | meanrms2[i] /= npix[i];
|
---|
225 | }
|
---|
226 |
|
---|
227 | Int_t bads = 0;
|
---|
228 |
|
---|
229 | //Blind the Bad Pixels
|
---|
230 | for (Int_t i=0; i<entries; i++)
|
---|
231 | {
|
---|
232 | const Double_t rms = (*fPedPhotCam)[i].GetRms();
|
---|
233 | const Byte_t aidx = (*fGeomCam)[i].GetAidx();
|
---|
234 |
|
---|
235 | if (rms>meanrms2[aidx]/fPedestalLevel && rms<=meanrms2[aidx]*fPedestalLevel)
|
---|
236 | continue;
|
---|
237 |
|
---|
238 | (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
|
---|
239 | bads++;
|
---|
240 | }
|
---|
241 |
|
---|
242 | // Check if the number of pixels to blind is > 60% of total number of pixels
|
---|
243 | //
|
---|
244 | // if (bads>0.6*entries)
|
---|
245 | // {
|
---|
246 | // fErrors[2]++;
|
---|
247 | // return kFALSE;
|
---|
248 | // }
|
---|
249 |
|
---|
250 | return kTRUE;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | // --------------------------------------------------------------------------
|
---|
255 | //
|
---|
256 | //
|
---|
257 | Int_t MBadPixelsCalc::Process()
|
---|
258 | {
|
---|
259 | if (fPedestalLevel>0)
|
---|
260 | CheckPedestalRms();
|
---|
261 |
|
---|
262 | return kTRUE;
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|