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

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