| 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 | //
|
|---|
| 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 | // Member Function: SetMethod()
|
|---|
| 187 | // ============================
|
|---|
| 188 | // When you call the MImgCleanStd task, the default method is kStandard.
|
|---|
| 189 | //
|
|---|
| 190 | // If you want to switch to the kDemocratic method you have to
|
|---|
| 191 | // call this member function.
|
|---|
| 192 | //
|
|---|
| 193 | // Example:
|
|---|
| 194 | //
|
|---|
| 195 | // MImgCleanStd clean;
|
|---|
| 196 | // //creates a default Cleaning object, with default setting
|
|---|
| 197 | //
|
|---|
| 198 | // clean.SetMethod(MImgCleanStd::kDemocratic);
|
|---|
| 199 | // //now the method of cleaning is changed to Democratic
|
|---|
| 200 | //
|
|---|
| 201 | //
|
|---|
| 202 | // FIRST AND SECOND CLEANING LEVEL
|
|---|
| 203 | // ===============================
|
|---|
| 204 | // When you call the MImgCleanStd task, the default cleaning levels are
|
|---|
| 205 | // fCleanLvl1 = 3, fCleanLvl2 = 2.5. You can change them easily when you
|
|---|
| 206 | // create the MImgCleanStd object.
|
|---|
| 207 | //
|
|---|
| 208 | // Example:
|
|---|
| 209 | //
|
|---|
| 210 | // MImgCleanStd clean(Float_t lvl1,Float_t lvl2);
|
|---|
| 211 | // //creates a default cleaning object, but the cleaning levels are now
|
|---|
| 212 | // //lvl1 and lvl2.
|
|---|
| 213 | //
|
|---|
| 214 | // RING NUMBER
|
|---|
| 215 | // ===========
|
|---|
| 216 | // The standard cleaning procedure is such that it looks for the
|
|---|
| 217 | // informations of the boundary part of the shower only on the first
|
|---|
| 218 | // neighbors of the CORE pixels.
|
|---|
| 219 | // There is the possibility now to look not only at the firs neighbors
|
|---|
| 220 | // (first ring),but also further away, around the CORE pixels. All the new
|
|---|
| 221 | // pixels you can find with this method, are tested with the second level
|
|---|
| 222 | // of cleaning and have to have at least an USED neighbor.
|
|---|
| 223 | //
|
|---|
| 224 | // They will be also set as USED and will be taken into account during the
|
|---|
| 225 | // calculation of the image parameters.
|
|---|
| 226 | // The only way to distinguish them from the other USED pixels, is the
|
|---|
| 227 | // Ring number, that is bigger than 1.
|
|---|
| 228 | //
|
|---|
| 229 | // Example: You can decide how many rings you want to analyze using:
|
|---|
| 230 | //
|
|---|
| 231 | // MImgCleanStd clean;
|
|---|
| 232 | // //creates a default cleaning object (default number of rings =1)
|
|---|
| 233 | // clean.SetCleanRings(UShort_t r);
|
|---|
| 234 | // //now it looks r times around the CORE pixels to find new pixels with
|
|---|
| 235 | // //signal.
|
|---|
| 236 | //
|
|---|
| 237 | //
|
|---|
| 238 | // Input Containers:
|
|---|
| 239 | // MGeomCam
|
|---|
| 240 | // MPedPhotCam
|
|---|
| 241 | // MCerPhotEvt
|
|---|
| 242 | //
|
|---|
| 243 | // Output Containers:
|
|---|
| 244 | // MCerPhotEvt
|
|---|
| 245 | //
|
|---|
| 246 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 247 | #include "MImgCleanStd.h"
|
|---|
| 248 |
|
|---|
| 249 | #include <stdlib.h> // atof
|
|---|
| 250 | #include <fstream> // ofstream, SavePrimitive
|
|---|
| 251 |
|
|---|
| 252 | #include <TGFrame.h> // TGFrame
|
|---|
| 253 | #include <TGLabel.h> // TGLabel
|
|---|
| 254 | #include <TGTextEntry.h> // TGTextEntry
|
|---|
| 255 |
|
|---|
| 256 | #include "MLog.h"
|
|---|
| 257 | #include "MLogManip.h"
|
|---|
| 258 |
|
|---|
| 259 | #include "MParList.h"
|
|---|
| 260 | #include "MCameraData.h"
|
|---|
| 261 |
|
|---|
| 262 | #include "MGeomPix.h"
|
|---|
| 263 | #include "MGeomCam.h"
|
|---|
| 264 |
|
|---|
| 265 | #include "MCerPhotPix.h"
|
|---|
| 266 | #include "MCerPhotEvt.h"
|
|---|
| 267 |
|
|---|
| 268 | #include "MGGroupFrame.h" // MGGroupFrame
|
|---|
| 269 |
|
|---|
| 270 | ClassImp(MImgCleanStd);
|
|---|
| 271 |
|
|---|
| 272 | using namespace std;
|
|---|
| 273 |
|
|---|
| 274 | enum {
|
|---|
| 275 | kImgCleanLvl1,
|
|---|
| 276 | kImgCleanLvl2
|
|---|
| 277 | };
|
|---|
| 278 |
|
|---|
| 279 | static const TString gsDefName = "MImgCleanStd";
|
|---|
| 280 | static const TString gsDefTitle = "Task to perform image cleaning";
|
|---|
| 281 |
|
|---|
| 282 | // --------------------------------------------------------------------------
|
|---|
| 283 | //
|
|---|
| 284 | // Default constructor. Here you can specify the cleaning method and levels.
|
|---|
| 285 | // If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
|
|---|
| 286 | // above mean) are used.
|
|---|
| 287 | // Here you can also specify how many rings around the core pixels you want
|
|---|
| 288 | // to analyze (with the fixed lvl2). The default value for "rings" is 1.
|
|---|
| 289 | //
|
|---|
| 290 | MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
|
|---|
| 291 | const char *name, const char *title)
|
|---|
| 292 | : fCleaningMethod(kStandard), fCleanLvl1(lvl1),
|
|---|
| 293 | fCleanLvl2(lvl2), fCleanRings(1)
|
|---|
| 294 |
|
|---|
| 295 | {
|
|---|
| 296 | fName = name ? name : gsDefName.Data();
|
|---|
| 297 | fTitle = title ? title : gsDefTitle.Data();
|
|---|
| 298 |
|
|---|
| 299 | Print();
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | // --------------------------------------------------------------------------
|
|---|
| 303 | //
|
|---|
| 304 | // The first step of cleaning defines the CORE pixels. All the other pixels
|
|---|
| 305 | // are set as UNUSED and belong to RING 0.
|
|---|
| 306 | // After this point, only the CORE pixels are set as USED, with RING
|
|---|
| 307 | // number 1.
|
|---|
| 308 | //
|
|---|
| 309 | // NT 28/04/2003: now the option to use the standard method or the
|
|---|
| 310 | // democratic method is implemented:
|
|---|
| 311 | //
|
|---|
| 312 | // kStandard: This method looks for all pixels with an entry (photons)
|
|---|
| 313 | // that is three times bigger than the noise of the pixel
|
|---|
| 314 | // (default: 3 sigma, clean level 1)
|
|---|
| 315 | //
|
|---|
| 316 | // kDemocratic: this method looks for all pixels with an entry (photons)
|
|---|
| 317 | // that is n times bigger than the noise of the mean of the
|
|---|
| 318 | // inner pixels (default: 3 sigmabar, clean level 1)
|
|---|
| 319 | //
|
|---|
| 320 | //
|
|---|
| 321 | void MImgCleanStd::CleanStep1()
|
|---|
| 322 | {
|
|---|
| 323 | const TArrayD &data = fData->GetData();
|
|---|
| 324 |
|
|---|
| 325 | //
|
|---|
| 326 | // check the number of all pixels against the noise level and
|
|---|
| 327 | // set them to 'unused' state if necessary
|
|---|
| 328 | //
|
|---|
| 329 | MCerPhotPix *pix;
|
|---|
| 330 |
|
|---|
| 331 | // Loop over all pixels
|
|---|
| 332 | MCerPhotEvtIter Next(fEvt, kFALSE);
|
|---|
| 333 | while ((pix=static_cast<MCerPhotPix*>(Next())))
|
|---|
| 334 | if (!pix->IsPixelUnmapped() && data[pix->GetPixId()] <= fCleanLvl1)
|
|---|
| 335 | pix->SetPixelUnused();
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | // --------------------------------------------------------------------------
|
|---|
| 339 | //
|
|---|
| 340 | // Check if the survived pixel have a neighbor, that also
|
|---|
| 341 | // survived, otherwise set pixel to unused (removes pixels without
|
|---|
| 342 | // neighbors).
|
|---|
| 343 | //
|
|---|
| 344 | void MImgCleanStd::CleanStep2()
|
|---|
| 345 | {
|
|---|
| 346 | MCerPhotPix *pix;
|
|---|
| 347 |
|
|---|
| 348 | // Loop over used pixels only
|
|---|
| 349 | TIter Next(*fEvt);
|
|---|
| 350 |
|
|---|
| 351 | while ((pix=static_cast<MCerPhotPix*>(Next())))
|
|---|
| 352 | {
|
|---|
| 353 | // get pixel id of this entry
|
|---|
| 354 | const Int_t idx = pix->GetPixId();
|
|---|
| 355 |
|
|---|
| 356 | // check for 'used' neighbors of this pixel
|
|---|
| 357 | const MGeomPix &gpix = (*fCam)[idx];
|
|---|
| 358 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 359 |
|
|---|
| 360 | Bool_t hasNeighbor = kFALSE;
|
|---|
| 361 |
|
|---|
| 362 | //loop on the neighbors to check if they are used
|
|---|
| 363 | for (Int_t j=0; j<nnmax; j++)
|
|---|
| 364 | {
|
|---|
| 365 | const Int_t idx2 = gpix.GetNeighbor(j);
|
|---|
| 366 |
|
|---|
| 367 | // when you find an used neighbor, break the loop
|
|---|
| 368 | if (fEvt->IsPixelUsed(idx2))
|
|---|
| 369 | {
|
|---|
| 370 | hasNeighbor = kTRUE;
|
|---|
| 371 | break;
|
|---|
| 372 | }
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | if (hasNeighbor == kFALSE)
|
|---|
| 376 | pix->SetPixelUnused();
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | //
|
|---|
| 380 | // now we declare all pixels that survive as CorePixels
|
|---|
| 381 | //
|
|---|
| 382 |
|
|---|
| 383 | Next.Reset();
|
|---|
| 384 | while ((pix=static_cast<MCerPhotPix*>(Next())))
|
|---|
| 385 | {
|
|---|
| 386 | if (pix->IsPixelUsed())
|
|---|
| 387 | pix->SetPixelCore();
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
|
|---|
| 392 | {
|
|---|
| 393 | const Int_t idx = pix.GetPixId();
|
|---|
| 394 |
|
|---|
| 395 | //
|
|---|
| 396 | // check if the pixel's next neighbor is a core pixel.
|
|---|
| 397 | // if it is a core pixel set pixel state to: used.
|
|---|
| 398 | //
|
|---|
| 399 | MGeomPix &gpix = (*fCam)[idx];
|
|---|
| 400 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 401 |
|
|---|
| 402 | for (Int_t j=0; j<nnmax; j++)
|
|---|
| 403 | {
|
|---|
| 404 | const Int_t idx2 = gpix.GetNeighbor(j);
|
|---|
| 405 |
|
|---|
| 406 | if (!fEvt->IsPixelCore(idx2))
|
|---|
| 407 | continue;
|
|---|
| 408 |
|
|---|
| 409 | pix.SetPixelUsed();
|
|---|
| 410 | break;
|
|---|
| 411 | }
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | // --------------------------------------------------------------------------
|
|---|
| 415 | //
|
|---|
| 416 | // NT: Add option "rings": default value = 1.
|
|---|
| 417 | // Look n (n>1) times for the boundary pixels around the used pixels.
|
|---|
| 418 | // If a pixel has more than 2.5 (clean level 2.5) sigma,
|
|---|
| 419 | // it is declared as used.
|
|---|
| 420 | //
|
|---|
| 421 | // If a value<2 for fCleanRings is used, no CleanStep4 is done.
|
|---|
| 422 | //
|
|---|
| 423 | void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
|
|---|
| 424 | {
|
|---|
| 425 | //
|
|---|
| 426 | // Skip events that have already a defined status;
|
|---|
| 427 | //
|
|---|
| 428 | if (pix.GetRing() != 0)
|
|---|
| 429 | return;
|
|---|
| 430 |
|
|---|
| 431 | //
|
|---|
| 432 | // check if the pixel's next neighbor is a used pixel.
|
|---|
| 433 | // if it is a used pixel set pixel state to: used,
|
|---|
| 434 | // and tell to which ring it belongs to.
|
|---|
| 435 | //
|
|---|
| 436 | const Int_t idx = pix.GetPixId();
|
|---|
| 437 |
|
|---|
| 438 | MGeomPix &gpix = (*fCam)[idx];
|
|---|
| 439 |
|
|---|
| 440 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 441 |
|
|---|
| 442 | for (Int_t j=0; j<nnmax; j++)
|
|---|
| 443 | {
|
|---|
| 444 | const Int_t idx2 = gpix.GetNeighbor(j);
|
|---|
| 445 |
|
|---|
| 446 | MCerPhotPix *npix = fEvt->GetPixById(idx2);
|
|---|
| 447 | if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 )
|
|---|
| 448 | continue;
|
|---|
| 449 |
|
|---|
| 450 | pix.SetRing(r);
|
|---|
| 451 | break;
|
|---|
| 452 | }
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | // --------------------------------------------------------------------------
|
|---|
| 456 | //
|
|---|
| 457 | // Look for the boundary pixels around the core pixels
|
|---|
| 458 | // if a pixel has more than 2.5 (clean level 2.5) sigma, and
|
|---|
| 459 | // a core neigbor, it is declared as used.
|
|---|
| 460 | //
|
|---|
| 461 | void MImgCleanStd::CleanStep3()
|
|---|
| 462 | {
|
|---|
| 463 | const TArrayD &data = fData->GetData();
|
|---|
| 464 |
|
|---|
| 465 | for (UShort_t r=1; r<fCleanRings+1; r++)
|
|---|
| 466 | {
|
|---|
| 467 | MCerPhotPix *pix;
|
|---|
| 468 |
|
|---|
| 469 | // Loop over all pixels
|
|---|
| 470 |
|
|---|
| 471 | MCerPhotEvtIter NextAll(fEvt, kFALSE);
|
|---|
| 472 | while ((pix=static_cast<MCerPhotPix*>(NextAll())))
|
|---|
| 473 | {
|
|---|
| 474 | //
|
|---|
| 475 | // if pixel is a core pixel or unmapped, go to the next pixel
|
|---|
| 476 | //
|
|---|
| 477 | if (pix->IsPixelCore() || pix->IsPixelUnmapped())
|
|---|
| 478 | continue;
|
|---|
| 479 |
|
|---|
| 480 | if (data[pix->GetPixId()] <= fCleanLvl2)
|
|---|
| 481 | continue;
|
|---|
| 482 |
|
|---|
| 483 | if (r==1)
|
|---|
| 484 | CleanStep3b(*pix);
|
|---|
| 485 | else
|
|---|
| 486 | CleanStep4(r, *pix);
|
|---|
| 487 | }
|
|---|
| 488 | }
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | // --------------------------------------------------------------------------
|
|---|
| 492 | //
|
|---|
| 493 | // Check if MEvtHeader exists in the Parameter list already.
|
|---|
| 494 | // if not create one and add them to the list
|
|---|
| 495 | //
|
|---|
| 496 | Int_t MImgCleanStd::PreProcess (MParList *pList)
|
|---|
| 497 | {
|
|---|
| 498 | fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 499 | if (!fCam)
|
|---|
| 500 | {
|
|---|
| 501 | *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
|---|
| 502 | return kFALSE;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
|
|---|
| 506 | if (!fEvt)
|
|---|
| 507 | {
|
|---|
| 508 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
|---|
| 509 | return kFALSE;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber("MPedPhotCam"));
|
|---|
| 513 | if (!fPed)
|
|---|
| 514 | {
|
|---|
| 515 | *fLog << dbginf << "MPedPhotCam not found... aborting." << endl;
|
|---|
| 516 | return kFALSE;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
|
|---|
| 520 | if (!fData)
|
|---|
| 521 | return kFALSE;
|
|---|
| 522 |
|
|---|
| 523 | return kTRUE;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | // --------------------------------------------------------------------------
|
|---|
| 527 | //
|
|---|
| 528 | // Cleans the image.
|
|---|
| 529 | //
|
|---|
| 530 | Int_t MImgCleanStd::Process()
|
|---|
| 531 | {
|
|---|
| 532 | switch (fCleaningMethod)
|
|---|
| 533 | {
|
|---|
| 534 | case kStandard:
|
|---|
| 535 | fData->CalcCleaningLevel(*fEvt, *fPed, *fCam);
|
|---|
| 536 | break;
|
|---|
| 537 | case kScaled:
|
|---|
| 538 | fData->CalcCleaningLevel2(*fEvt, *fPed, *fCam);
|
|---|
| 539 | break;
|
|---|
| 540 | case kDemocratic:
|
|---|
| 541 | fData->CalcCleaningLevelDemocratic(*fEvt, *fPed, *fCam);
|
|---|
| 542 | break;
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | #ifdef DEBUG
|
|---|
| 546 | *fLog << all << "CleanStep 1" << endl;
|
|---|
| 547 | #endif
|
|---|
| 548 | CleanStep1();
|
|---|
| 549 |
|
|---|
| 550 | // For speed reasons skip the rest of the cleaning if no
|
|---|
| 551 | // action will be taken!
|
|---|
| 552 | if (fCleanLvl1>=fCleanLvl2)
|
|---|
| 553 | return kTRUE;
|
|---|
| 554 |
|
|---|
| 555 | #ifdef DEBUG
|
|---|
| 556 | *fLog << all << "CleanStep 2" << endl;
|
|---|
| 557 | #endif
|
|---|
| 558 | CleanStep2();
|
|---|
| 559 | #ifdef DEBUG
|
|---|
| 560 | *fLog << all << "CleanStep 3" << endl;
|
|---|
| 561 | #endif
|
|---|
| 562 | CleanStep3();
|
|---|
| 563 | #ifdef DEBUG
|
|---|
| 564 | *fLog << all << "Done." << endl;
|
|---|
| 565 | #endif
|
|---|
| 566 |
|
|---|
| 567 | return kTRUE;
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | // --------------------------------------------------------------------------
|
|---|
| 571 | //
|
|---|
| 572 | // Print descriptor and cleaning levels.
|
|---|
| 573 | //
|
|---|
| 574 | void MImgCleanStd::Print(Option_t *o) const
|
|---|
| 575 | {
|
|---|
| 576 | *fLog << all << GetDescriptor() << " using ";
|
|---|
| 577 | switch (fCleaningMethod)
|
|---|
| 578 | {
|
|---|
| 579 | case kDemocratic:
|
|---|
| 580 | *fLog << "democratic";
|
|---|
| 581 | break;
|
|---|
| 582 | case kStandard:
|
|---|
| 583 | *fLog << "standard";
|
|---|
| 584 | break;
|
|---|
| 585 | case kScaled:
|
|---|
| 586 | *fLog << "scaled";
|
|---|
| 587 | break;
|
|---|
| 588 | }
|
|---|
| 589 | *fLog << " cleaning initialized with noise level " << fCleanLvl1 << " and " << fCleanLvl2;
|
|---|
| 590 | *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | // --------------------------------------------------------------------------
|
|---|
| 594 | //
|
|---|
| 595 | // Create two text entry fields, one for each cleaning level and a
|
|---|
| 596 | // describing text line.
|
|---|
| 597 | //
|
|---|
| 598 | void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
|
|---|
| 599 | {
|
|---|
| 600 | //
|
|---|
| 601 | // Create a frame for line 3 and 4 to be able
|
|---|
| 602 | // to align entry field and label in one line
|
|---|
| 603 | //
|
|---|
| 604 | TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
|
|---|
| 605 | TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
|
|---|
| 606 |
|
|---|
| 607 | /*
|
|---|
| 608 | * --> use with root >=3.02 <--
|
|---|
| 609 | *
|
|---|
| 610 |
|
|---|
| 611 | TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
|---|
| 612 | TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
|---|
| 613 |
|
|---|
| 614 | */
|
|---|
| 615 | TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
|
|---|
| 616 | TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
|
|---|
| 617 |
|
|---|
| 618 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
|
|---|
| 619 | // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
|
|---|
| 620 |
|
|---|
| 621 | entry1->SetText("3.0");
|
|---|
| 622 | entry2->SetText("2.5");
|
|---|
| 623 |
|
|---|
| 624 | entry1->Associate(f);
|
|---|
| 625 | entry2->Associate(f);
|
|---|
| 626 |
|
|---|
| 627 | TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
|
|---|
| 628 | TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
|
|---|
| 629 |
|
|---|
| 630 | l1->SetTextJustify(kTextLeft);
|
|---|
| 631 | l2->SetTextJustify(kTextLeft);
|
|---|
| 632 |
|
|---|
| 633 | //
|
|---|
| 634 | // Align the text of the label centered, left in the row
|
|---|
| 635 | // with a left padding of 10
|
|---|
| 636 | //
|
|---|
| 637 | TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
|
|---|
| 638 | TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
|
|---|
| 639 |
|
|---|
| 640 | //
|
|---|
| 641 | // Add one entry field and the corresponding label to each line
|
|---|
| 642 | //
|
|---|
| 643 | f1->AddFrame(entry1);
|
|---|
| 644 | f2->AddFrame(entry2);
|
|---|
| 645 |
|
|---|
| 646 | f1->AddFrame(l1, laylabel);
|
|---|
| 647 | f2->AddFrame(l2, laylabel);
|
|---|
| 648 |
|
|---|
| 649 | f->AddFrame(f1, layframe);
|
|---|
| 650 | f->AddFrame(f2, layframe);
|
|---|
| 651 |
|
|---|
| 652 | f->AddToList(entry1);
|
|---|
| 653 | f->AddToList(entry2);
|
|---|
| 654 | f->AddToList(l1);
|
|---|
| 655 | f->AddToList(l2);
|
|---|
| 656 | f->AddToList(laylabel);
|
|---|
| 657 | f->AddToList(layframe);
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | // --------------------------------------------------------------------------
|
|---|
| 661 | //
|
|---|
| 662 | // Process the GUI Events comming from the two text entry fields.
|
|---|
| 663 | //
|
|---|
| 664 | Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
|
|---|
| 665 | {
|
|---|
| 666 | if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
|
|---|
| 667 | return kTRUE;
|
|---|
| 668 |
|
|---|
| 669 | TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
|
|---|
| 670 |
|
|---|
| 671 | if (!txt)
|
|---|
| 672 | return kTRUE;
|
|---|
| 673 |
|
|---|
| 674 | Float_t lvl = atof(txt->GetText());
|
|---|
| 675 |
|
|---|
| 676 | switch (param1)
|
|---|
| 677 | {
|
|---|
| 678 | case kImgCleanLvl1:
|
|---|
| 679 | fCleanLvl1 = lvl;
|
|---|
| 680 | *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
|
|---|
| 681 | return kTRUE;
|
|---|
| 682 |
|
|---|
| 683 | case kImgCleanLvl2:
|
|---|
| 684 | fCleanLvl2 = lvl;
|
|---|
| 685 | *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
|
|---|
| 686 | return kTRUE;
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | return kTRUE;
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | // --------------------------------------------------------------------------
|
|---|
| 693 | //
|
|---|
| 694 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 695 | // to a macro. In the original root implementation it is used to write
|
|---|
| 696 | // gui elements to a macro-file.
|
|---|
| 697 | //
|
|---|
| 698 | void MImgCleanStd::StreamPrimitive(ofstream &out) const
|
|---|
| 699 | {
|
|---|
| 700 | out << " MImgCleanStd " << GetUniqueName() << "(";
|
|---|
| 701 | out << fCleanLvl1 << ", " << fCleanLvl2;
|
|---|
| 702 |
|
|---|
| 703 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
|---|
| 704 | {
|
|---|
| 705 | out << ", \"" << fName << "\"";
|
|---|
| 706 | if (fTitle!=gsDefTitle)
|
|---|
| 707 | out << ", \"" << fTitle << "\"";
|
|---|
| 708 | }
|
|---|
| 709 | out << ");" << endl;
|
|---|
| 710 |
|
|---|
| 711 | if (fCleaningMethod!=kDemocratic)
|
|---|
| 712 | return;
|
|---|
| 713 |
|
|---|
| 714 | out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
|
|---|
| 715 |
|
|---|
| 716 | if (fCleanRings==1)
|
|---|
| 717 | return;
|
|---|
| 718 |
|
|---|
| 719 | out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
|
|---|
| 720 | }
|
|---|