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@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Harald Kornmayer, 1/2001
|
---|
20 | ! Author(s): Nadia Tonello, 4/2003 <mailto:tonello@mppmu.mpg.de>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MImgCleanStd
|
---|
30 | //
|
---|
31 | // The Image Cleaning task selects the pixels you use for the Hillas
|
---|
32 | // parameters calculation.
|
---|
33 | //
|
---|
34 | // There are two methods to make the selection: the standard one, as done
|
---|
35 | // in the analysis of CT1 data, and the democratic one, as suggested by
|
---|
36 | // W.Wittek. The number of photo-electrons of a pixel is compared with the
|
---|
37 | // pedestal RMS of the pixel itself (standard method) or with the average
|
---|
38 | // RMS of the inner pixels (democratic method).
|
---|
39 | // In both cases, the possibility to have a camera with pixels of
|
---|
40 | // different area is taken into account.
|
---|
41 | // The too noisy pixels can be recognized and eventally switched off
|
---|
42 | // (Unmap: set blind pixels to UNUSED) separately, using the
|
---|
43 | // MBlindPixelCalc Class. In the MBlindPixelCalc class there is also the
|
---|
44 | // function to replace the value of the noisy pixels with the interpolation
|
---|
45 | // of the content of the neighbors (SetUseInterpolation).
|
---|
46 | //
|
---|
47 | // Example:
|
---|
48 | // ...
|
---|
49 | // MBlindPixelCalc blind;
|
---|
50 | // blind.SetUseInterpolation();
|
---|
51 | // blind.SetUseBlindPixels();
|
---|
52 | //
|
---|
53 | // MImgCleanStd clean;
|
---|
54 | // ...
|
---|
55 | // tlist.AddToList(&blind);
|
---|
56 | // tlist.AddToList(&clean);
|
---|
57 | //
|
---|
58 | // Look at the MBlindPixelCalc Class for more details.
|
---|
59 | //
|
---|
60 | // Starting point: default values ----------------------------------------
|
---|
61 | //
|
---|
62 | // When an event is read, before the image cleaning, all the pixels that
|
---|
63 | // are in MSignalCam are set as USED and NOT CORE. All the pixels belong
|
---|
64 | // to RING number 1 (like USED pixels).
|
---|
65 | // Look at MSignalPix.h to see how these informations of the pixel are
|
---|
66 | // stored.
|
---|
67 | // The default cleaning METHOD is the STANDARD one and the number of the
|
---|
68 | // rings around the CORE pixel it analyzes is 1. Look at the Constructor
|
---|
69 | // of the class in MImgCleanStd.cc to see (or change) the default values.
|
---|
70 | //
|
---|
71 | // Example: To modify this setting, use the member functions
|
---|
72 | // SetMethod(MImgCleanStd::kDemocratic) and SetCleanRings(UShort_t n).
|
---|
73 | //
|
---|
74 | // MImgCleanStd:CleanStep1 -----------------------------------------------
|
---|
75 | //
|
---|
76 | // The first step of cleaning defines the CORE pixels. The CORE pixels are
|
---|
77 | // the ones which contain the informations about the core of the electro-
|
---|
78 | // magnetic shower.
|
---|
79 | // The ratio (A_0/A_i) is calculated from fCam->GetPixRatio(i). A_0 is
|
---|
80 | // the area of the central pixel of the camera, A_i is the area of the
|
---|
81 | // examined pixel. In this way, if we have a MAGIC-like camera, with the
|
---|
82 | // outer pixels bigger than the inner ones, the level of cleaning in the
|
---|
83 | // two different regions is weighted.
|
---|
84 | // This avoids problems of deformations of the shower images.
|
---|
85 | // The signal S_i and the pedestal RMS Prms_i of the pixel are called from
|
---|
86 | // the object MSignalPix.
|
---|
87 | // If (default method = kStandard)
|
---|
88 | //Begin_Html
|
---|
89 | // <img src="images/MImgCleanStd-f1.png">
|
---|
90 | //End_Html
|
---|
91 | // the pixel is set as CORE pixel. L_1 (n=1) is called "first level of
|
---|
92 | // cleaning" (default: fCleanLvl1 = 3).
|
---|
93 | // All the other pixels are set as UNUSED and belong to RING 0.
|
---|
94 | // After this point, only the CORE pixels are set as USED, with RING
|
---|
95 | // number 1.
|
---|
96 | //
|
---|
97 | // MImgCleanStd:CleanStep2 ----------------------------------------------
|
---|
98 | //
|
---|
99 | // The second step of cleaning looks at the isolated CORE pixels and sets
|
---|
100 | // them to UNUSED. An isolated pixel is a pixel without CORE neighbors.
|
---|
101 | // At the end of this point, we have set as USED only CORE pixels with at
|
---|
102 | // least one CORE neighbor.
|
---|
103 | //
|
---|
104 | // MImgCleanStd:CleanStep3 ----------------------------------------------
|
---|
105 | //
|
---|
106 | // The third step of cleaning looks at all the pixels (USED or UNUSED) that
|
---|
107 | // surround the USED pixels.
|
---|
108 | // If the content of the analyzed pixel survives at the second level of
|
---|
109 | // cleaning, i.e. if
|
---|
110 | //Begin_Html
|
---|
111 | // <img src="images/MImgCleanStd-f1.png">
|
---|
112 | //End_Html
|
---|
113 | // the pixel is set as USED. L_2 (n=2) is called "second level of cleaning"
|
---|
114 | // (default:fCleanLvl2 = 2.5).
|
---|
115 | //
|
---|
116 | // When the number of RINGS to analyze is 1 (default value), only the
|
---|
117 | // pixels that have a neighbor CORE pixel are analyzed.
|
---|
118 | //
|
---|
119 | // There is the option to decide the number of times you want to repeat
|
---|
120 | // this procedure (number of RINGS analyzed around the core pixels = n).
|
---|
121 | // Every time the level of cleaning is the same (fCleanLvl2) and the pixel
|
---|
122 | // will belong to ring r+1, 1 < r < n+1. This is described in
|
---|
123 | // MImgCleanStd:CleanStep4 .
|
---|
124 | //
|
---|
125 | // Dictionary and member functions ---------------------------------------
|
---|
126 | //
|
---|
127 | // Here there is the detailed description of the member functions and of
|
---|
128 | // the terms commonly used in the class.
|
---|
129 | //
|
---|
130 | //
|
---|
131 | // STANDARD CLEANING:
|
---|
132 | // =================
|
---|
133 | // This is the method used for the CT1 data analysis. It is the default
|
---|
134 | // method of the class.
|
---|
135 | // The number of photo-electrons of a pixel (S_i) is compared to the
|
---|
136 | // pedestal RMS of the pixel itself (Prms_i). To have the comparison to
|
---|
137 | // the same photon density for all the pixels, taking into account they
|
---|
138 | // can have different areas, we have to keep in mind that the number of
|
---|
139 | // photons that hit each pixel, goes linearly with the area of the pixel.
|
---|
140 | // The fluctuations of the LONS are proportional to sqrt(A_i), so when we
|
---|
141 | // compare S_i with Prms_i, only a factor sqrt(A_0/A_i) is missing to
|
---|
142 | // have the same (N.photons/Area) threshold for all the pixels.
|
---|
143 | //
|
---|
144 | // !!WARNING: if noise independent from the
|
---|
145 | // pixel size (example: electronic noise) is introduced,
|
---|
146 | // then the noise fluctuations are no longer proportional
|
---|
147 | // to sqrt(A_i), and then the cut value (for a camera with
|
---|
148 | // pixels of different sizes) resulting from the above
|
---|
149 | // procedure would not be proportional to pixel size as we
|
---|
150 | // intend. In that case, democratic cleaning is preferred.
|
---|
151 | //
|
---|
152 | // If
|
---|
153 | //Begin_Html
|
---|
154 | // <img src="images/MImgCleanStd-f1.png">
|
---|
155 | //End_Html
|
---|
156 | // the pixel survives the cleaning and it is set as CORE (when L_n is the
|
---|
157 | // first level of cleaning, fCleanLvl1) or USED (when L_n is the second
|
---|
158 | // level of cleaning, fCleanLvl2).
|
---|
159 | //
|
---|
160 | // Example:
|
---|
161 | //
|
---|
162 | // MImgCleanStd clean;
|
---|
163 | // //creates a default Cleaning object, with default setting
|
---|
164 | // ...
|
---|
165 | // tlist.AddToList(&clean);
|
---|
166 | // // add the image cleaning to the main task list
|
---|
167 | //
|
---|
168 | //
|
---|
169 | // DEMOCRATIC CLEANING:
|
---|
170 | // ===================
|
---|
171 | // You use this cleaning method when you want to compare the number of
|
---|
172 | // photo-electons of each pixel with the average pedestal RMS of the
|
---|
173 | // inner pixels (for the MAGIC camera they are the smaller ones):
|
---|
174 | //Begin_Html
|
---|
175 | // <img src="images/MImgCleanStd-f2.png">
|
---|
176 | //End_Html
|
---|
177 | // In this case, the simple ratio (A_0/A_i) is used to weight the level of
|
---|
178 | // cleaning, because both the inner and the outer pixels (that in MAGIC
|
---|
179 | // have a different area) are compared to the same pedestal RMS, coming
|
---|
180 | // from the inner pixels.
|
---|
181 | //
|
---|
182 | // Make sure that you used a class calculating the MPedPhotCam which also
|
---|
183 | // updated the contents of the mean values (Recalc) correctly.
|
---|
184 | //
|
---|
185 | //
|
---|
186 | // PROBABILITY CLEANING
|
---|
187 | // ====================
|
---|
188 | // This method takes signal height (over signal noise) and arrival time
|
---|
189 | // into account. Instead of comparing signal/Noise with cleaning level
|
---|
190 | // one and two, we calculate
|
---|
191 | // - P_ped: The probability that a signal is a pedestal (using
|
---|
192 | // the signal height and the pedestal) For this probability the
|
---|
193 | // same algorithm like in kScaled is used (which is a standard
|
---|
194 | // cleaning which scales the noise with the mean noise of pixels
|
---|
195 | // with the same size)
|
---|
196 | // - P_sig: The probability that the signal corresponds to the pixel
|
---|
197 | // with the highest signal. For this probability we use the
|
---|
198 | // arrival time only.
|
---|
199 | //
|
---|
200 | // The cleaning now is done in levels of Probability (eg. 0.2, 0.05)
|
---|
201 | // The meaning of the cleaning levels is essentially the same (the same cleaning
|
---|
202 | // algorithm is used) but the cleaning is not done in levels of signal/noise
|
---|
203 | // but in level of this probability.
|
---|
204 | //
|
---|
205 | // This probability is calculated as (1-P_ped)*P_sig
|
---|
206 | //
|
---|
207 | // Example:
|
---|
208 | //
|
---|
209 | // MImgCleanStd clean(0.2, 0.05);
|
---|
210 | // clean.SetMethod(MImgCleanStd::kProbability);
|
---|
211 | //
|
---|
212 | //
|
---|
213 | // ABSOLUTE CLEANING
|
---|
214 | // =================
|
---|
215 | // This method takes signal height (photons) times area ratio
|
---|
216 | // ad the cleaning levels.
|
---|
217 | //
|
---|
218 | // The cleaning now is done in these levels (eg. 16, 20)
|
---|
219 | // The meaning of the cleaning levels is essentially the same (the same cleaning
|
---|
220 | // algorithm is used) but the cleaning is not done in different 'units'
|
---|
221 | //
|
---|
222 | // Example:
|
---|
223 | //
|
---|
224 | // MImgCleanStd clean(20, 16);
|
---|
225 | // clean.SetMethod(MImgCleanStd::kAbsolulte);
|
---|
226 | //
|
---|
227 | //
|
---|
228 | // Member Function: SetMethod()
|
---|
229 | // ============================
|
---|
230 | // When you call the MImgCleanStd task, the default method is kStandard.
|
---|
231 | //
|
---|
232 | // If you want to switch to the kDemocratic method you have to
|
---|
233 | // call this member function.
|
---|
234 | //
|
---|
235 | // Example:
|
---|
236 | //
|
---|
237 | // MImgCleanStd clean;
|
---|
238 | // //creates a default Cleaning object, with default setting
|
---|
239 | //
|
---|
240 | // clean.SetMethod(MImgCleanStd::kDemocratic);
|
---|
241 | // //now the method of cleaning is changed to Democratic
|
---|
242 | //
|
---|
243 | //
|
---|
244 | // FIRST AND SECOND CLEANING LEVEL
|
---|
245 | // ===============================
|
---|
246 | // When you call the MImgCleanStd task, the default cleaning levels are
|
---|
247 | // fCleanLvl1 = 3, fCleanLvl2 = 2.5. You can change them easily when you
|
---|
248 | // create the MImgCleanStd object.
|
---|
249 | //
|
---|
250 | // Example:
|
---|
251 | //
|
---|
252 | // MImgCleanStd clean(Float_t lvl1,Float_t lvl2);
|
---|
253 | // //creates a default cleaning object, but the cleaning levels are now
|
---|
254 | // //lvl1 and lvl2.
|
---|
255 | //
|
---|
256 | // RING NUMBER
|
---|
257 | // ===========
|
---|
258 | // The standard cleaning procedure is such that it looks for the
|
---|
259 | // informations of the boundary part of the shower only on the first
|
---|
260 | // neighbors of the CORE pixels.
|
---|
261 | // There is the possibility now to look not only at the firs neighbors
|
---|
262 | // (first ring),but also further away, around the CORE pixels. All the new
|
---|
263 | // pixels you can find with this method, are tested with the second level
|
---|
264 | // of cleaning and have to have at least an USED neighbor.
|
---|
265 | //
|
---|
266 | // They will be also set as USED and will be taken into account during the
|
---|
267 | // calculation of the image parameters.
|
---|
268 | // The only way to distinguish them from the other USED pixels, is the
|
---|
269 | // Ring number, that is bigger than 1.
|
---|
270 | //
|
---|
271 | // Example: You can decide how many rings you want to analyze using:
|
---|
272 | //
|
---|
273 | // MImgCleanStd clean;
|
---|
274 | // //creates a default cleaning object (default number of rings =1)
|
---|
275 | // clean.SetCleanRings(UShort_t r);
|
---|
276 | // //now it looks r times around the CORE pixels to find new pixels with
|
---|
277 | // //signal.
|
---|
278 | //
|
---|
279 | //
|
---|
280 | // Input Containers:
|
---|
281 | // MGeomCam
|
---|
282 | // MPedPhotCam
|
---|
283 | // MSignalCam
|
---|
284 | //
|
---|
285 | // Output Containers:
|
---|
286 | // MSignalCam
|
---|
287 | //
|
---|
288 | /////////////////////////////////////////////////////////////////////////////
|
---|
289 | #include "MImgCleanStd.h"
|
---|
290 |
|
---|
291 | #include <stdlib.h> // atof
|
---|
292 | #include <fstream> // ofstream, SavePrimitive
|
---|
293 |
|
---|
294 | #include <TEnv.h>
|
---|
295 |
|
---|
296 | #include <TGFrame.h> // TGFrame
|
---|
297 | #include <TGLabel.h> // TGLabel
|
---|
298 | #include <TGTextEntry.h> // TGTextEntry
|
---|
299 |
|
---|
300 | #include "MLog.h"
|
---|
301 | #include "MLogManip.h"
|
---|
302 |
|
---|
303 | #include "MParList.h"
|
---|
304 | #include "MCameraData.h"
|
---|
305 |
|
---|
306 | #include "MGeomPix.h"
|
---|
307 | #include "MGeomCam.h"
|
---|
308 |
|
---|
309 | #include "MSignalPix.h"
|
---|
310 | #include "MSignalCam.h"
|
---|
311 |
|
---|
312 | #include "MGGroupFrame.h" // MGGroupFrame
|
---|
313 |
|
---|
314 | ClassImp(MImgCleanStd);
|
---|
315 |
|
---|
316 | using namespace std;
|
---|
317 |
|
---|
318 | enum {
|
---|
319 | kImgCleanLvl1,
|
---|
320 | kImgCleanLvl2
|
---|
321 | };
|
---|
322 |
|
---|
323 | static const TString gsDefName = "MImgCleanStd";
|
---|
324 | static const TString gsDefTitle = "Task to perform image cleaning";
|
---|
325 |
|
---|
326 | const TString MImgCleanStd::gsNamePedPhotCam="MPedPhotCam"; // default name of the 'MPedPhotCam' container
|
---|
327 | const TString MImgCleanStd::gsNameSignalCam ="MSignalCam"; // default name of the 'MSignalCam' container
|
---|
328 | const TString MImgCleanStd::gsNameGeomCam ="MGeomCam"; // default name of the 'MGeomCam' container
|
---|
329 |
|
---|
330 | // --------------------------------------------------------------------------
|
---|
331 | //
|
---|
332 | // Default constructor. Here you can specify the cleaning method and levels.
|
---|
333 | // If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
|
---|
334 | // above mean) are used.
|
---|
335 | // Here you can also specify how many rings around the core pixels you want
|
---|
336 | // to analyze (with the fixed lvl2). The default value for "rings" is 1.
|
---|
337 | //
|
---|
338 | MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
|
---|
339 | const char *name, const char *title)
|
---|
340 | : fCleaningMethod(kStandard), fCleanLvl1(lvl1),
|
---|
341 | fCleanLvl2(lvl2), fCleanRings(1), fKeepSinglePixels(kFALSE),
|
---|
342 | fNamePedPhotCam(gsNamePedPhotCam), fNameGeomCam(gsNameGeomCam),
|
---|
343 | fNameSignalCam(gsNameSignalCam)
|
---|
344 | {
|
---|
345 | fName = name ? name : gsDefName.Data();
|
---|
346 | fTitle = title ? title : gsDefTitle.Data();
|
---|
347 | }
|
---|
348 |
|
---|
349 | // --------------------------------------------------------------------------
|
---|
350 | //
|
---|
351 | // The first step of cleaning defines the CORE pixels. All the other pixels
|
---|
352 | // are set as UNUSED and belong to RING 0.
|
---|
353 | // After this point, only the CORE pixels are set as USED, with RING
|
---|
354 | // number 1.
|
---|
355 | //
|
---|
356 | // NT 28/04/2003: now the option to use the standard method or the
|
---|
357 | // democratic method is implemented:
|
---|
358 | //
|
---|
359 | // kStandard: This method looks for all pixels with an entry (photons)
|
---|
360 | // that is three times bigger than the noise of the pixel
|
---|
361 | // (default: 3 sigma, clean level 1)
|
---|
362 | //
|
---|
363 | // kDemocratic: this method looks for all pixels with an entry (photons)
|
---|
364 | // that is n times bigger than the noise of the mean of the
|
---|
365 | // inner pixels (default: 3 sigmabar, clean level 1)
|
---|
366 | //
|
---|
367 | //
|
---|
368 | void MImgCleanStd::CleanStep1()
|
---|
369 | {
|
---|
370 | const TArrayD &data = fData->GetData();
|
---|
371 |
|
---|
372 | //
|
---|
373 | // check the number of all pixels against the noise level and
|
---|
374 | // set them to 'unused' state if necessary
|
---|
375 | //
|
---|
376 | const UInt_t npixevt = fEvt->GetNumPixels();
|
---|
377 | for (UInt_t idx=0; idx<npixevt; idx++)
|
---|
378 | {
|
---|
379 | if (data[idx]>fCleanLvl1)
|
---|
380 | continue;
|
---|
381 |
|
---|
382 | MSignalPix &pix = (*fEvt)[idx];
|
---|
383 | if (!pix.IsPixelUnmapped())
|
---|
384 | pix.SetPixelUnused();
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | // --------------------------------------------------------------------------
|
---|
389 | //
|
---|
390 | // Check if the survived pixel have a neighbor, that also
|
---|
391 | // survived. Set all single pixels Unused if !fKeepSinglePixels. Now we
|
---|
392 | // declare all pixels that survived previous CleanSteps as CorePixels.
|
---|
393 | // Return number of single pixels, and there cumulative size in size.
|
---|
394 | //
|
---|
395 | Short_t MImgCleanStd::CleanStep2(Float_t &size)
|
---|
396 | {
|
---|
397 | Short_t n=0;
|
---|
398 | size = 0;
|
---|
399 |
|
---|
400 | const UInt_t npixevt = fEvt->GetNumPixels();
|
---|
401 | for (UInt_t idx=0; idx<npixevt; idx++)
|
---|
402 | {
|
---|
403 | MSignalPix &pix = (*fEvt)[idx];
|
---|
404 | if (!pix.IsPixelUsed())
|
---|
405 | continue;
|
---|
406 |
|
---|
407 | // check for 'used' neighbors of this pixel
|
---|
408 | const MGeomPix &gpix = (*fCam)[idx];
|
---|
409 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
410 |
|
---|
411 | Bool_t hasNeighbor = kFALSE;
|
---|
412 |
|
---|
413 | //loop on the neighbors to check if they are used
|
---|
414 | for (Int_t j=0; j<nnmax; j++)
|
---|
415 | {
|
---|
416 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
417 |
|
---|
418 | // when you find an used neighbor, break the loop
|
---|
419 | if (fEvt->IsPixelUsed(idx2))
|
---|
420 | {
|
---|
421 | hasNeighbor = kTRUE;
|
---|
422 | break;
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | if (hasNeighbor == kFALSE)
|
---|
427 | {
|
---|
428 | if (!fKeepSinglePixels)
|
---|
429 | pix.SetPixelUnused();
|
---|
430 | size += pix.GetNumPhotons();
|
---|
431 | n++;
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | for (UInt_t idx=0; idx<npixevt; idx++)
|
---|
436 | {
|
---|
437 | MSignalPix &pix = (*fEvt)[idx];
|
---|
438 | if (pix.IsPixelUsed())
|
---|
439 | pix.SetPixelCore();
|
---|
440 | }
|
---|
441 |
|
---|
442 | return n;
|
---|
443 | }
|
---|
444 |
|
---|
445 | void MImgCleanStd::CleanStep3b(Int_t idx)
|
---|
446 | {
|
---|
447 | MSignalPix &pix = (*fEvt)[idx];
|
---|
448 |
|
---|
449 | //
|
---|
450 | // check if the pixel's next neighbor is a core pixel.
|
---|
451 | // if it is a core pixel set pixel state to: used.
|
---|
452 | //
|
---|
453 | MGeomPix &gpix = (*fCam)[idx];
|
---|
454 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
455 |
|
---|
456 | for (Int_t j=0; j<nnmax; j++)
|
---|
457 | {
|
---|
458 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
459 |
|
---|
460 | if (!fEvt->IsPixelCore(idx2))
|
---|
461 | continue;
|
---|
462 |
|
---|
463 | pix.SetPixelUsed();
|
---|
464 | break;
|
---|
465 | }
|
---|
466 | }
|
---|
467 |
|
---|
468 | // --------------------------------------------------------------------------
|
---|
469 | //
|
---|
470 | // NT: Add option "rings": default value = 1.
|
---|
471 | // Look n (n>1) times for the boundary pixels around the used pixels.
|
---|
472 | // If a pixel has more than 2.5 (clean level 2.5) sigma,
|
---|
473 | // it is declared as used.
|
---|
474 | //
|
---|
475 | // If a value<2 for fCleanRings is used, no CleanStep4 is done.
|
---|
476 | //
|
---|
477 | void MImgCleanStd::CleanStep4(UShort_t r, Int_t idx/*MSignalPix &pix*/)
|
---|
478 | {
|
---|
479 | MSignalPix &pix = (*fEvt)[idx];
|
---|
480 |
|
---|
481 | //
|
---|
482 | // Skip events that have already a defined status;
|
---|
483 | //
|
---|
484 | if (pix.GetRing() != 0)
|
---|
485 | return;
|
---|
486 |
|
---|
487 | //
|
---|
488 | // check if the pixel's next neighbor is a used pixel.
|
---|
489 | // if it is a used pixel set pixel state to: used,
|
---|
490 | // and tell to which ring it belongs to.
|
---|
491 | //
|
---|
492 | MGeomPix &gpix = (*fCam)[idx];
|
---|
493 |
|
---|
494 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
495 |
|
---|
496 | for (Int_t j=0; j<nnmax; j++)
|
---|
497 | {
|
---|
498 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
499 |
|
---|
500 | MSignalPix *npix = fEvt->GetPixById(idx2);
|
---|
501 | if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 )
|
---|
502 | continue;
|
---|
503 |
|
---|
504 | pix.SetRing(r);
|
---|
505 | break;
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | // --------------------------------------------------------------------------
|
---|
510 | //
|
---|
511 | // Look for the boundary pixels around the core pixels
|
---|
512 | // if a pixel has more than 2.5 (clean level 2.5) sigma, and
|
---|
513 | // a core neigbor, it is declared as used.
|
---|
514 | //
|
---|
515 | void MImgCleanStd::CleanStep3()
|
---|
516 | {
|
---|
517 | const TArrayD &data = fData->GetData();
|
---|
518 |
|
---|
519 | for (UShort_t r=1; r<fCleanRings+1; r++)
|
---|
520 | {
|
---|
521 | // Loop over all pixels
|
---|
522 | const UInt_t npixevt = fEvt->GetNumPixels();
|
---|
523 | for (UInt_t idx=0; idx<npixevt; idx++)
|
---|
524 | {
|
---|
525 | MSignalPix &pix = (*fEvt)[idx];
|
---|
526 |
|
---|
527 | //
|
---|
528 | // if pixel is a core pixel or unmapped, go to the next pixel
|
---|
529 | //
|
---|
530 | if (pix.IsPixelCore() || pix.IsPixelUnmapped())
|
---|
531 | continue;
|
---|
532 |
|
---|
533 | if (data[idx] <= fCleanLvl2)
|
---|
534 | continue;
|
---|
535 |
|
---|
536 | if (r==1)
|
---|
537 | CleanStep3b(idx);
|
---|
538 | else
|
---|
539 | CleanStep4(r, idx);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|
544 | // --------------------------------------------------------------------------
|
---|
545 | //
|
---|
546 | // Check if MEvtHeader exists in the Parameter list already.
|
---|
547 | // if not create one and add them to the list
|
---|
548 | //
|
---|
549 | Int_t MImgCleanStd::PreProcess (MParList *pList)
|
---|
550 | {
|
---|
551 | fCam = (MGeomCam*)pList->FindObject(AddSerialNumber(fNameGeomCam), "MGeomCam");
|
---|
552 | if (!fCam)
|
---|
553 | {
|
---|
554 | *fLog << err << fNameGeomCam << " [MGeomCam] not found (no geometry information available)... aborting." << endl;
|
---|
555 | return kFALSE;
|
---|
556 | }
|
---|
557 |
|
---|
558 | fEvt = (MSignalCam*)pList->FindObject(AddSerialNumber(fNameSignalCam), "MSignalCam");
|
---|
559 | if (!fEvt)
|
---|
560 | {
|
---|
561 | *fLog << err << fNameSignalCam << " [MSignalCam] not found... aborting." << endl;
|
---|
562 | return kFALSE;
|
---|
563 | }
|
---|
564 |
|
---|
565 | fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
|
---|
566 | if (!fPed)
|
---|
567 | {
|
---|
568 | *fLog << err << fNamePedPhotCam << " [MPedPhotCam] not found... aborting." << endl;
|
---|
569 | return kFALSE;
|
---|
570 | }
|
---|
571 |
|
---|
572 | fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
|
---|
573 | if (!fData)
|
---|
574 | return kFALSE;
|
---|
575 |
|
---|
576 | Print();
|
---|
577 |
|
---|
578 | return kTRUE;
|
---|
579 | }
|
---|
580 |
|
---|
581 | // --------------------------------------------------------------------------
|
---|
582 | //
|
---|
583 | // Cleans the image.
|
---|
584 | //
|
---|
585 | Int_t MImgCleanStd::Process()
|
---|
586 | {
|
---|
587 | switch (fCleaningMethod)
|
---|
588 | {
|
---|
589 | case kStandard:
|
---|
590 | fData->CalcCleaningLevel(*fEvt, *fPed, *fCam);
|
---|
591 | break;
|
---|
592 | case kScaled:
|
---|
593 | fData->CalcCleaningLevel2(*fEvt, *fPed, *fCam);
|
---|
594 | break;
|
---|
595 | case kDemocratic:
|
---|
596 | fData->CalcCleaningLevelDemocratic(*fEvt, *fPed, *fCam);
|
---|
597 | break;
|
---|
598 | case kProbability:
|
---|
599 | fData->CalcCleaningProbability(*fEvt, *fPed, *fCam);
|
---|
600 | break;
|
---|
601 | case kAbsolute:
|
---|
602 | fData->CalcCleaningAbsolute(*fEvt, *fCam);
|
---|
603 | break;
|
---|
604 | default:
|
---|
605 | break;
|
---|
606 | }
|
---|
607 |
|
---|
608 | #ifdef DEBUG
|
---|
609 | *fLog << all << "CleanStep 1" << endl;
|
---|
610 | #endif
|
---|
611 | CleanStep1();
|
---|
612 |
|
---|
613 |
|
---|
614 | #ifdef DEBUG
|
---|
615 | *fLog << all << "CleanStep 2" << endl;
|
---|
616 | #endif
|
---|
617 | Float_t size;
|
---|
618 | const Short_t n = CleanStep2(size);
|
---|
619 | fEvt->SetSinglePixels(n, size);
|
---|
620 |
|
---|
621 | // For speed reasons skip the rest of the cleaning if no
|
---|
622 | // action will be taken!
|
---|
623 | if (fCleanLvl1>fCleanLvl2)
|
---|
624 | {
|
---|
625 | #ifdef DEBUG
|
---|
626 | *fLog << all << "CleanStep 3" << endl;
|
---|
627 | #endif
|
---|
628 | CleanStep3();
|
---|
629 | }
|
---|
630 |
|
---|
631 | #ifdef DEBUG
|
---|
632 | *fLog << all << "Calc Islands" << endl;
|
---|
633 | #endif
|
---|
634 | // Takes roughly 10% of the time
|
---|
635 | fEvt->CalcIslands(*fCam);
|
---|
636 |
|
---|
637 | #ifdef DEBUG
|
---|
638 | *fLog << all << "Done." << endl;
|
---|
639 | #endif
|
---|
640 |
|
---|
641 | return kTRUE;
|
---|
642 | }
|
---|
643 |
|
---|
644 | // --------------------------------------------------------------------------
|
---|
645 | //
|
---|
646 | // Print descriptor and cleaning levels.
|
---|
647 | //
|
---|
648 | void MImgCleanStd::Print(Option_t *o) const
|
---|
649 | {
|
---|
650 | *fLog << all << GetDescriptor() << " using ";
|
---|
651 | switch (fCleaningMethod)
|
---|
652 | {
|
---|
653 | case kDemocratic:
|
---|
654 | *fLog << "democratic";
|
---|
655 | break;
|
---|
656 | case kStandard:
|
---|
657 | *fLog << "standard";
|
---|
658 | break;
|
---|
659 | case kScaled:
|
---|
660 | *fLog << "scaled";
|
---|
661 | break;
|
---|
662 | case kProbability:
|
---|
663 | *fLog << "probability";
|
---|
664 | break;
|
---|
665 | case kAbsolute:
|
---|
666 | *fLog << "absolute";
|
---|
667 | break;
|
---|
668 | }
|
---|
669 | *fLog << " cleaning" << endl;
|
---|
670 | *fLog << "initialized with level " << fCleanLvl1 << " and " << fCleanLvl2;
|
---|
671 | *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
|
---|
672 |
|
---|
673 | *fLog << "Name of MPedPhotCam container used: ";
|
---|
674 | *fLog << (fPed?((MParContainer*)fPed)->GetName():(const char*)fNamePedPhotCam) << endl;
|
---|
675 | }
|
---|
676 |
|
---|
677 | // --------------------------------------------------------------------------
|
---|
678 | //
|
---|
679 | // Create two text entry fields, one for each cleaning level and a
|
---|
680 | // describing text line.
|
---|
681 | //
|
---|
682 | void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
|
---|
683 | {
|
---|
684 | //
|
---|
685 | // Create a frame for line 3 and 4 to be able
|
---|
686 | // to align entry field and label in one line
|
---|
687 | //
|
---|
688 | TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
|
---|
689 | TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
|
---|
690 |
|
---|
691 | /*
|
---|
692 | * --> use with root >=3.02 <--
|
---|
693 | *
|
---|
694 |
|
---|
695 | TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
696 | TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
697 |
|
---|
698 | */
|
---|
699 | TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
|
---|
700 | TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
|
---|
701 |
|
---|
702 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
|
---|
703 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
|
---|
704 |
|
---|
705 | entry1->SetText("3.0");
|
---|
706 | entry2->SetText("2.5");
|
---|
707 |
|
---|
708 | entry1->Associate(f);
|
---|
709 | entry2->Associate(f);
|
---|
710 |
|
---|
711 | TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
|
---|
712 | TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
|
---|
713 |
|
---|
714 | l1->SetTextJustify(kTextLeft);
|
---|
715 | l2->SetTextJustify(kTextLeft);
|
---|
716 |
|
---|
717 | //
|
---|
718 | // Align the text of the label centered, left in the row
|
---|
719 | // with a left padding of 10
|
---|
720 | //
|
---|
721 | TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
|
---|
722 | TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
|
---|
723 |
|
---|
724 | //
|
---|
725 | // Add one entry field and the corresponding label to each line
|
---|
726 | //
|
---|
727 | f1->AddFrame(entry1);
|
---|
728 | f2->AddFrame(entry2);
|
---|
729 |
|
---|
730 | f1->AddFrame(l1, laylabel);
|
---|
731 | f2->AddFrame(l2, laylabel);
|
---|
732 |
|
---|
733 | f->AddFrame(f1, layframe);
|
---|
734 | f->AddFrame(f2, layframe);
|
---|
735 |
|
---|
736 | f->AddToList(entry1);
|
---|
737 | f->AddToList(entry2);
|
---|
738 | f->AddToList(l1);
|
---|
739 | f->AddToList(l2);
|
---|
740 | f->AddToList(laylabel);
|
---|
741 | f->AddToList(layframe);
|
---|
742 | }
|
---|
743 |
|
---|
744 | // --------------------------------------------------------------------------
|
---|
745 | //
|
---|
746 | // Process the GUI Events comming from the two text entry fields.
|
---|
747 | //
|
---|
748 | Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
|
---|
749 | {
|
---|
750 | if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
|
---|
751 | return kTRUE;
|
---|
752 |
|
---|
753 | TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
|
---|
754 |
|
---|
755 | if (!txt)
|
---|
756 | return kTRUE;
|
---|
757 |
|
---|
758 | Float_t lvl = atof(txt->GetText());
|
---|
759 |
|
---|
760 | switch (param1)
|
---|
761 | {
|
---|
762 | case kImgCleanLvl1:
|
---|
763 | fCleanLvl1 = lvl;
|
---|
764 | *fLog << "Cleaning level 1 set to " << lvl << endl;
|
---|
765 | return kTRUE;
|
---|
766 |
|
---|
767 | case kImgCleanLvl2:
|
---|
768 | fCleanLvl2 = lvl;
|
---|
769 | *fLog << "Cleaning level 2 set to " << lvl << endl;
|
---|
770 | return kTRUE;
|
---|
771 | }
|
---|
772 |
|
---|
773 | return kTRUE;
|
---|
774 | }
|
---|
775 |
|
---|
776 | // --------------------------------------------------------------------------
|
---|
777 | //
|
---|
778 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
779 | // to a macro. In the original root implementation it is used to write
|
---|
780 | // gui elements to a macro-file.
|
---|
781 | //
|
---|
782 | void MImgCleanStd::StreamPrimitive(ofstream &out) const
|
---|
783 | {
|
---|
784 | out << " MImgCleanStd " << GetUniqueName() << "(";
|
---|
785 | out << fCleanLvl1 << ", " << fCleanLvl2;
|
---|
786 |
|
---|
787 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
---|
788 | {
|
---|
789 | out << ", \"" << fName << "\"";
|
---|
790 | if (fTitle!=gsDefTitle)
|
---|
791 | out << ", \"" << fTitle << "\"";
|
---|
792 | }
|
---|
793 | out << ");" << endl;
|
---|
794 |
|
---|
795 | if (fCleaningMethod!=kStandard)
|
---|
796 | {
|
---|
797 | out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::k";
|
---|
798 | switch (fCleaningMethod)
|
---|
799 | {
|
---|
800 | case kScaled: out << "Scaled"; break;
|
---|
801 | case kDemocratic: out << "Democratic"; break;
|
---|
802 | case kProbability: out << "Probability"; break;
|
---|
803 | case kAbsolute: out << "Absolute"; break;
|
---|
804 | default:
|
---|
805 | break;
|
---|
806 | }
|
---|
807 | out << ");" << endl;
|
---|
808 | }
|
---|
809 | if (fCleanRings!=1)
|
---|
810 | out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
|
---|
811 |
|
---|
812 | if (gsNamePedPhotCam!=fNamePedPhotCam)
|
---|
813 | out << " " << GetUniqueName() << ".SetNamePedPhotCam(\"" << fNamePedPhotCam << "\");" << endl;
|
---|
814 | if (gsNameGeomCam!=fNameGeomCam)
|
---|
815 | out << " " << GetUniqueName() << ".SetNameGeomCam(\"" << fNameGeomCam << "\");" << endl;
|
---|
816 | if (gsNameSignalCam!=fNameSignalCam)
|
---|
817 | out << " " << GetUniqueName() << ".SetNameSignalCam(\"" << fNameSignalCam << "\");" << endl;
|
---|
818 | if (fKeepSinglePixels)
|
---|
819 | out << " " << GetUniqueName() << ".SetKeepSinglePixels();" << endl;
|
---|
820 |
|
---|
821 | }
|
---|
822 |
|
---|
823 | // --------------------------------------------------------------------------
|
---|
824 | //
|
---|
825 | // Read the setup from a TEnv, eg:
|
---|
826 | // MImgCleanStd.CleanLevel1: 3.0
|
---|
827 | // MImgCleanStd.CleanLevel2: 2.5
|
---|
828 | // MImgCleanStd.CleanMethod: Standard, Scaled, Democratic, Probability, Absolute
|
---|
829 | // MImgCleanStd.CleanRings: 1
|
---|
830 | // MImgCleanStd.KeepSinglePixels: yes, no
|
---|
831 | //
|
---|
832 | Int_t MImgCleanStd::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
833 | {
|
---|
834 | Bool_t rc = kFALSE;
|
---|
835 | if (IsEnvDefined(env, prefix, "CleanRings", print))
|
---|
836 | {
|
---|
837 | rc = kTRUE;
|
---|
838 | SetCleanRings(GetEnvValue(env, prefix, "CleanRings", fCleanRings));
|
---|
839 | }
|
---|
840 | if (IsEnvDefined(env, prefix, "CleanLevel1", print))
|
---|
841 | {
|
---|
842 | rc = kTRUE;
|
---|
843 | fCleanLvl1 = GetEnvValue(env, prefix, "CleanLevel1", fCleanLvl1);
|
---|
844 | }
|
---|
845 | if (IsEnvDefined(env, prefix, "CleanLevel2", print))
|
---|
846 | {
|
---|
847 | rc = kTRUE;
|
---|
848 | fCleanLvl2 = GetEnvValue(env, prefix, "CleanLevel2", fCleanLvl2);
|
---|
849 | }
|
---|
850 | if (IsEnvDefined(env, prefix, "KeepSinglePixels", print))
|
---|
851 | {
|
---|
852 | rc = kTRUE;
|
---|
853 | fKeepSinglePixels = GetEnvValue(env, prefix, "KeepSinglePixels", fKeepSinglePixels);
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (IsEnvDefined(env, prefix, "CleanMethod", print))
|
---|
857 | {
|
---|
858 | rc = kTRUE;
|
---|
859 | TString s = GetEnvValue(env, prefix, "CleanMethod", "");
|
---|
860 | s.ToLower();
|
---|
861 | if (s.BeginsWith("standard"))
|
---|
862 | SetMethod(kStandard);
|
---|
863 | if (s.BeginsWith("scaled"))
|
---|
864 | SetMethod(kScaled);
|
---|
865 | if (s.BeginsWith("democratic"))
|
---|
866 | SetMethod(kDemocratic);
|
---|
867 | if (s.BeginsWith("probability"))
|
---|
868 | SetMethod(kProbability);
|
---|
869 | if (s.BeginsWith("absolute"))
|
---|
870 | SetMethod(kAbsolute);
|
---|
871 | }
|
---|
872 |
|
---|
873 | return rc;
|
---|
874 | }
|
---|