source: trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc@ 3699

Last change on this file since 3699 was 3696, checked in by gaug, 21 years ago
*** empty log message ***
File size: 26.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// MHCalibrationCam
27//
28// Base class for camera calibration classes. Incorporates the TObjArray's:
29// - fHiGainArray (for calibrated High Gains per pixel)
30// - fLoGainArray (for calibrated Low Gains per pixel)
31// - fAverageHiGainAreas (for averaged High Gains events per camera area index)
32// - fAverageLoGainAreas (for averaged High Gains events per camera area index)
33// - fAverageHiGainSectors (for averaged High Gains events per camera sector )
34// - fAverageLoGainSectors (for averaged High Gains events per camera sector )
35// These TObjArray's are called by their default constructors, thus no objects
36// are created, until the derived class does so.
37//
38// The corresponding operators: [],() and the operators GetAverageHiGainArea(),
39// GetAverageLoGainArea(), GetAverageHiGainSector() and GetAverageLoGainSector()
40// have to be cast to the corresponding class. It is assumed that all classes
41// dealing with calibration pixels derive from MHGausEvents.
42//
43/////////////////////////////////////////////////////////////////////////////
44#include "MHCalibrationCam.h"
45
46#include <TVirtualPad.h>
47#include <TCanvas.h>
48#include <TPad.h>
49#include <TText.h>
50#include <TPaveText.h>
51
52#include "MLog.h"
53#include "MLogManip.h"
54
55#include "MCalibrationPix.h"
56#include "MCalibrationCam.h"
57
58#include "MHGausEvents.h"
59
60#include "MBadPixelsPix.h"
61#include "MBadPixelsCam.h"
62
63#include "MGeomCam.h"
64#include "MGeomPix.h"
65
66#include "MParList.h"
67
68ClassImp(MHCalibrationCam);
69
70using namespace std;
71
72const Int_t MHCalibrationCam::fgAverageNbins = 2000;
73const Int_t MHCalibrationCam::fgPulserFrequency = 500;
74// --------------------------------------------------------------------------
75//
76// Default Constructor.
77//
78// Sets:
79// - all pointers to NULL
80//
81// Initializes and sets owner of:
82// - fHiGainArray, fLoGainArray
83// - fAverageHiGainAreas, fAverageLoGainAreas
84// - fAverageHiGainSectors, fAverageLoGainSectors
85//
86// Initializes:
87// - fPulserFrequency to fgPulserFrequency
88//
89MHCalibrationCam::MHCalibrationCam(const char *name, const char *title)
90 : fGeom(NULL), fBadPixels(NULL), fCam(NULL)
91{
92 fName = name ? name : "MHCalibrationCam";
93 fTitle = title ? title : "Class to fill the calibration histograms ";
94
95 fHiGainArray = new TObjArray;
96 fHiGainArray->SetOwner();
97
98 fLoGainArray = new TObjArray;
99 fLoGainArray->SetOwner();
100
101 fAverageHiGainAreas = new TObjArray;
102 fAverageHiGainAreas->SetOwner();
103
104 fAverageLoGainAreas = new TObjArray;
105 fAverageLoGainAreas->SetOwner();
106
107 fAverageHiGainSectors = new TObjArray;
108 fAverageHiGainSectors->SetOwner();
109
110 fAverageLoGainSectors = new TObjArray;
111 fAverageLoGainSectors->SetOwner();
112
113 SetAverageNbins();
114 SetPulserFrequency();
115}
116
117// --------------------------------------------------------------------------
118//
119// Deletes the TClonesArray of:
120// - fHiGainArray, fLoGainArray
121// - fAverageHiGainAreas, fAverageLoGainAreas
122// - fAverageHiGainSectors, fAverageLoGainSectors
123//
124MHCalibrationCam::~MHCalibrationCam()
125{
126 delete fHiGainArray;
127 delete fLoGainArray;
128
129 delete fAverageHiGainAreas;
130 delete fAverageLoGainAreas;
131
132 delete fAverageHiGainSectors;
133 delete fAverageLoGainSectors;
134}
135
136// --------------------------------------------------------------------------
137//
138// Get i-th High Gain pixel (pixel number)
139//
140MHGausEvents &MHCalibrationCam::operator[](UInt_t i)
141{
142 return *static_cast<MHGausEvents*>(fHiGainArray->UncheckedAt(i));
143}
144
145// --------------------------------------------------------------------------
146//
147// Get i-th High Gain pixel (pixel number)
148//
149const MHGausEvents &MHCalibrationCam::operator[](UInt_t i) const
150{
151 return *static_cast<MHGausEvents*>(fHiGainArray->UncheckedAt(i));
152}
153
154// --------------------------------------------------------------------------
155//
156// Get i-th Low Gain pixel (pixel number)
157//
158MHGausEvents &MHCalibrationCam::operator()(UInt_t i)
159{
160 return *static_cast<MHGausEvents*>(fLoGainArray->UncheckedAt(i));
161}
162
163// --------------------------------------------------------------------------
164//
165// Get i-th Low Gain pixel (pixel number)
166//
167const MHGausEvents &MHCalibrationCam::operator()(UInt_t i) const
168{
169 return *static_cast<MHGausEvents*>(fLoGainArray->UncheckedAt(i));
170}
171
172// --------------------------------------------------------------------------
173//
174// Get i-th High Gain pixel Area (area number)
175//
176MHGausEvents &MHCalibrationCam::GetAverageHiGainArea(UInt_t i)
177{
178 return *static_cast<MHGausEvents*>(fAverageHiGainAreas->UncheckedAt(i));
179}
180
181// --------------------------------------------------------------------------
182//
183// Get i-th High Gain pixel Area (area number)
184//
185const MHGausEvents &MHCalibrationCam::GetAverageHiGainArea(UInt_t i) const
186{
187 return *static_cast<MHGausEvents *>(fAverageHiGainAreas->UncheckedAt(i));
188}
189
190// --------------------------------------------------------------------------
191//
192// Get i-th Low Gain pixel Area (area number)
193//
194MHGausEvents &MHCalibrationCam::GetAverageLoGainArea(UInt_t i)
195{
196 return *static_cast<MHGausEvents*>(fAverageLoGainAreas->UncheckedAt(i));
197}
198
199// --------------------------------------------------------------------------
200//
201// Get i-th Low Gain pixel Area (area number)
202//
203const MHGausEvents &MHCalibrationCam::GetAverageLoGainArea(UInt_t i) const
204{
205 return *static_cast<MHGausEvents*>(fAverageLoGainAreas->UncheckedAt(i));
206}
207
208// --------------------------------------------------------------------------
209//
210// Get i-th High Gain Sector (sector number)
211//
212MHGausEvents &MHCalibrationCam::GetAverageHiGainSector(UInt_t i)
213{
214 return *static_cast<MHGausEvents*>(fAverageHiGainSectors->UncheckedAt(i));
215}
216
217// --------------------------------------------------------------------------
218//
219// Get i-th High Gain Sector (sector number)
220//
221const MHGausEvents &MHCalibrationCam::GetAverageHiGainSector(UInt_t i) const
222{
223 return *static_cast<MHGausEvents*>(fAverageHiGainSectors->UncheckedAt(i));
224}
225
226// --------------------------------------------------------------------------
227//
228// Get i-th Low Gain Sector (sector number)
229//
230MHGausEvents &MHCalibrationCam::GetAverageLoGainSector(UInt_t i)
231{
232 return *static_cast<MHGausEvents*>(fAverageLoGainSectors->UncheckedAt(i));
233}
234
235// --------------------------------------------------------------------------
236//
237// Get i-th Low Gain Sector (sector number)
238//
239const MHGausEvents &MHCalibrationCam::GetAverageLoGainSector(UInt_t i) const
240{
241 return *static_cast<MHGausEvents*>(fAverageLoGainSectors->UncheckedAt(i));
242}
243
244
245// --------------------------------------------------------------------------
246//
247// Our own clone function is necessary since root 3.01/06 or Mars 0.4
248// I don't know the reason.
249//
250// Creates new MHCalibrationCam
251// Deletes the TObjArray's and Clones them individually
252// Copies the TArray's
253// Copies the fPulserFrequency
254//
255TObject *MHCalibrationCam::Clone(const char *) const
256{
257
258 const Int_t nhi = fHiGainArray->GetEntries();
259 const Int_t nlo = fLoGainArray->GetEntries();
260 const Int_t navhi = fAverageHiGainAreas->GetEntries();
261 const Int_t navlo = fAverageLoGainAreas->GetEntries();
262 const Int_t nsehi = fAverageHiGainSectors->GetEntries();
263 const Int_t nselo = fAverageLoGainSectors->GetEntries();
264
265 //
266 // FIXME, this might be done faster and more elegant, by direct copy.
267 //
268 MHCalibrationCam *cam = new MHCalibrationCam();
269
270 cam->fHiGainArray->Expand(nhi);
271 cam->fLoGainArray->Expand(nlo);
272 cam->fAverageHiGainAreas->Expand(navhi);
273 cam->fAverageLoGainAreas->Expand(navlo);
274 cam->fAverageHiGainSectors->Expand(nsehi);
275 cam->fAverageLoGainSectors->Expand(nselo);
276
277 for (int i=0; i<nhi; i++)
278 {
279 delete (*cam->fHiGainArray)[i];
280 (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
281 }
282 for (int i=0; i<nlo; i++)
283 {
284 delete (*cam->fLoGainArray)[i];
285 (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
286 }
287 for (int i=0; i<navhi; i++)
288 {
289 delete (*cam->fAverageHiGainAreas)[i];
290 (*cam->fAverageHiGainAreas)[i] = (*fAverageHiGainAreas)[i]->Clone();
291 }
292 for (int i=0; i<navlo; i++)
293 {
294 delete (*cam->fAverageLoGainAreas)[i];
295 (*cam->fAverageLoGainAreas)[i] = (*fAverageLoGainAreas)[i]->Clone();
296 }
297 for (int i=0; i<nsehi; i++)
298 {
299 delete (*cam->fAverageHiGainSectors)[i];
300 (*cam->fAverageHiGainSectors)[i] = (*fAverageHiGainSectors)[i]->Clone();
301 }
302 for (int i=0; i<nselo; i++)
303 {
304 delete (*cam->fAverageLoGainSectors)[i];
305 (*cam->fAverageLoGainSectors)[i] = (*fAverageLoGainSectors)[i]->Clone();
306 }
307
308 cam->fAverageAreaNum = fAverageAreaNum;
309 cam->fAverageAreaSat = fAverageAreaSat;
310 cam->fAverageAreaSigma = fAverageAreaSigma;
311 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
312 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
313 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
314 cam->fAverageSectorNum = fAverageSectorNum;
315
316 cam->fPulserFrequency = fPulserFrequency;
317
318 return cam;
319}
320
321// --------------------------------------------------------------------------
322//
323// Gets the pointers to:
324// - MGeomCam
325//
326// Calls SetupHists(const MParList *pList)
327//
328// Calls Delete-Function of:
329// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
330// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
331// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
332//
333Bool_t MHCalibrationCam::SetupFill(const MParList *pList)
334{
335
336 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
337 if (!fGeom)
338 {
339 *fLog << err << "MGeomCam not found... aborting." << endl;
340 return kFALSE;
341 }
342
343 fHiGainArray->Delete();
344 fLoGainArray->Delete();
345
346 fAverageHiGainAreas->Delete();
347 fAverageLoGainAreas->Delete();
348
349 fAverageHiGainSectors->Delete();
350 fAverageLoGainSectors->Delete();
351
352 return SetupHists(pList);
353}
354
355
356Bool_t MHCalibrationCam::SetupHists(const MParList *pList)
357{
358 return kTRUE;
359}
360
361// --------------------------------------------------------------------------
362//
363// Gets or creates the pointers to:
364// - MBadPixelsCam
365//
366// Searches pointer to:
367// - MArrivalTimeCam
368//
369// Initializes, if empty to MArrivalTimeCam::GetSize() for:
370// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
371//
372// Initializes, if empty to MGeomCam::GetNumAreas() for:
373// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
374//
375// Initializes, if empty to MGeomCam::GetNumSectors() for:
376// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
377//
378// Initializes TArray's to MGeomCam::GetNumAreas and MGeomCam::GetNumSectors, respectively
379// Fills with number of valid pixels (if !MBadPixelsPix::IsBad()):
380// - MHCalibrationCam::fAverageAreaNum[area index]
381// - MHCalibrationCam::fAverageSectorNum[area index]
382//
383// Calls InitializeHists() for every entry in:
384// - MHCalibrationCam::fHiGainArray
385// - MHCalibrationCam::fAverageHiGainAreas
386// - MHCalibrationCam::fAverageHiGainSectors
387//
388// Sets Titles and Names for the Histograms
389// - MHCalibrationCam::fAverageHiGainAreas
390// - MHCalibrationCam::fAverageHiGainSectors
391//
392Bool_t MHCalibrationCam::ReInit(MParList *pList)
393{
394
395 const Int_t npixels = fGeom->GetNumPixels();
396 const Int_t nsectors = fGeom->GetNumSectors();
397 const Int_t nareas = fGeom->GetNumAreas();
398
399 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
400 if (!fBadPixels)
401 {
402 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
403 if (!fBadPixels)
404 {
405 gLog << err << "Cannot find nor create MBadPixelsCam ... abort." << endl;
406 return kFALSE;
407 }
408 else
409 fBadPixels->InitSize(npixels);
410 }
411
412 //
413 // The function TArrayF::Set() already sets all entries to 0.
414 //
415 fAverageAreaNum. Set(nareas);
416 fAverageAreaSat. Set(nareas);
417 fAverageAreaSigma. Set(nareas);
418 fAverageAreaSigmaVar. Set(nareas);
419 fAverageAreaRelSigma. Set(nareas);
420 fAverageAreaRelSigmaVar.Set(nareas);
421 fAverageSectorNum. Set(nsectors);
422
423 for (Int_t i=0; i<npixels; i++)
424 {
425
426 if ((*fBadPixels)[i].IsBad())
427 continue;
428
429 fAverageAreaNum [(*fGeom)[i].GetAidx() ]++;
430 fAverageSectorNum[(*fGeom)[i].GetSector()]++;
431 }
432
433 return ReInitHists(pList);
434}
435
436
437Bool_t MHCalibrationCam::ReInitHists(MParList *pList)
438{
439 return kTRUE;
440}
441
442
443
444//--------------------------------------------------------------------------------
445//
446// Retrieves from MGeomCam:
447// - number of pixels
448// - number of pixel areas
449// - number of sectors
450//
451// For all TObjArray's (including the averaged ones), the following steps are performed:
452//
453// 1) Test size and return kFALSE if not matching
454// 2)
455//
456Bool_t MHCalibrationCam::Fill(const MParContainer *par, const Stat_t w)
457{
458
459 const Int_t npixels = fGeom->GetNumPixels();
460 const Int_t nareas = fGeom->GetNumAreas();
461 const Int_t nsectors = fGeom->GetNumSectors();
462
463 if (fHiGainArray->GetEntries() != npixels)
464 {
465 gLog << err << "ERROR - Size mismatch... abort." << endl;
466 return kFALSE;
467 }
468
469 if (fLoGainArray->GetEntries() != npixels)
470 {
471 gLog << err << "ERROR - Size mismatch... abort." << endl;
472 return kFALSE;
473 }
474
475 if (fAverageHiGainAreas->GetEntries() != nareas)
476 {
477 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
478 return kFALSE;
479 }
480
481 if (fAverageLoGainAreas->GetEntries() != nareas)
482 {
483 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
484 return kFALSE;
485 }
486
487 if (fAverageHiGainSectors->GetEntries() != nsectors)
488 {
489 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
490 return kFALSE;
491 }
492
493 if (fAverageLoGainSectors->GetEntries() != nsectors)
494 {
495 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
496 return kFALSE;
497 }
498
499 return FillHists(par, w);
500}
501
502Bool_t MHCalibrationCam::FillHists(const MParContainer *par, const Stat_t w)
503{
504 return kTRUE;
505}
506
507// --------------------------------------------------------------------------
508//
509// 1) FinalizeHists()
510// 2) FinalizeBadPixels()
511// 3) CalcAverageSigma()
512//
513Bool_t MHCalibrationCam::Finalize()
514{
515 if (!FinalizeHists())
516 return kFALSE;
517
518 FinalizeBadPixels();
519 CalcAverageSigma();
520
521 return kTRUE;
522}
523
524Bool_t MHCalibrationCam::FinalizeHists()
525{
526 return kTRUE;
527}
528
529void MHCalibrationCam::FinalizeBadPixels()
530{
531}
532
533
534// -------------------------------------------------------------
535//
536// If MBadPixelsPix::IsBad():
537// - calls MHGausEvents::SetExcluded()
538//
539// Calls:
540// - MHGausEvents::InitBins()
541// - MHGausEvents::ChangeHistId(i)
542// - MHGausEvents::SetEventFrequency(fPulserFrequency)
543//
544void MHCalibrationCam::InitHists(MHGausEvents &hist, MBadPixelsPix &bad, const Int_t i)
545{
546
547 if (bad.IsBad())
548 hist.SetExcluded();
549
550 hist.InitBins();
551 hist.ChangeHistId(i);
552 hist.SetEventFrequency(fPulserFrequency);
553
554}
555
556void MHCalibrationCam::FitHiGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
557 MBadPixelsPix::UncalibratedType_t fittyp,
558 MBadPixelsPix::UncalibratedType_t osctyp)
559{
560
561 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
562 {
563
564 MHGausEvents &hist = (*this)[i];
565
566 if (hist.IsExcluded())
567 continue;
568
569 MCalibrationPix &pix = calcam[i];
570 MBadPixelsPix &bad = badcam[i];
571
572 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
573
574 }
575
576 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
577 {
578
579 MHGausEvents &hist = GetAverageHiGainArea(j);
580 MCalibrationPix &pix = calcam.GetAverageArea(j);
581 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
582
583 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
584 }
585
586
587 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
588 {
589
590 MHGausEvents &hist = GetAverageHiGainSector(j);
591 MCalibrationPix &pix = calcam.GetAverageSector(j);
592 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
593
594 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
595 }
596
597}
598
599void MHCalibrationCam::FitLoGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
600 MBadPixelsPix::UncalibratedType_t fittyp,
601 MBadPixelsPix::UncalibratedType_t osctyp)
602{
603
604 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
605 {
606
607 MHGausEvents &hist = (*this)(i);
608
609 if (hist.IsExcluded())
610 continue;
611
612 MCalibrationPix &pix = calcam[i];
613 MBadPixelsPix &bad = badcam[i];
614
615 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
616
617 }
618
619 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
620 {
621
622 MHGausEvents &hist = GetAverageLoGainArea(j);
623 MCalibrationPix &pix = calcam.GetAverageArea(j);
624 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
625
626 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
627 }
628
629
630 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
631 {
632
633 MHGausEvents &hist = GetAverageLoGainSector(j);
634 MCalibrationPix &pix = calcam.GetAverageSector(j);
635 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
636
637 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
638 }
639}
640
641//------------------------------------------------------------
642//
643// For all averaged areas, the fitted sigma is multiplied with the square root of
644// the number involved pixels
645//
646void MHCalibrationCam::CalcAverageSigma()
647{
648
649 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
650 {
651
652 MCalibrationPix &pix = (*fCam).GetAverageArea(j);
653
654 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
655 fAverageAreaSigma[j] = pix.GetSigma () * numsqr;
656 fAverageAreaSigmaVar[j] = pix.GetSigmaErr () * pix.GetSigmaErr() * numsqr;
657
658 pix.SetSigma (fAverageAreaSigma[j]);
659 pix.SetSigmaVar(fAverageAreaSigmaVar[j]);
660
661 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / pix.GetMean();
662 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
663 fAverageAreaRelSigmaVar[j] += pix.GetMeanRelVar();
664 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
665 }
666}
667
668// ---------------------------------------------------------------------------
669//
670// Returns if the histogram is empty and sets the following flag:
671// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
672//
673// Fits the histograms with a Gaussian, in case of failure
674// calls MHGausEvents::RepeatFit(), in case of repeated failure
675// calls MHGausEvents::BypassFit() and sets the following flags:
676// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
677// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
678//
679// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
680// In case no, sets the following flags:
681// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
682// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
683//
684// Retrieves the results and store them in MCalibrationPix
685//
686void MHCalibrationCam::FitHiGainHists(MHGausEvents &hist,
687 MCalibrationPix &pix,
688 MBadPixelsPix &bad,
689 MBadPixelsPix::UncalibratedType_t fittyp,
690 MBadPixelsPix::UncalibratedType_t osctyp)
691{
692
693 if (hist.IsEmpty())
694 return;
695
696 //
697 // 2) Fit the Hi Gain histograms with a Gaussian
698 //
699 if (!hist.FitGaus())
700 //
701 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
702 //
703 if (!hist.RepeatFit())
704 {
705 hist.BypassFit();
706 bad.SetUncalibrated( fittyp );
707 }
708
709 hist.Renorm();
710
711 //
712 // 4) Check for oscillations
713 //
714 hist.CreateFourierSpectrum();
715
716
717 if (!hist.IsFourierSpectrumOK())
718 bad.SetUncalibrated( osctyp );
719
720 //
721 // 5) Retrieve the results and store them in this class
722 //
723 pix.SetHiGainMean ( hist.GetMean() );
724 pix.SetHiGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
725 pix.SetHiGainSigma ( hist.GetSigma() );
726 pix.SetHiGainSigmaVar ( hist.GetSigmaErr()* hist.GetSigmaErr() );
727 pix.SetHiGainProb ( hist.GetProb() );
728 pix.SetHiGainNumBlackout( hist.GetBlackout() );
729 pix.SetHiGainNumPickup ( hist.GetPickup() );
730
731}
732
733
734// ---------------------------------------------------------------------------
735//
736// Returns if the histogram is empty and sets the following flag:
737// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
738//
739// Fits the histograms with a Gaussian, in case of failure
740// calls MHGausEvents::RepeatFit(), in case of repeated failure
741// calls MHGausEvents::BypassFit() and sets the following flags:
742// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
743// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
744//
745// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
746// In case no, sets the following flags:
747// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
748// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
749//
750// Retrieves the results and store them in MCalibrationPix
751//
752void MHCalibrationCam::FitLoGainHists(MHGausEvents &hist,
753 MCalibrationPix &pix,
754 MBadPixelsPix &bad,
755 MBadPixelsPix::UncalibratedType_t fittyp,
756 MBadPixelsPix::UncalibratedType_t osctyp)
757{
758
759 if (hist.IsEmpty())
760 return;
761
762
763 //
764 // 2) Fit the Hi Gain histograms with a Gaussian
765 //
766 if (!hist.FitGaus())
767 //
768 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
769 //
770 if (!hist.RepeatFit())
771 {
772 hist.BypassFit();
773 bad.SetUncalibrated( fittyp );
774 }
775
776 //
777 // 4) Check for oscillations
778 //
779 hist.CreateFourierSpectrum();
780
781 if (!hist.IsFourierSpectrumOK())
782 bad.SetUncalibrated( osctyp );
783
784 //
785 // 5) Retrieve the results and store them in this class
786 //
787 pix.SetLoGainMean ( hist.GetMean() );
788 pix.SetLoGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
789 pix.SetLoGainSigma ( hist.GetSigma() );
790 pix.SetLoGainSigmaVar ( hist.GetSigmaErr() * hist.GetSigmaErr() );
791 pix.SetLoGainProb ( hist.GetProb() );
792 pix.SetLoGainNumBlackout( hist.GetBlackout() );
793 pix.SetLoGainNumPickup ( hist.GetPickup() );
794
795}
796
797
798
799// --------------------------------------------------------------------------
800//
801// Dummy, needed by MCamEvent
802//
803Bool_t MHCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
804{
805 return kTRUE;
806}
807
808// --------------------------------------------------------------------------
809//
810// What MHCamera needs in order to draw an individual pixel in the camera
811//
812void MHCalibrationCam::DrawPixelContent(Int_t idx) const
813{
814}
815
816// -----------------------------------------------------------------------------
817//
818// Default draw:
819//
820// Displays the averaged areas, both High Gain and Low Gain
821//
822// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
823//
824void MHCalibrationCam::Draw(const Option_t *opt)
825{
826
827 const Int_t nareas = fAverageHiGainAreas->GetEntries();
828 if (nareas == 0)
829 return;
830
831 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
832 pad->SetBorderMode(0);
833
834 pad->Divide(2,nareas);
835
836 for (Int_t i=0; i<nareas;i++)
837 {
838
839 pad->cd(2*(i+1)-1);
840 GetAverageHiGainArea(i).Draw(opt);
841
842 if (!fAverageAreaSat[i])
843 DrawAverageSigma(fAverageAreaSat[i], i,
844 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
845 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
846
847 pad->cd(2*(i+1));
848 GetAverageLoGainArea(i).Draw(opt);
849
850 if (fAverageAreaSat[i])
851 DrawAverageSigma(fAverageAreaSat[i], i,
852 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
853 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
854 }
855}
856
857// -----------------------------------------------------------------------------
858//
859// Default draw:
860//
861// Displays a TPaveText with the re-normalized sigmas of the average area
862//
863void MHCalibrationCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
864 Float_t sigma, Float_t sigmavar,
865 Float_t relsigma, Float_t relsigmavar) const
866{
867
868 if (sigma != 0 && sigmavar >= 0 && relsigmavar >= 0.)
869 {
870
871 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
872 newpad->SetFillStyle(4000);
873 newpad->Draw();
874 newpad->cd();
875
876 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
877 text->SetTextSize(0.07);
878 const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
879 " Pixels ", sat ? "Low Gain" : "High Gain");
880 TText *txt1 = text->AddText(line1.Data());
881 const TString line2 = Form("#sigma per pix: %2.2f #pm %2.2f",sigma,TMath::Sqrt(sigmavar));
882 TText *txt2 = text->AddText(line2.Data());
883 const TString line3 = Form("Rel. #sigma per pix: %2.2f #pm %2.2f",relsigma,TMath::Sqrt(relsigmavar));
884 TText *txt3 = text->AddText(line3.Data());
885 text->Draw("");
886
887 text->SetBit(kCanDelete);
888 txt1->SetBit(kCanDelete);
889 txt2->SetBit(kCanDelete);
890 txt3->SetBit(kCanDelete);
891 newpad->SetBit(kCanDelete);
892 }
893}
894
Note: See TracBrowser for help on using the repository browser.