source: trunk/MagicSoft/Mars/manalysis/MHPedestalCam.cc@ 4733

Last change on this file since 4733 was 4317, checked in by gaug, 21 years ago
*** empty log message ***
File size: 17.8 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): Thomas Bretz 12/2000 <mailto:tbretz@atsro.uni-wuerzburh.de>
19! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHPedestalCam
29//
30// Fills the extracted pedestals of MExtractedSignalCam into
31// the MHGausEvents-classes MHPedestalPix for every:
32//
33// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
34// or MHCalibrationCam::fHiGainArray, respectively, depending if
35// MArrivalTimePix::IsLoGainUsed() is set.
36//
37// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
38// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
39// MHCalibrationCam::fAverageHiGainAreas
40//
41// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
42// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
43// and MHCalibrationCam::fAverageHiGainSectors
44//
45// Every pedestal is directly taken from MExtractedSignalCam, filled by the
46// appropriate extractor.
47//
48// The pedestals are filled into a histogram and an array, in order to perform
49// a Fourier analysis (see MHGausEvents). The signals are moreover averaged on an
50// event-by-event basis and written into the corresponding average pixels.
51//
52// The histograms are fitted to a Gaussian, mean and sigma with its errors
53// and the fit probability are extracted. If none of these values are NaN's and
54// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
55// the fit is declared valid.
56// Otherwise, the fit is repeated within ranges of the previous mean
57// +- MHGausEvents::fPickupLimit (default: 5) sigma (see MHGausEvents::RepeatFit())
58// In case this does not make the fit valid, the histogram means and RMS's are
59// taken directly (see MHGausEvents::BypassFit()).
60//
61// Outliers of more than MHGausEvents::fPickupLimit (default: 5) sigmas
62// from the mean are counted as Pickup events (stored in MHGausEvents::fPickup)
63//
64// The number of summed FADC slices is taken to re-normalize
65// the result to a pedestal per pixel with the formulas (see MHPedestalPix::Renorm()):
66// - Mean Pedestal / slice = Mean Pedestal / Number slices
67// - Mean Pedestal Error / slice = Mean Pedestal Error / Number slices
68// - Sigma Pedestal / slice = Sigma Pedestal / Sqrt (Number slices)
69// - Sigma Pedestal Error / slice = Sigma Pedestal Error / Sqrt (Number slices)
70//
71// The class also fills arrays with the signal vs. event number, creates a fourier
72// spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
73// projected fourier components follow an exponential distribution.
74//
75// This same procedure is performed for the average pixels.
76//
77// The following results are written into MPedestalCam:
78//
79// - MCalibrationPix::SetMean()
80// - MCalibrationPix::SetMeanErr()
81// - MCalibrationPix::SetSigma()
82// - MCalibrationPix::SetSigmaErr()
83// - MCalibrationPix::SetProb()
84// - MCalibrationPix::SetNumPickup()
85//
86// For all averaged areas, the fitted sigma is multiplied with the square root of
87// the number involved pixels in order to be able to compare it to the average of
88// sigmas in the camera.
89//
90/////////////////////////////////////////////////////////////////////////////
91#include "MHPedestalCam.h"
92#include "MHPedestalPix.h"
93
94#include "MBadPixelsCam.h"
95#include "MBadPixelsPix.h"
96
97#include "MLog.h"
98#include "MLogManip.h"
99
100#include "MParList.h"
101
102#include "MExtractedSignalCam.h"
103#include "MExtractedSignalPix.h"
104
105#include "MPedestalCam.h"
106#include "MPedestalPix.h"
107
108#include "MGeomCam.h"
109#include "MGeomPix.h"
110
111#include "MCalibrationPedCam.h"
112
113#include "TH1.h"
114
115ClassImp(MHPedestalCam);
116
117using namespace std;
118// --------------------------------------------------------------------------
119//
120// Default constructor.
121//
122// Initializes:
123// - fExtractHiGainSlices to 0.
124// - fExtractLoGainSlices to 0.
125// - the event frequency to 1200 Hz.
126// - the fRenorm flag to kTRUE
127//
128MHPedestalCam::MHPedestalCam(const char *name, const char *title)
129 : fExtractHiGainSlices(0.), fExtractLoGainSlices(0.)
130{
131 fName = name ? name : "MHPedestalCam";
132 fTitle = title ? title : "";
133
134 SetPulserFrequency(1200);
135 SetRenorm();
136}
137
138
139
140// --------------------------------------------------------------------------
141//
142// Searches pointer to:
143// - MPedestalCam
144// - MExtractedSignalCam
145//
146// Searches or creates:
147// - MCalibrationPedCam
148//
149// Retrieves from MExtractedSignalCam:
150// - number of used High Gain FADC slices (MExtractedSignalCam::GetNumUsedHiGainFADCSlices())
151// - number of used Low Gain FADC slices (MExtractedSignalCam::GetNumUsedLoGainFADCSlices())
152//
153// Initializes, if empty to MGeomCam::GetNumPixels():
154// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
155//
156// Initializes, if empty to MGeomCam::GetNumAreas() for:
157// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
158//
159// Initializes, if empty to MGeomCam::GetNumSectors() for:
160// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
161//
162// Calls MHCalibrationCam::InitPedHists() for every entry in:
163// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
164// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
165// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
166//
167// Sets Titles and Names for the Histograms
168// - MHCalibrationCam::fAverageHiGainAreas
169// - MHCalibrationCam::fAverageHiGainSectors
170//
171// Sets number of bins to MHCalibrationCam::fAverageNbins for:
172// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
173// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
174//
175Bool_t MHPedestalCam::ReInitHists(MParList *pList)
176{
177
178 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
179 if (!signal)
180 {
181 gLog << err << "Cannot find MExtractedSignalCam... abort." << endl;
182 return kFALSE;
183 }
184
185
186 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
187
188 if (!fPedestals)
189 {
190 gLog << err << "Cannot find MPedestalCam ... abort." << endl;
191 return kFALSE;
192 }
193
194 const Int_t npixels = fGeom->GetNumPixels();
195 const Int_t nsectors = fGeom->GetNumSectors();
196 const Int_t nareas = fGeom->GetNumAreas();
197
198 fCam = (MCalibrationCam*)pList->FindObject("MCalibrationPedCam");
199 if (!fCam)
200 {
201 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationPedCam"));
202 if (!fCam)
203 return kFALSE;
204
205 fCam->Init(*fGeom);
206 }
207
208 Float_t sliceshi = signal->GetNumUsedHiGainFADCSlices();
209 Float_t sliceslo = signal->GetNumUsedLoGainFADCSlices();
210
211 if (sliceshi == 0.)
212 {
213 gLog << err << "Number of used signal slices in MExtractedSignalCam is zero ... abort."
214 << endl;
215 return kFALSE;
216 }
217
218 if (fExtractHiGainSlices != 0. && sliceshi != fExtractHiGainSlices )
219 {
220 gLog << err << "Number of used High Gain signal slices changed in MExtractedSignalCam ... abort."
221 << endl;
222 return kFALSE;
223 }
224
225 if (fExtractLoGainSlices != 0. && sliceslo != fExtractLoGainSlices )
226 {
227 gLog << err << "Number of used Low Gain signal slices changed in MExtractedSignalCam ... abort."
228 << endl;
229 return kFALSE;
230 }
231
232 fExtractHiGainSlices = sliceshi;
233 fExtractLoGainSlices = sliceslo;
234
235 if (fHiGainArray->GetEntries()==0)
236 {
237 fHiGainArray->Expand(npixels);
238 for (Int_t i=0; i<npixels; i++)
239 {
240 (*fHiGainArray)[i] = new MHPedestalPix;
241 InitPedHists((MHPedestalPix&)(*this)[i],i,fExtractHiGainSlices);
242
243 if ((*fBadPixels)[i].IsBad())
244 (*this)[i].SetExcluded();
245
246 (*fPedestals)[i].InitUseHists();
247 }
248
249 }
250
251 if (fLoGainArray->GetEntries()==0)
252 {
253 fLoGainArray->Expand(npixels);
254 for (Int_t i=0; i<npixels; i++)
255 {
256 (*fLoGainArray)[i] = new MHPedestalPix;
257 InitPedHists((MHPedestalPix&)(*this)(i),i,fExtractLoGainSlices);
258
259 if ((*fBadPixels)[i].IsBad())
260 (*this)(i).SetExcluded();
261 }
262 }
263
264 if (fAverageHiGainAreas->GetEntries()==0)
265 {
266 fAverageHiGainAreas->Expand(nareas);
267
268 for (Int_t j=0; j<nareas; j++)
269 {
270 (*fAverageHiGainAreas)[j] =
271 new MHPedestalPix("AverageHiGainArea",
272 "Average Pedestals area idx ");
273
274 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
275 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
276
277 InitPedHists((MHPedestalPix&)GetAverageHiGainArea(j),j,fExtractHiGainSlices);
278
279 }
280 }
281
282 if (fAverageLoGainAreas->GetEntries()==0)
283 {
284 fAverageLoGainAreas->Expand(nareas);
285
286 for (Int_t j=0; j<nareas; j++)
287 {
288 (*fAverageLoGainAreas)[j] =
289 new MHPedestalPix("AverageLoGainArea",
290 "Pedestals average Area idx ");
291
292 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
293 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
294
295 InitPedHists((MHPedestalPix&)GetAverageLoGainArea(j),j,fExtractLoGainSlices);
296
297 }
298 }
299
300 if (fAverageHiGainSectors->GetEntries()==0)
301 {
302 fAverageHiGainSectors->Expand(nsectors);
303
304 for (Int_t j=0; j<nsectors; j++)
305 {
306 (*fAverageHiGainSectors)[j] =
307 new MHPedestalPix("AverageHiGainSector",
308 "Pedestals average sector ");
309
310 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
311 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
312
313 InitPedHists((MHPedestalPix&)GetAverageHiGainSector(j),j,fExtractHiGainSlices);
314
315 }
316 }
317
318 if (fAverageLoGainSectors->GetEntries()==0)
319 {
320 fAverageLoGainSectors->Expand(nsectors);
321
322 for (Int_t j=0; j<nsectors; j++)
323 {
324 (*fAverageLoGainSectors)[j] =
325 new MHPedestalPix("AverageLoGainSector",
326 "Pedestals average sector ");
327
328 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
329 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
330
331 InitPedHists((MHPedestalPix&)GetAverageLoGainSector(j),j,fExtractLoGainSlices);
332
333 }
334 }
335
336 return kTRUE;
337}
338
339
340// -------------------------------------------------------------
341//
342// If MBadPixelsPix::IsBad():
343// - calls MHGausEvents::SetExcluded()
344//
345// Calls:
346// - MHGausEvents::InitBins()
347// - MHGausEvents::ChangeHistId(i)
348// - MHGausEvents::SetEventFrequency(fPulserFrequency)
349// - MHPedestalPix::SetNSlices(nslices)
350//
351void MHPedestalCam::InitPedHists(MHPedestalPix &hist, const Int_t i, const Float_t nslices)
352{
353 hist.InitBins();
354 hist.ChangeHistId(i);
355 hist.SetEventFrequency(fPulserFrequency);
356
357 if (fRenorm)
358 hist.SetNSlices(nslices);
359
360 hist.SetProbLimit(0.);
361
362 TH1F *h = hist.GetHGausHist();
363 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
364}
365// -------------------------------------------------------------------------------
366//
367// Retrieves pointer to MExtractedSignalCam:
368//
369// Retrieves from MGeomCam:
370// - number of pixels
371// - number of pixel areas
372// - number of sectors
373//
374// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
375// with the signals MExtractedSignalCam::GetExtractedSignalHiGain() and
376// MExtractedSignalCam::GetExtractedSignalLoGain(), respectively.
377//
378Bool_t MHPedestalCam::FillHists(const MParContainer *par, const Stat_t w)
379{
380
381 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
382 if (!signal)
383 {
384 gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
385 return kFALSE;
386 }
387
388 const UInt_t npixels = fGeom->GetNumPixels();
389 const UInt_t nareas = fGeom->GetNumAreas();
390 const UInt_t nsectors = fGeom->GetNumSectors();
391
392 TArrayF sumareahi(nareas);
393 TArrayF sumarealo(nareas);
394 TArrayF sumsectorhi(nsectors);
395 TArrayD sumsectorlo(nsectors);
396 TArrayI numareahi(nareas);
397 TArrayI numarealo(nareas);
398 TArrayI numsectorhi(nsectors);
399 TArrayI numsectorlo(nsectors);
400
401 for (UInt_t i=0; i<npixels; i++)
402 {
403 MHGausEvents &histhi = (*this)[i];
404 MHGausEvents &histlo = (*this)(i);
405
406 if (histhi.IsExcluded())
407 continue;
408
409 const MExtractedSignalPix &pix = (*signal)[i];
410
411 const Float_t pedhi = pix.GetExtractedSignalHiGain();
412 const Float_t pedlo = pix.GetExtractedSignalLoGain();
413
414 const Int_t aidx = (*fGeom)[i].GetAidx();
415 const Int_t sector = (*fGeom)[i].GetSector();
416
417 histhi.FillHistAndArray(pedhi) ;
418 sumareahi [aidx] += pedhi;
419 numareahi [aidx] ++;
420 sumsectorhi[sector] += pedhi;
421 numsectorhi[sector] ++;
422
423 histlo.FillHistAndArray(pedlo);
424 sumarealo [aidx] += pedlo;
425 numarealo [aidx] ++;
426 sumsectorlo[sector] += pedlo;
427 numsectorlo[sector] ++;
428
429 }
430
431 for (UInt_t j=0; j<nareas; j++)
432 {
433 MHGausEvents &histhi = GetAverageHiGainArea(j);
434 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
435
436 MHGausEvents &histlo = GetAverageLoGainArea(j);
437 histlo.FillHistAndArray(numarealo[j] == 0 ? 0. : sumarealo[j]/numarealo[j]);
438 }
439
440 for (UInt_t j=0; j<nsectors; j++)
441 {
442 MHGausEvents &histhi = GetAverageHiGainSector(j);
443 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
444
445 MHGausEvents &histlo = GetAverageLoGainSector(j);
446 histlo.FillHistAndArray(numsectorlo[j] == 0 ? 0. : sumsectorlo[j]/numsectorlo[j]);
447 }
448
449 return kTRUE;
450}
451
452// --------------------------------------------------------------------------
453//
454// Calls:
455// - MHCalibrationCam::FitHiGainArrays() with Bad Pixels flags 0
456// - MHCalibrationCam::FitLoGainArrays() with Bad Pixels flags 0
457//
458Bool_t MHPedestalCam::FinalizeHists()
459{
460
461 FitHiGainArrays((*fCam),*fBadPixels,
462 MBadPixelsPix::kHiGainNotFitted,
463 MBadPixelsPix::kHiGainOscillating);
464 FitLoGainArrays((*fCam),*fBadPixels,
465 MBadPixelsPix::kLoGainNotFitted,
466 MBadPixelsPix::kLoGainOscillating);
467
468
469 return kTRUE;
470
471
472}
473
474// ------------------------------------------------------------------
475//
476// The types are as follows:
477//
478// Fitted values:
479// ==============
480//
481// 0: Fitted Charge
482// 1: Error of fitted Charge
483// 2: Sigma of fitted Charge
484// 3: Error of Sigma of fitted Charge
485//
486//
487// Useful variables derived from the fit results:
488// =============================================
489//
490// 4: Returned probability of Gauss fit to Charge distribution
491// 5: Relative differenc of calculated pedestal (per slice) and fitted (per slice)
492// 6: Error of the Relative differenc of calculated pedestal (per slice) and fitted (per slice)
493// 7: Relative difference of the error of the mean pedestal (per slice) - calculated and fitted
494// 8: Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
495// 9: Error of Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
496// 10: Relative difference of the error of the pedestal RMS (per slice) - calculated and fitted
497//
498// Localized defects:
499// ==================
500//
501// 11: Gaus fit not OK
502// 12: Fourier spectrum not OK
503//
504Bool_t MHPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
505{
506
507 if (fHiGainArray->GetSize() <= idx)
508 return kFALSE;
509
510 if ((*this)[idx].IsExcluded())
511 return kFALSE;
512
513 const Float_t ped = (*fPedestals)[idx].GetPedestal();
514 const Float_t rms = (*fPedestals)[idx].GetPedestalRms();
515
516 const Float_t entsqr = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
517
518 const Float_t pederr = rms/entsqr;
519 const Float_t rmserr = rms/entsqr/2.;
520
521 const Float_t mean = (*this)[idx].GetMean();
522 const Float_t meanerr = (*this)[idx].GetMeanErr();
523 const Float_t sigma = (*this)[idx].GetSigma() ;
524 const Float_t sigmaerr = (*this)[idx].GetSigmaErr();
525
526 switch (type)
527 {
528 case 0:
529 val = mean;
530 break;
531 case 1:
532 val = meanerr;
533 break;
534 case 2:
535 val = sigma;
536 break;
537 case 3:
538 val = sigmaerr;
539 break;
540 case 4:
541 val = (*this)[idx].GetProb();
542 break;
543 case 5:
544 val = 2.*(mean-ped)/(ped+mean);
545 break;
546 case 6:
547 val = TMath::Sqrt((pederr*pederr + meanerr*meanerr) * (ped*ped + mean*mean))
548 *2./(ped+mean)/(ped+mean);
549 break;
550 case 7:
551 val = 2.*(meanerr-pederr)/(pederr + meanerr);
552 break;
553 case 8:
554 val = 2.*(sigma-rms)/(sigma+rms);
555 break;
556 case 9:
557 val = TMath::Sqrt((rmserr*rmserr + sigmaerr*sigmaerr) * (rms*rms + sigma*sigma))
558 *2./(rms+sigma)/(rms+sigma);
559 break;
560 case 10:
561 val = 2.*(sigmaerr - rmserr)/(sigmaerr + rmserr);
562 break;
563 case 11:
564 if (!(*this)[idx].IsGausFitOK())
565 val = 1.;
566 break;
567 case 12:
568 if (!(*this)[idx].IsFourierSpectrumOK())
569 val = 1.;
570 break;
571 default:
572 return kFALSE;
573 }
574 return kTRUE;
575}
576
577// --------------------------------------------------------------------------
578//
579// Calls MHGausEvents::DrawClone() for pixel idx
580//
581void MHPedestalCam::DrawPixelContent(Int_t idx) const
582{
583 (*this)[idx].DrawClone();
584}
Note: See TracBrowser for help on using the repository browser.