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

Last change on this file since 5744 was 5734, checked in by gaug, 20 years ago
*** empty log message ***
File size: 9.0 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 "MLog.h"
66#include "MLogManip.h"
67
68#include "MParList.h"
69
70#include "MRawEvtData.h"
71#include "MRawEvtPixelIter.h"
72#include "MRawRunHeader.h"
73
74#include "MPedestalCam.h"
75#include "MPedestalPix.h"
76
77#include "MArrivalTimeCam.h"
78#include "MArrivalTimePix.h"
79
80#include "MExtractedSignalCam.h"
81#include "MExtractedSignalPix.h"
82
83ClassImp(MExtractTimeAndCharge);
84
85using namespace std;
86
87const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.8;
88
89// --------------------------------------------------------------------------
90//
91// Default constructor.
92//
93// Sets:
94// - fLoGainFirstSave to 0
95// - fWindowSizeHiGain and fWindowSizeLoGain to 0
96// - fLoGainStartShift to fgLoGainStartShift+fgOffsetLoGain
97//
98MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
99 : fLoGainFirstSave(0), fWindowSizeHiGain(0), fWindowSizeLoGain(0)
100{
101 fName = name ? name : "MExtractTimeAndCharge";
102 fTitle = title ? title : "Base class for signal and time extractors";
103
104 SetLoGainStartShift();
105}
106
107// --------------------------------------------------------------------------
108//
109// The PreProcess searches for the following input containers:
110// - MRawEvtData
111// - MRawRunHeader
112// - MPedestalCam
113//
114// The following output containers are also searched and created if
115// they were not found:
116//
117// - MExtractedSignalCam
118// - MArrivalTimeCam
119//
120Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
121{
122
123 if (!MExtractTime::PreProcess(pList))
124 return kFALSE;
125
126 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
127 if (!fSignals)
128 return kFALSE;
129
130 *fLog << flush << inf;
131 Print();
132
133 return kTRUE;
134}
135
136// --------------------------------------------------------------------------
137//
138// The ReInit calls:
139// - MExtractor::ReInit()
140//
141// Call:
142// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
143// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
144// - InitArrays();
145//
146Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
147{
148
149 if (!MExtractTime::ReInit(pList))
150 return kFALSE;
151
152 if (!InitArrays())
153 return kFALSE;
154
155 if (fSignals)
156 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
157 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
158
159 return kTRUE;
160}
161
162// --------------------------------------------------------------------------
163//
164// Calculate the integral of the FADC time slices and store them as a new
165// pixel in the MArrivalTimeCam container.
166// Calculate the integral of the FADC time slices and store them as a new
167// pixel in the MExtractedSignalCam container.
168// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain are
169// supposed to extract the signal themselves.
170//
171Int_t MExtractTimeAndCharge::Process()
172{
173 // This cleaning is nor necessary: It is done automatically by
174 // Reset() before each execution of the Tasklist (Process())
175 // fArrTime->Clear();
176 // fSignals->Clear();
177
178 MRawEvtPixelIter pixel(fRawEvt);
179
180 while (pixel.Next())
181 {
182 //
183 // Find signal in hi- and lo-gain
184 //
185 Float_t sumhi =0., deltasumhi =0; // Set hi-gain of MExtractedSignalPix valid
186 Float_t timehi=0., deltatimehi=0; // Set hi-gain of MArrivalTimePix valid
187 Byte_t sathi=0;
188
189 const Int_t pixidx = pixel.GetPixelId();
190 const MPedestalPix &ped = (*fPedestals)[pixidx];
191 const Bool_t higainabflag = pixel.HasABFlag();
192
193 FindTimeAndChargeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(),
194 sumhi, deltasumhi,
195 timehi, deltatimehi,
196 sathi, ped, higainabflag);
197
198 // Make sure that in cases the time couldn't be correctly determined
199 // more meaningfull default values are assigned
200 if (timehi<0)
201 timehi = -1;
202 if (timehi>pixel.GetNumHiGainSamples())
203 timehi = pixel.GetNumHiGainSamples();
204
205 Float_t sumlo =0., deltasumlo =-1.; // invalidate logain of MExtractedSignalPix
206 Float_t timelo=0., deltatimelo=-1; // invalidate logain of MArrivalTimePix
207 Byte_t satlo=0;
208
209 //
210 // Adapt the low-gain extraction range from the obtained high-gain time
211 //
212 if (pixel.HasLoGain())
213 {
214 deltasumlo = 0; // make logain of MExtractedSignalPix valid
215 deltatimelo = 0; // make logain of MArrivalTimePix valid
216
217 fLoGainFirstSave = fLoGainFirst;
218 const Byte_t logainstart = (Byte_t)(timehi+fLoGainStartShift);
219 if (!sathi)
220 fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
221
222 if (fLoGainFirst < fLoGainLast)
223 {
224 const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
225 FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
226 sumlo, deltasumlo,
227 timelo, deltatimelo,
228 satlo, ped, logainabflag);
229 }
230 fLoGainFirst = fLoGainFirstSave;
231
232 // Make sure that in cases the time couldn't be correctly determined
233 // more meaningfull default values are assigned
234 if (timelo<0)
235 timelo = -1;
236 if (timelo>pixel.GetNumLoGainSamples())
237 timelo = pixel.GetNumLoGainSamples();
238 }
239
240 MExtractedSignalPix &pix = (*fSignals)[pixidx];
241 MArrivalTimePix &tix = (*fArrTime)[pixidx];
242
243 pix.SetExtractedSignal(sumhi, deltasumhi,sumlo, deltasumlo);
244 pix.SetGainSaturation(sathi, sathi, satlo);
245
246 tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
247 tix.SetGainSaturation(sathi, sathi, satlo);
248
249 } /* while (pixel.Next()) */
250
251 fArrTime->SetReadyToSave();
252 fSignals->SetReadyToSave();
253
254 return kTRUE;
255}
256
257// --------------------------------------------------------------------------
258//
259// In addition to the resources of the base-class MExtractor:
260// MJPedestal.MExtractor.LoGainStartShift: -2.8
261//
262Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
263{
264 Bool_t rc = kFALSE;
265
266 if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
267 {
268 fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fLoGainStartShift);
269 rc = kTRUE;
270 }
271
272
273 return MExtractTime::ReadEnv(env, prefix, print) ? kTRUE : rc;
274}
275
276void MExtractTimeAndCharge::Print(Option_t *o) const
277{
278 if (IsA()==Class())
279 *fLog << GetDescriptor() << ":" << endl;
280
281 *fLog << dec;
282 *fLog << " Taking " << fNumHiGainSamples
283 << " HiGain samples from slice " << (Int_t)fHiGainFirst
284 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
285 *fLog << " Taking " << fNumLoGainSamples
286 << " LoGain samples from slice " << (Int_t)fLoGainFirst
287 << " to " << (Int_t)fLoGainLast << " incl" << endl;
288
289 *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
290 MExtractTime::Print(o);
291}
Note: See TracBrowser for help on using the repository browser.