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 | return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE;
|
---|
369 | }
|
---|
370 |
|
---|
371 | Int_t MExtractPedestal::Process()
|
---|
372 | {
|
---|
373 | if (fExtractor)
|
---|
374 | fExtractor->SetNoiseCalculation(fRandomCalculation);
|
---|
375 |
|
---|
376 | const Int_t rc = Calc();
|
---|
377 |
|
---|
378 | if (fExtractor)
|
---|
379 | fExtractor->SetNoiseCalculation(kFALSE);
|
---|
380 |
|
---|
381 | return rc;
|
---|
382 | }
|
---|
383 |
|
---|
384 | // ---------------------------------------------------------------------------------
|
---|
385 | //
|
---|
386 | // Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
|
---|
387 | // - fSumx
|
---|
388 | // - fSumx2
|
---|
389 | // - fSumAB0
|
---|
390 | // - fSumAB1
|
---|
391 | // - fAreaSumx
|
---|
392 | // - fAreaSumx2
|
---|
393 | // - fAreaSumAB0
|
---|
394 | // - fAreaSumAB1
|
---|
395 | // - fAreaFilled
|
---|
396 | // - fAreaValid
|
---|
397 | // - fSectorSumx
|
---|
398 | // - fSectorSumx2
|
---|
399 | // - fSectorSumAB0
|
---|
400 | // - fSectorSumAB1
|
---|
401 | // - fSectorFilled
|
---|
402 | // - fSectorValid
|
---|
403 | //
|
---|
404 | Bool_t MExtractPedestal::ReInit(MParList *pList)
|
---|
405 | {
|
---|
406 | // If the size is not yet set, set the size
|
---|
407 | if (fSumx.GetSize()==0)
|
---|
408 | {
|
---|
409 | const Int_t npixels = fPedestalsOut->GetSize();
|
---|
410 | const Int_t areas = fPedestalsOut->GetNumAverageArea();
|
---|
411 | const Int_t sectors = fPedestalsOut->GetNumAverageSector();
|
---|
412 |
|
---|
413 | fSumx. Set(npixels);
|
---|
414 | fSumx2. Set(npixels);
|
---|
415 | fSumAB0.Set(npixels);
|
---|
416 | fSumAB1.Set(npixels);
|
---|
417 |
|
---|
418 | fAreaSumx. Set(areas);
|
---|
419 | fAreaSumx2. Set(areas);
|
---|
420 | fAreaSumAB0.Set(areas);
|
---|
421 | fAreaSumAB1.Set(areas);
|
---|
422 | fAreaFilled.Set(areas);
|
---|
423 | fAreaValid .Set(areas);
|
---|
424 |
|
---|
425 | fSectorSumx. Set(sectors);
|
---|
426 | fSectorSumx2. Set(sectors);
|
---|
427 | fSectorSumAB0.Set(sectors);
|
---|
428 | fSectorSumAB1.Set(sectors);
|
---|
429 | fSectorFilled.Set(sectors);
|
---|
430 | fSectorValid .Set(sectors);
|
---|
431 |
|
---|
432 | for (Int_t i=0; i<npixels; i++)
|
---|
433 | {
|
---|
434 | const UInt_t aidx = (*fGeom)[i].GetAidx();
|
---|
435 | const UInt_t sector = (*fGeom)[i].GetSector();
|
---|
436 |
|
---|
437 | fAreaValid [aidx] ++;
|
---|
438 | fSectorValid[sector]++;
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | if (fExtractor)
|
---|
443 | {
|
---|
444 | if (!fExtractor->InitArrays())
|
---|
445 | return kFALSE;
|
---|
446 |
|
---|
447 | SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
|
---|
448 | }
|
---|
449 |
|
---|
450 | return kTRUE;
|
---|
451 | }
|
---|
452 |
|
---|
453 | Int_t MExtractPedestal::PostProcess()
|
---|
454 | {
|
---|
455 | fPedestalsIn = NULL;
|
---|
456 | return fExtractor ? fExtractor->CallPostProcess() : kTRUE;
|
---|
457 | }
|
---|
458 |
|
---|
459 |
|
---|
460 | // --------------------------------------------------------------------------
|
---|
461 | //
|
---|
462 | // The following resources are available:
|
---|
463 | // ExtractWindowFirst: 15
|
---|
464 | // ExtractWindowSize: 6
|
---|
465 | // NumEventsDump: 500
|
---|
466 | // PedestalUpdate: yes
|
---|
467 | // RandomCalculation: yes
|
---|
468 | //
|
---|
469 | Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
470 | {
|
---|
471 | Bool_t rc=kFALSE;
|
---|
472 |
|
---|
473 | // find resource for numeventsdump
|
---|
474 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
---|
475 | {
|
---|
476 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
|
---|
477 | rc = kTRUE;
|
---|
478 | }
|
---|
479 |
|
---|
480 | // find resource for numeventsdump
|
---|
481 | if (IsEnvDefined(env, prefix, "NumAreasDump", print))
|
---|
482 | {
|
---|
483 | SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
|
---|
484 | rc = kTRUE;
|
---|
485 | }
|
---|
486 |
|
---|
487 | // find resource for numeventsdump
|
---|
488 | if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
|
---|
489 | {
|
---|
490 | SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
|
---|
491 | rc = kTRUE;
|
---|
492 | }
|
---|
493 |
|
---|
494 | // find resource for pedestal update
|
---|
495 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
---|
496 | {
|
---|
497 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
---|
498 | rc = kTRUE;
|
---|
499 | }
|
---|
500 |
|
---|
501 | if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
|
---|
502 | {
|
---|
503 | SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
|
---|
504 | rc = kTRUE;
|
---|
505 | }
|
---|
506 |
|
---|
507 | // find resource for random calculation
|
---|
508 | if (IsEnvDefined(env, prefix, "RandomCalculation", print))
|
---|
509 | {
|
---|
510 | SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
|
---|
511 | rc = kTRUE;
|
---|
512 | }
|
---|
513 |
|
---|
514 | // Find resources for ExtractWindow
|
---|
515 | Int_t ef = fExtractWinFirst;
|
---|
516 | Int_t es = fExtractWinSize;
|
---|
517 | if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
|
---|
518 | {
|
---|
519 | ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
|
---|
520 | rc = kTRUE;
|
---|
521 | }
|
---|
522 | if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
|
---|
523 | {
|
---|
524 | es = GetEnvValue(env, prefix, "ExtractWinSize", es);
|
---|
525 | rc = kTRUE;
|
---|
526 | }
|
---|
527 |
|
---|
528 | SetExtractWindow(ef,es);
|
---|
529 |
|
---|
530 | // find resource for MPedestalCam
|
---|
531 | if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
|
---|
532 | {
|
---|
533 | SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
|
---|
534 | rc = kTRUE;
|
---|
535 | }
|
---|
536 |
|
---|
537 | if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
|
---|
538 | {
|
---|
539 | SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
|
---|
540 | rc = kTRUE;
|
---|
541 | }
|
---|
542 |
|
---|
543 | if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
|
---|
544 | {
|
---|
545 | SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
|
---|
546 | rc = kTRUE;
|
---|
547 | }
|
---|
548 |
|
---|
549 | return rc;
|
---|
550 | }
|
---|
551 |
|
---|
552 | // ---------------------------------------------------------------------------------
|
---|
553 | //
|
---|
554 | // Calculates for pixel "idx":
|
---|
555 | //
|
---|
556 | // Ped per slice = sum / n / fExtractWinSize;
|
---|
557 | // RMS per slice = sqrt { (sum2 - sum*sum/n) / (n-1) / fExtractWinSize }
|
---|
558 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
|
---|
559 | //
|
---|
560 | // Stores the results in MPedestalCam[pixid]
|
---|
561 | //
|
---|
562 | void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
|
---|
563 | {
|
---|
564 | const Float_t sum = fSumx[pixid];
|
---|
565 | const Float_t sum2 = fSumx2[pixid];
|
---|
566 |
|
---|
567 | // 1. Calculate the mean of the sums:
|
---|
568 | Float_t ped = sum/nevts;
|
---|
569 |
|
---|
570 | // 2. Calculate the Variance of the sums:
|
---|
571 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
572 |
|
---|
573 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
574 | Float_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
|
---|
575 |
|
---|
576 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
577 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
578 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
579 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
580 |
|
---|
581 | // 5. Calculate the RMS from the Variance:
|
---|
582 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
583 |
|
---|
584 | (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
|
---|
585 | }
|
---|
586 |
|
---|
587 | // ---------------------------------------------------------------------------------
|
---|
588 | //
|
---|
589 | // Calculates for area idx "aidx" with "napix" valid pixels:
|
---|
590 | //
|
---|
591 | // Ped per slice = sum / nevts / fExtractWinSize / napix;
|
---|
592 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix }
|
---|
593 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix;
|
---|
594 | //
|
---|
595 | // Stores the results in MPedestalCam::GetAverageArea(aidx)
|
---|
596 | //
|
---|
597 | void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
|
---|
598 | {
|
---|
599 | const Float_t sum = fAreaSumx[aidx];
|
---|
600 | const Float_t sum2 = fAreaSumx2[aidx];
|
---|
601 |
|
---|
602 | // 1. Calculate the mean of the sums:
|
---|
603 | Float_t ped = sum/nevts;
|
---|
604 |
|
---|
605 | // 2. Calculate the Variance of the sums:
|
---|
606 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
607 |
|
---|
608 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
609 | Float_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
|
---|
610 |
|
---|
611 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
612 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
613 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
614 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
615 |
|
---|
616 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
---|
617 | ped /= napix;
|
---|
618 | var /= napix;
|
---|
619 | abOffs /= napix;
|
---|
620 |
|
---|
621 | // 6. Calculate the RMS from the Variance:
|
---|
622 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
623 |
|
---|
624 | fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
|
---|
625 | }
|
---|
626 |
|
---|
627 | // ---------------------------------------------------------------------------------
|
---|
628 | //
|
---|
629 | // Calculates for sector idx "sector" with "nspix" valid pixels:
|
---|
630 | //
|
---|
631 | // Ped per slice = sum / nevts / fExtractWinSize / nspix;
|
---|
632 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix }
|
---|
633 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix;
|
---|
634 | //
|
---|
635 | // Stores the results in MPedestalCam::GetAverageSector(sector)
|
---|
636 | //
|
---|
637 | void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
|
---|
638 | {
|
---|
639 | const Float_t sum = fSectorSumx[sector];
|
---|
640 | const Float_t sum2 = fSectorSumx2[sector];
|
---|
641 |
|
---|
642 | // 1. Calculate the mean of the sums:
|
---|
643 | Float_t ped = sum/nevts;
|
---|
644 |
|
---|
645 | // 2. Calculate the Variance of the sums:
|
---|
646 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
---|
647 |
|
---|
648 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
---|
649 | Float_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
|
---|
650 |
|
---|
651 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
---|
652 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
653 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
654 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
---|
655 |
|
---|
656 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
---|
657 | ped /= nspix;
|
---|
658 | var /= nspix;
|
---|
659 | abOffs /= nspix;
|
---|
660 |
|
---|
661 | // 6. Calculate the RMS from the Variance:
|
---|
662 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
---|
663 |
|
---|
664 | fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
|
---|
665 | }
|
---|
666 |
|
---|
667 | void MExtractPedestal::Print(Option_t *o) const
|
---|
668 | {
|
---|
669 | *fLog << GetDescriptor() << ":" << endl;
|
---|
670 | *fLog << "Name of input MPedestalCam: " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
|
---|
671 | *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl;
|
---|
672 | *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
|
---|
673 | *fLog << "Intermediate Storage is " << (fIntermediateStorage?"on":"off") << endl;
|
---|
674 | *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
|
---|
675 | if (fPedestalUpdate)
|
---|
676 | {
|
---|
677 | *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
|
---|
678 | *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
|
---|
679 | *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
|
---|
680 | }
|
---|
681 | if (fExtractor)
|
---|
682 | {
|
---|
683 | *fLog << "Extractor used: " << fExtractor->ClassName() << " (";
|
---|
684 | *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
|
---|
685 | }
|
---|
686 | }
|
---|