source: branches/MarsGapdTimeJitter/msignal/MExtractFACT.cc@ 18159

Last change on this file since 18159 was 17835, checked in by tbretz, 11 years ago
First working version.
File size: 7.6 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, 2014 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2014
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractFACT
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractFACT.h"
31
32#include <algorithm>
33
34#include <TRandom.h>
35
36#include "MLog.h"
37#include "MLogManip.h"
38
39#include "MParList.h"
40
41#include "MRawRunHeader.h"
42
43#include "MArrivalTimeCam.h"
44#include "MArrivalTimePix.h"
45
46#include "MExtractedSignalCam.h"
47#include "MExtractedSignalPix.h"
48
49#include "MPedestalSubtractedEvt.h"
50
51ClassImp(MExtractFACT);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default constructor.
58//
59// Sets:
60// - fWindowSizeHiGain and fWindowSizeLoGain to 0
61// - fLoGainStartShift to fgLoGainStartShift
62// - fLoGainSwitch to fgLoGainSwitch
63//
64MExtractFACT::MExtractFACT(const char *name, const char *title)
65{
66 fName = name ? name : "MExtractFACT";
67 fTitle = title ? title : "Base class for signal and time extractors";
68}
69
70// --------------------------------------------------------------------------
71//
72// The PreProcess searches for the following input containers:
73// - MRawEvtData
74// - MRawRunHeader
75// - MPedestalCam
76//
77// The following output containers are also searched and created if
78// they were not found:
79//
80// - MExtractedSignalCam
81// - MArrivalTimeCam
82//
83Int_t MExtractFACT::PreProcess(MParList *pList)
84{
85 if (!MExtractTime::PreProcess(pList))
86 return kFALSE;
87
88 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
89 if (!fSignals)
90 return kFALSE;
91
92 *fLog << flush << inf;
93 return kTRUE;
94}
95
96// --------------------------------------------------------------------------
97//
98// The ReInit calls:
99// - MExtractor::ReInit()
100//
101// Call:
102// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
103// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
104// - InitArrays();
105//
106Bool_t MExtractFACT::ReInit(MParList *pList)
107{
108 if (!MExtractTime::ReInit(pList))
109 return kFALSE;
110
111 //if (fSignals)
112 // fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
113 // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
114
115 return kTRUE;
116}
117
118// --------------------------------------------------------------------------
119//
120// Calculate the integral of the FADC time slices and store them as a new
121// pixel in the MArrivalTimeCam container.
122// Calculate the integral of the FADC time slices and store them as a new
123// pixel in the MExtractedSignalCam container.
124// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are
125// supposed to extract the signal themselves.
126//
127Int_t MExtractFACT::Process()
128{
129 // FIXME: Check ranges
130 //const UInt_t nroi = fSignal->GetNumSamples();
131 const UInt_t npix = fSignal->GetNumPixels();
132
133 const UInt_t rangehi = fHiGainLast - fHiGainFirst - 1;
134
135 for (UInt_t ch=0; ch<npix; ch++)
136 {
137 const Float_t *ptr = fSignal->GetSamples(ch);
138
139 const Float_t *pbeg = ptr+fHiGainFirst+1;
140 const Float_t *pend = ptr+fHiGainLast-1;
141
142 // Find maximum
143 const Float_t *pmax = pbeg;
144
145 if (!IsNoiseCalculation())
146 {
147 for (const Float_t *p=pbeg; p<pend; p++)
148 if (*p>*pmax)
149 pmax = p;
150 }
151
152 //Float_t max = *pmax;
153
154 // -------------------------------------------------------------------------
155 // Calculate a parabola through this and the surrounding points
156 // on logarithmic values (that's a gaussian)
157 //
158 // Quadratic interpolation
159 //
160 // calculate the parameters of a parabula such that
161 // y(i) = a + b*x(i) + c*x(i)^2
162 // y'(i) = b + 2*c*x(i)
163 //
164 // y = exp( - (x-k)^2 / s^2 / 2 )
165 //
166 // -2*s^2 * log(y) = x^2 - 2*k*x + k^2
167 //
168 // a = (k/s0)^2/2
169 // b = k/s^2
170 // c = -1/(2s^2) --> s = sqrt(-1/2c)
171 //
172 Float_t max = -1;
173 if (pmax>pbeg && pmax<pend-1)
174 {
175 const Float_t &v1 = pmax[-1];
176 const Float_t &v2 = pmax[ 0];
177 const Float_t &v3 = pmax[+1];
178 if (v1>0 && v2>0 && v3>0)
179 {
180 const double y1 = log(v1);
181 const double y2 = log(v2);
182 const double y3 = log(v3);
183
184 const double a = y2;
185 const double b = (y3-y1)/2;
186 const double c = (y1+y3)/2 - y2;
187 if (c<0)
188 {
189 const double w = -1./(2*c);
190 const double dx = b*w;
191
192 if (dx>=-1 && dx<=1)
193 {
194 max = exp(a + b*dx + c*dx*dx);
195
196 // Time is position of maximum
197 //time = dx;
198 //time += Int_t(pmax-ptr);
199 }
200 }
201 }
202 }
203
204 Float_t time = -1;
205 if (max>=0)
206 {
207 // -10: maximum search window
208
209 // Time is position of half hight leading edge
210 pend = std::max(pbeg, pmax-10);
211 for (;pmax>=pend; pmax--)
212 if (*pmax<max/2)
213 break;
214
215 if (pmax>pend && pmax[0]!=pmax[1])
216 {
217 time = (max/2-pmax[0])/(pmax[1]-pmax[0]);
218 time += Int_t(pmax-ptr);
219 }
220 }
221
222 if (time<0)
223 {
224 time = gRandom->Uniform(rangehi)+fHiGainFirst+1;
225 max = pbeg[uint16_t(time)];
226 }
227
228 // Now store the result in the corresponding containers
229 MExtractedSignalPix &pix = (*fSignals)[ch];
230 MArrivalTimePix &tix = (*fArrTime)[ch];
231 pix.SetExtractedSignal(max);
232 pix.SetGainSaturation(0);
233
234 tix.SetArrivalTime(time);
235 tix.SetGainSaturation(0);
236 }
237
238 fArrTime->SetReadyToSave();
239 fSignals->SetReadyToSave();
240
241 return kTRUE;
242}
243
244// --------------------------------------------------------------------------
245//
246// In addition to the resources of the base-class MExtractor:
247// MJPedestal.MExtractor.LoGainStartShift: -2.8
248//
249Int_t MExtractFACT::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
250{
251 Bool_t rc = MExtractTime::ReadEnv(env, prefix, print);
252 /*
253 if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
254 {
255 fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fgLoGainStartShift);
256 SetLoGainStartShift(fLoGainStartShift);
257 rc = kTRUE;
258 }
259
260 if (IsEnvDefined(env, prefix, "LoGainSwitch", print))
261 {
262 fLoGainSwitch = GetEnvValue(env, prefix, "LoGainSwitch", (Int_t)fLoGainSwitch);
263 rc = kTRUE;
264 }
265 */
266 return rc;
267}
268
Note: See TracBrowser for help on using the repository browser.