source: tags/Mars-V0.9.2/mhcalib/MHCalibrationCam.cc

Last change on this file was 7005, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 48.8 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 TOrdCollection'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 TOrdCollection'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// - SetAverageing() for calculating the event-by-event averages.
45// - SetDebug() for debug output.
46// - SetLoGain() for the case that low-gain slices are available, but
47// MRawRunHeader::GetNumLoGainSlices() gives still 0.
48// - SetCheckSize() for testing the sizes of the f*Arrays in ReInit() if they
49// are coinciding with the equiv. sizes in MGeomCam
50//
51// The flag kLoGain steers if the low-gain signal is treated at all or not.
52// The flag kAverageing steers if the event-by-event averages are treated at all.
53//
54// Class Version 5:
55// + Double_t fLowerFitLimitHiGain; // Lower limit for the fit range for the hi-gain hist
56// + Double_t fUpperFitLimitHiGain; // Upper limit for the fit range for the hi-gain hist
57// + Double_t fLowerFitLimitLoGain; // Lower limit for the fit range for the lo-gain hist
58// + Double_t fUpperFitLimitLoGain; // Upper limit for the fit range for the lo-gain hist
59// + Bool_t fIsHiGainFitRanges; // Are high-gain fit ranges defined?
60// + Bool_t fIsLoGainFitRanges; // Are low-gain fit ranges defined?
61//
62//
63/////////////////////////////////////////////////////////////////////////////
64#include "MHCalibrationCam.h"
65#include "MHCalibrationPix.h"
66
67#include <TVirtualPad.h>
68#include <TCanvas.h>
69#include <TPad.h>
70#include <TText.h>
71#include <TPaveText.h>
72#include <TOrdCollection.h>
73#include <TROOT.h>
74
75#include "MLog.h"
76#include "MLogManip.h"
77
78#include "MCalibrationIntensityCam.h"
79#include "MCalibrationCam.h"
80#include "MCalibrationPix.h"
81
82#include "MBadPixelsIntensityCam.h"
83#include "MBadPixelsCam.h"
84#include "MBadPixelsPix.h"
85
86#include "MGeomCam.h"
87#include "MGeomPix.h"
88
89#include "MParList.h"
90
91#include "MRawRunHeader.h"
92
93ClassImp(MHCalibrationCam);
94
95using namespace std;
96
97const Double_t MHCalibrationCam::fgLowerFitLimitHiGain = 0;
98const Double_t MHCalibrationCam::fgUpperFitLimitHiGain = 0;
99const Double_t MHCalibrationCam::fgLowerFitLimitLoGain = 0;
100const Double_t MHCalibrationCam::fgUpperFitLimitLoGain = 0;
101
102const Int_t MHCalibrationCam::fgPulserFrequency = 500;
103const Float_t MHCalibrationCam::fgProbLimit = 0.0001;
104const Float_t MHCalibrationCam::fgOverflowLimit = 0.005;
105
106const TString MHCalibrationCam::gsHistName = "Hist";
107const TString MHCalibrationCam::gsHistTitle = "";
108const TString MHCalibrationCam::gsHistXTitle = "";
109const TString MHCalibrationCam::gsHistYTitle = "Nr. events";
110
111// --------------------------------------------------------------------------
112//
113// Default Constructor.
114//
115// Sets:
116// - all pointers to NULL
117//
118// Initializes and sets owner of:
119// - fHiGainArray, fLoGainArray
120// - fAverageHiGainAreas, fAverageLoGainAreas
121// - fAverageHiGainSectors, fAverageLoGainSectors
122//
123// Initializes:
124// - fPulserFrequency to fgPulserFrequency
125// - fProbLimit to fgProbLimit
126// - fOverflowLimit to fgOverflowLimit
127//
128// - SetAveregeing (kTRUE);
129// - SetDebug (kFALSE);
130// - SetLoGain (kTRUE);
131//- SetOscillations(kTRUE);
132//- SetSizeCheck (kTRUE);
133//- SetInterlaced (kFALSE);
134//- SetLowerFitLimitHiGain();
135//- SetUpperFitLimitHiGain();
136//- SetLowerFitLimitLoGain();
137//- SetUpperFitLimitLoGain();
138//
139MHCalibrationCam::MHCalibrationCam(const char *name, const char *title)
140 : fIsHiGainFitRanges(kFALSE), fIsLoGainFitRanges(kFALSE),
141 fHistName(gsHistName),fHistTitle(gsHistTitle),
142 fHistXTitle(gsHistXTitle),fHistYTitle(gsHistYTitle),
143 fColor(MCalibrationCam::kNONE), fIntensBad(NULL),
144 fBadPixels(NULL), fIntensCam(NULL), fCam(NULL), fGeom(NULL),
145 fRunHeader(NULL)
146{
147
148 fHiGainArray = new TOrdCollection;
149 fHiGainArray->SetOwner();
150
151 fLoGainArray = new TOrdCollection;
152 fLoGainArray->SetOwner();
153
154 fAverageHiGainAreas = new TOrdCollection;
155 fAverageHiGainAreas->SetOwner();
156
157 fAverageLoGainAreas = new TOrdCollection;
158 fAverageLoGainAreas->SetOwner();
159
160 fAverageHiGainSectors = new TOrdCollection;
161 fAverageHiGainSectors->SetOwner();
162
163 fAverageLoGainSectors = new TOrdCollection;
164 fAverageLoGainSectors->SetOwner();
165
166 SetPulserFrequency();
167 SetProbLimit();
168 SetOverflowLimit();
169
170 SetAverageing (kTRUE);
171 SetDebug (kFALSE);
172 SetLoGain (kTRUE);
173 SetOscillations(kTRUE);
174 SetSizeCheck (kTRUE);
175
176 SetLowerFitLimitHiGain();
177 SetUpperFitLimitHiGain();
178 SetLowerFitLimitLoGain();
179 SetUpperFitLimitLoGain();
180}
181
182// --------------------------------------------------------------------------
183//
184// Deletes the TOrdCollection of:
185// - fHiGainArray, fLoGainArray
186// - fAverageHiGainAreas, fAverageLoGainAreas
187// - fAverageHiGainSectors, fAverageLoGainSectors
188//
189MHCalibrationCam::~MHCalibrationCam()
190{
191
192 delete fHiGainArray;
193 delete fLoGainArray;
194
195 delete fAverageHiGainAreas;
196 delete fAverageLoGainAreas;
197
198 delete fAverageHiGainSectors;
199 delete fAverageLoGainSectors;
200 /*
201
202 Remove ( fHiGainArray );
203 Remove ( fLoGainArray );
204
205 Remove ( fAverageHiGainAreas );
206 Remove ( fAverageLoGainAreas );
207
208 Remove ( fAverageHiGainSectors );
209 Remove ( fAverageLoGainSectors );
210 */
211
212}
213
214void MHCalibrationCam::Remove(TOrdCollection *col)
215{
216
217 if (!col)
218 return;
219
220 TOrdCollectionIter Next(col);
221
222 Int_t count = 0;
223
224 while (MHCalibrationPix *obj = (MHCalibrationPix*)Next())
225 {
226 *fLog << ++count << " " << obj << flush;
227 if (obj && obj->IsOnHeap())
228 {
229 obj->Draw();
230 delete obj;
231 }
232 }
233
234 delete col;
235}
236
237// --------------------------------------------------------------------------
238//
239// Returns size of fHiGainArray
240//
241const Int_t MHCalibrationCam::GetSize() const
242{
243 return fHiGainArray->GetSize();
244}
245
246// --------------------------------------------------------------------------
247//
248// Get i-th High Gain pixel (pixel number)
249//
250MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i)
251{
252 return *static_cast<MHCalibrationPix*>(fHiGainArray->At(i));
253}
254
255// --------------------------------------------------------------------------
256//
257// Get i-th High Gain pixel (pixel number)
258//
259const MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i) const
260{
261 return *static_cast<MHCalibrationPix*>(fHiGainArray->At(i));
262}
263
264// --------------------------------------------------------------------------
265//
266// Get i-th Low Gain pixel (pixel number)
267//
268MHCalibrationPix &MHCalibrationCam::operator()(UInt_t i)
269{
270 return *static_cast<MHCalibrationPix*>(fLoGainArray->At(i));
271}
272
273// --------------------------------------------------------------------------
274//
275// Get i-th Low Gain pixel (pixel number)
276//
277const MHCalibrationPix &MHCalibrationCam::operator()(UInt_t i) const
278{
279 return *static_cast<MHCalibrationPix*>(fLoGainArray->At(i));
280}
281
282// --------------------------------------------------------------------------
283//
284// Returns the current size of the TOrdCollection fAverageHiGainAreas
285// independently if the MHCalibrationPix is filled with values or not.
286//
287const Int_t MHCalibrationCam::GetAverageAreas() const
288{
289 return fAverageHiGainAreas->GetSize();
290}
291
292// --------------------------------------------------------------------------
293//
294// Get i-th High Gain pixel Area (area number)
295//
296MHCalibrationPix &MHCalibrationCam::GetAverageHiGainArea(UInt_t i)
297{
298 return *static_cast<MHCalibrationPix*>(fAverageHiGainAreas->At(i));
299}
300
301// --------------------------------------------------------------------------
302//
303// Get i-th High Gain pixel Area (area number)
304//
305const MHCalibrationPix &MHCalibrationCam::GetAverageHiGainArea(UInt_t i) const
306{
307 return *static_cast<MHCalibrationPix *>(fAverageHiGainAreas->At(i));
308}
309
310// --------------------------------------------------------------------------
311//
312// Get i-th Low Gain pixel Area (area number)
313//
314MHCalibrationPix &MHCalibrationCam::GetAverageLoGainArea(UInt_t i)
315{
316 return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->At(i));
317}
318
319// --------------------------------------------------------------------------
320//
321// Get i-th Low Gain pixel Area (area number)
322//
323const MHCalibrationPix &MHCalibrationCam::GetAverageLoGainArea(UInt_t i) const
324{
325 return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->At(i));
326}
327
328// --------------------------------------------------------------------------
329//
330// Returns the current size of the TOrdCollection fAverageHiGainSectors
331// independently if the MHCalibrationPix is filled with values or not.
332//
333const Int_t MHCalibrationCam::GetAverageSectors() const
334{
335 return fAverageHiGainSectors->GetSize();
336}
337
338// --------------------------------------------------------------------------
339//
340// Get i-th High Gain Sector (sector number)
341//
342MHCalibrationPix &MHCalibrationCam::GetAverageHiGainSector(UInt_t i)
343{
344 return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->At(i));
345}
346
347// --------------------------------------------------------------------------
348//
349// Get i-th High Gain Sector (sector number)
350//
351const MHCalibrationPix &MHCalibrationCam::GetAverageHiGainSector(UInt_t i) const
352{
353 return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->At(i));
354}
355
356// --------------------------------------------------------------------------
357//
358// Get i-th Low Gain Sector (sector number)
359//
360MHCalibrationPix &MHCalibrationCam::GetAverageLoGainSector(UInt_t i)
361{
362 return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->At(i));
363}
364
365// --------------------------------------------------------------------------
366//
367// Get i-th Low Gain Sector (sector number)
368//
369const MHCalibrationPix &MHCalibrationCam::GetAverageLoGainSector(UInt_t i) const
370{
371 return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->At(i));
372}
373
374// --------------------------------------------------------------------------
375//
376// Calls ResetHistTitles()
377//
378// Calls Reset() for each entry in:
379// - fHiGainArray, fLoGainArray
380// - fAverageHiGainAreas, fAverageLoGainAreas
381// - fAverageHiGainSectors, fAverageLoGainSectors
382//
383void MHCalibrationCam::ResetHists()
384{
385
386 ResetHistTitles();
387
388 if (fHiGainArray)
389 { fHiGainArray->ForEach(MHCalibrationPix,Reset)(); }
390
391 if (IsAverageing())
392 {
393 if (fAverageHiGainAreas)
394 { fAverageHiGainAreas->ForEach(MHCalibrationPix,Reset)(); }
395 if (fAverageHiGainSectors)
396 { fAverageHiGainSectors->ForEach(MHCalibrationPix,Reset)(); }
397 }
398
399 if (!IsLoGain())
400 return;
401
402 if (fLoGainArray)
403 { fLoGainArray->ForEach(MHCalibrationPix,Reset)(); }
404 if (IsAverageing())
405 {
406 if (fAverageLoGainAreas)
407 { fAverageLoGainAreas->ForEach(MHCalibrationPix,Reset)(); }
408 if (fAverageLoGainSectors)
409 { fAverageLoGainSectors->ForEach(MHCalibrationPix,Reset)(); }
410 }
411}
412
413// --------------------------------------------------------------------------
414//
415// Resets the histogram titles for each entry in:
416// - fHiGainArray, fLoGainArray
417// - fAverageHiGainAreas, fAverageLoGainAreas
418// - fAverageHiGainSectors, fAverageLoGainSectors
419//
420void MHCalibrationCam::ResetHistTitles()
421{
422
423 TH1F *h;
424
425 if (fHiGainArray)
426 for (Int_t i=0;i<fHiGainArray->GetSize(); i++)
427 {
428 MHCalibrationPix &pix = (*this)[i];
429 h = pix.GetHGausHist();
430 h->SetName (Form("%s%s%s%04d","H",fHistName.Data(),"HiGainPix",i));
431 h->SetTitle(Form("%s%s%04d%s",fHistTitle.Data()," High Gain Pixel ",i," Runs: "));
432 h->SetXTitle(fHistXTitle.Data());
433 h->SetYTitle(fHistYTitle.Data());
434 }
435
436 if (IsAverageing())
437 {
438 if (fAverageHiGainAreas)
439 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
440 {
441 MHCalibrationPix &pix = GetAverageHiGainArea(j);
442 h = pix.GetHGausHist();
443 h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"HiGainArea",j));
444 h->SetXTitle(fHistXTitle.Data());
445 h->SetYTitle(fHistYTitle.Data());
446 if (fGeom->InheritsFrom("MGeomCamMagic"))
447 h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
448 j==0 ? "Inner Pixels " : "Outer Pixels ","High Gain Runs: "));
449 else
450 h->SetTitle(Form("%s%s%d%s",fHistTitle.Data(),
451 " averaged on event-by-event basis High Gain Area Idx ",j," Runs: "));
452 }
453
454 if (fAverageHiGainSectors)
455 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
456 {
457 MHCalibrationPix &pix = GetAverageHiGainSector(j);
458 h = pix.GetHGausHist();
459 h->SetName (Form("%s%s%s%02d","H",fHistName.Data(),"HiGainSector",j));
460 h->SetTitle(Form("%s%s%02d%s",fHistTitle.Data(),
461 " averaged on event-by-event basis High Gain Sector ",j," Runs: "));
462 h->SetXTitle(fHistXTitle.Data());
463 h->SetYTitle(fHistYTitle.Data());
464 }
465 }
466
467 if (!IsLoGain())
468 return;
469
470 if (fLoGainArray)
471 for (Int_t i=0;i<fLoGainArray->GetSize(); i++)
472 {
473 MHCalibrationPix &pix = (*this)(i);
474 h = pix.GetHGausHist();
475 h->SetName (Form("%s%s%s%04d","H",fHistName.Data(),"LoGainPix",i));
476 h->SetTitle(Form("%s%s%04d%s",fHistTitle.Data()," Low Gain Pixel ",i," Runs: "));
477 h->SetXTitle(fHistXTitle.Data());
478 h->SetYTitle(fHistYTitle.Data());
479 }
480
481 if (IsAverageing())
482 {
483 if (fAverageLoGainAreas)
484 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
485 {
486 MHCalibrationPix &pix = GetAverageLoGainArea(j);
487 h = pix.GetHGausHist();
488 h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"LoGainArea",j));
489 h->SetXTitle(fHistXTitle.Data());
490 h->SetYTitle(fHistYTitle.Data());
491 if (fGeom->InheritsFrom("MGeomCamMagic"))
492 h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
493 j==0 ? "Inner Pixels " : "Outer Pixels ","Low Gain Runs: "));
494 else
495 h->SetTitle(Form("%s%s%d%s",fHistTitle.Data(),
496 " averaged on event-by-event basis Low Gain Area Idx ",j," Runs: "));
497 }
498
499 if (fAverageLoGainSectors)
500 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
501 {
502 MHCalibrationPix &pix = GetAverageLoGainSector(j);
503 h = pix.GetHGausHist();
504 h->SetName (Form("%s%s%s%02d","H",fHistName.Data(),"LoGainSector",j));
505 h->SetTitle(Form("%s%s%02d%s",fHistTitle.Data(),
506 " averaged on event-by-event basis Low Gain Sector ",j," Runs: "));
507 h->SetXTitle(fHistXTitle.Data());
508 h->SetYTitle(fHistYTitle.Data());
509 }
510 }
511}
512
513// --------------------------------------------------------------------------
514//
515// Gets the pointers to:
516// - MGeomCam
517//
518// Calls SetupHists(const MParList *pList)
519//
520// Calls Delete-Function of:
521// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
522// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
523// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
524//
525Bool_t MHCalibrationCam::SetupFill(const MParList *pList)
526{
527
528 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
529 if (!fGeom)
530 {
531 *fLog << err << GetDescriptor()
532 << ": MGeomCam not found... aborting." << endl;
533 return kFALSE;
534 }
535
536 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
537 if (!fRunHeader)
538 {
539 *fLog << warn << GetDescriptor()
540 << ": MRawRunHeader not found... will not store run numbers." << endl;
541 }
542
543 return SetupHists(pList);
544}
545
546
547// --------------------------------------------------------------------------
548//
549// Searches MRawEvtHeader to find the correct pulser colour
550//
551// Gets or creates the pointers to:
552// - MBadPixelsIntensityCam
553// - MBadPixelsCam
554//
555// Searches pointer to:
556// - MArrivalTimeCam
557//
558// Initializes, if empty to MArrivalTimeCam::GetSize() for:
559// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
560//
561// Initializes, if empty to MGeomCam::GetNumAreas() for:
562// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
563//
564// Initializes, if empty to MGeomCam::GetNumSectors() for:
565// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
566//
567// Initializes TArray's to MGeomCam::GetNumAreas and MGeomCam::GetNumSectors, respectively
568// Fills with number of valid pixels (if !MBadPixelsPix::IsBad()):
569// - MHCalibrationCam::fAverageAreaNum[area index]
570// - MHCalibrationCam::fAverageSectorNum[area index]
571//
572// Calls InitializeHists() for every entry in:
573// - MHCalibrationCam::fHiGainArray
574// - MHCalibrationCam::fAverageHiGainAreas
575// - MHCalibrationCam::fAverageHiGainSectors
576//
577// Sets Titles and Names for the Histograms
578// - MHCalibrationCam::fAverageHiGainAreas
579// - MHCalibrationCam::fAverageHiGainSectors
580//
581// Retrieves the run numbers from MRawRunHeader and stores them in fRunNumbers
582//
583Bool_t MHCalibrationCam::ReInit(MParList *pList)
584{
585
586 const Int_t npixels = fGeom->GetNumPixels();
587 const Int_t nsectors = fGeom->GetNumSectors();
588 const Int_t nareas = fGeom->GetNumAreas();
589
590 fIntensBad = (MBadPixelsIntensityCam*)pList->FindObject(AddSerialNumber("MBadPixelsIntensityCam"));
591 if (fIntensBad)
592 *fLog << inf << "Found MBadPixelsIntensityCam ... " << endl;
593 else
594 {
595 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
596 if (!fBadPixels)
597 {
598
599 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
600 if (!fBadPixels)
601 return kFALSE;
602
603 fBadPixels->InitSize(npixels);
604 }
605 }
606
607 if (IsAverageing())
608 {
609 //
610 // The function TArrayF::Set() already sets all entries to 0.
611 //
612 fAverageAreaNum. Set(nareas);
613 fAverageAreaSat. Set(nareas);
614 fAverageAreaSigma. Set(nareas);
615 fAverageAreaSigmaVar. Set(nareas);
616 fAverageAreaRelSigma. Set(nareas);
617 fAverageAreaRelSigmaVar.Set(nareas);
618 fAverageSectorNum. Set(nsectors);
619
620 for (Int_t aidx=0; aidx<nareas; aidx++)
621 fAverageAreaNum[aidx] = 0;
622
623 for (Int_t sector=0; sector<nsectors; sector++)
624 fAverageSectorNum[sector] = 0;
625
626 for (Int_t i=0; i<npixels; i++)
627 {
628
629 MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
630 if (bad.IsBad())
631 continue;
632
633 fAverageAreaNum [(*fGeom)[i].GetAidx() ]++;
634 fAverageSectorNum[(*fGeom)[i].GetSector()]++;
635 }
636 }
637
638 //
639 // Because ReInit has been called, a new run number is added
640 //
641 fRunNumbers.Set(fRunNumbers.GetSize()+1);
642
643 if (fRunHeader)
644 {
645 fRunNumbers[fRunNumbers.GetSize()-1] = fRunHeader->GetRunNumber();
646 if (IsLoGain())
647 SetLoGain(fRunHeader->GetNumSamplesLoGain());
648 }
649
650 if (!ReInitHists(pList))
651 return kFALSE;
652
653 ResetHistTitles();
654
655 if (!fRunHeader)
656 return kTRUE;
657
658 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
659 {
660 TH1F *h = (*this)[i].GetHGausHist();
661 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
662 }
663
664 if (IsLoGain())
665 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
666 {
667 TH1F *h = (*this)(i).GetHGausHist();
668 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
669 }
670
671 if (!IsAverageing())
672 return kTRUE;
673
674 for (Int_t j=0; j<nareas; j++)
675 {
676 TH1F *h = GetAverageHiGainArea(j).GetHGausHist();
677 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
678 }
679
680 if (IsLoGain())
681 for (Int_t j=0; j<nareas; j++)
682 {
683 TH1F *h = GetAverageLoGainArea(j).GetHGausHist();
684 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
685 }
686
687 for (Int_t j=0; j<nsectors; j++)
688 {
689 TH1F *h = GetAverageHiGainSector(j).GetHGausHist();
690 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
691 }
692
693 if (IsLoGain())
694 for (Int_t j=0; j<nsectors; j++)
695 {
696 TH1F *h = GetAverageLoGainSector(j).GetHGausHist();
697 h->SetTitle( Form("%s%08d ", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]));
698 }
699
700 return kTRUE;
701}
702
703//--------------------------------------------------------------------------------------
704//
705// Initializes the High Gain Arrays:
706//
707// - For every entry in the expanded arrays:
708// * Initialize an MHCalibrationPix
709// * Set Binning from fNbins, fFirst and fLast
710// * Set Histgram names and titles from fHistName and fHistTitle
711// * Set X-axis and Y-axis titles with fHistXTitle and fHistYTitle
712// * Call InitHists
713//
714void MHCalibrationCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
715{
716
717 if (fHiGainArray->GetSize()==0)
718 {
719 for (Int_t i=0; i<npixels; i++)
720 {
721 fHiGainArray->AddAt(new MHCalibrationPix(Form("%sHiGainPix%04d",fHistName.Data(),i),
722 Form("%s High Gain Pixel %4d",fHistTitle.Data(),i)),i);
723
724 MHCalibrationPix &pix = (*this)[i];
725 pix.SetNbins(fNbins);
726 pix.SetFirst(fFirst);
727 pix.SetLast (fLast);
728 pix.SetProbLimit(fProbLimit);
729
730 MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
731 InitHists(pix,bad,i);
732
733 if (fCam)
734 (*fCam)[i].SetPixId(i);
735 }
736 }
737
738 if (!IsAverageing())
739 return;
740
741 if (fAverageHiGainAreas->GetSize()==0)
742 {
743 for (Int_t j=0; j<nareas; j++)
744 {
745 fAverageHiGainAreas->AddAt(new MHCalibrationPix(Form("%sHiGainArea%d",fHistName.Data(),j),
746 Form("%s High Gain Area Idx %d",fHistTitle.Data(),j)),j);
747
748 MHCalibrationPix &pix = GetAverageHiGainArea(j);
749
750 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
751 pix.SetFirst(fFirst);
752 pix.SetLast (fLast);
753
754 if (fGeom && fGeom->InheritsFrom("MGeomCamMagic"))
755 {
756 pix.InitBins();
757 pix.SetEventFrequency(fPulserFrequency);
758 }
759 else
760 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
761 }
762 }
763
764 if (fAverageHiGainSectors->GetSize()==0)
765 {
766 for (Int_t j=0; j<nsectors; j++)
767 {
768 fAverageHiGainSectors->AddAt(new MHCalibrationPix(Form("%sHiGainSector%02d",fHistName.Data(),j),
769 Form("%s High Gain Sector %02d",fHistTitle.Data(),j)),j);
770 MHCalibrationPix &pix = GetAverageHiGainSector(j);
771
772 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nsectors));
773 pix.SetFirst(fFirst);
774 pix.SetLast (fLast);
775
776 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
777 }
778 }
779}
780
781//--------------------------------------------------------------------------------------
782//
783// Return, if IsLoGain() is kFALSE
784//
785// Initializes the Low Gain Arrays:
786//
787// - For every entry in the expanded arrays:
788// * Initialize an MHCalibrationPix
789// * Set Binning from fNbins, fFirst and fLast
790// * Set Histgram names and titles from fHistName and fHistTitle
791// * Set X-axis and Y-axis titles with fHistXTitle and fHistYTitle
792// * Call InitHists
793//
794void MHCalibrationCam::InitLoGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
795{
796
797 if (!IsLoGain())
798 return;
799
800 if (fLoGainArray->GetSize()==0)
801 {
802 for (Int_t i=0; i<npixels; i++)
803 {
804 fLoGainArray->AddAt(new MHCalibrationPix(Form("%sLoGainPix%04d",fHistName.Data(),i),
805 Form("%s Low Gain Pixel%04d",fHistTitle.Data(),i)),i);
806
807 MHCalibrationPix &pix = (*this)(i);
808 pix.SetNbins(fNbins);
809 pix.SetFirst(fFirst);
810 pix.SetLast (fLast);
811 pix.SetProbLimit(fProbLimit);
812
813 MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
814 InitHists(pix,bad,i);
815 }
816 }
817
818 if (!IsAverageing())
819 return;
820
821 if (fAverageLoGainAreas->GetSize()==0)
822 {
823 for (Int_t j=0; j<nareas; j++)
824 {
825 fAverageLoGainAreas->AddAt(new MHCalibrationPix(Form("%sLoGainArea%d",fHistName.Data(),j),
826 Form("%s Low Gain Area Idx %d",fHistTitle.Data(),j)),j);
827
828 MHCalibrationPix &pix = GetAverageLoGainArea(j);
829
830 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
831 pix.SetFirst(fFirst);
832 pix.SetLast (fLast);
833
834 if (fGeom && fGeom->InheritsFrom("MGeomCamMagic"))
835 {
836 pix.InitBins();
837 pix.SetEventFrequency(fPulserFrequency);
838 }
839 else
840 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
841 }
842 }
843
844 if (fAverageLoGainSectors->GetSize()==0)
845 {
846 for (Int_t j=0; j<nsectors; j++)
847 {
848 fAverageLoGainSectors->AddAt(new MHCalibrationPix(Form("%sLoGainSector%02d",fHistName.Data(),j),
849 Form("%s Low Gain Sector %02d",fHistTitle.Data(),j)),j);
850 MHCalibrationPix &pix = GetAverageLoGainSector(j);
851
852 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nsectors));
853 pix.SetFirst(fFirst);
854 pix.SetLast (fLast);
855
856 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
857 }
858 }
859}
860
861//--------------------------------------------------------------------------------
862//
863// Retrieves from MGeomCam:
864// - number of pixels
865// - number of pixel areas
866// - number of sectors
867//
868// Return kFALSE, if sizes of the TOrdCollections do not match npixels, nareas or nsectors
869//
870// Call FillHists()
871//
872Bool_t MHCalibrationCam::Fill(const MParContainer *par, const Stat_t w)
873{
874
875 if (!IsSizeCheck())
876 return FillHists(par,w);
877
878 const Int_t npixels = fGeom->GetNumPixels();
879 const Int_t nareas = fGeom->GetNumAreas();
880 const Int_t nsectors = fGeom->GetNumSectors();
881
882 //
883 // Hi-Gain OrdCollections
884 //
885 if (fHiGainArray->GetSize() != npixels)
886 {
887 *fLog << err << "ERROR - Size mismatch in number of pixels... abort." << endl;
888 return kFALSE;
889 }
890
891 if (IsLoGain())
892 {
893 if (fLoGainArray->GetSize() != npixels)
894 {
895 *fLog << err << "ERROR - Size mismatch in number of pixels... abort." << endl;
896 return kFALSE;
897 }
898 }
899
900 if (!IsAverageing())
901 return FillHists(par,w);
902
903 if (fAverageHiGainAreas->GetSize() != nareas)
904 {
905 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
906 return kFALSE;
907 }
908
909 if (fAverageHiGainSectors->GetSize() != nsectors)
910 {
911 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
912 return kFALSE;
913 }
914
915 if (IsLoGain())
916 {
917
918 if (fAverageLoGainAreas->GetSize() != nareas)
919 {
920 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
921 return kFALSE;
922 }
923
924 if (fAverageLoGainSectors->GetSize() != nsectors)
925 {
926 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
927 return kFALSE;
928 }
929 }
930
931 return FillHists(par, w);
932}
933
934// --------------------------------------------------------------------------
935//
936// 0) Ask if fHiGainArray and fLoGainArray have been initialized,
937// otherwise return kFALSE.
938// 1) FinalizeHists()
939// 2) FinalizeBadPixels()
940// 3) CalcAverageSigma()
941//
942Bool_t MHCalibrationCam::Finalize()
943{
944
945 if (GetNumExecutions() < 2)
946 return kTRUE;
947
948 if (fHiGainArray->GetSize() == 0 && fLoGainArray->GetSize() == 0)
949 {
950 *fLog << err << GetDescriptor()
951 << ": ERROR - Both (HiGain and LoGain) histogram arrays have not been initialized... abort." << endl;
952 return kFALSE;
953 }
954
955 for (Int_t i=0; i<fAverageHiGainAreas->GetSize(); i++)
956 {
957 TH1F *h = GetAverageHiGainArea(i).GetHGausHist();
958 switch (fColor)
959 {
960 case MCalibrationCam::kNONE:
961 break;
962 case MCalibrationCam::kBLUE:
963 h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
964 break;
965 case MCalibrationCam::kGREEN:
966 h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
967 break;
968 case MCalibrationCam::kUV:
969 h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
970 break;
971 case MCalibrationCam::kCT1:
972 h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
973 break;
974 }
975 }
976
977 for (Int_t i=0; i<fAverageLoGainAreas->GetSize(); i++)
978 {
979 TH1F *h = GetAverageLoGainArea(i).GetHGausHist();
980 switch (fColor)
981 {
982 case MCalibrationCam::kNONE:
983 break;
984 case MCalibrationCam::kBLUE:
985 h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
986 break;
987 case MCalibrationCam::kGREEN:
988 h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
989 break;
990 case MCalibrationCam::kUV:
991 h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
992 break;
993 case MCalibrationCam::kCT1:
994 h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
995 break;
996 }
997 }
998
999 if (!FinalizeHists())
1000 return kFALSE;
1001
1002
1003 FinalizeBadPixels();
1004 CalcAverageSigma();
1005
1006 return kTRUE;
1007}
1008
1009// -------------------------------------------------------------
1010//
1011// If MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun):
1012// - calls MHCalibrationPix::SetExcluded()
1013//
1014// Calls:
1015// - MHGausEvents::InitBins()
1016// - MHCalibrationPix::ChangeHistId(i)
1017// - MHCalibrationPix::SetEventFrequency(fPulserFrequency)
1018//
1019void MHCalibrationCam::InitHists(MHCalibrationPix &hist, MBadPixelsPix &bad, const Int_t i)
1020{
1021
1022 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1023 hist.SetExcluded();
1024
1025 hist.InitBins();
1026 hist.SetEventFrequency(fPulserFrequency);
1027}
1028
1029// -------------------------------------------------------------
1030//
1031// - Searches for the CalibrationIntensity*Cam corresponding to 'name'.
1032// - In case, it does not exist in the parameter list, it searches
1033// for the corresponding MCalibration*Cam.
1034// - Initializes the MCalibration*Cam, if not yet done.
1035//
1036Bool_t MHCalibrationCam::InitCams( MParList *plist, const TString name )
1037{
1038
1039 TString intensname = "MCalibrationIntensity";
1040 intensname += name;
1041 intensname += "Cam";
1042
1043 TString ordname = "MCalibration";
1044 ordname += name;
1045 ordname += "Cam";
1046
1047 fIntensCam = (MCalibrationIntensityCam*)plist->FindObject(AddSerialNumber(intensname));
1048 if (fIntensCam)
1049 *fLog << inf << "Found " << intensname << "... " << endl;
1050 else
1051 {
1052 fCam = (MCalibrationCam*)plist->FindObject(AddSerialNumber(ordname));
1053 if (!fCam)
1054 {
1055 fCam = (MCalibrationCam*)plist->FindCreateObj(AddSerialNumber(ordname));
1056 if (!fCam)
1057 return kFALSE;
1058
1059 fCam->Init(*fGeom);
1060 }
1061 }
1062 return kTRUE;
1063}
1064
1065// --------------------------------------------------------------------------
1066//
1067// Calls FitHiGainHists for every entry in:
1068// - fHiGainArray
1069// - fAverageHiGainAreas
1070// - fAverageHiGainSectors
1071//
1072void MHCalibrationCam::FitHiGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
1073 MBadPixelsPix::UncalibratedType_t fittyp,
1074 MBadPixelsPix::UncalibratedType_t osctyp)
1075{
1076 fIsHiGainFitRanges = TMath::Abs(fUpperFitLimitHiGain - fLowerFitLimitHiGain) > 1E-5;
1077
1078 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
1079 {
1080
1081 MHCalibrationPix &hist = (*this)[i];
1082
1083 if (hist.IsExcluded())
1084 continue;
1085
1086 MCalibrationPix &pix = calcam[i];
1087 MBadPixelsPix &bad = badcam[i];
1088
1089 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
1090 }
1091
1092 if (!IsAverageing())
1093 return;
1094
1095 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
1096 {
1097
1098 MHCalibrationPix &hist = GetAverageHiGainArea(j);
1099 MCalibrationPix &pix = calcam.GetAverageArea(j);
1100 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
1101
1102 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
1103 }
1104
1105 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
1106 {
1107 MHCalibrationPix &hist = GetAverageHiGainSector(j);
1108 MCalibrationPix &pix = calcam.GetAverageSector(j);
1109 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
1110
1111 FitHiGainHists(hist,pix,bad,fittyp,osctyp);
1112 }
1113}
1114
1115// --------------------------------------------------------------------------
1116//
1117// Calls FitLoGainHists for every entry in:
1118// - fLoGainArray
1119// - fAverageLoGainAreas
1120// - fAverageLoGainSectors
1121//
1122void MHCalibrationCam::FitLoGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam,
1123 MBadPixelsPix::UncalibratedType_t fittyp,
1124 MBadPixelsPix::UncalibratedType_t osctyp)
1125{
1126 fIsLoGainFitRanges = TMath::Abs(fUpperFitLimitLoGain - fLowerFitLimitLoGain) > 1E-5;
1127
1128 if (!IsLoGain())
1129 return;
1130
1131 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
1132 {
1133
1134 MHCalibrationPix &hist = (*this)(i);
1135
1136 if (hist.IsExcluded())
1137 continue;
1138
1139 MCalibrationPix &pix = calcam[i];
1140 MBadPixelsPix &bad = badcam[i];
1141
1142 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
1143
1144 }
1145
1146 if (!IsAverageing())
1147 return;
1148
1149 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
1150 {
1151
1152 MHCalibrationPix &hist = GetAverageLoGainArea(j);
1153 MCalibrationPix &pix = calcam.GetAverageArea(j);
1154 MBadPixelsPix &bad = calcam.GetAverageBadArea(j);
1155
1156 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
1157 }
1158
1159 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
1160 {
1161
1162 MHCalibrationPix &hist = GetAverageLoGainSector(j);
1163 MCalibrationPix &pix = calcam.GetAverageSector(j);
1164 MBadPixelsPix &bad = calcam.GetAverageBadSector(j);
1165
1166 FitLoGainHists(hist,pix,bad,fittyp,osctyp);
1167 }
1168}
1169
1170//------------------------------------------------------------
1171//
1172// For all averaged areas, the fitted sigma is multiplied with the square root of
1173// the number involved pixels
1174//
1175void MHCalibrationCam::CalcAverageSigma()
1176{
1177
1178 if (!fCam)
1179 return;
1180
1181 if (!IsAverageing())
1182 return;
1183
1184 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
1185 {
1186
1187 MCalibrationPix &pix = fCam->GetAverageArea(j);
1188
1189 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
1190 fAverageAreaSigma[j] = pix.GetSigma () * numsqr;
1191 fAverageAreaSigmaVar[j] = pix.GetSigmaErr () * pix.GetSigmaErr() * numsqr;
1192
1193 pix.SetSigma (fAverageAreaSigma[j]);
1194 pix.SetSigmaVar(fAverageAreaSigmaVar[j]);
1195
1196 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / pix.GetMean();
1197 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
1198 fAverageAreaRelSigmaVar[j] += pix.GetMeanRelVar();
1199 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
1200 }
1201}
1202
1203// ---------------------------------------------------------------------------
1204//
1205// Returns if the histogram is empty and sets the following flag:
1206// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
1207//
1208// Fits the histograms with a Gaussian, in case of failure
1209// calls MHCalibrationPix::RepeatFit(), in case of repeated failure
1210// calls MHCalibrationPix::BypassFit() and sets the following flags:
1211// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
1212// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
1213//
1214// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
1215// In case no, sets the following flags:
1216// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
1217// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
1218//
1219// Retrieves the results and store them in MCalibrationPix
1220//
1221void MHCalibrationCam::FitHiGainHists(MHCalibrationPix &hist,
1222 MCalibrationPix &pix,
1223 MBadPixelsPix &bad,
1224 MBadPixelsPix::UncalibratedType_t fittyp,
1225 MBadPixelsPix::UncalibratedType_t osctyp)
1226{
1227
1228 if (hist.IsEmpty() || hist.IsOnlyOverflow() || hist.IsOnlyUnderflow())
1229 {
1230 *fLog << warn << GetDescriptor()
1231 << ": Only overflow or underflow in hi-gain pixel: " << pix.GetPixId() << endl;
1232 return;
1233 }
1234 //
1235 // 2) Fit the Hi Gain histograms with a Gaussian
1236 //
1237 if (fIsHiGainFitRanges)
1238 {
1239 if (!hist.FitGaus("R",fLowerFitLimitHiGain,fUpperFitLimitHiGain))
1240 bad.SetUncalibrated( fittyp );
1241 }
1242 else
1243 if (!hist.FitGaus())
1244 //
1245 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
1246 //
1247 if (!hist.RepeatFit())
1248 {
1249 hist.BypassFit();
1250 bad.SetUncalibrated( fittyp );
1251 }
1252
1253
1254 //
1255 // 4) Check for oscillations
1256 //
1257 if (IsOscillations())
1258 {
1259 hist.CreateFourierSpectrum();
1260
1261 if (!hist.IsFourierSpectrumOK())
1262 bad.SetUncalibrated( osctyp );
1263 }
1264
1265 //
1266 // 5) Retrieve the results and store them in this class
1267 //
1268 pix.SetHiGainMean ( hist.GetMean() );
1269 pix.SetHiGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
1270 pix.SetHiGainRms ( hist.GetHistRms() );
1271 pix.SetHiGainSigma ( hist.GetSigma() );
1272 pix.SetHiGainSigmaVar ( hist.GetSigmaErr()* hist.GetSigmaErr() );
1273 pix.SetHiGainProb ( hist.GetProb() );
1274 pix.SetHiGainNumBlackout( hist.GetBlackout() );
1275 pix.SetHiGainNumPickup ( hist.GetPickup() );
1276
1277 if (IsDebug())
1278 {
1279 *fLog << dbginf << GetDescriptor() << ": ID " << GetName()
1280 << " HiGainSaturation: " << pix.IsHiGainSaturation()
1281 << " HiGainMean: " << hist.GetMean ()
1282 << " HiGainMeanErr: " << hist.GetMeanErr ()
1283 << " HiGainMeanSigma: " << hist.GetSigma ()
1284 << " HiGainMeanSigmaErr: " << hist.GetSigmaErr()
1285 << " HiGainMeanProb: " << hist.GetProb ()
1286 << " HiGainNumBlackout: " << hist.GetBlackout()
1287 << " HiGainNumPickup : " << hist.GetPickup ()
1288 << endl;
1289 }
1290
1291}
1292
1293
1294// ---------------------------------------------------------------------------
1295//
1296// Returns if the histogram is empty and sets the following flag:
1297// - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
1298//
1299// Fits the histograms with a Gaussian, in case of failure
1300// calls MHCalibrationPix::RepeatFit(), in case of repeated failure
1301// calls MHCalibrationPix::BypassFit() and sets the following flags:
1302// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp )
1303// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
1304//
1305// Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
1306// In case no, sets the following flags:
1307// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp )
1308// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
1309//
1310// Retrieves the results and store them in MCalibrationPix
1311//
1312void MHCalibrationCam::FitLoGainHists(MHCalibrationPix &hist,
1313 MCalibrationPix &pix,
1314 MBadPixelsPix &bad,
1315 MBadPixelsPix::UncalibratedType_t fittyp,
1316 MBadPixelsPix::UncalibratedType_t osctyp)
1317{
1318
1319 if (hist.IsEmpty() || hist.IsOnlyOverflow() || hist.IsOnlyUnderflow())
1320 {
1321 *fLog << warn << GetDescriptor()
1322 << ": Only overflow or underflow in lo-gain pixel: " << pix.GetPixId() << endl;
1323 return;
1324 }
1325 //
1326 // 2) Fit the Hi Gain histograms with a Gaussian
1327 //
1328 if (fIsLoGainFitRanges)
1329 {
1330 if (!hist.FitGaus("R",fLowerFitLimitLoGain,fUpperFitLimitLoGain))
1331 bad.SetUncalibrated( fittyp );
1332 }
1333 else
1334 if (!hist.FitGaus())
1335 //
1336 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
1337 //
1338 if (!hist.RepeatFit())
1339 {
1340 hist.BypassFit();
1341 if (pix.IsHiGainSaturation())
1342 bad.SetUncalibrated( fittyp );
1343 }
1344
1345 //
1346 // 4) Check for oscillations
1347 //
1348 if (IsOscillations())
1349 {
1350 hist.CreateFourierSpectrum();
1351
1352 if (!hist.IsFourierSpectrumOK())
1353 bad.SetUncalibrated( osctyp );
1354 }
1355
1356 //
1357 // 5) Retrieve the results and store them in this class
1358 //
1359 pix.SetLoGainMean ( hist.GetMean() );
1360 pix.SetLoGainMeanVar ( hist.GetMeanErr() * hist.GetMeanErr() );
1361 pix.SetLoGainRms ( hist.GetHistRms() );
1362 pix.SetLoGainSigma ( hist.GetSigma() );
1363 pix.SetLoGainSigmaVar ( hist.GetSigmaErr() * hist.GetSigmaErr() );
1364 pix.SetLoGainProb ( hist.GetProb() );
1365 pix.SetLoGainNumBlackout( hist.GetBlackout() );
1366 pix.SetLoGainNumPickup ( hist.GetPickup() );
1367
1368 if (IsDebug())
1369 {
1370 *fLog << dbginf << GetDescriptor() << "ID: " << hist.GetName()
1371 << " HiGainSaturation: " << pix.IsHiGainSaturation()
1372 << " LoGainMean: " << hist.GetMean ()
1373 << " LoGainMeanErr: " << hist.GetMeanErr ()
1374 << " LoGainMeanSigma: " << hist.GetSigma ()
1375 << " LoGainMeanSigmaErr: " << hist.GetSigmaErr()
1376 << " LoGainMeanProb: " << hist.GetProb ()
1377 << " LoGainNumBlackout: " << hist.GetBlackout()
1378 << " LoGainNumPickup : " << hist.GetPickup ()
1379 << endl;
1380 }
1381
1382}
1383
1384
1385
1386// -----------------------------------------------------------------------------
1387//
1388// Default draw:
1389//
1390// Displays the averaged areas, both High Gain and Low Gain
1391//
1392// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
1393//
1394void MHCalibrationCam::Draw(const Option_t *opt)
1395{
1396
1397 if (!IsAverageing())
1398 return;
1399
1400 const Int_t nareas = fAverageHiGainAreas->GetSize();
1401 if (nareas == 0)
1402 return;
1403
1404 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
1405 pad->SetBorderMode(0);
1406
1407 pad->Divide(IsLoGain() ? 2 : 1,nareas);
1408
1409 for (Int_t i=0; i<nareas;i++)
1410 {
1411
1412 pad->cd(IsLoGain() ? 2*(i+1)-1 : i+1);
1413 GetAverageHiGainArea(i).Draw(opt);
1414
1415 if (!fAverageAreaSat[i])
1416 DrawAverageSigma(fAverageAreaSat[i], i,
1417 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
1418 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
1419
1420 if (IsLoGain())
1421 {
1422 pad->cd(2*(i+1));
1423 GetAverageLoGainArea(i).Draw(opt);
1424 }
1425
1426 if (fAverageAreaSat[i])
1427 DrawAverageSigma(fAverageAreaSat[i], i,
1428 fAverageAreaSigma[i], fAverageAreaSigmaVar[i],
1429 fAverageAreaRelSigma[i], fAverageAreaRelSigmaVar[i]);
1430 }
1431
1432}
1433
1434// -----------------------------------------------------------------------------
1435//
1436// Default draw:
1437//
1438// Displays a TPaveText with the re-normalized sigmas of the average area
1439//
1440void MHCalibrationCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
1441 Float_t sigma, Float_t sigmavar,
1442 Float_t relsigma, Float_t relsigmavar) const
1443{
1444
1445 if (sigma != 0 && sigmavar >= 0 && relsigmavar >= 0.)
1446 {
1447
1448 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
1449 newpad->SetFillStyle(4000);
1450 newpad->Draw();
1451 newpad->cd();
1452
1453 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
1454 text->SetTextSize(0.05);
1455 const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
1456 " Pixels ", sat ? "Low Gain" : "High Gain");
1457 TText *txt1 = text->AddText(line1.Data());
1458 const TString line2 = Form("#sigma per pix: %2.2f #pm %2.2f",sigma,TMath::Sqrt(sigmavar));
1459 TText *txt2 = text->AddText(line2.Data());
1460 const TString line3 = Form("Rel. #sigma per pix: %2.2f #pm %2.2f",relsigma,TMath::Sqrt(relsigmavar));
1461 TText *txt3 = text->AddText(line3.Data());
1462 text->Draw("");
1463
1464 text->SetBit(kCanDelete);
1465 txt1->SetBit(kCanDelete);
1466 txt2->SetBit(kCanDelete);
1467 txt3->SetBit(kCanDelete);
1468 newpad->SetBit(kCanDelete);
1469 }
1470}
1471
1472// -----------------------------------------------------------------------------
1473//
1474// Available options
1475// Debug
1476// LoGain
1477// Oscillations
1478// SizeCheck
1479// Averageing
1480// Nbins
1481// First
1482// Last
1483// ProbLimit
1484// OverflowLimit
1485// PulserFrequency
1486// LowerFitLimitHiGain
1487// UpperFitLimitHiGain
1488// LowerFitLimitLoGain
1489// UpperFitLimitLoGain
1490//
1491Int_t MHCalibrationCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
1492{
1493
1494 Bool_t rc = kFALSE;
1495 if (IsEnvDefined(env, prefix, "Debug", print))
1496 {
1497 SetDebug(GetEnvValue(env, prefix, "Debug", IsDebug()));
1498 rc = kTRUE;
1499 }
1500 if (IsEnvDefined(env, prefix, "LoGain", print))
1501 {
1502 SetDebug(GetEnvValue(env, prefix, "LoGain", IsLoGain()));
1503 rc = kTRUE;
1504 }
1505 if (IsEnvDefined(env, prefix, "Oscillations", print))
1506 {
1507 SetOscillations(GetEnvValue(env, prefix, "Oscillations", IsOscillations()));
1508 rc = kTRUE;
1509 }
1510 if (IsEnvDefined(env, prefix, "SizeCheck", print))
1511 {
1512 SetSizeCheck(GetEnvValue(env, prefix, "SizeCheck", IsSizeCheck()));
1513 rc = kTRUE;
1514 }
1515 if (IsEnvDefined(env, prefix, "Averageing", print))
1516 {
1517 SetAverageing(GetEnvValue(env, prefix, "Averageing", IsAverageing()));
1518 rc = kTRUE;
1519 }
1520
1521 if (IsEnvDefined(env, prefix, "Nbins", print))
1522 {
1523 SetNbins(GetEnvValue(env, prefix, "Nbins", fNbins));
1524 rc = kTRUE;
1525 }
1526 if (IsEnvDefined(env, prefix, "First", print))
1527 {
1528 SetFirst(GetEnvValue(env, prefix, "First", fFirst));
1529 rc = kTRUE;
1530 }
1531
1532 if (IsEnvDefined(env, prefix, "Last", print))
1533 {
1534 SetLast(GetEnvValue(env, prefix, "Last", fLast));
1535 rc = kTRUE;
1536 }
1537
1538 if (IsEnvDefined(env, prefix, "ProbLimit", print))
1539 {
1540 SetProbLimit(GetEnvValue(env, prefix, "ProbLimit", fProbLimit));
1541 rc = kTRUE;
1542 }
1543
1544 if (IsEnvDefined(env, prefix, "OverflowLimit", print))
1545 {
1546 SetOverflowLimit(GetEnvValue(env, prefix, "OverflowLimit", fOverflowLimit));
1547 rc = kTRUE;
1548 }
1549
1550 if (IsEnvDefined(env, prefix, "PulserFrequency", print))
1551 {
1552 SetPulserFrequency(GetEnvValue(env, prefix, "PulserFrequency", fPulserFrequency));
1553 rc = kTRUE;
1554 }
1555
1556 if (IsEnvDefined(env, prefix, "LowerFitLimitHiGain", print))
1557 {
1558 SetLowerFitLimitHiGain(GetEnvValue(env, prefix, "LowerFitLimitHiGain", fLowerFitLimitHiGain));
1559 rc = kTRUE;
1560 }
1561
1562 if (IsEnvDefined(env, prefix, "UpperFitLimitHiGain", print))
1563 {
1564 SetUpperFitLimitHiGain(GetEnvValue(env, prefix, "UpperFitLimitHiGain", fUpperFitLimitHiGain));
1565 rc = kTRUE;
1566 }
1567
1568 if (IsEnvDefined(env, prefix, "LowerFitLimitLoGain", print))
1569 {
1570 SetLowerFitLimitLoGain(GetEnvValue(env, prefix, "LowerFitLimitLoGain", fLowerFitLimitLoGain));
1571 rc = kTRUE;
1572 }
1573
1574 if (IsEnvDefined(env, prefix, "UpperFitLimitLoGain", print))
1575 {
1576 SetUpperFitLimitLoGain(GetEnvValue(env, prefix, "UpperFitLimitLoGain", fUpperFitLimitLoGain));
1577 rc = kTRUE;
1578 }
1579
1580
1581 return rc;
1582}
1583
Note: See TracBrowser for help on using the repository browser.