source: trunk/Mars/msignal/MExtractTimeSpline.cc@ 19007

Last change on this file since 19007 was 3899, checked in by gaug, 21 years ago
*** empty log message ***
File size: 5.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): Sebastian Raducci 12/2003 <mailto:raducci@fisica.uniud.it>
18! Markus Gaug 04/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2002-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractTimeSpline
28//
29// This is a task that calculates the arrival times of photons.
30// It returns the absolute maximum of the spline that interpolates
31// the FADC slices
32//
33//
34//////////////////////////////////////////////////////////////////////////////
35#include "MExtractTimeSpline.h"
36#include "MCubicSpline.h"
37
38#include "MGeomCam.h"
39#include "MPedestalPix.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44
45ClassImp(MExtractTimeSpline);
46
47using namespace std;
48
49const Byte_t MExtractTimeSpline::fgHiGainFirst = 0;
50const Byte_t MExtractTimeSpline::fgHiGainLast = 14;
51const Byte_t MExtractTimeSpline::fgLoGainFirst = 3;
52const Byte_t MExtractTimeSpline::fgLoGainLast = 14;
53// --------------------------------------------------------------------------
54//
55// Default constructor.
56//
57// Calls:
58// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
59//
60MExtractTimeSpline::MExtractTimeSpline(const char *name, const char *title)
61 : fXHiGain(NULL), fXLoGain(NULL)
62{
63
64 fName = name ? name : "MExtractTimeSpline";
65 fTitle = title ? title : "Calculate photons arrival time using a spline";
66
67 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
68
69}
70
71MExtractTimeSpline::~MExtractTimeSpline()
72{
73
74 if (fXHiGain)
75 delete fXHiGain;
76 if (fXLoGain)
77 delete fXLoGain;
78
79}
80
81
82// --------------------------------------------------------------------------
83//
84// SetRange:
85//
86// Calls:
87// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
88// - Deletes x, if not NULL
89// - Creates x according to the range
90//
91void MExtractTimeSpline::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
92{
93
94 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
95
96 if (fXHiGain)
97 delete fXHiGain;
98
99 if (fXLoGain)
100 delete fXLoGain;
101
102 Int_t range = fHiGainLast - fHiGainFirst + 1;
103
104 if (range < 2)
105 {
106 *fLog << warn << GetDescriptor()
107 << Form("%s%2i%s%2i%s",": Hi-Gain Extraction range [",(int)fHiGainFirst,","
108 ,fHiGainLast,"] too small, ") << endl;
109 *fLog << warn << GetDescriptor()
110 << " will move higher limit to obtain 4 slices " << endl;
111 SetRange(fHiGainFirst, fHiGainLast+4-range,fLoGainFirst,fLoGainLast);
112 range = fHiGainLast - fHiGainFirst + 1;
113 }
114
115 fXHiGain = new Byte_t[range+1];
116 for (Int_t i=0; i<range+1; i++)
117 fXHiGain[i] = i;
118
119 range = fLoGainLast - fLoGainFirst + 1;
120
121 if (range >= 2)
122 {
123
124 fXLoGain = new Byte_t[range+1];
125 for (Int_t i=0; i<range+1; i++)
126 fXLoGain[i] = i;
127 }
128}
129
130
131// --------------------------------------------------------------------------
132//
133// Calculates the arrival time for each pixel
134//
135void MExtractTimeSpline::FindTimeHiGain(Byte_t *first, Float_t &time, Float_t &dtime,
136 Byte_t &sat, const MPedestalPix &ped) const
137{
138
139 const Int_t range = fHiGainLast - fHiGainFirst + 1;
140 const Byte_t *end = first + range;
141 Byte_t *p = first;
142
143 //
144 // Check for saturation in all other slices
145 //
146 while (p<end)
147 if (*p++ >= fSaturationLimit)
148 sat++;
149
150 //
151 // Initialize the spline
152 //
153 MCubicSpline spline(first,fXHiGain,kTRUE,range,0.0,0.0);
154
155 //
156 // Now find the maximum
157 //
158 Double_t abMaximum = spline.EvalAbMax();
159 Double_t maximum = spline.EvalMax();
160 const Double_t pedestal = ped.GetPedestal();
161 const Double_t halfMax = (maximum + pedestal)/2.;
162 time = (halfMax > pedestal) ? (Float_t ) spline.FindVal(halfMax,abMaximum,'l') + (Float_t)fHiGainFirst : 0.0;
163}
164
165// --------------------------------------------------------------------------
166//
167// Calculates the arrival time for each pixel
168//
169void MExtractTimeSpline::FindTimeLoGain(Byte_t *first, Float_t &time, Float_t &dtime,
170 Byte_t &sat, const MPedestalPix &ped) const
171{
172
173 const Int_t range = fLoGainLast - fLoGainFirst + 1;
174
175 if (range < 2)
176 return;
177
178 const Byte_t *end = first + range;
179 Byte_t *p = first;
180
181 //
182 // Check for saturation in all other slices
183 //
184 while (p<end)
185 if (*p++ >= fSaturationLimit)
186 sat++;
187
188 //
189 // Initialize the spline
190 //
191 MCubicSpline spline(first,fXLoGain,kTRUE,range,0.0,0.0);
192
193 //
194 // Now find the maximum
195 //
196 Double_t abMaximum = spline.EvalAbMax();
197 Double_t maximum = spline.EvalMax();
198 const Double_t pedestal = ped.GetPedestal();
199 const Double_t halfMax = (maximum + pedestal)/2.;
200
201 time = (halfMax > pedestal) ? (Float_t )spline.FindVal(halfMax,abMaximum,'l') + (Float_t)fLoGainFirst : 0.0;
202}
203
Note: See TracBrowser for help on using the repository browser.