source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc@ 3601

Last change on this file since 3601 was 3601, checked in by gaug, 21 years ago
*** empty log message ***
File size: 25.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15
16! *
17!
18!
19! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHCalibrationChargeCam
29//
30// Fills the extracted signals of MExtractedSignalCam into the MH-classes:
31//
32// MHCalibrationChargeHiGainPix, MHCalibrationChargeLoGainPix for each pixel
33// and additionally for an average of the inner and the outer pixels, respectively.
34//
35// By default, subsequently the hi-gain classes are treated unless
36// more than fNumHiGainSaturationLimit (default: 1%) of the overall FADC
37// slices show saturation. In that case, the low-gain classes are treated.
38// If more than fNumLoGainSaturationLimit (default: 1%) of the overall
39// low-gain FADC slices saturate, the pixel is declared not valid and no further
40// treatment is pursued.
41//
42// The filled histograms are fitted to a Gaussian and the mean and sigma with
43// its errors and the fit probability are extracted. If none of these values are
44// NaN's and if the probability is bigger than fProbLimit (default: 0.5%), the fit
45// is declared valid. Otherwise, the fit is repeated within ranges of the previous mean
46// +- 5 sigma. In case that this does not help, the histogram means and RMS's are taken directly,
47// but the flag kFitValid is set to FALSE. Outliers of more than fPickUpLimit (default: 5) sigmas
48// from the mean are counted as PickUp events.
49//
50// Additionally, the slice number with the highest value is stored and a corresponding
51// histogram is filled. This histogram serves only for a rough cross-check if the
52// signal does not lie at the edges of chose extraction window.
53//
54// The class also fills arrays with the signal vs. event number, creates a fourier
55// spectrum out of it and investigates if the projected frequencies follow an exponential
56// distribution. In case that the probability of the exponential fit is less than
57// fProbLimit, the pixel is declared HiGainOscillating or LoGainOscillating, respectively.
58//
59// The results are written into MCalibrationChargeCam.
60//
61/////////////////////////////////////////////////////////////////////////////
62#include "MHCalibrationChargeCam.h"
63
64#include <TVirtualPad.h>
65#include <TCanvas.h>
66#include <TPad.h>
67#include <TText.h>
68#include <TPaveText.h>
69
70#include "MLog.h"
71#include "MLogManip.h"
72
73#include "MParList.h"
74
75#include "MHCalibrationChargeHiGainPix.h"
76#include "MHCalibrationChargeLoGainPix.h"
77#include "MHCalibrationChargePix.h"
78
79#include "MCalibrationChargeCam.h"
80#include "MCalibrationChargePix.h"
81
82#include "MGeomCam.h"
83#include "MGeomPix.h"
84
85#include "MBadPixelsCam.h"
86#include "MBadPixelsPix.h"
87
88#include "MRawEvtData.h"
89#include "MRawEvtPixelIter.h"
90
91#include "MExtractedSignalCam.h"
92#include "MExtractedSignalPix.h"
93
94ClassImp(MHCalibrationChargeCam);
95
96using namespace std;
97
98const Float_t MHCalibrationChargeCam::fgNumHiGainSaturationLimit = 0.005;
99const Float_t MHCalibrationChargeCam::fgNumLoGainSaturationLimit = 0.005;
100//
101//
102//
103MHCalibrationChargeCam::MHCalibrationChargeCam(const char *name, const char *title)
104 : fRawEvt(NULL), fGeom(NULL), fBadPixels(NULL)
105{
106 fName = name ? name : "MHCalibrationChargeCam";
107 fTitle = title ? title : "Class to fill the calibration histograms ";
108
109 fHiGainArray = new TObjArray;
110 fHiGainArray->SetOwner();
111
112 fLoGainArray = new TObjArray;
113 fLoGainArray->SetOwner();
114
115 fAverageHiGainInnerPix = new MHCalibrationChargeHiGainPix("AverageHiGainInnerPix",
116 "Average HiGain FADC sums of inner pixels");
117 fAverageLoGainInnerPix = new MHCalibrationChargeLoGainPix("AverageLoGainInnerPix",
118 "Average LoGain FADC sums of inner pixels");
119 fAverageHiGainOuterPix = new MHCalibrationChargeHiGainPix("AverageHiGainOuterPix",
120 "Average HiGain FADC sums of outer pixels");
121 fAverageLoGainOuterPix = new MHCalibrationChargeLoGainPix("AverageLoGainOuterPix",
122 "Average LoGain FADC sums of outer pixels");
123
124 fAverageHiGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels HiGain");
125 fAverageLoGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels LoGain");
126 fAverageHiGainOuterPix->GetHGausHist()->SetTitle("Summed FADC slices average Outer pixels HiGain");
127 fAverageLoGainOuterPix->GetHGausHist()->SetTitle("Summed FADC slices average Outer pixels LoGain");
128
129 fAverageHiGainInnerPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Inner pixels HiGain");
130 fAverageLoGainInnerPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Inner pixels LoGain");
131 fAverageHiGainOuterPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Outer pixels HiGain");
132 fAverageLoGainOuterPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Outer pixels LoGain");
133
134 fAverageHiGainInnerPix->SetChargeFirst(-1000.);
135 fAverageHiGainOuterPix->SetChargeFirst(-1000.);
136
137 fAverageHiGainInnerPix->SetChargeLast(4000.);
138 fAverageLoGainInnerPix->SetChargeLast(4000.);
139 fAverageHiGainOuterPix->SetChargeLast(4000.);
140 fAverageLoGainOuterPix->SetChargeLast(4000.);
141
142 fAverageHiGainInnerPix->SetChargeNbins(4000);
143 fAverageLoGainInnerPix->SetChargeNbins(4000);
144 fAverageHiGainOuterPix->SetChargeNbins(4000);
145 fAverageLoGainOuterPix->SetChargeNbins(4000);
146
147 SetNumHiGainSaturationLimit();
148 SetNumLoGainSaturationLimit();
149
150 fNumInnerPixels = 0;
151 fNumOuterPixels = 0;
152 fNumExcluded = 0;
153
154 fAverageInnerSat = 0;
155 fAverageOuterSat = 0;
156 fAverageInnerPixSigma = 0.;
157 fAverageOuterPixSigma = 0.;
158 fAverageInnerPixSigmaErr = 0.;
159 fAverageOuterPixSigmaErr = 0.;
160 fAverageInnerPixRelSigma = 0.;
161 fAverageOuterPixRelSigma = 0.;
162 fAverageInnerPixRelSigmaErr = 0.;
163 fAverageOuterPixRelSigmaErr = 0.;
164
165}
166
167// --------------------------------------------------------------------------
168//
169// Delete the TClonesArray of MHCalibrationChargePix containers
170// Delete the MHCalibrationPINDiode and the MHCalibrationBlindPix
171//
172// Delete the histograms if they exist
173//
174MHCalibrationChargeCam::~MHCalibrationChargeCam()
175{
176 delete fHiGainArray;
177 delete fLoGainArray;
178
179 delete fAverageHiGainInnerPix;
180 delete fAverageLoGainInnerPix;
181 delete fAverageHiGainOuterPix;
182 delete fAverageLoGainOuterPix;
183
184}
185
186// --------------------------------------------------------------------------
187//
188// Get i-th pixel (pixel number)
189//
190MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::operator[](UInt_t i)
191{
192 return *static_cast<MHCalibrationChargeHiGainPix*>(fHiGainArray->UncheckedAt(i));
193}
194
195// --------------------------------------------------------------------------
196//
197// Get i-th pixel (pixel number)
198//
199const MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::operator[](UInt_t i) const
200{
201 return *static_cast<MHCalibrationChargeHiGainPix*>(fHiGainArray->UncheckedAt(i));
202}
203
204// --------------------------------------------------------------------------
205//
206// Get i-th pixel (pixel number)
207//
208MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::operator()(UInt_t i)
209{
210 return *static_cast<MHCalibrationChargeLoGainPix*>(fLoGainArray->UncheckedAt(i));
211}
212
213// --------------------------------------------------------------------------
214//
215// Get i-th pixel (pixel number)
216//
217const MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::operator()(UInt_t i) const
218{
219 return *static_cast<MHCalibrationChargeLoGainPix*>(fLoGainArray->UncheckedAt(i));
220}
221
222
223#if 0
224// --------------------------------------------------------------------------
225//
226// Our own clone function is necessary since root 3.01/06 or Mars 0.4
227// I don't know the reason
228//
229TObject *MHCalibrationChargeCam::Clone(const char *) const
230{
231
232 const Int_t nhi = fHiGainArray->GetSize();
233 const Int_t nlo = fLoGainArray->GetSize();
234 //
235 // FIXME, this might be done faster and more elegant, by direct copy.
236 //
237 MHCalibrationChargeCam *cam = (MHCalibrationChargeCam*)(this)->Clone("");
238// MHCalibrationChargeCam cam;
239// Copy(*cam);
240
241/*
242 cam->fHiGainArray->Delete();
243 cam->fLoGainArray->Delete();
244
245 cam->fHiGainArray->Expand(nhi);
246 cam->fLoGainArray->Expand(nlo);
247
248 for (int i=0; i<nhi; i++)
249 {
250 delete (*cam->fHiGainArray)[i];
251 (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
252 }
253 for (int i=0; i<nlo; i++)
254 {
255 delete (*cam->fLoGainArray)[i];
256 (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
257 }
258*/
259
260/*
261 delete cam->fAverageHiGainInnerPix;
262 delete cam->fAverageLoGainInnerPix;
263 delete cam->fAverageHiGainOuterPix;
264 delete cam->fAverageLoGainOuterPix;
265
266 cam->GetAverageHiGainInnerPix() = *(MHCalibrationChargeHiGainPix*)fAverageHiGainInnerPix->Clone();
267 cam->GetAverageLoGainInnerPix() = *(MHCalibrationChargeLoGainPix*)fAverageLoGainInnerPix->Clone();
268
269 cam->GetAverageHiGainOuterPix() = *(MHCalibrationChargeHiGainPix*)fAverageHiGainOuterPix->Clone();
270 cam->GetAverageLoGainOuterPix() = *(MHCalibrationChargeLoGainPix*)fAverageLoGainOuterPix->Clone();
271
272 fAverageHiGainInnerPix->Copy(cam->GetAverageHiGainInnerPix());
273 fAverageLoGainInnerPix->Copy(cam->GetAverageLoGainInnerPix());
274 fAverageHiGainOuterPix->Copy(cam->GetAverageHiGainOuterPix());
275 fAverageLoGainOuterPix->Copy(cam->GetAverageLoGainOuterPix());
276*/
277
278 return cam;
279}
280#endif
281// --------------------------------------------------------------------------
282//
283// To setup the object we get the number of pixels from a MGeomCam object
284// in the Parameter list.
285//
286Bool_t MHCalibrationChargeCam::SetupFill(const MParList *pList)
287{
288
289 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
290 if (!fRawEvt)
291 {
292 *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
293 return kFALSE;
294 }
295
296 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
297 if (!fGeom)
298 {
299 *fLog << err << "MGeomCam not found... aborting." << endl;
300 return kFALSE;
301 }
302
303 fHiGainArray->Delete();
304 fLoGainArray->Delete();
305
306 fAverageHiGainInnerPix->Init();
307 fAverageLoGainInnerPix->Init();
308 fAverageHiGainOuterPix->Init();
309 fAverageLoGainOuterPix->Init();
310
311 return kTRUE;
312}
313
314Bool_t MHCalibrationChargeCam::ReInit(MParList *pList)
315{
316
317 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
318 if (!fBadPixels)
319 return kFALSE;
320
321
322 fCam = (MCalibrationChargeCam*)pList->FindCreateObj("MCalibrationChargeCam");
323 if (!fCam)
324 return kFALSE;
325
326 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
327 if (!signal)
328 {
329 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
330 return kFALSE;
331 }
332
333 const Int_t n = signal->GetSize();
334
335 if (fHiGainArray->GetEntries()==0)
336 {
337 fHiGainArray->Expand(n);
338
339 for (Int_t i=0; i<n; i++)
340 {
341 //
342 // Oscillating pixels
343 //
344 (*fHiGainArray)[i] = new MHCalibrationChargeHiGainPix;
345
346 if ((*fBadPixels)[i].IsBad())
347 {
348 *fLog << warn << "Excluded pixel: " << i << " from calibration " << endl;
349 fNumExcluded++;
350 (*this)[i].SetExcluded();
351 }
352 (*this)[i].Init();
353 (*this)[i].ChangeHistId(i);
354 }
355 }
356
357
358 if (fLoGainArray->GetEntries()==0)
359 {
360 fLoGainArray->Expand(n);
361
362 for (Int_t i=0; i<n; i++)
363 {
364 (*fLoGainArray)[i] = new MHCalibrationChargeLoGainPix;
365 //
366 // Pixels with non-valid behavior
367 //
368 if ((*fBadPixels)[i].IsBad())
369 (*this)(i).SetExcluded();
370
371 (*this)(i).Init();
372 (*this)(i).ChangeHistId(i);
373 }
374 }
375
376
377 *fLog << inf << GetDescriptor() << ": " << fNumExcluded << " excluded Pixels " << endl;
378
379 return kTRUE;
380}
381
382
383// --------------------------------------------------------------------------
384Bool_t MHCalibrationChargeCam::Fill(const MParContainer *par, const Stat_t w)
385{
386
387 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
388 if (!signal)
389 {
390 *fLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
391 return kFALSE;
392 }
393
394 Int_t n = signal->GetSize();
395 Int_t lofirst = signal->GetFirstUsedSliceLoGain();
396
397 if (fHiGainArray->GetEntries() != n)
398 {
399 *fLog << err << "ERROR - Size mismatch... abort." << endl;
400 return kFALSE;
401 }
402
403 if (fLoGainArray->GetEntries() != n)
404 {
405 *fLog << err << "ERROR - Size mismatch... abort." << endl;
406 return kFALSE;
407 }
408
409 //
410 // First the extracted signal
411 //
412 Float_t sumhiinnertot = 0.;
413 Float_t sumloinnertot = 0.;
414 Float_t sumhioutertot = 0.;
415 Float_t sumlooutertot = 0.;
416 Int_t sumhiinnersat = 0;
417 Int_t sumloinnersat = 0;
418 Int_t sumhioutersat = 0;
419 Int_t sumlooutersat = 0;
420
421 fNumInnerPixels = fNumOuterPixels = 0;
422
423 for (int i=0; i<n; i++)
424 {
425
426 if ((*this)[i].IsExcluded())
427 continue;
428
429 const MExtractedSignalPix &pix = (*signal)[i];
430
431 const Float_t sumhi = pix.GetExtractedSignalHiGain();
432 const Float_t sumlo = pix.GetExtractedSignalLoGain();
433
434 (*this)[i].FillHistAndArray(sumhi);
435 (*this)(i).FillHistAndArray(sumlo);
436
437 const Int_t sathi = (Int_t)pix.GetNumHiGainSaturated();
438 const Int_t satlo = (Int_t)pix.GetNumLoGainSaturated();
439
440 (*this)[i].SetSaturated(sathi);
441 (*this)(i).SetSaturated(satlo);
442
443 if (fGeom->GetPixRatio(i) == 1.)
444 {
445 sumhiinnertot += sumhi;
446 sumloinnertot += sumlo;
447 sumhiinnersat += sathi;
448 sumloinnersat += satlo;
449 fNumInnerPixels++;
450 }
451 else
452 {
453 sumhioutertot += sumhi;
454 sumlooutertot += sumlo;
455 sumhioutersat += sathi;
456 sumlooutersat += satlo;
457 fNumOuterPixels++;
458 }
459
460 }
461
462 fAverageHiGainInnerPix->FillHistAndArray(sumhiinnertot/fNumInnerPixels);
463 fAverageLoGainInnerPix->FillHistAndArray(sumloinnertot/fNumInnerPixels);
464 fAverageHiGainOuterPix->FillHistAndArray(sumhioutertot/fNumOuterPixels);
465 fAverageLoGainOuterPix->FillHistAndArray(sumlooutertot/fNumOuterPixels);
466
467 fAverageHiGainInnerPix->SetSaturated((Float_t)sumhiinnersat/fNumInnerPixels);
468 fAverageLoGainInnerPix->SetSaturated((Float_t)sumloinnersat/fNumInnerPixels);
469 fAverageHiGainOuterPix->SetSaturated((Float_t)sumhioutersat/fNumOuterPixels);
470 fAverageLoGainOuterPix->SetSaturated((Float_t)sumlooutersat/fNumOuterPixels);
471
472 //
473 // Now the times
474 //
475 sumhiinnertot = sumloinnertot = sumhioutertot = sumlooutertot = 0.;
476 fNumInnerPixels = fNumOuterPixels = 0;
477
478 MRawEvtPixelIter pixel(fRawEvt);
479 while (pixel.Next())
480 {
481
482 const UInt_t pixid = pixel.GetPixelId();
483
484 if ((*this)[pixid].IsExcluded())
485 continue;
486
487 const Float_t timehi = (Float_t)pixel.GetIdxMaxHiGainSample();
488 const Float_t timelo = (Float_t)pixel.GetIdxMaxLoGainSample(lofirst);
489
490 (*this)[pixid].FillAbsTime(timehi);
491 (*this)(pixid).FillAbsTime(timelo);
492
493 if (fGeom->GetPixRatio(pixel.GetPixelId()) == 1.)
494 {
495 sumhiinnertot += timehi;
496 sumloinnertot += timelo;
497 fNumInnerPixels++;
498 }
499 else
500 {
501 sumhioutertot += timehi;
502 sumlooutertot += timelo;
503 fNumOuterPixels++;
504 }
505 }
506
507 fAverageHiGainInnerPix-> FillAbsTime(sumhiinnertot/fNumInnerPixels);
508 fAverageLoGainInnerPix-> FillAbsTime(sumloinnertot/fNumInnerPixels);
509 fAverageHiGainOuterPix-> FillAbsTime(sumhioutertot/fNumOuterPixels);
510 fAverageLoGainOuterPix-> FillAbsTime(sumlooutertot/fNumOuterPixels);
511
512 return kTRUE;
513}
514
515// --------------------------------------------------------------------------
516//
517// 1) Return if the charge distribution is already succesfully fitted
518// or if the histogram is empty
519// 2) Fit the histograms with a Gaussian
520// 3) In case of failure set the bit kFitted to false and take histogram means and RMS
521// 4) Check for pickup noise
522// 5) Check the fourier spectrum
523// 5) Retrieve the results and store them in this class
524//
525Bool_t MHCalibrationChargeCam::Finalize()
526{
527
528 for (int i=0; i<fHiGainArray->GetSize(); i++)
529 {
530
531 MCalibrationChargePix &pix = (*fCam)[i];
532 MHCalibrationChargeHiGainPix &histhi = (*this)[i];
533 MBadPixelsPix &bad = (*fBadPixels)[i];
534
535 FinalizeHiGainHists(histhi,pix,bad);
536
537 }
538
539 for (int i=0; i<fLoGainArray->GetSize(); i++)
540 {
541
542 if ((*this)(i).IsExcluded())
543 continue;
544
545 MHCalibrationChargeLoGainPix &histlo = (*this)(i);
546 MCalibrationChargePix &pix = (*fCam)[i];
547 MBadPixelsPix &bad = (*fBadPixels)[i];
548
549 FinalizeLoGainHists(histlo,pix,bad);
550
551 }
552
553 FinalizeHiGainHists(*fAverageHiGainInnerPix,*fCam->GetAverageInnerPix(),*fCam->GetAverageInnerBadPix());
554 FinalizeLoGainHists(*fAverageLoGainInnerPix,*fCam->GetAverageInnerPix(),*fCam->GetAverageInnerBadPix());
555 FinalizeHiGainHists(*fAverageHiGainOuterPix,*fCam->GetAverageOuterPix(),*fCam->GetAverageOuterBadPix());
556 FinalizeLoGainHists(*fAverageLoGainOuterPix,*fCam->GetAverageOuterPix(),*fCam->GetAverageOuterBadPix());
557
558 FinalizeAveragePix(*fCam->GetAverageInnerPix(),fNumInnerPixels,
559 fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
560 fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr,
561 fAverageInnerSat);
562 FinalizeAveragePix(*fCam->GetAverageOuterPix(),fNumOuterPixels,
563 fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
564 fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr,
565 fAverageOuterSat);
566
567 return kTRUE;
568}
569
570void MHCalibrationChargeCam::FinalizeHiGainHists(MHCalibrationChargeHiGainPix &hist,
571 MCalibrationChargePix &pix,
572 MBadPixelsPix &bad)
573{
574
575 if (hist.IsEmpty())
576 {
577 *fLog << warn << "Empty Hi Gain histogram in pixel: " << pix.GetPixId() << endl;
578 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
579 return;
580 }
581
582 if (hist.GetSaturated() > fNumHiGainSaturationLimit*hist.GetHGausHist()->GetEntries())
583 {
584 pix.SetHiGainSaturation();
585 return;
586 }
587
588 //
589 // 2) Fit the Hi Gain histograms with a Gaussian
590 //
591 if (!hist.FitGaus())
592 //
593 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
594 //
595 if (!hist.RepeatFit())
596 {
597 hist.BypassFit();
598 *fLog << warn << "Hi Gain could not be fitted in pixel: " << pix.GetPixId() << endl;
599 bad.SetUncalibrated( MBadPixelsPix::kHiGainNotFitted );
600 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
601 }
602
603 //
604 // 4) Check for pickup
605 //
606 hist.CountPickup();
607
608 //
609 // 5) Check for oscillations
610 //
611 hist.CreateFourierSpectrum();
612
613 //
614 // 6) Retrieve the results and store them in this class
615 //
616 pix.SetHiGainMeanCharge( hist.GetMean() );
617 pix.SetHiGainMeanChargeErr( hist.GetMeanErr() );
618 pix.SetHiGainSigmaCharge( hist.GetSigma() );
619 pix.SetHiGainSigmaChargeErr( hist.GetSigmaErr() );
620 pix.SetHiGainChargeProb ( hist.GetProb() );
621
622 pix.SetAbsTimeMean ( hist.GetAbsTimeMean());
623 pix.SetAbsTimeRms ( hist.GetAbsTimeRms() );
624
625 pix.SetHiGainNumPickup ( hist.GetPickup() );
626
627 if (!hist.IsFourierSpectrumOK())
628 {
629 *fLog << warn << "Oscillating Hi Gain in pixel: " << pix.GetPixId() << endl;
630 bad.SetUncalibrated( MBadPixelsPix::kHiGainOscillating );
631 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
632 }
633}
634
635
636void MHCalibrationChargeCam::FinalizeLoGainHists(MHCalibrationChargeLoGainPix &hist,
637 MCalibrationChargePix &pix,
638 MBadPixelsPix &bad)
639{
640
641 if (hist.IsEmpty())
642 {
643 if (pix.IsHiGainSaturation())
644 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
645 return;
646 }
647
648 if (hist.GetSaturated() > fNumLoGainSaturationLimit*hist.GetHGausHist()->GetEntries())
649 {
650 pix.SetLoGainSaturation();
651 bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
652 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
653 return;
654 }
655
656 //
657 // 2) Fit the Lo Gain histograms with a Gaussian
658 //
659 if (!hist.FitGaus())
660 //
661 // 3) In case of failure set the bit kFitted to false and take histogram means and RMS
662 //
663 if (!hist.RepeatFit())
664 {
665 hist.BypassFit();
666 bad.SetUncalibrated( MBadPixelsPix::kLoGainNotFitted );
667 if (pix.IsHiGainSaturation())
668 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
669 }
670
671 //
672 // 4) Check for pickup
673 //
674 hist.CountPickup();
675
676 //
677 // 5) Check for oscillations
678 //
679 hist.CreateFourierSpectrum();
680
681 //
682 // 6) Retrieve the results and store them in this class
683 //
684 pix.SetLoGainMeanCharge( hist.GetMean() );
685 pix.SetLoGainMeanChargeErr( hist.GetMeanErr() );
686 pix.SetLoGainSigmaCharge( hist.GetSigma() );
687 pix.SetLoGainSigmaChargeErr( hist.GetSigmaErr() );
688 pix.SetLoGainChargeProb ( hist.GetProb() );
689
690 if (pix.IsHiGainSaturation())
691 {
692 pix.SetAbsTimeMean ( hist.GetAbsTimeMean());
693 pix.SetAbsTimeRms ( hist.GetAbsTimeRms() );
694 }
695
696 pix.SetLoGainNumPickup ( hist.GetPickup() );
697
698 if (!hist.IsFourierSpectrumOK())
699 {
700 bad.SetUncalibrated( MBadPixelsPix::kLoGainOscillating );
701 if (pix.IsHiGainSaturation())
702 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
703 }
704}
705
706void MHCalibrationChargeCam::FinalizeAveragePix(MCalibrationChargePix &pix, Int_t npix,
707 Float_t &sigma, Float_t &sigmaerr,
708 Float_t &relsigma, Float_t &relsigmaerr,
709 Bool_t &b)
710{
711
712 if (pix.IsHiGainSaturation())
713 b = kTRUE;
714
715 sigma = pix.GetSigmaCharge () * TMath::Sqrt((Float_t)npix);
716 sigmaerr = pix.GetSigmaChargeErr () * TMath::Sqrt((Float_t)npix);
717
718 relsigma = sigma / pix.GetMeanCharge();
719
720 relsigmaerr = sigmaerr*sigmaerr / sigma / sigma;
721 relsigmaerr += pix.GetMeanChargeErr()*pix.GetMeanChargeErr() / pix.GetMeanCharge() / pix.GetMeanCharge();
722
723 relsigmaerr *= relsigma;
724 relsigmaerr = TMath::Sqrt(relsigmaerr);
725
726 pix.SetSigmaCharge (sigma);
727 pix.SetSigmaChargeErr(sigmaerr);
728
729}
730
731
732Bool_t MHCalibrationChargeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
733{
734 return kTRUE;
735}
736
737// --------------------------------------------------------------------------
738//
739// What MHCamera needs in order to draw an individual pixel in the camera
740//
741void MHCalibrationChargeCam::DrawPixelContent(Int_t idx) const
742{
743
744 if (idx == -1)
745 fAverageHiGainInnerPix->DrawClone();
746 if (idx == -2)
747 fAverageHiGainOuterPix->DrawClone();
748 if (idx == -3)
749 fAverageLoGainInnerPix->DrawClone();
750 if (idx == -4)
751 fAverageLoGainOuterPix->DrawClone();
752 (*this)[idx].DrawClone();
753
754}
755
756
757void MHCalibrationChargeCam::Draw(const Option_t *opt)
758{
759
760 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
761 pad->SetBorderMode(0);
762
763 pad->Divide(2,2);
764
765 pad->cd(1);
766
767 fAverageHiGainInnerPix->Draw(opt);
768
769 if (!fAverageInnerSat)
770 DrawAverageSigma(fAverageInnerSat, 1,
771 fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
772 fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr);
773
774 pad->cd(2);
775
776 fAverageLoGainInnerPix->Draw(opt);
777
778 if (fAverageInnerSat)
779 DrawAverageSigma(fAverageInnerSat, 1,
780 fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
781 fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr);
782
783 pad->cd(3);
784
785 fAverageHiGainOuterPix->Draw(opt);
786
787 if (!fAverageOuterSat)
788 DrawAverageSigma(fAverageOuterSat, 0,
789 fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
790 fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr);
791
792 pad->cd(4);
793
794 fAverageLoGainOuterPix->Draw(opt);
795
796 if (fAverageOuterSat)
797 DrawAverageSigma(fAverageOuterSat, 0,
798 fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
799 fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr);
800}
801
802void MHCalibrationChargeCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
803 Float_t sigma, Float_t sigmaerr,
804 Float_t relsigma, Float_t relsigmaerr) const
805{
806
807 if (sigma != 0)
808 {
809
810 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
811 newpad->SetFillStyle(4000);
812 newpad->Draw();
813 newpad->cd();
814
815 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
816 text->SetTextSize(0.07);
817 const TString line1 = Form("%s%s%s",inner ? "Inner" : "Outer",
818 " Pixels ", sat ? "Low Gain" : "High Gain");
819 TText *txt1 = text->AddText(line1.Data());
820 const TString line2 = Form("Sigma per Pixel: %2.2f #pm %2.2f",sigma,sigmaerr);
821 TText *txt2 = text->AddText(line2.Data());
822 const TString line3 = Form("Rel. Sigma per Pixel: %2.2f #pm %2.2f",relsigma,relsigmaerr);
823 TText *txt3 = text->AddText(line3.Data());
824 text->Draw("");
825
826 text->SetBit(kCanDelete);
827 txt1->SetBit(kCanDelete);
828 txt2->SetBit(kCanDelete);
829 txt3->SetBit(kCanDelete);
830 newpad->SetBit(kCanDelete);
831 }
832}
833
Note: See TracBrowser for help on using the repository browser.