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 | //
|
---|
264 | // Cleans the image.
|
---|
265 | //
|
---|
266 | Bool_t MImgCleanStd::Process()
|
---|
267 | {
|
---|
268 | CleanStep1();
|
---|
269 | CleanStep2();
|
---|
270 | CleanStep3();
|
---|
271 |
|
---|
272 | return kTRUE;
|
---|
273 | }
|
---|
274 |
|
---|
275 | #include <stdlib.h> // atof
|
---|
276 |
|
---|
277 | #include <TGFrame.h> // TGFrame
|
---|
278 | #include <TGLabel.h> // TGLabel
|
---|
279 | #include <TGTextEntry.h> // TGTextEntry
|
---|
280 |
|
---|
281 | #include "MGGroupFrame.h" // MGGroupFrame
|
---|
282 |
|
---|
283 | enum {
|
---|
284 | kImgCleanLvl1,
|
---|
285 | kImgCleanLvl2
|
---|
286 | };
|
---|
287 |
|
---|
288 | void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
|
---|
289 | {
|
---|
290 | //
|
---|
291 | // Create a frame for line 3 and 4 to be able
|
---|
292 | // to align entry field and label in one line
|
---|
293 | //
|
---|
294 | TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
|
---|
295 | TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
|
---|
296 |
|
---|
297 | /*
|
---|
298 | * --> use with root >=3.02 <--
|
---|
299 | *
|
---|
300 |
|
---|
301 | TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
302 | TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
303 |
|
---|
304 | */
|
---|
305 | TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
|
---|
306 | TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
|
---|
307 |
|
---|
308 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
|
---|
309 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
|
---|
310 |
|
---|
311 | entry1->SetText("3.0");
|
---|
312 | entry2->SetText("2.5");
|
---|
313 |
|
---|
314 | entry1->Associate(f);
|
---|
315 | entry2->Associate(f);
|
---|
316 |
|
---|
317 | TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1 for standard image cleaning.");
|
---|
318 | TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2 for standard image cleaning.");
|
---|
319 |
|
---|
320 | l1->SetTextJustify(kTextLeft);
|
---|
321 | l2->SetTextJustify(kTextLeft);
|
---|
322 |
|
---|
323 | //
|
---|
324 | // Align the text of the label centered, left in the row
|
---|
325 | // with a left padding of 10
|
---|
326 | //
|
---|
327 | TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
|
---|
328 | TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
|
---|
329 |
|
---|
330 | //
|
---|
331 | // Add one entry field and the corresponding label to each line
|
---|
332 | //
|
---|
333 | f1->AddFrame(entry1);
|
---|
334 | f2->AddFrame(entry2);
|
---|
335 |
|
---|
336 | f1->AddFrame(l1, laylabel);
|
---|
337 | f2->AddFrame(l2, laylabel);
|
---|
338 |
|
---|
339 | f->AddFrame(f1, layframe);
|
---|
340 | f->AddFrame(f2, layframe);
|
---|
341 |
|
---|
342 | f->AddToList(entry1);
|
---|
343 | f->AddToList(entry2);
|
---|
344 | f->AddToList(l1);
|
---|
345 | f->AddToList(l2);
|
---|
346 | f->AddToList(laylabel);
|
---|
347 | f->AddToList(layframe);
|
---|
348 | }
|
---|
349 |
|
---|
350 | Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
|
---|
351 | {
|
---|
352 | if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
|
---|
353 | return kTRUE;
|
---|
354 |
|
---|
355 | TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
|
---|
356 |
|
---|
357 | if (!txt)
|
---|
358 | return kTRUE;
|
---|
359 |
|
---|
360 | Float_t lvl = atof(txt->GetText());
|
---|
361 |
|
---|
362 | switch (param1)
|
---|
363 | {
|
---|
364 | case kImgCleanLvl1:
|
---|
365 | fCleanLvl1 = lvl;
|
---|
366 | *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
|
---|
367 | return kTRUE;
|
---|
368 |
|
---|
369 | case kImgCleanLvl2:
|
---|
370 | fCleanLvl2 = lvl;
|
---|
371 | *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
|
---|
372 | return kTRUE;
|
---|
373 | }
|
---|
374 |
|
---|
375 | return kTRUE;
|
---|
376 | }
|
---|