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

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