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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
|
---|
19 | ! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // MImgCleanStd //
|
---|
29 | // //
|
---|
30 | // This is the standard image cleaning. If you want to know how it works //
|
---|
31 | // Please look at the three CleanSteps and Process //
|
---|
32 | // //
|
---|
33 | // FIXME: MImgCleanStd is not yet completely optimized for speed. //
|
---|
34 | // Maybe we don't have to loop over all pixels all the time... //
|
---|
35 | // //
|
---|
36 | // Input Containers: //
|
---|
37 | // MGeomCam, MCerPhotEvt //
|
---|
38 | // //
|
---|
39 | // Output Containers: //
|
---|
40 | // -/- //
|
---|
41 | // //
|
---|
42 | /////////////////////////////////////////////////////////////////////////////
|
---|
43 | #include "MImgCleanStd.h"
|
---|
44 |
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 |
|
---|
48 | #include "MParList.h"
|
---|
49 | #include "MGeomPix.h"
|
---|
50 | #include "MGeomCam.h"
|
---|
51 | #include "MCerPhotPix.h"
|
---|
52 | #include "MCerPhotEvt.h"
|
---|
53 |
|
---|
54 | ClassImp(MImgCleanStd);
|
---|
55 |
|
---|
56 | // --------------------------------------------------------------------------
|
---|
57 | //
|
---|
58 | // Default constructor. Here you can specify the cleaning levels. If you
|
---|
59 | // don't specify them the 'common standard' values 2.5 and 3.0 (sigma
|
---|
60 | // above mean) are used
|
---|
61 | //
|
---|
62 | MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
|
---|
63 | const char *name, const char *title)
|
---|
64 | : fCleanLvl1(lvl1), fCleanLvl2(lvl2)
|
---|
65 | {
|
---|
66 | fName = name ? name : "MImgCleanStd";
|
---|
67 | fTitle = title ? title : "Task which does a standard image cleaning";
|
---|
68 |
|
---|
69 | *fLog << "Cleaning initialized. Using noise level " << lvl1 << " and " << lvl2 << endl;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // This method looks for all pixels with an entry (photons)
|
---|
75 | // that is three times bigger than the noise of the pixel
|
---|
76 | // (std: 3 sigma, clean level 1)
|
---|
77 | //
|
---|
78 | void MImgCleanStd::CleanStep1()
|
---|
79 | {
|
---|
80 | const Int_t entries = fEvt->GetNumPixels();
|
---|
81 |
|
---|
82 | //
|
---|
83 | // check the number of all pixels against the noise level and
|
---|
84 | // set them to 'unused' state if necessary
|
---|
85 | //
|
---|
86 | for (Int_t i=0; i<entries; i++ )
|
---|
87 | {
|
---|
88 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
89 |
|
---|
90 | const Float_t entry = pix.GetNumPhotons();
|
---|
91 | const Float_t noise = pix.GetErrorPhot();
|
---|
92 |
|
---|
93 | // COBB: '<=' to skip entry=noise=0
|
---|
94 | if (entry <= fCleanLvl1 * noise)
|
---|
95 | pix.SetPixelUnused();
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // check if the survived pixel have a neighbor, that also
|
---|
102 | // survived
|
---|
103 | //
|
---|
104 | void MImgCleanStd::CleanStep2()
|
---|
105 | {
|
---|
106 | const Int_t entries = fEvt->GetNumPixels();
|
---|
107 |
|
---|
108 | //
|
---|
109 | // In the worst case we have to loop 6 times 577 times, to
|
---|
110 | // catch the behaviour of all next neighbors. Here we can gain
|
---|
111 | // much by using an array instead of checking through all pixels
|
---|
112 | // (MCerPhotEvt::IsPixelUsed) all the time.
|
---|
113 | //
|
---|
114 | Byte_t ispixused[577];
|
---|
115 |
|
---|
116 | for (Int_t i=0; i<entries; i++)
|
---|
117 | {
|
---|
118 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
119 | ispixused[pix.GetPixId()] = pix.IsPixelUsed();
|
---|
120 | }
|
---|
121 |
|
---|
122 | for (Int_t i=0; i<entries; i++)
|
---|
123 | {
|
---|
124 | //
|
---|
125 | // get entry i from list
|
---|
126 | //
|
---|
127 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
128 |
|
---|
129 | //
|
---|
130 | // check if pixel is in use, if not goto next pixel in list
|
---|
131 | //
|
---|
132 | if (!pix.IsPixelUsed())
|
---|
133 | continue;
|
---|
134 |
|
---|
135 | //
|
---|
136 | // get pixel id of this entry
|
---|
137 | //
|
---|
138 | const Int_t id = pix.GetPixId();
|
---|
139 |
|
---|
140 | //
|
---|
141 | // count number of next neighbors of this pixel which
|
---|
142 | // state is 'used'
|
---|
143 | //
|
---|
144 | const MGeomPix &gpix = (*fCam)[id];
|
---|
145 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
146 |
|
---|
147 | Bool_t cnt = kFALSE;
|
---|
148 | for (Int_t j=0; j<nnmax; j++)
|
---|
149 | {
|
---|
150 | const Int_t id2 = gpix.GetNeighbor(j);
|
---|
151 |
|
---|
152 | if (!ispixused[id2])
|
---|
153 | continue;
|
---|
154 |
|
---|
155 | cnt = kTRUE;
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | if (cnt)
|
---|
159 | continue;
|
---|
160 |
|
---|
161 | //
|
---|
162 | // check if no next neighbor has the state 'used'
|
---|
163 | // set this pixel to 'unused', too.
|
---|
164 | //
|
---|
165 | pix.SetPixelUnused();
|
---|
166 | }
|
---|
167 |
|
---|
168 | //
|
---|
169 | // now we declare all pixels that survive as CorePixels
|
---|
170 | //
|
---|
171 | for (Int_t i=0; i<entries; i++)
|
---|
172 | {
|
---|
173 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
174 |
|
---|
175 | if (pix.IsPixelUsed())
|
---|
176 | pix.SetCorePixel();
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | // --------------------------------------------------------------------------
|
---|
181 | //
|
---|
182 | // Look for the boundary pixels around the core pixels
|
---|
183 | // if a pixel has more than 2.5 (clean level 2) sigma, and
|
---|
184 | // a core neigbor it is declared as used.
|
---|
185 | //
|
---|
186 | void MImgCleanStd::CleanStep3()
|
---|
187 | {
|
---|
188 | const Int_t entries = fEvt->GetNumPixels();
|
---|
189 |
|
---|
190 | for (Int_t i=0; i<entries; i++)
|
---|
191 | {
|
---|
192 | //
|
---|
193 | // get pixel as entry il from list
|
---|
194 | //
|
---|
195 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
196 |
|
---|
197 | //
|
---|
198 | // if pixel is a core pixel go to the next pixel
|
---|
199 | //
|
---|
200 | if (pix.IsCorePixel())
|
---|
201 | continue;
|
---|
202 |
|
---|
203 | //
|
---|
204 | // check the num of photons against the noise level
|
---|
205 | //
|
---|
206 | const Float_t entry = pix.GetNumPhotons();
|
---|
207 | const Float_t noise = pix.GetErrorPhot();
|
---|
208 |
|
---|
209 | if (entry <= fCleanLvl2 * noise )
|
---|
210 | continue;
|
---|
211 |
|
---|
212 | //
|
---|
213 | // get pixel id of this entry
|
---|
214 | //
|
---|
215 | const Int_t id = pix.GetPixId();
|
---|
216 |
|
---|
217 | //
|
---|
218 | // check if the pixel's next neighbor is a core pixel.
|
---|
219 | // if it is a core pixel set pixel state to: used.
|
---|
220 | //
|
---|
221 | MGeomPix &gpix = (*fCam)[id];
|
---|
222 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
223 |
|
---|
224 | for (Int_t j=0; j<nnmax; j++)
|
---|
225 | {
|
---|
226 | const Int_t id2 = gpix.GetNeighbor(j);
|
---|
227 |
|
---|
228 | if (!fEvt->IsPixelCore(id2))
|
---|
229 | continue;
|
---|
230 |
|
---|
231 | pix.SetPixelUsed();
|
---|
232 | break;
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | // --------------------------------------------------------------------------
|
---|
238 | //
|
---|
239 | // check if MEvtHeader exists in the Parameter list already.
|
---|
240 | // if not create one and add them to the list
|
---|
241 | //
|
---|
242 | Bool_t MImgCleanStd::PreProcess (MParList *pList)
|
---|
243 | {
|
---|
244 | fCam = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
245 | if (!fCam)
|
---|
246 | {
|
---|
247 | *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
---|
248 | return kFALSE;
|
---|
249 | }
|
---|
250 |
|
---|
251 | fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
|
---|
252 | if (!fEvt)
|
---|
253 | {
|
---|
254 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
---|
255 | return kFALSE;
|
---|
256 | }
|
---|
257 |
|
---|
258 | return kTRUE;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // --------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // Cleans the image.
|
---|
264 | //
|
---|
265 | Bool_t MImgCleanStd::Process()
|
---|
266 | {
|
---|
267 | CleanStep1();
|
---|
268 | CleanStep2();
|
---|
269 | CleanStep3();
|
---|
270 |
|
---|
271 | return kTRUE;
|
---|
272 | }
|
---|
273 |
|
---|