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

Last change on this file since 8296 was 8296, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 30.5 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.25 2007-02-03 20:03:35 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): Markus Gaug 01/2004 <mailto:markus@ifae.es>
21! Author(s): Thomas Bretz 01/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
22!
23! Copyright: MAGIC Software Development, 2000-2006
24!
25!
26\* ======================================================================== */
27
28/////////////////////////////////////////////////////////////////////////////
29//
30// MExtractPedestal
31//
32// Pedestal Extractor base class
33//
34// Input Containers:
35// MRawEvtData
36// MRawRunHeader
37// MRawEvtHeader
38// MGeomCam
39// MPedestalCam
40//
41// Output Containers:
42// MPedestalCam
43//
44// This class should be used for pedestal extractors with the following facilities:
45// a) Standardized calculation of AB-noise, mean pedestals and RMS
46// b) Standardized treatment of area- and sector averaged pedestals values
47// c) Possibility to use a signal extractor to be applied on the pedestals
48// d) Possibility to handle two MPedestalCams: one for the signal extractor and
49// a second to be filled during the pedestal calculating process.
50//
51// ad a): Every calculated value is referred to one FADC slice (e.g. Mean pedestal per slice),
52// RMS per slice.
53// MExtractPedestal applies the following formula (1):
54//
55// Pedestal per slice = sum(x_i) / n / slices
56// PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
57// AB-Offset per slice = (sumAB0 - sumAB1) / n / slices
58//
59// where x_i is the sum of "slices" FADC slices and sum means the sum over all
60// events. "n" is the number of events, "slices" is the number of summed FADC samples.
61//
62// Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
63// asymmetric and they are correlated.
64//
65// It is important to know that the Pedestal per slice and PedRMS per slice depend
66// on the number of used FADC slices, as seen in the following plots:
67//
68//Begin_Html
69/*
70<img src="images/PedestalStudyInner.gif">
71*/
72//End_Html
73//
74//Begin_Html
75/*
76<img src="images/PedestalStudyOuter.gif">
77*/
78//End_Html
79//
80// The plots show the inner and outer pixels, respectivly and have the following meaning:
81//
82// 1) The calculated mean pedestal per slice (from MPedCalcPedRun)
83// 2) The fitted mean pedestal per slice (from MHPedestalCam)
84// 3) The calculated pedestal RMS per slice (from MPedCalcPedRun)
85// 4) The fitted sigma of the pedestal distribution per slice
86// (from MHPedestalCam)
87// 5) The relative difference between calculation and histogram fit
88// for the mean
89// 6) The relative difference between calculation and histogram fit
90// for the sigma or RMS, respectively.
91//
92// The calculated means do not change significantly except for the case of 2 slices,
93// however the RMS changes from 5.7 per slice in the case of 2 extracted slices
94// to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
95//
96// ad b) Every calculated value is referred to one FADC slice and one (averaged) pixel,
97// (e.g. Mean Pedestal per area index per slice per pixel, etc. )
98//
99// MExtractPedestal applies the following formula (2):
100//
101// Averaged Pedestal per slice = sum(x_i) / n / slices / n_pix
102// PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices / n_pix )
103// AB-Offset per slice = (sumAB0 - sumAB1) / n / slices / n_pix
104//
105// where x_i is the sum of "slices" FADC slices and sum means the sum over all
106// events and all concerned pixels.
107// "n" is the number of events, "slices" is the number of summed FADC samples and
108// "n_pix" is the number of pixels belonging to the specific area index or camera sector.
109//
110// Calculating these averaged event-by-event values is very important to trace coherent
111// fluctuations. An example is given in the following plots:
112//
113//Begin_Html
114/*
115<img src="images/PedestalOscillations.gif">
116*/
117//End_Html
118//
119// The plots show the extracted pedestals of the inner pixels (obtained
120// with MHPedestalCam), averaged on an event-by-event basis from
121// run 13428 with switched off camera LV.
122// The meaning of the four plots is:
123//
124// 1) The distribution of the averaged pedestals
125// 2) The averaged pedestals vs. time.
126// One can see clearly the oscillation pattern
127// 3) The fourier transform of the averaged pedestals vs. time.
128// One can see clearly a peak at a certain frequency
129// 4) The projection of the fourier components with the non-exponential
130// (and therefore significant) outlier.
131//
132// ad c) Many signal extractors, especially those using a sliding window
133// have biases and their resolutions for zero-signals do not agree
134// with the pedestal RMS. For the F-Factor method in the calibration
135// and the image cleaning, however, both have to be known and measured.
136//
137// For this reason, a signal extractor can be handed over to the
138// pedestal extractor and applied on the pedestal events with the
139// function SetExtractor().
140// The results will get stored in an MPedestalCam.
141//
142// Note that only extractors deriving from MExtractTimeAndCharge
143// can be used.
144//
145// ad d) The signal extractors themselves need a pedestal to be subtracted
146// from the FADC slices.
147// If the user wishes that the pededestals do not get overwritten by
148// the results from the signal extractor, a different named MPedestalCam
149// can be created with the function: SetNamePedestalOut().
150//
151// See also: MPedestalCam, MPedestalPix, MPedCalcPedRun, MPedCalcFromLoGain
152//
153/////////////////////////////////////////////////////////////////////////////
154#include "MExtractPedestal.h"
155
156#include "MParList.h"
157
158#include "MLog.h"
159#include "MLogManip.h"
160
161#include "MRawRunHeader.h"
162#include "MRawEvtHeader.h"
163#include "MRawEvtPixelIter.h"
164
165#include "MPedestalPix.h"
166#include "MPedestalCam.h"
167
168#include "MGeomPix.h"
169#include "MGeomCam.h"
170
171#include "MExtractTimeAndCharge.h"
172#include "MPedestalSubtractedEvt.h"
173
174ClassImp(MExtractPedestal);
175
176using namespace std;
177
178const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
179const TString MExtractPedestal::fgNameRawEvtData = "MRawEvtData";
180
181const UShort_t MExtractPedestal::fgCheckWinFirst = 0;
182const UShort_t MExtractPedestal::fgCheckWinLast = 29;
183const UShort_t MExtractPedestal::fgMaxSignalVar = 40;
184
185// --------------------------------------------------------------------------
186//
187// Default constructor:
188//
189// Sets:
190// - all pointers to NULL
191//
192// Calls:
193// - Clear()
194//
195MExtractPedestal::MExtractPedestal(const char *name, const char *title)
196 : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL),
197 fPedestalsOut(NULL), fExtractor(NULL), fSignal(0),
198 fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE)
199{
200 fName = name ? name : "MExtractPedestal";
201 fTitle = title ? title : "Base class to calculate pedestals";
202
203 SetIntermediateStorage( kFALSE );
204 SetRandomCalculation ( kTRUE );
205
206 SetNamePedestalCamIn();
207 SetNamePedestalCamOut();
208 SetNamePedestalCamInter();
209 SetNameRawEvtData();
210
211 SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
212 SetMaxSignalVar(fgMaxSignalVar);
213
214 Clear();
215}
216
217// --------------------------------------------------------------------------
218//
219// Call reset() of all Arays
220//
221void MExtractPedestal::ResetArrays()
222{
223 // Reset contents of arrays.
224 fSumx.Reset();
225 fSumx2.Reset();
226 fSumAB0.Reset();
227 fSumAB1.Reset();
228 fAreaSumx.Reset();
229 fAreaSumx2.Reset();
230 fAreaSumAB0.Reset();
231 fAreaSumAB1.Reset();
232 fAreaFilled.Reset();
233 fAreaValid.Reset();
234 fSectorSumx.Reset();
235 fSectorSumx2.Reset();
236 fSectorSumAB0.Reset();
237 fSectorSumAB1.Reset();
238 fSectorFilled.Reset();
239 fSectorValid.Reset();
240
241}
242
243// --------------------------------------------------------------------------
244//
245// Resets Arrays:
246//
247// Sets:
248// - fRawEvt to NULL
249// - fRunHeader to NULL
250//
251void MExtractPedestal::Clear(const Option_t *o)
252{
253
254 fRawEvt = NULL;
255 fRunHeader = NULL;
256
257 // If the size is yet set, set the size
258 if (fSumx.GetSize()>0)
259 ResetArrays();
260
261}
262
263// --------------------------------------------------------------------------
264//
265// Checks:
266// - if a window is odd
267//
268Bool_t MExtractPedestal::SetExtractWindow(UShort_t windowf, UShort_t windows)
269{
270 Bool_t rc = kTRUE;
271
272 if (windows==0)
273 {
274 *fLog << warn << GetDescriptor();
275 *fLog << " - WARNING: Window size in SetExtractWindow has to be > 0... adjusting to 2!" << endl;
276 windows = 2;
277 rc = kFALSE;
278 }
279
280 fExtractWinSize = windows;
281 fExtractWinFirst = windowf;
282 fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
283
284 return rc;
285}
286
287// --------------------------------------------------------------------------
288//
289// SetCheckRange:
290//
291// Exits, if the first argument is smaller than 0
292// Exits, if the the last argument is smaller than the first
293//
294Bool_t MExtractPedestal::SetCheckRange(UShort_t chfirst, UShort_t chlast)
295{
296
297 Bool_t rc = kTRUE;
298
299 if (chlast<=chfirst)
300 {
301 *fLog << warn << GetDescriptor();
302 *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;
303 chlast = chfirst+1;
304 rc = kFALSE;
305 }
306
307 fCheckWinFirst = chfirst;
308 fCheckWinLast = chlast;
309
310 return rc;
311}
312
313
314// --------------------------------------------------------------------------
315//
316// Check (and if neccesary: correct) the extraction and check ranges.
317//
318void MExtractPedestal::CheckExtractionWindow(UInt_t offset)
319{
320 // fSignal->GetNumSamples() not yet initialized!!!
321 const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain();
322
323 if (fCheckWinLast >= num)
324 {
325 *fLog << inf;
326 *fLog << "CheckWindow [" << fCheckWinFirst+offset << "," << fCheckWinLast+offset;
327 *fLog << "] out of range [0," << num-1 << "]... ";
328 *fLog << "reset upper edge." << endl;
329
330 fCheckWinLast = num-1;
331 }
332
333 if (offset+fExtractWinLast >= num)
334 {
335 *fLog << inf;
336 *fLog << "ExtractWindow [" << fExtractWinFirst+offset << "," << fExtractWinLast+offset;
337 *fLog << "] out of range [0," << num-1 << "]... ";
338 *fLog << "reset upper edge." << endl;
339
340 fExtractWinLast = num-offset-1;
341 }
342
343 fExtractWinSize = fExtractWinLast-fExtractWinFirst+1;
344
345 if (fExtractor || TMath::Even(fExtractWinSize))
346 return;
347
348 fExtractWinLast += offset+fExtractWinLast==num-1 ? -1 : +1;
349
350 *fLog << inf;
351 *fLog << "ExtractionWindow odd... set to [";
352 *fLog << fExtractWinFirst+offset << "," << fExtractWinLast+offset << "]" << endl;
353
354 fExtractWinSize = fExtractWinLast-fExtractWinFirst+1;
355}
356
357// --------------------------------------------------------------------------
358//
359// Look for the following input containers:
360//
361// - MRawEvtData
362// - MRawRunHeader
363// - MRawEvtHeader
364// - MGeomCam
365//
366// The following output containers are also searched and created if
367// they were not found:
368//
369// - MPedestalCam with the name fPedContainerName
370//
371Int_t MExtractPedestal::PreProcess(MParList *pList)
372{
373
374 Clear();
375
376 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber(fNameRawEvtData));
377 if (!fRawEvt)
378 if (!fUseSpecialPixels)
379 {
380 *fLog << err << AddSerialNumber(fNameRawEvtData) << " not found... aborting." << endl;
381 return kFALSE;
382 }
383
384
385 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
386 if (!fRawEvt)
387 {
388 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
389 return kFALSE;
390 }
391
392 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
393 if (!fRunHeader)
394 {
395 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
396 return kFALSE;
397 }
398
399 fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
400 if (!fGeom)
401 {
402 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
403 return kFALSE;
404 }
405
406 fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt"));
407 if (!fSignal)
408 {
409 *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl;
410 return kFALSE;
411 }
412
413 if (fExtractor && !fPedestalsIn)
414 {
415 fPedestalsIn = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamIn), "MPedestalCam");
416 if (!fPedestalsIn)
417 {
418 *fLog << err << AddSerialNumber(fNamePedestalCamIn) << " not found... aborting." << endl;
419 return kFALSE;
420 }
421 }
422
423 if (!fPedestalsInter && fIntermediateStorage)
424 {
425 fPedestalsInter = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamInter));
426 if (!fPedestalsInter)
427 return kFALSE;
428 }
429
430 if (!fPedestalsOut)
431 {
432 fPedestalsOut = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamOut));
433 if (!fPedestalsOut)
434 return kFALSE;
435 }
436
437 return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE;
438}
439
440//-----------------------------------------------------------------------
441//
442// Call Calc(). If fExtractor!=NULL enclose the call in setting the
443// NoiseCalculation to fRandomCalculation
444//
445Int_t MExtractPedestal::Process()
446{
447 //
448 // Necessary check for extraction of special pixels
449 // together with data which does not yet have them
450 //
451 if (fSumx.GetSize()==0)
452 return kTRUE;
453
454 if (fExtractor)
455 fExtractor->SetNoiseCalculation(fRandomCalculation);
456
457 const Int_t rc = Calc();
458
459 if (fExtractor)
460 fExtractor->SetNoiseCalculation(kFALSE);
461
462 return rc;
463}
464
465// ---------------------------------------------------------------------------------
466//
467// Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
468// - fSumx
469// - fSumx2
470// - fSumAB0
471// - fSumAB1
472// - fAreaSumx
473// - fAreaSumx2
474// - fAreaSumAB0
475// - fAreaSumAB1
476// - fAreaFilled
477// - fAreaValid
478// - fSectorSumx
479// - fSectorSumx2
480// - fSectorSumAB0
481// - fSectorSumAB1
482// - fSectorFilled
483// - fSectorValid
484//
485Bool_t MExtractPedestal::ReInit(MParList *pList)
486{
487 // Necessary check for special pixels which might not yet have existed
488 if (!fRawEvt)
489 {
490 if (fRunHeader->GetFormatVersion() > 3)
491 return kTRUE;
492
493 *fLog << err << "ERROR - " << fNameRawEvtData << " [MRawEvtData] has not ";
494 *fLog << "been found and format version > 3... abort." << endl;
495 return kFALSE;
496 }
497
498 // If the size is not yet set, set the size
499 if (fSumx.GetSize()==0)
500 {
501 // Initialize the normal pixels (size of MPedestalCam already set by MGeomApply)
502 const Int_t npixels = fPedestalsOut->GetSize();
503
504 fSumx. Set(npixels);
505 fSumx2. Set(npixels);
506 fSumAB0.Set(npixels);
507 fSumAB1.Set(npixels);
508
509 if (fUseSpecialPixels)
510 {
511 // Initialize size of MPedestalCam in case of special pixels (not done by MGeomApply)
512 const UShort_t nspecial = fRunHeader->GetNumSpecialPixels();
513 if (nspecial == 0)
514 {
515 *fLog << warn << "WARNING - Number of special pixels is 0." << endl;
516 return kTRUE;
517 }
518
519 fPedestalsOut->InitSize((UInt_t)nspecial);
520 }
521 else
522 {
523 // Initialize the averaged areas and sectors (do not exist for special pixels)
524 const Int_t areas = fPedestalsOut->GetNumAverageArea();
525 const Int_t sectors = fPedestalsOut->GetNumAverageSector();
526
527 fAreaSumx. Set(areas);
528 fAreaSumx2. Set(areas);
529 fAreaSumAB0.Set(areas);
530 fAreaSumAB1.Set(areas);
531 fAreaFilled.Set(areas);
532 fAreaValid .Set(areas);
533
534 fSectorSumx. Set(sectors);
535 fSectorSumx2. Set(sectors);
536 fSectorSumAB0.Set(sectors);
537 fSectorSumAB1.Set(sectors);
538 fSectorFilled.Set(sectors);
539 fSectorValid .Set(sectors);
540
541 for (Int_t i=0; i<npixels; i++)
542 {
543 const UInt_t aidx = (*fGeom)[i].GetAidx();
544 const UInt_t sector = (*fGeom)[i].GetSector();
545
546 fAreaValid [aidx] ++;
547 fSectorValid[sector]++;
548 }
549 }
550 }
551
552 if (fExtractor)
553 {
554 if (!fExtractor->ReInit(pList))
555 return kFALSE;
556
557 // If an extractor is set determin the window size automatically!
558 fExtractWinFirst = fExtractor->GetHiGainFirst();
559 fExtractWinLast = fExtractor->GetHiGainLast();
560
561 // fSignal->GetNumSamples() not yet initialized!!!
562 const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain();
563 if (fExtractWinLast >= num)
564 {
565 *fLog << err << GetDescriptor();
566 *fLog << " - ERROR: Selected fExtractWinLast out of range." << endl;
567 return kFALSE;
568 }
569 }
570
571 //CheckExtractionWindow();
572
573 return kTRUE;
574}
575
576// ---------------------------------------------------------------------------------
577//
578// PostProcess the extractor if available
579//
580Int_t MExtractPedestal::PostProcess()
581{
582 fPedestalsIn = NULL;
583 return fExtractor ? fExtractor->CallPostProcess() : kTRUE;
584}
585
586// ---------------------------------------------------------------------------------
587//
588// Check whether the signal variation between fCheckWinFirst and fCheckWinLast
589// exceeds fMaxSignalVar or the signal is greater than 250
590//
591Bool_t MExtractPedestal::CheckVariation(UInt_t idx) const
592{
593 // This is the fast workaround to put hi- and lo-gains together
594 Byte_t *slices = fSignal->GetSamplesRaw(idx);//pixel.GetSamples();
595
596 // Start 'real' work
597 UShort_t max = 0;
598 UShort_t min = (UShort_t)-1;
599
600 // Find the maximum and minimum signal per slice in the high gain window
601 for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
602 {
603 if (*slice > max)
604 max = *slice;
605 if (*slice < min)
606 min = *slice;
607 }
608
609 // If the maximum in the high gain window is smaller than
610 return max-min<fMaxSignalVar && max<250;
611}
612
613// ---------------------------------------------------------------------------------
614//
615// Invoke the hi-gain extraction starting at fExtractWinFirst+offset
616// for fExtractWinLast-fExtractWinFirst+1 slices. If Noise calculation
617// is set it is up to the signal extractor to do the right thing.
618//
619// Returns the extracted signal.
620//
621Float_t MExtractPedestal::CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const
622{
623 // Use the same extraction window as for signal extraction
624 const Int_t first = fExtractWinFirst;
625 const Int_t last = fExtractWinLast;
626
627 const Int_t start = first+offset;
628
629 const Int_t range = last-first+1;
630
631 // This check is already done in CheckExtractionWindow
632 // if (range>pixel.GetNumSamples()-start)
633 // range = pixel.GetNumSamples()-start;
634
635 const Int_t idx = pixel.GetPixelId();
636
637 // Do some handling if maxpos is last slice?
638 const Int_t maxposhi = fSignal->GetMax(idx, start, start+range-1);
639
640 const Float_t *sig = fSignal->GetSamples(idx);
641
642 // The pedestal is extracted with the hi-gain extractor (eg. digital
643 // filter weights) but from the lo-gains
644 Float_t dummy[3];
645 Float_t sum = 0;
646 fExtractor->FindTimeAndChargeHiGain2(sig+start, range, sum,
647 dummy[0], dummy[1], dummy[2],
648 0, maxposhi);
649 return sum;
650}
651
652// ---------------------------------------------------------------------------------
653//
654// Sum slices from fExtractWinFirst to fExtractWinLast. The total sum is
655// returned. ab0 and ab1 will contain the total sum splitted by the
656// AB-flag. If the AB-flag is invalid ab0=ab1=0 is returned.
657//
658UInt_t MExtractPedestal::CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const
659{
660 const Int_t first = fExtractWinFirst+offset;
661
662 Byte_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first;
663 Byte_t *end = ptr + fExtractWinSize;
664
665 Int_t abflag = pixel.HasABFlag() + first;
666
667 UInt_t ab[2] = { 0, 0 };
668 while (ptr<end)
669 ab[abflag++ & 0x1] += *ptr++;
670
671 // This check if for old data without AB-Flag in the data
672 const Bool_t valid = pixel.IsABFlagValid();
673
674 ab0 = valid ? ab[0] : 0;
675 ab1 = valid ? ab[1] : 0;
676
677 return ab[0]+ab[1];
678}
679
680// --------------------------------------------------------------------------
681//
682// The following resources are available:
683// ExtractWindowFirst: 15
684// ExtractWindowSize: 6
685// PedestalUpdate: yes
686// RandomCalculation: yes
687//
688Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
689{
690 Bool_t rc=kFALSE;
691
692 // find resource for fUseSpecialPixels
693 if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
694 {
695 SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
696 rc = kTRUE;
697 }
698
699 if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
700 {
701 SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
702 rc = kTRUE;
703 }
704
705 // find resource for random calculation
706 if (IsEnvDefined(env, prefix, "RandomCalculation", print))
707 {
708 SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
709 rc = kTRUE;
710 }
711
712 // Find resources for ExtractWindow
713 Int_t ef = fExtractWinFirst;
714 Int_t es = fExtractWinSize;
715 if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
716 {
717 ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
718 rc = kTRUE;
719 }
720 if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
721 {
722 es = GetEnvValue(env, prefix, "ExtractWinSize", es);
723 rc = kTRUE;
724 }
725
726 SetExtractWindow(ef,es);
727
728 // Find resources for CheckWindow
729 Int_t cfs = fCheckWinFirst;
730 Int_t cls = fCheckWinLast;
731 if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
732 {
733 cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs);
734 rc = kTRUE;
735 }
736 if (IsEnvDefined(env, prefix, "CheckWinLast", print))
737 {
738 cls = GetEnvValue(env, prefix, "CheckWinLast", cls);
739 rc = kTRUE;
740 }
741
742 SetCheckRange(cfs,cls);
743
744 // find resource for maximum signal variation
745 if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
746 {
747 SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
748 rc = kTRUE;
749 }
750
751 // find resource for MPedestalCam
752 if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
753 {
754 SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
755 rc = kTRUE;
756 }
757
758 if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
759 {
760 SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
761 rc = kTRUE;
762 }
763
764 if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
765 {
766 SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
767 rc = kTRUE;
768 }
769
770 return rc;
771}
772
773// ---------------------------------------------------------------------------------
774//
775// Calculates for pixel "idx":
776//
777// Ped per slice = sum / n / fExtractWinSize;
778// RMS per slice = sqrt { (sum2 - sum*sum/n) / (n-1) / fExtractWinSize }
779// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
780//
781// Stores the results in MPedestalCam[pixid]
782//
783void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
784{
785 const Double_t sum = fSumx[pixid];
786 const Double_t sum2 = fSumx2[pixid];
787
788 // 1. Calculate the mean of the sums:
789 Double_t ped = sum/nevts;
790
791 // 2. Calculate the Variance of the sums:
792 Double_t var = (sum2-sum*sum/nevts)/(nevts-1.);
793
794 // 3. Calculate the amplitude of the 150MHz "AB" noise
795 Double_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
796
797 // 4. Scale the mean, variance and AB-noise to the number of slices:
798 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
799 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
800 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
801 // The pedestal extracted with the extractor is divided by
802 // the number of hi-gain samples because the calibration
803 // multiplies by this number
804
805 // 5. Calculate the RMS from the Variance:
806 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
807
808 // abOffs contains only half of the signal as ped.
809 // Therefor abOffs is not the full, but the half amplitude
810 (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
811}
812
813// ---------------------------------------------------------------------------------
814//
815// Calculates for area idx "aidx" with "napix" valid pixels:
816//
817// Ped per slice = sum / nevts / fExtractWinSize / napix;
818// RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix }
819// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix;
820//
821// Stores the results in MPedestalCam::GetAverageArea(aidx)
822//
823void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
824{
825 const Double_t sum = fAreaSumx[aidx];
826 const Double_t sum2 = fAreaSumx2[aidx];
827
828 // 1. Calculate the mean of the sums:
829 Double_t ped = sum/nevts;
830
831 // 2. Calculate the Variance of the sums:
832 Double_t var = (sum2/napix-sum*sum/nevts)/(nevts-1.);
833
834 // 3. Calculate the amplitude of the 150MHz "AB" noise
835 Double_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
836
837 // 4. Scale the mean, variance and AB-noise to the number of slices:
838 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
839 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
840 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
841 // The pedestal extracted with the extractor is divided by
842 // the number of hi-gain samples because the calibration
843 // multiplies by this number
844
845 // 5. Scale the mean, variance and AB-noise to the number of pixels:
846 ped /= napix;
847 var /= napix;
848 abOffs /= napix;
849
850 // 6. Calculate the RMS from the Variance:
851 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
852
853 // abOffs contains only half of the signal as ped.
854 // Therefor abOffs is not the full, but the half amplitude
855 fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
856}
857
858// ---------------------------------------------------------------------------------
859//
860// Calculates for sector idx "sector" with "nspix" valid pixels:
861//
862// Ped per slice = sum / nevts / fExtractWinSize / nspix;
863// RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix }
864// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix;
865//
866// Stores the results in MPedestalCam::GetAverageSector(sector)
867//
868void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
869{
870 const Double_t sum = fSectorSumx[sector];
871 const Double_t sum2 = fSectorSumx2[sector];
872
873 // 1. Calculate the mean of the sums:
874 Double_t ped = sum/nevts;
875
876 // 2. Calculate the Variance of the sums:
877 Double_t var = (sum2/nspix-sum*sum/nevts)/(nevts-1.);
878
879 // 3. Calculate the amplitude of the 150MHz "AB" noise
880 Double_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
881
882 // 4. Scale the mean, variance and AB-noise to the number of slices:
883 ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
884 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
885 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
886 // The pedestal extracted with the extractor is divided by
887 // the number of hi-gain samples because the calibration
888 // multiplies by this number
889
890 // 5. Scale the mean, variance and AB-noise to the number of pixels:
891 ped /= nspix;
892 var /= nspix;
893 abOffs /= nspix;
894
895 // 6. Calculate the RMS from the Variance:
896 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
897
898 // abOffs contains only half of the signal as ped.
899 // Therefor abOffs is not the full, but the half amplitude
900 fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
901}
902
903//-----------------------------------------------------------------------
904//
905void MExtractPedestal::Print(Option_t *o) const
906{
907 *fLog << GetDescriptor() << ":" << endl;
908 *fLog << "Name of input MPedestalCam: " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
909 *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl;
910 *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
911 *fLog << "Intermediate Storage is " << (fIntermediateStorage?"on":"off") << endl;
912 *fLog << "Special pixel mode " << (fUseSpecialPixels?"on":"off") << endl;
913 if (fExtractor)
914 {
915 *fLog << "Extractor used: " << fExtractor->ClassName() << " (";
916 *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
917 }
918 *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << " incl." << endl;
919 *fLog << "CheckWindow from slice " << fCheckWinFirst << " to " << fCheckWinLast << " incl." << endl;
920 *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl;
921}
Note: See TracBrowser for help on using the repository browser.