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

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