1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.58 2006-11-01 15:48:31 tbretz Exp $
|
---|
3 | ! --------------------------------------------------------------------------
|
---|
4 | !
|
---|
5 | ! *
|
---|
6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | ! *
|
---|
11 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
12 | ! * documentation for any purpose is hereby granted without fee,
|
---|
13 | ! * provided that the above copyright notice appear in all copies and
|
---|
14 | ! * that both that copyright notice and this permission notice appear
|
---|
15 | ! * in supporting documentation. It is provided "as is" without express
|
---|
16 | ! * or implied warranty.
|
---|
17 | ! *
|
---|
18 | !
|
---|
19 | !
|
---|
20 | ! Author(s): Markus Gaug, 05/2004 <mailto:markus@ifae.es>
|
---|
21 | ! Author(s): Thomas Bretz, 05/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
22 | !
|
---|
23 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
24 | !
|
---|
25 | !
|
---|
26 | \* ======================================================================== */
|
---|
27 |
|
---|
28 | //////////////////////////////////////////////////////////////////////////////
|
---|
29 | //
|
---|
30 | // MExtractTimeAndCharge
|
---|
31 | //
|
---|
32 | // Base class for the signal extractors which extract the arrival time
|
---|
33 | // and the signal at the same time. Uses the functions
|
---|
34 | // FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() to extract the signal and
|
---|
35 | // substract the pedestal value.
|
---|
36 | //
|
---|
37 | // The following figure gives and example of possible inheritance trees.
|
---|
38 | // An extractor class can inherit from each of the following base classes:
|
---|
39 | // - MExtractor
|
---|
40 | // - MExtractTime
|
---|
41 | // - MExtractTimeAndCharge
|
---|
42 | //
|
---|
43 | //Begin_Html
|
---|
44 | /*
|
---|
45 | <img src="images/ExtractorClasses.gif">
|
---|
46 | */
|
---|
47 | //End_Html
|
---|
48 | //
|
---|
49 | // The following variables have to be set by the derived class and
|
---|
50 | // do not have defaults:
|
---|
51 | // - fNumHiGainSamples
|
---|
52 | // - fNumLoGainSamples
|
---|
53 | // - fSqrtHiGainSamples
|
---|
54 | // - fSqrtLoGainSamples
|
---|
55 | //
|
---|
56 | // Input Containers:
|
---|
57 | // MRawEvtData
|
---|
58 | // MRawRunHeader
|
---|
59 | // MPedestalCam
|
---|
60 | //
|
---|
61 | // Output Containers:
|
---|
62 | // MArrivalTimeCam
|
---|
63 | // MExtractedSignalCam
|
---|
64 | //
|
---|
65 | // For weired events check: Run 94127 Event 672, 1028
|
---|
66 | //
|
---|
67 | //////////////////////////////////////////////////////////////////////////////
|
---|
68 | #include "MExtractTimeAndCharge.h"
|
---|
69 |
|
---|
70 | #include <TRandom.h>
|
---|
71 | #include <TVector3.h>
|
---|
72 |
|
---|
73 | #include "MMath.h"
|
---|
74 |
|
---|
75 | #include "MLog.h"
|
---|
76 | #include "MLogManip.h"
|
---|
77 |
|
---|
78 | #include "MParList.h"
|
---|
79 |
|
---|
80 | #include "MRawEvtPixelIter.h"
|
---|
81 | #include "MRawRunHeader.h"
|
---|
82 |
|
---|
83 | #include "MArrivalTimeCam.h"
|
---|
84 | #include "MArrivalTimePix.h"
|
---|
85 |
|
---|
86 | #include "MExtractedSignalCam.h"
|
---|
87 | #include "MExtractedSignalPix.h"
|
---|
88 |
|
---|
89 | #include "MPedestalSubtractedEvt.h"
|
---|
90 |
|
---|
91 | ClassImp(MExtractTimeAndCharge);
|
---|
92 |
|
---|
93 | using namespace std;
|
---|
94 |
|
---|
95 | const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.5;
|
---|
96 | const Byte_t MExtractTimeAndCharge::fgLoGainSwitch = 120;
|
---|
97 |
|
---|
98 | // --------------------------------------------------------------------------
|
---|
99 | //
|
---|
100 | // Default constructor.
|
---|
101 | //
|
---|
102 | // Sets:
|
---|
103 | // - fWindowSizeHiGain and fWindowSizeLoGain to 0
|
---|
104 | // - fLoGainStartShift to fgLoGainStartShift
|
---|
105 | // - fLoGainSwitch to fgLoGainSwitch
|
---|
106 | //
|
---|
107 | MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
|
---|
108 | : fWindowSizeHiGain(0), fWindowSizeLoGain(0)
|
---|
109 | {
|
---|
110 | fName = name ? name : "MExtractTimeAndCharge";
|
---|
111 | fTitle = title ? title : "Base class for signal and time extractors";
|
---|
112 |
|
---|
113 | SetLoGainStartShift();
|
---|
114 | SetLoGainSwitch();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // --------------------------------------------------------------------------
|
---|
118 | //
|
---|
119 | // The PreProcess searches for the following input containers:
|
---|
120 | // - MRawEvtData
|
---|
121 | // - MRawRunHeader
|
---|
122 | // - MPedestalCam
|
---|
123 | //
|
---|
124 | // The following output containers are also searched and created if
|
---|
125 | // they were not found:
|
---|
126 | //
|
---|
127 | // - MExtractedSignalCam
|
---|
128 | // - MArrivalTimeCam
|
---|
129 | //
|
---|
130 | Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
|
---|
131 | {
|
---|
132 | if (!MExtractTime::PreProcess(pList))
|
---|
133 | return kFALSE;
|
---|
134 |
|
---|
135 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
|
---|
136 | if (!fSignals)
|
---|
137 | return kFALSE;
|
---|
138 |
|
---|
139 | *fLog << flush << inf;
|
---|
140 | return kTRUE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | // --------------------------------------------------------------------------
|
---|
144 | //
|
---|
145 | // The ReInit calls:
|
---|
146 | // - MExtractor::ReInit()
|
---|
147 | //
|
---|
148 | // Call:
|
---|
149 | // - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
150 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
151 | // - InitArrays();
|
---|
152 | //
|
---|
153 | Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
|
---|
154 | {
|
---|
155 | if (!MExtractTime::ReInit(pList))
|
---|
156 | return kFALSE;
|
---|
157 |
|
---|
158 | if (!InitArrays(fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain()))
|
---|
159 | return kFALSE;
|
---|
160 |
|
---|
161 | if (fSignals)
|
---|
162 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
163 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
164 | return kTRUE;
|
---|
165 | }
|
---|
166 |
|
---|
167 | // --------------------------------------------------------------------------
|
---|
168 | //
|
---|
169 | // Return the x-value lower than sat0 at which the signal has been
|
---|
170 | // fallen bwlow maxcont/2. This time is determined using a simple second
|
---|
171 | // order polynomial interpolation.
|
---|
172 | //
|
---|
173 | Double_t MExtractTimeAndCharge::GetSaturationTime(Int_t sat0, const Float_t *sig, Int_t maxcont) const
|
---|
174 | {
|
---|
175 | const Int_t p = sat0>1 ? sat0-2 : sat0-1;
|
---|
176 | if (sat0<=0)
|
---|
177 | return 0;
|
---|
178 |
|
---|
179 | // Find the place at which the signal is maxcont/2
|
---|
180 | const TVector3 vx(sig[p], sig[p+1], sig[p+2]);
|
---|
181 | const TVector3 vy(p, p+1, p+2);
|
---|
182 |
|
---|
183 | return MMath::InterpolParabLin(vx, vy, maxcont/2);
|
---|
184 | }
|
---|
185 |
|
---|
186 | // --------------------------------------------------------------------------
|
---|
187 | //
|
---|
188 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
189 | // pixel in the MArrivalTimeCam container.
|
---|
190 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
191 | // pixel in the MExtractedSignalCam container.
|
---|
192 | // The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are
|
---|
193 | // supposed to extract the signal themselves.
|
---|
194 | //
|
---|
195 | Int_t MExtractTimeAndCharge::Process()
|
---|
196 | {
|
---|
197 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
198 |
|
---|
199 | while (pixel.Next())
|
---|
200 | {
|
---|
201 | const Int_t pixidx = pixel.GetPixelId();
|
---|
202 |
|
---|
203 | const Float_t *sig = fSignal->GetSamples(pixidx);
|
---|
204 |
|
---|
205 | const Int_t numh = pixel.GetNumHiGainSamples();
|
---|
206 |
|
---|
207 | Int_t sathi0 = fHiGainFirst; // First slice to extract and first saturating slice
|
---|
208 | Int_t sathi1 = fHiGainLast; // Last slice to extract and last saturating slice
|
---|
209 |
|
---|
210 | Int_t maxcont;
|
---|
211 | Int_t maxposhi = fSignal->GetMax(pixidx, sathi0, sathi1, maxcont);
|
---|
212 | // Would it be better to take lastsat-firstsat?
|
---|
213 | Int_t numsathi = fSignal->GetSaturation(pixidx, fSaturationLimit, sathi0, sathi1);
|
---|
214 |
|
---|
215 | Float_t sumhi =0., deltasumhi =-1; // Set hi-gain of MExtractedSignalPix valid
|
---|
216 | Float_t timehi=0., deltatimehi=-1; // Set hi-gain of MArrivalTimePix valid
|
---|
217 |
|
---|
218 | // Do not even try to extract the hi-gain if we have
|
---|
219 | // more than one saturating slice
|
---|
220 | const Int_t rangehi = fHiGainLast - fHiGainFirst + 1;
|
---|
221 |
|
---|
222 | if (numsathi<2)
|
---|
223 | FindTimeAndChargeHiGain2(sig+fHiGainFirst, rangehi,
|
---|
224 | sumhi, deltasumhi, timehi, deltatimehi,
|
---|
225 | numsathi, maxposhi);
|
---|
226 |
|
---|
227 | // If we have saturating slices try to get a better estimate
|
---|
228 | // of the arrival time than timehi or sathi0. This is
|
---|
229 | // usefull to know where to start lo-gain extraction.
|
---|
230 | if (numsathi>1)
|
---|
231 | {
|
---|
232 | timehi = GetSaturationTime(sathi0, sig, maxcont)-fHiGainFirst;
|
---|
233 | deltatimehi = 0;
|
---|
234 | }
|
---|
235 |
|
---|
236 | // Make sure that in cases the time couldn't be correctly determined
|
---|
237 | // more meaningfull default values are assigned.
|
---|
238 | // For extractors like the digital filter and the spline
|
---|
239 | // we allow extracpolation by one slice.
|
---|
240 | if (deltatimehi>-0.5 && (timehi<-1 || timehi>=rangehi))
|
---|
241 | {
|
---|
242 | // Flag this as unreliable!
|
---|
243 | timehi = gRandom->Uniform(rangehi+1)-1;
|
---|
244 | // deltatimehi=-1;
|
---|
245 | }
|
---|
246 |
|
---|
247 | timehi += fHiGainFirst;
|
---|
248 |
|
---|
249 | Float_t sumlo =0, deltasumlo =-1; // invalidate logain of MExtractedSignalPix
|
---|
250 | Float_t timelo=0, deltatimelo=-1; // invalidate logain of MArrivalTimePix
|
---|
251 | Int_t numsatlo=0;
|
---|
252 |
|
---|
253 | //
|
---|
254 | // Adapt the low-gain extraction range from the obtained high-gain time
|
---|
255 | //
|
---|
256 |
|
---|
257 | // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
|
---|
258 | // MEANS: Hi gain has saturated, but the signal is to dim
|
---|
259 | // to extract the lo-gain properly
|
---|
260 | // This could happen because the maxcont was not extracted from
|
---|
261 | // all slices!
|
---|
262 | // THIS produces pulse positions ~= -1
|
---|
263 | // The signal might be handled in MCalibrateData, but hwat's about
|
---|
264 | // the arrival times in MCalibrateRelTime
|
---|
265 | if (numsathi>0 && maxcont<=fLoGainSwitch)
|
---|
266 | deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
|
---|
267 |
|
---|
268 | // If more than 8 hi-gain slices have saturated this is
|
---|
269 | // no physical event. We just assume that something with
|
---|
270 | // the extraction is wrong
|
---|
271 | if (numsathi>8) // FIXME: Should be something like 2?
|
---|
272 | deltasumhi=deltatimehi=-1;
|
---|
273 |
|
---|
274 | // FIXME: What to do with the pixel if it saturates too early???
|
---|
275 | if (pixel.HasLoGain() && maxcont>fLoGainSwitch)
|
---|
276 | {
|
---|
277 | Int_t first = numh+fLoGainFirst;
|
---|
278 | Int_t last = numh+fLoGainLast;
|
---|
279 |
|
---|
280 | // To determin the window in which the lo-gain is extracted
|
---|
281 | // clearly more information about the relation between the
|
---|
282 | // extraction window and the reslting time is necessary.
|
---|
283 | //
|
---|
284 | // numh + fLoGainStartShift == 14 / fLoGainStartShift=-1
|
---|
285 | //
|
---|
286 | // The lo-gain is expected to have its raising edge
|
---|
287 | // at timehi+numh+fOffsetLoGain. We start to search for the
|
---|
288 | // lo-gain fLoGainStartShift slices earlier.
|
---|
289 | //
|
---|
290 | // Instead of fLoGainStartShift the extractor should now how many
|
---|
291 | // slices before the expected raising edge the start of the
|
---|
292 | // search must be placed and from there we can step 1.5 slices
|
---|
293 | // back to be on the safe side.
|
---|
294 | //
|
---|
295 | // The jitter in the hi-/lo-gain offset ssems to be around +/-0.5
|
---|
296 | if (deltatimehi>-0.5)
|
---|
297 | first = TMath::FloorNint(timehi+numh+fOffsetLoGain+fLoGainStartShift);
|
---|
298 | //else ???
|
---|
299 |
|
---|
300 | if (first<0)
|
---|
301 | first = 0;
|
---|
302 | if (first>last)
|
---|
303 | first=last;
|
---|
304 |
|
---|
305 | /*
|
---|
306 | // Currently we have to stick to this check because at least
|
---|
307 | // the spline has arrays of this size...
|
---|
308 | if (first>last)
|
---|
309 | first = last;
|
---|
310 | if (first<numh+fLoGainFirst)
|
---|
311 | first = numh+fLoGainFirst;
|
---|
312 | */
|
---|
313 | Int_t satlo0 = first; // First slice to extract and first saturating slice
|
---|
314 | Int_t satlo1 = last; // Last slice to extract and last saturating slice
|
---|
315 |
|
---|
316 | // Would it be better to take lastsat-firstsat?
|
---|
317 | Int_t maxlo;
|
---|
318 | Int_t maxposlo = fSignal->GetMax(pixidx, satlo0, satlo1, maxlo);
|
---|
319 | numsatlo = fSignal->GetSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
|
---|
320 |
|
---|
321 | const Int_t rangelo = last-first+1;
|
---|
322 | FindTimeAndChargeLoGain2(sig+first, rangelo,
|
---|
323 | sumlo, deltasumlo, timelo, deltatimelo,
|
---|
324 | numsatlo, maxposlo);
|
---|
325 |
|
---|
326 | // If we have saturating slices try to get a better estimate
|
---|
327 | // of the arrival time than timehi or sathi0. This is
|
---|
328 | // usefull to know where to start lo-gain extraction.
|
---|
329 | if (numsatlo>1)
|
---|
330 | {
|
---|
331 | timelo = GetSaturationTime(satlo0, sig, maxlo)-numh-first;
|
---|
332 | deltatimelo = 0;
|
---|
333 | }
|
---|
334 |
|
---|
335 | // Make sure that in cases the time couldn't be correctly determined
|
---|
336 | // more meaningfull default values are assigned
|
---|
337 | // For extractors like the digital filter and the spline
|
---|
338 | // we allow extracpolation by one slice.
|
---|
339 | if (deltatimelo>-0.5 && (timelo<-1 || timelo>=rangelo))
|
---|
340 | {
|
---|
341 | // Flag this as unreliable!
|
---|
342 | timelo = gRandom->Uniform(rangelo+1)-1;
|
---|
343 | //deltatimelo=-1;
|
---|
344 | }
|
---|
345 |
|
---|
346 | timelo += first-numh;
|
---|
347 |
|
---|
348 | // If more than 6 lo-gain slices have saturated this is
|
---|
349 | // no physical event. We just assume that something with
|
---|
350 | // the extraction is wrong
|
---|
351 | if (numsatlo>6)
|
---|
352 | deltasumlo=deltatimelo=-1;
|
---|
353 |
|
---|
354 | //if (TMath::Abs(timelo-fOffsetLoGain - timehi)>1.0)
|
---|
355 | // deltatimelo = -1;
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | // Now store the result in the corresponding containers
|
---|
360 | MExtractedSignalPix &pix = (*fSignals)[pixidx];
|
---|
361 | MArrivalTimePix &tix = (*fArrTime)[pixidx];
|
---|
362 | pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
|
---|
363 | pix.SetGainSaturation(numsathi, numsatlo);
|
---|
364 |
|
---|
365 | tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
|
---|
366 | tix.SetGainSaturation(numsathi, numsatlo);
|
---|
367 | } /* while (pixel.Next()) */
|
---|
368 |
|
---|
369 | fArrTime->SetReadyToSave();
|
---|
370 | fSignals->SetReadyToSave();
|
---|
371 |
|
---|
372 | return kTRUE;
|
---|
373 | }
|
---|
374 |
|
---|
375 | // --------------------------------------------------------------------------
|
---|
376 | //
|
---|
377 | // In addition to the resources of the base-class MExtractor:
|
---|
378 | // MJPedestal.MExtractor.LoGainStartShift: -2.8
|
---|
379 | //
|
---|
380 | Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
381 | {
|
---|
382 | Bool_t rc = MExtractTime::ReadEnv(env, prefix, print);
|
---|
383 |
|
---|
384 | if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
|
---|
385 | {
|
---|
386 | fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fgLoGainStartShift);
|
---|
387 | SetLoGainStartShift(fLoGainStartShift);
|
---|
388 | rc = kTRUE;
|
---|
389 | }
|
---|
390 |
|
---|
391 | if (IsEnvDefined(env, prefix, "LoGainSwitch", print))
|
---|
392 | {
|
---|
393 | fLoGainSwitch = GetEnvValue(env, prefix, "LoGainSwitch", fLoGainSwitch);
|
---|
394 | rc = kTRUE;
|
---|
395 | }
|
---|
396 |
|
---|
397 | return rc;
|
---|
398 | }
|
---|
399 |
|
---|
400 | void MExtractTimeAndCharge::Print(Option_t *o) const
|
---|
401 | {
|
---|
402 | MExtractTime::Print(o);
|
---|
403 |
|
---|
404 | *fLog << dec;
|
---|
405 | *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
|
---|
406 | *fLog << " LoGainSwitch: " << (Int_t)fLoGainSwitch << endl;
|
---|
407 | }
|
---|