| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
|
|---|
| 19 | ! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | #include "MImgCleanStd.h"
|
|---|
| 27 |
|
|---|
| 28 | #include "MLog.h"
|
|---|
| 29 | #include "MLogManip.h"
|
|---|
| 30 |
|
|---|
| 31 | #include "MParList.h"
|
|---|
| 32 | #include "MGeomCam.h"
|
|---|
| 33 | #include "MCerPhotPix.h"
|
|---|
| 34 | #include "MCerPhotEvt.h"
|
|---|
| 35 |
|
|---|
| 36 | ClassImp(MImgCleanStd)
|
|---|
| 37 |
|
|---|
| 38 | MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
|
|---|
| 39 | const char *name, const char *title)
|
|---|
| 40 | : fCleanLvl1(lvl1), fCleanLvl2(lvl2)
|
|---|
| 41 | {
|
|---|
| 42 | //
|
|---|
| 43 | // the default constructor
|
|---|
| 44 | //
|
|---|
| 45 | *fName = name ? name : "MImgCleanStd";
|
|---|
| 46 | *fTitle = title ? title : "Task which does a standard image cleaning";
|
|---|
| 47 |
|
|---|
| 48 | *fLog << "Cleaning initialized. Using noise level " << lvl1 << " and " << lvl2 << endl;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | void MImgCleanStd::CleanStep1()
|
|---|
| 52 | {
|
|---|
| 53 | //
|
|---|
| 54 | // This method looks for all pixels with an entry (photons)
|
|---|
| 55 | // that is three times bigger than the noise of the pixel
|
|---|
| 56 | // (std: 3 sigma, clean level 1)
|
|---|
| 57 | //
|
|---|
| 58 |
|
|---|
| 59 | const Int_t entries = fEvt->GetNumPixels();
|
|---|
| 60 |
|
|---|
| 61 | //
|
|---|
| 62 | // check the number of all pixels against the noise level and
|
|---|
| 63 | // set them to 'unused' state if necessary
|
|---|
| 64 | //
|
|---|
| 65 | for (Int_t i=0; i<entries; i++ )
|
|---|
| 66 | {
|
|---|
| 67 | MCerPhotPix &pix = (*fEvt)[i];
|
|---|
| 68 |
|
|---|
| 69 | const Float_t entry = pix.GetNumPhotons();
|
|---|
| 70 | const Float_t noise = pix.GetErrorPhot();
|
|---|
| 71 |
|
|---|
| 72 | // COBB: '<=' to skip entry=noise=0
|
|---|
| 73 | if (entry <= fCleanLvl1 * noise )
|
|---|
| 74 | pix.SetPixelUnused();
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | void MImgCleanStd::CleanStep2()
|
|---|
| 79 | {
|
|---|
| 80 | //
|
|---|
| 81 | // check if the survived pixel have a neighbor, that also
|
|---|
| 82 | // survived
|
|---|
| 83 | //
|
|---|
| 84 |
|
|---|
| 85 | const Int_t entries = fEvt->GetNumPixels();
|
|---|
| 86 |
|
|---|
| 87 | for (Int_t i=0; i<entries; i++)
|
|---|
| 88 | {
|
|---|
| 89 | //
|
|---|
| 90 | // get entry i from list
|
|---|
| 91 | //
|
|---|
| 92 | MCerPhotPix &pix = (*fEvt)[i];
|
|---|
| 93 |
|
|---|
| 94 | //
|
|---|
| 95 | // check if pixel is in use, if not goto next pixel in list
|
|---|
| 96 | //
|
|---|
| 97 | if (!pix.IsPixelUsed())
|
|---|
| 98 | continue;
|
|---|
| 99 |
|
|---|
| 100 | //
|
|---|
| 101 | // get pixel id of this entry
|
|---|
| 102 | //
|
|---|
| 103 | const Int_t id = pix.GetPixId();
|
|---|
| 104 |
|
|---|
| 105 | //
|
|---|
| 106 | // count number of next neighbors of this pixel which
|
|---|
| 107 | // state is 'used'
|
|---|
| 108 | //
|
|---|
| 109 | MGeomPix &gpix = (*fCam)[id];
|
|---|
| 110 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 111 |
|
|---|
| 112 | Int_t cnt = 0;
|
|---|
| 113 | for (Int_t j=0; j<nnmax; j++)
|
|---|
| 114 | {
|
|---|
| 115 | const Int_t id2 = gpix.GetNeighbor(j); //GetNN(id, in) ;
|
|---|
| 116 |
|
|---|
| 117 | if (id2 < 0)
|
|---|
| 118 | continue;
|
|---|
| 119 |
|
|---|
| 120 | if (fEvt->IsPixelUsed(id2))
|
|---|
| 121 | cnt++;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | //
|
|---|
| 125 | // check if no next neighbor has the state 'used'
|
|---|
| 126 | // set this pixel to 'unused', too.
|
|---|
| 127 | //
|
|---|
| 128 | if (cnt==0)
|
|---|
| 129 | pix.SetPixelUnused();
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | //
|
|---|
| 133 | // now we declare all pixels that survive as CorePixels
|
|---|
| 134 | //
|
|---|
| 135 | for (Int_t i=0; i<entries; i++)
|
|---|
| 136 | {
|
|---|
| 137 | MCerPhotPix &pix = (*fEvt)[i];
|
|---|
| 138 |
|
|---|
| 139 | if (pix.IsPixelUsed())
|
|---|
| 140 | pix.SetCorePixel();
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | void MImgCleanStd::CleanStep3()
|
|---|
| 145 | {
|
|---|
| 146 | //
|
|---|
| 147 | // Look for the boundary pixels around the core pixels
|
|---|
| 148 | // if a pixel has more than 2.5 (clean level 2) sigma, and
|
|---|
| 149 | // a core neigbor it is declared as used.
|
|---|
| 150 | //
|
|---|
| 151 | const Int_t entries = fEvt->GetNumPixels();
|
|---|
| 152 |
|
|---|
| 153 | for (Int_t i=0; i<entries; i++)
|
|---|
| 154 | {
|
|---|
| 155 | //
|
|---|
| 156 | // get pixel as entry il from list
|
|---|
| 157 | //
|
|---|
| 158 | MCerPhotPix &pix = (*fEvt)[i];
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | // if pixel is a core pixel go to the next pixel
|
|---|
| 162 | //
|
|---|
| 163 | if (pix.IsCorePixel())
|
|---|
| 164 | continue;
|
|---|
| 165 |
|
|---|
| 166 | //
|
|---|
| 167 | // check the num of photons against the noise level
|
|---|
| 168 | //
|
|---|
| 169 | const Float_t entry = pix.GetNumPhotons();
|
|---|
| 170 | const Float_t noise = pix.GetErrorPhot();
|
|---|
| 171 |
|
|---|
| 172 | if (entry <= fCleanLvl2 * noise )
|
|---|
| 173 | continue;
|
|---|
| 174 |
|
|---|
| 175 | //
|
|---|
| 176 | // get pixel id of this entry
|
|---|
| 177 | //
|
|---|
| 178 | const Int_t id = pix.GetPixId();
|
|---|
| 179 |
|
|---|
| 180 | //
|
|---|
| 181 | // check if the pixel's next neighbor is a core pixel.
|
|---|
| 182 | // if it is a core pixel set pixel state to: used.
|
|---|
| 183 | //
|
|---|
| 184 | MGeomPix &gpix = (*fCam)[id];
|
|---|
| 185 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 186 |
|
|---|
| 187 | for (Int_t j=0; j<nnmax; j++)
|
|---|
| 188 | {
|
|---|
| 189 | const Int_t id2 = gpix.GetNeighbor(j);
|
|---|
| 190 |
|
|---|
| 191 | if (id2 <0)
|
|---|
| 192 | continue;
|
|---|
| 193 |
|
|---|
| 194 | if (!fEvt->IsPixelCore(id2))
|
|---|
| 195 | continue;
|
|---|
| 196 |
|
|---|
| 197 | pix.SetPixelUsed();
|
|---|
| 198 |
|
|---|
| 199 | break ;
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | Bool_t MImgCleanStd::PreProcess (MParList *pList)
|
|---|
| 205 | {
|
|---|
| 206 | //
|
|---|
| 207 | // check if MEvtHeader exists in the Parameter list already.
|
|---|
| 208 | // if not create one and add them to the list
|
|---|
| 209 | //
|
|---|
| 210 | fCam = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 211 | if (!fCam)
|
|---|
| 212 | {
|
|---|
| 213 | *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
|---|
| 214 | return kFALSE;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
|
|---|
| 218 | if (!fEvt)
|
|---|
| 219 | {
|
|---|
| 220 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
|---|
| 221 | return kFALSE;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | return kTRUE;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | Bool_t MImgCleanStd::Process()
|
|---|
| 228 | {
|
|---|
| 229 | CleanStep1();
|
|---|
| 230 | CleanStep2();
|
|---|
| 231 | CleanStep3();
|
|---|
| 232 |
|
|---|
| 233 | return kTRUE;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|