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

Last change on this file since 4126 was 4121, checked in by gaug, 21 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 /*
306 for (int i=0; i<nhi; i++)
307 {
308 delete (*cam->fHiGainArray)[i];
309 (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
310 }
311 for (int i=0; i<nlo; i++)
312 {
313 delete (*cam->fLoGainArray)[i];
314 (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
315 }
316 */
317
318 for (int i=0; i<navhi; i++)
319 {
320 delete (*cam->fAverageHiGainAreas)[i];
321 (*cam->fAverageHiGainAreas)[i] = (*fAverageHiGainAreas)[i]->Clone();
322 }
323 for (int i=0; i<navlo; i++)
324 {
325 delete (*cam->fAverageLoGainAreas)[i];
326 (*cam->fAverageLoGainAreas)[i] = (*fAverageLoGainAreas)[i]->Clone();
327 }
328 for (int i=0; i<nsehi; i++)
329 {
330 delete (*cam->fAverageHiGainSectors)[i];
331 (*cam->fAverageHiGainSectors)[i] = (*fAverageHiGainSectors)[i]->Clone();
332 }
333 for (int i=0; i<nselo; i++)
334 {
335 delete (*cam->fAverageLoGainSectors)[i];
336 (*cam->fAverageLoGainSectors)[i] = (*fAverageLoGainSectors)[i]->Clone();
337 }
338
339 cam->fAverageAreaNum = fAverageAreaNum;
340 cam->fAverageAreaSat = fAverageAreaSat;
341 cam->fAverageAreaSigma = fAverageAreaSigma;
342 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
343 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
344 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
345 cam->fAverageSectorNum = fAverageSectorNum;
346 cam->fRunNumbers = fRunNumbers;
347
348 cam->fPulserFrequency = fPulserFrequency;
349 cam->fAverageNbins = fAverageNbins;
350
351 return cam;
352}
353
354// --------------------------------------------------------------------------
355//
356// Gets the pointers to:
357// - MGeomCam
358//
359// Calls SetupHists(const MParList *pList)
360//
361// Calls Delete-Function of:
362// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
363// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
364// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
365//
366Bool_t MHCalibrationCam::SetupFill(const MParList *pList)
367{
368
369 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
370 if (!fGeom)
371 {
372 *fLog << err << GetDescriptor()
373 << ": MGeomCam not found... aborting." << endl;
374 return kFALSE;
375 }
376
377 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
378 if (!fRunHeader)
379 {
380 *fLog << warn << GetDescriptor()
381 << ": MRawRunHeader not found... will not store run numbers." << endl;
382 }
383
384 fHiGainArray->Delete();
385 fLoGainArray->Delete();
386
387 fAverageHiGainAreas->Delete();
388 fAverageLoGainAreas->Delete();
389
390 fAverageHiGainSectors->Delete();
391 fAverageLoGainSectors->Delete();
392
393 return SetupHists(pList);
394}
395
396
397Bool_t MHCalibrationCam::SetupHists(const MParList *pList)
398{
399 return kTRUE;
400}
401
402// --------------------------------------------------------------------------
403//
404// Gets or creates the pointers to:
405// - MBadPixelsCam
406//
407// Searches pointer to:
408// - MArrivalTimeCam
409//
410// Initializes, if empty to MArrivalTimeCam::GetSize() for:
411// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
412//
413// Initializes, if empty to MGeomCam::GetNumAreas() for:
414// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
415//
416// Initializes, if empty to MGeomCam::GetNumSectors() for:
417// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
418//
419// Initializes TArray's to MGeomCam::GetNumAreas and MGeomCam::GetNumSectors, respectively
420// Fills with number of valid pixels (if !MBadPixelsPix::IsBad()):
421// - MHCalibrationCam::fAverageAreaNum[area index]
422// - MHCalibrationCam::fAverageSectorNum[area index]
423//
424// Calls InitializeHists() for every entry in:
425// - MHCalibrationCam::fHiGainArray
426// - MHCalibrationCam::fAverageHiGainAreas
427// - MHCalibrationCam::fAverageHiGainSectors
428//
429// Sets Titles and Names for the Histograms
430// - MHCalibrationCam::fAverageHiGainAreas
431// - MHCalibrationCam::fAverageHiGainSectors
432//
433// Retrieves the run numbers from MRawRunHeader and stores them in fRunNumbers
434//
435Bool_t MHCalibrationCam::ReInit(MParList *pList)
436{
437
438 const Int_t npixels = fGeom->GetNumPixels();
439 const Int_t nsectors = fGeom->GetNumSectors();
440 const Int_t nareas = fGeom->GetNumAreas();
441
442 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
443 if (!fBadPixels)
444 {
445
446 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
447 if (!fBadPixels)
448 {
449 gLog << err << "Cannot find nor create MBadPixelsCam ... abort." << endl;
450 return kFALSE;
451 }
452 else
453 fBadPixels->InitSize(npixels);
454 }
455
456 //
457 // The function TArrayF::Set() already sets all entries to 0.
458 //
459 fAverageAreaNum. Set(nareas);
460 fAverageAreaSat. Set(nareas);
461 fAverageAreaSigma. Set(nareas);
462 fAverageAreaSigmaVar. Set(nareas);
463 fAverageAreaRelSigma. Set(nareas);
464 fAverageAreaRelSigmaVar.Set(nareas);
465 fAverageSectorNum. Set(nsectors);
466 fRunNumbers. Set(fRunNumbers.GetSize()+1);
467
468 for (Int_t aidx=0; aidx<nareas; aidx++)
469 fAverageAreaNum[aidx] = 0;
470
471 for (Int_t sector=0; sector<nsectors; sector++)
472 fAverageSectorNum[sector] = 0;
473
474 for (Int_t i=0; i<npixels; i++)
475 {
476
477 if ((*fBadPixels)[i].IsBad())
478 continue;
479
480 fAverageAreaNum [(*fGeom)[i].GetAidx() ]++;
481 fAverageSectorNum[(*fGeom)[i].GetSector()]++;
482 }
483
484 if (fRunHeader)
485 fRunNumbers[fRunNumbers.GetSize()-1] = fRunHeader->GetRunNumber();
486
487 if (!ReInitHists(pList))
488 return kFALSE;
489
490 if (!fRunHeader)
491 return kTRUE;
492
493 for (Int_t i=0; i<fHiGainArray->GetEntries(); i++)
494 {
495 TH1F *h = (*this)[i].GetHGausHist();
496 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
497 }
498
499 for (Int_t i=0; i<fLoGainArray->GetEntries(); i++)
500 {
501 TH1F *h = (*this)(i).GetHGausHist();
502 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
503 }
504
505 for (Int_t j=0; j<nareas; j++)
506 {
507 TH1F *h = GetAverageHiGainArea(j).GetHGausHist();
508 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
509 }
510
511 for (Int_t j=0; j<nareas; j++)
512 {
513 TH1F *h = GetAverageLoGainArea(j).GetHGausHist();
514 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
515 }
516
517 for (Int_t j=0; j<nsectors; j++)
518 {
519 TH1F *h = GetAverageHiGainSector(j).GetHGausHist();
520 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
521 }
522
523 for (Int_t j=0; j<nsectors; j++)
524 {
525 TH1F *h = GetAverageLoGainSector(j).GetHGausHist();
526 h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
527 }
528
529 return kTRUE;
530}
531
532
533
534Bool_t MHCalibrationCam::ReInitHists(MParList *pList)
535{
536 return kTRUE;
537}
538
539
540
541//--------------------------------------------------------------------------------
542//
543// Retrieves from MGeomCam:
544// - number of pixels
545// - number of pixel areas
546// - number of sectors
547//
548// For all TObjArray's (including the averaged ones), the following steps are performed:
549//
550// 1) Test size and return kFALSE if not matching
551// 2)
552//
553Bool_t MHCalibrationCam::Fill(const MParContainer *par, const Stat_t w)
554{
555
556 const Int_t npixels = fGeom->GetNumPixels();
557 const Int_t nareas = fGeom->GetNumAreas();
558 const Int_t nsectors = fGeom->GetNumSectors();
559
560 if (fHiGainArray->GetEntries() != npixels)
561 {
562 gLog << err << "ERROR - Size mismatch... abort." << endl;
563 return kFALSE;
564 }
565
566 if (fLoGainArray->GetEntries() != npixels)
567 {
568 gLog << err << "ERROR - Size mismatch... abort." << endl;
569 return kFALSE;
570 }
571
572 if (fAverageHiGainAreas->GetEntries() != nareas)
573 {
574 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
575 return kFALSE;
576 }
577
578 if (fAverageLoGainAreas->GetEntries() != nareas)
579 {
580 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
581 return kFALSE;
582 }
583
584 if (fAverageHiGainSectors->GetEntries() != nsectors)
585 {
586 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
587 return kFALSE;
588 }
589
590 if (fAverageLoGainSectors->GetEntries() != nsectors)
591 {
592 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
593 return kFALSE;
594 }
595
596 return FillHists(par, w);
597}
598
599Bool_t MHCalibrationCam::FillHists(const MParContainer *par, const Stat_t w)
600{
601 return kTRUE;
602}
603
604// --------------------------------------------------------------------------
605//
606// 1) FinalizeHists()
607// 2) FinalizeBadPixels()
608// 3) CalcAverageSigma()
609//
610Bool_t MHCalibrationCam::Finalize()
611{
612 if (!FinalizeHists())
613 return kFALSE;
614
615 FinalizeBadPixels();
616 CalcAverageSigma();
617
618 return kTRUE;
619}
620
621Bool_t MHCalibrationCam::FinalizeHists()
622{
623 return kTRUE;
624}
625
626void MHCalibrationCam::FinalizeBadPixels()
627{
628}
629
630
631// -------------------------------------------------------------
632//
633// If MBadPixelsPix::IsBad():
634// - calls MHGausEvents::SetExcluded()
635//
636// Calls:
637// - MHGausEvents::InitBins()
638// - MHGausEvents::ChangeHistId(i)
639// - MHGausEvents::SetEventFrequency(fPulserFrequency)
640//
641void MHCalibrationCam::InitHists(MHGausEvents &hist, MBadPixelsPix &bad, const Int_t i)
642{
643
644 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
645 hist.SetExcluded();
646
647 hist.InitBins();
648 hist.ChangeHistId(i);
649 hist.SetEventFrequency(fPulserFrequency);
650
651 TH1F *h = hist.GetHGausHist();
652 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
653}
654
655void MHCalibrationCam::FitHiGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
656 MBadPixelsPix::UncalibratedType_t fittyp,
657 MBadPixelsPix::UncalibratedType_t osctyp)
658{
659
660 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
661 {
662
663 MHGausEvents &hist = (*this)[i];
664
665 if (hist.IsExcluded())
666 continue;
667
668 MCalibrationPix &pix = calcam[i];
669 MBadPixelsPix &bad = badcam[i];
670
671 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
672
673 }
674
675 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
676 {
677
678 MHGausEvents &hist = GetAverageHiGainArea(j);
679 MCalibrationPix &pix = calcam.GetAverageArea(j);
680 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
681
682 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
683 }
684
685
686 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
687 {
688
689 MHGausEvents &hist = GetAverageHiGainSector(j);
690 MCalibrationPix &pix = calcam.GetAverageSector(j);
691 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
692
693 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
694 }
695
696}
697
698void MHCalibrationCam::FitLoGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
699 MBadPixelsPix::UncalibratedType_t fittyp,
700 MBadPixelsPix::UncalibratedType_t osctyp)
701{
702
703 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
704 {
705
706 MHGausEvents &hist = (*this)(i);
707
708 if (hist.IsExcluded())
709 continue;
710
711 MCalibrationPix &pix = calcam[i];
712 MBadPixelsPix &bad = badcam[i];
713
714 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
715
716 }
717
718 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
719 {
720
721 MHGausEvents &hist = GetAverageLoGainArea(j);
722 MCalibrationPix &pix = calcam.GetAverageArea(j);
723 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
724
725 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
726 }
727
728
729 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
730 {
731
732 MHGausEvents &hist = GetAverageLoGainSector(j);
733 MCalibrationPix &pix = calcam.GetAverageSector(j);
734 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
735
736 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
737 }
738}
739
740//------------------------------------------------------------
741//
742// For all averaged areas, the fitted sigma is multiplied with the square root of
743// the number involved pixels
744//
745void MHCalibrationCam::CalcAverageSigma()
746{
747
748 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
749 {
750
751 MCalibrationPix &pix = (*fCam).GetAverageArea(j);
752
753 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
754 fAverageAreaSigma[j] = pix.GetSigma () * numsqr;
755 fAverageAreaSigmaVar[j] = pix.GetSigmaErr () * pix.GetSigmaErr() * numsqr;
756
757 pix.SetSigma (fAverageAreaSigma[j]);
758 pix.SetSigmaVar(fAverageAreaSigmaVar[j]);
759
760 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / pix.GetMean();
761 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
762 fAverageAreaRelSigmaVar[j] += pix.GetMeanRelVar();
763 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
764 }
765}
766
767// ---------------------------------------------------------------------------
768//
769// Returns if the histogram is empty and sets the following flag:
770// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
771//
772// Fits the histograms with a Gaussian, in case of failure
773// calls MHGausEvents::RepeatFit(), in case of repeated failure
774// calls MHGausEvents::BypassFit() and sets the following flags:
775// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
776// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
777//
778// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
779// In case no, sets the following flags:
780// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
781// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
782//
783// Retrieves the results and store them in MCalibrationPix
784//
785void MHCalibrationCam::FitHiGainHists(MHGausEvents &hist,
786 MCalibrationPix &pix,
787 MBadPixelsPix &bad,
788 MBadPixelsPix::UncalibratedType_t fittyp,
789 MBadPixelsPix::UncalibratedType_t osctyp)
790{
791
792 if (hist.IsEmpty())
793 return;
794
795 //
796 // 2) Fit the Hi Gain histograms with a Gaussian
797 //
798 if (!hist.FitGaus())
799 //
800 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
801 //
802 if (!hist.RepeatFit())
803 {
804 hist.BypassFit();
805 bad.SetUncalibrated( fittyp );
806 }
807
808 hist.Renorm();
809 //
810 // 4) Check for oscillations
811 //
812 hist.CreateFourierSpectrum();
813
814
815 if (!hist.IsFourierSpectrumOK())
816 bad.SetUncalibrated( osctyp );
817
818 //
819 // 5) Retrieve the results and store them in this class
820 //
821 pix.SetHiGainMean ( hist.GetMean() );
822 pix.SetHiGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
823 pix.SetHiGainSigma ( hist.GetSigma() );
824 pix.SetHiGainSigmaVar ( hist.GetSigmaErr()* hist.GetSigmaErr() );
825 pix.SetHiGainProb ( hist.GetProb() );
826 pix.SetHiGainNumBlackout( hist.GetBlackout() );
827 pix.SetHiGainNumPickup ( hist.GetPickup() );
828
829}
830
831
832// ---------------------------------------------------------------------------
833//
834// Returns if the histogram is empty and sets the following flag:
835// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
836//
837// Fits the histograms with a Gaussian, in case of failure
838// calls MHGausEvents::RepeatFit(), in case of repeated failure
839// calls MHGausEvents::BypassFit() and sets the following flags:
840// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
841// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
842//
843// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
844// In case no, sets the following flags:
845// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
846// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
847//
848// Retrieves the results and store them in MCalibrationPix
849//
850void MHCalibrationCam::FitLoGainHists(MHGausEvents &hist,
851 MCalibrationPix &pix,
852 MBadPixelsPix &bad,
853 MBadPixelsPix::UncalibratedType_t fittyp,
854 MBadPixelsPix::UncalibratedType_t osctyp)
855{
856
857 if (hist.IsEmpty())
858 return;
859
860
861 //
862 // 2) Fit the Hi Gain histograms with a Gaussian
863 //
864 if (!hist.FitGaus())
865 //
866 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
867 //
868 if (!hist.RepeatFit())
869 {
870 hist.BypassFit();
871 bad.SetUncalibrated( fittyp );
872 }
873
874 //
875 // 4) Check for oscillations
876 //
877 hist.CreateFourierSpectrum();
878
879 if (!hist.IsFourierSpectrumOK())
880 bad.SetUncalibrated( osctyp );
881
882 //
883 // 5) Retrieve the results and store them in this class
884 //
885 pix.SetLoGainMean ( hist.GetMean() );
886 pix.SetLoGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
887 pix.SetLoGainSigma ( hist.GetSigma() );
888 pix.SetLoGainSigmaVar ( hist.GetSigmaErr() * hist.GetSigmaErr() );
889 pix.SetLoGainProb ( hist.GetProb() );
890 pix.SetLoGainNumBlackout( hist.GetBlackout() );
891 pix.SetLoGainNumPickup ( hist.GetPickup() );
892
893}
894
895
896
897// --------------------------------------------------------------------------
898//
899// Dummy, needed by MCamEvent
900//
901Bool_t MHCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
902{
903 return kTRUE;
904}
905
906// --------------------------------------------------------------------------
907//
908// What MHCamera needs in order to draw an individual pixel in the camera
909//
910void MHCalibrationCam::DrawPixelContent(Int_t idx) const
911{
912}
913
914// -----------------------------------------------------------------------------
915//
916// Default draw:
917//
918// Displays the averaged areas, both High Gain and Low Gain
919//
920// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
921//
922void MHCalibrationCam::Draw(const Option_t *opt)
923{
924
925 const Int_t nareas = fAverageHiGainAreas->GetEntries();
926 if (nareas == 0)
927 return;
928
929 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
930 pad->SetBorderMode(0);
931
932 pad->Divide(2,nareas);
933
934 for (Int_t i=0; i<nareas;i++)
935 {
936
937 pad->cd(2*(i+1)-1);
938 GetAverageHiGainArea(i).Draw(opt);
939
940 if (!fAverageAreaSat[i])
941 DrawAverageSigma(fAverageAreaSat[i], i,
942 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
943 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
944
945 pad->cd(2*(i+1));
946 GetAverageLoGainArea(i).Draw(opt);
947
948 if (fAverageAreaSat[i])
949 DrawAverageSigma(fAverageAreaSat[i], i,
950 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
951 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
952 }
953}
954
955// -----------------------------------------------------------------------------
956//
957// Default draw:
958//
959// Displays a TPaveText with the re-normalized sigmas of the average area
960//
961void MHCalibrationCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
962 Float_t sigma, Float_t sigmavar,
963 Float_t relsigma, Float_t relsigmavar) const
964{
965
966 if (sigma != 0 && sigmavar >= 0 && relsigmavar >= 0.)
967 {
968
969 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
970 newpad->SetFillStyle(4000);
971 newpad->Draw();
972 newpad->cd();
973
974 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
975 text->SetTextSize(0.07);
976 const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
977 " Pixels ", sat ? "Low Gain" : "High Gain");
978 TText *txt1 = text->AddText(line1.Data());
979 const TString line2 = Form("#sigma per pix: %2.2f #pm %2.2f",sigma,TMath::Sqrt(sigmavar));
980 TText *txt2 = text->AddText(line2.Data());
981 const TString line3 = Form("Rel. #sigma per pix: %2.2f #pm %2.2f",relsigma,TMath::Sqrt(relsigmavar));
982 TText *txt3 = text->AddText(line3.Data());
983 text->Draw("");
984
985 text->SetBit(kCanDelete);
986 txt1->SetBit(kCanDelete);
987 txt2->SetBit(kCanDelete);
988 txt3->SetBit(kCanDelete);
989 newpad->SetBit(kCanDelete);
990 }
991}
992
Note: See TracBrowser for help on using the repository browser.