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

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