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

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