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

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