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, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
20 | ! Markus Gaug , 04/2004 <mailto:markus@ifae.es>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | //////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MExtractSlidingWindow
|
---|
30 | //
|
---|
31 | // Extracts the signal from a sliding window of size fHiGainWindowSize and
|
---|
32 | // fLoGainWindowSize. The signal is the one which maximizes the integral
|
---|
33 | // contents.
|
---|
34 | //
|
---|
35 | // Call: SetRange(higainfirst, higainlast, logainfirst, logainlast)
|
---|
36 | // to modify the ranges in which the window is allowed to move.
|
---|
37 | // Defaults are:
|
---|
38 | //
|
---|
39 | // fHiGainFirst = fgHiGainFirst = 0
|
---|
40 | // fHiGainLast = fgHiGainLast = 14
|
---|
41 | // fLoGainFirst = fgLoGainFirst = 3
|
---|
42 | // fLoGainLast = fgLoGainLast = 14
|
---|
43 | //
|
---|
44 | // Call: SetWindowSize(windowhigain, windowlogain)
|
---|
45 | // to modify the sliding window widths. Windows have to be an even number.
|
---|
46 | // In case of odd numbers, the window will be modified.
|
---|
47 | //
|
---|
48 | // Defaults are:
|
---|
49 | //
|
---|
50 | // fHiGainWindowSize = fgHiGainWindowSize = 6
|
---|
51 | // fLoGainWindowSize = fgLoGainWindowSize = 6
|
---|
52 | //
|
---|
53 | //////////////////////////////////////////////////////////////////////////////
|
---|
54 | #include "MExtractSlidingWindow.h"
|
---|
55 | #include "MExtractor.h"
|
---|
56 |
|
---|
57 | #include "MLog.h"
|
---|
58 | #include "MLogManip.h"
|
---|
59 |
|
---|
60 | #include "MExtractedSignalCam.h"
|
---|
61 |
|
---|
62 | ClassImp(MExtractSlidingWindow);
|
---|
63 |
|
---|
64 | using namespace std;
|
---|
65 |
|
---|
66 | const Byte_t MExtractSlidingWindow::fgHiGainFirst = 0;
|
---|
67 | const Byte_t MExtractSlidingWindow::fgHiGainLast = 14;
|
---|
68 | const Byte_t MExtractSlidingWindow::fgLoGainFirst = 3;
|
---|
69 | const Byte_t MExtractSlidingWindow::fgLoGainLast = 14;
|
---|
70 | const Byte_t MExtractSlidingWindow::fgHiGainWindowSize = 6;
|
---|
71 | const Byte_t MExtractSlidingWindow::fgLoGainWindowSize = 6;
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // Default constructor.
|
---|
75 | //
|
---|
76 | // Sets:
|
---|
77 | // - fWindowSizeHiGain to fgHiGainWindowSize
|
---|
78 | // - fWindowSizeLoGain to fgLoGainWindowSize
|
---|
79 | //
|
---|
80 | // Calls:
|
---|
81 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
---|
82 | //
|
---|
83 | MExtractSlidingWindow::MExtractSlidingWindow(const char *name, const char *title)
|
---|
84 | : fWindowSizeHiGain(fgHiGainWindowSize),
|
---|
85 | fWindowSizeLoGain(fgLoGainWindowSize)
|
---|
86 | {
|
---|
87 |
|
---|
88 | fName = name ? name : "MExtractSlidingWindow";
|
---|
89 | fTitle = title ? title : "Signal Extractor for a sliding FADC window";
|
---|
90 |
|
---|
91 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // SetRange:
|
---|
97 | //
|
---|
98 | // Calls:
|
---|
99 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
100 | // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
---|
101 | //
|
---|
102 | void MExtractSlidingWindow::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
103 | {
|
---|
104 |
|
---|
105 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
106 |
|
---|
107 | //
|
---|
108 | // Redo the checks if the window is still inside the ranges
|
---|
109 | //
|
---|
110 |
|
---|
111 | SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | // --------------------------------------------------------------------------
|
---|
117 | //
|
---|
118 | // The ReInit calls:
|
---|
119 | // - MExtractor::ReInit()
|
---|
120 | // - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
|
---|
121 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
122 | //
|
---|
123 | Bool_t MExtractSlidingWindow::ReInit(MParList *pList)
|
---|
124 | {
|
---|
125 |
|
---|
126 | MExtractor::ReInit(pList);
|
---|
127 |
|
---|
128 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
|
---|
129 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
130 |
|
---|
131 | return kTRUE;
|
---|
132 |
|
---|
133 | }
|
---|
134 |
|
---|
135 | // --------------------------------------------------------------------------
|
---|
136 | //
|
---|
137 | // Checks:
|
---|
138 | // - if a window is odd, subtract one
|
---|
139 | // - if a window is bigger than the one defined by the ranges, set it to the available range
|
---|
140 | // - if a window is smaller than 2, set it to 2
|
---|
141 | //
|
---|
142 | // Sets:
|
---|
143 | // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
|
---|
144 | // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
|
---|
145 | // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
|
---|
146 | // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
|
---|
147 | //
|
---|
148 | void MExtractSlidingWindow::SetWindowSize(Byte_t windowh, Byte_t windowl)
|
---|
149 | {
|
---|
150 |
|
---|
151 | fWindowSizeHiGain = windowh & ~1;
|
---|
152 | fWindowSizeLoGain = windowl & ~1;
|
---|
153 |
|
---|
154 | if (fWindowSizeHiGain != windowh)
|
---|
155 | *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: "
|
---|
156 | << int(fWindowSizeHiGain) << " samples " << endl;
|
---|
157 |
|
---|
158 | if (fWindowSizeLoGain != windowl)
|
---|
159 | *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: "
|
---|
160 | << int(fWindowSizeLoGain) << " samples " << endl;
|
---|
161 |
|
---|
162 | const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
|
---|
163 | const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
|
---|
164 |
|
---|
165 | if (fWindowSizeHiGain > availhirange)
|
---|
166 | {
|
---|
167 | *fLog << warn << GetDescriptor()
|
---|
168 | << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",(int)fWindowSizeHiGain,
|
---|
169 | " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl;
|
---|
170 | *fLog << warn << GetDescriptor()
|
---|
171 | << ": Will set window size to: " << (int)availhirange << endl;
|
---|
172 | fWindowSizeHiGain = availhirange;
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (fWindowSizeLoGain > availlorange)
|
---|
176 | {
|
---|
177 | *fLog << warn << GetDescriptor()
|
---|
178 | << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",(int)fWindowSizeLoGain,
|
---|
179 | " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl;
|
---|
180 | *fLog << warn << GetDescriptor()
|
---|
181 | << ": Will set window size to: " << (int)availlorange << endl;
|
---|
182 | fWindowSizeLoGain = availlorange;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (fWindowSizeHiGain<2)
|
---|
186 | {
|
---|
187 | fWindowSizeHiGain = 2;
|
---|
188 | *fLog << warn << GetDescriptor() << ": Hi Gain window size set to two samples" << endl;
|
---|
189 | }
|
---|
190 |
|
---|
191 | if (fWindowSizeLoGain<2)
|
---|
192 | {
|
---|
193 | fWindowSizeLoGain = 2;
|
---|
194 | *fLog << warn << GetDescriptor() << ": Lo Gain window size set to two samples" << endl;
|
---|
195 | }
|
---|
196 |
|
---|
197 | fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
|
---|
198 | fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
|
---|
199 |
|
---|
200 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
201 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
202 |
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | // --------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // FindSignalHiGain:
|
---|
209 | //
|
---|
210 | // - Loop from ptr to (ptr+fWindowSizeHiGain)
|
---|
211 | // - Sum up contents of *ptr
|
---|
212 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
213 | // - Loop from (ptr+fWindowSizeHiGain) to (ptr+fHiGainLast-fHiGainFirst)
|
---|
214 | // - Sum the content of *(ptr+fWindowSizeHiGain) and subtract *ptr
|
---|
215 | // - Check if the sum has become bigger and store it in case yes.
|
---|
216 | //
|
---|
217 | void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &max, Byte_t &sat) const
|
---|
218 | {
|
---|
219 | const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
|
---|
220 |
|
---|
221 | Int_t sum=0;
|
---|
222 | Int_t sumtot =0;
|
---|
223 |
|
---|
224 | //
|
---|
225 | // Calculate the sum of the first fWindowSize slices
|
---|
226 | //
|
---|
227 | sat = 0;
|
---|
228 | Byte_t *p = ptr;
|
---|
229 |
|
---|
230 | while (p<ptr+fWindowSizeHiGain-fHiLoLast)
|
---|
231 | {
|
---|
232 | sum += *p;
|
---|
233 | if (*p++ >= fSaturationLimit)
|
---|
234 | sat++;
|
---|
235 | }
|
---|
236 |
|
---|
237 | //
|
---|
238 | // Check for saturation in all other slices
|
---|
239 | //
|
---|
240 | while (p<end)
|
---|
241 | if (*p++ >= fSaturationLimit)
|
---|
242 | sat++;
|
---|
243 |
|
---|
244 | //
|
---|
245 | // If part of the "low-Gain" slices are used,
|
---|
246 | // repeat steps one and two for the logain part until fHiLoLast
|
---|
247 | //
|
---|
248 | Byte_t *l = logain;
|
---|
249 | while (l<logain+fHiLoLast)
|
---|
250 | {
|
---|
251 | sum += *l;
|
---|
252 | if (*l++ >= fSaturationLimit)
|
---|
253 | sat++;
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | //
|
---|
258 | // Calculate the i-th sum as
|
---|
259 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
260 | // This is fast and accurate (because we are using int's)
|
---|
261 | //
|
---|
262 | sumtot=sum;
|
---|
263 | for (p=ptr; p+fWindowSizeHiGain-fHiLoLast<end; p++)
|
---|
264 | {
|
---|
265 | sum += *(p+fWindowSizeHiGain-fHiLoLast) - *p;
|
---|
266 | if (sum>sumtot)
|
---|
267 | sumtot = sum;
|
---|
268 | }
|
---|
269 |
|
---|
270 | for (l=logain; l<logain+fHiLoLast; l++)
|
---|
271 | {
|
---|
272 | sum += *l - *p++;
|
---|
273 | if (sum>sumtot)
|
---|
274 | sumtot = sum;
|
---|
275 | }
|
---|
276 | max = (Float_t)sumtot;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | // --------------------------------------------------------------------------
|
---|
281 | //
|
---|
282 | // FindSignalLoGain:
|
---|
283 | //
|
---|
284 | // - Loop from ptr to (ptr+fWindowSizeLoGain)
|
---|
285 | // - Sum up contents of *ptr
|
---|
286 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
287 | // - Loop from (ptr+fWindowSizeLoGain) to (ptr+fLoGainLast-fLoGainFirst)
|
---|
288 | // - Sum the content of *(ptr+fWindowSizeLoGain) and subtract *ptr
|
---|
289 | // - Check if the sum has become bigger and store it in case yes.
|
---|
290 | //
|
---|
291 | void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Float_t &max, Byte_t &sat) const
|
---|
292 | {
|
---|
293 | const Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
|
---|
294 |
|
---|
295 | Int_t sum=0;
|
---|
296 | Int_t sumtot=0;
|
---|
297 | //
|
---|
298 | // Calculate the sum of the first fWindowSize slices
|
---|
299 | //
|
---|
300 | sat = 0;
|
---|
301 | Byte_t *p = ptr;
|
---|
302 | while (p<ptr+fWindowSizeLoGain)
|
---|
303 | {
|
---|
304 | sum += *p;
|
---|
305 | if (*p++ >= fSaturationLimit)
|
---|
306 | sat++;
|
---|
307 | }
|
---|
308 |
|
---|
309 | //
|
---|
310 | // Check for saturation in all other slices
|
---|
311 | //
|
---|
312 | while (p<end)
|
---|
313 | if (*p++ >= fSaturationLimit)
|
---|
314 | sat++;
|
---|
315 |
|
---|
316 | //
|
---|
317 | // Calculate the i-th sum as
|
---|
318 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
319 | // This is fast and accurate (because we are using int's)
|
---|
320 | //
|
---|
321 | sumtot=sum;
|
---|
322 | for (p=ptr; p+fWindowSizeLoGain<end; p++)
|
---|
323 | {
|
---|
324 | sum += *(p+fWindowSizeLoGain) - *p;
|
---|
325 | if (sum>sumtot)
|
---|
326 | sumtot = sum;
|
---|
327 | }
|
---|
328 | max = (Float_t)sumtot;
|
---|
329 | }
|
---|
330 |
|
---|
331 |
|
---|