1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndChargeDigitalFilter.cc,v 1.74 2006-10-25 18:36:26 tbretz Exp $
|
---|
3 | ! --------------------------------------------------------------------------
|
---|
4 | !
|
---|
5 | ! *
|
---|
6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | ! *
|
---|
11 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
12 | ! * documentation for any purpose is hereby granted without fee,
|
---|
13 | ! * provided that the above copyright notice appear in all copies and
|
---|
14 | ! * that both that copyright notice and this permission notice appear
|
---|
15 | ! * in supporting documentation. It is provided "as is" without express
|
---|
16 | ! * or implied warranty.
|
---|
17 | ! *
|
---|
18 | !
|
---|
19 | !
|
---|
20 | ! Author(s): Hendrik Bartko, 09/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
21 | ! Author(s): Markus Gaug, 05/2004 <mailto:markus@ifae.es>
|
---|
22 | ! Author(s): Diego Tescaro, 05/2004 <mailto:tescaro@pd.infn.it>
|
---|
23 | !
|
---|
24 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
25 | !
|
---|
26 | !
|
---|
27 | \* ======================================================================== */
|
---|
28 |
|
---|
29 | //////////////////////////////////////////////////////////////////////////////
|
---|
30 | //
|
---|
31 | // MExtractTimeAndChargeDigitalFilter
|
---|
32 | //
|
---|
33 | // Hendrik has promised to write more documentation
|
---|
34 | //
|
---|
35 | // The following variables have to be set by the derived class and
|
---|
36 | // do not have defaults:
|
---|
37 | // - fNumHiGainSamples
|
---|
38 | // - fNumLoGainSamples
|
---|
39 | // - fSqrtHiGainSamples
|
---|
40 | // - fSqrtLoGainSamples
|
---|
41 | //
|
---|
42 | // The reading of automatic weights files (color, type) can be switched
|
---|
43 | // off using EnableAutomaticWeights(kFALSE).
|
---|
44 | //
|
---|
45 | // An empty name or "-" as the weights file name is a synonym for
|
---|
46 | // setting all weights to 1
|
---|
47 | //
|
---|
48 | // Input Containers:
|
---|
49 | // MRawEvtData
|
---|
50 | // MRawRunHeader
|
---|
51 | // MPedestalCam
|
---|
52 | // [MCalibrationPattern]
|
---|
53 | //
|
---|
54 | // Output Containers:
|
---|
55 | // MArrivalTimeCam
|
---|
56 | // MExtractedSignalCam
|
---|
57 | //
|
---|
58 | //////////////////////////////////////////////////////////////////////////////
|
---|
59 | #include "MExtractTimeAndChargeDigitalFilter.h"
|
---|
60 |
|
---|
61 | #include <errno.h>
|
---|
62 | #include <fstream>
|
---|
63 |
|
---|
64 | #include <TRandom.h>
|
---|
65 |
|
---|
66 | #include "MLog.h"
|
---|
67 | #include "MLogManip.h"
|
---|
68 |
|
---|
69 | #include "MParList.h"
|
---|
70 |
|
---|
71 | #include "MRawRunHeader.h"
|
---|
72 | #include "MCalibrationPattern.h"
|
---|
73 | #include "MExtractedSignalCam.h"
|
---|
74 | #include "MExtralgoDigitalFilter.h"
|
---|
75 |
|
---|
76 | ClassImp(MExtractTimeAndChargeDigitalFilter);
|
---|
77 |
|
---|
78 | using namespace std;
|
---|
79 |
|
---|
80 | const Byte_t MExtractTimeAndChargeDigitalFilter::fgHiGainFirst = 0;
|
---|
81 | const Byte_t MExtractTimeAndChargeDigitalFilter::fgHiGainLast = 15;
|
---|
82 | const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainFirst = 1;
|
---|
83 | const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainLast = 14;
|
---|
84 | const Int_t MExtractTimeAndChargeDigitalFilter::fgBinningResolutionHiGain = 10;
|
---|
85 | const Int_t MExtractTimeAndChargeDigitalFilter::fgBinningResolutionLoGain = 10;
|
---|
86 | const Int_t MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain = 4;
|
---|
87 | const Int_t MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain = 4;
|
---|
88 | const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain = 0.95;
|
---|
89 |
|
---|
90 | // --------------------------------------------------------------------------
|
---|
91 | //
|
---|
92 | // Default constructor.
|
---|
93 | //
|
---|
94 | // Calls:
|
---|
95 | // - SetWindowSize();
|
---|
96 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
---|
97 | // - SetBinningResolution();
|
---|
98 | //
|
---|
99 | // Sets all weights to 1.
|
---|
100 | //
|
---|
101 | MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title)
|
---|
102 | : fBinningResolutionHiGain(fgBinningResolutionHiGain),
|
---|
103 | fBinningResolutionLoGain(fgBinningResolutionLoGain),
|
---|
104 | fAutomaticWeights(kTRUE)
|
---|
105 | {
|
---|
106 | fName = name ? name : "MExtractTimeAndChargeDigitalFilter";
|
---|
107 | fTitle = title ? title : "Digital Filter";
|
---|
108 |
|
---|
109 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
110 | SetWindowSize(3, 5);
|
---|
111 | SetOffsetLoGain(fgOffsetLoGain);
|
---|
112 | }
|
---|
113 |
|
---|
114 | // ---------------------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Checks:
|
---|
117 | // - if a window is bigger than the one defined by the ranges, set it
|
---|
118 | // to the available range
|
---|
119 | //
|
---|
120 | // Sets:
|
---|
121 | // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
|
---|
122 | // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
|
---|
123 | //
|
---|
124 | // This function might be used to turn the digital filter into a
|
---|
125 | // sliding window extractor by setting the filename to NULL
|
---|
126 | //
|
---|
127 | void MExtractTimeAndChargeDigitalFilter::SetWindowSize(Int_t windowh, Int_t windowl)
|
---|
128 | {
|
---|
129 | fWindowSizeHiGain = windowh;
|
---|
130 | fWindowSizeLoGain = windowl;
|
---|
131 |
|
---|
132 | const Int_t availhirange = (Int_t)(fHiGainLast-fHiGainFirst+1);
|
---|
133 |
|
---|
134 | if (fWindowSizeHiGain > availhirange)
|
---|
135 | {
|
---|
136 | *fLog << warn << GetDescriptor() << ": Hi Gain window size: " << Form("%2i",fWindowSizeHiGain);
|
---|
137 | *fLog << " is bigger than available range: [" << Form("%2i", (int)fHiGainFirst);
|
---|
138 | *fLog << "," << Form("%21", (int)fHiGainLast) << "]" << endl;
|
---|
139 |
|
---|
140 | fHiGainLast = fHiGainFirst + fWindowSizeHiGain;
|
---|
141 |
|
---|
142 | *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fHiGainLast << endl;
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (fWindowSizeHiGain < 2)
|
---|
146 | {
|
---|
147 | fWindowSizeHiGain = 2;
|
---|
148 | *fLog << warn << GetDescriptor() << ": High Gain window size set to two samples" << endl;
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (fLoGainLast != 0 && fWindowSizeLoGain != 0)
|
---|
152 | {
|
---|
153 | const Int_t availlorange = (Int_t)(fLoGainLast-fLoGainFirst+1);
|
---|
154 |
|
---|
155 | if (fWindowSizeLoGain > availlorange)
|
---|
156 | {
|
---|
157 | *fLog << warn << GetDescriptor() << ": Lo Gain window size: " << Form("%2i",fWindowSizeLoGain);
|
---|
158 | *fLog << " is bigger than available range: [" << Form("%2i", (int)fLoGainFirst);
|
---|
159 | *fLog << "," << Form("%21", (int)fLoGainLast) << "]" << endl;
|
---|
160 |
|
---|
161 | fLoGainLast = fLoGainFirst + fWindowSizeLoGain;
|
---|
162 |
|
---|
163 | *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fLoGainLast << endl;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if (fWindowSizeLoGain<2)
|
---|
167 | {
|
---|
168 | fWindowSizeLoGain = 2;
|
---|
169 | *fLog << warn << GetDescriptor() << ": Low Gain window size set to two samples" << endl;
|
---|
170 | }
|
---|
171 | }
|
---|
172 | //
|
---|
173 | // We need here the effective number of samples which is about 2.5 in the case of a window
|
---|
174 | // size of 6. The exact numbers have to be found still.
|
---|
175 | //
|
---|
176 | fNumHiGainSamples = fWindowSizeHiGain;
|
---|
177 | fNumLoGainSamples = fWindowSizeLoGain;
|
---|
178 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
179 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | // --------------------------------------------------------------------------
|
---|
184 | //
|
---|
185 | // Executing MExtractTimeAndCharge::PreProcess and searching for
|
---|
186 | // MCalibrationPattern
|
---|
187 | //
|
---|
188 | Int_t MExtractTimeAndChargeDigitalFilter::PreProcess(MParList *pList)
|
---|
189 | {
|
---|
190 | if (!MExtractTimeAndCharge::PreProcess(pList))
|
---|
191 | return kFALSE;
|
---|
192 |
|
---|
193 | fCalibPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
|
---|
194 | return kTRUE;
|
---|
195 | }
|
---|
196 |
|
---|
197 | // --------------------------------------------------------------------------
|
---|
198 | //
|
---|
199 | // The weights are determined using GetAutimaticWeights().
|
---|
200 | //
|
---|
201 | // kFALSE is returned if it returned an error.
|
---|
202 | // kTRUE is returned if no new weights were set.
|
---|
203 | //
|
---|
204 | // If new weights are set
|
---|
205 | // fNumHiGainSamples
|
---|
206 | // fNumLoGainSamples
|
---|
207 | // fSqrtHiGainSamples
|
---|
208 | // fSqrtLoGainSamples
|
---|
209 | // and
|
---|
210 | // fSignals->SetUsedFADCSlices(...)
|
---|
211 | // is updated accordingly.
|
---|
212 | //
|
---|
213 | Bool_t MExtractTimeAndChargeDigitalFilter::GetWeights()
|
---|
214 | {
|
---|
215 | switch (GetAutomaticWeights())
|
---|
216 | {
|
---|
217 | case kERROR: // An error occured
|
---|
218 | return kFALSE;
|
---|
219 | case kFALSE: // No new weights set
|
---|
220 | return kTRUE;
|
---|
221 | }
|
---|
222 |
|
---|
223 | //
|
---|
224 | // We need here the effective number of samples. In pricipal the number
|
---|
225 | // is different depending on the weights used and must be set
|
---|
226 | // event by event.
|
---|
227 | //
|
---|
228 | fNumHiGainSamples = fAmpWeightsHiGain.GetSum()/fBinningResolutionHiGain;
|
---|
229 | fNumLoGainSamples = fAmpWeightsLoGain.GetSum()/fBinningResolutionLoGain;
|
---|
230 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
231 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
232 |
|
---|
233 | // From MExtractTimeAndCharge::ReInit
|
---|
234 | if (fSignals)
|
---|
235 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast/*+fHiLoLast*/, fNumHiGainSamples,
|
---|
236 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
237 | return kTRUE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // --------------------------------------------------------------------------
|
---|
241 | //
|
---|
242 | // InitArrays
|
---|
243 | //
|
---|
244 | // Gets called in the ReInit() and initialized the arrays
|
---|
245 | //
|
---|
246 | Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays(Int_t n)
|
---|
247 | {
|
---|
248 | if (!fRunHeader)
|
---|
249 | return kFALSE;
|
---|
250 |
|
---|
251 | return GetWeights();
|
---|
252 | }
|
---|
253 |
|
---|
254 | // --------------------------------------------------------------------------
|
---|
255 | //
|
---|
256 | // Check if reading a new weights file is necessary because the calibration
|
---|
257 | // pattern has changed. (Cannot be done in ReInit, because at this time
|
---|
258 | // the calibration pattern is not available.
|
---|
259 | // Then process the event.
|
---|
260 | //
|
---|
261 | Int_t MExtractTimeAndChargeDigitalFilter::Process()
|
---|
262 | {
|
---|
263 | // Change Weights if the calibration patter changes
|
---|
264 | if (!GetWeights())
|
---|
265 | return kERROR;
|
---|
266 |
|
---|
267 | // Process event
|
---|
268 | return MExtractTimeAndCharge::Process();
|
---|
269 | }
|
---|
270 |
|
---|
271 | // --------------------------------------------------------------------------
|
---|
272 | //
|
---|
273 | // Apply the digital filter algorithm to the high-gain slices.
|
---|
274 | //
|
---|
275 | void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain2(const Float_t *ptr, Int_t num,
|
---|
276 | Float_t &sum, Float_t &dsum,
|
---|
277 | Float_t &time, Float_t &dtime,
|
---|
278 | Byte_t sat, Int_t maxpos) const
|
---|
279 | {
|
---|
280 | // Do some handling if maxpos is last slice!
|
---|
281 |
|
---|
282 | MExtralgoDigitalFilter df(fBinningResolutionHiGain, fWindowSizeHiGain,
|
---|
283 | fAmpWeightsHiGain.GetArray(),
|
---|
284 | fTimeWeightsHiGain.GetArray(),
|
---|
285 | fPulseHiGain.GetArray());
|
---|
286 | df.SetData(num, ptr);
|
---|
287 |
|
---|
288 | if (IsNoiseCalculation())
|
---|
289 | {
|
---|
290 | sum = df.ExtractNoise(gRandom->Integer(fBinningResolutionHiGain));
|
---|
291 | return;
|
---|
292 | }
|
---|
293 |
|
---|
294 | df.Extract(/*maxpos*/);
|
---|
295 | df.GetSignal(sum, dsum);
|
---|
296 | df.GetTime(time, dtime);
|
---|
297 | }
|
---|
298 |
|
---|
299 | void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeLoGain2(const Float_t *ptr, Int_t num,
|
---|
300 | Float_t &sum, Float_t &dsum,
|
---|
301 | Float_t &time, Float_t &dtime,
|
---|
302 | Byte_t sat, Int_t maxpos) const
|
---|
303 | {
|
---|
304 | MExtralgoDigitalFilter df(fBinningResolutionLoGain, fWindowSizeLoGain,
|
---|
305 | fAmpWeightsLoGain.GetArray(),
|
---|
306 | fTimeWeightsLoGain.GetArray(),
|
---|
307 | fPulseLoGain.GetArray());
|
---|
308 |
|
---|
309 | df.SetData(num, ptr);
|
---|
310 |
|
---|
311 | if (IsNoiseCalculation())
|
---|
312 | {
|
---|
313 | sum = df.ExtractNoise(gRandom->Integer(fBinningResolutionHiGain));
|
---|
314 | return;
|
---|
315 | }
|
---|
316 |
|
---|
317 | df.Extract(/*maxpos*/);
|
---|
318 | df.GetSignal(sum, dsum);
|
---|
319 | df.GetTime(time, dtime);
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|
323 | // --------------------------------------------------------------------------
|
---|
324 | //
|
---|
325 | // Read the setup from a TEnv, eg:
|
---|
326 | // MJPedestal.MExtractor.WeightsFile: filename
|
---|
327 | // MJPedestal.MExtractor.AutomaticWeights: off
|
---|
328 | //
|
---|
329 | Int_t MExtractTimeAndChargeDigitalFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
330 | {
|
---|
331 |
|
---|
332 | Bool_t rc = kFALSE;
|
---|
333 |
|
---|
334 | if (IsEnvDefined(env, prefix, "AutomaticWeights", print))
|
---|
335 | {
|
---|
336 | EnableAutomaticWeights(GetEnvValue(env, prefix, "AutomaticWeights", fAutomaticWeights));
|
---|
337 | rc = kTRUE;
|
---|
338 | }
|
---|
339 |
|
---|
340 | if (IsEnvDefined(env, prefix, "WeightsFile", print))
|
---|
341 | {
|
---|
342 | SetNameWeightsFile(GetEnvValue(env, prefix, "WeightsFile", ""));
|
---|
343 | rc = kTRUE;
|
---|
344 | }
|
---|
345 |
|
---|
346 | return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc;
|
---|
347 | }
|
---|
348 |
|
---|
349 | //----------------------------------------------------------------------------
|
---|
350 | //
|
---|
351 | // If automatic weights are requested, no default weights (name.IsNull())
|
---|
352 | // are requested, fRunHeader is available and fRunHeader->IsMonteCarloRun()
|
---|
353 | // is true prepend "MC_" in from of the name.
|
---|
354 | //
|
---|
355 | // return poth+name;
|
---|
356 | //
|
---|
357 | TString MExtractTimeAndChargeDigitalFilter::CompileWeightFileName(TString path, const TString &name) const
|
---|
358 | {
|
---|
359 | if (fAutomaticWeights && !name.IsNull() && fRunHeader && fRunHeader->IsMonteCarloRun())
|
---|
360 | path += "MC_";
|
---|
361 |
|
---|
362 | path += name;
|
---|
363 |
|
---|
364 | return path;
|
---|
365 | }
|
---|
366 |
|
---|
367 | //----------------------------------------------------------------------------
|
---|
368 | //
|
---|
369 | // Read a pre-defined weights file into the class.
|
---|
370 | // This is mandatory for the extraction
|
---|
371 | //
|
---|
372 | // If filenname is empty, then all weights will be set to 1.
|
---|
373 | //
|
---|
374 | // Returns:
|
---|
375 | // kTRUE: new weights set
|
---|
376 | // kFALSE: no weights set
|
---|
377 | // kERROR: error
|
---|
378 | //
|
---|
379 | Int_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename, TString path)
|
---|
380 | {
|
---|
381 | if (filename.IsNull())
|
---|
382 | {
|
---|
383 | fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
|
---|
384 | fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
|
---|
385 | fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
|
---|
386 | fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
|
---|
387 |
|
---|
388 | fAmpWeightsHiGain.Reset(1);
|
---|
389 | fTimeWeightsHiGain.Reset(1);
|
---|
390 | fAmpWeightsLoGain.Reset(1);
|
---|
391 | fTimeWeightsLoGain.Reset(1);
|
---|
392 | return kTRUE;
|
---|
393 | }
|
---|
394 |
|
---|
395 | // Add "MC_" in front of the filename if necessary
|
---|
396 | filename = CompileWeightFileName(path, filename);
|
---|
397 |
|
---|
398 | //filename = MJob::ExpandPath(filename);
|
---|
399 |
|
---|
400 | if (fNameWeightsFileSet==filename)
|
---|
401 | return kFALSE; // No file read
|
---|
402 |
|
---|
403 | ifstream fin(filename.Data());
|
---|
404 | if (!fin)
|
---|
405 | {
|
---|
406 | *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": ";
|
---|
407 | *fLog << strerror(errno) << endl;
|
---|
408 | return kERROR;
|
---|
409 | }
|
---|
410 |
|
---|
411 | *fLog << all << GetDescriptor() << ": Reading weights in " << filename << "..." << flush;
|
---|
412 |
|
---|
413 | Int_t len = 0;
|
---|
414 | Int_t cnt = 0;
|
---|
415 | Int_t line = 0;
|
---|
416 | Bool_t hi = kFALSE;
|
---|
417 | Bool_t lo = kFALSE;
|
---|
418 |
|
---|
419 | TString str;
|
---|
420 |
|
---|
421 | while (1)
|
---|
422 | {
|
---|
423 | str.ReadLine(fin);
|
---|
424 | if (!fin)
|
---|
425 | break;
|
---|
426 |
|
---|
427 | line++;
|
---|
428 |
|
---|
429 | if (str.Contains("# High Gain Weights:"))
|
---|
430 | {
|
---|
431 | if (hi)
|
---|
432 | {
|
---|
433 | *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl;
|
---|
434 | return kERROR;
|
---|
435 | }
|
---|
436 |
|
---|
437 | if (2!=sscanf(str.Data(), "# High Gain Weights: %2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain))
|
---|
438 | {
|
---|
439 | *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
|
---|
440 | *fLog << str << endl;
|
---|
441 | return kERROR;
|
---|
442 | }
|
---|
443 |
|
---|
444 | len = fBinningResolutionHiGain*fWindowSizeHiGain;
|
---|
445 | fAmpWeightsHiGain .Set(len);
|
---|
446 | fTimeWeightsHiGain.Set(len);
|
---|
447 | fPulseHiGain.Set(len);
|
---|
448 | hi = kTRUE;
|
---|
449 | continue;
|
---|
450 | }
|
---|
451 |
|
---|
452 | if (str.Contains("# Low Gain Weights:"))
|
---|
453 | {
|
---|
454 | if (lo)
|
---|
455 | {
|
---|
456 | *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl;
|
---|
457 | return kERROR;
|
---|
458 | }
|
---|
459 |
|
---|
460 | if (2!=sscanf(str.Data(),"# Low Gain Weights: %2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain))
|
---|
461 | {
|
---|
462 | *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
|
---|
463 | *fLog << str << endl;
|
---|
464 | return kERROR;
|
---|
465 | }
|
---|
466 |
|
---|
467 | len = fBinningResolutionLoGain*fWindowSizeLoGain;
|
---|
468 | fAmpWeightsLoGain .Set(len);
|
---|
469 | fTimeWeightsLoGain.Set(len);
|
---|
470 | fPulseLoGain.Set(len);
|
---|
471 | lo = kTRUE;
|
---|
472 | continue;
|
---|
473 | }
|
---|
474 |
|
---|
475 | // Handle lines with comments
|
---|
476 | if (str.Contains("#"))
|
---|
477 | continue;
|
---|
478 |
|
---|
479 | // Nothing found so far
|
---|
480 | if (len == 0)
|
---|
481 | continue;
|
---|
482 |
|
---|
483 | if (3!=sscanf(str.Data(), "%f %f %f",
|
---|
484 | lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
|
---|
485 | lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt],
|
---|
486 | lo ? &fPulseLoGain[cnt] : &fPulseHiGain[cnt]))
|
---|
487 | {
|
---|
488 | *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
|
---|
489 | *fLog << str << endl;
|
---|
490 | return kERROR;
|
---|
491 | }
|
---|
492 |
|
---|
493 | if (++cnt == len)
|
---|
494 | {
|
---|
495 | len = 0;
|
---|
496 | cnt = 0;
|
---|
497 | }
|
---|
498 | }
|
---|
499 |
|
---|
500 | if (cnt != len)
|
---|
501 | {
|
---|
502 | *fLog << err << "ERROR - Size mismatch in weights file " << filename << endl;
|
---|
503 | return kERROR;
|
---|
504 | }
|
---|
505 |
|
---|
506 | if (!hi)
|
---|
507 | {
|
---|
508 | *fLog << err << "ERROR - No correct header found in weights file " << filename << endl;
|
---|
509 | return kERROR;
|
---|
510 | }
|
---|
511 |
|
---|
512 | *fLog << "done." << endl;
|
---|
513 |
|
---|
514 | *fLog << inf << " File contains " << fWindowSizeHiGain << " hi-gain slices ";
|
---|
515 | *fLog << "with a resolution of " << fBinningResolutionHiGain << endl;
|
---|
516 |
|
---|
517 | *fLog << inf << " File contains " << fWindowSizeLoGain << " lo-gain slices ";
|
---|
518 | *fLog << "with a resolution of " << fBinningResolutionLoGain << endl;
|
---|
519 |
|
---|
520 | //CalcBinningResArrays();
|
---|
521 |
|
---|
522 | switch (fWindowSizeHiGain)
|
---|
523 | {
|
---|
524 | case 4:
|
---|
525 | SetResolutionPerPheHiGain(0.036);
|
---|
526 | break;
|
---|
527 | case 6:
|
---|
528 | SetResolutionPerPheHiGain(0.021);
|
---|
529 | break;
|
---|
530 | default:
|
---|
531 | *fLog << warn << "Could not set the high-gain extractor resolution per phe for window size "
|
---|
532 | << fWindowSizeHiGain << endl;
|
---|
533 | }
|
---|
534 |
|
---|
535 | switch (fWindowSizeLoGain)
|
---|
536 | {
|
---|
537 | case 4:
|
---|
538 | SetResolutionPerPheLoGain(0.005);
|
---|
539 | break;
|
---|
540 | case 6:
|
---|
541 | SetResolutionPerPheLoGain(0.004);
|
---|
542 | break;
|
---|
543 | default:
|
---|
544 | *fLog << warn << "Could not set the low-gain extractor resolution per phe for window size "
|
---|
545 | << fWindowSizeLoGain << endl;
|
---|
546 | }
|
---|
547 |
|
---|
548 | fNameWeightsFileSet = filename;
|
---|
549 |
|
---|
550 | return kTRUE;
|
---|
551 | }
|
---|
552 |
|
---|
553 |
|
---|
554 | //----------------------------------------------------------------------------
|
---|
555 | //
|
---|
556 | // The default (+ prepending possible "MC_") is read for:
|
---|
557 | //
|
---|
558 | // - RunType: Pedestal (independant of fAutomaticWeights)
|
---|
559 | // - fAutomaticWeights disabled
|
---|
560 | //
|
---|
561 | // if fAutomaticWeights enabled:
|
---|
562 | // - fNameWeightsFile.IsNull()
|
---|
563 | // - !fCalibPattern
|
---|
564 | // - fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE
|
---|
565 | //
|
---|
566 | // If automatic weights are enabled, the case above didn't take place and
|
---|
567 | // fNameWeightsFile starts with "calibration_weights_"
|
---|
568 | // - the color (blue, UV) is replaced by the appropriate one
|
---|
569 | // taken from the calibration pattern
|
---|
570 | //
|
---|
571 | // In most cases a debug output is printed. Further output about the color
|
---|
572 | // determination can be switched on with debug level > 5;
|
---|
573 | //
|
---|
574 | // Returns:
|
---|
575 | // kFALSE: No new weights set
|
---|
576 | // kTRUE: New weights set
|
---|
577 | // kERROR: Error
|
---|
578 | //
|
---|
579 | Int_t MExtractTimeAndChargeDigitalFilter::GetAutomaticWeights()
|
---|
580 | {
|
---|
581 | const Ssiz_t pos = fNameWeightsFile.Last('/')+1;
|
---|
582 | const Ssiz_t len = fNameWeightsFile.Length();
|
---|
583 |
|
---|
584 | // Split file name in path and name
|
---|
585 | TString path = fNameWeightsFile(0, pos>=0?pos:len);
|
---|
586 | TString name = fNameWeightsFile(pos>=0?pos:0, len);
|
---|
587 |
|
---|
588 | // Remove trailing "MC_" for automatic weights
|
---|
589 | if (fAutomaticWeights && name.BeginsWith("MC_"))
|
---|
590 | name.Remove(0, 3);
|
---|
591 |
|
---|
592 | // In case of a pedetsal run no calibration pattern can be available
|
---|
593 | // the default weights are always used.
|
---|
594 | if (fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal)
|
---|
595 | {
|
---|
596 | *fLog << dbg << "Pedestal file... using default weights: " << fNameWeightsFile << endl;
|
---|
597 | return ReadWeightsFile(name, path);
|
---|
598 | }
|
---|
599 |
|
---|
600 | // If automatic weights are switched off use default weights
|
---|
601 | if (!fAutomaticWeights)
|
---|
602 | {
|
---|
603 | *fLog << dbg << "Automatic weights switched off... using default weights: " << fNameWeightsFile << endl;
|
---|
604 | return ReadWeightsFile(name, path);
|
---|
605 | }
|
---|
606 |
|
---|
607 | // If automatic weights are switched on but no filename is given raise error
|
---|
608 | if (fNameWeightsFile.IsNull())
|
---|
609 | {
|
---|
610 | *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl;
|
---|
611 | return kERROR;
|
---|
612 | }
|
---|
613 |
|
---|
614 | // If this is no pedestal run, automatic weights are requested and a
|
---|
615 | // filename for the weights file is given pedestal-extraction from
|
---|
616 | // cosmics data is assumed.
|
---|
617 | if (!fCalibPattern)
|
---|
618 | {
|
---|
619 | *fLog << dbg << "No decoded calibration pattern available... using default weights: " << fNameWeightsFile << endl;
|
---|
620 | return ReadWeightsFile(name, path);
|
---|
621 | }
|
---|
622 |
|
---|
623 | const Bool_t debug = gLog.GetDebugLevel()>5;
|
---|
624 |
|
---|
625 | // If no calibration pattern is available do not change the
|
---|
626 | // current weighs or current weights file name.
|
---|
627 | if (fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE)
|
---|
628 | {
|
---|
629 | // If we are extracting data and the calibration pattern is kNONE
|
---|
630 | // we assume that it is a data file without interleaved events
|
---|
631 | // and calibration pattern information available.
|
---|
632 | if ((fRunHeader->GetRunType()!=MRawRunHeader::kRTData && !fRunHeader->IsMonteCarloRun()) || debug)
|
---|
633 | *fLog << dbg << "No calibration color set so far... guessing default: " << fNameWeightsFile << endl;
|
---|
634 |
|
---|
635 | return ReadWeightsFile(name, path);
|
---|
636 | }
|
---|
637 |
|
---|
638 | if (debug)
|
---|
639 | {
|
---|
640 | *fLog << dbg << endl;
|
---|
641 | *fLog << underline << GetDescriptor() << endl;
|
---|
642 | *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl;
|
---|
643 | *fLog << " Run type: ";
|
---|
644 | }
|
---|
645 |
|
---|
646 | if (name.BeginsWith("calibration_weights_") && fCalibPattern)
|
---|
647 | {
|
---|
648 | if (debug)
|
---|
649 | *fLog << " Calibration with color " << fCalibPattern->GetPulserColorStr() << ", setting ";
|
---|
650 | switch (fCalibPattern->GetPulserColor())
|
---|
651 | {
|
---|
652 | case MCalibrationCam::kBLUE: // 2
|
---|
653 | case MCalibrationCam::kGREEN: // 1
|
---|
654 | if (debug)
|
---|
655 | *fLog << "blue/green, ";
|
---|
656 | name.ReplaceAll("UV", "blue");
|
---|
657 | break;
|
---|
658 |
|
---|
659 | case MCalibrationCam::kUV: // 3
|
---|
660 | case MCalibrationCam::kCT1: // 0
|
---|
661 | if (debug)
|
---|
662 | *fLog << "UV/CT1, ";
|
---|
663 | name.ReplaceAll("blue", "UV");
|
---|
664 | break;
|
---|
665 | case MCalibrationCam::kNONE:
|
---|
666 | break;
|
---|
667 | default: // kNone + etc
|
---|
668 | *fLog << err << "ERROR - Cannot get automatic weights for " << fCalibPattern->GetPulserColorStr() << endl;
|
---|
669 | return kERROR;
|
---|
670 | }
|
---|
671 | }
|
---|
672 |
|
---|
673 | return ReadWeightsFile(name, path);
|
---|
674 | }
|
---|
675 |
|
---|
676 | //----------------------------------------------------------------------------
|
---|
677 | //
|
---|
678 | // Print the setup of the digital filter extraction used. Use
|
---|
679 | // the option "weights" if you want to print also all weights.
|
---|
680 | //
|
---|
681 | void MExtractTimeAndChargeDigitalFilter::Print(Option_t *o) const
|
---|
682 | {
|
---|
683 | if (IsA()==Class())
|
---|
684 | *fLog << GetDescriptor() << ":" << endl;
|
---|
685 |
|
---|
686 | MExtractTimeAndCharge::Print(o);
|
---|
687 | *fLog << " Window Size HiGain: " << setw(2) << fWindowSizeHiGain << " LoGain: " << setw(2) << fWindowSizeLoGain << endl;
|
---|
688 | *fLog << " Binning Res HiGain: " << setw(2) << fBinningResolutionHiGain << " LoGain: " << setw(2) << fBinningResolutionHiGain << endl;
|
---|
689 | *fLog << " Weights File desired: " << (fNameWeightsFile.IsNull()?"-":fNameWeightsFile.Data()) << endl;
|
---|
690 | if (!fNameWeightsFileSet.IsNull())
|
---|
691 | *fLog << " Weights File set: " << fNameWeightsFileSet << endl;
|
---|
692 |
|
---|
693 | TString opt(o);
|
---|
694 | if (!opt.Contains("weights"))
|
---|
695 | return;
|
---|
696 |
|
---|
697 | *fLog << endl;
|
---|
698 | *fLog << inf << "Using the following weights: " << endl;
|
---|
699 | *fLog << "Hi-Gain:" << endl;
|
---|
700 | for (Int_t i=0; i<fBinningResolutionHiGain*fWindowSizeHiGain; i++)
|
---|
701 | *fLog << " " << fAmpWeightsHiGain[i] << " \t " << fTimeWeightsHiGain[i] << endl;
|
---|
702 |
|
---|
703 | *fLog << "Lo-Gain:" << endl;
|
---|
704 | for (Int_t i=0; i<fBinningResolutionLoGain*fWindowSizeLoGain; i++)
|
---|
705 | *fLog << " " << fAmpWeightsLoGain[i] << " \t " << fTimeWeightsLoGain[i] << endl;
|
---|
706 | }
|
---|