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 MCerPhotEvt are set as USED and NOT CORE. All the pixels belong
|
---|
64 | // to RING number 1 (like USED pixels).
|
---|
65 | // Look at MCerPhotPix.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 MCerPhotPix.
|
---|
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 | // STANDARD CLEANING:
|
---|
131 | // =================
|
---|
132 | // This is the method used for the CT1 data analysis. It is the default
|
---|
133 | // method of the class.
|
---|
134 | // The number of photo-electrons of a pixel (S_i) is compared to the
|
---|
135 | // pedestal RMS of the pixel itself (Prms_i). To have the comparison to
|
---|
136 | // the same photon density for all the pixels, taking into account they
|
---|
137 | // can have different areas, we have to keep in mind that the number of
|
---|
138 | // photons that hit each pixel, goes linearly with the area of the pixel.
|
---|
139 | // The fluctuations of the LONS are proportional to sqrt(A_i), so when we
|
---|
140 | // compare S_i with Prms_i, only a factor sqrt(A_0/A_i) is missing to
|
---|
141 | // have the same (N.photons/Area) threshold for all the pixels.
|
---|
142 | //
|
---|
143 | // !!WARNING: if noise independent from the
|
---|
144 | // pixel size (example: electronic noise) is introduced,
|
---|
145 | // then the noise fluctuations are no longer proportional
|
---|
146 | // to sqrt(A_i), and then the cut value (for a camera with
|
---|
147 | // pixels of different sizes) resulting from the above
|
---|
148 | // procedure would not be proportional to pixel size as we
|
---|
149 | // intend. In that case, democratic cleaning is preferred.
|
---|
150 | //
|
---|
151 | // If
|
---|
152 | //Begin_Html
|
---|
153 | // <img src="images/MImgCleanStd-f1.png">
|
---|
154 | //End_Html
|
---|
155 | // the pixel survives the cleaning and it is set as CORE (when L_n is the
|
---|
156 | // first level of cleaning, fCleanLvl1) or USED (when L_n is the second
|
---|
157 | // level of cleaning, fCleanLvl2).
|
---|
158 | //
|
---|
159 | // Example:
|
---|
160 | //
|
---|
161 | // MImgCleanStd clean;
|
---|
162 | // //creates a default Cleaning object, with default setting
|
---|
163 | // ...
|
---|
164 | // tlist.AddToList(&clean);
|
---|
165 | // // add the image cleaning to the main task list
|
---|
166 | //
|
---|
167 | // DEMOCRATIC CLEANING:
|
---|
168 | // ===================
|
---|
169 | // You use this cleaning method when you want to compare the number of
|
---|
170 | // photo-electons of each pixel with the average pedestal RMS
|
---|
171 | // (fInnerNoise = fSgb->GetSigmabarInner()) of the inner pixels (for the
|
---|
172 | // MAGIC camera they are the smaller ones):
|
---|
173 | //Begin_Html
|
---|
174 | // <img src="images/MImgCleanStd-f2.png">
|
---|
175 | //End_Html
|
---|
176 | // In this case, the simple ratio (A_0/A_i) is used to weight the level of
|
---|
177 | // cleaning, because both the inner and the outer pixels (that in MAGIC
|
---|
178 | // have a different area) are compared to the same pedestal RMS, coming
|
---|
179 | // from the inner pixels.
|
---|
180 | // To calculate the average pedestal RMS of the inner pixels, you have to
|
---|
181 | // add to the main task list an object of type MSigmabarCalc before the
|
---|
182 | // MImgCleanStd object. To know how the calculation of fInnerNoise is done
|
---|
183 | // look at the MSigmabarCalc Class.
|
---|
184 | //
|
---|
185 | // Example:
|
---|
186 | //
|
---|
187 | // MSigmabarCalc sbcalc;
|
---|
188 | // //creates an object that calcutates the average pedestal RMS
|
---|
189 | // MImgCleanStd clean;
|
---|
190 | // ...
|
---|
191 | // tlist.AddToList(&sbcalc);
|
---|
192 | // tlist.AddToList(&clean);
|
---|
193 | //
|
---|
194 | // Member Function: SetMethod()
|
---|
195 | // ============================
|
---|
196 | // When you call the MImgCleanStd task, the default method is kStandard.
|
---|
197 | //
|
---|
198 | // If you want to switch to the kDemocratic method you have to
|
---|
199 | // call this member function.
|
---|
200 | //
|
---|
201 | // Example:
|
---|
202 | //
|
---|
203 | // MImgCleanStd clean;
|
---|
204 | // //creates a default Cleaning object, with default setting
|
---|
205 | //
|
---|
206 | // clean.SetMethod(MImgCleanStd::kDemocratic);
|
---|
207 | // //now the method of cleaning is changed to Democratic
|
---|
208 | //
|
---|
209 | // FIRST AND SECOND CLEANING LEVEL
|
---|
210 | // ===============================
|
---|
211 | // When you call the MImgCleanStd task, the default cleaning levels are
|
---|
212 | // fCleanLvl1 = 3, fCleanLvl2 = 2.5. You can change them easily when you
|
---|
213 | // create the MImgCleanStd object.
|
---|
214 | //
|
---|
215 | // Example:
|
---|
216 | //
|
---|
217 | // MImgCleanStd clean(Float_t lvl1,Float_t lvl2);
|
---|
218 | // //creates a default cleaning object, but the cleaning levels are now
|
---|
219 | // //lvl1 and lvl2.
|
---|
220 | //
|
---|
221 | // RING NUMBER
|
---|
222 | // ===========
|
---|
223 | // The standard cleaning procedure is such that it looks for the
|
---|
224 | // informations of the boundary part of the shower only on the first
|
---|
225 | // neighbors of the CORE pixels.
|
---|
226 | // There is the possibility now to look not only at the firs neighbors
|
---|
227 | // (first ring),but also further away, around the CORE pixels. All the new
|
---|
228 | // pixels you can find with this method, are tested with the second level
|
---|
229 | // of cleaning and have to have at least an USED neighbor.
|
---|
230 | //
|
---|
231 | // They will be also set as USED and will be taken into account during the
|
---|
232 | // calculation of the image parameters.
|
---|
233 | // The only way to distinguish them from the other USED pixels, is the
|
---|
234 | // Ring number, that is bigger than 1.
|
---|
235 | //
|
---|
236 | // Example: You can decide how many rings you want to analyze using:
|
---|
237 | //
|
---|
238 | // MImgCleanStd clean;
|
---|
239 | // //creates a default cleaning object (default number of rings =1)
|
---|
240 | // clean.SetCleanRings(UShort_t r);
|
---|
241 | // //now it looks r times around the CORE pixels to find new pixels with
|
---|
242 | // //signal.
|
---|
243 | //
|
---|
244 | //
|
---|
245 | // Input Containers:
|
---|
246 | // MGeomCam
|
---|
247 | // MCerPhotEvt
|
---|
248 | // [MSigmabar]
|
---|
249 | //
|
---|
250 | // Output Containers:
|
---|
251 | // MCerPhotEvt
|
---|
252 | //
|
---|
253 | /////////////////////////////////////////////////////////////////////////////
|
---|
254 | #include "MImgCleanStd.h"
|
---|
255 |
|
---|
256 | #include <stdlib.h> // atof
|
---|
257 | #include <fstream> // ofstream, SavePrimitive
|
---|
258 |
|
---|
259 | #include <TGFrame.h> // TGFrame
|
---|
260 | #include <TGLabel.h> // TGLabel
|
---|
261 | #include <TGTextEntry.h> // TGTextEntry
|
---|
262 |
|
---|
263 | #include "MLog.h"
|
---|
264 | #include "MLogManip.h"
|
---|
265 |
|
---|
266 | #include "MParList.h"
|
---|
267 | #include "MSigmabar.h"
|
---|
268 | #include "MCameraData.h"
|
---|
269 |
|
---|
270 | #include "MGeomPix.h"
|
---|
271 | #include "MGeomCam.h"
|
---|
272 |
|
---|
273 | #include "MCerPhotPix.h"
|
---|
274 | #include "MCerPhotEvt.h"
|
---|
275 |
|
---|
276 | #include "MPedestalPix.h"
|
---|
277 | #include "MPedestalCam.h"
|
---|
278 |
|
---|
279 | #include "MGGroupFrame.h" // MGGroupFrame
|
---|
280 |
|
---|
281 | ClassImp(MImgCleanStd);
|
---|
282 |
|
---|
283 | using namespace std;
|
---|
284 |
|
---|
285 | enum {
|
---|
286 | kImgCleanLvl1,
|
---|
287 | kImgCleanLvl2
|
---|
288 | };
|
---|
289 |
|
---|
290 | static const TString gsDefName = "MImgCleanStd";
|
---|
291 | static const TString gsDefTitle = "Task to perform image cleaning";
|
---|
292 |
|
---|
293 | // --------------------------------------------------------------------------
|
---|
294 | //
|
---|
295 | // Default constructor. Here you can specify the cleaning method and levels.
|
---|
296 | // If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
|
---|
297 | // above mean) are used.
|
---|
298 | // Here you can also specify how many rings around the core pixels you want
|
---|
299 | // to analyze (with the fixed lvl2). The default value for "rings" is 1.
|
---|
300 | //
|
---|
301 | MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
|
---|
302 | const char *name, const char *title)
|
---|
303 | : fSgb(NULL), fCleaningMethod(kStandard), fCleanLvl1(lvl1),
|
---|
304 | fCleanLvl2(lvl2), fCleanRings(1)
|
---|
305 |
|
---|
306 | {
|
---|
307 | fName = name ? name : gsDefName.Data();
|
---|
308 | fTitle = title ? title : gsDefTitle.Data();
|
---|
309 |
|
---|
310 | Print();
|
---|
311 | }
|
---|
312 |
|
---|
313 | // --------------------------------------------------------------------------
|
---|
314 | //
|
---|
315 | // The first step of cleaning defines the CORE pixels. All the other pixels
|
---|
316 | // are set as UNUSED and belong to RING 0.
|
---|
317 | // After this point, only the CORE pixels are set as USED, with RING
|
---|
318 | // number 1.
|
---|
319 | //
|
---|
320 | // NT 28/04/2003: now the option to use the standard method or the
|
---|
321 | // democratic method is implemented:
|
---|
322 | //
|
---|
323 | // kStandard: This method looks for all pixels with an entry (photons)
|
---|
324 | // that is three times bigger than the noise of the pixel
|
---|
325 | // (default: 3 sigma, clean level 1)
|
---|
326 | //
|
---|
327 | // kDemocratic: this method looks for all pixels with an entry (photons)
|
---|
328 | // that is n times bigger than the noise of the mean of the
|
---|
329 | // inner pixels (default: 3 sigmabar, clean level 1)
|
---|
330 | //
|
---|
331 | //
|
---|
332 | void MImgCleanStd::CleanStep1()
|
---|
333 | {
|
---|
334 | const Int_t entries = fEvt->GetNumPixels();
|
---|
335 | const TArrayD &data = fData->GetData();
|
---|
336 |
|
---|
337 | //
|
---|
338 | // check the number of all pixels against the noise level and
|
---|
339 | // set them to 'unused' state if necessary
|
---|
340 | //
|
---|
341 | for (Int_t i=0; i<entries; i++ )
|
---|
342 | {
|
---|
343 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
344 |
|
---|
345 | if (data[pix.GetPixId()] <= fCleanLvl1)
|
---|
346 | pix.SetPixelUnused();
|
---|
347 | }
|
---|
348 | }
|
---|
349 |
|
---|
350 | // --------------------------------------------------------------------------
|
---|
351 | //
|
---|
352 | // Check if the survived pixel have a neighbor, that also
|
---|
353 | // survived, otherwise set pixel to unused (removes pixels without
|
---|
354 | // neighbors).
|
---|
355 | //
|
---|
356 | // Takes the maximum pixel id from CleanStep1 as an argument
|
---|
357 | //
|
---|
358 | void MImgCleanStd::CleanStep2()
|
---|
359 | {
|
---|
360 | const Int_t entries = fEvt->GetNumPixels();
|
---|
361 |
|
---|
362 | //
|
---|
363 | // In the worst case we have to loop 6 times 577 times, to
|
---|
364 | // catch the behaviour of all next neighbors. Here we can gain
|
---|
365 | // much by using an array instead of checking through all pixels
|
---|
366 | // (MCerPhotEvt::IsPixelUsed) all the time.
|
---|
367 | //
|
---|
368 | // We allocate the array ourself because the TArrays always do
|
---|
369 | // range check which slows down the access to the array
|
---|
370 | // by 25-50%
|
---|
371 | //
|
---|
372 | Byte_t *ispixused = new Byte_t[fCam->GetNumPixels()];
|
---|
373 | memset(ispixused, 0, sizeof(Byte_t)*fCam->GetNumPixels());
|
---|
374 |
|
---|
375 | for (Int_t i=0; i<entries; i++)
|
---|
376 | {
|
---|
377 | const MCerPhotPix &pix = (*fEvt)[i];
|
---|
378 | ispixused[pix.GetPixId()] = pix.IsPixelUsed() ? 1 : 0 ;
|
---|
379 | }
|
---|
380 |
|
---|
381 | for (Int_t i=0; i<entries; i++)
|
---|
382 | {
|
---|
383 | // get entry i from list
|
---|
384 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
385 |
|
---|
386 | // get pixel id of this entry
|
---|
387 | const Int_t idx = pix.GetPixId();
|
---|
388 |
|
---|
389 | // check if pixel is in use, if not goto next pixel in list
|
---|
390 | if (ispixused[idx] == 0)
|
---|
391 | continue;
|
---|
392 |
|
---|
393 | // check for 'used' neighbors of this pixel
|
---|
394 | const MGeomPix &gpix = (*fCam)[idx];
|
---|
395 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
396 |
|
---|
397 | Bool_t hasNeighbor = kFALSE;
|
---|
398 |
|
---|
399 | //loop on the neighbors to check if they are used
|
---|
400 | for (Int_t j=0; j<nnmax; j++)
|
---|
401 | {
|
---|
402 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
403 |
|
---|
404 | // when you find an used neighbor, break the loop
|
---|
405 | if (ispixused[idx2] == 1)
|
---|
406 | {
|
---|
407 | hasNeighbor = kTRUE;
|
---|
408 | break;
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | if (hasNeighbor == kFALSE)
|
---|
413 | pix.SetPixelUnused();
|
---|
414 | }
|
---|
415 |
|
---|
416 | delete ispixused;
|
---|
417 |
|
---|
418 | //
|
---|
419 | // now we declare all pixels that survive as CorePixels
|
---|
420 | //
|
---|
421 | for (Int_t i=0; i<entries; i++)
|
---|
422 | {
|
---|
423 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
424 |
|
---|
425 | if (pix.IsPixelUsed())
|
---|
426 | pix.SetPixelCore();
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 | void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
|
---|
431 | {
|
---|
432 | const Int_t idx = pix.GetPixId();
|
---|
433 |
|
---|
434 | //
|
---|
435 | // check if the pixel's next neighbor is a core pixel.
|
---|
436 | // if it is a core pixel set pixel state to: used.
|
---|
437 | //
|
---|
438 | MGeomPix &gpix = (*fCam)[idx];
|
---|
439 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
440 |
|
---|
441 | for (Int_t j=0; j<nnmax; j++)
|
---|
442 | {
|
---|
443 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
444 |
|
---|
445 | if (!fEvt->GetPixById(idx2) || !fEvt->IsPixelCore(idx2))
|
---|
446 | continue;
|
---|
447 |
|
---|
448 | pix.SetPixelUsed();
|
---|
449 | break;
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | // --------------------------------------------------------------------------
|
---|
454 | //
|
---|
455 | // NT: Add option "rings": default value = 1.
|
---|
456 | // Look n (n>1) times for the boundary pixels around the used pixels.
|
---|
457 | // If a pixel has more than 2.5 (clean level 2.5) sigma,
|
---|
458 | // it is declared as used.
|
---|
459 | //
|
---|
460 | // If a value<2 for fCleanRings is used, no CleanStep4 is done.
|
---|
461 | //
|
---|
462 | void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
|
---|
463 | {
|
---|
464 | // Skip events that have already a defined status;
|
---|
465 | if( pix.GetRing()!= 0)
|
---|
466 | return;
|
---|
467 | //
|
---|
468 | // check if the pixel's next neighbor is a used pixel.
|
---|
469 | // if it is a used pixel set pixel state to: used,
|
---|
470 | // and tell to which ring it belongs to.
|
---|
471 | //
|
---|
472 | const Int_t idx = pix.GetPixId();
|
---|
473 |
|
---|
474 | MGeomPix &gpix = (*fCam)[idx];
|
---|
475 |
|
---|
476 | const Int_t nnmax = gpix.GetNumNeighbors();
|
---|
477 |
|
---|
478 | for (Int_t j=0; j<nnmax; j++)
|
---|
479 | {
|
---|
480 | const Int_t idx2 = gpix.GetNeighbor(j);
|
---|
481 |
|
---|
482 | MCerPhotPix *npix = fEvt->GetPixById(idx2);
|
---|
483 |
|
---|
484 | if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 )
|
---|
485 | continue;
|
---|
486 |
|
---|
487 | pix.SetRing(r);
|
---|
488 | break;
|
---|
489 | }
|
---|
490 | }
|
---|
491 |
|
---|
492 | // --------------------------------------------------------------------------
|
---|
493 | //
|
---|
494 | // Look for the boundary pixels around the core pixels
|
---|
495 | // if a pixel has more than 2.5 (clean level 2.5) sigma, and
|
---|
496 | // a core neigbor, it is declared as used.
|
---|
497 | //
|
---|
498 | void MImgCleanStd::CleanStep3()
|
---|
499 | {
|
---|
500 | const Int_t entries = fEvt->GetNumPixels();
|
---|
501 | const TArrayD &data = fData->GetData();
|
---|
502 |
|
---|
503 | for (UShort_t r=1; r<fCleanRings+1; r++)
|
---|
504 | {
|
---|
505 | for (Int_t i=0; i<entries; i++)
|
---|
506 | {
|
---|
507 | //
|
---|
508 | // get pixel as entry il from list
|
---|
509 | //
|
---|
510 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
511 |
|
---|
512 | //
|
---|
513 | // if pixel is a core pixel go to the next pixel
|
---|
514 | //
|
---|
515 | if (pix.IsPixelCore())
|
---|
516 | continue;
|
---|
517 |
|
---|
518 | if (data[pix.GetPixId()] <= fCleanLvl2)
|
---|
519 | continue;
|
---|
520 |
|
---|
521 | if (r==1)
|
---|
522 | CleanStep3b(pix);
|
---|
523 | else
|
---|
524 | CleanStep4(r, pix);
|
---|
525 | }
|
---|
526 | }
|
---|
527 | }
|
---|
528 |
|
---|
529 | // --------------------------------------------------------------------------
|
---|
530 | //
|
---|
531 | // Check if MEvtHeader exists in the Parameter list already.
|
---|
532 | // if not create one and add them to the list
|
---|
533 | //
|
---|
534 | Int_t MImgCleanStd::PreProcess (MParList *pList)
|
---|
535 | {
|
---|
536 | fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
537 | if (!fCam)
|
---|
538 | {
|
---|
539 | *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
---|
540 | return kFALSE;
|
---|
541 | }
|
---|
542 |
|
---|
543 | fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
|
---|
544 | if (!fEvt)
|
---|
545 | {
|
---|
546 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
---|
547 | return kFALSE;
|
---|
548 | }
|
---|
549 |
|
---|
550 | if (fCleaningMethod == kDemocratic)
|
---|
551 | {
|
---|
552 | fSgb = (MSigmabar*)pList->FindObject(AddSerialNumber("MSigmabar"));
|
---|
553 | if (!fSgb)
|
---|
554 | {
|
---|
555 | *fLog << dbginf << "MSigmabar not found... aborting." << endl;
|
---|
556 | return kFALSE;
|
---|
557 | }
|
---|
558 | }
|
---|
559 | else
|
---|
560 | {
|
---|
561 | fPed = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
562 | if (!fPed)
|
---|
563 | {
|
---|
564 | *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
|
---|
565 | return kFALSE;
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
|
---|
570 | if (!fData)
|
---|
571 | return kFALSE;
|
---|
572 |
|
---|
573 | return kTRUE;
|
---|
574 | }
|
---|
575 |
|
---|
576 | // --------------------------------------------------------------------------
|
---|
577 | //
|
---|
578 | // Cleans the image.
|
---|
579 | //
|
---|
580 | Int_t MImgCleanStd::Process()
|
---|
581 | {
|
---|
582 | if (fSgb)
|
---|
583 | fData->Calc(*fEvt, *fSgb, *fCam);
|
---|
584 | else
|
---|
585 | fData->Calc(*fEvt, *fPed, *fCam);
|
---|
586 |
|
---|
587 | #ifdef DEBUG
|
---|
588 | *fLog << all << "CleanStep 1" << endl;
|
---|
589 | #endif
|
---|
590 | CleanStep1();
|
---|
591 | #ifdef DEBUG
|
---|
592 | *fLog << all << "CleanStep 2" << endl;
|
---|
593 | #endif
|
---|
594 | CleanStep2();
|
---|
595 | #ifdef DEBUG
|
---|
596 | *fLog << all << "CleanStep 3" << endl;
|
---|
597 | #endif
|
---|
598 | CleanStep3();
|
---|
599 | #ifdef DEBUG
|
---|
600 | *fLog << all << "Done." << endl;
|
---|
601 | #endif
|
---|
602 |
|
---|
603 | return kTRUE;
|
---|
604 | }
|
---|
605 |
|
---|
606 | // --------------------------------------------------------------------------
|
---|
607 | //
|
---|
608 | // Print descriptor and cleaning levels.
|
---|
609 | //
|
---|
610 | void MImgCleanStd::Print(Option_t *o) const
|
---|
611 | {
|
---|
612 | *fLog << all << GetDescriptor() << " using ";
|
---|
613 | switch (fCleaningMethod)
|
---|
614 | {
|
---|
615 | case kDemocratic:
|
---|
616 | *fLog << "democratic";
|
---|
617 | break;
|
---|
618 | case kStandard:
|
---|
619 | *fLog << "standard";
|
---|
620 | break;
|
---|
621 | }
|
---|
622 | *fLog << " cleaning initialized with noise level " << fCleanLvl1 << " and " << fCleanLvl2;
|
---|
623 | *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
|
---|
624 | }
|
---|
625 |
|
---|
626 | // --------------------------------------------------------------------------
|
---|
627 | //
|
---|
628 | // Create two text entry fields, one for each cleaning level and a
|
---|
629 | // describing text line.
|
---|
630 | //
|
---|
631 | void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
|
---|
632 | {
|
---|
633 | //
|
---|
634 | // Create a frame for line 3 and 4 to be able
|
---|
635 | // to align entry field and label in one line
|
---|
636 | //
|
---|
637 | TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
|
---|
638 | TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
|
---|
639 |
|
---|
640 | /*
|
---|
641 | * --> use with root >=3.02 <--
|
---|
642 | *
|
---|
643 |
|
---|
644 | TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
645 | TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
646 |
|
---|
647 | */
|
---|
648 | TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
|
---|
649 | TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
|
---|
650 |
|
---|
651 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
|
---|
652 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
|
---|
653 |
|
---|
654 | entry1->SetText("3.0");
|
---|
655 | entry2->SetText("2.5");
|
---|
656 |
|
---|
657 | entry1->Associate(f);
|
---|
658 | entry2->Associate(f);
|
---|
659 |
|
---|
660 | TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
|
---|
661 | TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
|
---|
662 |
|
---|
663 | l1->SetTextJustify(kTextLeft);
|
---|
664 | l2->SetTextJustify(kTextLeft);
|
---|
665 |
|
---|
666 | //
|
---|
667 | // Align the text of the label centered, left in the row
|
---|
668 | // with a left padding of 10
|
---|
669 | //
|
---|
670 | TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
|
---|
671 | TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
|
---|
672 |
|
---|
673 | //
|
---|
674 | // Add one entry field and the corresponding label to each line
|
---|
675 | //
|
---|
676 | f1->AddFrame(entry1);
|
---|
677 | f2->AddFrame(entry2);
|
---|
678 |
|
---|
679 | f1->AddFrame(l1, laylabel);
|
---|
680 | f2->AddFrame(l2, laylabel);
|
---|
681 |
|
---|
682 | f->AddFrame(f1, layframe);
|
---|
683 | f->AddFrame(f2, layframe);
|
---|
684 |
|
---|
685 | f->AddToList(entry1);
|
---|
686 | f->AddToList(entry2);
|
---|
687 | f->AddToList(l1);
|
---|
688 | f->AddToList(l2);
|
---|
689 | f->AddToList(laylabel);
|
---|
690 | f->AddToList(layframe);
|
---|
691 | }
|
---|
692 |
|
---|
693 | // --------------------------------------------------------------------------
|
---|
694 | //
|
---|
695 | // Process the GUI Events comming from the two text entry fields.
|
---|
696 | //
|
---|
697 | Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
|
---|
698 | {
|
---|
699 | if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
|
---|
700 | return kTRUE;
|
---|
701 |
|
---|
702 | TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
|
---|
703 |
|
---|
704 | if (!txt)
|
---|
705 | return kTRUE;
|
---|
706 |
|
---|
707 | Float_t lvl = atof(txt->GetText());
|
---|
708 |
|
---|
709 | switch (param1)
|
---|
710 | {
|
---|
711 | case kImgCleanLvl1:
|
---|
712 | fCleanLvl1 = lvl;
|
---|
713 | *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
|
---|
714 | return kTRUE;
|
---|
715 |
|
---|
716 | case kImgCleanLvl2:
|
---|
717 | fCleanLvl2 = lvl;
|
---|
718 | *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
|
---|
719 | return kTRUE;
|
---|
720 | }
|
---|
721 |
|
---|
722 | return kTRUE;
|
---|
723 | }
|
---|
724 |
|
---|
725 | // --------------------------------------------------------------------------
|
---|
726 | //
|
---|
727 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
728 | // to a macro. In the original root implementation it is used to write
|
---|
729 | // gui elements to a macro-file.
|
---|
730 | //
|
---|
731 | void MImgCleanStd::StreamPrimitive(ofstream &out) const
|
---|
732 | {
|
---|
733 | out << " MImgCleanStd " << GetUniqueName() << "(";
|
---|
734 | out << fCleanLvl1 << ", " << fCleanLvl2;
|
---|
735 |
|
---|
736 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
---|
737 | {
|
---|
738 | out << ", \"" << fName << "\"";
|
---|
739 | if (fTitle!=gsDefTitle)
|
---|
740 | out << ", \"" << fTitle << "\"";
|
---|
741 | }
|
---|
742 | out << ");" << endl;
|
---|
743 |
|
---|
744 | if (fCleaningMethod!=kDemocratic)
|
---|
745 | return;
|
---|
746 |
|
---|
747 | out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
|
---|
748 |
|
---|
749 | if (fCleanRings==1)
|
---|
750 | return;
|
---|
751 |
|
---|
752 | out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
|
---|
753 | }
|
---|