source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc@ 4858

Last change on this file since 4858 was 4583, checked in by gaug, 20 years ago
*** empty log message ***
File size: 12.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//
27// MHCalibrationChargePINDiode
28//
29// Histogram class for the charge calibration of the PIN Diode.
30// Stores and fits the charges, the RMS of the charges and stores the
31// location of the maximum FADC slice. Charges are taken from MExtractedSignalPINDiode.
32//
33//////////////////////////////////////////////////////////////////////////////
34#include "MHCalibrationChargePINDiode.h"
35
36#include <TH1.h>
37#include <TF1.h>
38#include <TPad.h>
39#include <TVirtualPad.h>
40#include <TCanvas.h>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MParList.h"
46
47#include "MExtractedSignalPINDiode.h"
48#include "MCalibrationChargePINDiode.h"
49
50ClassImp(MHCalibrationChargePINDiode);
51
52using namespace std;
53
54const Axis_t MHCalibrationChargePINDiode::fgAbsTimeFirst = -0.5;
55const Axis_t MHCalibrationChargePINDiode::fgAbsTimeLast = 29.5;
56const Int_t MHCalibrationChargePINDiode::fgAbsTimeNbins = 30;
57const Axis_t MHCalibrationChargePINDiode::fgChargeFirst = -0.5;
58const Axis_t MHCalibrationChargePINDiode::fgChargeLast = 1999.5;
59const Int_t MHCalibrationChargePINDiode::fgChargeNbins = 2000;
60const Int_t MHCalibrationChargePINDiode::fgRmsChargeNbins = 200;
61const Axis_t MHCalibrationChargePINDiode::fgRmsChargeFirst = 0.;
62const Axis_t MHCalibrationChargePINDiode::fgRmsChargeLast = 200.;
63const Float_t MHCalibrationChargePINDiode::fgTimeLowerLimit = 3.;
64const Float_t MHCalibrationChargePINDiode::fgTimeUpperLimit = 4.;
65// --------------------------------------------------------------------------
66//
67// Default Constructor.
68//
69// Sets:
70// - the default number for fAbsTimeFirst (fgAbsTimeFirst)
71// - the default number for fAbsTimeLast (fgAbsTimeLast)
72// - the default number for fAbsTimeNbins (fgAbsTimeNbins)
73// - the default number for MHGausEvents::fNbins (fgChargeNbins)
74// - the default number for MHGausEvents::fFirst (fgChargeFirst)
75// - the default number for MHGausEvents::fLast (fgChargeLast)
76// - the default number for fRmsChargeNbins (fgRmsChargeNbins)
77// - the default number for fRmsChargeFirst (fgRmsChargeFirst)
78// - the default number for fRmsChargeLast (fgRmsChargeLast)
79// - the default number for fTimeLowerLimit (fgTimeLowerLimit)
80// - the default number for fTimeUpperLimit (fgTimeUpperLimit)
81//
82// - the default name of the fHGausHist ("HCalibrationChargePINDiode")
83// - the default title of the fHGausHist ("Distribution of Summed FADC slices PIN Diode")
84// - the default x-axis title for fHGausHist ("Sum FADC Slices")
85// - the default y-axis title for fHGausHist ("Nr. of events")
86// - the default name of the fHAbsTime ("HAbsTimePINDiode")
87// - the default title of the fHAbsTime ("Distribution of Absolute Arrival Times PIN Diode")
88// - the default x-axis title for fHAbsTime ("Absolute Arrival Time [FADC slice nr]")
89// - the default y-axis title for fHAbsTime ("Nr. of events")
90// - the default name of the fHRmsCharge ("HRmsChargePINDiode")
91// - the default title of the fHRmsCharge ("Distribution of Variances of summed FADC slices PIN Diode")
92// - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
93// - the default y-axis title for fHRmsCharge ("Nr. of events")
94// - the default directory of the fHRmsCharge (NULL)
95// - the current style for fHRmsCharge (NULL)
96//
97// Initializes:
98// - fHRmsCharge()
99// - all pointers to NULL
100//
101// Calls:
102// - Clear()
103//
104MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
105 : fPINDiode(NULL), fSigPIN(NULL), fHRmsCharge()
106{
107
108 fName = name ? name : "MHCalibrationChargePINDiode";
109 fTitle = title ? title : "Fill the FADC sums of the PINDiode events and perform the fits";
110
111 SetAbsTimeFirst();
112 SetAbsTimeLast();
113 SetAbsTimeNbins();
114
115 SetNbins( fgChargeNbins );
116 SetFirst( fgChargeFirst );
117 SetLast ( fgChargeLast );
118
119 SetRmsChargeNbins();
120 SetRmsChargeFirst();
121 SetRmsChargeLast();
122
123 SetTimeLowerLimit();
124 SetTimeUpperLimit();
125
126 fHGausHist.SetName("HCalibrationChargePINDiode");
127 fHGausHist.SetTitle("Distribution of Summed FADC slices PIN Diode");
128 fHGausHist.SetXTitle("Sum FADC Slices");
129 fHGausHist.SetYTitle("Nr. of events");
130
131 fHAbsTime.SetName("HAbsTimePINDiode");
132 fHAbsTime.SetTitle("Distribution of Absolute Arrival Times PIN Diode");
133 fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
134 fHAbsTime.SetYTitle("Nr. of events");
135
136 fHRmsCharge.SetName("HRmsChargePINDiode");
137 fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");
138 fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
139 fHRmsCharge.SetYTitle("Nr. of events");
140 fHRmsCharge.UseCurrentStyle();
141 fHRmsCharge.SetDirectory(NULL);
142
143 Clear();
144}
145
146// --------------------------------------------------------------------------
147//
148// Initializes Binning of the following histograms:
149// - fHGausHist.SetBins(fNbins,fFirst,fLast);
150// - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
151// - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
152//
153Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList)
154{
155
156 MHGausEvents::InitBins();
157
158 fHAbsTime. SetBins(fAbsTimeNbins, fAbsTimeFirst, fAbsTimeLast);
159 fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
160
161 return kTRUE;
162
163}
164
165// --------------------------------------------------------------------------
166//
167// Gets or creates the pointers to:
168// - MExtractedSignalPINDiode
169// - MCalibrationChargePINDiode
170//
171Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
172{
173
174 fSigPIN = (MExtractedSignalPINDiode*)pList->FindCreateObj("MExtractedSignalPINDiode");
175 if (!fSigPIN)
176 {
177 *fLog << err << "MExtractedSignalPINDiode not found... aborting " << endl;
178 return kFALSE;
179 }
180
181 fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
182 if (!fPINDiode)
183 {
184 *fLog << err << "MCalibrationChargePINDiode not found... aborting " << endl;
185 return kFALSE;
186 }
187
188 return kTRUE;
189}
190
191// --------------------------------------------------------------------------
192//
193// Retrieves from MExtractedSignalPINDiode:
194// - Number of used FADC samples via MExtractedSignalPINDiode::GetNumFADCSamples()
195// - Extracted signal via MExtractedSignalPINDiode::GetExtractedSignal()
196// - Signal Rms MExtractedSignalPINDiode::GetExtractedRms()
197// - Arrival Time MExtractedSignalPINDiode::GetExtractedTime()
198//
199// Fills the following histograms:
200// - MHGausEvents::FillHistAndArray(signal)
201// - MHCalibrationChargePix::FillAbsTime(time);
202// - FillRmsCharge(rms);
203//
204Bool_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
205{
206
207 MExtractedSignalPINDiode *extractor = (MExtractedSignalPINDiode*)par;
208
209 if (!extractor)
210 {
211 *fLog << err << "No argument in MExtractedSignalPINDiode::Fill... abort." << endl;
212 return kFALSE;
213 }
214
215 Float_t slices = (Float_t)extractor->GetNumFADCSamples();
216
217 if (slices == 0.)
218 {
219 *fLog << err << "Number of used signal slices in MExtractedSignalPINDiode is zero ... abort."
220 << endl;
221 return kFALSE;
222 }
223
224 const Float_t signal = (float)extractor->GetExtractedSignal();
225 const Float_t time = extractor->GetExtractedTime();
226 const Float_t rms = extractor->GetExtractedRms();
227
228 FillHistAndArray(signal);
229 FillAbsTime(time);
230 FillRmsCharge(rms);
231
232 return kTRUE;
233}
234
235// --------------------------------------------------------------------------
236//
237// Returns kTRUE, if empty
238//
239// Performs the following fits:
240// - MHGausEvents::FitGaus()
241// - FitRmsCharge()
242//
243// Creates the fourier spectrum (MHGausEvents::CreateFourierSpectrum()
244// and sets bit MCalibrationChargePINDiode::SetOscillating( MHGausEvents::IsFourierSpectrumOK() )
245// Retrieves the results of the following fits and stores them in MCalibrationChargePINDiode:
246// - Mean Charge and Error
247// - Sigma Charge and Error
248// - Fit Probability
249// - Abs Time Mean
250// - Abs Time Rms
251// - Rms Charge Mean and Error
252// - Rms Charge Sigma and Error
253//
254// Performs one consistency check on the arrival time:
255// The check returns kFALSE if:
256//
257// -The mean arrival time is in fTimeLowerLimit slices from the lower edge
258// and fUpperLimit slices from the upper edge
259//
260Bool_t MHCalibrationChargePINDiode::Finalize()
261{
262
263 if (IsGausFitOK() || IsEmpty())
264 return kTRUE;
265
266 FitGaus();
267 FitRmsCharge();
268
269 CreateFourierSpectrum();
270 fPINDiode->SetOscillating ( !IsFourierSpectrumOK() );
271
272 fPINDiode->SetMean ( fMean );
273 fPINDiode->SetMeanVar ( fMeanErr * fMeanErr );
274 fPINDiode->SetSigma ( fSigma );
275 fPINDiode->SetSigmaVar ( fSigmaErr * fMeanErr );
276 fPINDiode->SetProb ( fProb );
277
278 fPINDiode->SetAbsTimeMean( GetAbsTimeMean() );
279 fPINDiode->SetAbsTimeRms( GetAbsTimeRms() );
280
281 fPINDiode->SetRmsChargeMean( GetRmsChargeMean() );
282 fPINDiode->SetRmsChargeMeanErr( GetRmsChargeMeanErr() );
283 fPINDiode->SetRmsChargeSigma( GetRmsChargeSigma() );
284 fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr() );
285
286 fPINDiode->SetValid(kTRUE);
287
288 const Byte_t loweredge = fSigPIN->GetFirstUsedSlice();
289 const Byte_t upperedge = fSigPIN->GetLastUsedSlice();
290 const Float_t lowerlimit = (Float_t)loweredge + fTimeLowerLimit;
291 const Float_t upperlimit = (Float_t)upperedge + fTimeUpperLimit;
292
293 if (GetAbsTimeMean() < lowerlimit)
294 {
295 *fLog << warn << GetDescriptor()
296 << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," smaller than ",
297 lowerlimit," FADC slices from lower edge in PIN Diode") << endl;
298 *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
299 fPINDiode->SetValid(kFALSE);
300 }
301
302 if ( GetAbsTimeMean() > upperlimit )
303 {
304 *fLog << warn << GetDescriptor()
305 << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," bigger than ",
306 upperlimit," FADC slices from upper edge in PIN Diode") << endl;
307 *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
308 fPINDiode->SetValid(kFALSE);
309 }
310
311 return kTRUE;
312}
313
314// --------------------------------------------------------------------------
315//
316// Fills fHRmsCharge with q
317// Returns kFALSE, if overflow or underflow occurred, else kTRUE
318//
319Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
320{
321 return fHRmsCharge.Fill(q) > -1;
322}
323
324// -----------------------------------------------------------
325//
326// Fits -- not yet implemented
327//
328Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
329{
330 return 1;
331}
332
333
334// -------------------------------------------------------------------------
335//
336// Draw the histogram
337//
338// The following options can be chosen:
339//
340// "": displays the fHGausHist with fits and fHRmsCharge
341// "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
342//
343void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
344{
345
346 TString option(opt);
347 option.ToLower();
348
349 Int_t win = 1;
350
351 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
352 TVirtualPad *pad = NULL;
353
354 oldpad->SetBorderMode(0);
355
356 if (option.Contains("all"))
357 {
358 option.ReplaceAll("all","");
359 oldpad->Divide(2,1);
360 win = 2;
361 oldpad->cd(1);
362 TVirtualPad *newpad = gPad;
363 pad = newpad;
364 pad->Divide(1,2);
365 pad->cd(1);
366 }
367 else
368 {
369 pad = oldpad;
370 pad->Divide(1,2);
371 pad->cd(1);
372 }
373
374 if (IsEmpty())
375 return;
376
377 if (!IsOnlyOverflow())
378 gPad->SetLogy();
379
380 gPad->SetTicks();
381
382 fHGausHist.Draw(opt);
383 if (fFGausFit)
384 {
385 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
386 fFGausFit->Draw("same");
387 }
388
389 pad->cd(2);
390 fHRmsCharge.Draw(opt);
391
392 oldpad->cd(2);
393 MHGausEvents::Draw("fourierevents");
394}
395
396
397
398
Note: See TracBrowser for help on using the repository browser.