source: trunk/Mars/mhcalib/MHCalibrationChargePINDiode.cc@ 16130

Last change on this file since 16130 was 12856, checked in by tbretz, 13 years ago
Commented out an unused variable for convenience.
File size: 12.7 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.;
65const TString MHCalibrationChargePINDiode::gsHistName = "Charge";
66const TString MHCalibrationChargePINDiode::gsHistTitle = "Signals";
67const TString MHCalibrationChargePINDiode::gsHistXTitle = "Signal [FADC counts]";
68const TString MHCalibrationChargePINDiode::gsHistYTitle = "Nr. events";
69const TString MHCalibrationChargePINDiode::gsAbsHistName = "AbsTime";
70const TString MHCalibrationChargePINDiode::gsAbsHistTitle = "Abs. Arr. Times";
71const TString MHCalibrationChargePINDiode::gsAbsHistXTitle = "Time [FADC slices]";
72const TString MHCalibrationChargePINDiode::gsAbsHistYTitle = "Nr. events";
73
74// --------------------------------------------------------------------------
75//
76// Default Constructor.
77//
78// Sets:
79// - the default number for fAbsTimeFirst (fgAbsTimeFirst)
80// - the default number for fAbsTimeLast (fgAbsTimeLast)
81// - the default number for fAbsTimeNbins (fgAbsTimeNbins)
82// - the default number for MHGausEvents::fNbins (fgChargeNbins)
83// - the default number for MHGausEvents::fFirst (fgChargeFirst)
84// - the default number for MHGausEvents::fLast (fgChargeLast)
85// - the default number for fRmsChargeNbins (fgRmsChargeNbins)
86// - the default number for fRmsChargeFirst (fgRmsChargeFirst)
87// - the default number for fRmsChargeLast (fgRmsChargeLast)
88// - the default number for fTimeLowerLimit (fgTimeLowerLimit)
89// - the default number for fTimeUpperLimit (fgTimeUpperLimit)
90//
91// - the default name of the fHGausHist ("HCalibrationChargePINDiode")
92// - the default title of the fHGausHist ("Distribution of Summed FADC slices PIN Diode")
93// - the default x-axis title for fHGausHist ("Sum FADC Slices")
94// - the default y-axis title for fHGausHist ("Nr. of events")
95// - the default name of the fHAbsTime ("HAbsTimePINDiode")
96// - the default title of the fHAbsTime ("Distribution of Absolute Arrival Times PIN Diode")
97// - the default x-axis title for fHAbsTime ("Absolute Arrival Time [FADC slice nr]")
98// - the default y-axis title for fHAbsTime ("Nr. of events")
99// - the default name of the fHRmsCharge ("HRmsChargePINDiode")
100// - the default title of the fHRmsCharge ("Distribution of Variances of summed FADC slices PIN Diode")
101// - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
102// - the default y-axis title for fHRmsCharge ("Nr. of events")
103// - the default directory of the fHRmsCharge (NULL)
104// - the current style for fHRmsCharge (NULL)
105//
106// - fHistName to gsHistName
107// - fHistTitle to gsHistTitle
108// - fHistXTitle to gsHistXTitle
109// - fHistYTitle to gsHistYTitle
110//
111// - fAbsHistName to gsAbsHistName
112// - fAbsHistTitle to gsAbsHistTitle
113// - fAbsHistXTitle to gsAbsHistXTitle
114// - fAbsHistYTitle to gsAbsHistYTitle
115//
116// Initializes:
117// - fHRmsCharge()
118// - all pointers to NULL
119//
120// Calls:
121// - Clear()
122//
123MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
124 : fPINDiode(NULL), fSigPIN(NULL), fHRmsCharge()
125{
126
127 fName = name ? name : "MHCalibrationChargePINDiode";
128 fTitle = title ? title : "Fill the FADC sums of the PINDiode events and perform the fits";
129
130 SetBinning(fgChargeNbins, fgChargeFirst, fgChargeLast);
131 SetBinningAbsTime(fgAbsTimeNbins, fgAbsTimeFirst, fgAbsTimeLast);
132 SetBinningRmsCharge(fgRmsChargeNbins, fgRmsChargeFirst, fgRmsChargeLast);
133
134 SetTimeLowerLimit();
135 SetTimeUpperLimit();
136
137 SetHistName (gsHistName .Data());
138 SetHistTitle (gsHistTitle .Data());
139 SetHistXTitle(gsHistXTitle.Data());
140 SetHistYTitle(gsHistYTitle.Data());
141
142 SetAbsHistName (gsAbsHistName .Data());
143 SetAbsHistTitle (gsAbsHistTitle .Data());
144 SetAbsHistXTitle(gsAbsHistXTitle.Data());
145 SetAbsHistYTitle(gsAbsHistYTitle.Data());
146
147 fHRmsCharge.SetName("HRmsChargePINDiode");
148 fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");
149 fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
150 fHRmsCharge.SetYTitle("Nr. of events");
151 fHRmsCharge.UseCurrentStyle();
152 fHRmsCharge.SetDirectory(NULL);
153
154 Clear();
155}
156
157// --------------------------------------------------------------------------
158//
159// Initializes Binning of the following histograms:
160// - fHGausHist.SetBins(fNbins,fFirst,fLast);
161// - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
162// - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
163//
164Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList)
165{
166
167 TH1F *h = GetHGausHist();
168
169 h->SetName (fHistName.Data());
170 h->SetTitle(fHistTitle.Data());
171 h->SetXTitle(fHistXTitle.Data());
172 h->SetYTitle(fHistYTitle.Data());
173
174 h = GetHAbsTime();
175
176 h->SetName (fAbsHistName.Data());
177 h->SetTitle(fAbsHistTitle.Data());
178 h->SetXTitle(fAbsHistXTitle.Data());
179 h->SetYTitle(fAbsHistYTitle.Data());
180
181 MHCalibrationPix::InitBins();
182
183 fHAbsTime. SetBins(fAbsTimeNbins, fAbsTimeFirst, fAbsTimeLast);
184 fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
185
186 fExclusionMean = 0;
187 fExclusionSigma = 0;
188 fExclusionChi2 = 0;
189
190 return kTRUE;
191
192}
193
194// --------------------------------------------------------------------------
195//
196// Gets or creates the pointers to:
197// - MExtractedSignalPINDiode
198// - MCalibrationChargePINDiode
199//
200Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
201{
202
203 fSigPIN = (MExtractedSignalPINDiode*)pList->FindCreateObj("MExtractedSignalPINDiode");
204 if (!fSigPIN)
205 return kFALSE;
206
207 fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
208 if (!fPINDiode)
209 return kFALSE;
210
211 return kTRUE;
212}
213
214// --------------------------------------------------------------------------
215//
216// Retrieves from MExtractedSignalPINDiode:
217// - Number of used FADC samples via MExtractedSignalPINDiode::GetNumFADCSamples()
218// - Extracted signal via MExtractedSignalPINDiode::GetExtractedSignal()
219// - Signal Rms MExtractedSignalPINDiode::GetExtractedRms()
220// - Arrival Time MExtractedSignalPINDiode::GetExtractedTime()
221//
222// Fills the following histograms:
223// - MHGausEvents::FillHistAndArray(signal)
224// - MHCalibrationChargePix::FillAbsTime(time);
225// - FillRmsCharge(rms);
226//
227Int_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
228{
229
230 const MExtractedSignalPINDiode *extractor = dynamic_cast<const MExtractedSignalPINDiode*>(par);
231 if (!extractor)
232 {
233 *fLog << err << "No argument in MExtractedSignalPINDiode::Fill... abort." << endl;
234 return kERROR;
235 }
236
237 const Float_t signal = (float)extractor->GetExtractedSignal();
238 const Float_t time = extractor->GetExtractedTime();
239 const Float_t sigma = extractor->GetExtractedSigma();
240 const Float_t chi2 = extractor->GetExtractedChi2();
241
242 if (time < 3. || time > 24.)
243 {
244 fExclusionMean++;
245 return kTRUE;
246 }
247
248 if (sigma < 5. || sigma > 18.)
249 {
250 fExclusionSigma++;
251 return kTRUE;
252 }
253
254 if (chi2 > 0.35)
255 {
256 fExclusionChi2++;
257 return kTRUE;
258 }
259
260 FillHistAndArray(signal);
261 FillAbsTime(time);
262 FillRmsCharge(sigma);
263
264 return kTRUE;
265}
266
267// --------------------------------------------------------------------------
268//
269// Returns kTRUE, if empty
270//
271// Performs the following fits:
272// - MHGausEvents::FitGaus()
273// - FitRmsCharge()
274//
275// Creates the fourier spectrum (MHGausEvents::CreateFourierSpectrum()
276// and sets bit MCalibrationChargePINDiode::SetOscillating( MHGausEvents::IsFourierSpectrumOK() )
277// Retrieves the results of the following fits and stores them in MCalibrationChargePINDiode:
278// - Mean Charge and Error
279// - Sigma Charge and Error
280// - Fit Probability
281// - Abs Time Mean
282// - Abs Time Rms
283// - Rms Charge Mean and Error
284// - Rms Charge Sigma and Error
285//
286// Performs one consistency check on the arrival time:
287// The check returns kFALSE if:
288//
289// -The mean arrival time is in fTimeLowerLimit slices from the lower edge
290// and fUpperLimit slices from the upper edge
291//
292Bool_t MHCalibrationChargePINDiode::Finalize()
293{
294
295 if (IsGausFitOK() || IsEmpty())
296 return kTRUE;
297
298 FitGaus();
299 FitRmsCharge();
300
301 fPINDiode->SetMean ( fMean );
302 fPINDiode->SetMeanVar ( fMeanErr * fMeanErr );
303 fPINDiode->SetSigma ( fSigma );
304 fPINDiode->SetSigmaVar ( fSigmaErr * fMeanErr );
305 fPINDiode->SetProb ( fProb );
306
307 fPINDiode->SetAbsTimeMean( GetAbsTimeMean() );
308 fPINDiode->SetAbsTimeRms( GetAbsTimeRms() );
309
310 fPINDiode->SetRmsChargeMean( GetRmsChargeMean() );
311 fPINDiode->SetRmsChargeMeanErr( GetRmsChargeMeanErr() );
312 fPINDiode->SetRmsChargeSigma( GetRmsChargeSigma() );
313 fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr() );
314
315 fPINDiode->SetValid(kTRUE);
316
317 return kTRUE;
318}
319
320// --------------------------------------------------------------------------
321//
322// Fills fHRmsCharge with q
323// Returns kFALSE, if overflow or underflow occurred, else kTRUE
324//
325Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
326{
327 return fHRmsCharge.Fill(q) > -1;
328}
329
330// -----------------------------------------------------------
331//
332// Fits -- not yet implemented
333//
334Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
335{
336 return 1;
337}
338
339
340// -------------------------------------------------------------------------
341//
342// Draw the histogram
343//
344// The following options can be chosen:
345//
346// "": displays the fHGausHist with fits and fHRmsCharge
347// "all": executes additionally MHCalibrationPix::Draw(), with option "fourierevents"
348//
349void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
350{
351
352 TString option(opt);
353 option.ToLower();
354
355// Int_t win = 1;
356
357 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
358 TVirtualPad *pad = NULL;
359
360 oldpad->SetBorderMode(0);
361
362 if (option.Contains("all"))
363 {
364 option.ReplaceAll("all","");
365 oldpad->Divide(2,1);
366// win = 2;
367 oldpad->cd(1);
368 TVirtualPad *newpad = gPad;
369 pad = newpad;
370 pad->Divide(1,2);
371 pad->cd(1);
372 }
373 else
374 {
375 pad = oldpad;
376 pad->Divide(1,2);
377 pad->cd(1);
378 }
379
380 if (IsEmpty())
381 return;
382
383 if (!IsOnlyOverflow() && !IsOnlyUnderflow())
384 gPad->SetLogy();
385
386 gPad->SetTicks();
387
388 fHGausHist.Draw(opt);
389 if (fFGausFit)
390 {
391 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
392 fFGausFit->Draw("same");
393 }
394
395 pad->cd(2);
396 fHRmsCharge.Draw(opt);
397
398 oldpad->cd(2);
399 MHCalibrationPix::Draw("fourierevents");
400}
401
402
403
404
Note: See TracBrowser for help on using the repository browser.