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

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