source: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc@ 8045

Last change on this file since 8045 was 7188, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 24.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Markus Gaug 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
172ClassImp(MExtractPedestal);
173
174using namespace std;
175
176const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
177const TString MExtractPedestal::fgNameRawEvtData = "MRawEvtData";
178const UInt_t MExtractPedestal::fgNumDump = 500;
179
180// --------------------------------------------------------------------------
181//
182// Default constructor:
183//
184// Sets:
185// - all pointers to NULL
186//
187// Calls:
188// - AddToBranchList("fHiGainPixId");
189// - AddToBranchList("fHiGainFadcSamples");
190// - Clear()
191//
192MExtractPedestal::MExtractPedestal(const char *name, const char *title)
193 : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL),
194 fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE)
195{
196 fName = name ? name : "MExtractPedestal";
197 fTitle = title ? title : "Base class to calculate pedestals";
198
199 AddToBranchList("fHiGainPixId");
200 AddToBranchList("fLoGainPixId");
201 AddToBranchList("fHiGainFadcSamples");
202 AddToBranchList("fLoGainFadcSamples");
203
204 SetIntermediateStorage( kFALSE );
205 SetPedestalUpdate ( kTRUE );
206 SetRandomCalculation ( kTRUE );
207
208 SetNamePedestalCamIn();
209 SetNamePedestalCamOut();
210 SetNamePedestalCamInter();
211 SetNameRawEvtData();
212 SetNumDump();
213
214 Clear();
215}
216
217void MExtractPedestal::ResetArrays()
218{
219 // Reset contents of arrays.
220 fSumx.Reset();
221 fSumx2.Reset();
222 fSumAB0.Reset();
223 fSumAB1.Reset();
224 fAreaSumx.Reset();
225 fAreaSumx2.Reset();
226 fAreaSumAB0.Reset();
227 fAreaSumAB1.Reset();
228 fAreaFilled.Reset();
229 fAreaValid.Reset();
230 fSectorSumx.Reset();
231 fSectorSumx2.Reset();
232 fSectorSumAB0.Reset();
233 fSectorSumAB1.Reset();
234 fSectorFilled.Reset();
235 fSectorValid.Reset();
236
237}
238
239// --------------------------------------------------------------------------
240//
241// Resets Arrays:
242//
243// Sets:
244// - fRawEvt to NULL
245// - fRunHeader to NULL
246// - fEvtHeader to NULL
247//
248void MExtractPedestal::Clear(const Option_t *o)
249{
250
251 fRawEvt = NULL;
252 fRunHeader = NULL;
253 fEvtHeader = NULL;
254
255 // If the size is yet set, set the size
256 if (fSumx.GetSize()>0)
257 ResetArrays();
258
259}
260
261// --------------------------------------------------------------------------
262//
263// Checks:
264// - if a window is odd
265//
266Bool_t MExtractPedestal::SetExtractWindow(UShort_t windowf, UShort_t windows)
267{
268
269 Bool_t rc = kTRUE;
270
271 const Int_t odd = windows & 0x1;
272
273 if (odd && !fExtractor)
274 {
275 *fLog << warn << GetDescriptor();
276 *fLog << " - WARNING: Window size in SetExtractWindow has to be even... ";
277 *fLog << " raising from " << windows << " to ";
278 windows += 1;
279 *fLog << windows << "!" << endl;
280 rc = kFALSE;
281 }
282
283 if (windows==0)
284 {
285 *fLog << warn << GetDescriptor();
286 *fLog << " - WARNING: Window size in SetExtractWindow has to be > 0... adjusting to 2!" << endl;
287 windows = 2;
288 rc = kFALSE;
289 }
290
291 fExtractWinSize = windows;
292 fExtractWinFirst = windowf;
293 fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
294
295 return rc;
296}
297
298// --------------------------------------------------------------------------
299//
300// Look for the following input containers:
301//
302// - MRawEvtData
303// - MRawRunHeader
304// - MRawEvtHeader
305// - MGeomCam
306//
307// The following output containers are also searched and created if
308// they were not found:
309//
310// - MPedestalCam with the name fPedContainerName
311//
312Int_t MExtractPedestal::PreProcess(MParList *pList)
313{
314
315 Clear();
316
317 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber(fNameRawEvtData));
318 if (!fRawEvt)
319 if (!fUseSpecialPixels)
320 {
321 *fLog << err << AddSerialNumber(fNameRawEvtData) << " not found... aborting." << endl;
322 return kFALSE;
323 }
324
325
326 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
327 if (!fRawEvt)
328 {
329 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
330 return kFALSE;
331 }
332
333 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
334 if (!fRunHeader)
335 {
336 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
337 return kFALSE;
338 }
339
340 fEvtHeader = (MRawEvtHeader*)pList->FindObject(AddSerialNumber("MRawEvtHeader"));
341 if (!fEvtHeader)
342 {
343 *fLog << err << AddSerialNumber("MRawEvtHeader") << " not found... aborting." << endl;
344 return kFALSE;
345 }
346
347 fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
348 if (!fGeom)
349 {
350 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
351 return kFALSE;
352 }
353
354 if (fExtractor && !fPedestalsIn)
355 {
356 fPedestalsIn = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamIn), "MPedestalCam");
357 if (!fPedestalsIn)
358 {
359 *fLog << err << AddSerialNumber(fNamePedestalCamIn) << " not found... aborting." << endl;
360 return kFALSE;
361 }
362 }
363
364 if (!fPedestalsInter && fIntermediateStorage)
365 {
366 fPedestalsInter = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamInter));
367 if (!fPedestalsInter)
368 return kFALSE;
369 }
370
371 if (!fPedestalsOut)
372 {
373 fPedestalsOut = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamOut));
374 if (!fPedestalsOut)
375 return kFALSE;
376 }
377
378 *fLog << inf;
379 Print();
380
381 return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE;
382}
383
384Int_t MExtractPedestal::Process()
385{
386 //
387 // Necessary check for extraction of special pixels
388 // together with data which does not yet have them
389 //
390 if (fSumx.GetSize()==0)
391 return kTRUE;
392
393 if (fExtractor)
394 fExtractor->SetNoiseCalculation(fRandomCalculation);
395
396 const Int_t rc = Calc();
397
398 if (fExtractor)
399 fExtractor->SetNoiseCalculation(kFALSE);
400
401 return rc;
402}
403
404// ---------------------------------------------------------------------------------
405//
406// Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
407// - fSumx
408// - fSumx2
409// - fSumAB0
410// - fSumAB1
411// - fAreaSumx
412// - fAreaSumx2
413// - fAreaSumAB0
414// - fAreaSumAB1
415// - fAreaFilled
416// - fAreaValid
417// - fSectorSumx
418// - fSectorSumx2
419// - fSectorSumAB0
420// - fSectorSumAB1
421// - fSectorFilled
422// - fSectorValid
423//
424Bool_t MExtractPedestal::ReInit(MParList *pList)
425{
426 // Necessary check for special pixels which might not yet have existed
427 if (!fRawEvt)
428 {
429 if (fRunHeader->GetFormatVersion() > 3)
430 return kTRUE;
431
432 *fLog << err << "ERROR - " << fNameRawEvtData << " [MRawEvtData] has not ";
433 *fLog << "been found and format version > 3... abort." << endl;
434 return kFALSE;
435 }
436
437 // If the size is not yet set, set the size
438 if (fSumx.GetSize()==0)
439 {
440 // Initialize the normal pixels (size of MPedestalCam already set by MGeomApply)
441 const Int_t npixels = fPedestalsOut->GetSize();
442
443 fSumx. Set(npixels);
444 fSumx2. Set(npixels);
445 fSumAB0.Set(npixels);
446 fSumAB1.Set(npixels);
447
448 if (fUseSpecialPixels)
449 {
450 // Initialize size of MPedestalCam in case of special pixels (not done by MGeomApply)
451 const UShort_t nspecial = fRunHeader->GetNumSpecialPixels();
452 if (nspecial == 0)
453 {
454 *fLog << warn << "WARNING - Number of special pixels is 0." << endl;
455 return kTRUE;
456 }
457
458 fPedestalsOut->InitSize((UInt_t)nspecial);
459 }
460 else
461 {
462 // Initialize the averaged areas and sectors (do not exist for special pixels)
463 const Int_t areas = fPedestalsOut->GetNumAverageArea();
464 const Int_t sectors = fPedestalsOut->GetNumAverageSector();
465
466 fAreaSumx. Set(areas);
467 fAreaSumx2. Set(areas);
468 fAreaSumAB0.Set(areas);
469 fAreaSumAB1.Set(areas);
470 fAreaFilled.Set(areas);
471 fAreaValid .Set(areas);
472
473 fSectorSumx. Set(sectors);
474 fSectorSumx2. Set(sectors);
475 fSectorSumAB0.Set(sectors);
476 fSectorSumAB1.Set(sectors);
477 fSectorFilled.Set(sectors);
478 fSectorValid .Set(sectors);
479
480 for (Int_t i=0; i<npixels; i++)
481 {
482 const UInt_t aidx = (*fGeom)[i].GetAidx();
483 const UInt_t sector = (*fGeom)[i].GetSector();
484
485 fAreaValid [aidx] ++;
486 fSectorValid[sector]++;
487 }
488 }
489 }
490
491 if (fExtractor)
492 {
493 if (!((MTask*)fExtractor)->ReInit(pList))
494 return kFALSE;
495
496 SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
497 }
498
499 return kTRUE;
500}
501
502Int_t MExtractPedestal::PostProcess()
503{
504 fPedestalsIn = NULL;
505 return fExtractor ? fExtractor->CallPostProcess() : kTRUE;
506}
507
508
509// --------------------------------------------------------------------------
510//
511// The following resources are available:
512// ExtractWindowFirst: 15
513// ExtractWindowSize: 6
514// NumEventsDump: 500
515// PedestalUpdate: yes
516// RandomCalculation: yes
517//
518Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
519{
520 Bool_t rc=kFALSE;
521
522 // find resource for numdump
523 if (IsEnvDefined(env, prefix, "NumDump", print))
524 {
525 const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
526 if (num<=0)
527 {
528 *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
529 return kERROR;
530 }
531
532 SetNumDump(num);
533 rc = kTRUE;
534 }
535
536 // find resource for fUseSpecialPixels
537 if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
538 {
539 SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
540 rc = kTRUE;
541 }
542
543 // find resource for numeventsdump
544 if (IsEnvDefined(env, prefix, "NumEventsDump", print))
545 {
546 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
547 rc = kTRUE;
548 }
549
550 // find resource for numeventsdump
551 if (IsEnvDefined(env, prefix, "NumAreasDump", print))
552 {
553 SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
554 rc = kTRUE;
555 }
556
557 // find resource for numeventsdump
558 if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
559 {
560 SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
561 rc = kTRUE;
562 }
563
564 // find resource for pedestal update
565 if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
566 {
567 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
568 rc = kTRUE;
569 }
570
571 if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
572 {
573 SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
574 rc = kTRUE;
575 }
576
577 // find resource for random calculation
578 if (IsEnvDefined(env, prefix, "RandomCalculation", print))
579 {
580 SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
581 rc = kTRUE;
582 }
583
584 // Find resources for ExtractWindow
585 Int_t ef = fExtractWinFirst;
586 Int_t es = fExtractWinSize;
587 if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
588 {
589 ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
590 rc = kTRUE;
591 }
592 if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
593 {
594 es = GetEnvValue(env, prefix, "ExtractWinSize", es);
595 rc = kTRUE;
596 }
597
598 SetExtractWindow(ef,es);
599
600 // find resource for MPedestalCam
601 if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
602 {
603 SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
604 rc = kTRUE;
605 }
606
607 if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
608 {
609 SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
610 rc = kTRUE;
611 }
612
613 if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
614 {
615 SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
616 rc = kTRUE;
617 }
618
619 return rc;
620}
621
622// ---------------------------------------------------------------------------------
623//
624// Calculates for pixel "idx":
625//
626// Ped per slice = sum / n / fExtractWinSize;
627// RMS per slice = sqrt { (sum2 - sum*sum/n) / (n-1) / fExtractWinSize }
628// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
629//
630// Stores the results in MPedestalCam[pixid]
631//
632void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
633{
634 const Double_t sum = fSumx[pixid];
635 const Double_t sum2 = fSumx2[pixid];
636
637 // 1. Calculate the mean of the sums:
638 Double_t ped = sum/nevts;
639
640 // 2. Calculate the Variance of the sums:
641 Double_t var = (sum2-sum*sum/nevts)/(nevts-1.);
642
643 // 3. Calculate the amplitude of the 150MHz "AB" noise
644 Double_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
645
646 // 4. Scale the mean, variance and AB-noise to the number of slices:
647 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
648 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
649 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
650
651 // 5. Calculate the RMS from the Variance:
652 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
653
654 (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
655}
656
657// ---------------------------------------------------------------------------------
658//
659// Calculates for area idx "aidx" with "napix" valid pixels:
660//
661// Ped per slice = sum / nevts / fExtractWinSize / napix;
662// RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix }
663// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix;
664//
665// Stores the results in MPedestalCam::GetAverageArea(aidx)
666//
667void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
668{
669 const Double_t sum = fAreaSumx[aidx];
670 const Double_t sum2 = fAreaSumx2[aidx];
671
672 // 1. Calculate the mean of the sums:
673 Double_t ped = sum/nevts;
674
675 // 2. Calculate the Variance of the sums:
676 Double_t var = (sum2/napix-sum*sum/nevts)/(nevts-1.);
677
678 // 3. Calculate the amplitude of the 150MHz "AB" noise
679 Double_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
680
681 // 4. Scale the mean, variance and AB-noise to the number of slices:
682 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
683 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
684 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
685
686 // 5. Scale the mean, variance and AB-noise to the number of pixels:
687 ped /= napix;
688 var /= napix;
689 abOffs /= napix;
690
691 // 6. Calculate the RMS from the Variance:
692 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
693
694 fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
695}
696
697// ---------------------------------------------------------------------------------
698//
699// Calculates for sector idx "sector" with "nspix" valid pixels:
700//
701// Ped per slice = sum / nevts / fExtractWinSize / nspix;
702// RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix }
703// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix;
704//
705// Stores the results in MPedestalCam::GetAverageSector(sector)
706//
707void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
708{
709 const Double_t sum = fSectorSumx[sector];
710 const Double_t sum2 = fSectorSumx2[sector];
711
712 // 1. Calculate the mean of the sums:
713 Double_t ped = sum/nevts;
714
715 // 2. Calculate the Variance of the sums:
716 Double_t var = (sum2/nspix-sum*sum/nevts)/(nevts-1.);
717
718 // 3. Calculate the amplitude of the 150MHz "AB" noise
719 Double_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
720
721 // 4. Scale the mean, variance and AB-noise to the number of slices:
722 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
723 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
724 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
725
726 // 5. Scale the mean, variance and AB-noise to the number of pixels:
727 ped /= nspix;
728 var /= nspix;
729 abOffs /= nspix;
730
731 // 6. Calculate the RMS from the Variance:
732 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
733
734 fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
735}
736
737void MExtractPedestal::Print(Option_t *o) const
738{
739 *fLog << GetDescriptor() << ":" << endl;
740 *fLog << "Name of input MPedestalCam: " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
741 *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl;
742 *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
743 *fLog << "Intermediate Storage is " << (fIntermediateStorage?"on":"off") << endl;
744 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
745 *fLog << "Special pixel mode " << (fUseSpecialPixels?"on":"off") << endl;
746 if (fPedestalUpdate)
747 {
748 *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
749 *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
750 *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
751 }
752 if (fExtractor)
753 {
754 *fLog << "Extractor used: " << fExtractor->ClassName() << " (";
755 *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
756 }
757}
Note: See TracBrowser for help on using the repository browser.