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 | ! Author(s): Hendrik Bartko, 02/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MExtractTimeHighestIntegral
|
---|
29 | //
|
---|
30 | // Calculates the arrival time as the mean time of the fWindowSize time slices
|
---|
31 | // which have the highest integral content.
|
---|
32 | //
|
---|
33 | //
|
---|
34 | //////////////////////////////////////////////////////////////////////////////
|
---|
35 | #include "MExtractTimeHighestIntegral.h"
|
---|
36 |
|
---|
37 | #include "MLog.h"
|
---|
38 | #include "MLogManip.h"
|
---|
39 | #include "MPedestalPix.h"
|
---|
40 |
|
---|
41 | ClassImp(MExtractTimeHighestIntegral);
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | const Byte_t MExtractTimeHighestIntegral::fgHiGainFirst = 0;
|
---|
46 | const Byte_t MExtractTimeHighestIntegral::fgHiGainLast = 14;
|
---|
47 | const Byte_t MExtractTimeHighestIntegral::fgLoGainFirst = 3;
|
---|
48 | const Byte_t MExtractTimeHighestIntegral::fgLoGainLast = 14;
|
---|
49 | const Byte_t MExtractTimeHighestIntegral::fgHiGainWindowSize = 6;
|
---|
50 | const Byte_t MExtractTimeHighestIntegral::fgLoGainWindowSize = 6;
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor.
|
---|
54 | //
|
---|
55 | // Calls:
|
---|
56 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
---|
57 | //
|
---|
58 | MExtractTimeHighestIntegral::MExtractTimeHighestIntegral(const char *name, const char *title)
|
---|
59 | : fHiGainWindowSize(fgHiGainWindowSize),
|
---|
60 | fLoGainWindowSize(fgLoGainWindowSize)
|
---|
61 | {
|
---|
62 |
|
---|
63 | fName = name ? name : "MExtractTimeHighestIntegral";
|
---|
64 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
65 |
|
---|
66 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
67 | }
|
---|
68 |
|
---|
69 | // --------------------------------------------------------------------------
|
---|
70 | //
|
---|
71 | // SetRange:
|
---|
72 | //
|
---|
73 | // Calls:
|
---|
74 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
75 | //
|
---|
76 | void MExtractTimeHighestIntegral::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
77 | {
|
---|
78 |
|
---|
79 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
80 |
|
---|
81 |
|
---|
82 | Int_t range = fHiGainLast - fHiGainFirst + 1;
|
---|
83 |
|
---|
84 | if (range < 2)
|
---|
85 | {
|
---|
86 | *fLog << warn << GetDescriptor()
|
---|
87 | << Form("%s%2i%s%2i%s",": Hi-Gain Extraction range [",(int)fHiGainFirst,","
|
---|
88 | ,fHiGainLast,"] too small, ") << endl;
|
---|
89 | *fLog << warn << GetDescriptor()
|
---|
90 | << " will move higher limit to obtain 4 slices " << endl;
|
---|
91 | SetRange(fHiGainFirst, fHiGainLast+4-range,fLoGainFirst,fLoGainLast);
|
---|
92 | }
|
---|
93 |
|
---|
94 | range = fLoGainLast - fLoGainFirst + 1;
|
---|
95 |
|
---|
96 | if (range < 2)
|
---|
97 | {
|
---|
98 | *fLog << warn << GetDescriptor()
|
---|
99 | << Form("%s%2i%s%2i%s",": Lo-Gain Extraction range [",(int)fLoGainFirst,","
|
---|
100 | ,fLoGainLast,"] too small, ") << endl;
|
---|
101 | *fLog << warn << GetDescriptor()
|
---|
102 | << " will move logher limit to obtain 4 slices " << endl;
|
---|
103 | SetRange(fHiGainFirst, fHiGainLast,fLoGainFirst,fLoGainLast+4-range);
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | SetWindowSize(fHiGainWindowSize,fLoGainWindowSize);
|
---|
108 |
|
---|
109 | fNumHiGainSamples = fHiGainLast-fHiGainFirst+1;
|
---|
110 | fNumLoGainSamples = fLoGainLast-fLoGainFirst+1;
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Checks:
|
---|
117 | // - if a window is odd, subtract one
|
---|
118 | // - if a window is bigger than the one defined by the ranges, set it to the available range
|
---|
119 | // - if a window is smaller than 2, set it to 2
|
---|
120 | //
|
---|
121 | void MExtractTimeHighestIntegral::SetWindowSize(Byte_t windowh, Byte_t windowl)
|
---|
122 | {
|
---|
123 |
|
---|
124 | fHiGainWindowSize = windowh & ~1;
|
---|
125 | fLoGainWindowSize = windowl & ~1;
|
---|
126 |
|
---|
127 | if (fHiGainWindowSize != windowh)
|
---|
128 | *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: "
|
---|
129 | << int(fHiGainWindowSize) << " samples " << endl;
|
---|
130 |
|
---|
131 | if (fLoGainWindowSize != windowl)
|
---|
132 | *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: "
|
---|
133 | << int(fLoGainWindowSize) << " samples " << endl;
|
---|
134 |
|
---|
135 | const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
|
---|
136 | const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
|
---|
137 |
|
---|
138 | if (fHiGainWindowSize > availhirange)
|
---|
139 | {
|
---|
140 | *fLog << warn << GetDescriptor()
|
---|
141 | << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",(int)fHiGainWindowSize,
|
---|
142 | " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl;
|
---|
143 | *fLog << warn << GetDescriptor()
|
---|
144 | << ": Will set window size to: " << (int)availhirange << endl;
|
---|
145 | fHiGainWindowSize = availhirange;
|
---|
146 | }
|
---|
147 |
|
---|
148 | if (fLoGainWindowSize > availlorange)
|
---|
149 | {
|
---|
150 | *fLog << warn << GetDescriptor()
|
---|
151 | << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",(int)fLoGainWindowSize,
|
---|
152 | " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl;
|
---|
153 | *fLog << warn << GetDescriptor()
|
---|
154 | << ": Will set window size to: " << (int)availlorange << endl;
|
---|
155 | fLoGainWindowSize= availlorange;
|
---|
156 | }
|
---|
157 |
|
---|
158 | fHiGainWindowSizeSqrt = TMath::Sqrt((Float_t)fHiGainWindowSize);
|
---|
159 | fLoGainWindowSizeSqrt = TMath::Sqrt((Float_t)fLoGainWindowSize);
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | void MExtractTimeHighestIntegral::FindTimeHiGain(Byte_t *ptr, Float_t &time, Float_t &deltatime, Byte_t &sat, const MPedestalPix &ped) const
|
---|
164 | {
|
---|
165 |
|
---|
166 | const Byte_t *end = ptr + fHiGainLast - fHiGainFirst +1 ;
|
---|
167 |
|
---|
168 | Int_t sum=0; // integral content of the actual window
|
---|
169 | Int_t max = 0; // highest integral content of all windows
|
---|
170 |
|
---|
171 | //
|
---|
172 | // Calculate the sum of the first fWindowSize slices
|
---|
173 | //
|
---|
174 | sat = 0;
|
---|
175 | Byte_t *p = ptr;
|
---|
176 |
|
---|
177 | while (p<ptr+fHiGainWindowSize)
|
---|
178 | {
|
---|
179 | sum += *p;
|
---|
180 | if (*p++ >= fSaturationLimit)
|
---|
181 | sat++;
|
---|
182 | }
|
---|
183 |
|
---|
184 | //
|
---|
185 | // Check for saturation in all other slices
|
---|
186 | //
|
---|
187 | while (p<end)
|
---|
188 | if (*p++ >= fSaturationLimit)
|
---|
189 | sat++;
|
---|
190 |
|
---|
191 | //
|
---|
192 | // Calculate the i-th sum as
|
---|
193 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
194 | // This is fast and accurate (because we are using int's)
|
---|
195 | //
|
---|
196 | max=sum;
|
---|
197 | Byte_t *ptrmax=ptr; // pointer to the first slice of the maximum window
|
---|
198 |
|
---|
199 | for (p=ptr; p+fHiGainWindowSize<end; p++)
|
---|
200 | {
|
---|
201 | sum += *(p+fHiGainWindowSize) - *p;
|
---|
202 |
|
---|
203 | if (sum>max)
|
---|
204 | {
|
---|
205 | max = sum;
|
---|
206 | ptrmax = p+1;
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | // now calculate the time for the maximum window
|
---|
211 | Int_t timesignalsum = 0;
|
---|
212 | Int_t timesquaredsum =0;
|
---|
213 | Int_t timesum =0;
|
---|
214 |
|
---|
215 | for (p=ptrmax; p < ptrmax + fHiGainWindowSize; p++)
|
---|
216 | {
|
---|
217 | timesignalsum += *p*(p-ptr);
|
---|
218 | timesum += p-ptr;
|
---|
219 | timesquaredsum += (p-ptr)*(p-ptr);
|
---|
220 | }
|
---|
221 |
|
---|
222 | const Float_t pedes = ped.GetPedestal();
|
---|
223 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
224 | const Float_t pedsubsum = max - fHiGainWindowSize*pedes;
|
---|
225 | const Float_t pedsubtimesignalsum = timesignalsum - timesum*pedes;
|
---|
226 |
|
---|
227 | time = pedsubsum != 0 ? pedsubtimesignalsum / pedsubsum + Float_t(fHiGainFirst): 1;
|
---|
228 | deltatime = pedsubsum != 0 ? pedrms / pedsubsum * sqrt(timesquaredsum - fHiGainWindowSize*time) : 1;
|
---|
229 | }
|
---|
230 |
|
---|
231 | void MExtractTimeHighestIntegral::FindTimeLoGain(Byte_t *ptr, Float_t &time, Float_t &deltatime, Byte_t &sat, const MPedestalPix &ped) const
|
---|
232 | {
|
---|
233 |
|
---|
234 | const Byte_t *end = ptr + fLoGainLast - fLoGainFirst +1 ;
|
---|
235 |
|
---|
236 | Int_t sum=0; // integral content of the actual window
|
---|
237 | Int_t max = 0; // highest integral content of all windows
|
---|
238 |
|
---|
239 | //
|
---|
240 | // Calculate the sum of the first fWindowSize slices
|
---|
241 | //
|
---|
242 | sat = 0;
|
---|
243 | Byte_t *p = ptr;
|
---|
244 |
|
---|
245 | while (p<ptr+fLoGainWindowSize)
|
---|
246 | {
|
---|
247 | sum += *p;
|
---|
248 | if (*p++ >= fSaturationLimit)
|
---|
249 | sat++;
|
---|
250 | }
|
---|
251 |
|
---|
252 | //
|
---|
253 | // Check for saturation in all other slices
|
---|
254 | //
|
---|
255 | while (p<end)
|
---|
256 | if (*p++ >= fSaturationLimit)
|
---|
257 | sat++;
|
---|
258 |
|
---|
259 | //
|
---|
260 | // Calculate the i-th sum as
|
---|
261 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
262 | // This is fast and accurate (because we are using int's)
|
---|
263 | //
|
---|
264 | max=sum;
|
---|
265 | Byte_t *ptrmax=ptr; // pointer to the first slice of the maximum window
|
---|
266 |
|
---|
267 | for (p=ptr; p+fLoGainWindowSize<end; p++)
|
---|
268 | {
|
---|
269 | sum += *(p+fLoGainWindowSize) - *p;
|
---|
270 |
|
---|
271 | if (sum>max)
|
---|
272 | {
|
---|
273 | max = sum;
|
---|
274 | ptrmax = p+1;
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | // now calculate the time for the maximum window
|
---|
279 | Int_t timesignalsum = 0;
|
---|
280 | Int_t timesquaredsum =0;
|
---|
281 | Int_t timesum =0;
|
---|
282 |
|
---|
283 | for (p=ptrmax; p < ptrmax + fLoGainWindowSize; p++)
|
---|
284 | {
|
---|
285 | timesignalsum += *p*(p-ptr);
|
---|
286 | timesum += p-ptr;
|
---|
287 | timesquaredsum += (p-ptr)*(p-ptr);
|
---|
288 | }
|
---|
289 |
|
---|
290 | const Float_t pedes = ped.GetPedestal();
|
---|
291 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
292 | const Float_t pedsubsum = max - fLoGainWindowSize*pedes;
|
---|
293 | const Float_t pedsubtimesignalsum = timesignalsum - timesum*pedes;
|
---|
294 |
|
---|
295 | time = pedsubsum != 0 ? pedsubtimesignalsum / pedsubsum + Float_t(fLoGainFirst) : 1;
|
---|
296 | deltatime = pedsubsum != 0 ? pedrms / pedsubsum * sqrt(timesquaredsum - fLoGainWindowSize*time) : 1;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // In addition to the resources of the base-class MExtractor:
|
---|
302 | // MJPedestal.MExtractor.WindowSizeHiGain: 6
|
---|
303 | // MJPedestal.MExtractor.WindowSizeLoGain: 6
|
---|
304 | //
|
---|
305 | Int_t MExtractTimeHighestIntegral::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
306 | {
|
---|
307 | Byte_t hw = fHiGainWindowSize;
|
---|
308 | Byte_t lw = fLoGainWindowSize;
|
---|
309 |
|
---|
310 | Bool_t rc = kFALSE;
|
---|
311 |
|
---|
312 | if (IsEnvDefined(env, prefix, "HiGainWindowSize", print))
|
---|
313 | {
|
---|
314 | hw = GetEnvValue(env, prefix, "HiGainWindowSize", hw);
|
---|
315 | rc = kTRUE;
|
---|
316 | }
|
---|
317 | if (IsEnvDefined(env, prefix, "LoGainWindowSize", print))
|
---|
318 | {
|
---|
319 | lw = GetEnvValue(env, prefix, "LoGainWindowSize", lw);
|
---|
320 | rc = kTRUE;
|
---|
321 | }
|
---|
322 |
|
---|
323 | if (rc)
|
---|
324 | SetWindowSize(hw, lw);
|
---|
325 |
|
---|
326 | return MExtractTime::ReadEnv(env, prefix, print) ? kTRUE : rc;
|
---|
327 | }
|
---|
328 |
|
---|
329 | void MExtractTimeHighestIntegral::Print(Option_t *o) const
|
---|
330 | {
|
---|
331 | *fLog << all;
|
---|
332 | *fLog << GetDescriptor() << ":" << endl;
|
---|
333 | *fLog << " Windows: Hi-Gain=" << (int)fHiGainWindowSize << " Lo-Gain=" << (int)fLoGainWindowSize << endl;
|
---|
334 | MExtractTime::Print(o);
|
---|
335 | }
|
---|