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

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