source: trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc@ 8025

Last change on this file since 8025 was 7900, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.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 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): Markus Gaug, 05/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractTimeAndCharge
28//
29// Base class for the signal extractors which extract the arrival time
30// and the signal at the same time. Uses the functions
31// FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() to extract the signal and
32// substract the pedestal value.
33//
34// The following figure gives and example of possible inheritance trees.
35// An extractor class can inherit from each of the following base classes:
36// - MExtractor
37// - MExtractTime
38// - MExtractTimeAndCharge
39//
40//Begin_Html
41/*
42<img src="images/ExtractorClasses.gif">
43*/
44//End_Html
45//
46// The following variables have to be set by the derived class and
47// do not have defaults:
48// - fNumHiGainSamples
49// - fNumLoGainSamples
50// - fSqrtHiGainSamples
51// - fSqrtLoGainSamples
52//
53// Input Containers:
54// MRawEvtData
55// MRawRunHeader
56// MPedestalCam
57//
58// Output Containers:
59// MArrivalTimeCam
60// MExtractedSignalCam
61//
62//////////////////////////////////////////////////////////////////////////////
63#include "MExtractTimeAndCharge.h"
64
65#include <TRandom.h>
66
67#include "MLog.h"
68#include "MLogManip.h"
69
70#include "MParList.h"
71
72#include "MRawEvtData.h"
73#include "MRawEvtPixelIter.h"
74#include "MRawRunHeader.h"
75
76#include "MPedestalCam.h"
77#include "MPedestalPix.h"
78
79#include "MArrivalTimeCam.h"
80#include "MArrivalTimePix.h"
81
82#include "MExtractedSignalCam.h"
83#include "MExtractedSignalPix.h"
84
85ClassImp(MExtractTimeAndCharge);
86
87using namespace std;
88
89const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -3.5;
90const Byte_t MExtractTimeAndCharge::fgLoGainSwitch = 120;
91
92// --------------------------------------------------------------------------
93//
94// Default constructor.
95//
96// Sets:
97// - fLoGainFirstSave to 0
98// - fWindowSizeHiGain and fWindowSizeLoGain to 0
99// - fLoGainStartShift to fgLoGainStartShift+fgOffsetLoGain
100// - fLoGainSwitch to fgLoGainSwitch
101//
102MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
103 : fLoGainFirstSave(0), fWindowSizeHiGain(0), fWindowSizeLoGain(0)
104{
105 fName = name ? name : "MExtractTimeAndCharge";
106 fTitle = title ? title : "Base class for signal and time extractors";
107
108 SetLoGainStartShift();
109 SetLoGainSwitch();
110}
111
112// --------------------------------------------------------------------------
113//
114// The PreProcess searches for the following input containers:
115// - MRawEvtData
116// - MRawRunHeader
117// - MPedestalCam
118//
119// The following output containers are also searched and created if
120// they were not found:
121//
122// - MExtractedSignalCam
123// - MArrivalTimeCam
124//
125Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
126{
127
128 if (!MExtractTime::PreProcess(pList))
129 return kFALSE;
130
131 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
132 if (!fSignals)
133 return kFALSE;
134
135 *fLog << flush << inf;
136 return kTRUE;
137}
138
139// --------------------------------------------------------------------------
140//
141// The ReInit calls:
142// - MExtractor::ReInit()
143//
144// Call:
145// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
146// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
147// - InitArrays();
148//
149Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
150{
151
152 if (!MExtractTime::ReInit(pList))
153 return kFALSE;
154
155 if (!InitArrays())
156 return kFALSE;
157
158 if (fSignals)
159 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
160 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
161
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Calculate the integral of the FADC time slices and store them as a new
169// pixel in the MArrivalTimeCam container.
170// Calculate the integral of the FADC time slices and store them as a new
171// pixel in the MExtractedSignalCam container.
172// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are
173// supposed to extract the signal themselves.
174//
175Int_t MExtractTimeAndCharge::Process()
176{
177
178 MRawEvtPixelIter pixel(fRawEvt);
179
180 while (pixel.Next())
181 {
182 // COPY HERE PRODUCING ARRAY WITH SAMPLES
183
184 /*
185 const MPedestalPix &ped = (*fPedestals)[pixidx];
186
187 const Float_t pedes = ped.GetPedestal();
188 const Float_t ABoffs = ped.GetPedestalABoffset();
189
190 const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
191
192 const Int_t num = pixel.GetNumHiGainSamples()+pixel.GetNumLoGainSamples();
193
194 MArrayF sample(num);
195
196 const Int_t abflag = pixel.HasABFlag() ? 1 : 0;
197 const Int_t ids0 = fHiGainFirst + abflag;
198
199 Int_t ids = ids0;
200
201 Float_t null = 0; // Starting value for maxpos
202 Float_t *maxpos = &null; // Position of maximum
203 Float_t *sat1 = 0; // First saturating slice
204 Float_t *sat2 = 0; // Last saturating slice
205
206 const Float_t *beg = sample.GetArray();
207 const Float_t *end = beg + num;
208
209 Float_t *ptr = beg;
210 while (ptr<end)
211 {
212 *sample++ = (Float_t)*ptr - pedmean[ids++&0x1];
213
214 // This extraction must be done independant for lo- and hi-gain
215 // if (*ptr > *maxpos)
216 // maxpos = ptr;
217 //
218 // if (*ptr >= fSaturationLimit)
219 // {
220 // sat2 = ptr;
221 // if (!sat1)
222 // sat1 = ptr;
223 // }
224 //
225 // ptr++;
226 }
227 */
228
229 //
230 // Find signal in hi- and lo-gain
231 //
232 Float_t sumhi =0., deltasumhi =0; // Set hi-gain of MExtractedSignalPix valid
233 Float_t timehi=0., deltatimehi=0; // Set hi-gain of MArrivalTimePix valid
234 Byte_t sathi=0;
235
236 // Initialize fMaxBinContent for the case, it gets not set by the derived class
237 fMaxBinContent = fLoGainSwitch + 1;
238
239 const Int_t pixidx = pixel.GetPixelId();
240 const MPedestalPix &ped = (*fPedestals)[pixidx];
241 const Bool_t higainabflag = pixel.HasABFlag();
242
243 FindTimeAndChargeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(),
244 sumhi, deltasumhi, timehi, deltatimehi,
245 sathi, ped, higainabflag);
246
247 // Make sure that in cases the time couldn't be correctly determined
248 // more meaningfull default values are assigned
249 if (timehi<=0 || timehi>pixel.GetNumHiGainSamples())
250 timehi = gRandom->Uniform(pixel.GetNumHiGainSamples());
251
252 Float_t sumlo =0., deltasumlo =-1.; // invalidate logain of MExtractedSignalPix
253 Float_t timelo=0., deltatimelo=-1; // invalidate logain of MArrivalTimePix
254 Byte_t satlo=0;
255
256 //
257 // Adapt the low-gain extraction range from the obtained high-gain time
258 //
259
260 // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
261 // MEANS: Hi gain has saturated, but it is too early to extract
262 // the lo-gain properly
263 // THIS produces pulse positions ~= -1
264 // The signal might be handled in MCalibrateData, but hwat's about
265 // the arrival times in MCalibrateRelTime
266 if (sathi && fMaxBinContent<=fLoGainSwitch)
267 deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
268
269 // FIXME: What to do with the pixel if it saturates too early???
270 if (pixel.HasLoGain() && (fMaxBinContent > fLoGainSwitch /*|| sathi>0*/) )
271 {
272 fLoGainFirstSave = fLoGainFirst;
273
274 // sathi is the number (not index!) of the first saturating slice
275 // 0 indicates that no saturation was found
276 // FIMXME: Is 3 an accurate value?
277
278 const Float_t pos = sathi==0 ? timehi : (int)(sathi)-3;
279
280 if (pos+fLoGainStartShift>0)
281 fLoGainFirst = (Byte_t)(pos + fLoGainStartShift);
282
283 if (fLoGainFirst<fLoGainFirstSave)
284 fLoGainFirst = fLoGainFirstSave;
285
286 if (fLoGainLast-fLoGainFirst >= fWindowSizeLoGain)
287 {
288 deltasumlo = 0; // make logain of MExtractedSignalPix valid
289 deltatimelo = 0; // make logain of MArrivalTimePix valid
290
291 const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
292 FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
293 sumlo, deltasumlo, timelo, deltatimelo,
294 satlo, ped, logainabflag);
295
296 if (satlo>6)
297 deltasumlo=deltatimelo=-1;
298 }
299 fLoGainFirst = fLoGainFirstSave;
300
301 // Make sure that in cases the time couldn't be correctly determined
302 // more meaningfull default values are assigned
303 if (timelo<=0 || timelo>pixel.GetNumLoGainSamples())
304 timelo = gRandom->Uniform(pixel.GetNumLoGainSamples());
305 }
306
307 MExtractedSignalPix &pix = (*fSignals)[pixidx];
308 MArrivalTimePix &tix = (*fArrTime)[pixidx];
309 pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
310 pix.SetGainSaturation(sathi, satlo);
311
312 tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
313 tix.SetGainSaturation(sathi, satlo);
314
315 } /* while (pixel.Next()) */
316
317 fArrTime->SetReadyToSave();
318 fSignals->SetReadyToSave();
319
320 return kTRUE;
321}
322
323// --------------------------------------------------------------------------
324//
325// In addition to the resources of the base-class MExtractor:
326// MJPedestal.MExtractor.LoGainStartShift: -2.8
327//
328Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
329{
330
331 Bool_t rc = MExtractTime::ReadEnv(env, prefix, print);
332
333 if (rc)
334 SetLoGainStartShift();
335
336 if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
337 {
338 fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fgLoGainStartShift);
339 SetLoGainStartShift(fLoGainStartShift);
340 rc = kTRUE;
341 }
342
343 if (IsEnvDefined(env, prefix, "LoGainSwitch", print))
344 {
345 fLoGainSwitch = GetEnvValue(env, prefix, "LoGainSwitch", fLoGainSwitch);
346 rc = kTRUE;
347 }
348
349 return rc;
350}
351
352void MExtractTimeAndCharge::Print(Option_t *o) const
353{
354 if (IsA()==Class())
355 *fLog << GetDescriptor() << ":" << endl;
356
357 *fLog << dec;
358 *fLog << " Taking " << fWindowSizeHiGain
359 << " HiGain samples from slice " << (Int_t)fHiGainFirst
360 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
361 *fLog << " Taking " << fWindowSizeLoGain
362 << " LoGain samples from slice " << (Int_t)fLoGainFirst
363 << " to " << (Int_t)fLoGainLast << " incl" << endl;
364
365 *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
366 *fLog << " LoGainSwitch: " << (Int_t)fLoGainSwitch << endl;
367 MExtractTime::Print(o);
368}
Note: See TracBrowser for help on using the repository browser.