source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.cc@ 8422

Last change on this file since 8422 was 8417, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 33.1 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MHCalibrationHiLoCam.cc,v 1.21 2007-04-18 15:33:56 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHCalibrationHiLoCam
29//
30// Fills the extracted high-gain low-gain charge ratios of MArrivalTimeCam into
31// the MHCalibrationPix-classes MHCalibrationPix for every:
32//
33// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
34// or MHCalibrationCam::fHiGainArray, respectively, depending if
35// MArrivalTimePix::IsLoGainUsed() is set.
36//
37// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
38// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
39// MHCalibrationCam::fAverageHiGainAreas
40//
41// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
42// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
43// and MHCalibrationCam::fAverageHiGainSectors
44//
45// The histograms are fitted to a Gaussian, mean and sigma with its errors
46// and the fit probability are extracted. If none of these values are NaN's and
47// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
48// the fit is declared valid.
49// Otherwise, the fit is repeated within ranges of the previous mean
50// +- MHCalibrationPix::fPickupLimit (default: 5) sigma (see MHCalibrationPix::RepeatFit())
51// In case this does not make the fit valid, the histogram means and RMS's are
52// taken directly (see MHCalibrationPix::BypassFit()) and the following flags are set:
53// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiLoNotFitted ) and
54// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
55//
56// Outliers of more than MHCalibrationPix::fPickupLimit (default: 5) sigmas
57// from the mean are counted as Pickup events (stored in MHCalibrationPix::fPickup)
58//
59// The class also fills arrays with the signal vs. event number, creates a fourier
60// spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
61// projected fourier components follow an exponential distribution.
62// In case that the probability of the exponential fit is less than
63// MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
64// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiLoOscillating ) and
65// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
66//
67// This same procedure is performed for the average pixels.
68//
69// The following results are written into MCalibrationHiLoCam:
70//
71// - MCalibrationPix::SetMean()
72// - MCalibrationPix::SetMeanErr()
73// - MCalibrationPix::SetSigma()
74// - MCalibrationPix::SetSigmaErr()
75// - MCalibrationPix::SetProb()
76// - MCalibrationPix::SetNumPickup()
77//
78// For all averaged areas, the fitted sigma is multiplied with the square root of
79// the number involved pixels in order to be able to compare it to the average of
80// sigmas in the camera.
81//
82/////////////////////////////////////////////////////////////////////////////
83#include "MHCalibrationHiLoCam.h"
84
85#include <TOrdCollection.h>
86#include <TPad.h>
87#include <TVirtualPad.h>
88#include <TCanvas.h>
89#include <TStyle.h>
90#include <TF1.h>
91#include <TLine.h>
92#include <TLatex.h>
93#include <TLegend.h>
94#include <TGraph.h>
95#include <TProfile.h>
96
97#include "MHCalibrationHiLoPix.h"
98
99#include "MLog.h"
100#include "MLogManip.h"
101
102#include "MParList.h"
103
104#include "MCalibrationHiLoCam.h"
105#include "MCalibrationHiLoPix.h"
106#include "MCalibrationCam.h"
107#include "MCalibrationIntensityCam.h"
108#include "MCalibrationPix.h"
109
110#include "MExtractedSignalCam.h"
111#include "MExtractedSignalPix.h"
112#include "MArrivalTimeCam.h"
113#include "MArrivalTimePix.h"
114
115#include "MGeomCam.h"
116#include "MGeomPix.h"
117
118#include "MBadPixelsCam.h"
119#include "MBadPixelsPix.h"
120
121ClassImp(MHCalibrationHiLoCam);
122
123using namespace std;
124
125const Int_t MHCalibrationHiLoCam::fgNbins = 175;
126const Axis_t MHCalibrationHiLoCam::fgFirst = -5.1;
127const Axis_t MHCalibrationHiLoCam::fgLast = 29.9;
128const Float_t MHCalibrationHiLoCam::fgProbLimit = 0.;
129const Int_t MHCalibrationHiLoCam::fgHivsLoNbins = 90;
130const Axis_t MHCalibrationHiLoCam::fgHivsLoFirst = 95.;
131const Axis_t MHCalibrationHiLoCam::fgHivsLoLast = 995.;
132const Axis_t MHCalibrationHiLoCam::fgLowerFitLimitProfile = 480.;
133const Axis_t MHCalibrationHiLoCam::fgUpperFitLimitProfile = 680.;
134const TString MHCalibrationHiLoCam::gsHistName = "HiLo";
135const TString MHCalibrationHiLoCam::gsHistTitle = "HiGain vs. LoGain";
136const TString MHCalibrationHiLoCam::gsHistXTitle = "Amplification Ratio [1]";
137const TString MHCalibrationHiLoCam::gsHistYTitle = "Nr. events";
138const TString MHCalibrationHiLoCam::gsHivsLoHistName = "HivsLo";
139const TString MHCalibrationHiLoCam::gsHivsLoHistTitle = "High-gain vs. Low-gain Charge";
140const TString MHCalibrationHiLoCam::gsHivsLoHistXTitle = "Q High-Gain [FADC counts]";
141const TString MHCalibrationHiLoCam::gsHivsLoHistYTitle = "Q Low-Gain [FADC counts]";
142
143// --------------------------------------------------------------------------
144//
145// Default Constructor.
146//
147// Sets:
148// - fNbins to fgNbins
149// - fFirst to fgFirst
150// - fLast to fgLast
151//
152// - fHistName to gsHistName
153// - fHistTitle to gsHistTitle
154// - fHistXTitle to gsHistXTitle
155// - fHistYTitle to gsHistYTitle
156//
157// - fLowerLimt to fgLowerLim
158// - fUpperLimt to fgUpperLim
159//
160MHCalibrationHiLoCam::MHCalibrationHiLoCam(const char *name, const char *title)
161 : fArrTimes(NULL), fHivsLoResults("Results","Fit Results high-gain vs. low-gain",
162 200,-10.,10.,200,0.,20.),
163 fUsedLoGainSlices(0)
164{
165
166 fName = name ? name : "MHCalibrationHiLoCam";
167 fTitle = title ? title : "Histogram class for the high-gain vs. low-gain amplification ratio calibration";
168
169 SetNbins(fgNbins);
170 SetFirst(fgFirst);
171 SetLast (fgLast );
172
173 SetProbLimit(fgProbLimit);
174
175 SetHistName (gsHistName .Data());
176 SetHistTitle (gsHistTitle .Data());
177 SetHistXTitle(gsHistXTitle.Data());
178 SetHistYTitle(gsHistYTitle.Data());
179
180 SetHivsLoNbins(fgHivsLoNbins);
181 SetHivsLoFirst(fgHivsLoFirst);
182 SetHivsLoLast (fgHivsLoLast );
183
184 SetLowerFitLimitProfile();
185 SetUpperFitLimitProfile();
186
187 SetHivsLoHistName (gsHivsLoHistName .Data());
188 SetHivsLoHistTitle (gsHivsLoHistTitle .Data());
189 SetHivsLoHistXTitle(gsHivsLoHistXTitle.Data());
190 SetHivsLoHistYTitle(gsHivsLoHistYTitle.Data());
191
192 SetOscillations(kFALSE);
193
194 fHivsLoResults.GetXaxis()->SetTitle("Offset per FADC slices [FADC cnts]");
195 fHivsLoResults.GetYaxis()->SetTitle("Gains ratio [1]");
196 fHivsLoResults.SetDirectory(0);
197
198}
199
200// --------------------------------------------------------------------------
201//
202// Creates new MHCalibrationHiLoCam only with the averaged areas:
203// the rest has to be retrieved directly, e.g. via:
204// MHCalibrationHiLoCam *cam = MParList::FindObject("MHCalibrationHiLoCam");
205// - cam->GetAverageSector(5).DrawClone();
206// - (*cam)[100].DrawClone()
207//
208TObject *MHCalibrationHiLoCam::Clone(const char *) const
209{
210
211 MHCalibrationHiLoCam *cam = new MHCalibrationHiLoCam();
212
213 //
214 // Copy the data members
215 //
216 cam->fColor = fColor;
217 cam->fRunNumbers = fRunNumbers;
218 cam->fPulserFrequency = fPulserFrequency;
219 cam->fFlags = fFlags;
220 cam->fNbins = fNbins;
221 cam->fFirst = fFirst;
222 cam->fLast = fLast;
223
224 //
225 // Copy the MArrays
226 //
227 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
228 cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
229 cam->fAverageAreaSat = fAverageAreaSat;
230 cam->fAverageAreaSigma = fAverageAreaSigma;
231 cam->fAverageAreaSigmaVar = fAverageAreaSigmaVar;
232 cam->fAverageAreaNum = fAverageAreaNum;
233 cam->fAverageSectorNum = fAverageSectorNum;
234
235 if (!IsAverageing())
236 return cam;
237
238 const Int_t navhi = fAverageHiGainAreas->GetSize();
239 const Int_t navlo = fAverageLoGainAreas->GetSize();
240
241 for (int i=0; i<navhi; i++)
242 cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
243
244 for (int i=0; i<navlo; i++)
245 cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
246
247 return cam;
248}
249
250// --------------------------------------------------------------------------
251//
252// Gets or creates the pointers to:
253// - MCalibrationHiLoCam
254//
255// Searches pointer to:
256// - MExtractedSignalCam
257// - MArrivalTimeCam
258//
259// Calls:
260// - MHCalibrationCam::InitHiGainArrays()
261// - MHCalibrationCam::InitLoGainArrays()
262//
263// Sets:
264// - fSumarea to nareas
265// - fSumsector to nareas
266// - fNumarea to nareas
267// - fNumsector to nareas
268//
269Bool_t MHCalibrationHiLoCam::ReInitHists(MParList *pList)
270{
271
272 fCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationHiLoCam"));
273 if (!fCam)
274 {
275 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationHiLoCam"));
276 if (!fCam)
277 return kFALSE;
278 fCam->Init(*fGeom);
279 }
280
281 MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
282 if (!signal)
283 {
284 *fLog << err << "MExtractedSignalCam not found... abort." << endl;
285 return kFALSE;
286 }
287
288 fUsedLoGainSlices = signal->GetNumUsedLoGainFADCSlices();
289
290 fArrTimes = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
291 if (!fArrTimes)
292 {
293 *fLog << warn << "MArrivalTimeCam not found... cannot calibrated arrival times between "
294 <<"high and low-gain" << endl;
295 SetLoGain(kFALSE);
296 }
297
298 const Int_t npixels = fGeom->GetNumPixels();
299 const Int_t nsectors = fGeom->GetNumSectors();
300 const Int_t nareas = fGeom->GetNumAreas();
301
302 InitHiGainArrays(npixels,nareas,nsectors);
303 InitLoGainArrays(npixels,nareas,nsectors);
304
305 fSumareahi .Set(nareas);
306 fSumsectorhi.Set(nsectors);
307 fNumareahi .Set(nareas);
308 fNumsectorhi.Set(nsectors);
309 if (IsLoGain())
310 {
311 fSumarealo .Set(nareas);
312 fSumsectorlo.Set(nsectors);
313 fNumarealo .Set(nareas);
314 fNumsectorlo.Set(nsectors);
315 }
316 return kTRUE;
317}
318
319// --------------------------------------------------------------------------
320//
321// Retrieve:
322// - fRunHeader->GetNumSamplesHiGain();
323//
324// Initializes the High Gain Arrays:
325//
326// - For every entry in the expanded arrays:
327// * Initialize an MHCalibrationHiLoPix
328// * Set Binning from fNbins, fFirst and fLast
329// * Set Binning of Abs Times histogram from fAbsNbins, fAbsFirst and fAbsLast
330// * Set Histgram names and titles from fHistName and fHistTitle
331// * Set Abs Times Histgram names and titles from fAbsHistName and fAbsHistTitle
332// * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
333// * Set X-axis and Y-axis titles of Abs Times Histogram from fAbsHistXTitle and fAbsHistYTitle
334// * Call InitHists
335//
336//
337void MHCalibrationHiLoCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
338{
339
340 TProfile *h;
341
342 if (fHiGainArray->GetSize()==0)
343 {
344 for (Int_t i=0; i<npixels; i++)
345 {
346 fHiGainArray->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainPix%04d",fHistName.Data(),i),
347 Form("%s High Gain Pixel%04d",fHistTitle.Data(),i)),i);
348
349 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)(*this)[i];
350
351 pix.SetNbins(fNbins);
352 pix.SetFirst(fFirst);
353 pix.SetLast (fLast);
354
355 pix.SetProbLimit(fProbLimit);
356
357 pix.SetHivsLoNbins(fHivsLoNbins);
358 pix.SetHivsLoFirst(fHivsLoFirst);
359 pix.SetHivsLoLast (fHivsLoLast);
360
361 InitHists(pix,(*fBadPixels)[i],i);
362
363 if (fCam)
364 (*fCam)[i].SetPixId(i);
365
366 h = pix.GetHivsLo();
367
368 h->SetName (Form("H%sHiGainPix%04d",fHivsLoHistName.Data(),i));
369 h->SetTitle(Form("%s High Gain Pixel %04d",fHivsLoHistTitle.Data(),i));
370 h->SetXTitle(fHivsLoHistXTitle.Data());
371 h->SetYTitle(fHivsLoHistYTitle.Data());
372 h->SetDirectory(0);
373 }
374 }
375
376
377 if (fAverageHiGainAreas->GetSize()==0)
378 {
379 for (Int_t j=0; j<nareas; j++)
380 {
381 fAverageHiGainAreas->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainArea%d",fHistName.Data(),j),
382 Form("%s High Gain Area Idx %d",fHistTitle.Data(),j)),j);
383
384 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
385
386 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
387 pix.SetFirst(fFirst);
388 pix.SetLast (fLast);
389
390 pix.SetHivsLoNbins(fHivsLoNbins);
391 pix.SetHivsLoFirst(fHivsLoFirst);
392 pix.SetHivsLoLast (fHivsLoLast);
393
394 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
395
396 if (fCam)
397 fCam->GetAverageArea(j).SetPixId(j);
398
399 h = pix.GetHivsLo();
400
401 h->SetName (Form("H%sHiGainArea%d",fHivsLoHistName.Data(),j));
402 h->SetTitle(Form("%s averaged on event-by-event basis High Gain Area Idx %d",
403 fHivsLoHistTitle.Data(), j));
404 h->SetXTitle(fHivsLoHistXTitle.Data());
405 h->SetYTitle(fHivsLoHistYTitle.Data());
406 h->SetDirectory(0);
407 }
408 }
409
410 if (fAverageHiGainSectors->GetSize()==0)
411 {
412 for (Int_t j=0; j<nsectors; j++)
413 {
414 fAverageHiGainSectors->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainSector%02d",fHistName.Data(),j),
415 Form("%s High Gain Sector %02d",fHistTitle.Data(),j)),j);
416
417 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageHiGainSector(j);
418
419 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
420 pix.SetFirst(fFirst);
421 pix.SetLast (fLast);
422
423 pix.SetHivsLoNbins(fHivsLoNbins);
424 pix.SetHivsLoFirst(fHivsLoFirst);
425 pix.SetHivsLoLast (fHivsLoLast);
426
427 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
428
429 if (fCam)
430 fCam->GetAverageSector(j).SetPixId(j);
431
432 h = pix.GetHivsLo();
433
434 h->SetName (Form("H%sHiGainSector%02d",fHivsLoHistName.Data(),j));
435 h->SetTitle(Form("%s averaged on event-by-event basis High Gain Area Sector %02d",
436 fHivsLoHistTitle.Data(),j));
437 h->SetXTitle(fHivsLoHistXTitle.Data());
438 h->SetYTitle(fHivsLoHistYTitle.Data());
439 h->SetDirectory(0);
440 }
441 }
442}
443
444//--------------------------------------------------------------------------------------
445//
446// Return, if IsLoGain() is kFALSE
447//
448// Retrieve:
449// - fRunHeader->GetNumSamplesHiGain();
450//
451// Initializes the Low Gain Arrays:
452//
453// - For every entry in the expanded arrays:
454// * Initialize an MHCalibrationHiLoPix
455// * Set Binning from fNbins, fFirst and fLast
456// * Set Binning of HivsLo Times histogram from fHivsLoNbins, fHivsLoFirst and fHivsLoLast
457// * Set Histgram names and titles from fHistName and fHistTitle
458// * Set HivsLo Times Histgram names and titles from fHivsLoHistName and fHivsLoHistTitle
459// * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
460// * Set X-axis and Y-axis titles of HivsLo Times Histogram from fHivsLoHistXTitle and fHivsLoHistYTitle
461// * Call InitHists
462//
463void MHCalibrationHiLoCam::InitLoGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
464{
465 if (!IsLoGain())
466 return;
467
468 TProfile *h;
469
470 if (fLoGainArray->GetSize()==0 )
471 {
472 for (Int_t i=0; i<npixels; i++)
473 {
474 fLoGainArray->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainPix%04d",fHistName.Data(),i),
475 Form("%s Low Gain Pixel %04d",fHistTitle.Data(),i)),i);
476
477 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)(*this)(i);
478
479 pix.SetNbins(fNbins);
480 pix.SetFirst(fFirst);
481 pix.SetLast (fLast);
482
483 pix.SetProbLimit(fProbLimit);
484
485 pix.SetHivsLoNbins(fHivsLoNbins);
486 pix.SetHivsLoFirst(fHivsLoFirst);
487 pix.SetHivsLoLast (fHivsLoLast );
488
489 InitHists(pix,(*fBadPixels)[i],i);
490
491 h = pix.GetHivsLo();
492
493 h->SetName (Form("H%sLoGainPix%04d",fHivsLoHistName.Data(),i));
494 h->SetTitle(Form("%s Low Gain Pixel %04d",fHivsLoHistTitle.Data(),i));
495 h->SetXTitle(fHivsLoHistXTitle.Data());
496 h->SetYTitle(fHivsLoHistYTitle.Data());
497 h->SetDirectory(0);
498 }
499 }
500
501 if (fAverageLoGainAreas->GetSize()==0)
502 {
503 for (Int_t j=0; j<nareas; j++)
504 {
505 fAverageLoGainAreas->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainArea%d",fHistName.Data(),j),
506 Form("%s Low Gain Area Idx %d",fHistTitle.Data(),j)),j);
507
508 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageLoGainArea(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.SetHivsLoNbins(fHivsLoNbins);
515 pix.SetHivsLoFirst(fHivsLoFirst);
516 pix.SetHivsLoLast (fHivsLoLast );
517
518 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
519
520 h = pix.GetHivsLo();
521
522 h->SetName (Form("H%sLoGainArea%02d",fHivsLoHistName.Data(),j));
523 h->SetTitle(Form("%s%s%02d",fHivsLoHistTitle.Data(),
524 " averaged on event-by-event basis Low Gain Area Idx ",j));
525 h->SetXTitle(fHivsLoHistXTitle.Data());
526 h->SetYTitle(fHivsLoHistYTitle.Data());
527 h->SetDirectory(0);
528 }
529 }
530
531
532 if (fAverageLoGainSectors->GetSize()==0 && IsLoGain())
533 {
534 for (Int_t j=0; j<nsectors; j++)
535 {
536 fAverageLoGainSectors->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainSector%02d",fHistName.Data(),j),
537 Form("%s Low Gain Sector %02d",fHistTitle.Data(),j)),j);
538
539 MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageLoGainSector(j);
540
541 pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
542 pix.SetFirst(fFirst);
543 pix.SetLast (fLast);
544
545 pix.SetHivsLoNbins(fHivsLoNbins);
546 pix.SetHivsLoFirst(fHivsLoFirst);
547 pix.SetHivsLoLast (fHivsLoLast);
548
549 InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
550
551 h = pix.GetHivsLo();
552
553 h->SetName (Form("H%sLoGainSector%02d",fHivsLoHistName.Data(),j));
554 h->SetTitle(Form("%s%s%02d",fHivsLoHistTitle.Data(),
555 " averaged on event-by-event basis Low Gain Area Sector ",j));
556 h->SetXTitle(fHivsLoHistXTitle.Data());
557 h->SetYTitle(fHivsLoHistYTitle.Data());
558 h->SetDirectory(0);
559 }
560 }
561}
562
563
564
565// -------------------------------------------------------------------------------
566//
567// Retrieves pointer to MExtractedSignalCam:
568//
569// Retrieves from MGeomCam:
570// - number of pixels
571// - number of pixel areas
572// - number of sectors
573//
574// Fills histograms (MHGausEvents::FillHistAndArray()) with:
575// - MExtractedSignalPix::GetExtractedSignalHiGain(pixid) / MExtractedSignalPix::GetExtractedSignalLoGain;
576// if the high-gain signal does not show high-gain saturation, but the low-gain
577// has been extracted.
578// - MArrivalTimePix::GetArrivalTimeHiGain(pixid) / MArrivalTimePix::GetArrivalTimeLoGain;
579// if the high-gain signal does not show high-gain saturation, but the low-gain
580// has been extracted.
581//
582Bool_t MHCalibrationHiLoCam::FillHists(const MParContainer *par, const Stat_t w)
583{
584
585 MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
586 if (!signal)
587 {
588 gLog << err << "No argument in MExtractedSignal::Fill... abort." << endl;
589 return kFALSE;
590 }
591
592 const Int_t npixels = fGeom->GetNumPixels();
593 const Int_t nareas = fGeom->GetNumAreas();
594 const Int_t nsectors = fGeom->GetNumSectors();
595
596 fSumareahi .Reset();
597 fSumsectorhi.Reset();
598 fNumareahi .Reset();
599 fNumsectorhi.Reset();
600 fSumarealo .Reset();
601 fSumsectorlo.Reset();
602 fNumarealo .Reset();
603 fNumsectorlo.Reset();
604
605 for (Int_t i=0; i<npixels; i++)
606 {
607 const MExtractedSignalPix &pix = (*signal)[i];
608 const Int_t aidx = (*fGeom)[i].GetAidx();
609 const Int_t sector = (*fGeom)[i].GetSector();
610
611 const Float_t siglo = pix.GetExtractedSignalLoGain();
612
613 //
614 // Skip all pixels with:
615 // - Saturated high-gain
616 // - Not extracted low-gain
617 // (see MExtractTimeAndCharge::fLoGainSwitch for setting the criteria)
618 //
619 if (siglo < 0.5 || pix.IsHiGainSaturated())
620 continue;
621
622 const Float_t sighi = pix.GetExtractedSignalHiGain();
623
624 // *fLog << err << sighi << " " << siglo << endl;
625 const Float_t ratio = sighi / siglo;
626
627 MHCalibrationHiLoPix &histhi = (MHCalibrationHiLoPix&)(*this)[i];
628
629 histhi.FillHist(ratio);
630 histhi.FillHivsLo(sighi,siglo);
631
632 if (IsAverageing())
633 {
634 MHCalibrationHiLoPix &histhi2 = (MHCalibrationHiLoPix&)GetAverageHiGainArea(aidx);
635 histhi2.FillHivsLo(sighi,siglo);
636 }
637
638 fSumareahi [aidx] += ratio;
639 fNumareahi [aidx] ++;
640 fSumsectorhi[sector] += ratio;
641 fNumsectorhi[sector] ++;
642
643 if (IsLoGain())
644 {
645 const MArrivalTimePix &tix = (*fArrTimes)[i];
646 MHCalibrationPix &histlo = (*this)(i);
647
648 const Float_t diff = tix.GetArrivalTimeLoGain() - tix.GetArrivalTimeHiGain();
649
650 histlo.FillHist(diff);
651 fSumarealo [aidx] += diff;
652 fNumarealo [aidx] ++;
653 fSumsectorlo[sector] += diff;
654 fNumsectorlo[sector] ++;
655 }
656 }
657
658 if (!IsAverageing())
659 return kTRUE;
660
661 for (Int_t j=0; j<nareas; j++)
662 {
663
664 MHCalibrationHiLoPix &histhi = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
665
666 if (IsOscillations())
667 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
668 else
669 histhi.FillHist(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
670
671 if (IsLoGain())
672 {
673 MHCalibrationPix &histlo = GetAverageLoGainArea(j);
674 if (IsOscillations())
675 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
676 else
677 histlo.FillHist(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
678 }
679 }
680
681 for (Int_t j=0; j<nsectors; j++)
682 {
683 MHCalibrationPix &hist = GetAverageHiGainSector(j);
684
685 if (IsOscillations())
686 hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
687 else
688 hist.FillHist(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
689
690 if (IsLoGain())
691 {
692
693 MHCalibrationPix &histlo = GetAverageLoGainSector(j);
694
695 if (IsOscillations())
696 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
697 else
698 histlo.FillHist(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
699 }
700 }
701
702 return kTRUE;
703}
704
705// --------------------------------------------------------------------------
706//
707// Calls:
708// - MHCalibrationCam::FitHiGainArrays() with flags:
709// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
710// - MHCalibrationCam::FitLoGainArrays() with flags:
711// MBadPixelsPix::kHiLoNotFitted and MBadPixelsPix::kHiLoOscillating
712//
713Bool_t MHCalibrationHiLoCam::FinalizeHists()
714{
715
716 *fLog << endl;
717
718 MCalibrationCam *hilocam = fCam;
719
720 const Int_t nareas = fAverageHiGainAreas->GetSize();
721
722 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
723 {
724
725 MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)(*this)[i];
726
727 if (hist.IsExcluded())
728 continue;
729
730 CheckOverflow(hist);
731
732 TProfile *h = hist.GetHivsLo();
733 h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
734
735 TF1 *fit = h->GetFunction("pol1");
736
737 const Float_t gainr = fit->GetParameter(1) > 0.001
738 ? 1./fit->GetParameter(1) : 0.;
739
740 // The number of used slices are just a mean value
741 // the real number might change from event to event.
742 // (up to 50%!)
743 const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
744
745 fHivsLoResults.Fill(offset,gainr);
746
747 MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)(*fCam)[i];
748 pix.SetOffsetPerSlice(offset);
749 pix.SetGainRatio (gainr );
750
751 }
752
753 //
754 // Check histogram overflow
755 //
756 if (IsAverageing())
757 {
758 for (Int_t j=0; j<nareas; j++)
759 CheckOverflow(GetAverageHiGainArea(j));
760
761 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
762 CheckOverflow(GetAverageHiGainSector(j));
763 }
764
765
766 FitHiGainArrays(*hilocam, *fBadPixels,
767 MBadPixelsPix::kHiLoNotFitted,
768 MBadPixelsPix::kHiLoOscillating);
769
770 if (!IsLoGain())
771 return kTRUE;
772
773 for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
774 {
775
776 MHCalibrationPix &hist = (*this)(i);
777
778 if (hist.IsExcluded())
779 continue;
780
781 CheckOverflow(hist);
782 }
783
784 if (IsAverageing())
785 {
786 for (Int_t j=0; j<nareas; j++)
787 {
788
789 MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
790 //
791 // Check histogram overflow
792 //
793 CheckOverflow(hist);
794
795 TProfile *h = hist.GetHivsLo();
796 h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
797
798 TF1 *fit = h->GetFunction("pol1");
799
800 const Float_t gainr = fit->GetParameter(1) > 0.001
801 ? 1./fit->GetParameter(1) : 0.;
802
803 // The number of used slices are just a mean value
804 // the real number might change from event to event.
805 // (up to 50%!)
806 const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
807
808 MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)fCam->GetAverageArea(0);
809 pix.SetOffsetPerSlice(offset);
810 pix.SetGainRatio (gainr );
811
812 }
813
814 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
815 {
816
817 MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)GetAverageHiGainSector(j);
818 //
819 // Check histogram overflow
820 //
821 CheckOverflow(hist);
822
823 TProfile *h = hist.GetHivsLo();
824 h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
825
826 TF1 *fit = h->GetFunction("pol1");
827
828 const Float_t gainr = fit->GetParameter(1) > 0.001
829 ? 1./fit->GetParameter(1) : 0.;
830
831 // The number of used slices are just a mean value
832 // the real number might change from event to event.
833 // (up to 50%!)
834 const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
835
836 MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)fCam->GetAverageSector(0);
837 pix.SetOffsetPerSlice(offset);
838 pix.SetGainRatio (gainr );
839
840 }
841 }
842
843 FitLoGainArrays(*hilocam, *fBadPixels,
844 MBadPixelsPix::kHiLoNotFitted,
845 MBadPixelsPix::kHiLoOscillating);
846
847 return kTRUE;
848}
849
850// --------------------------------------------------------------------------
851//
852// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
853// - MBadPixelsPix::kHiLoNotFitted
854// - MBadPixelsPix::kHiLoOscillating
855//
856void MHCalibrationHiLoCam::FinalizeBadPixels()
857{
858
859 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
860 {
861 MBadPixelsPix &bad = (*fBadPixels)[i];
862
863 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoNotFitted ))
864 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
865
866 if (bad.IsUncalibrated( MBadPixelsPix::kHiLoOscillating))
867 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
868
869 }
870}
871
872// --------------------------------------------------------------------------
873//
874// The types are as follows:
875//
876// Fitted values:
877// ==============
878//
879// 0: Fitted Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMean()
880// 1: Error Mean High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetMeanErr()
881// 2: Sigma fitted High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigma()
882// 3: Error Sigma High-Gain Low-Gain Charge Ratio in FADC slices (MHGausEvents::GetSigmaErr()
883//
884// Useful variables derived from the fit results:
885// =============================================
886//
887// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
888//
889// Localized defects:
890// ==================
891//
892// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
893// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
894//
895Bool_t MHCalibrationHiLoCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
896{
897
898 if (fHiGainArray->GetSize() <= idx)
899 return kFALSE;
900
901 const MHCalibrationPix &pixhi = (*this)[idx];
902 const MHCalibrationPix &pixlo = (*this)(idx);
903
904 switch (type)
905 {
906 case 0:
907 val = pixhi.GetMean();
908 break;
909 case 1:
910 val = pixhi.GetMeanErr();
911 break;
912 case 2:
913 val = pixhi.GetSigma();
914 break;
915 case 3:
916 val = pixhi.GetSigmaErr();
917 break;
918 case 4:
919 val = pixhi.GetProb();
920 break;
921 case 5:
922 if (!pixhi.IsGausFitOK())
923 val = 1.;
924 break;
925 case 6:
926 if (!pixhi.IsFourierSpectrumOK())
927 val = 1.;
928 break;
929 case 7:
930 if (!IsLoGain())
931 break;
932 val = pixlo.GetMean();
933 break;
934 case 8:
935 if (!IsLoGain())
936 break;
937 val = pixlo.GetMeanErr();
938 break;
939 case 9:
940 if (!IsLoGain())
941 break;
942 val = pixlo.GetSigma();
943 break;
944 case 10:
945 if (!IsLoGain())
946 break;
947 val = pixlo.GetSigmaErr();
948 break;
949 case 11:
950 if (!IsLoGain())
951 break;
952 val = pixlo.GetProb();
953 break;
954 case 12:
955 if (!IsLoGain())
956 break;
957 if (!pixlo.IsGausFitOK())
958 val = 1.;
959 break;
960 case 13:
961 if (!IsLoGain())
962 break;
963 if (!pixlo.IsFourierSpectrumOK())
964 val = 1.;
965 break;
966 default:
967 return kFALSE;
968 }
969 return kTRUE;
970}
971
972// --------------------------------------------------------------------------
973//
974// Calls MHCalibrationPix::DrawClone() for pixel idx
975//
976void MHCalibrationHiLoCam::DrawPixelContent(Int_t idx) const
977{
978 (*this)[idx].DrawClone();
979}
980
981void MHCalibrationHiLoCam::CheckOverflow( MHCalibrationPix &pix )
982{
983
984 if (pix.IsExcluded())
985 return;
986
987 TH1F *hist = pix.GetHGausHist();
988
989 Stat_t overflow = hist->GetBinContent(hist->GetNbinsX()+1);
990 if (overflow > fOverflowLimit*hist->GetEntries())
991 {
992 *fLog << warn << "Hist-overflow " << overflow
993 << " times in " << pix.GetName() << endl;
994 }
995
996 overflow = hist->GetBinContent(0);
997 if (overflow > fOverflowLimit*hist->GetEntries())
998 {
999 *fLog << warn << "Hist-underflow " << overflow
1000 << " times in " << pix.GetName() << endl;
1001 }
1002}
1003
1004// -----------------------------------------------------------------------------
1005//
1006// Default draw:
1007//
1008// Displays the averaged areas, both amplification ratio as time difference
1009//
1010void MHCalibrationHiLoCam::Draw(const Option_t *opt)
1011{
1012
1013 if (!IsAverageing())
1014 return;
1015
1016 const Int_t nareas = fAverageHiGainAreas->GetSize();
1017 if (nareas == 0)
1018 return;
1019
1020 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
1021 pad->SetBorderMode(0);
1022
1023 pad->Divide(IsLoGain() ? 2 : 1,nareas);
1024
1025 for (Int_t i=0; i<nareas;i++)
1026 {
1027
1028 pad->cd(IsLoGain() ? 2*(i+1)-1 : i+1);
1029
1030 GetAverageHiGainArea(i).Draw(opt);
1031
1032 if (IsLoGain())
1033 {
1034 pad->cd(2*(i+1));
1035
1036 TH1F *hist = GetAverageLoGainArea(i).GetHGausHist();
1037 hist->SetXTitle("Extracted Time Difference [FADC sl.]");
1038 GetAverageLoGainArea(i).Draw(opt);
1039 }
1040 }
1041}
1042
1043Int_t MHCalibrationHiLoCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
1044{
1045
1046 Bool_t rc = kFALSE;
1047
1048 if (MHCalibrationCam::ReadEnv(env,prefix,print))
1049 rc = kTRUE;
1050
1051 if (IsEnvDefined(env, prefix, "LowerFitLimitProfile", print))
1052 {
1053 SetLowerFitLimitProfile(GetEnvValue(env, prefix, "LowerFitLimitProfile", fLowerFitLimitProfile));
1054 rc = kTRUE;
1055 }
1056
1057 if (IsEnvDefined(env, prefix, "UpperFitLimitProfile", print))
1058 {
1059 SetUpperFitLimitProfile(GetEnvValue(env, prefix, "UpperFitLimitProfile", fUpperFitLimitProfile));
1060 rc = kTRUE;
1061 }
1062
1063 if (IsEnvDefined(env, prefix, "HivsLoNbins", print))
1064 {
1065 SetHivsLoNbins(GetEnvValue(env, prefix, "HivsLoNbins", fHivsLoNbins));
1066 rc = kTRUE;
1067 }
1068
1069 if (IsEnvDefined(env, prefix, "HivsLoFirst", print))
1070 {
1071 SetHivsLoFirst(GetEnvValue(env, prefix, "HivsLoFirst", fHivsLoFirst));
1072 rc = kTRUE;
1073 }
1074
1075 if (IsEnvDefined(env, prefix, "HivsLoLast", print))
1076 {
1077 SetHivsLoLast(GetEnvValue(env, prefix, "HivsLoLast", fHivsLoLast));
1078 rc = kTRUE;
1079 }
1080
1081 return rc;
1082}
Note: See TracBrowser for help on using the repository browser.