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