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

Last change on this file since 3700 was 3696, checked in by gaug, 21 years ago
*** empty log message ***
File size: 12.3 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 = 199.5;
59const Int_t MHCalibrationChargePINDiode::fgChargeNbins = 200;
60const Int_t MHCalibrationChargePINDiode::fgRmsChargeNbins = 100;
61const Axis_t MHCalibrationChargePINDiode::fgRmsChargeFirst = 0.;
62const Axis_t MHCalibrationChargePINDiode::fgRmsChargeLast = 100.;
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 const Byte_t loweredge = fSigPIN->GetFirstUsedSlice();
287 const Byte_t upperedge = fSigPIN->GetLastUsedSlice();
288 const Float_t lowerlimit = (Float_t)loweredge + fTimeLowerLimit;
289 const Float_t upperlimit = (Float_t)upperedge + fTimeUpperLimit;
290
291 if (GetAbsTimeMean() < lowerlimit)
292 {
293 *fLog << warn << GetDescriptor() << ": Mean ArrivalTime in first " << fTimeLowerLimit
294 << " extraction bin in PIN Diode " << endl;
295 *fLog << GetAbsTimeMean() << " " << lowerlimit << endl;
296 return kFALSE;
297 }
298
299 if ( GetAbsTimeMean() > upperlimit )
300 {
301 *fLog << warn << GetDescriptor() << ": Mean ArrivalTime in last " << fTimeUpperLimit
302 << " two extraction bins in PIN Diode " << endl;
303 *fLog << GetAbsTimeMean() << " " << upperlimit << endl;
304 return kFALSE;
305 }
306
307 return kTRUE;
308}
309
310// --------------------------------------------------------------------------
311//
312// Fills fHRmsCharge with q
313// Returns kFALSE, if overflow or underflow occurred, else kTRUE
314//
315Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
316{
317 return fHRmsCharge.Fill(q) > -1;
318}
319
320// -----------------------------------------------------------
321//
322// Fits -- not yet implemented
323//
324Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
325{
326 return 1;
327}
328
329
330// -------------------------------------------------------------------------
331//
332// Draw the histogram
333//
334// The following options can be chosen:
335//
336// "": displays the fHGausHist with fits and fHRmsCharge
337// "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
338//
339void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
340{
341
342 TString option(opt);
343 option.ToLower();
344
345 Int_t win = 1;
346
347 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
348 TVirtualPad *pad = NULL;
349
350 oldpad->SetBorderMode(0);
351
352 if (option.Contains("all"))
353 {
354 option.ReplaceAll("all","");
355 oldpad->Divide(2,1);
356 win = 2;
357 oldpad->cd(1);
358 TVirtualPad *newpad = gPad;
359 pad = newpad;
360 pad->Divide(1,2);
361 pad->cd(1);
362 }
363 else
364 {
365 pad = oldpad;
366 pad->Divide(1,2);
367 pad->cd(1);
368 }
369
370 if (!IsEmpty())
371 gPad->SetLogy();
372
373 gPad->SetTicks();
374
375 fHGausHist.Draw(opt);
376 if (fFGausFit)
377 {
378 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
379 fFGausFit->Draw("same");
380 }
381
382 pad->cd(2);
383 fHRmsCharge.Draw(opt);
384
385 oldpad->cd(2);
386 MHGausEvents::Draw("fourierevents");
387}
388
389
390
391
Note: See TracBrowser for help on using the repository browser.