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

Last change on this file since 7069 was 7028, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 19.2 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 "MCalibrationHiLoCam.h"
90#include "MCalibrationCam.h"
91#include "MCalibrationPix.h"
92
93#include "MExtractedSignalCam.h"
94#include "MExtractedSignalPix.h"
95#include "MArrivalTimeCam.h"
96#include "MArrivalTimePix.h"
97
98#include "MGeomCam.h"
99#include "MGeomPix.h"
100
101#include "MBadPixelsIntensityCam.h"
102#include "MBadPixelsCam.h"
103#include "MBadPixelsPix.h"
104
105#include <TOrdCollection.h>
106#include <TPad.h>
107#include <TVirtualPad.h>
108#include <TCanvas.h>
109#include <TStyle.h>
110#include <TF1.h>
111#include <TLine.h>
112#include <TLatex.h>
113#include <TLegend.h>
114#include <TGraph.h>
115
116ClassImp(MHCalibrationHiLoCam);
117
118using namespace std;
119
120const Int_t MHCalibrationHiLoCam::fgNbins = 175;
121const Axis_t MHCalibrationHiLoCam::fgFirst = -5.1;
122const Axis_t MHCalibrationHiLoCam::fgLast = 29.9;
123const Float_t MHCalibrationHiLoCam::fgProbLimit = 0.;
124const TString MHCalibrationHiLoCam::gsHistName = "HiLo";
125const TString MHCalibrationHiLoCam::gsHistTitle = "HiGain vs. LoGain";
126const TString MHCalibrationHiLoCam::gsHistXTitle = "Amplification Ratio [1]";
127const TString MHCalibrationHiLoCam::gsHistYTitle = "Nr. events";
128
129// --------------------------------------------------------------------------
130//
131// Default Constructor.
132//
133// Sets:
134// - fNbins to fgNbins
135// - fFirst to fgFirst
136// - fLast to fgLast
137//
138// - fHistName to gsHistName
139// - fHistTitle to gsHistTitle
140// - fHistXTitle to gsHistXTitle
141// - fHistYTitle to gsHistYTitle
142//
143// - fLowerLimt to fgLowerLim
144// - fUpperLimt to fgUpperLim
145//
146MHCalibrationHiLoCam::MHCalibrationHiLoCam(const char *name, const char *title)
147 : fArrTimes(NULL)
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 SetOscillations(kFALSE);
165}
166
167// --------------------------------------------------------------------------
168//
169// Creates new MHCalibrationHiLoCam only with the averaged areas:
170// the rest has to be retrieved directly, e.g. via:
171// MHCalibrationHiLoCam *cam = MParList::FindObject("MHCalibrationHiLoCam");
172// - cam->GetAverageSector(5).DrawClone();
173// - (*cam)[100].DrawClone()
174//
175TObject *MHCalibrationHiLoCam::Clone(const char *) const
176{
177
178 MHCalibrationHiLoCam *cam = new MHCalibrationHiLoCam();
179
180 //
181 // Copy the data members
182 //
183 cam->fColor = fColor;
184 cam->fRunNumbers = fRunNumbers;
185 cam->fPulserFrequency = fPulserFrequency;
186 cam->fFlags = fFlags;
187 cam->fNbins = fNbins;
188 cam->fFirst = fFirst;
189 cam->fLast = fLast;
190
191 //
192 // Copy the MArrays
193 //
194 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
195 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
196 cam->fAverageAreaSat = fAverageAreaSat;
197 cam->fAverageAreaSigma = fAverageAreaSigma;
198 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
199 cam->fAverageAreaNum = fAverageAreaNum;
200 cam->fAverageSectorNum = fAverageSectorNum;
201
202 if (!IsAverageing())
203 return cam;
204
205 const Int_t navhi = fAverageHiGainAreas->GetSize();
206 const Int_t navlo = fAverageLoGainAreas->GetSize();
207
208 for (int i=0; i<navhi; i++)
209 cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
210
211 for (int i=0; i<navlo; i++)
212 cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
213
214 return cam;
215}
216
217// --------------------------------------------------------------------------
218//
219// Gets or creates the pointers to:
220// - MCalibrationHiLoCam
221//
222// Searches pointer to:
223// - MExtractedSignalCam
224// - MArrivalTimeCam
225//
226// Calls:
227// - MHCalibrationCam::InitHiGainArrays()
228// - MHCalibrationCam::InitLoGainArrays()
229//
230// Sets:
231// - fSumarea to nareas
232// - fSumsector to nareas
233// - fNumarea to nareas
234// - fNumsector to nareas
235//
236Bool_t MHCalibrationHiLoCam::ReInitHists(MParList *pList)
237{
238
239 fCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationHiLoCam"));
240 if (!fCam)
241 {
242 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationHiLoCam"));
243 if (!fCam)
244 return kFALSE;
245 fCam->Init(*fGeom);
246 }
247
248 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
249 if (!signal)
250 {
251 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
252 return kFALSE;
253 }
254
255 fArrTimes = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
256 if (!fArrTimes)
257 {
258 *fLog << warn << "MArrivalTimeCam not found... cannot calibrated arrival times between "
259 <<"high and low-gain" << endl;
260 SetLoGain(kFALSE);
261 }
262
263 const Int_t npixels = fGeom->GetNumPixels();
264 const Int_t nsectors = fGeom->GetNumSectors();
265 const Int_t nareas = fGeom->GetNumAreas();
266
267 InitHiGainArrays(npixels,nareas,nsectors);
268 InitLoGainArrays(npixels,nareas,nsectors);
269
270 fSumareahi .Set(nareas);
271 fSumsectorhi.Set(nsectors);
272 fNumareahi .Set(nareas);
273 fNumsectorhi.Set(nsectors);
274 if (IsLoGain())
275 {
276 fSumarealo .Set(nareas);
277 fSumsectorlo.Set(nsectors);
278 fNumarealo .Set(nareas);
279 fNumsectorlo.Set(nsectors);
280 }
281 return kTRUE;
282}
283
284// -------------------------------------------------------------------------------
285//
286// Retrieves pointer to MExtractedSignalCam:
287//
288// Retrieves from MGeomCam:
289// - number of pixels
290// - number of pixel areas
291// - number of sectors
292//
293// Fills histograms (MHGausEvents::FillHistAndArray()) with:
294// - MExtractedSignalPix::GetExtractedSignalHiGain(pixid) / MExtractedSignalPix::GetExtractedSignalLoGain;
295// if the high-gain signal does not show high-gain saturation, but the low-gain
296// has been extracted.
297// - MArrivalTimePix::GetArrivalTimeHiGain(pixid) / MArrivalTimePix::GetArrivalTimeLoGain;
298// if the high-gain signal does not show high-gain saturation, but the low-gain
299// has been extracted.
300//
301Bool_t MHCalibrationHiLoCam::FillHists(const MParContainer *par, const Stat_t w)
302{
303
304 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
305 if (!signal)
306 {
307 gLog << err << "No argument in MExtractedSignal::Fill... abort." << endl;
308 return kFALSE;
309 }
310
311 const Int_t npixels = fGeom->GetNumPixels();
312 const Int_t nareas = fGeom->GetNumAreas();
313 const Int_t nsectors = fGeom->GetNumSectors();
314
315 fSumareahi .Reset();
316 fSumsectorhi.Reset();
317 fNumareahi .Reset();
318 fNumsectorhi.Reset();
319 fSumarealo .Reset();
320 fSumsectorlo.Reset();
321 fNumarealo .Reset();
322 fNumsectorlo.Reset();
323
324 for (Int_t i=0; i<npixels; i++)
325 {
326 const MExtractedSignalPix &pix = (*signal)[i];
327 const Int_t aidx = (*fGeom)[i].GetAidx();
328 const Int_t sector = (*fGeom)[i].GetSector();
329
330 const Float_t siglo = pix.GetExtractedSignalLoGain();
331
332 //
333 // Skip all pixels with:
334 // - Saturated high-gain
335 // - Not extracted low-gain
336 // (see MExtractTimeAndCharge::fLoGainSwitch for setting the criteria)
337 //
338 if (siglo < 0.5 || pix.GetNumHiGainSaturated() > 0)
339 continue;
340
341 const Float_t sighi = pix.GetExtractedSignalHiGain();
342 const Float_t ratio = sighi / siglo;
343
344 MHCalibrationPix &histhi = (*this)[i];
345
346 histhi.FillHist(ratio);
347 fSumareahi [aidx] += ratio;
348 fNumareahi [aidx] ++;
349 fSumsectorhi[sector] += ratio;
350 fNumsectorhi[sector] ++;
351
352 if (IsLoGain())
353 {
354 const MArrivalTimePix &tix = (*fArrTimes)[i];
355 MHCalibrationPix &histlo = (*this)(i);
356
357 const Float_t diff = tix.GetArrivalTimeLoGain() - tix.GetArrivalTimeHiGain();
358
359 histlo.FillHist(diff);
360 fSumarealo [aidx] += diff;
361 fNumarealo [aidx] ++;
362 fSumsectorlo[sector] += diff;
363 fNumsectorlo[sector] ++;
364 }
365 }
366
367 if (!IsAverageing())
368 return kTRUE;
369
370 for (Int_t j=0; j<nareas; j++)
371 {
372 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
373 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
374
375 if (IsLoGain())
376 {
377 MHCalibrationPix &histlo = GetAverageLoGainArea(j);
378 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
379 }
380 }
381
382 for (Int_t j=0; j<nsectors; j++)
383 {
384 MHCalibrationPix &hist = GetAverageHiGainSector(j);
385 hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
386
387 if (IsLoGain())
388 {
389 MHCalibrationPix &histlo = GetAverageLoGainSector(j);
390 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
391 }
392 }
393
394 return kTRUE;
395}
396
397// --------------------------------------------------------------------------
398//
399// Calls:
400// - MHCalibrationCam::FitHiGainArrays() with flags:
401// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
402// - MHCalibrationCam::FitLoGainArrays() with flags:
403// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
404//
405Bool_t MHCalibrationHiLoCam::FinalizeHists()
406{
407
408 *fLog << endl;
409
410 MCalibrationCam *hilocam = fCam;
411 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
412
413 const Int_t nareas = fAverageHiGainAreas->GetSize();
414 const Int_t nsectors = fAverageHiGainSectors->GetSize();
415
416 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
417 {
418
419 MHCalibrationPix &hist = (*this)[i];
420
421 if (hist.IsExcluded())
422 continue;
423
424 CheckOverflow(hist);
425 }
426
427 //
428 // Check histogram overflow
429 //
430 if (IsAverageing())
431 {
432 for (Int_t j=0; j<nareas; j++)
433 CheckOverflow(GetAverageHiGainArea(j));
434
435 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
436 CheckOverflow(GetAverageHiGainSector(j));
437 }
438
439
440 FitHiGainArrays(*hilocam,*badcam,
441 MBadPixelsPix::kHiLoNotFitted,
442 MBadPixelsPix::kHiLoOscillating);
443
444 if (!IsLoGain())
445 return kTRUE;
446
447 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
448 {
449
450 MHCalibrationPix &hist = (*this)(i);
451
452 if (hist.IsExcluded())
453 continue;
454
455 CheckOverflow(hist);
456 }
457
458 if (IsAverageing())
459 {
460 for (Int_t j=0; j<nareas; j++)
461 CheckOverflow(GetAverageLoGainArea(j));
462
463 for (Int_t j=0; j<nsectors; j++)
464 CheckOverflow(GetAverageLoGainSector(j));
465 }
466
467 FitLoGainArrays(*hilocam,*badcam,
468 MBadPixelsPix::kHiLoNotFitted,
469 MBadPixelsPix::kHiLoOscillating);
470
471 return kTRUE;
472}
473
474// --------------------------------------------------------------------------
475//
476// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
477// - MBadPixelsPix::kHiLoNotFitted
478// - MBadPixelsPix::kHiLoOscillating
479//
480void MHCalibrationHiLoCam::FinalizeBadPixels()
481{
482
483 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
484
485 for (Int_t i=0; i<badcam->GetSize(); i++)
486 {
487 MBadPixelsPix &bad = (*badcam)[i];
488
489 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoNotFitted ))
490 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
491
492 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoOscillating))
493 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
494
495 }
496}
497
498// --------------------------------------------------------------------------
499//
500// The types are as follows:
501//
502// Fitted values:
503// ==============
504//
505// 0: Fitted Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMean()
506// 1: Error Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMeanErr()
507// 2: Sigma fitted High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigma()
508// 3: Error Sigma High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigmaErr()
509//
510// Useful variables derived from the fit results:
511// =============================================
512//
513// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
514//
515// Localized defects:
516// ==================
517//
518// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
519// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
520//
521Bool_t MHCalibrationHiLoCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
522{
523
524 if (fHiGainArray->GetSize() <= idx)
525 return kFALSE;
526
527 const MHCalibrationPix &pixhi = (*this)[idx];
528 const MHCalibrationPix &pixlo = (*this)(idx);
529
530 switch (type)
531 {
532 case 0:
533 val = pixhi.GetMean();
534 break;
535 case 1:
536 val = pixhi.GetMeanErr();
537 break;
538 case 2:
539 val = pixhi.GetSigma();
540 break;
541 case 3:
542 val = pixhi.GetSigmaErr();
543 break;
544 case 4:
545 val = pixhi.GetProb();
546 break;
547 case 5:
548 if (!pixhi.IsGausFitOK())
549 val = 1.;
550 break;
551 case 6:
552 if (!pixhi.IsFourierSpectrumOK())
553 val = 1.;
554 break;
555 case 7:
556 if (!IsLoGain())
557 break;
558 val = pixlo.GetMean();
559 break;
560 case 8:
561 if (!IsLoGain())
562 break;
563 val = pixlo.GetMeanErr();
564 break;
565 case 9:
566 if (!IsLoGain())
567 break;
568 val = pixlo.GetSigma();
569 break;
570 case 10:
571 if (!IsLoGain())
572 break;
573 val = pixlo.GetSigmaErr();
574 break;
575 case 11:
576 if (!IsLoGain())
577 break;
578 val = pixlo.GetProb();
579 break;
580 case 12:
581 if (!IsLoGain())
582 break;
583 if (!pixlo.IsGausFitOK())
584 val = 1.;
585 break;
586 case 13:
587 if (!IsLoGain())
588 break;
589 if (!pixlo.IsFourierSpectrumOK())
590 val = 1.;
591 break;
592 default:
593 return kFALSE;
594 }
595 return kTRUE;
596}
597
598// --------------------------------------------------------------------------
599//
600// Calls MHCalibrationPix::DrawClone() for pixel idx
601//
602void MHCalibrationHiLoCam::DrawPixelContent(Int_t idx) const
603{
604 (*this)[idx].DrawClone();
605}
606
607void MHCalibrationHiLoCam::CheckOverflow( MHCalibrationPix &pix )
608{
609
610 if (pix.IsExcluded())
611 return;
612
613 TH1F *hist = pix.GetHGausHist();
614
615 Stat_t overflow = hist->GetBinContent(hist->GetNbinsX()+1);
616 if (overflow > fOverflowLimit*hist->GetEntries())
617 {
618 *fLog << warn << "Hist-overflow " << overflow
619 << " times in " << pix.GetName() << endl;
620 }
621
622 overflow = hist->GetBinContent(0);
623 if (overflow > fOverflowLimit*hist->GetEntries())
624 {
625 *fLog << warn << "Hist-underflow " << overflow
626 << " times in " << pix.GetName() << endl;
627 }
628}
629
630// -----------------------------------------------------------------------------
631//
632// Default draw:
633//
634// Displays the averaged areas, both amplification ratio as time difference
635//
636void MHCalibrationHiLoCam::Draw(const Option_t *opt)
637{
638
639 if (!IsAverageing())
640 return;
641
642 const Int_t nareas = fAverageHiGainAreas->GetSize();
643 if (nareas == 0)
644 return;
645
646 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
647 pad->SetBorderMode(0);
648
649 pad->Divide(IsLoGain() ? 2 : 1,nareas);
650
651 for (Int_t i=0; i<nareas;i++)
652 {
653
654 pad->cd(IsLoGain() ? 2*(i+1)-1 : i+1);
655
656 GetAverageHiGainArea(i).Draw(opt);
657
658 if (IsLoGain())
659 {
660 pad->cd(2*(i+1));
661
662 TH1F *hist = GetAverageLoGainArea(i).GetHGausHist();
663 hist->SetXTitle("Extracted Time Difference [FADC sl.]");
664 GetAverageLoGainArea(i).Draw(opt);
665 }
666 }
667}
668
Note: See TracBrowser for help on using the repository browser.