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

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