source: trunk/Mars/mimage/MImgCleanFAMOUS.cc@ 20051

Last change on this file since 20051 was 19970, checked in by tbretz, 4 years ago
Zero Signal does not contribute.
File size: 8.4 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): Thomas Bretz, 06/2020 <mailto:tbretz@physik.rwth-aachen.de>
19!
20! Copyright: MAGIC Software Development, 2000-2020
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MImgCleanFAMOUS
28//
29// This image cleaning algorithm was introduced by J. Audehm (Master
30// thesis, RWTH Aachen, 2020) based on a cleaning by M. Schaufel
31// (Master thesus, RWTH Aachen, 2017). It was slightly modified
32// to fit into the framework.
33//
34/////////////////////////////////////////////////////////////////////////////
35#include "MImgCleanFAMOUS.h"
36
37#include <TEnv.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MParList.h"
43
44#include "MGeomPix.h"
45#include "MGeomCam.h"
46
47#include "MSignalPix.h"
48#include "MSignalCam.h"
49
50ClassImp(MImgCleanFAMOUS);
51
52using namespace std;
53
54static const TString gsDefName = "MImgCleanFAMOUS";
55static const TString gsDefTitle = "Task to perform image cleaning";
56
57const TString MImgCleanFAMOUS::gsNameSignalCam ="MSignalCam"; // default name of the 'MSignalCam' container
58const TString MImgCleanFAMOUS::gsNameGeomCam ="MGeomCam"; // default name of the 'MGeomCam' container
59
60// --------------------------------------------------------------------------
61//
62// Default constructor. Here you can specify the cleaning method and levels.
63// If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
64// above mean) are used.
65// Here you can also specify how many rings around the core pixels you want
66// to analyze (with the fixed lvl2). The default value for "rings" is 1.
67//
68MImgCleanFAMOUS::MImgCleanFAMOUS(const char *name, const char *title)
69 : fSignalMin(40), fSignalMax(4000), fTimeMin(110), fTimeMax(150),
70 fSlopeMin(0), fSlopeMax(100), fTimeWindow(5),
71 fNameGeomCam(gsNameGeomCam), fNameSignalCam(gsNameSignalCam)
72{
73 fName = name ? name : gsDefName.Data();
74 fTitle = title ? title : gsDefTitle.Data();
75}
76
77void MImgCleanFAMOUS::ResetCleaning() const
78{
79 //
80 // check the number of all pixels against the noise level and
81 // set them to 'unused' state if necessary
82 //
83 const UInt_t npixevt = fEvt->GetNumPixels();
84 for (UInt_t idx=0; idx<npixevt; idx++)
85 {
86 MSignalPix &pix = (*fEvt)[idx];
87 if (pix.IsPixelUnmapped())
88 continue;
89
90 pix.SetPixelUnused();
91 pix.SetPixelCore(kFALSE);
92 pix.SetIdxIsland(-1);
93 }
94}
95
96// --------------------------------------------------------------------------
97//
98void MImgCleanFAMOUS::FindIsland(Int_t idx) const
99{
100 // Get the pixel information of a pixel with this index
101 MSignalPix &pix = (*fEvt)[idx];
102 if (!pix.IsPixelUsed())
103 return;
104
105 // Get geometrical description of pixel idx
106 const MGeom &gpix = (*fCam)[idx];
107
108 // Now do the same with all its neighbors and sum the
109 // sizes which they correspond to
110 const Int_t n = gpix.GetNumNeighbors();
111
112 for (int i=0; i<n; i++)
113 {
114 // Index of neighbor pixel
115 const UInt_t ipix = gpix.GetNeighbor(i);
116
117 // Signal of neighbor pixel
118 const MSignalPix &npix = (*fEvt)[ipix];
119
120 if (TMath::Abs(npix.GetArrivalTime()-pix.GetArrivalTime())>=fTimeWindow)
121 continue;
122
123 if (npix.GetNumPhotons()<=0)
124 continue;
125
126 // FIXME: Checks on minimum signal and slope parameter?
127
128 if (npix.IsPixelUnmapped())
129 continue;
130
131 pix.SetPixelUsed();
132 pix.SetIdxIsland(1);
133
134 FindIsland(ipix);
135 }
136}
137
138
139void MImgCleanFAMOUS::DoCleaning() const
140{
141 UInt_t max_idx = -1;
142
143 // Serach for the brightest none-saturating pixel
144 // that is consistent with originating form a shower
145 const UInt_t npixevt = fEvt->GetNumPixels();
146 for (UInt_t idx=0; idx<npixevt; idx++)
147 {
148 MSignalPix &pix = (*fEvt)[idx];
149
150 // Check that the slopd of the rising edge looks reasonable
151 if (pix.GetTimeSlope() <= fSlopeMin || pix.GetTimeSlope()>fSlopeMax)
152 continue;
153
154 // Check that pixel aligns with the trigger position
155 if (pix.GetArrivalTime() <= fTimeMin || pix.GetArrivalTime()>fTimeMax)
156 continue;
157
158 // Check if this is above the cleaning level and not saturating
159 if (pix.GetNumPhotons() <= fSignalMin || pix.GetNumPhotons()>fSignalMax)
160 continue;
161
162 // Ignore unmapped pixels
163 if (pix.IsPixelUnmapped())
164 continue;
165
166 pix.SetPixelCore();
167
168 if (max_idx<0 || pix.GetNumPhotons()>(*fEvt)[max_idx].GetNumPhotons())
169 max_idx = idx;
170 }
171
172 if (max_idx<0)
173 return;
174
175 (*fEvt)[max_idx].SetPixelUsed();
176 FindIsland(max_idx);
177}
178
179// --------------------------------------------------------------------------
180//
181// Check if MEvtHeader exists in the Parameter list already.
182// if not create one and add them to the list
183//
184Int_t MImgCleanFAMOUS::PreProcess(MParList *pList)
185{
186 fCam = (MGeomCam*)pList->FindObject(AddSerialNumber(fNameGeomCam), "MGeomCam");
187 if (!fCam)
188 {
189 *fLog << err << fNameGeomCam << " [MGeomCam] not found (no geometry information available)... aborting." << endl;
190 return kFALSE;
191 }
192 fEvt = (MSignalCam*)pList->FindObject(AddSerialNumber(fNameSignalCam), "MSignalCam");
193 if (!fEvt)
194 {
195 *fLog << err << fNameSignalCam << " [MSignalCam] not found... aborting." << endl;
196 return kFALSE;
197 }
198
199 Print();
200
201 return kTRUE;
202}
203
204// --------------------------------------------------------------------------
205//
206// Cleans the image.
207//
208Int_t MImgCleanFAMOUS::Process()
209{
210 ResetCleaning();
211 DoCleaning();
212
213 // Takes roughly 10% of the time
214 fEvt->CalcIslands(*fCam);
215
216 return kTRUE;
217}
218
219// --------------------------------------------------------------------------
220//
221// Print descriptor and cleaning levels.
222//
223void MImgCleanFAMOUS::Print(Option_t *o) const
224{
225 *fLog << all << GetDescriptor() << " using" << endl;
226 *fLog << " * " << fSignalMin << " < Signal <= " << fSignalMax << endl;
227 *fLog << " * " << fTimeMin << " < Time <= " << fTimeMax << endl;
228 *fLog << " * " << fSlopeMin << " < Slope <= " << fSlopeMax << endl;
229 *fLog << " * " << "Delta T < " << fTimeWindow << endl;
230}
231
232// --------------------------------------------------------------------------
233//
234// Read the setup from a TEnv, eg:
235// MImgCleanFAMOUS.SignalMin: 40
236// MImgCleanFAMOUS.SignalMax: 4000
237// MImgCleanFAMOUS.TimeMin: 110
238// MImgCleanFAMOUS.TimeMax: 150
239// MImgCleanFAMOUS.SlopeMin: 0
240// MImgCleanFAMOUS.SlopeMax: 100
241// MImgCleanFAMOUS.TimeWindow: 5
242//
243Int_t MImgCleanFAMOUS::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
244{
245 Bool_t rc = kFALSE;
246 if (IsEnvDefined(env, prefix, "SignalMin", print))
247 {
248 rc = kTRUE;
249 fSignalMin = GetEnvValue(env, prefix, "SignalMin", fSignalMin);
250 }
251 if (IsEnvDefined(env, prefix, "SignalMax", print))
252 {
253 rc = kTRUE;
254 fSignalMax = GetEnvValue(env, prefix, "SignalMax", fSignalMax);
255 }
256 if (IsEnvDefined(env, prefix, "TimeMin", print))
257 {
258 rc = kTRUE;
259 fTimeMin = GetEnvValue(env, prefix, "TimeMin", fTimeMin);
260 }
261 if (IsEnvDefined(env, prefix, "TimeMax", print))
262 {
263 rc = kTRUE;
264 fTimeMax = GetEnvValue(env, prefix, "TimeMax", fTimeMax);
265 }
266 if (IsEnvDefined(env, prefix, "SlopeMin", print))
267 {
268 rc = kTRUE;
269 fSlopeMin = GetEnvValue(env, prefix, "SlopeMin", fSlopeMin);
270 }
271 if (IsEnvDefined(env, prefix, "SlopeMax", print))
272 {
273 rc = kTRUE;
274 fSlopeMax = GetEnvValue(env, prefix, "SlopeMax", fSlopeMax);
275 }
276 if (IsEnvDefined(env, prefix, "TimeWindow", print))
277 {
278 rc = kTRUE;
279 fTimeWindow = GetEnvValue(env, prefix, "TimeWindow", fTimeWindow);
280 }
281
282 return rc;
283}
Note: See TracBrowser for help on using the repository browser.