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

Last change on this file since 1013 was 1003, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): 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/////////////////////////////////////////////////////////////////////////////
27// //
28// MImgCleanStd //
29// //
30// This is the standard image cleaning. If you want to know how it works //
31// Please look at the three CleanSteps and Process //
32// //
33// FIXME: MImgCleanStd is rather slow at the moment because it loops //
34// unnecessarily over all pixels in all its loops (s.MHillas) //
35// The speed could be improved very much by using Hash-Tables //
36// (linked lists, see THashTable and THashList, too) //
37// //
38// Input Containers: //
39// MGeomCam, MCerPhotEvt //
40// //
41// Output Containers: //
42// -/- //
43// //
44/////////////////////////////////////////////////////////////////////////////
45#include "MImgCleanStd.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51#include "MGeomPix.h"
52#include "MGeomCam.h"
53#include "MCerPhotPix.h"
54#include "MCerPhotEvt.h"
55
56ClassImp(MImgCleanStd);
57
58// --------------------------------------------------------------------------
59//
60// Default constructor. Here you can specify the cleaning levels. If you
61// don't specify them the 'common standard' values 2.5 and 3.0 (sigma
62// above mean) are used
63//
64MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
65 const char *name, const char *title)
66 : fCleanLvl1(lvl1), fCleanLvl2(lvl2)
67{
68 fName = name ? name : "MImgCleanStd";
69 fTitle = title ? title : "Task which does a standard image cleaning";
70
71 *fLog << "Cleaning initialized. Using noise level " << lvl1 << " and " << lvl2 << endl;
72}
73
74// --------------------------------------------------------------------------
75//
76// This method looks for all pixels with an entry (photons)
77// that is three times bigger than the noise of the pixel
78// (std: 3 sigma, clean level 1)
79//
80void MImgCleanStd::CleanStep1()
81{
82 const Int_t entries = fEvt->GetNumPixels();
83
84 //
85 // check the number of all pixels against the noise level and
86 // set them to 'unused' state if necessary
87 //
88 for (Int_t i=0; i<entries; i++ )
89 {
90 MCerPhotPix &pix = (*fEvt)[i];
91
92 const Float_t entry = pix.GetNumPhotons();
93 const Float_t noise = pix.GetErrorPhot();
94
95 // COBB: '<=' to skip entry=noise=0
96 if (entry <= fCleanLvl1 * noise )
97 pix.SetPixelUnused();
98 }
99}
100
101// --------------------------------------------------------------------------
102//
103// check if the survived pixel have a neighbor, that also
104// survived
105//
106void MImgCleanStd::CleanStep2()
107{
108 const Int_t entries = fEvt->GetNumPixels();
109
110 for (Int_t i=0; i<entries; i++)
111 {
112 //
113 // get entry i from list
114 //
115 MCerPhotPix &pix = (*fEvt)[i];
116
117 //
118 // check if pixel is in use, if not goto next pixel in list
119 //
120 if (!pix.IsPixelUsed())
121 continue;
122
123 //
124 // get pixel id of this entry
125 //
126 const Int_t id = pix.GetPixId();
127
128 //
129 // count number of next neighbors of this pixel which
130 // state is 'used'
131 //
132 const MGeomPix &gpix = (*fCam)[id];
133 const Int_t nnmax = gpix.GetNumNeighbors();
134
135 Int_t cnt = 0;
136 for (Int_t j=0; j<nnmax; j++)
137 {
138 const Int_t id2 = gpix.GetNeighbor(j); //GetNN(id, in) ;
139
140 if (id2 < 0)
141 continue;
142
143 if (fEvt->IsPixelUsed(id2))
144 cnt++;
145 }
146
147 //
148 // check if no next neighbor has the state 'used'
149 // set this pixel to 'unused', too.
150 //
151 if (cnt==0)
152 pix.SetPixelUnused();
153 }
154
155 //
156 // now we declare all pixels that survive as CorePixels
157 //
158 for (Int_t i=0; i<entries; i++)
159 {
160 MCerPhotPix &pix = (*fEvt)[i];
161
162 if (pix.IsPixelUsed())
163 pix.SetCorePixel();
164 }
165}
166
167// --------------------------------------------------------------------------
168//
169// Look for the boundary pixels around the core pixels
170// if a pixel has more than 2.5 (clean level 2) sigma, and
171// a core neigbor it is declared as used.
172//
173void MImgCleanStd::CleanStep3()
174{
175 const Int_t entries = fEvt->GetNumPixels();
176
177 for (Int_t i=0; i<entries; i++)
178 {
179 //
180 // get pixel as entry il from list
181 //
182 MCerPhotPix &pix = (*fEvt)[i];
183
184 //
185 // if pixel is a core pixel go to the next pixel
186 //
187 if (pix.IsCorePixel())
188 continue;
189
190 //
191 // check the num of photons against the noise level
192 //
193 const Float_t entry = pix.GetNumPhotons();
194 const Float_t noise = pix.GetErrorPhot();
195
196 if (entry <= fCleanLvl2 * noise )
197 continue;
198
199 //
200 // get pixel id of this entry
201 //
202 const Int_t id = pix.GetPixId();
203
204 //
205 // check if the pixel's next neighbor is a core pixel.
206 // if it is a core pixel set pixel state to: used.
207 //
208 MGeomPix &gpix = (*fCam)[id];
209 const Int_t nnmax = gpix.GetNumNeighbors();
210
211 for (Int_t j=0; j<nnmax; j++)
212 {
213 const Int_t id2 = gpix.GetNeighbor(j);
214
215 if (id2 <0)
216 continue;
217
218 if (!fEvt->IsPixelCore(id2))
219 continue;
220
221 pix.SetPixelUsed();
222
223 break ;
224 }
225 }
226}
227
228// --------------------------------------------------------------------------
229//
230// check if MEvtHeader exists in the Parameter list already.
231// if not create one and add them to the list
232//
233Bool_t MImgCleanStd::PreProcess (MParList *pList)
234{
235 fCam = (MGeomCam*)pList->FindObject("MGeomCam");
236 if (!fCam)
237 {
238 *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
239 return kFALSE;
240 }
241
242 fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
243 if (!fEvt)
244 {
245 *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
246 return kFALSE;
247 }
248
249 return kTRUE;
250}
251
252// --------------------------------------------------------------------------
253//
254// Cleans the image.
255//
256Bool_t MImgCleanStd::Process()
257{
258 CleanStep1();
259 CleanStep2();
260 CleanStep3();
261
262 return kTRUE;
263}
264
Note: See TracBrowser for help on using the repository browser.