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