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

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