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

Last change on this file since 4017 was 3778, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 17.6 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
113ClassImp(MHPedestalCam);
114
115using namespace std;
116// --------------------------------------------------------------------------
117//
118// Default constructor.
119//
120// Initializes:
121// - fExtractHiGainSlices to 0.
122// - fExtractLoGainSlices to 0.
123//
124MHPedestalCam::MHPedestalCam(const char *name, const char *title)
125 : fExtractHiGainSlices(0.), fExtractLoGainSlices(0.)
126{
127 fName = name ? name : "MHPedestalCam";
128 fTitle = title ? title : "";
129
130}
131
132
133
134// --------------------------------------------------------------------------
135//
136// Searches pointer to:
137// - MPedestalCam
138// - MExtractedSignalCam
139//
140// Searches or creates:
141// - MCalibrationPedCam
142//
143// Retrieves from MExtractedSignalCam:
144// - number of used High Gain FADC slices (MExtractedSignalCam::GetNumUsedHiGainFADCSlices())
145// - number of used Low Gain FADC slices (MExtractedSignalCam::GetNumUsedLoGainFADCSlices())
146//
147// Initializes, if empty to MGeomCam::GetNumPixels():
148// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
149//
150// Initializes, if empty to MGeomCam::GetNumAreas() for:
151// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
152//
153// Initializes, if empty to MGeomCam::GetNumSectors() for:
154// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
155//
156// Calls MHCalibrationCam::InitPedHists() for every entry in:
157// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
158// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
159// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
160//
161// Sets Titles and Names for the Histograms
162// - MHCalibrationCam::fAverageHiGainAreas
163// - MHCalibrationCam::fAverageHiGainSectors
164//
165// Sets number of bins to MHCalibrationCam::fAverageNbins for:
166// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
167// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
168//
169Bool_t MHPedestalCam::ReInitHists(MParList *pList)
170{
171
172 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
173 if (!signal)
174 {
175 gLog << err << "Cannot find MExtractedSignalCam... abort." << endl;
176 return kFALSE;
177 }
178
179
180 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
181
182 if (!fPedestals)
183 {
184 gLog << err << "Cannot find MPedestalCam ... abort." << endl;
185 return kFALSE;
186 }
187
188 const Int_t npixels = fGeom->GetNumPixels();
189 const Int_t nsectors = fGeom->GetNumSectors();
190 const Int_t nareas = fGeom->GetNumAreas();
191
192 fCam = (MCalibrationCam*)pList->FindObject("MCalibrationPedCam");
193 if (!fCam)
194 {
195 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationPedCam"));
196 if (!fCam)
197 return kFALSE;
198
199 fCam->Init(*fGeom);
200 }
201
202 Float_t sliceshi = signal->GetNumUsedHiGainFADCSlices();
203 Float_t sliceslo = signal->GetNumUsedLoGainFADCSlices();
204
205 if (sliceshi == 0.)
206 {
207 gLog << err << "Number of used signal slices in MExtractedSignalCam is zero ... abort."
208 << endl;
209 return kFALSE;
210 }
211
212 if (fExtractHiGainSlices != 0. && sliceshi != fExtractHiGainSlices )
213 {
214 gLog << err << "Number of used High Gain signal slices changed in MExtractedSignalCam ... abort."
215 << endl;
216 return kFALSE;
217 }
218
219 if (fExtractLoGainSlices != 0. && sliceslo != fExtractLoGainSlices )
220 {
221 gLog << err << "Number of used Low Gain signal slices changed in MExtractedSignalCam ... abort."
222 << endl;
223 return kFALSE;
224 }
225
226 fExtractHiGainSlices = sliceshi;
227 fExtractLoGainSlices = sliceslo;
228
229 if (fHiGainArray->GetEntries()==0)
230 {
231 fHiGainArray->Expand(npixels);
232 for (Int_t i=0; i<npixels; i++)
233 {
234 (*fHiGainArray)[i] = new MHPedestalPix;
235 InitPedHists((MHPedestalPix&)(*this)[i],i,fExtractHiGainSlices);
236
237 if ((*fBadPixels)[i].IsBad())
238 {
239 (*this)[i].SetExcluded();
240 }
241 (*fPedestals)[i].InitUseHists();
242 }
243
244 }
245
246 if (fLoGainArray->GetEntries()==0)
247 {
248 fLoGainArray->Expand(npixels);
249 for (Int_t i=0; i<npixels; i++)
250 {
251 (*fLoGainArray)[i] = new MHPedestalPix;
252 InitPedHists((MHPedestalPix&)(*this)(i),i,fExtractLoGainSlices);
253
254 if ((*fBadPixels)[i].IsBad())
255 (*this)(i).SetExcluded();
256 }
257 }
258
259 if (fAverageHiGainAreas->GetEntries()==0)
260 {
261 fAverageHiGainAreas->Expand(nareas);
262
263 for (Int_t j=0; j<nareas; j++)
264 {
265 (*fAverageHiGainAreas)[j] =
266 new MHPedestalPix("AverageHiGainArea",
267 "Average Pedestals area idx ");
268
269 InitPedHists((MHPedestalPix&)GetAverageHiGainArea(j),j,fExtractHiGainSlices);
270
271 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
272 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
273 }
274 }
275
276 if (fAverageLoGainAreas->GetEntries()==0)
277 {
278 fAverageLoGainAreas->Expand(nareas);
279
280 for (Int_t j=0; j<nareas; j++)
281 {
282 (*fAverageLoGainAreas)[j] =
283 new MHPedestalPix("AverageLoGainArea",
284 "Pedestals average Area idx ");
285
286 InitPedHists((MHPedestalPix&)GetAverageLoGainArea(j),j,fExtractLoGainSlices);
287
288 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
289 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
290 }
291 }
292
293 if (fAverageHiGainSectors->GetEntries()==0)
294 {
295 fAverageHiGainSectors->Expand(nsectors);
296
297 for (Int_t j=0; j<nsectors; j++)
298 {
299 (*fAverageHiGainSectors)[j] =
300 new MHPedestalPix("AverageHiGainSector",
301 "Pedestals average sector ");
302
303 InitPedHists((MHPedestalPix&)GetAverageHiGainSector(j),j,fExtractHiGainSlices);
304
305 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
306 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
307 }
308 }
309
310 if (fAverageLoGainSectors->GetEntries()==0)
311 {
312 fAverageLoGainSectors->Expand(nsectors);
313
314 for (Int_t j=0; j<nsectors; j++)
315 {
316 (*fAverageLoGainSectors)[j] =
317 new MHPedestalPix("AverageLoGainSector",
318 "Pedestals average sector ");
319
320 InitPedHists((MHPedestalPix&)GetAverageLoGainSector(j),j,fExtractLoGainSlices);
321
322 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
323 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
324 }
325 }
326
327 return kTRUE;
328}
329
330
331// -------------------------------------------------------------
332//
333// If MBadPixelsPix::IsBad():
334// - calls MHGausEvents::SetExcluded()
335//
336// Calls:
337// - MHGausEvents::InitBins()
338// - MHGausEvents::ChangeHistId(i)
339// - MHGausEvents::SetEventFrequency(fPulserFrequency)
340// - MHPedestalPix::SetNSlices(nslices)
341//
342void MHPedestalCam::InitPedHists(MHPedestalPix &hist, const Int_t i, const Float_t nslices)
343{
344 hist.InitBins();
345 hist.ChangeHistId(i);
346 hist.SetEventFrequency(fPulserFrequency);
347 hist.SetNSlices(nslices);
348 hist.SetProbLimit(0.);
349}
350
351
352
353// -------------------------------------------------------------------------------
354//
355// Retrieves pointer to MExtractedSignalCam:
356//
357// Retrieves from MGeomCam:
358// - number of pixels
359// - number of pixel areas
360// - number of sectors
361//
362// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
363// with the signals MExtractedSignalCam::GetExtractedSignalHiGain() and
364// MExtractedSignalCam::GetExtractedSignalLoGain(), respectively.
365//
366Bool_t MHPedestalCam::FillHists(const MParContainer *par, const Stat_t w)
367{
368
369 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
370 if (!signal)
371 {
372 gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
373 return kFALSE;
374 }
375
376 const UInt_t npixels = fGeom->GetNumPixels();
377 const UInt_t nareas = fGeom->GetNumAreas();
378 const UInt_t nsectors = fGeom->GetNumSectors();
379
380 TArrayF sumareahi(nareas);
381 TArrayF sumarealo(nareas);
382 TArrayF sumsectorhi(nsectors);
383 TArrayD sumsectorlo(nsectors);
384 TArrayI numareahi(nareas);
385 TArrayI numarealo(nareas);
386 TArrayI numsectorhi(nsectors);
387 TArrayI numsectorlo(nsectors);
388
389 for (UInt_t i=0; i<npixels; i++)
390 {
391 MHGausEvents &histhi = (*this)[i];
392 MHGausEvents &histlo = (*this)(i);
393
394 if (histhi.IsExcluded())
395 continue;
396
397 const MExtractedSignalPix &pix = (*signal)[i];
398
399 const Float_t pedhi = pix.GetExtractedSignalHiGain();
400 const Float_t pedlo = pix.GetExtractedSignalLoGain();
401
402 const Int_t aidx = (*fGeom)[i].GetAidx();
403 const Int_t sector = (*fGeom)[i].GetSector();
404
405 histhi.FillHistAndArray(pedhi) ;
406 sumareahi [aidx] += pedhi;
407 numareahi [aidx] ++;
408 sumsectorhi[sector] += pedhi;
409 numsectorhi[sector] ++;
410
411 histlo.FillHistAndArray(pedlo);
412 sumarealo [aidx] += pedlo;
413 numarealo [aidx] ++;
414 sumsectorlo[sector] += pedlo;
415 numsectorlo[sector] ++;
416
417 }
418
419 for (UInt_t j=0; j<nareas; j++)
420 {
421 MHGausEvents &histhi = GetAverageHiGainArea(j);
422 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
423
424 MHGausEvents &histlo = GetAverageLoGainArea(j);
425 histlo.FillHistAndArray(numarealo[j] == 0 ? 0. : sumarealo[j]/numarealo[j]);
426 }
427
428 for (UInt_t j=0; j<nsectors; j++)
429 {
430 MHGausEvents &histhi = GetAverageHiGainSector(j);
431 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
432
433 MHGausEvents &histlo = GetAverageLoGainSector(j);
434 histlo.FillHistAndArray(numsectorlo[j] == 0 ? 0. : sumsectorlo[j]/numsectorlo[j]);
435 }
436
437 return kTRUE;
438}
439
440// --------------------------------------------------------------------------
441//
442// Calls:
443// - MHCalibrationCam::FitHiGainArrays() with Bad Pixels flags 0
444// - MHCalibrationCam::FitLoGainArrays() with Bad Pixels flags 0
445//
446Bool_t MHPedestalCam::FinalizeHists()
447{
448
449 FitHiGainArrays((*fCam),*fBadPixels,
450 MBadPixelsPix::kHiGainNotFitted,
451 MBadPixelsPix::kHiGainOscillating);
452 FitLoGainArrays((*fCam),*fBadPixels,
453 MBadPixelsPix::kLoGainNotFitted,
454 MBadPixelsPix::kLoGainOscillating);
455
456
457 return kTRUE;
458
459
460}
461
462// ------------------------------------------------------------------
463//
464// The types are as follows:
465//
466// Fitted values:
467// ==============
468//
469// 0: Fitted Charge
470// 1: Error of fitted Charge
471// 2: Sigma of fitted Charge
472// 3: Error of Sigma of fitted Charge
473//
474//
475// Useful variables derived from the fit results:
476// =============================================
477//
478// 4: Returned probability of Gauss fit to Charge distribution
479// 5: Relative differenc of calculated pedestal (per slice) and fitted (per slice)
480// 6: Error of the Relative differenc of calculated pedestal (per slice) and fitted (per slice)
481// 7: Relative difference of the error of the mean pedestal (per slice) - calculated and fitted
482// 8: Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
483// 9: Error of Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
484// 10: Relative difference of the error of the pedestal RMS (per slice) - calculated and fitted
485//
486// Localized defects:
487// ==================
488//
489// 11: Gaus fit not OK
490// 12: Fourier spectrum not OK
491//
492Bool_t MHPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
493{
494
495 if (fHiGainArray->GetSize() <= idx)
496 return kFALSE;
497
498 if ((*this)[idx].IsExcluded())
499 return kFALSE;
500
501 const Float_t ped = (*fPedestals)[idx].GetPedestal();
502 const Float_t rms = (*fPedestals)[idx].GetPedestalRms();
503
504 const Float_t entsqr = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
505
506 const Float_t pederr = rms/entsqr;
507 const Float_t rmserr = rms/entsqr/2.;
508
509 const Float_t mean = (*this)[idx].GetMean();
510 const Float_t meanerr = (*this)[idx].GetMeanErr();
511 const Float_t sigma = (*this)[idx].GetSigma() ;
512 const Float_t sigmaerr = (*this)[idx].GetSigmaErr();
513
514 switch (type)
515 {
516 case 0:
517 val = mean;
518 break;
519 case 1:
520 val = meanerr;
521 break;
522 case 2:
523 val = sigma;
524 break;
525 case 3:
526 val = sigmaerr;
527 break;
528 case 4:
529 val = (*this)[idx].GetProb();
530 break;
531 case 5:
532 val = 2.*(mean-ped)/(ped+mean);
533 break;
534 case 6:
535 val = TMath::Sqrt((pederr*pederr + meanerr*meanerr) * (ped*ped + mean*mean))
536 *2./(ped+mean)/(ped+mean);
537 break;
538 case 7:
539 val = 2.*(meanerr-pederr)/(pederr + meanerr);
540 break;
541 case 8:
542 val = 2.*(sigma-rms)/(sigma+rms);
543 break;
544 case 9:
545 val = TMath::Sqrt((rmserr*rmserr + sigmaerr*sigmaerr) * (rms*rms + sigma*sigma))
546 *2./(rms+sigma)/(rms+sigma);
547 break;
548 case 10:
549 val = 2.*(sigmaerr - rmserr)/(sigmaerr + rmserr);
550 break;
551 case 11:
552 if (!(*this)[idx].IsGausFitOK())
553 val = 1.;
554 break;
555 case 12:
556 if (!(*this)[idx].IsFourierSpectrumOK())
557 val = 1.;
558 break;
559 default:
560 return kFALSE;
561 }
562 return kTRUE;
563}
564
565// --------------------------------------------------------------------------
566//
567// Calls MHGausEvents::DrawClone() for pixel idx
568//
569void MHPedestalCam::DrawPixelContent(Int_t idx) const
570{
571 (*this)[idx].DrawClone();
572}
Note: See TracBrowser for help on using the repository browser.