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

Last change on this file since 4955 was 4947, checked in by gaug, 21 years ago
*** empty log message ***
File size: 17.4 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 MHCalibrationPix-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// +- MHCalibrationPix::fPickupLimit (default: 5) sigma (see MHCalibrationPix::RepeatFit())
58// In case this does not make the fit valid, the histogram means and RMS's are
59// taken directly (see MHCalibrationPix::BypassFit()).
60//
61// Outliers of more than MHCalibrationPix::fPickupLimit (default: 5) sigmas
62// from the mean are counted as Pickup events (stored in MHCalibrationPix::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//
171Bool_t MHPedestalCam::ReInitHists(MParList *pList)
172{
173
174 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
175 if (!signal)
176 {
177 gLog << err << "Cannot find MExtractedSignalCam... abort." << endl;
178 return kFALSE;
179 }
180
181
182 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
183
184 if (!fPedestals)
185 {
186 gLog << err << "Cannot find MPedestalCam ... abort." << endl;
187 return kFALSE;
188 }
189
190 const Int_t npixels = fGeom->GetNumPixels();
191 const Int_t nsectors = fGeom->GetNumSectors();
192 const Int_t nareas = fGeom->GetNumAreas();
193
194 fCam = (MCalibrationCam*)pList->FindObject("MCalibrationPedCam");
195 if (!fCam)
196 {
197 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationPedCam"));
198 if (!fCam)
199 return kFALSE;
200
201 fCam->Init(*fGeom);
202 }
203
204 Float_t sliceshi = signal->GetNumUsedHiGainFADCSlices();
205 Float_t sliceslo = signal->GetNumUsedLoGainFADCSlices();
206
207 if (sliceshi == 0.)
208 {
209 gLog << err << "Number of used signal slices in MExtractedSignalCam is zero ... abort."
210 << endl;
211 return kFALSE;
212 }
213
214 if (fExtractHiGainSlices != 0. && sliceshi != fExtractHiGainSlices )
215 {
216 gLog << err << "Number of used High Gain signal slices changed in MExtractedSignalCam ... abort."
217 << endl;
218 return kFALSE;
219 }
220
221 if (fExtractLoGainSlices != 0. && sliceslo != fExtractLoGainSlices )
222 {
223 gLog << err << "Number of used Low Gain signal slices changed in MExtractedSignalCam ... abort."
224 << endl;
225 return kFALSE;
226 }
227
228 fExtractHiGainSlices = sliceshi;
229 fExtractLoGainSlices = sliceslo;
230
231 if (fHiGainArray->GetEntries()==0)
232 {
233 fHiGainArray->Expand(npixels);
234 for (Int_t i=0; i<npixels; i++)
235 {
236 (*fHiGainArray)[i] = new MHPedestalPix;
237 InitPedHists((MHPedestalPix&)(*this)[i],i,fExtractHiGainSlices);
238
239 if ((*fBadPixels)[i].IsBad())
240 (*this)[i].SetExcluded();
241
242 (*fPedestals)[i].InitUseHists();
243 }
244
245 }
246
247 if (fLoGainArray->GetEntries()==0)
248 {
249 fLoGainArray->Expand(npixels);
250 for (Int_t i=0; i<npixels; i++)
251 {
252 (*fLoGainArray)[i] = new MHPedestalPix;
253 InitPedHists((MHPedestalPix&)(*this)(i),i,fExtractLoGainSlices);
254
255 if ((*fBadPixels)[i].IsBad())
256 (*this)(i).SetExcluded();
257 }
258 }
259
260 if (fAverageHiGainAreas->GetEntries()==0)
261 {
262 fAverageHiGainAreas->Expand(nareas);
263
264 for (Int_t j=0; j<nareas; j++)
265 {
266 (*fAverageHiGainAreas)[j] =
267 new MHPedestalPix("AverageHiGainArea",
268 "Average Pedestals area idx ");
269
270 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
271
272 InitPedHists((MHPedestalPix&)GetAverageHiGainArea(j),j,fExtractHiGainSlices);
273
274 }
275 }
276
277 if (fAverageLoGainAreas->GetEntries()==0)
278 {
279 fAverageLoGainAreas->Expand(nareas);
280
281 for (Int_t j=0; j<nareas; j++)
282 {
283 (*fAverageLoGainAreas)[j] =
284 new MHPedestalPix("AverageLoGainArea",
285 "Pedestals average Area idx ");
286
287 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Pedestals average Area Idx ");
288
289 InitPedHists((MHPedestalPix&)GetAverageLoGainArea(j),j,fExtractLoGainSlices);
290
291 }
292 }
293
294 if (fAverageHiGainSectors->GetEntries()==0)
295 {
296 fAverageHiGainSectors->Expand(nsectors);
297
298 for (Int_t j=0; j<nsectors; j++)
299 {
300 (*fAverageHiGainSectors)[j] =
301 new MHPedestalPix("AverageHiGainSector",
302 "Pedestals average sector ");
303
304 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
305
306 InitPedHists((MHPedestalPix&)GetAverageHiGainSector(j),j,fExtractHiGainSlices);
307
308 }
309 }
310
311 if (fAverageLoGainSectors->GetEntries()==0)
312 {
313 fAverageLoGainSectors->Expand(nsectors);
314
315 for (Int_t j=0; j<nsectors; j++)
316 {
317 (*fAverageLoGainSectors)[j] =
318 new MHPedestalPix("AverageLoGainSector",
319 "Pedestals average sector ");
320
321 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Pedestals average Sector ");
322
323 InitPedHists((MHPedestalPix&)GetAverageLoGainSector(j),j,fExtractLoGainSlices);
324
325 }
326 }
327
328 return kTRUE;
329}
330
331
332// -------------------------------------------------------------
333//
334// If MBadPixelsPix::IsBad():
335// - calls MHCalibrationPix::SetExcluded()
336//
337// Calls:
338// - MHGausEvents::InitBins()
339// - MHCalibrationPix::ChangeHistId(i)
340// - MHCalibrationPix::SetEventFrequency(fPulserFrequency)
341// - MHPedestalPix::SetNSlices(nslices)
342//
343void MHPedestalCam::InitPedHists(MHPedestalPix &hist, const Int_t i, const Float_t nslices)
344{
345
346 hist.InitBins();
347 hist.ChangeHistId(i);
348 hist.SetEventFrequency(fPulserFrequency);
349
350 if (fRenorm)
351 hist.SetNSlices(nslices);
352
353 hist.SetProbLimit(0.);
354
355 TH1F *h = hist.GetHGausHist();
356 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
357}
358// -------------------------------------------------------------------------------
359//
360// Retrieves pointer to MExtractedSignalCam:
361//
362// Retrieves from MGeomCam:
363// - number of pixels
364// - number of pixel areas
365// - number of sectors
366//
367// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
368// with the signals MExtractedSignalCam::GetExtractedSignalHiGain() and
369// MExtractedSignalCam::GetExtractedSignalLoGain(), respectively.
370//
371Bool_t MHPedestalCam::FillHists(const MParContainer *par, const Stat_t w)
372{
373
374 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
375 if (!signal)
376 {
377 gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
378 return kFALSE;
379 }
380
381 const UInt_t npixels = fGeom->GetNumPixels();
382 const UInt_t nareas = fGeom->GetNumAreas();
383 const UInt_t nsectors = fGeom->GetNumSectors();
384
385 TArrayF sumareahi(nareas);
386 TArrayF sumarealo(nareas);
387 TArrayF sumsectorhi(nsectors);
388 TArrayD sumsectorlo(nsectors);
389 TArrayI numareahi(nareas);
390 TArrayI numarealo(nareas);
391 TArrayI numsectorhi(nsectors);
392 TArrayI numsectorlo(nsectors);
393
394 for (UInt_t i=0; i<npixels; i++)
395 {
396 MHCalibrationPix &histhi = (*this)[i];
397 MHCalibrationPix &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 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
427 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
428
429 MHCalibrationPix &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 MHCalibrationPix &histhi = GetAverageHiGainSector(j);
436 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
437
438 MHCalibrationPix &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
462 return kTRUE;
463
464
465}
466
467// ------------------------------------------------------------------
468//
469// The types are as follows:
470//
471// Fitted values:
472// ==============
473//
474// 0: Fitted Charge
475// 1: Error of fitted Charge
476// 2: Sigma of fitted Charge
477// 3: Error of Sigma of fitted Charge
478//
479//
480// Useful variables derived from the fit results:
481// =============================================
482//
483// 4: Returned probability of Gauss fit to Charge distribution
484// 5: Relative differenc of calculated pedestal (per slice) and fitted (per slice)
485// 6: Error of the Relative differenc of calculated pedestal (per slice) and fitted (per slice)
486// 7: Relative difference of the error of the mean pedestal (per slice) - calculated and fitted
487// 8: Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
488// 9: Error of Relative differenc of calculated pedestal RMS (per slice) and fitted sigma (per slice)
489// 10: Relative difference of the error of the pedestal RMS (per slice) - calculated and fitted
490//
491// Localized defects:
492// ==================
493//
494// 11: Gaus fit not OK
495// 12: Fourier spectrum not OK
496//
497Bool_t MHPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
498{
499
500 if (fHiGainArray->GetSize() <= idx)
501 return kFALSE;
502
503 if ((*this)[idx].IsExcluded())
504 return kFALSE;
505
506 const Float_t ped = (*fPedestals)[idx].GetPedestal();
507 const Float_t rms = (*fPedestals)[idx].GetPedestalRms();
508
509 const Float_t entsqr = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
510
511 const Float_t pederr = rms/entsqr;
512 const Float_t rmserr = rms/entsqr/2.;
513
514 const Float_t mean = (*this)[idx].GetMean();
515 const Float_t meanerr = (*this)[idx].GetMeanErr();
516 const Float_t sigma = (*this)[idx].GetSigma() ;
517 const Float_t sigmaerr = (*this)[idx].GetSigmaErr();
518
519 switch (type)
520 {
521 case 0:
522 val = mean;
523 break;
524 case 1:
525 val = meanerr;
526 break;
527 case 2:
528 val = sigma;
529 break;
530 case 3:
531 val = sigmaerr;
532 break;
533 case 4:
534 val = (*this)[idx].GetProb();
535 break;
536 case 5:
537 val = 2.*(mean-ped)/(ped+mean);
538 break;
539 case 6:
540 val = TMath::Sqrt((pederr*pederr + meanerr*meanerr) * (ped*ped + mean*mean))
541 *2./(ped+mean)/(ped+mean);
542 break;
543 case 7:
544 val = 2.*(meanerr-pederr)/(pederr + meanerr);
545 break;
546 case 8:
547 val = 2.*(sigma-rms)/(sigma+rms);
548 break;
549 case 9:
550 val = TMath::Sqrt((rmserr*rmserr + sigmaerr*sigmaerr) * (rms*rms + sigma*sigma))
551 *2./(rms+sigma)/(rms+sigma);
552 break;
553 case 10:
554 val = 2.*(sigmaerr - rmserr)/(sigmaerr + rmserr);
555 break;
556 case 11:
557 if (!(*this)[idx].IsGausFitOK())
558 val = 1.;
559 break;
560 case 12:
561 if (!(*this)[idx].IsFourierSpectrumOK())
562 val = 1.;
563 break;
564 default:
565 return kFALSE;
566 }
567 return kTRUE;
568}
569
570// --------------------------------------------------------------------------
571//
572// Calls MHGausEvents::DrawClone() for pixel idx
573//
574void MHPedestalCam::DrawPixelContent(Int_t idx) const
575{
576 (*this)[idx].DrawClone();
577}
Note: See TracBrowser for help on using the repository browser.