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

Last change on this file since 3723 was 3723, checked in by gaug, 20 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
403 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
404 if (!fBadPixels)
405 {
406 gLog << err << "Cannot find nor create MBadPixelsCam ... abort." << endl;
407 return kFALSE;
408 }
409 else
410 fBadPixels->InitSize(npixels);
411 }
412
413 //
414 // The function TArrayF::Set() already sets all entries to 0.
415 //
416 fAverageAreaNum. Set(nareas);
417 fAverageAreaSat. Set(nareas);
418 fAverageAreaSigma. Set(nareas);
419 fAverageAreaSigmaVar. Set(nareas);
420 fAverageAreaRelSigma. Set(nareas);
421 fAverageAreaRelSigmaVar.Set(nareas);
422 fAverageSectorNum. Set(nsectors);
423
424 for (Int_t i=0; i<npixels; i++)
425 {
426
427 if ((*fBadPixels)[i].IsBad())
428 continue;
429
430 fAverageAreaNum [(*fGeom)[i].GetAidx() ]++;
431 fAverageSectorNum[(*fGeom)[i].GetSector()]++;
432 }
433
434 return ReInitHists(pList);
435}
436
437
438Bool_t MHCalibrationCam::ReInitHists(MParList *pList)
439{
440 return kTRUE;
441}
442
443
444
445//--------------------------------------------------------------------------------
446//
447// Retrieves from MGeomCam:
448// - number of pixels
449// - number of pixel areas
450// - number of sectors
451//
452// For all TObjArray's (including the averaged ones), the following steps are performed:
453//
454// 1) Test size and return kFALSE if not matching
455// 2)
456//
457Bool_t MHCalibrationCam::Fill(const MParContainer *par, const Stat_t w)
458{
459
460 const Int_t npixels = fGeom->GetNumPixels();
461 const Int_t nareas = fGeom->GetNumAreas();
462 const Int_t nsectors = fGeom->GetNumSectors();
463
464 if (fHiGainArray->GetEntries() != npixels)
465 {
466 gLog << err << "ERROR - Size mismatch... abort." << endl;
467 return kFALSE;
468 }
469
470 if (fLoGainArray->GetEntries() != npixels)
471 {
472 gLog << err << "ERROR - Size mismatch... abort." << endl;
473 return kFALSE;
474 }
475
476 if (fAverageHiGainAreas->GetEntries() != nareas)
477 {
478 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
479 return kFALSE;
480 }
481
482 if (fAverageLoGainAreas->GetEntries() != nareas)
483 {
484 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
485 return kFALSE;
486 }
487
488 if (fAverageHiGainSectors->GetEntries() != nsectors)
489 {
490 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
491 return kFALSE;
492 }
493
494 if (fAverageLoGainSectors->GetEntries() != nsectors)
495 {
496 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
497 return kFALSE;
498 }
499
500 return FillHists(par, w);
501}
502
503Bool_t MHCalibrationCam::FillHists(const MParContainer *par, const Stat_t w)
504{
505 return kTRUE;
506}
507
508// --------------------------------------------------------------------------
509//
510// 1) FinalizeHists()
511// 2) FinalizeBadPixels()
512// 3) CalcAverageSigma()
513//
514Bool_t MHCalibrationCam::Finalize()
515{
516 if (!FinalizeHists())
517 return kFALSE;
518
519 FinalizeBadPixels();
520 CalcAverageSigma();
521
522 return kTRUE;
523}
524
525Bool_t MHCalibrationCam::FinalizeHists()
526{
527 return kTRUE;
528}
529
530void MHCalibrationCam::FinalizeBadPixels()
531{
532}
533
534
535// -------------------------------------------------------------
536//
537// If MBadPixelsPix::IsBad():
538// - calls MHGausEvents::SetExcluded()
539//
540// Calls:
541// - MHGausEvents::InitBins()
542// - MHGausEvents::ChangeHistId(i)
543// - MHGausEvents::SetEventFrequency(fPulserFrequency)
544//
545void MHCalibrationCam::InitHists(MHGausEvents &hist, MBadPixelsPix &bad, const Int_t i)
546{
547
548 if (bad.IsBad())
549 hist.SetExcluded();
550
551 hist.InitBins();
552 hist.ChangeHistId(i);
553 hist.SetEventFrequency(fPulserFrequency);
554
555}
556
557void MHCalibrationCam::FitHiGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
558 MBadPixelsPix::UncalibratedType_t fittyp,
559 MBadPixelsPix::UncalibratedType_t osctyp)
560{
561
562 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
563 {
564
565 MHGausEvents &hist = (*this)[i];
566
567 if (hist.IsExcluded())
568 continue;
569
570 MCalibrationPix &pix = calcam[i];
571 MBadPixelsPix &bad = badcam[i];
572
573 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
574
575 }
576
577 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
578 {
579
580 MHGausEvents &hist = GetAverageHiGainArea(j);
581 MCalibrationPix &pix = calcam.GetAverageArea(j);
582 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
583
584 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
585 }
586
587
588 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
589 {
590
591 MHGausEvents &hist = GetAverageHiGainSector(j);
592 MCalibrationPix &pix = calcam.GetAverageSector(j);
593 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
594
595 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
596 }
597
598}
599
600void MHCalibrationCam::FitLoGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
601 MBadPixelsPix::UncalibratedType_t fittyp,
602 MBadPixelsPix::UncalibratedType_t osctyp)
603{
604
605 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
606 {
607
608 MHGausEvents &hist = (*this)(i);
609
610 if (hist.IsExcluded())
611 continue;
612
613 MCalibrationPix &pix = calcam[i];
614 MBadPixelsPix &bad = badcam[i];
615
616 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
617
618 }
619
620 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
621 {
622
623 MHGausEvents &hist = GetAverageLoGainArea(j);
624 MCalibrationPix &pix = calcam.GetAverageArea(j);
625 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
626
627 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
628 }
629
630
631 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
632 {
633
634 MHGausEvents &hist = GetAverageLoGainSector(j);
635 MCalibrationPix &pix = calcam.GetAverageSector(j);
636 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
637
638 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
639 }
640}
641
642//------------------------------------------------------------
643//
644// For all averaged areas, the fitted sigma is multiplied with the square root of
645// the number involved pixels
646//
647void MHCalibrationCam::CalcAverageSigma()
648{
649
650 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
651 {
652
653 MCalibrationPix &pix = (*fCam).GetAverageArea(j);
654
655 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
656 fAverageAreaSigma[j] = pix.GetSigma () * numsqr;
657 fAverageAreaSigmaVar[j] = pix.GetSigmaErr () * pix.GetSigmaErr() * numsqr;
658
659 pix.SetSigma (fAverageAreaSigma[j]);
660 pix.SetSigmaVar(fAverageAreaSigmaVar[j]);
661
662 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / pix.GetMean();
663 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
664 fAverageAreaRelSigmaVar[j] += pix.GetMeanRelVar();
665 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
666 }
667}
668
669// ---------------------------------------------------------------------------
670//
671// Returns if the histogram is empty and sets the following flag:
672// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
673//
674// Fits the histograms with a Gaussian, in case of failure
675// calls MHGausEvents::RepeatFit(), in case of repeated failure
676// calls MHGausEvents::BypassFit() and sets the following flags:
677// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
678// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
679//
680// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
681// In case no, sets the following flags:
682// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
683// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
684//
685// Retrieves the results and store them in MCalibrationPix
686//
687void MHCalibrationCam::FitHiGainHists(MHGausEvents &hist,
688 MCalibrationPix &pix,
689 MBadPixelsPix &bad,
690 MBadPixelsPix::UncalibratedType_t fittyp,
691 MBadPixelsPix::UncalibratedType_t osctyp)
692{
693
694 if (hist.IsEmpty())
695 return;
696
697 //
698 // 2) Fit the Hi Gain histograms with a Gaussian
699 //
700 if (!hist.FitGaus())
701 //
702 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
703 //
704 if (!hist.RepeatFit())
705 {
706 hist.BypassFit();
707 bad.SetUncalibrated( fittyp );
708 }
709
710 hist.Renorm();
711
712 //
713 // 4) Check for oscillations
714 //
715 hist.CreateFourierSpectrum();
716
717
718 if (!hist.IsFourierSpectrumOK())
719 bad.SetUncalibrated( osctyp );
720
721 //
722 // 5) Retrieve the results and store them in this class
723 //
724 pix.SetHiGainMean ( hist.GetMean() );
725 pix.SetHiGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
726 pix.SetHiGainSigma ( hist.GetSigma() );
727 pix.SetHiGainSigmaVar ( hist.GetSigmaErr()* hist.GetSigmaErr() );
728 pix.SetHiGainProb ( hist.GetProb() );
729 pix.SetHiGainNumBlackout( hist.GetBlackout() );
730 pix.SetHiGainNumPickup ( hist.GetPickup() );
731
732}
733
734
735// ---------------------------------------------------------------------------
736//
737// Returns if the histogram is empty and sets the following flag:
738// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
739//
740// Fits the histograms with a Gaussian, in case of failure
741// calls MHGausEvents::RepeatFit(), in case of repeated failure
742// calls MHGausEvents::BypassFit() and sets the following flags:
743// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
744// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
745//
746// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
747// In case no, sets the following flags:
748// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
749// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
750//
751// Retrieves the results and store them in MCalibrationPix
752//
753void MHCalibrationCam::FitLoGainHists(MHGausEvents &hist,
754 MCalibrationPix &pix,
755 MBadPixelsPix &bad,
756 MBadPixelsPix::UncalibratedType_t fittyp,
757 MBadPixelsPix::UncalibratedType_t osctyp)
758{
759
760 if (hist.IsEmpty())
761 return;
762
763
764 //
765 // 2) Fit the Hi Gain histograms with a Gaussian
766 //
767 if (!hist.FitGaus())
768 //
769 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
770 //
771 if (!hist.RepeatFit())
772 {
773 hist.BypassFit();
774 bad.SetUncalibrated( fittyp );
775 }
776
777 //
778 // 4) Check for oscillations
779 //
780 hist.CreateFourierSpectrum();
781
782 if (!hist.IsFourierSpectrumOK())
783 bad.SetUncalibrated( osctyp );
784
785 //
786 // 5) Retrieve the results and store them in this class
787 //
788 pix.SetLoGainMean ( hist.GetMean() );
789 pix.SetLoGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
790 pix.SetLoGainSigma ( hist.GetSigma() );
791 pix.SetLoGainSigmaVar ( hist.GetSigmaErr() * hist.GetSigmaErr() );
792 pix.SetLoGainProb ( hist.GetProb() );
793 pix.SetLoGainNumBlackout( hist.GetBlackout() );
794 pix.SetLoGainNumPickup ( hist.GetPickup() );
795
796}
797
798
799
800// --------------------------------------------------------------------------
801//
802// Dummy, needed by MCamEvent
803//
804Bool_t MHCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
805{
806 return kTRUE;
807}
808
809// --------------------------------------------------------------------------
810//
811// What MHCamera needs in order to draw an individual pixel in the camera
812//
813void MHCalibrationCam::DrawPixelContent(Int_t idx) const
814{
815}
816
817// -----------------------------------------------------------------------------
818//
819// Default draw:
820//
821// Displays the averaged areas, both High Gain and Low Gain
822//
823// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
824//
825void MHCalibrationCam::Draw(const Option_t *opt)
826{
827
828 const Int_t nareas = fAverageHiGainAreas->GetEntries();
829 if (nareas == 0)
830 return;
831
832 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
833 pad->SetBorderMode(0);
834
835 pad->Divide(2,nareas);
836
837 for (Int_t i=0; i<nareas;i++)
838 {
839
840 pad->cd(2*(i+1)-1);
841 GetAverageHiGainArea(i).Draw(opt);
842
843 if (!fAverageAreaSat[i])
844 DrawAverageSigma(fAverageAreaSat[i], i,
845 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
846 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
847
848 pad->cd(2*(i+1));
849 GetAverageLoGainArea(i).Draw(opt);
850
851 if (fAverageAreaSat[i])
852 DrawAverageSigma(fAverageAreaSat[i], i,
853 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
854 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
855 }
856}
857
858// -----------------------------------------------------------------------------
859//
860// Default draw:
861//
862// Displays a TPaveText with the re-normalized sigmas of the average area
863//
864void MHCalibrationCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
865 Float_t sigma, Float_t sigmavar,
866 Float_t relsigma, Float_t relsigmavar) const
867{
868
869 if (sigma != 0 && sigmavar >= 0 && relsigmavar >= 0.)
870 {
871
872 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
873 newpad->SetFillStyle(4000);
874 newpad->Draw();
875 newpad->cd();
876
877 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
878 text->SetTextSize(0.07);
879 const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
880 " Pixels ", sat ? "Low Gain" : "High Gain");
881 TText *txt1 = text->AddText(line1.Data());
882 const TString line2 = Form("#sigma per pix: %2.2f #pm %2.2f",sigma,TMath::Sqrt(sigmavar));
883 TText *txt2 = text->AddText(line2.Data());
884 const TString line3 = Form("Rel. #sigma per pix: %2.2f #pm %2.2f",relsigma,TMath::Sqrt(relsigmavar));
885 TText *txt3 = text->AddText(line3.Data());
886 text->Draw("");
887
888 text->SetBit(kCanDelete);
889 txt1->SetBit(kCanDelete);
890 txt2->SetBit(kCanDelete);
891 txt3->SetBit(kCanDelete);
892 newpad->SetBit(kCanDelete);
893 }
894}
895
Note: See TracBrowser for help on using the repository browser.