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

Last change on this file since 6569 was 6528, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 18.5 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 return kFALSE;
242 fCam->Init(*fGeom);
243 }
244
245 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
246 if (!signal)
247 {
248 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
249 return kFALSE;
250 }
251
252 MArrivalTimeCam *times = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
253 if (!times)
254 {
255 *fLog << warn << "MArrivalTimeCam not found... cannot calibrated arrival times between "
256 <<"high and low-gain" << endl;
257 SetLoGain(kFALSE);
258 }
259
260 const Int_t npixels = fGeom->GetNumPixels();
261 const Int_t nsectors = fGeom->GetNumSectors();
262 const Int_t nareas = fGeom->GetNumAreas();
263
264 InitHiGainArrays(npixels,nareas,nsectors);
265 InitLoGainArrays(npixels,nareas,nsectors);
266
267 fSumareahi .Set(nareas);
268 fSumsectorhi.Set(nsectors);
269 fNumareahi .Set(nareas);
270 fNumsectorhi.Set(nsectors);
271 if (IsLoGain())
272 {
273 fSumarealo .Set(nareas);
274 fSumsectorlo.Set(nsectors);
275 fNumarealo .Set(nareas);
276 fNumsectorlo.Set(nsectors);
277 }
278 return kTRUE;
279}
280
281// -------------------------------------------------------------------------------
282//
283// Retrieves pointer to MExtractedSignalCam:
284//
285// Retrieves from MGeomCam:
286// - number of pixels
287// - number of pixel areas
288// - number of sectors
289//
290// Fills histograms (MHGausEvents::FillHistAndArray()) with:
291// - MExtractedSignalPix::GetExtractedSignalHiGain(pixid) / MExtractedSignalPix::GetExtractedSignalLoGain;
292// if the high-gain signal does not show high-gain saturation, but the low-gain
293// has been extracted.
294// - MArrivalTimePix::GetArrivalTimeHiGain(pixid) / MArrivalTimePix::GetArrivalTimeLoGain;
295// if the high-gain signal does not show high-gain saturation, but the low-gain
296// has been extracted.
297//
298Bool_t MHCalibrationHiLoCam::FillHists(const MParContainer *par, const Stat_t w)
299{
300
301 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
302 if (!signal)
303 {
304 gLog << err << "No argument in MExtractedSignal::Fill... abort." << endl;
305 return kFALSE;
306 }
307
308 MArrivalTimeCam *times = (MArrivalTimeCam*)par;
309
310 const Int_t npixels = fGeom->GetNumPixels();
311 const Int_t nareas = fGeom->GetNumAreas();
312 const Int_t nsectors = fGeom->GetNumSectors();
313
314 fSumareahi .Reset();
315 fSumsectorhi.Reset();
316 fNumareahi .Reset();
317 fNumsectorhi.Reset();
318 fSumarealo .Reset();
319 fSumsectorlo.Reset();
320 fNumarealo .Reset();
321 fNumsectorlo.Reset();
322
323 for (Int_t i=0; i<npixels; i++)
324 {
325 const MExtractedSignalPix &pix = (*signal)[i];
326 const Int_t aidx = (*fGeom)[i].GetAidx();
327 const Int_t sector = (*fGeom)[i].GetSector();
328
329 const Float_t siglo = pix.GetExtractedSignalLoGain();
330
331 //
332 // Skip all pixels with:
333 // - Saturated high-gain
334 // - Not extracted low-gain
335 // (see MExtractTimeAndCharge::fLoGainSwitch for setting the criteria)
336 //
337 if (siglo < 0.5 || pix.GetNumHiGainSaturated() > 0)
338 continue;
339
340 const Float_t sighi = pix.GetExtractedSignalHiGain();
341 const Float_t ratio = sighi / siglo;
342
343 MHCalibrationPix &histhi = (*this)[i];
344
345 histhi.FillHistAndArray(ratio);
346 fSumareahi [aidx] += ratio;
347 fNumareahi [aidx] ++;
348 fSumsectorhi[sector] += ratio;
349 fNumsectorhi[sector] ++;
350
351 if (IsLoGain())
352 {
353 const MArrivalTimePix &tix = (*times)[i];
354 MHCalibrationPix &histlo = (*this)(i);
355
356 const Float_t diff = tix.GetArrivalTimeLoGain() - tix.GetArrivalTimeHiGain();
357
358 histlo.FillHistAndArray(diff);
359 fSumarealo [aidx] += diff;
360 fNumarealo [aidx] ++;
361 fSumsectorlo[sector] += diff;
362 fNumsectorlo[sector] ++;
363 }
364 }
365
366 for (Int_t j=0; j<nareas; j++)
367 {
368 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
369 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
370
371 if (IsLoGain())
372 {
373 MHCalibrationPix &histlo = GetAverageLoGainArea(j);
374 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
375 }
376 }
377
378 for (Int_t j=0; j<nsectors; j++)
379 {
380 MHCalibrationPix &hist = GetAverageHiGainSector(j);
381 hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
382
383 if (IsLoGain())
384 {
385 MHCalibrationPix &histlo = GetAverageLoGainSector(j);
386 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
387 }
388 }
389
390 return kTRUE;
391}
392
393// --------------------------------------------------------------------------
394//
395// Calls:
396// - MHCalibrationCam::FitHiGainArrays() with flags:
397// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
398// - MHCalibrationCam::FitLoGainArrays() with flags:
399// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
400//
401Bool_t MHCalibrationHiLoCam::FinalizeHists()
402{
403
404 *fLog << endl;
405
406 MCalibrationCam *hilocam = fCam;
407 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
408
409 const Int_t nareas = fAverageHiGainAreas->GetSize();
410 const Int_t nsectors = fAverageHiGainSectors->GetSize();
411
412 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
413 {
414
415 MHCalibrationPix &hist = (*this)[i];
416
417 if (hist.IsExcluded())
418 continue;
419
420 CheckOverflow(hist);
421 }
422
423 for (Int_t j=0; j<nareas; j++)
424 {
425
426 MHCalibrationPix &hist = GetAverageHiGainArea(j);
427 //
428 // Check histogram overflow
429 //
430 CheckOverflow(hist);
431 }
432
433 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
434 {
435
436 MHCalibrationPix &hist = GetAverageHiGainSector(j);
437 //
438 // Check histogram overflow
439 //
440 CheckOverflow(hist);
441 }
442
443 FitHiGainArrays(*hilocam,*badcam,
444 MBadPixelsPix::kHiLoNotFitted,
445 MBadPixelsPix::kHiLoOscillating);
446
447 if (!IsLoGain())
448 return kTRUE;
449
450 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
451 {
452
453 MHCalibrationPix &hist = (*this)(i);
454
455 if (hist.IsExcluded())
456 continue;
457
458 CheckOverflow(hist);
459 }
460
461 for (Int_t j=0; j<nareas; j++)
462 {
463
464 MHCalibrationPix &hist = GetAverageLoGainArea(j);
465 CheckOverflow(hist);
466 }
467
468 for (Int_t j=0; j<nsectors; j++)
469 {
470
471 MHCalibrationPix &hist = GetAverageLoGainSector(j);
472 CheckOverflow(hist);
473 }
474
475 FitLoGainArrays(*hilocam,*badcam,
476 MBadPixelsPix::kHiLoNotFitted,
477 MBadPixelsPix::kHiLoOscillating);
478
479 return kTRUE;
480}
481
482// --------------------------------------------------------------------------
483//
484// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
485// - MBadPixelsPix::kHiLoNotFitted
486// - MBadPixelsPix::kHiLoOscillating
487//
488void MHCalibrationHiLoCam::FinalizeBadPixels()
489{
490
491 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
492
493 for (Int_t i=0; i<badcam->GetSize(); i++)
494 {
495 MBadPixelsPix &bad = (*badcam)[i];
496
497 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoNotFitted ))
498 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
499
500 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoOscillating))
501 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
502
503 }
504}
505
506// --------------------------------------------------------------------------
507//
508// The types are as follows:
509//
510// Fitted values:
511// ==============
512//
513// 0: Fitted Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMean()
514// 1: Error Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMeanErr()
515// 2: Sigma fitted High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigma()
516// 3: Error Sigma High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigmaErr()
517//
518// Useful variables derived from the fit results:
519// =============================================
520//
521// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
522//
523// Localized defects:
524// ==================
525//
526// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
527// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
528//
529Bool_t MHCalibrationHiLoCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
530{
531
532 if (fHiGainArray->GetSize() <= idx)
533 return kFALSE;
534
535 const MHCalibrationPix &pixhi = (*this)[idx];
536 const MHCalibrationPix &pixlo = (*this)(idx);
537
538 switch (type)
539 {
540 case 0:
541 val = pixhi.GetMean();
542 break;
543 case 1:
544 val = pixhi.GetMeanErr();
545 break;
546 case 2:
547 val = pixhi.GetSigma();
548 break;
549 case 3:
550 val = pixhi.GetSigmaErr();
551 break;
552 case 4:
553 val = pixhi.GetProb();
554 break;
555 case 5:
556 if (!pixhi.IsGausFitOK())
557 val = 1.;
558 break;
559 case 6:
560 if (!pixhi.IsFourierSpectrumOK())
561 val = 1.;
562 break;
563 case 7:
564 if (!IsLoGain())
565 break;
566 val = pixlo.GetMean();
567 break;
568 case 8:
569 if (!IsLoGain())
570 break;
571 val = pixlo.GetMeanErr();
572 break;
573 case 9:
574 if (!IsLoGain())
575 break;
576 val = pixlo.GetSigma();
577 break;
578 case 10:
579 if (!IsLoGain())
580 break;
581 val = pixlo.GetSigmaErr();
582 break;
583 case 11:
584 if (!IsLoGain())
585 break;
586 val = pixlo.GetProb();
587 break;
588 case 12:
589 if (!IsLoGain())
590 break;
591 if (!pixlo.IsGausFitOK())
592 val = 1.;
593 break;
594 case 13:
595 if (!IsLoGain())
596 break;
597 if (!pixlo.IsFourierSpectrumOK())
598 val = 1.;
599 break;
600 default:
601 return kFALSE;
602 }
603 return kTRUE;
604}
605
606// --------------------------------------------------------------------------
607//
608// Calls MHCalibrationPix::DrawClone() for pixel idx
609//
610void MHCalibrationHiLoCam::DrawPixelContent(Int_t idx) const
611{
612 (*this)[idx].DrawClone();
613}
614
615void MHCalibrationHiLoCam::CheckOverflow( MHCalibrationPix &pix )
616{
617
618 if (pix.IsExcluded())
619 return;
620
621 TH1F *hist = pix.GetHGausHist();
622
623 Stat_t overflow = hist->GetBinContent(hist->GetNbinsX()+1);
624 if (overflow > fOverflowLimit*hist->GetEntries())
625 {
626 *fLog << warn << "Hist-overflow " << overflow
627 << " times in " << pix.GetName() << endl;
628 }
629
630 overflow = hist->GetBinContent(0);
631 if (overflow > fOverflowLimit*hist->GetEntries())
632 {
633 *fLog << warn << "Hist-underflow " << overflow
634 << " times in " << pix.GetName() << endl;
635 }
636}
637
Note: See TracBrowser for help on using the repository browser.