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

Last change on this file since 5246 was 5242, checked in by gaug, 20 years ago
*** empty log message ***
File size: 8.1 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// Default constructor.
79//
80// Sets:
81// - fLoGainStartShift to fgLoGainStartShift+fgOffsetLoGain
82//
83MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
84{
85
86 fName = name ? name : "MExtractTimeAndCharge";
87 fTitle = title ? title : "Base class for signal and time extractors";
88
89 SetLoGainStartShift();
90}
91
92// --------------------------------------------------------------------------
93//
94// The PreProcess searches for the following input containers:
95// - MRawEvtData
96// - MRawRunHeader
97// - MPedestalCam
98//
99// The following output containers are also searched and created if
100// they were not found:
101//
102// - MExtractedSignalCam
103// - MArrivalTimeCam
104//
105Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
106{
107
108 if (!MExtractTime::PreProcess(pList))
109 return kFALSE;
110
111 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
112 if (!fSignals)
113 {
114 *fLog << err << GetDescriptor()
115 << ": Could not find nor create MExtractedSignalCam,... aborting." << endl;
116 return kFALSE;
117 }
118
119
120 return kTRUE;
121}
122
123// --------------------------------------------------------------------------
124//
125// The ReInit calls:
126// - MExtractor::ReInit()
127//
128// Call:
129// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
130// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
131//
132Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
133{
134
135 MExtractTime::ReInit(pList);
136
137 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
138 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
139
140 *fLog << dec << endl;
141 *fLog << inf << GetDescriptor() << ": Taking " << fNumHiGainSamples
142 << " HiGain samples from slice " << (Int_t)fHiGainFirst
143 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
144 *fLog << inf << GetDescriptor() << ": Taking " << fNumLoGainSamples
145 << " LoGain samples from slice " << (Int_t)fLoGainFirst
146 << " to " << (Int_t)fLoGainLast << " incl" << endl;
147
148 return kTRUE;
149}
150
151void MExtractTimeAndCharge::FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
152 Float_t &time, Float_t &dtime,
153 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
154{
155 return;
156}
157
158void MExtractTimeAndCharge::FindTimeAndChargeLoGain(Byte_t *firstused, Float_t &sum, Float_t &dsum,
159 Float_t &time, Float_t &dtime,
160 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
161{
162 return;
163}
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 fArrTime->Clear();
180 fSignals->Clear();
181
182 while (pixel.Next())
183 {
184 //
185 // Find signal in hi- and lo-gain
186 //
187 Float_t sumhi =0., deltasumhi =0.;
188 Float_t timehi=0., deltatimehi=0.;
189 Byte_t sathi=0;
190
191 const Int_t pixid = pixel.GetPixelId();
192 const MPedestalPix &ped = (*fPedestals)[pixid];
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 Float_t sumlo =0., deltasumlo =0.;
201 Float_t timelo=0., deltatimelo=0.;
202 Byte_t satlo=0;
203
204 //
205 // Adapt the low-gain extraction range from the obtained high-gain time
206 //
207 if (pixel.HasLoGain())
208 {
209 fLoGainFirstSave = fLoGainFirst;
210 fLoGainFirst = (Int_t)(timehi+fLoGainStartShift);
211 fLoGainFirst = fLoGainFirst < fLoGainFirstSave ? fLoGainFirstSave : fLoGainFirst;
212
213 if ( fLoGainFirst < fLoGainLast )
214 {
215 const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
216 FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
217 sumlo, deltasumlo,
218 timelo, deltatimelo,
219 satlo, ped, logainabflag);
220 }
221
222 fLoGainFirst = fLoGainFirstSave;
223 }
224
225 MExtractedSignalPix &pix = (*fSignals)[pixid];
226 MArrivalTimePix &tix = (*fArrTime)[pixid];
227
228 pix.SetExtractedSignal(sumhi, deltasumhi,sumlo, deltasumlo);
229 pix.SetGainSaturation(sathi, sathi, satlo);
230
231 tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
232 tix.SetGainSaturation(sathi, sathi, satlo);
233
234 } /* while (pixel.Next()) */
235
236 fArrTime->SetReadyToSave();
237 fSignals->SetReadyToSave();
238
239 return kTRUE;
240}
241
242// --------------------------------------------------------------------------
243//
244// In addition to the resources of the base-class MExtractor:
245// MJPedestal.MExtractor.LoGainStartShift: -2.8
246//
247Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
248{
249 Bool_t rc = kFALSE;
250
251 if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
252 {
253 fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fLoGainStartShift);
254 rc = kTRUE;
255 }
256
257
258 return MExtractTime::ReadEnv(env, prefix, print) ? kTRUE : rc;
259}
Note: See TracBrowser for help on using the repository browser.