source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc@ 4946

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