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

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