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

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