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

Last change on this file since 6319 was 6007, checked in by gaug, 20 years ago
*** empty log message ***
File size: 18.6 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 = 200;
121const Axis_t MHCalibrationHiLoCam::fgFirst = 0.;
122const Axis_t MHCalibrationHiLoCam::fgLast = 20.;
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// Default Constructor.
131//
132// Sets:
133// - fNbins to fgNbins
134// - fFirst to fgFirst
135// - fLast to fgLast
136//
137// - fHistName to gsHistName
138// - fHistTitle to gsHistTitle
139// - fHistXTitle to gsHistXTitle
140// - fHistYTitle to gsHistYTitle
141//
142// - fLowerLimt to fgLowerLim
143// - fUpperLimt to fgUpperLim
144//
145MHCalibrationHiLoCam::MHCalibrationHiLoCam(const char *name, const char *title)
146{
147
148 fName = name ? name : "MHCalibrationHiLoCam";
149 fTitle = title ? title : "Histogram class for the high-gain vs. low-gain amplification ratio calibration";
150
151 SetNbins(fgNbins);
152 SetFirst(fgFirst);
153 SetLast (fgLast );
154
155 SetProbLimit(fgProbLimit);
156
157 SetHistName (gsHistName .Data());
158 SetHistTitle (gsHistTitle .Data());
159 SetHistXTitle(gsHistXTitle.Data());
160 SetHistYTitle(gsHistYTitle.Data());
161
162}
163
164// --------------------------------------------------------------------------
165//
166// Creates new MHCalibrationHiLoCam only with the averaged areas:
167// the rest has to be retrieved directly, e.g. via:
168// MHCalibrationHiLoCam *cam = MParList::FindObject("MHCalibrationHiLoCam");
169// - cam->GetAverageSector(5).DrawClone();
170// - (*cam)[100].DrawClone()
171//
172TObject *MHCalibrationHiLoCam::Clone(const char *) const
173{
174
175 MHCalibrationHiLoCam *cam = new MHCalibrationHiLoCam();
176
177 //
178 // Copy the data members
179 //
180 cam->fColor = fColor;
181 cam->fRunNumbers = fRunNumbers;
182 cam->fPulserFrequency = fPulserFrequency;
183 cam->fFlags = fFlags;
184 cam->fNbins = fNbins;
185 cam->fFirst = fFirst;
186 cam->fLast = fLast;
187
188 //
189 // Copy the MArrays
190 //
191 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
192 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
193 cam->fAverageAreaSat = fAverageAreaSat;
194 cam->fAverageAreaSigma = fAverageAreaSigma;
195 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
196 cam->fAverageAreaNum = fAverageAreaNum;
197 cam->fAverageSectorNum = fAverageSectorNum;
198
199 if (!IsAverageing())
200 return cam;
201
202 const Int_t navhi = fAverageHiGainAreas->GetSize();
203 const Int_t navlo = fAverageLoGainAreas->GetSize();
204
205 for (int i=0; i<navhi; i++)
206 cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
207
208 for (int i=0; i<navlo; i++)
209 cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
210
211 return cam;
212}
213
214// --------------------------------------------------------------------------
215//
216// Gets or creates the pointers to:
217// - MCalibrationHiLoCam
218//
219// Searches pointer to:
220// - MExtractedSignalCam
221// - MArrivalTimeCam
222//
223// Calls:
224// - MHCalibrationCam::InitHiGainArrays()
225// - MHCalibrationCam::InitLoGainArrays()
226//
227// Sets:
228// - fSumarea to nareas
229// - fSumsector to nareas
230// - fNumarea to nareas
231// - fNumsector to nareas
232//
233Bool_t MHCalibrationHiLoCam::ReInitHists(MParList *pList)
234{
235
236 fCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationHiLoCam"));
237 if (!fCam)
238 {
239 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationHiLoCam"));
240 if (!fCam)
241 {
242 *fLog << err << "Cannot find nor create MCalibrationHiLoCam... abort." << endl;
243 return kFALSE;
244 }
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 MArrivalTimeCam *times = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
256 if (!times)
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 MArrivalTimeCam *times = (MArrivalTimeCam*)par;
312
313 const Int_t npixels = fGeom->GetNumPixels();
314 const Int_t nareas = fGeom->GetNumAreas();
315 const Int_t nsectors = fGeom->GetNumSectors();
316
317 fSumareahi .Reset();
318 fSumsectorhi.Reset();
319 fNumareahi .Reset();
320 fNumsectorhi.Reset();
321 fSumarealo .Reset();
322 fSumsectorlo.Reset();
323 fNumarealo .Reset();
324 fNumsectorlo.Reset();
325
326 for (Int_t i=0; i<npixels; i++)
327 {
328 const MExtractedSignalPix &pix = (*signal)[i];
329 const Int_t aidx = (*fGeom)[i].GetAidx();
330 const Int_t sector = (*fGeom)[i].GetSector();
331
332 const Float_t siglo = pix.GetExtractedSignalLoGain();
333
334 //
335 // Skip all pixels with:
336 // - Saturated high-gain
337 // - Not extracted low-gain
338 // (see MExtractTimeAndCharge::fLoGainSwitch for setting the criteria)
339 //
340 if (siglo < 0.5 || pix.GetNumHiGainSaturated() > 0)
341 continue;
342
343 const Float_t sighi = pix.GetExtractedSignalHiGain();
344 const Float_t ratio = sighi / siglo;
345
346 MHCalibrationPix &histhi = (*this)[i];
347
348 histhi.FillHistAndArray(ratio);
349 fSumareahi [aidx] += ratio;
350 fNumareahi [aidx] ++;
351 fSumsectorhi[sector] += ratio;
352 fNumsectorhi[sector] ++;
353
354 if (IsLoGain())
355 {
356 const MArrivalTimePix &tix = (*times)[i];
357 MHCalibrationPix &histlo = (*this)(i);
358
359 const Float_t diff = tix.GetArrivalTimeLoGain() - tix.GetArrivalTimeHiGain();
360
361 histlo.FillHistAndArray(diff);
362 fSumarealo [aidx] += diff;
363 fNumarealo [aidx] ++;
364 fSumsectorlo[sector] += diff;
365 fNumsectorlo[sector] ++;
366 }
367 }
368
369 for (Int_t j=0; j<nareas; j++)
370 {
371 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
372 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
373
374 if (IsLoGain())
375 {
376 MHCalibrationPix &histlo = GetAverageLoGainArea(j);
377 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
378 }
379 }
380
381 for (Int_t j=0; j<nsectors; j++)
382 {
383 MHCalibrationPix &hist = GetAverageHiGainSector(j);
384 hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
385
386 if (IsLoGain())
387 {
388 MHCalibrationPix &histlo = GetAverageLoGainSector(j);
389 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
390 }
391 }
392
393 return kTRUE;
394}
395
396// --------------------------------------------------------------------------
397//
398// Calls:
399// - MHCalibrationCam::FitHiGainArrays() with flags:
400// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
401// - MHCalibrationCam::FitLoGainArrays() with flags:
402// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
403//
404Bool_t MHCalibrationHiLoCam::FinalizeHists()
405{
406
407 *fLog << endl;
408
409 MCalibrationCam *hilocam = fCam;
410 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
411
412 const Int_t nareas = fAverageHiGainAreas->GetSize();
413 const Int_t nsectors = fAverageHiGainSectors->GetSize();
414
415 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
416 {
417
418 MHCalibrationPix &hist = (*this)[i];
419
420 if (hist.IsExcluded())
421 continue;
422
423 CheckOverflow(hist);
424 }
425
426 for (Int_t j=0; j<nareas; j++)
427 {
428
429 MHCalibrationPix &hist = GetAverageHiGainArea(j);
430 //
431 // Check histogram overflow
432 //
433 CheckOverflow(hist);
434 }
435
436 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
437 {
438
439 MHCalibrationPix &hist = GetAverageHiGainSector(j);
440 //
441 // Check histogram overflow
442 //
443 CheckOverflow(hist);
444 }
445
446 FitHiGainArrays(*hilocam,*badcam,
447 MBadPixelsPix::kHiLoNotFitted,
448 MBadPixelsPix::kHiLoOscillating);
449
450 if (!IsLoGain())
451 return kTRUE;
452
453 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
454 {
455
456 MHCalibrationPix &hist = (*this)(i);
457
458 if (hist.IsExcluded())
459 continue;
460
461 CheckOverflow(hist);
462 }
463
464 for (Int_t j=0; j<nareas; j++)
465 {
466
467 MHCalibrationPix &hist = GetAverageLoGainArea(j);
468 CheckOverflow(hist);
469 }
470
471 for (Int_t j=0; j<nsectors; j++)
472 {
473
474 MHCalibrationPix &hist = GetAverageLoGainSector(j);
475 CheckOverflow(hist);
476 }
477
478 FitLoGainArrays(*hilocam,*badcam,
479 MBadPixelsPix::kHiLoNotFitted,
480 MBadPixelsPix::kHiLoOscillating);
481
482 return kTRUE;
483}
484
485// --------------------------------------------------------------------------
486//
487// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
488// - MBadPixelsPix::kHiLoNotFitted
489// - MBadPixelsPix::kHiLoOscillating
490//
491void MHCalibrationHiLoCam::FinalizeBadPixels()
492{
493
494 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
495
496 for (Int_t i=0; i<badcam->GetSize(); i++)
497 {
498 MBadPixelsPix &bad = (*badcam)[i];
499
500 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoNotFitted ))
501 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
502
503 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoOscillating))
504 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
505
506 }
507}
508
509// --------------------------------------------------------------------------
510//
511// The types are as follows:
512//
513// Fitted values:
514// ==============
515//
516// 0: Fitted Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMean()
517// 1: Error Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMeanErr()
518// 2: Sigma fitted High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigma()
519// 3: Error Sigma High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigmaErr()
520//
521// Useful variables derived from the fit results:
522// =============================================
523//
524// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
525//
526// Localized defects:
527// ==================
528//
529// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
530// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
531//
532Bool_t MHCalibrationHiLoCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
533{
534
535 if (fHiGainArray->GetSize() <= idx)
536 return kFALSE;
537
538 const MHCalibrationPix &pixhi = (*this)[idx];
539 const MHCalibrationPix &pixlo = (*this)(idx);
540
541 switch (type)
542 {
543 case 0:
544 val = pixhi.GetMean();
545 break;
546 case 1:
547 val = pixhi.GetMeanErr();
548 break;
549 case 2:
550 val = pixhi.GetSigma();
551 break;
552 case 3:
553 val = pixhi.GetSigmaErr();
554 break;
555 case 4:
556 val = pixhi.GetProb();
557 break;
558 case 5:
559 if (!pixhi.IsGausFitOK())
560 val = 1.;
561 break;
562 case 6:
563 if (!pixhi.IsFourierSpectrumOK())
564 val = 1.;
565 break;
566 case 7:
567 if (!IsLoGain())
568 break;
569 val = pixlo.GetMean();
570 break;
571 case 8:
572 if (!IsLoGain())
573 break;
574 val = pixlo.GetMeanErr();
575 break;
576 case 9:
577 if (!IsLoGain())
578 break;
579 val = pixlo.GetSigma();
580 break;
581 case 10:
582 if (!IsLoGain())
583 break;
584 val = pixlo.GetSigmaErr();
585 break;
586 case 11:
587 if (!IsLoGain())
588 break;
589 val = pixlo.GetProb();
590 break;
591 case 12:
592 if (!IsLoGain())
593 break;
594 if (!pixlo.IsGausFitOK())
595 val = 1.;
596 break;
597 case 13:
598 if (!IsLoGain())
599 break;
600 if (!pixlo.IsFourierSpectrumOK())
601 val = 1.;
602 break;
603 default:
604 return kFALSE;
605 }
606 return kTRUE;
607}
608
609// --------------------------------------------------------------------------
610//
611// Calls MHCalibrationPix::DrawClone() for pixel idx
612//
613void MHCalibrationHiLoCam::DrawPixelContent(Int_t idx) const
614{
615 (*this)[idx].DrawClone();
616}
617
618void MHCalibrationHiLoCam::CheckOverflow( MHCalibrationPix &pix )
619{
620
621 if (pix.IsExcluded())
622 return;
623
624 TH1F *hist = pix.GetHGausHist();
625
626 Stat_t overflow = hist->GetBinContent(hist->GetNbinsX()+1);
627 if (overflow > fOverflowLimit*hist->GetEntries())
628 {
629 *fLog << warn << "Hist-overflow " << overflow
630 << " times in " << pix.GetName() << endl;
631 }
632
633 overflow = hist->GetBinContent(0);
634 if (overflow > fOverflowLimit*hist->GetEntries())
635 {
636 *fLog << warn << "Hist-underflow " << overflow
637 << " times in " << pix.GetName() << endl;
638 }
639}
640
Note: See TracBrowser for help on using the repository browser.