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 01/2004 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractPedestal
|
---|
28 | //
|
---|
29 | // Pedestal Extractor base class
|
---|
30 | //
|
---|
31 | // Input Containers:
|
---|
32 | // MRawEvtData
|
---|
33 | // MRawRunHeader
|
---|
34 | // MRawEvtHeader
|
---|
35 | // MGeomCam
|
---|
36 | // MPedestalCam
|
---|
37 | //
|
---|
38 | // Output Containers:
|
---|
39 | // MPedestalCam
|
---|
40 | //
|
---|
41 | // This class should be used for pedestal extractors with the following facilities:
|
---|
42 | // a) Standardized calculation of AB-noise, mean pedestals and RMS
|
---|
43 | // b) Standardized treatment of area- and sector averaged pedestals values
|
---|
44 | // c) Possibility to use a signal extractor to be applied on the pedestals
|
---|
45 | // d) Possibility to handle two MPedestalCams: one for the signal extractor and
|
---|
46 | // a second to be filled during the pedestal calculating process.
|
---|
47 | //
|
---|
48 | // ad a): Every calculated value is referred to one FADC slice (e.g. Mean pedestal per slice),
|
---|
49 | // RMS per slice.
|
---|
50 | // MExtractPedestal applies the following formula (1):
|
---|
51 | //
|
---|
52 | // Pedestal per slice = sum(x_i) / n / slices
|
---|
53 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
|
---|
54 | // AB-Offset per slice = (sumAB0 - sumAB1) / n / slices
|
---|
55 | //
|
---|
56 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
---|
57 | // events. "n" is the number of events, "slices" is the number of summed FADC samples.
|
---|
58 | //
|
---|
59 | // Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
|
---|
60 | // asymmetric and they are correlated.
|
---|
61 | //
|
---|
62 | // It is important to know that the Pedestal per slice and PedRMS per slice depend
|
---|
63 | // on the number of used FADC slices, as seen in the following plots:
|
---|
64 | //
|
---|
65 | //Begin_Html
|
---|
66 | /*
|
---|
67 | <img src="images/PedestalStudyInner.gif">
|
---|
68 | */
|
---|
69 | //End_Html
|
---|
70 | //
|
---|
71 | //Begin_Html
|
---|
72 | /*
|
---|
73 | <img src="images/PedestalStudyOuter.gif">
|
---|
74 | */
|
---|
75 | //End_Html
|
---|
76 | //
|
---|
77 | // The plots show the inner and outer pixels, respectivly and have the following meaning:
|
---|
78 | //
|
---|
79 | // 1) The calculated mean pedestal per slice (from MPedCalcPedRun)
|
---|
80 | // 2) The fitted mean pedestal per slice (from MHPedestalCam)
|
---|
81 | // 3) The calculated pedestal RMS per slice (from MPedCalcPedRun)
|
---|
82 | // 4) The fitted sigma of the pedestal distribution per slice
|
---|
83 | // (from MHPedestalCam)
|
---|
84 | // 5) The relative difference between calculation and histogram fit
|
---|
85 | // for the mean
|
---|
86 | // 6) The relative difference between calculation and histogram fit
|
---|
87 | // for the sigma or RMS, respectively.
|
---|
88 | //
|
---|
89 | // The calculated means do not change significantly except for the case of 2 slices,
|
---|
90 | // however the RMS changes from 5.7 per slice in the case of 2 extracted slices
|
---|
91 | // to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
|
---|
92 | //
|
---|
93 | // ad b) Every calculated value is referred to one FADC slice and one (averaged) pixel,
|
---|
94 | // (e.g. Mean Pedestal per area index per slice per pixel, etc. )
|
---|
95 | //
|
---|
96 | // MExtractPedestal applies the following formula (2):
|
---|
97 | //
|
---|
98 | // Averaged Pedestal per slice = sum(x_i) / n / slices / n_pix
|
---|
99 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices / n_pix )
|
---|
100 | // AB-Offset per slice = (sumAB0 - sumAB1) / n / slices / n_pix
|
---|
101 | //
|
---|
102 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
---|
103 | // events and all concerned pixels.
|
---|
104 | // "n" is the number of events, "slices" is the number of summed FADC samples and
|
---|
105 | // "n_pix" is the number of pixels belonging to the specific area index or camera sector.
|
---|
106 | //
|
---|
107 | // Calculating these averaged event-by-event values is very important to trace coherent
|
---|
108 | // fluctuations. An example is given in the following plots:
|
---|
109 | //
|
---|
110 | //Begin_Html
|
---|
111 | /*
|
---|
112 | <img src="images/PedestalOscillations.gif">
|
---|
113 | */
|
---|
114 | //End_Html
|
---|
115 | //
|
---|
116 | // The plots show the extracted pedestals of the inner pixels (obtained
|
---|
117 | // with MHPedestalCam), averaged on an event-by-event basis from
|
---|
118 | // run 13428 with switched off camera LV.
|
---|
119 | // The meaning of the four plots is:
|
---|
120 | //
|
---|
121 | // 1) The distribution of the averaged pedestals
|
---|
122 | // 2) The averaged pedestals vs. time.
|
---|
123 | // One can see clearly the oscillation pattern
|
---|
124 | // 3) The fourier transform of the averaged pedestals vs. time.
|
---|
125 | // One can see clearly a peak at a certain frequency
|
---|
126 | // 4) The projection of the fourier components with the non-exponential
|
---|
127 | // (and therefore significant) outlier.
|
---|
128 | //
|
---|
129 | // ad c) Many signal extractors, especially those using a sliding window
|
---|
130 | // have biases and their resolutions for zero-signals do not agree
|
---|
131 | // with the pedestal RMS. For the F-Factor method in the calibration
|
---|
132 | // and the image cleaning, however, both have to be known and measured.
|
---|
133 | //
|
---|
134 | // For this reason, a signal extractor can be handed over to the
|
---|
135 | // pedestal extractor and applied on the pedestal events with the
|
---|
136 | // function SetExtractor().
|
---|
137 | // The results will get stored in an MPedestalCam.
|
---|
138 | //
|
---|
139 | // Note that only extractors deriving from MExtractTimeAndCharge
|
---|
140 | // can be used.
|
---|
141 | //
|
---|
142 | // ad d) The signal extractors themselves need a pedestal to be subtracted
|
---|
143 | // from the FADC slices.
|
---|
144 | // If the user wishes that the pededestals do not get overwritten by
|
---|
145 | // the results from the signal extractor, a different named MPedestalCam
|
---|
146 | // can be created with the function: SetNamePedestalOut().
|
---|
147 | //
|
---|
148 | // See also: MPedestalCam, MPedestalPix, MPedCalcPedRun, MPedCalcFromLoGain
|
---|
149 | //
|
---|
150 | /////////////////////////////////////////////////////////////////////////////
|
---|
151 | #include "MExtractPedestal.h"
|
---|
152 |
|
---|
153 | #include "MParList.h"
|
---|
154 |
|
---|
155 | #include "MLog.h"
|
---|
156 | #include "MLogManip.h"
|
---|
157 |
|
---|
158 | #include "MRawRunHeader.h"
|
---|
159 | #include "MRawEvtHeader.h"
|
---|
160 | #include "MRawEvtPixelIter.h"
|
---|
161 | #include "MRawEvtData.h"
|
---|
162 |
|
---|
163 | #include "MPedestalPix.h"
|
---|
164 | #include "MPedestalCam.h"
|
---|
165 |
|
---|
166 | #include "MGeomPix.h"
|
---|
167 | #include "MGeomCam.h"
|
---|
168 |
|
---|
169 | #include "MTaskEnv.h"
|
---|
170 | #include "MExtractTimeAndCharge.h"
|
---|
171 |
|
---|
172 | ClassImp(MExtractPedestal);
|
---|
173 |
|
---|
174 | using namespace std;
|
---|
175 |
|
---|
176 | const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
|
---|
177 |
|
---|
178 | // --------------------------------------------------------------------------
|
---|
179 | //
|
---|
180 | // Default constructor:
|
---|
181 | //
|
---|
182 | // Sets:
|
---|
183 | // - all pointers to NULL
|
---|
184 | //
|
---|
185 | // Calls:
|
---|
186 | // - AddToBranchList("fHiGainPixId");
|
---|
187 | // - AddToBranchList("fHiGainFadcSamples");
|
---|
188 | // - Clear()
|
---|
189 | //
|
---|
190 | MExtractPedestal::MExtractPedestal(const char *name, const char *title)
|
---|
191 | : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL),
|
---|
192 | fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0)
|
---|
193 | {
|
---|
194 | fName = name ? name : "MExtractPedestal";
|
---|
195 | fTitle = title ? title : "Base class to calculate pedestals";
|
---|
196 |
|
---|
197 | AddToBranchList("fHiGainPixId");
|
---|
198 | AddToBranchList("fLoGainPixId");
|
---|
199 | AddToBranchList("fHiGainFadcSamples");
|
---|
200 | AddToBranchList("fLoGainFadcSamples");
|
---|
201 |
|
---|
202 | SetIntermediateStorage( kFALSE );
|
---|
203 | SetPedestalUpdate ( kTRUE );
|
---|
204 | SetRandomCalculation ( kTRUE );
|
---|
205 |
|
---|
206 | SetNamePedestalCamIn();
|
---|
207 | SetNamePedestalCamOut();
|
---|
208 | SetNumDump();
|
---|
209 |
|
---|
210 | Clear();
|
---|
211 | }
|
---|
212 |
|
---|
213 | void MExtractPedestal::ResetArrays()
|
---|
214 | {
|
---|
215 | // Reset contents of arrays.
|
---|
216 | fSumx.Reset();
|
---|
217 | fSumx2.Reset();
|
---|
218 | fSumAB0.Reset();
|
---|
219 | fSumAB1.Reset();
|
---|
220 | fAreaSumx.Reset();
|
---|
221 | fAreaSumx2.Reset();
|
---|
222 | fAreaSumAB0.Reset();
|
---|
223 | fAreaSumAB1.Reset();
|
---|
224 | fAreaFilled.Reset();
|
---|
225 | fAreaValid.Reset();
|
---|
226 | fSectorSumx.Reset();
|
---|
227 | fSectorSumx2.Reset();
|
---|
228 | fSectorSumAB0.Reset();
|
---|
229 | fSectorSumAB1.Reset();
|
---|
230 | fSectorFilled.Reset();
|
---|
231 | fSectorValid.Reset();
|
---|
232 |
|
---|
233 | }
|
---|
234 |
|
---|
235 | // --------------------------------------------------------------------------
|
---|
236 | //
|
---|
237 | // Resets Arrays:
|
---|
238 | //
|
---|
239 | // Sets:
|
---|
240 | // - fRawEvt to NULL
|
---|
241 | // - fRunHeader to NULL
|
---|
242 | // - fEvtHeader to NULL
|
---|
243 | //
|
---|
244 | void MExtractPedestal::Clear(const Option_t *o)
|
---|
245 | {
|
---|
246 |
|
---|
247 | fRawEvt = NULL;
|
---|
248 | fRunHeader = NULL;
|
---|
249 | fEvtHeader = NULL;
|
---|
250 |
|
---|
251 | // If the size is yet set, set the size
|
---|
252 | if (fSumx.GetSize()>0)
|
---|
253 | ResetArrays();
|
---|
254 |
|
---|
255 | }
|
---|
256 |
|
---|
257 | // --------------------------------------------------------------------------
|
---|
258 | //
|
---|
259 | // Checks:
|
---|
260 | // - if a window is odd
|
---|
261 | //
|
---|
262 | Bool_t MExtractPedestal::SetExtractWindow(UShort_t windowf, UShort_t windows)
|
---|
263 | {
|
---|
264 |
|
---|
265 | Bool_t rc = kTRUE;
|
---|
266 |
|
---|
267 | const Int_t odd = windows & 0x1;
|
---|
268 |
|
---|
269 | if (odd && !fExtractor)
|
---|
270 | {
|
---|
271 | *fLog << warn << GetDescriptor();
|
---|
272 | *fLog << " - WARNING: Window size in SetExtractWindow has to be even... ";
|
---|
273 | *fLog << " raising from " << windows << " to ";
|
---|
274 | windows += 1;
|
---|
275 | *fLog << windows << "!" << endl;
|
---|
276 | rc = kFALSE;
|
---|
277 | }
|
---|
278 |
|
---|
279 | if (windows==0)
|
---|
280 | {
|
---|
281 | *fLog << warn << GetDescriptor();
|
---|
282 | *fLog << " - WARNING: Window size in SetExtractWindow has to be > 0... adjusting to 2!" << endl;
|
---|
283 | windows = 2;
|
---|
284 | rc = kFALSE;
|
---|
285 | }
|
---|
286 |
|
---|
287 | fExtractWinSize = windows;
|
---|
288 | fExtractWinFirst = windowf;
|
---|
289 | fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
|
---|
290 |
|
---|
291 | return rc;
|
---|
292 | }
|
---|
293 |
|
---|
294 | // --------------------------------------------------------------------------
|
---|
295 | //
|
---|
296 | // Look for the following input containers:
|
---|
297 | //
|
---|
298 | // - MRawEvtData
|
---|
299 | // - MRawRunHeader
|
---|
300 | // - MRawEvtHeader
|
---|
301 | // - MGeomCam
|
---|
302 | //
|
---|
303 | // The following output containers are also searched and created if
|
---|
304 | // they were not found:
|
---|
305 | //
|
---|
306 | // - MPedestalCam with the name fPedContainerName
|
---|
307 | //
|
---|
308 | Int_t MExtractPedestal::PreProcess(MParList *pList)
|
---|
309 | {
|
---|
310 |
|
---|
311 | Clear();
|
---|
312 |
|
---|
313 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
314 | if (!fRawEvt)
|
---|
315 | {
|
---|
316 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
317 | return kFALSE;
|
---|
318 | }
|
---|
319 |
|
---|
320 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
---|
321 | if (!fRunHeader)
|
---|
322 | {
|
---|
323 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
---|
324 | return kFALSE;
|
---|
325 | }
|
---|
326 |
|
---|
327 | fEvtHeader = (MRawEvtHeader*)pList->FindObject(AddSerialNumber("MRawEvtHeader"));
|
---|
328 | if (!fEvtHeader)
|
---|
329 | {
|
---|
330 | *fLog << err << AddSerialNumber("MRawEvtHeader") << " not found... aborting." << endl;
|
---|
331 | return kFALSE;
|
---|
332 | }
|
---|
333 |
|
---|
334 | fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
335 | if (!fGeom)
|
---|
336 | {
|
---|
337 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
---|
338 | return kFALSE;
|
---|
339 | }
|
---|
340 |
|
---|
341 | if (fExtractor && !fPedestalsIn)
|
---|
342 | {
|
---|
343 | fPedestalsIn = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamIn), "MPedestalCam");
|
---|
344 | if (!fPedestalsIn)
|
---|
345 | {
|
---|
346 | *fLog << err << AddSerialNumber(fNamePedestalCamIn) << " not found... aborting." << endl;
|
---|
347 | return kFALSE;
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | if (!fPedestalsInter && fIntermediateStorage)
|
---|
352 | {
|
---|
353 | fPedestalsInter = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamInter));
|
---|
354 | if (!fPedestalsInter)
|
---|
355 | return kFALSE;
|
---|
356 | }
|
---|
357 |
|
---|
358 | if (!fPedestalsOut)
|
---|
359 | {
|
---|
360 | fPedestalsOut = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamOut));
|
---|
361 | if (!fPedestalsOut)
|
---|
362 | return kFALSE;
|
---|
363 | }
|
---|
364 |
|
---|
365 | *fLog << inf;
|
---|
366 | Print();
|
---|
367 |
|
---|
368 | // FIMXE: MUST call fExtractor->PreProcess()???
|
---|
369 | return kTRUE;
|
---|
370 | }
|
---|
371 |
|
---|
372 | Int_t MExtractPedestal::Process()
|
---|
373 | {
|
---|
374 | if (fExtractor)
|
---|
375 | fExtractor->SetNoiseCalculation(fRandomCalculation);
|
---|
376 |
|
---|
377 | const Int_t rc = Calc();
|
---|
378 |
|
---|
379 | if (fExtractor)
|
---|
380 | fExtractor->SetNoiseCalculation(kFALSE);
|
---|
381 |
|
---|
382 | return rc;
|
---|
383 | }
|
---|
384 |
|
---|
385 | // ---------------------------------------------------------------------------------
|
---|
386 | //
|
---|
387 | // Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
|
---|
388 | // - fSumx
|
---|
389 | // - fSumx2
|
---|
390 | // - fSumAB0
|
---|
391 | // - fSumAB1
|
---|
392 | // - fAreaSumx
|
---|
393 | // - fAreaSumx2
|
---|
394 | // - fAreaSumAB0
|
---|
395 | // - fAreaSumAB1
|
---|
396 | // - fAreaFilled
|
---|
397 | // - fAreaValid
|
---|
398 | // - fSectorSumx
|
---|
399 | // - fSectorSumx2
|
---|
400 | // - fSectorSumAB0
|
---|
401 | // - fSectorSumAB1
|
---|
402 | // - fSectorFilled
|
---|
403 | // - fSectorValid
|
---|
404 | //
|
---|
405 | Bool_t MExtractPedestal::ReInit(MParList *pList)
|
---|
406 | {
|
---|
407 | // If the size is not yet set, set the size
|
---|
408 | if (fSumx.GetSize()==0)
|
---|
409 | {
|
---|
410 | const Int_t npixels = fPedestalsOut->GetSize();
|
---|
411 | const Int_t areas = fPedestalsOut->GetNumAverageArea();
|
---|
412 | const Int_t sectors = fPedestalsOut->GetNumAverageSector();
|
---|
413 |
|
---|
414 | fSumx. Set(npixels);
|
---|
415 | fSumx2. Set(npixels);
|
---|
416 | fSumAB0.Set(npixels);
|
---|
417 | fSumAB1.Set(npixels);
|
---|
418 |
|
---|
419 | fAreaSumx. Set(areas);
|
---|
420 | fAreaSumx2. Set(areas);
|
---|
421 | fAreaSumAB0.Set(areas);
|
---|
422 | fAreaSumAB1.Set(areas);
|
---|
423 | fAreaFilled.Set(areas);
|
---|
424 | fAreaValid .Set(areas);
|
---|
425 |
|
---|
426 | fSectorSumx. Set(sectors);
|
---|
427 | fSectorSumx2. Set(sectors);
|
---|
428 | fSectorSumAB0.Set(sectors);
|
---|
429 | fSectorSumAB1.Set(sectors);
|
---|
430 | fSectorFilled.Set(sectors);
|
---|
431 | fSectorValid .Set(sectors);
|
---|
432 |
|
---|
433 | for (Int_t i=0; i<npixels; i++)
|
---|
434 | {
|
---|
435 | const UInt_t aidx = (*fGeom)[i].GetAidx();
|
---|
436 | const UInt_t sector = (*fGeom)[i].GetSector();
|
---|
437 |
|
---|
438 | fAreaValid [aidx] ++;
|
---|
439 | fSectorValid[sector]++;
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | if (fExtractor)
|
---|
444 | {
|
---|
445 | if (!fExtractor->InitArrays())
|
---|
446 | return kFALSE;
|
---|
447 |
|
---|
448 | SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
|
---|
449 | }
|
---|
450 |
|
---|
451 | return kTRUE;
|
---|
452 | }
|
---|
453 |
|
---|
454 | Int_t MExtractPedestal::PostProcess()
|
---|
455 | {
|
---|
456 | fPedestalsIn = NULL;
|
---|
457 | return kTRUE;
|
---|
458 | }
|
---|
459 |
|
---|
460 |
|
---|
461 | // --------------------------------------------------------------------------
|
---|
462 | //
|
---|
463 | // The following resources are available:
|
---|
464 | // ExtractWindowFirst: 15
|
---|
465 | // ExtractWindowSize: 6
|
---|
466 | // NumEventsDump: 500
|
---|
467 | // PedestalUpdate: yes
|
---|
468 | // RandomCalculation: yes
|
---|
469 | //
|
---|
470 | Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
471 | {
|
---|
472 | Bool_t rc=kFALSE;
|
---|
473 |
|
---|
474 | // find resource for numeventsdump
|
---|
475 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
---|
476 | {
|
---|
477 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
|
---|
478 | rc = kTRUE;
|
---|
479 | }
|
---|
480 |
|
---|
481 | // find resource for numeventsdump
|
---|
482 | if (IsEnvDefined(env, prefix, "NumAreasDump", print))
|
---|
483 | {
|
---|
484 | SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
|
---|
485 | rc = kTRUE;
|
---|
486 | }
|
---|
487 |
|
---|
488 | // find resource for numeventsdump
|
---|
489 | if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
|
---|
490 | {
|
---|
491 | SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
|
---|
492 | rc = kTRUE;
|
---|
493 | }
|
---|
494 |
|
---|
495 | // find resource for pedestal update
|
---|
496 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
---|
497 | {
|
---|
498 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
---|
499 | rc = kTRUE;
|
---|
500 | }
|
---|
501 |
|
---|
502 | if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
|
---|
503 | {
|
---|
504 | SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
|
---|
505 | rc = kTRUE;
|
---|
506 | }
|
---|
507 |
|
---|
508 | // find resource for random calculation
|
---|
509 | if (IsEnvDefined(env, prefix, "RandomCalculation", print))
|
---|
510 | {
|
---|
511 | SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
|
---|
512 | rc = kTRUE;
|
---|
513 | }
|
---|
514 |
|
---|
515 | // Find resources for ExtractWindow
|
---|
516 | Int_t ef = fExtractWinFirst;
|
---|
517 | Int_t es = fExtractWinSize;
|
---|
518 | if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
|
---|
519 | {
|
---|
520 | ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
|
---|
521 | rc = kTRUE;
|
---|
522 | }
|
---|
523 | if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
|
---|
524 | {
|
---|
525 | es = GetEnvValue(env, prefix, "ExtractWinSize", es);
|
---|
526 | rc = kTRUE;
|
---|
527 | }
|
---|
528 |
|
---|
529 | SetExtractWindow(ef,es);
|
---|
530 |
|
---|
531 | // find resource for MPedestalCam
|
---|
532 | if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
|
---|
533 | {
|
---|
534 | SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
|
---|
535 | rc = kTRUE;
|
---|
536 | }
|
---|
537 |
|
---|
538 | if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
|
---|
539 | {
|
---|
540 | SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
|
---|
541 | rc = kTRUE;
|
---|
542 | }
|
---|
543 |
|
---|
544 | if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
|
---|
545 | {
|
---|
546 | SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
|
---|
547 | rc = kTRUE;
|
---|
548 | }
|
---|
549 |
|
---|
550 | return rc;
|
---|
551 | }
|
---|
552 |
|
---|
553 | // ---------------------------------------------------------------------------------
|
---|
554 | //
|
---|
555 | // Calculates for pixel "idx":
|
---|
556 | //
|
---|
557 | // Ped per slice = sum / n / fExtractWinSize;
|
---|
558 | // RMS per slice = sqrt { (sum2 - sum*sum/n) / (n-1) / fExtractWinSize }
|
---|
559 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
|
---|
560 | //
|
---|
561 | // Stores the results in MPedestalCam[pixid]
|
---|
562 | //
|
---|
563 | void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
|
---|
564 | {
|
---|
565 | const Float_t sum = fSumx[pixid];
|
---|
566 | const Float_t sum2 = fSumx2[pixid];
|
---|
567 |
|
---|
568 | // 1. Calculate the mean of the sums:
|
---|
569 | Float_t ped = sum/nevts;
|
---|
570 |
|
---|
571 | // 2. Calculate the Variance of the sums:
|
---|
572 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
573 |
|
---|
574 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
575 | Float_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
|
---|
576 |
|
---|
577 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
578 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
579 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
580 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
581 |
|
---|
582 | // 5. Calculate the RMS from the Variance:
|
---|
583 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
584 |
|
---|
585 | (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
|
---|
586 | }
|
---|
587 |
|
---|
588 | // ---------------------------------------------------------------------------------
|
---|
589 | //
|
---|
590 | // Calculates for area idx "aidx" with "napix" valid pixels:
|
---|
591 | //
|
---|
592 | // Ped per slice = sum / nevts / fExtractWinSize / napix;
|
---|
593 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix }
|
---|
594 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix;
|
---|
595 | //
|
---|
596 | // Stores the results in MPedestalCam::GetAverageArea(aidx)
|
---|
597 | //
|
---|
598 | void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
|
---|
599 | {
|
---|
600 | const Float_t sum = fAreaSumx[aidx];
|
---|
601 | const Float_t sum2 = fAreaSumx2[aidx];
|
---|
602 |
|
---|
603 | // 1. Calculate the mean of the sums:
|
---|
604 | Float_t ped = sum/nevts;
|
---|
605 |
|
---|
606 | // 2. Calculate the Variance of the sums:
|
---|
607 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
608 |
|
---|
609 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
610 | Float_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
|
---|
611 |
|
---|
612 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
613 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
614 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
615 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
616 |
|
---|
617 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
---|
618 | ped /= napix;
|
---|
619 | var /= napix;
|
---|
620 | abOffs /= napix;
|
---|
621 |
|
---|
622 | // 6. Calculate the RMS from the Variance:
|
---|
623 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
624 |
|
---|
625 | fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
|
---|
626 | }
|
---|
627 |
|
---|
628 | // ---------------------------------------------------------------------------------
|
---|
629 | //
|
---|
630 | // Calculates for sector idx "sector" with "nspix" valid pixels:
|
---|
631 | //
|
---|
632 | // Ped per slice = sum / nevts / fExtractWinSize / nspix;
|
---|
633 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix }
|
---|
634 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix;
|
---|
635 | //
|
---|
636 | // Stores the results in MPedestalCam::GetAverageSector(sector)
|
---|
637 | //
|
---|
638 | void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
|
---|
639 | {
|
---|
640 | const Float_t sum = fSectorSumx[sector];
|
---|
641 | const Float_t sum2 = fSectorSumx2[sector];
|
---|
642 |
|
---|
643 | // 1. Calculate the mean of the sums:
|
---|
644 | Float_t ped = sum/nevts;
|
---|
645 |
|
---|
646 | // 2. Calculate the Variance of the sums:
|
---|
647 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
648 |
|
---|
649 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
650 | Float_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
|
---|
651 |
|
---|
652 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
653 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
654 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
655 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
656 |
|
---|
657 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
---|
658 | ped /= nspix;
|
---|
659 | var /= nspix;
|
---|
660 | abOffs /= nspix;
|
---|
661 |
|
---|
662 | // 6. Calculate the RMS from the Variance:
|
---|
663 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
664 |
|
---|
665 | fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
|
---|
666 | }
|
---|
667 |
|
---|
668 | void MExtractPedestal::Print(Option_t *o) const
|
---|
669 | {
|
---|
670 | *fLog << GetDescriptor() << ":" << endl;
|
---|
671 | *fLog << "Name of input MPedestalCam: " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
|
---|
672 | *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl;
|
---|
673 | *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
|
---|
674 | *fLog << "Intermediate Storage is " << (fIntermediateStorage?"on":"off") << endl;
|
---|
675 | *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
|
---|
676 | if (fPedestalUpdate)
|
---|
677 | {
|
---|
678 | *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
|
---|
679 | *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
|
---|
680 | *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
|
---|
681 | }
|
---|
682 | if (fExtractor)
|
---|
683 | {
|
---|
684 | *fLog << "Extractor used: " << fExtractor->ClassName() << " (";
|
---|
685 | *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
|
---|
686 | }
|
---|
687 | }
|
---|