source: trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc@ 1443

Last change on this file since 1443 was 1394, checked in by tbretz, 22 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 11.3 KB
Line 
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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2002
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 <stdlib.h> // atof
46
47#include <TGFrame.h> // TGFrame
48#include <TGLabel.h> // TGLabel
49#include <TGTextEntry.h> // TGTextEntry
50
51#include "MLog.h"
52#include "MLogManip.h"
53
54#include "MParList.h"
55#include "MGeomPix.h"
56#include "MGeomCam.h"
57#include "MCerPhotPix.h"
58#include "MCerPhotEvt.h"
59
60#include "MGGroupFrame.h" // MGGroupFrame
61
62ClassImp(MImgCleanStd);
63
64enum {
65 kImgCleanLvl1,
66 kImgCleanLvl2
67};
68
69// --------------------------------------------------------------------------
70//
71// Default constructor. Here you can specify the cleaning levels. If you
72// don't specify them the 'common standard' values 2.5 and 3.0 (sigma
73// above mean) are used
74//
75MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
76 const char *name, const char *title)
77 : fCleanLvl1(lvl1), fCleanLvl2(lvl2)
78{
79 fName = name ? name : "MImgCleanStd";
80 fTitle = title ? title : "Task which does a standard image cleaning";
81
82 Print();
83}
84
85// --------------------------------------------------------------------------
86//
87// This method looks for all pixels with an entry (photons)
88// that is three times bigger than the noise of the pixel
89// (std: 3 sigma, clean level 1)
90//
91void MImgCleanStd::CleanStep1()
92{
93 const Int_t entries = fEvt->GetNumPixels();
94
95 //
96 // check the number of all pixels against the noise level and
97 // set them to 'unused' state if necessary
98 //
99 for (Int_t i=0; i<entries; i++ )
100 {
101 MCerPhotPix &pix = (*fEvt)[i];
102
103 const Float_t entry = pix.GetNumPhotons();
104 const Float_t noise = pix.GetErrorPhot();
105
106 // COBB: '<=' to skip entry=noise=0
107 if (entry <= fCleanLvl1 * noise)
108 pix.SetPixelUnused();
109 }
110}
111
112// --------------------------------------------------------------------------
113//
114// check if the survived pixel have a neighbor, that also
115// survived
116//
117void MImgCleanStd::CleanStep2()
118{
119 const Int_t entries = fEvt->GetNumPixels();
120
121 //
122 // In the worst case we have to loop 6 times 577 times, to
123 // catch the behaviour of all next neighbors. Here we can gain
124 // much by using an array instead of checking through all pixels
125 // (MCerPhotEvt::IsPixelUsed) all the time.
126 //
127 Byte_t ispixused[577];
128
129 for (Int_t i=0; i<entries; i++)
130 {
131 MCerPhotPix &pix = (*fEvt)[i];
132 ispixused[pix.GetPixId()] = pix.IsPixelUsed();
133 }
134
135 for (Int_t i=0; i<entries; i++)
136 {
137 //
138 // get entry i from list
139 //
140 MCerPhotPix &pix = (*fEvt)[i];
141
142 //
143 // check if pixel is in use, if not goto next pixel in list
144 //
145 if (!pix.IsPixelUsed())
146 continue;
147
148 //
149 // get pixel id of this entry
150 //
151 const Int_t id = pix.GetPixId();
152
153 //
154 // count number of next neighbors of this pixel which
155 // state is 'used'
156 //
157 const MGeomPix &gpix = (*fCam)[id];
158 const Int_t nnmax = gpix.GetNumNeighbors();
159
160 Bool_t cnt = kFALSE;
161 for (Int_t j=0; j<nnmax; j++)
162 {
163 const Int_t id2 = gpix.GetNeighbor(j);
164
165 if (!ispixused[id2])
166 continue;
167
168 cnt = kTRUE;
169 break;
170 }
171 if (cnt)
172 continue;
173
174 //
175 // check if no next neighbor has the state 'used'
176 // set this pixel to 'unused', too.
177 //
178 pix.SetPixelUnused();
179 }
180
181 //
182 // now we declare all pixels that survive as CorePixels
183 //
184 for (Int_t i=0; i<entries; i++)
185 {
186 MCerPhotPix &pix = (*fEvt)[i];
187
188 if (pix.IsPixelUsed())
189 pix.SetPixelCore();
190 }
191}
192
193// --------------------------------------------------------------------------
194//
195// Look for the boundary pixels around the core pixels
196// if a pixel has more than 2.5 (clean level 2.5) sigma, and
197// a core neigbor it is declared as used.
198//
199void MImgCleanStd::CleanStep3()
200{
201 const Int_t entries = fEvt->GetNumPixels();
202
203 for (Int_t i=0; i<entries; i++)
204 {
205 //
206 // get pixel as entry il from list
207 //
208 MCerPhotPix &pix = (*fEvt)[i];
209
210 //
211 // if pixel is a core pixel go to the next pixel
212 //
213 if (pix.IsPixelCore())
214 continue;
215
216 //
217 // check the num of photons against the noise level
218 //
219 const Float_t entry = pix.GetNumPhotons();
220 const Float_t noise = pix.GetErrorPhot();
221
222 if (entry <= fCleanLvl2 * noise )
223 continue;
224
225 //
226 // get pixel id of this entry
227 //
228 const Int_t id = pix.GetPixId();
229
230 //
231 // check if the pixel's next neighbor is a core pixel.
232 // if it is a core pixel set pixel state to: used.
233 //
234 MGeomPix &gpix = (*fCam)[id];
235 const Int_t nnmax = gpix.GetNumNeighbors();
236
237 for (Int_t j=0; j<nnmax; j++)
238 {
239 const Int_t id2 = gpix.GetNeighbor(j);
240
241 if (!fEvt->IsPixelCore(id2))
242 continue;
243
244 pix.SetPixelUsed();
245 break;
246 }
247 }
248}
249
250// --------------------------------------------------------------------------
251//
252// check if MEvtHeader exists in the Parameter list already.
253// if not create one and add them to the list
254//
255Bool_t MImgCleanStd::PreProcess (MParList *pList)
256{
257 fCam = (MGeomCam*)pList->FindObject("MGeomCam");
258 if (!fCam)
259 {
260 *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
261 return kFALSE;
262 }
263
264 fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
265 if (!fEvt)
266 {
267 *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
268 return kFALSE;
269 }
270
271 return kTRUE;
272}
273
274
275// --------------------------------------------------------------------------
276//
277// Cleans the image.
278//
279Bool_t MImgCleanStd::Process()
280{
281 CleanStep1();
282 CleanStep2();
283 CleanStep3();
284
285 return kTRUE;
286}
287
288// --------------------------------------------------------------------------
289//
290// Print descriptor and cleaning levels.
291//
292void MImgCleanStd::Print(Option_t *o) const
293{
294 *fLog << GetDescriptor() << " initialized with noise level ";
295 *fLog << fCleanLvl1 << " and " << fCleanLvl2 << endl;
296}
297
298// --------------------------------------------------------------------------
299//
300// Craete two text entry fields, one for each cleaning level and a
301// describing text line.
302//
303void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
304{
305 //
306 // Create a frame for line 3 and 4 to be able
307 // to align entry field and label in one line
308 //
309 TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
310 TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
311
312 /*
313 * --> use with root >=3.02 <--
314 *
315
316 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
317 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
318
319 */
320 TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
321 TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
322
323 // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
324 // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
325
326 entry1->SetText("3.0");
327 entry2->SetText("2.5");
328
329 entry1->Associate(f);
330 entry2->Associate(f);
331
332 TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
333 TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
334
335 l1->SetTextJustify(kTextLeft);
336 l2->SetTextJustify(kTextLeft);
337
338 //
339 // Align the text of the label centered, left in the row
340 // with a left padding of 10
341 //
342 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
343 TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
344
345 //
346 // Add one entry field and the corresponding label to each line
347 //
348 f1->AddFrame(entry1);
349 f2->AddFrame(entry2);
350
351 f1->AddFrame(l1, laylabel);
352 f2->AddFrame(l2, laylabel);
353
354 f->AddFrame(f1, layframe);
355 f->AddFrame(f2, layframe);
356
357 f->AddToList(entry1);
358 f->AddToList(entry2);
359 f->AddToList(l1);
360 f->AddToList(l2);
361 f->AddToList(laylabel);
362 f->AddToList(layframe);
363}
364
365// --------------------------------------------------------------------------
366//
367// Process the GUI Events comming from the two text entry fields.
368//
369Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
370{
371 if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
372 return kTRUE;
373
374 TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
375
376 if (!txt)
377 return kTRUE;
378
379 Float_t lvl = atof(txt->GetText());
380
381 switch (param1)
382 {
383 case kImgCleanLvl1:
384 fCleanLvl1 = lvl;
385 *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
386 return kTRUE;
387
388 case kImgCleanLvl2:
389 fCleanLvl2 = lvl;
390 *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
391 return kTRUE;
392 }
393
394 return kTRUE;
395}
Note: See TracBrowser for help on using the repository browser.