source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.cc@ 6000

Last change on this file since 6000 was 5946, checked in by mazin, 20 years ago
*** empty log message ***
File size: 18.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): Markus Gaug 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24/////////////////////////////////////////////////////////////////////////////
25//
26// MHCalibrationHiLoCam
27//
28// Fills the extracted high-gain low-gain charge ratios of MArrivalTimeCam into
29// the MHCalibrationPix-classes MHCalibrationPix for every:
30//
31// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
32// or MHCalibrationCam::fHiGainArray, respectively, depending if
33// MArrivalTimePix::IsLoGainUsed() is set.
34//
35// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
36// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
37// MHCalibrationCam::fAverageHiGainAreas
38//
39// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
40// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
41// and MHCalibrationCam::fAverageHiGainSectors
42//
43// The histograms are fitted to a Gaussian, mean and sigma with its errors
44// and the fit probability are extracted. If none of these values are NaN's and
45// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
46// the fit is declared valid.
47// Otherwise, the fit is repeated within ranges of the previous mean
48// +- MHCalibrationPix::fPickupLimit (default: 5) sigma (see MHCalibrationPix::RepeatFit())
49// In case this does not make the fit valid, the histogram means and RMS's are
50// taken directly (see MHCalibrationPix::BypassFit()) and the following flags are set:
51// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiLoNotFitted ) and
52// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
53//
54// Outliers of more than MHCalibrationPix::fPickupLimit (default: 5) sigmas
55// from the mean are counted as Pickup events (stored in MHCalibrationPix::fPickup)
56//
57// The class also fills arrays with the signal vs. event number, creates a fourier
58// spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
59// projected fourier components follow an exponential distribution.
60// In case that the probability of the exponential fit is less than
61// MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
62// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiLoOscillating ) and
63// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
64//
65// This same procedure is performed for the average pixels.
66//
67// The following results are written into MCalibrationHiLoCam:
68//
69// - MCalibrationPix::SetMean()
70// - MCalibrationPix::SetMeanErr()
71// - MCalibrationPix::SetSigma()
72// - MCalibrationPix::SetSigmaErr()
73// - MCalibrationPix::SetProb()
74// - MCalibrationPix::SetNumPickup()
75//
76// For all averaged areas, the fitted sigma is multiplied with the square root of
77// the number involved pixels in order to be able to compare it to the average of
78// sigmas in the camera.
79//
80/////////////////////////////////////////////////////////////////////////////
81#include "MHCalibrationHiLoCam.h"
82#include "MHCalibrationPix.h"
83
84#include "MLog.h"
85#include "MLogManip.h"
86
87#include "MParList.h"
88
89#include "MCalibrationIntensityHiLoCam.h"
90
91#include "MCalibrationHiLoCam.h"
92#include "MCalibrationCam.h"
93#include "MCalibrationPix.h"
94
95#include "MExtractedSignalCam.h"
96#include "MExtractedSignalPix.h"
97#include "MArrivalTimeCam.h"
98#include "MArrivalTimePix.h"
99
100#include "MGeomCam.h"
101#include "MGeomPix.h"
102
103#include "MBadPixelsIntensityCam.h"
104#include "MBadPixelsCam.h"
105#include "MBadPixelsPix.h"
106
107#include <TOrdCollection.h>
108#include <TPad.h>
109#include <TVirtualPad.h>
110#include <TCanvas.h>
111#include <TStyle.h>
112#include <TF1.h>
113#include <TLine.h>
114#include <TLatex.h>
115#include <TLegend.h>
116#include <TGraph.h>
117
118ClassImp(MHCalibrationHiLoCam);
119
120using namespace std;
121
122const Int_t MHCalibrationHiLoCam::fgNbins = 200;
123const Axis_t MHCalibrationHiLoCam::fgFirst = 0.;
124const Axis_t MHCalibrationHiLoCam::fgLast = 20.;
125const Float_t MHCalibrationHiLoCam::fgProbLimit = 0.;
126const TString MHCalibrationHiLoCam::gsHistName = "HiLo";
127const TString MHCalibrationHiLoCam::gsHistTitle = "HiGain vs. LoGain";
128const TString MHCalibrationHiLoCam::gsHistXTitle = "Amplification Ratio [1]";
129const TString MHCalibrationHiLoCam::gsHistYTitle = "Nr. events";
130// --------------------------------------------------------------------------
131//
132// Default Constructor.
133//
134// Sets:
135// - fNbins to fgNbins
136// - fFirst to fgFirst
137// - fLast to fgLast
138//
139// - fHistName to gsHistName
140// - fHistTitle to gsHistTitle
141// - fHistXTitle to gsHistXTitle
142// - fHistYTitle to gsHistYTitle
143//
144// - fLowerLimt to fgLowerLim
145// - fUpperLimt to fgUpperLim
146//
147MHCalibrationHiLoCam::MHCalibrationHiLoCam(const char *name, const char *title)
148{
149
150 fName = name ? name : "MHCalibrationHiLoCam";
151 fTitle = title ? title : "Histogram class for the high-gain vs. low-gain amplification ratio calibration";
152
153 SetNbins(fgNbins);
154 SetFirst(fgFirst);
155 SetLast (fgLast );
156
157 SetProbLimit(fgProbLimit);
158
159 SetHistName (gsHistName .Data());
160 SetHistTitle (gsHistTitle .Data());
161 SetHistXTitle(gsHistXTitle.Data());
162 SetHistYTitle(gsHistYTitle.Data());
163
164}
165
166// --------------------------------------------------------------------------
167//
168// Creates new MHCalibrationHiLoCam only with the averaged areas:
169// the rest has to be retrieved directly, e.g. via:
170// MHCalibrationHiLoCam *cam = MParList::FindObject("MHCalibrationHiLoCam");
171// - cam->GetAverageSector(5).DrawClone();
172// - (*cam)[100].DrawClone()
173//
174TObject *MHCalibrationHiLoCam::Clone(const char *) const
175{
176
177 MHCalibrationHiLoCam *cam = new MHCalibrationHiLoCam();
178
179 //
180 // Copy the data members
181 //
182 cam->fColor = fColor;
183 cam->fRunNumbers = fRunNumbers;
184 cam->fPulserFrequency = fPulserFrequency;
185 cam->fFlags = fFlags;
186 cam->fNbins = fNbins;
187 cam->fFirst = fFirst;
188 cam->fLast = fLast;
189
190 //
191 // Copy the MArrays
192 //
193 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
194 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
195 cam->fAverageAreaSat = fAverageAreaSat;
196 cam->fAverageAreaSigma = fAverageAreaSigma;
197 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
198 cam->fAverageAreaNum = fAverageAreaNum;
199 cam->fAverageSectorNum = fAverageSectorNum;
200
201 if (!IsAverageing())
202 return cam;
203
204 const Int_t navhi = fAverageHiGainAreas->GetSize();
205 const Int_t navlo = fAverageLoGainAreas->GetSize();
206
207 for (int i=0; i<navhi; i++)
208 cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
209
210 for (int i=0; i<navlo; i++)
211 cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
212
213 return cam;
214}
215
216// --------------------------------------------------------------------------
217//
218// Gets or creates the pointers to:
219// - MCalibrationHiLoCam
220//
221// Searches pointer to:
222// - MExtractedSignalCam
223// - MArrivalTimeCam
224//
225// Calls:
226// - MHCalibrationCam::InitHiGainArrays()
227// - MHCalibrationCam::InitLoGainArrays()
228//
229// Sets:
230// - fSumarea to nareas
231// - fSumsector to nareas
232// - fNumarea to nareas
233// - fNumsector to nareas
234//
235Bool_t MHCalibrationHiLoCam::ReInitHists(MParList *pList)
236{
237
238 if (!InitCams(pList,"HiLo"))
239 return kFALSE;
240
241 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
242 if (!signal)
243 {
244 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
245 return kFALSE;
246 }
247
248 MArrivalTimeCam *times = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
249 if (!times)
250 {
251 *fLog << warn << "MArrivalTimeCam not found... cannot calibrated arrival times between "
252 <<"high and low-gain" << endl;
253 SetLoGain(kFALSE);
254 }
255
256 const Int_t npixels = fGeom->GetNumPixels();
257 const Int_t nsectors = fGeom->GetNumSectors();
258 const Int_t nareas = fGeom->GetNumAreas();
259
260 InitHiGainArrays(npixels,nareas,nsectors);
261 InitLoGainArrays(npixels,nareas,nsectors);
262
263 fSumareahi .Set(nareas);
264 fSumsectorhi.Set(nsectors);
265 fNumareahi .Set(nareas);
266 fNumsectorhi.Set(nsectors);
267 if (IsLoGain())
268 {
269 fSumarealo .Set(nareas);
270 fSumsectorlo.Set(nsectors);
271 fNumarealo .Set(nareas);
272 fNumsectorlo.Set(nsectors);
273 }
274 return kTRUE;
275}
276
277// -------------------------------------------------------------------------------
278//
279// Retrieves pointer to MExtractedSignalCam:
280//
281// Retrieves from MGeomCam:
282// - number of pixels
283// - number of pixel areas
284// - number of sectors
285//
286// Fills histograms (MHGausEvents::FillHistAndArray()) with:
287// - MExtractedSignalPix::GetExtractedSignalHiGain(pixid) / MExtractedSignalPix::GetExtractedSignalLoGain;
288// if the high-gain signal does not show high-gain saturation, but the low-gain
289// has been extracted.
290// - MArrivalTimePix::GetArrivalTimeHiGain(pixid) / MArrivalTimePix::GetArrivalTimeLoGain;
291// if the high-gain signal does not show high-gain saturation, but the low-gain
292// has been extracted.
293//
294Bool_t MHCalibrationHiLoCam::FillHists(const MParContainer *par, const Stat_t w)
295{
296
297 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
298 if (!signal)
299 {
300 gLog << err << "No argument in MExtractedSignal::Fill... abort." << endl;
301 return kFALSE;
302 }
303
304 MArrivalTimeCam *times = (MArrivalTimeCam*)par;
305
306 const Int_t npixels = fGeom->GetNumPixels();
307 const Int_t nareas = fGeom->GetNumAreas();
308 const Int_t nsectors = fGeom->GetNumSectors();
309
310 fSumareahi .Reset();
311 fSumsectorhi.Reset();
312 fNumareahi .Reset();
313 fNumsectorhi.Reset();
314 fSumarealo .Reset();
315 fSumsectorlo.Reset();
316 fNumarealo .Reset();
317 fNumsectorlo.Reset();
318
319 for (Int_t i=0; i<npixels; i++)
320 {
321 const MExtractedSignalPix &pix = (*signal)[i];
322 const Int_t aidx = (*fGeom)[i].GetAidx();
323 const Int_t sector = (*fGeom)[i].GetSector();
324
325 const Float_t siglo = pix.GetExtractedSignalLoGain();
326
327 //
328 // Skip all pixels with:
329 // - Saturated high-gain
330 // - Not extracted low-gain
331 // (see MExtractTimeAndCharge::fLoGainSwitch for setting the criteria)
332 //
333 if (siglo < 0.5 || pix.GetNumHiGainSaturated() > 0)
334 continue;
335
336 const Float_t sighi = pix.GetExtractedSignalHiGain();
337 const Float_t ratio = sighi / siglo;
338
339 MHCalibrationPix &histhi = (*this)[i];
340
341 histhi.FillHistAndArray(ratio);
342 fSumareahi [aidx] += ratio;
343 fNumareahi [aidx] ++;
344 fSumsectorhi[sector] += ratio;
345 fNumsectorhi[sector] ++;
346
347 if (IsLoGain())
348 {
349 const MArrivalTimePix &tix = (*times)[i];
350 MHCalibrationPix &histlo = (*this)(i);
351
352 const Float_t diff = tix.GetArrivalTimeLoGain() - tix.GetArrivalTimeHiGain();
353
354 histlo.FillHistAndArray(diff);
355 fSumarealo [aidx] += diff;
356 fNumarealo [aidx] ++;
357 fSumsectorlo[sector] += diff;
358 fNumsectorlo[sector] ++;
359 }
360 }
361
362 for (Int_t j=0; j<nareas; j++)
363 {
364 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
365 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
366
367 if (IsLoGain())
368 {
369 MHCalibrationPix &histlo = GetAverageLoGainArea(j);
370 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
371 }
372 }
373
374 for (Int_t j=0; j<nsectors; j++)
375 {
376 MHCalibrationPix &hist = GetAverageHiGainSector(j);
377 hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
378
379 if (IsLoGain())
380 {
381 MHCalibrationPix &histlo = GetAverageLoGainSector(j);
382 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
383 }
384 }
385
386 return kTRUE;
387}
388
389// --------------------------------------------------------------------------
390//
391// Calls:
392// - MHCalibrationCam::FitHiGainArrays() with flags:
393// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
394// - MHCalibrationCam::FitLoGainArrays() with flags:
395// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
396//
397Bool_t MHCalibrationHiLoCam::FinalizeHists()
398{
399
400 *fLog << endl;
401
402 MCalibrationCam *hilocam = fIntensCam ? fIntensCam->GetCam() : fCam;
403 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
404
405 const Int_t nareas = fAverageHiGainAreas->GetSize();
406 const Int_t nsectors = fAverageHiGainSectors->GetSize();
407
408 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
409 {
410
411 MHCalibrationPix &hist = (*this)[i];
412
413 if (hist.IsExcluded())
414 continue;
415
416 CheckOverflow(hist);
417 }
418
419 for (Int_t j=0; j<nareas; j++)
420 {
421
422 MHCalibrationPix &hist = GetAverageHiGainArea(j);
423 //
424 // Check histogram overflow
425 //
426 CheckOverflow(hist);
427 }
428
429 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
430 {
431
432 MHCalibrationPix &hist = GetAverageHiGainSector(j);
433 //
434 // Check histogram overflow
435 //
436 CheckOverflow(hist);
437 }
438
439 FitHiGainArrays(*hilocam,*badcam,
440 MBadPixelsPix::kHiLoNotFitted,
441 MBadPixelsPix::kHiLoOscillating);
442
443 if (!IsLoGain())
444 return kTRUE;
445
446 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
447 {
448
449 MHCalibrationPix &hist = (*this)(i);
450
451 if (hist.IsExcluded())
452 continue;
453
454 CheckOverflow(hist);
455 }
456
457 for (Int_t j=0; j<nareas; j++)
458 {
459
460 MHCalibrationPix &hist = GetAverageLoGainArea(j);
461 CheckOverflow(hist);
462 }
463
464 for (Int_t j=0; j<nsectors; j++)
465 {
466
467 MHCalibrationPix &hist = GetAverageLoGainSector(j);
468 CheckOverflow(hist);
469 }
470
471 FitLoGainArrays(*hilocam,*badcam,
472 MBadPixelsPix::kHiLoNotFitted,
473 MBadPixelsPix::kHiLoOscillating);
474
475 return kTRUE;
476}
477
478// --------------------------------------------------------------------------
479//
480// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
481// - MBadPixelsPix::kHiLoNotFitted
482// - MBadPixelsPix::kHiLoOscillating
483//
484void MHCalibrationHiLoCam::FinalizeBadPixels()
485{
486
487 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
488
489 for (Int_t i=0; i<badcam->GetSize(); i++)
490 {
491 MBadPixelsPix &bad = (*badcam)[i];
492
493 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoNotFitted ))
494 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
495
496 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoOscillating))
497 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
498
499 }
500}
501
502// --------------------------------------------------------------------------
503//
504// The types are as follows:
505//
506// Fitted values:
507// ==============
508//
509// 0: Fitted Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMean()
510// 1: Error Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMeanErr()
511// 2: Sigma fitted High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigma()
512// 3: Error Sigma High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigmaErr()
513//
514// Useful variables derived from the fit results:
515// =============================================
516//
517// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
518//
519// Localized defects:
520// ==================
521//
522// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
523// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
524//
525Bool_t MHCalibrationHiLoCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
526{
527
528 if (fHiGainArray->GetSize() <= idx)
529 return kFALSE;
530
531 const MHCalibrationPix &pixhi = (*this)[idx];
532 const MHCalibrationPix &pixlo = (*this)(idx);
533
534 switch (type)
535 {
536 case 0:
537 val = pixhi.GetMean();
538 break;
539 case 1:
540 val = pixhi.GetMeanErr();
541 break;
542 case 2:
543 val = pixhi.GetSigma();
544 break;
545 case 3:
546 val = pixhi.GetSigmaErr();
547 break;
548 case 4:
549 val = pixhi.GetProb();
550 break;
551 case 5:
552 if (!pixhi.IsGausFitOK())
553 val = 1.;
554 break;
555 case 6:
556 if (!pixhi.IsFourierSpectrumOK())
557 val = 1.;
558 break;
559 case 7:
560 if (!IsLoGain())
561 break;
562 val = pixlo.GetMean();
563 break;
564 case 8:
565 if (!IsLoGain())
566 break;
567 val = pixlo.GetMeanErr();
568 break;
569 case 9:
570 if (!IsLoGain())
571 break;
572 val = pixlo.GetSigma();
573 break;
574 case 10:
575 if (!IsLoGain())
576 break;
577 val = pixlo.GetSigmaErr();
578 break;
579 case 11:
580 if (!IsLoGain())
581 break;
582 val = pixlo.GetProb();
583 break;
584 case 12:
585 if (!IsLoGain())
586 break;
587 if (!pixlo.IsGausFitOK())
588 val = 1.;
589 break;
590 case 13:
591 if (!IsLoGain())
592 break;
593 if (!pixlo.IsFourierSpectrumOK())
594 val = 1.;
595 break;
596 default:
597 return kFALSE;
598 }
599 return kTRUE;
600}
601
602// --------------------------------------------------------------------------
603//
604// Calls MHCalibrationPix::DrawClone() for pixel idx
605//
606void MHCalibrationHiLoCam::DrawPixelContent(Int_t idx) const
607{
608 (*this)[idx].DrawClone();
609}
610
611void MHCalibrationHiLoCam::CheckOverflow( MHCalibrationPix &pix )
612{
613
614 if (pix.IsExcluded())
615 return;
616
617 TH1F *hist = pix.GetHGausHist();
618
619 Stat_t overflow = hist->GetBinContent(hist->GetNbinsX()+1);
620 if (overflow > fOverflowLimit*hist->GetEntries())
621 {
622 *fLog << warn << "Hist-overflow " << overflow
623 << " times in " << pix.GetName() << endl;
624 }
625
626 overflow = hist->GetBinContent(0);
627 if (overflow > fOverflowLimit*hist->GetEntries())
628 {
629 *fLog << warn << "Hist-underflow " << overflow
630 << " times in " << pix.GetName() << endl;
631 }
632}
633
Note: See TracBrowser for help on using the repository browser.