source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePINDiode.cc@ 7814

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