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

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