source: trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.cc@ 4644

Last change on this file since 4644 was 4449, checked in by gaug, 20 years ago
*** empty log message ***
File size: 10.5 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 analyzing 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! Author(s): Markus Gaug 05/2004 <mailto:markus@ifae.es>
18!
19! Copyright: MAGIC Software Development, 2002-2004
20!
21!
22\* ======================================================================== */
23
24//////////////////////////////////////////////////////////////////////////////
25//
26// MExtractTimeAndChargeSpline
27//
28// Fast Spline extractor using a cubic spline algorithm of Numerical Recipes.
29// It returns the integral below the interpolating spline.
30//
31// Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
32// to modify the ranges. Ranges have to be an even number. In case of odd
33// ranges, the last slice will be reduced by one.
34//
35// Defaults are:
36//
37// fHiGainFirst = fgHiGainFirst = 3
38// fHiGainLast = fgHiGainLast = 14
39// fLoGainFirst = fgLoGainFirst = 3
40// fLoGainLast = fgLoGainLast = 14
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MExtractFixedWindowSpline.h"
44
45#include "MExtractedSignalCam.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50ClassImp(MExtractFixedWindowSpline);
51
52using namespace std;
53
54const Byte_t MExtractFixedWindowSpline::fgHiGainFirst = 2;
55const Byte_t MExtractFixedWindowSpline::fgHiGainLast = 14;
56const Byte_t MExtractFixedWindowSpline::fgLoGainFirst = 3;
57const Byte_t MExtractFixedWindowSpline::fgLoGainLast = 14;
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62// Calls:
63// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
64//
65MExtractFixedWindowSpline::MExtractFixedWindowSpline(const char *name, const char *title)
66 : fHiGainFirstDeriv(NULL), fLoGainFirstDeriv(NULL),
67 fHiGainSecondDeriv(NULL), fLoGainSecondDeriv(NULL)
68{
69
70 fName = name ? name : "MExtractFixedWindowSpline";
71 fTitle = title ? title : "Signal Extractor for a fixed FADC window using a fast spline";
72
73 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
74}
75
76MExtractFixedWindowSpline::~MExtractFixedWindowSpline()
77{
78
79 if (fHiGainFirstDeriv)
80 delete [] fHiGainFirstDeriv;
81 if (fLoGainFirstDeriv)
82 delete [] fLoGainFirstDeriv;
83 if (fHiGainSecondDeriv)
84 delete [] fHiGainSecondDeriv;
85 if (fLoGainSecondDeriv)
86 delete [] fLoGainSecondDeriv;
87
88}
89
90// --------------------------------------------------------------------------
91//
92// SetRange:
93//
94// Checks:
95// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
96// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
97// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
98// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
99//
100// Calls:
101// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
102//
103// Sets:
104// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
105// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
106// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
107// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
108//
109void MExtractFixedWindowSpline::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
110{
111
112 const Byte_t windowhi = hilast-hifirst+1;
113 const Byte_t windowlo = lolast-lofirst+1;
114
115 const Byte_t whieven = windowhi & ~1;
116 const Byte_t wloeven = windowlo & ~1;
117
118 if (whieven != windowhi)
119 {
120 *fLog << warn << GetDescriptor()
121 << Form("%s%2i%s%2i",": Hi Gain window size has to be even, set last slice from "
122 ,(int)hilast," to ",(int)(hilast-1)) << endl;
123 hilast -= 1;
124 }
125
126 if (wloeven != windowlo)
127 {
128 *fLog << warn << GetDescriptor()
129 << Form("%s%2i%s%2i",": Lo Gain window size has to be even, set last slice from "
130 ,(int)lolast," to ",(int)(lolast-1)) << endl;
131 lolast -= 1;
132 }
133
134 if (whieven<2)
135 {
136 *fLog << warn << GetDescriptor()
137 << Form("%s%2i%s%2i",": Hi Gain window is smaller than 2 FADC sampes, set last slice from"
138 ,(int)hilast," to ",(int)(hifirst+1)) << endl;
139 hilast = hifirst+1;
140 }
141
142 if (wloeven<2)
143 {
144 *fLog << warn << GetDescriptor()
145 << Form("%s%2i%s%2i",": Lo Gain window is smaller than 2 FADC sampes, set last slice from"
146 ,(int)lolast," to ",(int)(lofirst+1)) << endl;
147 lolast = lofirst+1;
148 }
149
150
151 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
152
153 //
154 // Very important: Because the spline interpolates between the slice,
155 // the number of samples for the pedestal subtraction
156 // is now 1 less than with e.g. MExtractFixedWindow
157 //
158 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst);
159 fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst);
160
161 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
162 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
163
164}
165
166// --------------------------------------------------------------------------
167//
168// ReInit
169//
170// Calls:
171// - MExtractor::ReInit(pList);
172// - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
173// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
174//
175// Deletes all arrays, if not NULL
176// Creates new arrays according to the extraction range
177//
178Bool_t MExtractFixedWindowSpline::ReInit(MParList *pList)
179{
180
181 if (!MExtractor::ReInit(pList))
182 return kFALSE;
183
184 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
185 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
186
187 if (fHiGainFirstDeriv)
188 delete [] fHiGainFirstDeriv;
189 if (fLoGainFirstDeriv)
190 delete [] fLoGainFirstDeriv;
191 if (fHiGainSecondDeriv)
192 delete [] fHiGainSecondDeriv;
193 if (fLoGainSecondDeriv)
194 delete [] fLoGainSecondDeriv;
195
196 Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
197
198 fHiGainFirstDeriv = new Float_t[range];
199 memset(fHiGainFirstDeriv,0,range*sizeof(Float_t));
200 fHiGainSecondDeriv = new Float_t[range];
201 memset(fHiGainSecondDeriv,0,range*sizeof(Float_t));
202
203 range = fLoGainLast - fLoGainFirst + 1;
204
205 fLoGainFirstDeriv = new Float_t[range];
206 memset(fLoGainFirstDeriv,0,range*sizeof(Float_t));
207 fLoGainSecondDeriv = new Float_t[range];
208 memset(fLoGainSecondDeriv,0,range*sizeof(Float_t));
209
210 return kTRUE;
211}
212
213
214// --------------------------------------------------------------------------
215//
216// FindSignalHiGain:
217//
218// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
219// - Sum up contents of *ptr
220// - If *ptr is greater than fSaturationLimit, raise sat by 1
221//
222// - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
223// - Sum up contents of logain
224// - If *logain is greater than fSaturationLimit, raise sat by 1
225//
226void MExtractFixedWindowSpline::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
227{
228
229 const Byte_t *end = ptr + fHiGainLast - fHiGainFirst;
230 Int_t range = fHiGainLast - fHiGainFirst + fHiLoLast + 1;
231
232 Float_t pp;
233 Int_t i = 0;
234
235 Int_t summ = 0;
236 sum = (Float_t)*ptr++/2.;
237 //
238 // Check for saturation in all other slices
239 //
240 while (ptr<end)
241 {
242
243 summ += *ptr;
244 i++;
245
246 pp = fHiGainSecondDeriv[i-1] + 4.;
247 fHiGainSecondDeriv[i] = -1.0/pp;
248 fHiGainFirstDeriv [i] = *(ptr+1) - 2.* *(ptr) + *(ptr-1);
249 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
250
251 if (*ptr++ >= fSaturationLimit)
252 sat++;
253 }
254
255 if (*ptr++ >= fSaturationLimit)
256 sat++;
257
258 if (fHiLoLast == 0)
259 {
260 sum += (Float_t)*ptr/2.;
261 fHiGainSecondDeriv[++i] = 0.;
262
263 }
264 else
265 {
266 summ += *ptr;
267 i++;
268
269 pp = fHiGainSecondDeriv[i-1] + 4.;
270 fHiGainSecondDeriv[i] = -1.0/pp;
271 fHiGainFirstDeriv [i] = *(logain) - 2.* *(ptr) + *(ptr-1);
272 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
273
274 end = logain + fHiLoLast - 1;
275
276 while (logain<end)
277 {
278
279 summ += *logain;
280 i++;
281
282 pp = fHiGainSecondDeriv[i-1] + 4.;
283 fHiGainSecondDeriv[i] = -1.0/pp;
284 fHiGainFirstDeriv [i] = *(logain+1) - 2.* *(logain) + *(ptr-1);
285 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
286
287 if (*logain++ >= fSaturationLimit)
288 sat++;
289
290 }
291 sum += (Float_t)*logain/2;
292 fHiGainSecondDeriv[++i] = 0.;
293 }
294
295 for (Int_t k=range-2;k>0;k--)
296 {
297 fHiGainSecondDeriv[k] = fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k];
298 sum += 0.25*fHiGainSecondDeriv[k];
299 }
300
301 sum += (Float_t)summ;
302}
303
304// --------------------------------------------------------------------------
305//
306// FindSignalLoGain:
307//
308// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
309// - Sum up contents of *ptr
310// - If *ptr is greater than fSaturationLimit, raise sat by 1
311//
312void MExtractFixedWindowSpline::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
313{
314
315 const Byte_t *end = ptr + fLoGainLast - fLoGainFirst;
316 Int_t range = fLoGainLast - fLoGainFirst + 1;
317
318 Float_t pp;
319 Int_t i = 0;
320
321 fLoGainSecondDeriv[0] = 0.;
322 fLoGainFirstDeriv[0] = 0.;
323
324 Int_t summ = 0;
325 sum = (Float_t)*ptr++/2.;
326 //
327 // Check for saturation in all other slices
328 //
329 while (ptr<end)
330 {
331
332 summ += *ptr;
333 i++;
334
335 pp = fLoGainSecondDeriv[i-1] + 4.;
336 fLoGainSecondDeriv[i] = -1.0/pp;
337 fLoGainFirstDeriv [i] = *(ptr+1) - 2.* *(ptr) + *(ptr-1);
338 fLoGainFirstDeriv [i] = (6.0*fLoGainFirstDeriv[i]-fLoGainFirstDeriv[i-1])/pp;
339
340 if (*ptr++ >= fSaturationLimit)
341 sat++;
342 }
343
344 if (*ptr++ >= fSaturationLimit)
345 sat++;
346
347 sum += (Float_t)*ptr/2.;
348 fLoGainSecondDeriv[++i] = 0.;
349
350 for (Int_t k=range-2;k>0;k--)
351 {
352 fLoGainSecondDeriv[k] = fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k];
353 sum += 0.25*fLoGainSecondDeriv[k];
354 }
355
356 sum += (Float_t)summ;
357}
358
Note: See TracBrowser for help on using the repository browser.