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

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