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

Last change on this file since 5538 was 5538, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.8 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 variables have to be set by the derived class and
35// do not have defaults:
36// - fNumHiGainSamples
37// - fNumLoGainSamples
38// - fSqrtHiGainSamples
39// - fSqrtLoGainSamples
40//
41// Input Containers:
42// MRawEvtData
43// MRawRunHeader
44// MPedestalCam
45//
46// Output Containers:
47// MArrivalTimeCam
48// MExtractedSignalCam
49//
50//////////////////////////////////////////////////////////////////////////////
51#include "MExtractTimeAndCharge.h"
52
53#include "MLog.h"
54#include "MLogManip.h"
55
56#include "MParList.h"
57
58#include "MRawEvtData.h"
59#include "MRawEvtPixelIter.h"
60#include "MRawRunHeader.h"
61
62#include "MPedestalCam.h"
63#include "MPedestalPix.h"
64
65#include "MArrivalTimeCam.h"
66#include "MArrivalTimePix.h"
67
68#include "MExtractedSignalCam.h"
69#include "MExtractedSignalPix.h"
70
71ClassImp(MExtractTimeAndCharge);
72
73using namespace std;
74
75const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.8;
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81// Sets:
82// - fLoGainStartShift to fgLoGainStartShift+fgOffsetLoGain
83//
84MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
85 : fLoGainFirstSave(0), fWindowSizeHiGain(0), fWindowSizeLoGain(0)
86{
87 fName = name ? name : "MExtractTimeAndCharge";
88 fTitle = title ? title : "Base class for signal and time extractors";
89
90 SetLoGainStartShift();
91}
92
93// --------------------------------------------------------------------------
94//
95// The PreProcess searches for the following input containers:
96// - MRawEvtData
97// - MRawRunHeader
98// - MPedestalCam
99//
100// The following output containers are also searched and created if
101// they were not found:
102//
103// - MExtractedSignalCam
104// - MArrivalTimeCam
105//
106Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
107{
108
109 if (!MExtractTime::PreProcess(pList))
110 return kFALSE;
111
112 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
113 if (!fSignals)
114 {
115 *fLog << err << fNameSignalCam.Data() << " could not be found nor created... aborting" << endl;
116 return kFALSE;
117 }
118
119 return kTRUE;
120}
121
122// --------------------------------------------------------------------------
123//
124// The ReInit calls:
125// - MExtractor::ReInit()
126//
127// Call:
128// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
129// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
130// - InitArrays();
131//
132Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
133{
134
135 if (!MExtractTime::ReInit(pList))
136 return kFALSE;
137
138 if (fSignals)
139 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
140 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
141
142
143 if (!InitArrays())
144 return kFALSE;
145
146 Print();
147
148 return kTRUE;
149}
150
151// --------------------------------------------------------------------------
152//
153// Calculate the integral of the FADC time slices and store them as a new
154// pixel in the MArrivalTimeCam container.
155// Calculate the integral of the FADC time slices and store them as a new
156// pixel in the MExtractedSignalCam container.
157// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain are
158// supposed to extract the signal themselves.
159//
160Int_t MExtractTimeAndCharge::Process()
161{
162
163 MRawEvtPixelIter pixel(fRawEvt);
164 fArrTime->Clear();
165 fSignals->Clear();
166
167 while (pixel.Next())
168 {
169 //
170 // Find signal in hi- and lo-gain
171 //
172 Float_t sumhi =0., deltasumhi =0.;
173 Float_t timehi=0., deltatimehi=0.;
174 Byte_t sathi=0;
175
176 const Int_t pixid = pixel.GetPixelId();
177 const MPedestalPix &ped = (*fPedestals)[pixid];
178 const Bool_t higainabflag = pixel.HasABFlag();
179
180 FindTimeAndChargeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(),
181 sumhi, deltasumhi,
182 timehi, deltatimehi,
183 sathi, ped, higainabflag);
184
185 Float_t sumlo =0., deltasumlo =0.;
186 Float_t timelo=0., deltatimelo=0.;
187 Byte_t satlo=0;
188
189 //
190 // Adapt the low-gain extraction range from the obtained high-gain time
191 //
192 if (pixel.HasLoGain())
193 {
194 fLoGainFirstSave = (Int_t)fLoGainFirst;
195 const Int_t logainstart = (Int_t)(timehi+fLoGainStartShift);
196 fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
197
198 if ( fLoGainFirst < fLoGainLast )
199 {
200 const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
201 FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
202 sumlo, deltasumlo,
203 timelo, deltatimelo,
204 satlo, ped, logainabflag);
205 }
206
207 fLoGainFirst = fLoGainFirstSave;
208 }
209
210 MExtractedSignalPix &pix = (*fSignals)[pixid];
211 MArrivalTimePix &tix = (*fArrTime)[pixid];
212
213 pix.SetExtractedSignal(sumhi, deltasumhi,sumlo, deltasumlo);
214 pix.SetGainSaturation(sathi, sathi, satlo);
215
216 tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
217 tix.SetGainSaturation(sathi, sathi, satlo);
218
219 } /* while (pixel.Next()) */
220
221 fArrTime->SetReadyToSave();
222 fSignals->SetReadyToSave();
223
224 return kTRUE;
225}
226
227// --------------------------------------------------------------------------
228//
229// In addition to the resources of the base-class MExtractor:
230// MJPedestal.MExtractor.LoGainStartShift: -2.8
231//
232Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
233{
234 Bool_t rc = kFALSE;
235
236 if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
237 {
238 fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fLoGainStartShift);
239 rc = kTRUE;
240 }
241
242
243 return MExtractTime::ReadEnv(env, prefix, print) ? kTRUE : rc;
244}
245
246void MExtractTimeAndCharge::Print(Option_t *o) const
247{
248
249 *fLog << all;
250 if (IsA()==MExtractTimeAndCharge::Class())
251 *fLog << GetDescriptor() << ":" << endl;
252
253 *fLog << dec << endl;
254 *fLog << inf << "Taking " << fNumHiGainSamples
255 << " HiGain samples from slice " << (Int_t)fHiGainFirst
256 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
257 *fLog << inf << "Taking " << fNumLoGainSamples
258 << " LoGain samples from slice " << (Int_t)fLoGainFirst
259 << " to " << (Int_t)fLoGainLast << " incl" << endl;
260
261 *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
262 MExtractTime::Print(o);
263}
Note: See TracBrowser for help on using the repository browser.