source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc@ 7454

Last change on this file since 7454 was 7288, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 48.6 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// MHCalibrationChargeCam
27//
28// Fills the extracted signals of MExtractedSignalCam into the MHCalibrationPix-classes
29// MHCalibrationChargeHiGainPix and MHCalibrationChargeLoGainPix for every:
30//
31// - Pixel, stored in the TOrdCollection's MHCalibrationCam::fHiGainArray and
32// MHCalibrationCam::fLoGainArray
33//
34// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
35// stored in the TOrdCollection's MHCalibrationCam::fAverageHiGainAreas and
36// MHCalibrationCam::fAverageLoGainAreas
37//
38// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
39// stored in the TOrdCollection's MHCalibrationCam::fAverageHiGainSectors and
40// MHCalibrationCam::fAverageLoGainSectors
41//
42// Every signal is taken from MExtractedSignalCam and filled into a histogram and
43// an array, in order to perform a Fourier analysis (see MHGausEvents).
44// The signals are moreover averaged on an event-by-event basis and written into
45// the corresponding average pixels.
46//
47// Additionally, the (FADC slice) position of the maximum is stored in an Absolute
48// Arrival Time histogram. This histogram serves for a rough cross-check if the
49// signal does not lie at or outside the edges of the extraction window.
50//
51// The Charge histograms are fitted to a Gaussian, mean and sigma with its errors
52// and the fit probability are extracted. If none of these values are NaN's and
53// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
54// the fit is declared valid.
55// Otherwise, the fit is repeated within ranges of the previous mean
56// +- MHCalibrationPix::fPickupLimit (default: 5) sigma (see MHCalibrationPix::RepeatFit())
57// In case this does not make the fit valid, the histogram means and RMS's are
58// taken directly (see MHCalibrationPix::BypassFit()) and the following flags are set:
59// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted ) or
60// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted ) and
61// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
62//
63// Outliers of more than MHCalibrationPix::fPickupLimit (default: 5) sigmas
64// from the mean are counted as Pickup events (stored in MHCalibrationPix::fPickup)
65//
66// If more than fNumHiGainSaturationLimit (default: 15%) of the overall FADC
67// slices show saturation, the following flag is set:
68// - MCalibrationChargePix::SetHiGainSaturation();
69// In that case, the calibration constants are derived from the low-gain results.
70//
71// If more than fNumLoGainSaturationLimit (default: 1%) of the overall
72// low-gain FADC slices saturate, the following flags are set:
73// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturation ) and
74// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnsuitableRun )
75//
76// The class also fills arrays with the signal vs. event number, creates a fourier
77// spectrum and investigates if the projected fourier components follow an exponential
78// distribution. In case that the probability of the exponential fit is less than
79// MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
80// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating ) or
81// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating ) and
82// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
83//
84// This same procedure is performed for the average pixels.
85//
86// The following results are written into MCalibrationChargeCam:
87//
88// - MCalibrationPix::SetHiGainSaturation()
89// - MCalibrationPix::SetHiGainMean()
90// - MCalibrationPix::SetHiGainMeanErr()
91// - MCalibrationPix::SetHiGainSigma()
92// - MCalibrationPix::SetHiGainSigmaErr()
93// - MCalibrationPix::SetHiGainProb()
94// - MCalibrationPix::SetHiGainNumPickup()
95//
96// - MCalibrationPix::SetLoGainMean()
97// - MCalibrationPix::SetLoGainMeanErr()
98// - MCalibrationPix::SetLoGainSigma()
99// - MCalibrationPix::SetLoGainSigmaErr()
100// - MCalibrationPix::SetLoGainProb()
101// - MCalibrationPix::SetLoGainNumPickup()
102//
103// - MCalibrationChargePix::SetAbsTimeMean()
104// - MCalibrationChargePix::SetAbsTimeRms()
105//
106// For all averaged areas, the fitted sigma is multiplied with the square root of
107// the number involved pixels in order to be able to compare it to the average of
108// sigmas in the camera.
109//
110// Class Version 2:
111// + Float_t fNumLoGainBlackoutLimit; // Rel. amount blackout logain events until pixel is declared unsuitable
112//
113/////////////////////////////////////////////////////////////////////////////
114#include "MHCalibrationChargeCam.h"
115#include "MHCalibrationCam.h"
116
117#include "MLog.h"
118#include "MLogManip.h"
119
120#include "MParList.h"
121
122#include "MHCalibrationChargePix.h"
123#include "MHCalibrationPix.h"
124
125#include "MCalibrationIntensityCam.h"
126#include "MCalibrationChargeCam.h"
127#include "MCalibrationChargePix.h"
128
129#include "MGeomCam.h"
130#include "MGeomPix.h"
131
132#include "MBadPixelsIntensityCam.h"
133#include "MBadPixelsCam.h"
134#include "MBadPixelsPix.h"
135
136#include "MRawEvtData.h"
137#include "MRawRunHeader.h"
138#include "MRawEvtPixelIter.h"
139
140#include "MExtractedSignalCam.h"
141#include "MExtractedSignalPix.h"
142
143#include "MArrayI.h"
144#include "MArrayD.h"
145
146#include <TOrdCollection.h>
147#include <TPad.h>
148#include <TVirtualPad.h>
149#include <TCanvas.h>
150#include <TStyle.h>
151#include <TF1.h>
152#include <TLatex.h>
153#include <TLegend.h>
154#include <TGraph.h>
155#include <TEnv.h>
156
157ClassImp(MHCalibrationChargeCam);
158
159using namespace std;
160
161const Int_t MHCalibrationChargeCam::fgChargeHiGainNbins = 500;
162const Axis_t MHCalibrationChargeCam::fgChargeHiGainFirst = -98.;
163const Axis_t MHCalibrationChargeCam::fgChargeHiGainLast = 1902.;
164const Int_t MHCalibrationChargeCam::fgChargeLoGainNbins = 500;
165const Axis_t MHCalibrationChargeCam::fgChargeLoGainFirst = -99.;
166const Axis_t MHCalibrationChargeCam::fgChargeLoGainLast = 901.;
167const Float_t MHCalibrationChargeCam::fgProbLimit = 0.00000001;
168const TString MHCalibrationChargeCam::gsHistName = "Charge";
169const TString MHCalibrationChargeCam::gsHistTitle = "Signals";
170const TString MHCalibrationChargeCam::gsHistXTitle = "Signal [FADC counts]";
171const TString MHCalibrationChargeCam::gsHistYTitle = "Nr. events";
172const TString MHCalibrationChargeCam::gsAbsHistName = "AbsTime";
173const TString MHCalibrationChargeCam::gsAbsHistTitle = "Abs. Arr. Times";
174const TString MHCalibrationChargeCam::gsAbsHistXTitle = "Time [FADC slices]";
175const TString MHCalibrationChargeCam::gsAbsHistYTitle = "Nr. events";
176const Float_t MHCalibrationChargeCam::fgNumHiGainSaturationLimit = 0.15;
177const Float_t MHCalibrationChargeCam::fgNumLoGainSaturationLimit = 0.005;
178const Float_t MHCalibrationChargeCam::fgNumLoGainBlackoutLimit = 0.05;
179const Float_t MHCalibrationChargeCam::fgLoGainBlackoutLimit = 3.5;
180const Float_t MHCalibrationChargeCam::fgLoGainPickupLimit = 3.5;
181const Float_t MHCalibrationChargeCam::fgTimeLowerLimit = 1.;
182const Float_t MHCalibrationChargeCam::fgTimeUpperLimit = 3.;
183const TString MHCalibrationChargeCam::fgReferenceFile = "mjobs/calibrationref.rc";
184
185// --------------------------------------------------------------------------
186//
187// Default Constructor.
188//
189// Sets:
190// - all pointers to NULL
191//
192// Initializes:
193// - fNumHiGainSaturationLimit to fgNumHiGainSaturationLimit
194// - fNumLoGainSaturationLimit to fgNumLoGainSaturationLimit
195// - fTimeLowerLimit to fgTimeLowerLimit
196// - fTimeUpperLimit to fgTimeUpperLimit
197// - fNumLoGainBlackoutLimit to fgNumLoGainBlackoutLimit
198//
199// - fNbins to fgChargeHiGainNbins
200// - fFirst to fgChargeHiGainFirst
201// - fLast to fgChargeHiGainLast
202//
203// - fLoGainNbins to fgChargeLoGainNbins
204// - fLoGainFirst to fgChargeLoGainFirst
205// - fLoGainLast to fgChargeLoGainLast
206//
207// - fHistName to gsHistName
208// - fHistTitle to gsHistTitle
209// - fHistXTitle to gsHistXTitle
210// - fHistYTitle to gsHistYTitle
211//
212// - fAbsHistName to gsAbsHistName
213// - fAbsHistTitle to gsAbsHistTitle
214// - fAbsHistXTitle to gsAbsHistXTitle
215// - fAbsHistYTitle to gsAbsHistYTitle
216//
217MHCalibrationChargeCam::MHCalibrationChargeCam(const char *name, const char *title)
218 : fRawEvt(NULL)
219{
220
221 fName = name ? name : "MHCalibrationChargeCam";
222 fTitle = title ? title : "Class to fill the calibration histograms ";
223
224 SetNumHiGainSaturationLimit(fgNumHiGainSaturationLimit);
225 SetNumLoGainSaturationLimit(fgNumLoGainSaturationLimit);
226
227 SetNumLoGainBlackoutLimit (fgNumLoGainBlackoutLimit);
228
229 SetTimeLowerLimit();
230 SetTimeUpperLimit();
231
232 SetNbins(fgChargeHiGainNbins);
233 SetFirst(fgChargeHiGainFirst);
234 SetLast (fgChargeHiGainLast );
235
236 SetProbLimit(fgProbLimit);
237
238 SetLoGainNbins(fgChargeLoGainNbins);
239 SetLoGainFirst(fgChargeLoGainFirst);
240 SetLoGainLast (fgChargeLoGainLast );
241
242 SetHistName (gsHistName .Data());
243 SetHistTitle (gsHistTitle .Data());
244 SetHistXTitle(gsHistXTitle.Data());
245 SetHistYTitle(gsHistYTitle.Data());
246
247 SetAbsHistName (gsAbsHistName .Data());
248 SetAbsHistTitle (gsAbsHistTitle .Data());
249 SetAbsHistXTitle(gsAbsHistXTitle.Data());
250 SetAbsHistYTitle(gsAbsHistYTitle.Data());
251
252 SetReferenceFile();
253
254 fInnerRefCharge = 278.;
255 fOuterRefCharge = 282.;
256}
257
258// --------------------------------------------------------------------------
259//
260// Creates new MHCalibrationChargeCam only with the averaged areas:
261// the rest has to be retrieved directly, e.g. via:
262// MHCalibrationChargeCam *cam = MParList::FindObject("MHCalibrationChargeCam");
263// - cam->GetAverageSector(5).DrawClone();
264// - (*cam)[100].DrawClone()
265//
266TObject *MHCalibrationChargeCam::Clone(const char *) const
267{
268
269 MHCalibrationChargeCam *cam = new MHCalibrationChargeCam();
270
271 //
272 // Copy the data members
273 //
274 cam->fColor = fColor;
275 cam->fRunNumbers = fRunNumbers;
276 cam->fPulserFrequency = fPulserFrequency;
277 cam->fFlags = fFlags;
278 cam->fNbins = fNbins;
279 cam->fFirst = fFirst;
280 cam->fLast = fLast;
281 cam->fLoGainNbins = fLoGainNbins;
282 cam->fLoGainFirst = fLoGainFirst;
283 cam->fLoGainLast = fLoGainLast;
284 cam->fReferenceFile = fReferenceFile;
285
286 //
287 // Copy the MArrays
288 //
289 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
290 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
291 cam->fAverageAreaSat = fAverageAreaSat;
292 cam->fAverageAreaSigma = fAverageAreaSigma;
293 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
294 cam->fAverageAreaNum = fAverageAreaNum;
295 cam->fAverageSectorNum = fAverageSectorNum;
296
297 if (!IsAverageing())
298 return cam;
299
300 const Int_t navhi = fAverageHiGainAreas->GetSize();
301
302 for (int i=0; i<navhi; i++)
303 cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
304
305 if (IsLoGain())
306 {
307
308 const Int_t navlo = fAverageLoGainAreas->GetSize();
309 for (int i=0; i<navlo; i++)
310 cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
311
312 }
313
314 return cam;
315}
316
317// --------------------------------------------------------------------------
318//
319// Gets the pointers to:
320// - MRawEvtData
321//
322Bool_t MHCalibrationChargeCam::SetupHists(const MParList *pList)
323{
324
325 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
326 if (!fRawEvt)
327 {
328 *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
329 return kFALSE;
330 }
331
332 return kTRUE;
333}
334
335// --------------------------------------------------------------------------
336//
337// Gets or creates the pointers to:
338// - MExtractedSignalCam
339// - MCalibrationChargeCam or MCalibrationIntensityChargeCam
340// - MBadPixelsCam
341//
342// Initializes the number of used FADC slices from MExtractedSignalCam
343// into MCalibrationChargeCam and test for changes in that variable
344//
345// Calls:
346// - InitHiGainArrays()
347// - InitLoGainArrays()
348//
349// Sets:
350// - fSumhiarea to nareas
351// - fSumloarea to nareas
352// - fTimehiarea to nareas
353// - fTimeloarea to nareas
354// - fSumhisector to nsectors
355// - fSumlosector to nsectors
356// - fTimehisector to nsectors
357// - fTimelosector to nsectors
358// - fSathiarea to nareas
359// - fSatloarea to nareas
360// - fSathisector to nsectors
361// - fSatlosector to nsectors
362//
363Bool_t MHCalibrationChargeCam::ReInitHists(MParList *pList)
364{
365
366 MExtractedSignalCam *signal =
367 (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
368 if (!signal)
369 {
370 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
371 return kFALSE;
372 }
373
374 if (!InitCams(pList,"Charge"))
375 return kFALSE;
376
377 fFirstHiGain = signal->GetFirstUsedSliceHiGain();
378 fLastHiGain = signal->GetLastUsedSliceHiGain();
379 fFirstLoGain = signal->GetFirstUsedSliceLoGain();
380 fLastLoGain = signal->GetLastUsedSliceLoGain();
381
382 const Int_t npixels = fGeom->GetNumPixels();
383 const Int_t nsectors = fGeom->GetNumSectors();
384 const Int_t nareas = fGeom->GetNumAreas();
385
386 //
387 // In case of the intense blue, double the range
388 //
389 if (fGeom->InheritsFrom("MGeomCamMagic"))
390 if ( fColor == MCalibrationCam::kBLUE)
391 SetLoGainLast(2.*fLoGainLast - fLoGainFirst);
392
393 InitHiGainArrays(npixels,nareas,nsectors);
394 InitLoGainArrays(npixels,nareas,nsectors);
395
396 fSumhiarea .Set(nareas);
397 fSumloarea .Set(nareas);
398 fTimehiarea .Set(nareas);
399 fTimeloarea .Set(nareas);
400 fSumhisector.Set(nsectors);
401 fSumlosector.Set(nsectors);
402 fTimehisector.Set(nsectors);
403 fTimelosector.Set(nsectors);
404
405 fSathiarea .Set(nareas);
406 fSatloarea .Set(nareas);
407 fSathisector.Set(nsectors);
408 fSatlosector.Set(nsectors);
409
410 return kTRUE;
411}
412
413// --------------------------------------------------------------------------
414//
415// Retrieve:
416// - fRunHeader->GetNumSamplesHiGain();
417//
418// Initializes the High Gain Arrays:
419//
420// - For every entry in the expanded arrays:
421// * Initialize an MHCalibrationChargePix
422// * Set Binning from fNbins, fFirst and fLast
423// * Set Binning of Abs Times histogram from fAbsNbins, fAbsFirst and fAbsLast
424// * Set Histgram names and titles from fHistName and fHistTitle
425// * Set Abs Times Histgram names and titles from fAbsHistName and fAbsHistTitle
426// * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
427// * Set X-axis and Y-axis titles of Abs Times Histogram from fAbsHistXTitle and fAbsHistYTitle
428// * Call InitHists
429//
430//
431void MHCalibrationChargeCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
432{
433
434 MBadPixelsCam *badcam = fIntensBad
435 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
436
437 TH1F *h;
438
439 const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain();
440
441 if (fHiGainArray->GetSize()==0)
442 {
443 for (Int_t i=0; i<npixels; i++)
444 {
445 fHiGainArray->AddAt(new MHCalibrationChargePix(Form("%sHiGainPix%04d",fHistName.Data(),i),
446 Form("%s High Gain Pixel%04d",fHistTitle.Data(),i)),i);
447
448 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)(*this)[i];
449
450 pix.SetNbins(fNbins);
451 pix.SetFirst(fFirst);
452 pix.SetLast (fLast);
453
454 pix.SetProbLimit(fProbLimit);
455
456 pix.SetAbsTimeNbins(higainsamples);
457 pix.SetAbsTimeFirst(-0.5);
458 pix.SetAbsTimeLast(higainsamples-0.5);
459
460 InitHists(pix,(*badcam)[i],i);
461
462 h = pix.GetHAbsTime();
463
464 h->SetName (Form("H%sHiGainPix%04d",fAbsHistName.Data(),i));
465 h->SetTitle(Form("%s High Gain Pixel %04d",fAbsHistTitle.Data(),i));
466 h->SetXTitle(fAbsHistXTitle.Data());
467 h->SetYTitle(fAbsHistYTitle.Data());
468 }
469 }
470
471
472 if (fAverageHiGainAreas->GetSize()==0)
473 {
474 for (Int_t j=0; j<nareas; j++)
475 {
476 fAverageHiGainAreas->AddAt(new MHCalibrationChargePix(Form("%sHiGainArea%d",fHistName.Data(),j),
477 Form("%s High Gain Area Idx %d",fHistTitle.Data(),j)),j);
478
479 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
480
481 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
482 pix.SetFirst(fFirst);
483 pix.SetLast (fLast);
484
485 pix.SetAbsTimeNbins(higainsamples);
486 pix.SetAbsTimeFirst(-0.5);
487 pix.SetAbsTimeLast(higainsamples-0.5);
488
489 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
490
491 h = pix.GetHAbsTime();
492
493 h->SetName (Form("H%sHiGainArea%d",fAbsHistName.Data(),j));
494 h->SetTitle(Form("%s%s%d",fAbsHistTitle.Data(),
495 " averaged on event-by-event basis High Gain Area Idx ",j));
496 h->SetXTitle(fAbsHistXTitle.Data());
497 h->SetYTitle(fAbsHistYTitle.Data());
498 }
499 }
500
501 if (fAverageHiGainSectors->GetSize()==0)
502 {
503 for (Int_t j=0; j<nsectors; j++)
504 {
505 fAverageHiGainSectors->AddAt(new MHCalibrationChargePix(Form("%sHiGainSector%02d",fHistName.Data(),j),
506 Form("%s High Gain Sector %02d",fHistTitle.Data(),j)),j);
507
508 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageHiGainSector(j);
509
510 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
511 pix.SetFirst(fFirst);
512 pix.SetLast (fLast);
513
514 pix.SetAbsTimeNbins(higainsamples);
515 pix.SetAbsTimeFirst(-0.5);
516 pix.SetAbsTimeLast(higainsamples-0.5);
517
518 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
519
520 h = pix.GetHAbsTime();
521
522 h->SetName (Form("H%sHiGainSector%02d",fAbsHistName.Data(),j));
523 h->SetTitle(Form("%s%s%02d",fAbsHistTitle.Data(),
524 " averaged on event-by-event basis High Gain Area Sector ",j));
525 h->SetXTitle(fAbsHistXTitle.Data());
526 h->SetYTitle(fAbsHistYTitle.Data());
527 }
528 }
529}
530
531//--------------------------------------------------------------------------------------
532//
533// Return, if IsLoGain() is kFALSE
534//
535// Retrieve:
536// - fRunHeader->GetNumSamplesHiGain();
537//
538// Initializes the Low Gain Arrays:
539//
540// - For every entry in the expanded arrays:
541// * Initialize an MHCalibrationChargePix
542// * Set Binning from fNbins, fFirst and fLast
543// * Set Binning of Abs Times histogram from fAbsNbins, fAbsFirst and fAbsLast
544// * Set Histgram names and titles from fHistName and fHistTitle
545// * Set Abs Times Histgram names and titles from fAbsHistName and fAbsHistTitle
546// * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
547// * Set X-axis and Y-axis titles of Abs Times Histogram from fAbsHistXTitle and fAbsHistYTitle
548// * Call InitHists
549//
550void MHCalibrationChargeCam::InitLoGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
551{
552
553 if (!IsLoGain())
554 return;
555
556
557 MBadPixelsCam *badcam = fIntensBad
558 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
559
560 const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain();
561
562 TH1F *h;
563
564 if (fLoGainArray->GetSize()==0 )
565 {
566 for (Int_t i=0; i<npixels; i++)
567 {
568 fLoGainArray->AddAt(new MHCalibrationChargePix(Form("%sLoGainPix%04d",fHistName.Data(),i),
569 Form("%s Low Gain Pixel %04d",fHistTitle.Data(),i)),i);
570
571 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)(*this)(i);
572
573 pix.SetNbins(fLoGainNbins);
574 pix.SetFirst(fLoGainFirst);
575 pix.SetLast (fLoGainLast);
576
577 pix.SetProbLimit(fProbLimit);
578
579 pix.SetAbsTimeNbins(logainsamples);
580 pix.SetAbsTimeFirst(-0.5);
581 pix.SetAbsTimeLast(logainsamples-0.5);
582 pix.SetPickupLimit(fgLoGainPickupLimit);
583 pix.SetBlackoutLimit(fgLoGainBlackoutLimit);
584
585 InitHists(pix,(*badcam)[i],i);
586
587 h = pix.GetHAbsTime();
588
589 h->SetName (Form("H%sLoGainPix%04d",fAbsHistName.Data(),i));
590 h->SetTitle(Form("%s Low Gain Pixel %04d",fAbsHistTitle.Data(),i));
591 h->SetXTitle(fAbsHistXTitle.Data());
592 h->SetYTitle(fAbsHistYTitle.Data());
593 }
594 }
595
596 if (fAverageLoGainAreas->GetSize()==0)
597 {
598 for (Int_t j=0; j<nareas; j++)
599 {
600 fAverageLoGainAreas->AddAt(new MHCalibrationChargePix(Form("%sLoGainArea%d",fHistName.Data(),j),
601 Form("%s Low Gain Area Idx %d",fHistTitle.Data(),j)),j);
602
603 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
604
605 pix.SetNbins(fLoGainNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
606 pix.SetFirst(fLoGainFirst);
607 pix.SetLast (fLoGainLast);
608
609 pix.SetAbsTimeNbins(logainsamples);
610 pix.SetAbsTimeFirst(-0.5);
611 pix.SetAbsTimeLast(logainsamples-0.5);
612
613 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
614
615 h = pix.GetHAbsTime();
616
617 h->SetName (Form("H%sLoGainArea%02d",fAbsHistName.Data(),j));
618 h->SetTitle(Form("%s%s%02d",fAbsHistTitle.Data(),
619 " averaged on event-by-event basis Low Gain Area Idx ",j));
620 h->SetXTitle(fAbsHistXTitle.Data());
621 h->SetYTitle(fAbsHistYTitle.Data());
622 }
623 }
624
625
626 if (fAverageLoGainSectors->GetSize()==0 && IsLoGain())
627 {
628 for (Int_t j=0; j<nsectors; j++)
629 {
630 fAverageLoGainSectors->AddAt(new MHCalibrationChargePix(Form("%sLoGainSector%02d",fHistName.Data(),j),
631 Form("%s Low Gain Sector %02d",fHistTitle.Data(),j)),j);
632
633 MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
634
635 pix.SetNbins(fLoGainNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
636 pix.SetFirst(fLoGainFirst);
637 pix.SetLast (fLoGainLast);
638
639 pix.SetAbsTimeNbins(logainsamples);
640 pix.SetAbsTimeFirst(-0.5);
641 pix.SetAbsTimeLast(logainsamples-0.5);
642
643 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
644
645 h = pix.GetHAbsTime();
646
647 h->SetName (Form("H%sLoGainSector%02d",fAbsHistName.Data(),j));
648 h->SetTitle(Form("%s%s%02d",fAbsHistTitle.Data(),
649 " averaged on event-by-event basis Low Gain Area Sector ",j));
650 h->SetXTitle(fAbsHistXTitle.Data());
651 h->SetYTitle(fAbsHistYTitle.Data());
652 }
653 }
654}
655
656
657// --------------------------------------------------------------------------
658//
659// Retrieves from MExtractedSignalCam:
660// - first used LoGain FADC slice
661//
662// Retrieves from MGeomCam:
663// - number of pixels
664// - number of pixel areas
665// - number of sectors
666//
667// For all TOrdCollection's (including the averaged ones), the following steps are performed:
668//
669// 1) Fill Charges histograms (MHGausEvents::FillHistAndArray()) with:
670// - MExtractedSignalPix::GetExtractedSignalHiGain();
671// - MExtractedSignalPix::GetExtractedSignalLoGain();
672//
673// 2) Set number of saturated slices (MHCalibrationChargePix::AddSaturated()) with:
674// - MExtractedSignalPix::GetNumHiGainSaturated();
675// - MExtractedSignalPix::GetNumLoGainSaturated();
676//
677// 3) Fill AbsTime histograms (MHCalibrationChargePix::FillAbsTime()) with:
678// - MRawEvtPixelIter::GetIdxMaxHiGainSample();
679// - MRawEvtPixelIter::GetIdxMaxLoGainSample(first slice);
680//
681Bool_t MHCalibrationChargeCam::FillHists(const MParContainer *par, const Stat_t w)
682{
683
684 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
685 if (!signal)
686 {
687 *fLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
688 return kFALSE;
689 }
690
691 const UInt_t npixels = fGeom->GetNumPixels();
692 const UInt_t nareas = fGeom->GetNumAreas();
693 const UInt_t nsectors = fGeom->GetNumSectors();
694 const UInt_t lofirst = signal->GetFirstUsedSliceLoGain();
695
696 fSumhiarea .Reset();
697 fSumloarea .Reset();
698 fTimehiarea .Reset();
699 fTimeloarea .Reset();
700 fSumhisector.Reset();
701 fSumlosector.Reset();
702 fTimehisector.Reset();
703 fTimelosector.Reset();
704
705 fSathiarea .Reset();
706 fSatloarea .Reset();
707 fSathisector.Reset();
708 fSatlosector.Reset();
709
710 for (UInt_t i=0; i<npixels; i++)
711 {
712
713 MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)(*this)[i];
714
715 if (histhi.IsExcluded())
716 continue;
717
718 const MExtractedSignalPix &pix = (*signal)[i];
719
720 const Float_t sumhi = pix.GetExtractedSignalHiGain();
721 const Bool_t sathi = pix.GetNumHiGainSaturated()>0;
722
723 if (IsOscillations())
724 histhi.FillHistAndArray(sumhi);
725 else
726 histhi.FillHist(sumhi);
727
728 histhi.AddSaturated(sathi);
729
730 const Int_t aidx = (*fGeom)[i].GetAidx();
731 const Int_t sector = (*fGeom)[i].GetSector();
732
733 fSumhiarea[aidx] += sumhi;
734 fSumhisector[sector] += sumhi;
735 if (sathi)
736 {
737 fSathiarea[aidx]++;
738 fSathisector[sector]++;
739 }
740
741 if (IsLoGain())
742 {
743 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(i);
744 const Float_t sumlo = pix.GetExtractedSignalLoGain();
745 const Int_t satlo = (Int_t)pix.GetNumLoGainSaturated();
746
747 if (IsOscillations())
748 histlo.FillHistAndArray(sumlo);
749 else
750 histlo.FillHist(sumlo);
751
752 histlo.AddSaturated(satlo);
753
754 fSumloarea[aidx] += sumlo;
755 fSatloarea[aidx] += satlo;
756 fSumlosector[sector] += sumlo;
757 fSatlosector[sector] += satlo;
758 }
759
760 }
761
762 MRawEvtPixelIter pixel(fRawEvt);
763 while (pixel.Next())
764 {
765
766 const UInt_t pixid = pixel.GetPixelId();
767
768 MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)(*this)[pixid];
769
770 if (histhi.IsExcluded())
771 continue;
772
773 const Float_t timehi = (Float_t)pixel.GetIdxMaxHiGainSample();
774
775 histhi.FillAbsTime(timehi);
776
777 const Int_t aidx = (*fGeom)[pixid].GetAidx();
778 const Int_t sector = (*fGeom)[pixid].GetSector();
779
780 fTimehiarea [aidx] += timehi;
781 fTimehisector[sector] += timehi;
782
783 if (IsLoGain())
784 {
785 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(pixid);
786
787 const Float_t timelo = (Float_t)pixel.GetIdxMaxLoGainSample(lofirst);
788 histlo.FillAbsTime(timelo);
789
790 fTimeloarea[aidx] += timelo;
791 fTimelosector[sector] += timelo;
792 }
793 }
794
795 for (UInt_t j=0; j<nareas; j++)
796 {
797
798 const Int_t npix = fAverageAreaNum[j];
799
800 if (npix == 0)
801 continue;
802
803 MHCalibrationChargePix &hipix = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
804
805
806 if (IsOscillations())
807 hipix.FillHistAndArray(fSumhiarea [j]/npix);
808 else
809 hipix.FillHist(fSumhiarea[j]/npix);
810
811 hipix.AddSaturated ((Float_t)fSathiarea [j]/npix > 0.5 ? 1 : 0);
812 hipix.FillAbsTime (fTimehiarea[j]/npix);
813
814 if (IsLoGain())
815 {
816 MHCalibrationChargePix &lopix = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
817 if (IsOscillations())
818 lopix.FillHistAndArray(fSumloarea [j]/npix);
819 else
820 lopix.FillHist(fSumloarea [j]/npix);
821 lopix.AddSaturated ((Float_t)fSatloarea [j]/npix > 0.5 ? 1 : 0);
822 lopix.FillAbsTime (fTimeloarea[j]/npix);
823 }
824 }
825
826 for (UInt_t j=0; j<nsectors; j++)
827 {
828
829 const Int_t npix = fAverageSectorNum[j];
830
831 if (npix == 0)
832 continue;
833
834 MHCalibrationChargePix &hipix = (MHCalibrationChargePix&)GetAverageHiGainSector(j);
835
836 if (IsOscillations())
837 hipix.FillHistAndArray(fSumhisector [j]/npix);
838 else
839 hipix.FillHist(fSumhisector [j]/npix);
840
841 hipix.AddSaturated ((Float_t)fSathisector[j]/npix > 0.5 ? 1 : 0);
842 hipix.FillAbsTime (fTimehisector[j]/npix);
843
844 if (IsLoGain())
845 {
846 MHCalibrationChargePix &lopix = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
847
848 if (IsOscillations())
849 lopix.FillHistAndArray(fSumlosector [j]/npix);
850 else
851 lopix.FillHist(fSumlosector [j]/npix);
852
853 lopix.AddSaturated ((Float_t)fSatlosector[j]/npix > 0.5 ? 1 : 0);
854 lopix.FillAbsTime (fTimelosector[j]/npix);
855 }
856 }
857
858 return kTRUE;
859}
860
861// --------------------------------------------------------------------------
862//
863// For all TOrdCollection's (including the averaged ones), the following steps are performed:
864//
865// 1) Returns if the pixel is excluded.
866// 2) Tests saturation. In case yes, set the flag: MCalibrationPix::SetHiGainSaturation()
867// or the flag: MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturated )
868// 3) Store the absolute arrival times in the MCalibrationChargePix's. If flag
869// MCalibrationPix::IsHiGainSaturation() is set, the Low-Gain arrival times are stored,
870// otherwise the Hi-Gain ones.
871// 4) Calls to MHCalibrationCam::FitHiGainArrays() and MCalibrationCam::FitLoGainArrays()
872// with the flags:
873// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted )
874// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted )
875// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating )
876// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating )
877//
878Bool_t MHCalibrationChargeCam::FinalizeHists()
879{
880
881 *fLog << endl;
882
883 TH1F *h = NULL;
884
885 MCalibrationCam *chargecam = fIntensCam ? fIntensCam->GetCam() : fCam;
886 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
887
888
889 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
890 {
891
892 MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)(*this)[i];
893
894 if (histhi.IsExcluded())
895 continue;
896
897 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i] ;
898
899 const Int_t numsat = histhi.GetSaturated();
900
901 pix.SetNumSaturated(numsat);
902
903 if (numsat > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
904 {
905 pix.SetHiGainSaturation();
906 if (IsOscillations())
907 histhi.CreateFourierSpectrum();
908 continue;
909 }
910
911 MBadPixelsPix &bad = (*badcam)[i];
912
913 h = histhi.GetHGausHist();
914
915 Stat_t overflow = h->GetBinContent(h->GetNbinsX()+1);
916 if (overflow > fOverflowLimit*histhi.GetHGausHist()->GetEntries())
917 {
918 *fLog << warn
919 << "HiGain Hist-overflow " << overflow
920 << " times in: " << histhi.GetName() << " (w/o saturation!) " << endl;
921 bad.SetUncalibrated( MBadPixelsPix::kHiGainOverFlow );
922 }
923
924 overflow = h->GetBinContent(0);
925 if (overflow > fOverflowLimit*histhi.GetHGausHist()->GetEntries())
926 {
927 *fLog << warn
928 << "HiGain Hist-underflow " << overflow
929 << " times in pix: " << histhi.GetName() << " (w/o saturation!) " << endl;
930 bad.SetUncalibrated( MBadPixelsPix::kHiGainOverFlow );
931 }
932
933 FinalizeAbsTimes(histhi, pix, bad, fFirstHiGain, fLastHiGain);
934 }
935
936 if (IsLoGain())
937 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
938 {
939
940 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(i);
941 MBadPixelsPix &bad = (*badcam)[i];
942
943 if (histlo.IsExcluded())
944 continue;
945
946 if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
947 {
948 *fLog << warn << "Saturated Lo Gain histogram in pixel: " << i << endl;
949 bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
950 if (IsOscillations())
951 histlo.CreateFourierSpectrum();
952 continue;
953 }
954
955 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i] ;
956 if (!pix.IsHiGainSaturation())
957 continue;
958
959 h = histlo.GetHGausHist();
960
961 Stat_t overflow = h->GetBinContent(h->GetNbinsX()+1);
962 if (overflow > fOverflowLimit*histlo.GetHGausHist()->GetEntries())
963 {
964 *fLog << warn
965 << "LoGain Hist-overflow " << overflow
966 << " times in: " << histlo.GetName() << " (w/o saturation!) " << endl;
967 bad.SetUncalibrated( MBadPixelsPix::kLoGainOverFlow );
968 }
969
970 overflow = h->GetBinContent(0);
971 if (overflow > fOverflowLimit*histlo.GetHGausHist()->GetEntries())
972 {
973 *fLog << warn
974 << "LoGain Hist-underflow " << overflow
975 << " times in: " << histlo.GetName() << " (w/o saturation!) " << endl;
976 bad.SetUncalibrated( MBadPixelsPix::kLoGainOverFlow );
977 }
978
979 FinalizeAbsTimes(histlo, pix, bad, fFirstLoGain, fLastLoGain);
980 }
981
982 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
983 {
984
985 MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
986 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageArea(j);
987
988 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
989 {
990 pix.SetHiGainSaturation();
991 if (IsOscillations())
992 histhi.CreateFourierSpectrum();
993 continue;
994 }
995
996 MBadPixelsPix &bad = chargecam->GetAverageBadArea(j);
997 FinalizeAbsTimes(histhi, pix, bad, fFirstHiGain, fLastHiGain);
998 }
999
1000 if (IsLoGain())
1001 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
1002 {
1003
1004 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
1005
1006 if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
1007 {
1008 *fLog << warn << "Saturated Lo Gain histogram in area idx: " << j << endl;
1009 if (IsOscillations())
1010 histlo.CreateFourierSpectrum();
1011 continue;
1012 }
1013
1014 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageArea(j);
1015
1016 if (pix.IsHiGainSaturation())
1017 {
1018 MBadPixelsPix &bad = chargecam->GetAverageBadArea(j);
1019 FinalizeAbsTimes(histlo, pix, bad, fFirstLoGain, fLastLoGain);
1020 }
1021
1022 }
1023
1024 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
1025 {
1026
1027 MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)GetAverageHiGainSector(j);
1028 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageSector(j);
1029
1030 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
1031 {
1032 pix.SetHiGainSaturation();
1033 if (IsOscillations())
1034 histhi.CreateFourierSpectrum();
1035 continue;
1036 }
1037
1038 MBadPixelsPix &bad = chargecam->GetAverageBadSector(j);
1039 FinalizeAbsTimes(histhi, pix, bad, fFirstHiGain, fLastHiGain);
1040 }
1041
1042 if (IsLoGain())
1043 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
1044 {
1045
1046 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
1047 MBadPixelsPix &bad = chargecam->GetAverageBadSector(j);
1048
1049 if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
1050 {
1051 *fLog << warn << "Saturated Lo Gain histogram in sector: " << j << endl;
1052 bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
1053 if (IsOscillations())
1054 histlo.CreateFourierSpectrum();
1055 continue;
1056 }
1057
1058 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageSector(j);
1059
1060 if (pix.IsHiGainSaturation())
1061 FinalizeAbsTimes(histlo, pix, bad, fFirstLoGain, fLastLoGain);
1062 }
1063
1064 //
1065 // Perform the fitting for the High Gain (done in MHCalibrationCam)
1066 //
1067 FitHiGainArrays(*chargecam, *badcam,
1068 MBadPixelsPix::kHiGainNotFitted,
1069 MBadPixelsPix::kHiGainOscillating);
1070
1071 //
1072 // Perform the fitting for the Low Gain (done in MHCalibrationCam)
1073 //
1074 if (IsLoGain())
1075 FitLoGainArrays(*chargecam, *badcam,
1076 MBadPixelsPix::kLoGainNotFitted,
1077 MBadPixelsPix::kLoGainOscillating);
1078
1079 //
1080 // Check for pixels which have the high-gain saturated, but the low-gain
1081 // switch not applied in sufficient cases. Have to exclude these pixels,
1082 // although they not abnormal. They simply cannot be calibrated...
1083 //
1084 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
1085 {
1086
1087 MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(i);
1088 if (histlo.IsExcluded())
1089 continue;
1090
1091 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i] ;
1092 if (!pix.IsHiGainSaturation())
1093 continue;
1094
1095 //
1096 // Now,treat only low-gain calibrated pixels:
1097 //
1098 const Double_t lim = fNumLoGainBlackoutLimit*histlo.GetHGausHist()->GetEntries();
1099 if (histlo.GetBlackout() <= lim)
1100 continue;
1101
1102 MBadPixelsPix &bad = (*badcam)[i];
1103 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
1104 bad.SetUncalibrated(MBadPixelsPix::kLoGainBlackout);
1105 }
1106
1107 return kTRUE;
1108}
1109
1110// --------------------------------------------------------------------------------
1111//
1112// Fill the absolute time results into MCalibrationChargePix
1113//
1114// Check absolute time validity:
1115// - Mean arrival time is at least fTimeLowerLimit slices from the lower edge
1116// - Mean arrival time is at least fUpperLimit slices from the upper edge
1117//
1118void MHCalibrationChargeCam::FinalizeAbsTimes(MHCalibrationChargePix &hist, MCalibrationChargePix &pix, MBadPixelsPix &bad,
1119 Byte_t first, Byte_t last)
1120{
1121 const Float_t mean = hist.GetAbsTimeMean();
1122 const Float_t rms = hist.GetAbsTimeRms();
1123
1124 pix.SetAbsTimeMean(mean);
1125 pix.SetAbsTimeRms(rms);
1126
1127 const Float_t lowerlimit = (Float_t)first + fTimeLowerLimit;
1128 const Float_t upperlimit = (Float_t)last - fTimeUpperLimit;
1129
1130 if (mean<lowerlimit)
1131 {
1132 *fLog << warn << "Mean Arr.Time: "
1133 << Form("%4.1f < %4.1f, %3.1f", mean, TMath::Floor(first)+fTimeLowerLimit, fTimeLowerLimit)
1134 << " slices below " << Form("%2i", (Int_t)first) << " in "
1135 << hist.GetName() << endl;
1136 bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin );
1137 }
1138
1139 if (mean>upperlimit)
1140 {
1141 *fLog << warn << "Mean Arr.Time: "
1142 << Form("%4.1f > %4.1f, %3.1f", mean, TMath::Floor(last)-fTimeUpperLimit, fTimeUpperLimit)
1143 << " slices above " << Form("%2i", (Int_t)last) << " in "
1144 << hist.GetName() << endl;
1145 bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins );
1146 }
1147}
1148
1149// --------------------------------------------------------------------------
1150//
1151// Sets all pixels to MBadPixelsPix::kUnsuitableRun, if following flags are set:
1152// - MBadPixelsPix::kLoGainSaturation
1153//
1154// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
1155// - if MBadPixelsPix::kHiGainNotFitted and !MCalibrationPix::IsHiGainSaturation()
1156// - if MBadPixelsPix::kHiGainOscillating and !MCalibrationPix::IsHiGainSaturation()
1157// - if MBadPixelsPix::kLoGainNotFitted and MCalibrationPix::IsLoGainSaturation()
1158// - if MBadPixelsPix::kLoGainOscillating and MCalibrationPix::IsLoGainSaturation()
1159//
1160void MHCalibrationChargeCam::FinalizeBadPixels()
1161{
1162
1163 MBadPixelsCam *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
1164 MCalibrationCam *chargecam = fIntensCam ? fIntensCam->GetCam() : fCam;
1165
1166 for (Int_t i=0; i<badcam->GetSize(); i++)
1167 {
1168
1169 MBadPixelsPix &bad = (*badcam)[i];
1170 MCalibrationPix &pix = (*chargecam)[i];
1171
1172 if (bad.IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
1173 if (!pix.IsHiGainSaturation())
1174 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
1175
1176 if (bad.IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
1177 if (pix.IsHiGainSaturation())
1178 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
1179
1180 if (bad.IsUncalibrated(MBadPixelsPix::kLoGainSaturation))
1181 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
1182
1183 if (IsOscillations())
1184 {
1185 if (bad.IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
1186 if (!pix.IsHiGainSaturation())
1187 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
1188
1189 if (bad.IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
1190 if (pix.IsHiGainSaturation())
1191 bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
1192 }
1193 }
1194}
1195
1196// --------------------------------------------------------------------------
1197//
1198// Calls MHCalibrationPix::DrawClone() for pixel idx
1199//
1200void MHCalibrationChargeCam::DrawPixelContent(Int_t idx) const
1201{
1202 (*this)[idx].DrawClone();
1203}
1204
1205
1206// -----------------------------------------------------------------------------
1207//
1208// Default draw:
1209//
1210// Displays the averaged areas, both High Gain and Low Gain
1211//
1212// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
1213//
1214void MHCalibrationChargeCam::Draw(const Option_t *opt)
1215{
1216
1217 const Int_t nareas = fAverageHiGainAreas->GetSize();
1218 if (nareas == 0)
1219 return;
1220
1221 TString option(opt);
1222 option.ToLower();
1223
1224 if (!option.Contains("datacheck"))
1225 {
1226 MHCalibrationCam::Draw(opt);
1227 return;
1228 }
1229
1230 //
1231 // From here on , the datacheck - Draw
1232 //
1233 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
1234 pad->SetBorderMode(0);
1235 pad->Divide(1,nareas);
1236
1237 //
1238 // Loop over inner and outer pixels
1239 //
1240 for (Int_t i=0; i<nareas;i++)
1241 {
1242
1243 pad->cd(i+1);
1244
1245 MHCalibrationChargePix &hipix = (MHCalibrationChargePix&)GetAverageHiGainArea(i);
1246 //
1247 // Ask for Hi-Gain saturation
1248 //
1249 if (hipix.GetSaturated() > fNumHiGainSaturationLimit*hipix.GetHGausHist()->GetEntries() && IsLoGain())
1250 {
1251 MHCalibrationChargePix &lopix = (MHCalibrationChargePix&)GetAverageLoGainArea(i);
1252 DrawDataCheckPixel(lopix,i ? fOuterRefCharge : fInnerRefCharge);
1253 }
1254 else
1255 DrawDataCheckPixel(hipix,i ? fOuterRefCharge : fInnerRefCharge);
1256
1257 }
1258}
1259
1260// -----------------------------------------------------------------------------
1261//
1262// Draw the average pixel for the datacheck:
1263//
1264// Displays the averaged areas, both High Gain and Low Gain
1265//
1266// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
1267//
1268void MHCalibrationChargeCam::DrawDataCheckPixel(MHCalibrationChargePix &pix, const Float_t refline)
1269{
1270 if (pix.IsEmpty())
1271 return;
1272
1273 TVirtualPad *newpad = gPad;
1274 newpad->Divide(1,2);
1275 newpad->cd(1);
1276
1277 gPad->SetTicks();
1278 if (!pix.IsEmpty() && !pix.IsOnlyOverflow() && !pix.IsOnlyUnderflow())
1279 gPad->SetLogy();
1280
1281 TH1F *hist = pix.GetHGausHist();
1282
1283 TH1F *null = new TH1F("Null",hist->GetTitle(),100,
1284 pix.GetFirst() > 0. ? pix.GetFirst() : 0.,
1285 pix.GetLast() > pix.GetFirst()
1286 ? ( pix.GetLast() > 450.
1287 ? ( fColor == MCalibrationCam::kBLUE ? 800. : 450. )
1288 : pix.GetLast() )
1289 : pix.GetFirst()*2.);
1290
1291 null->SetMaximum(1.1*hist->GetMaximum());
1292 null->SetDirectory(NULL);
1293 null->SetBit(kCanDelete);
1294 null->SetStats(kFALSE);
1295 //
1296 // set the labels bigger
1297 //
1298 TAxis *xaxe = null->GetXaxis();
1299 TAxis *yaxe = null->GetYaxis();
1300 xaxe->CenterTitle();
1301 yaxe->CenterTitle();
1302 xaxe->SetTitleSize(0.07);
1303 yaxe->SetTitleSize(0.07);
1304 xaxe->SetTitleOffset(0.7);
1305 yaxe->SetTitleOffset(0.55);
1306 xaxe->SetLabelSize(0.06);
1307 yaxe->SetLabelSize(0.06);
1308 xaxe->SetTitle(hist->GetXaxis()->GetTitle());
1309 yaxe->SetTitle(hist->GetYaxis()->GetTitle());
1310
1311 null->Draw();
1312 hist->Draw("same");
1313
1314 gStyle->SetOptFit();
1315
1316 TF1 *fit = pix.GetFGausFit();
1317
1318 if (fit)
1319 {
1320 switch ( fColor )
1321 {
1322 case MCalibrationCam::kGREEN:
1323 fit->SetLineColor(kGreen);
1324 break;
1325 case MCalibrationCam::kBLUE:
1326 fit->SetLineColor(kBlue);
1327 break;
1328 case MCalibrationCam::kUV:
1329 fit->SetLineColor(106);
1330 break;
1331 case MCalibrationCam::kCT1:
1332 fit->SetLineColor(006);
1333 break;
1334 default:
1335 fit->SetLineColor(kRed);
1336 }
1337 fit->Draw("same");
1338 }
1339
1340 DisplayRefLines(null,refline);
1341
1342 newpad->cd(2);
1343 gPad->SetTicks();
1344
1345 TH1F *null2 = new TH1F("Null2",hist->GetTitle(),100,0.,pix.GetEvents()->GetSize()/pix.GetEventFrequency());
1346
1347 null2->SetMinimum(pix.GetMean()-10.*pix.GetSigma());
1348 null2->SetMaximum(pix.GetMean()+10.*pix.GetSigma());
1349 null2->SetDirectory(NULL);
1350 null2->SetBit(kCanDelete);
1351 null2->SetStats(kFALSE);
1352 //
1353 // set the labels bigger
1354 //
1355 TAxis *xaxe2 = null2->GetXaxis();
1356 TAxis *yaxe2 = null2->GetYaxis();
1357 xaxe2->CenterTitle();
1358 yaxe2->CenterTitle();
1359 xaxe2->SetTitleSize(0.07);
1360 yaxe2->SetTitleSize(0.07);
1361 xaxe2->SetTitleOffset(0.7);
1362 yaxe2->SetTitleOffset(0.55);
1363 xaxe2->SetLabelSize(0.06);
1364 yaxe2->SetLabelSize(0.06);
1365
1366 pix.CreateGraphEvents();
1367 TGraph *gr = pix.GetGraphEvents();
1368 if (gr)
1369 {
1370 xaxe2->SetTitle(gr->GetXaxis()->GetTitle());
1371 yaxe2->SetTitle(gr->GetYaxis()->GetTitle());
1372 }
1373
1374 null2->Draw();
1375
1376 pix.DrawEvents("same");
1377
1378 // newpad->cd(3);
1379 // pix.DrawPowerSpectrum(*newpad,4);
1380
1381 return;
1382
1383}
1384
1385
1386void MHCalibrationChargeCam::DisplayRefLines(const TH1F *hist, const Float_t refline) const
1387{
1388
1389 TGraph *uv10 = new TGraph(2);
1390 uv10->SetPoint(0,refline,0.);
1391 uv10->SetPoint(1,refline,hist->GetMaximum());
1392 uv10->SetBit(kCanDelete);
1393 uv10->SetLineColor(106);
1394 uv10->SetLineStyle(2);
1395 uv10->SetLineWidth(3);
1396 uv10->Draw("L");
1397
1398 TLegend *leg = new TLegend(0.8,0.55,0.99,0.99);
1399 leg->SetBit(kCanDelete);
1400 leg->AddEntry(uv10,"10 Leds UV","l");
1401
1402 leg->Draw();
1403}
1404
1405Int_t MHCalibrationChargeCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
1406{
1407
1408 Bool_t rc = kFALSE;
1409
1410 if (MHCalibrationCam::ReadEnv(env,prefix,print))
1411 rc = kTRUE;
1412
1413 if (IsEnvDefined(env, prefix, "HiGainNbins", print))
1414 {
1415 SetNbins(GetEnvValue(env, prefix, "HiGainNbins", fNbins));
1416 rc = kTRUE;
1417 }
1418
1419 if (IsEnvDefined(env, prefix, "HiGainFirst", print))
1420 {
1421 SetFirst(GetEnvValue(env, prefix, "HiGainFirst", fFirst));
1422 rc = kTRUE;
1423 }
1424
1425 if (IsEnvDefined(env, prefix, "HiGainLast", print))
1426 {
1427 SetLast(GetEnvValue(env, prefix, "HiGainLast", fLast));
1428 rc = kTRUE;
1429 }
1430
1431 if (IsEnvDefined(env, prefix, "LoGainNbins", print))
1432 {
1433 SetLoGainNbins(GetEnvValue(env, prefix, "LoGainNbins", fLoGainNbins));
1434 rc = kTRUE;
1435 }
1436
1437 if (IsEnvDefined(env, prefix, "LoGainFirst", print))
1438 {
1439 SetLoGainFirst(GetEnvValue(env, prefix, "LoGainFirst", fLoGainFirst));
1440 rc = kTRUE;
1441 }
1442
1443 if (IsEnvDefined(env, prefix, "LoGainLast", print))
1444 {
1445 SetLoGainLast(GetEnvValue(env, prefix, "LoGainLast", fLoGainLast));
1446 rc = kTRUE;
1447 }
1448
1449 if (IsEnvDefined(env, prefix, "TimeLowerLimit", print))
1450 {
1451 SetTimeLowerLimit(GetEnvValue(env, prefix, "TimeLowerLimit", fTimeLowerLimit));
1452 rc = kTRUE;
1453 }
1454
1455 if (IsEnvDefined(env, prefix, "TimeUpperLimit", print))
1456 {
1457 SetTimeUpperLimit(GetEnvValue(env, prefix, "TimeUpperLimit", fTimeUpperLimit));
1458 rc = kTRUE;
1459 }
1460
1461 if (IsEnvDefined(env, prefix, "ReferenceFile", print))
1462 {
1463 SetReferenceFile(GetEnvValue(env,prefix,"ReferenceFile",fReferenceFile.Data()));
1464 rc = kTRUE;
1465 }
1466
1467 if (IsEnvDefined(env, prefix, "NumHiGainSaturationLimit", print))
1468 {
1469 SetNumHiGainSaturationLimit(GetEnvValue(env, prefix, "NumHiGainSaturationLimit", fNumHiGainSaturationLimit));
1470 rc = kTRUE;
1471 }
1472
1473 if (IsEnvDefined(env, prefix, "NumLoGainSaturationLimit", print))
1474 {
1475 SetNumLoGainSaturationLimit(GetEnvValue(env, prefix, "NumLoGainSaturationLimit", fNumLoGainSaturationLimit));
1476 rc = kTRUE;
1477 }
1478
1479 if (IsEnvDefined(env, prefix, "NumLoGainBlackoutLimit", print))
1480 {
1481 SetNumLoGainBlackoutLimit(GetEnvValue(env, prefix, "NumLoGainBlackoutLimit", fNumLoGainBlackoutLimit));
1482 rc = kTRUE;
1483 }
1484
1485
1486 TEnv refenv(fReferenceFile);
1487
1488 fInnerRefCharge = refenv.GetValue("InnerRefCharge",fInnerRefCharge);
1489 fOuterRefCharge = refenv.GetValue("OuterRefCharge",fOuterRefCharge);
1490
1491 return rc;
1492}
Note: See TracBrowser for help on using the repository browser.