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

Last change on this file since 6329 was 5098, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 13.8 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// Default Constructor.
76//
77// Sets:
78// - the default number for fAbsTimeFirst (fgAbsTimeFirst)
79// - the default number for fAbsTimeLast (fgAbsTimeLast)
80// - the default number for fAbsTimeNbins (fgAbsTimeNbins)
81// - the default number for MHGausEvents::fNbins (fgChargeNbins)
82// - the default number for MHGausEvents::fFirst (fgChargeFirst)
83// - the default number for MHGausEvents::fLast (fgChargeLast)
84// - the default number for fRmsChargeNbins (fgRmsChargeNbins)
85// - the default number for fRmsChargeFirst (fgRmsChargeFirst)
86// - the default number for fRmsChargeLast (fgRmsChargeLast)
87// - the default number for fTimeLowerLimit (fgTimeLowerLimit)
88// - the default number for fTimeUpperLimit (fgTimeUpperLimit)
89//
90// - the default name of the fHGausHist ("HCalibrationChargePINDiode")
91// - the default title of the fHGausHist ("Distribution of Summed FADC slices PIN Diode")
92// - the default x-axis title for fHGausHist ("Sum FADC Slices")
93// - the default y-axis title for fHGausHist ("Nr. of events")
94// - the default name of the fHAbsTime ("HAbsTimePINDiode")
95// - the default title of the fHAbsTime ("Distribution of Absolute Arrival Times PIN Diode")
96// - the default x-axis title for fHAbsTime ("Absolute Arrival Time [FADC slice nr]")
97// - the default y-axis title for fHAbsTime ("Nr. of events")
98// - the default name of the fHRmsCharge ("HRmsChargePINDiode")
99// - the default title of the fHRmsCharge ("Distribution of Variances of summed FADC slices PIN Diode")
100// - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
101// - the default y-axis title for fHRmsCharge ("Nr. of events")
102// - the default directory of the fHRmsCharge (NULL)
103// - the current style for fHRmsCharge (NULL)
104//
105// - fHistName to gsHistName
106// - fHistTitle to gsHistTitle
107// - fHistXTitle to gsHistXTitle
108// - fHistYTitle to gsHistYTitle
109//
110// - fAbsHistName to gsAbsHistName
111// - fAbsHistTitle to gsAbsHistTitle
112// - fAbsHistXTitle to gsAbsHistXTitle
113// - fAbsHistYTitle to gsAbsHistYTitle
114//
115// Initializes:
116// - fHRmsCharge()
117// - all pointers to NULL
118//
119// Calls:
120// - Clear()
121//
122MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
123 : fPINDiode(NULL), fSigPIN(NULL), fHRmsCharge()
124{
125
126 fName = name ? name : "MHCalibrationChargePINDiode";
127 fTitle = title ? title : "Fill the FADC sums of the PINDiode events and perform the fits";
128
129 SetAbsTimeFirst();
130 SetAbsTimeLast();
131 SetAbsTimeNbins();
132
133 SetNbins( fgChargeNbins );
134 SetFirst( fgChargeFirst );
135 SetLast ( fgChargeLast );
136
137 SetRmsChargeNbins();
138 SetRmsChargeFirst();
139 SetRmsChargeLast();
140
141 SetTimeLowerLimit();
142 SetTimeUpperLimit();
143
144 SetHistName (gsHistName .Data());
145 SetHistTitle (gsHistTitle .Data());
146 SetHistXTitle(gsHistXTitle.Data());
147 SetHistYTitle(gsHistYTitle.Data());
148
149 SetAbsHistName (gsAbsHistName .Data());
150 SetAbsHistTitle (gsAbsHistTitle .Data());
151 SetAbsHistXTitle(gsAbsHistXTitle.Data());
152 SetAbsHistYTitle(gsAbsHistYTitle.Data());
153
154 fHRmsCharge.SetName("HRmsChargePINDiode");
155 fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");
156 fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
157 fHRmsCharge.SetYTitle("Nr. of events");
158 fHRmsCharge.UseCurrentStyle();
159 fHRmsCharge.SetDirectory(NULL);
160
161 Clear();
162}
163
164// --------------------------------------------------------------------------
165//
166// Initializes Binning of the following histograms:
167// - fHGausHist.SetBins(fNbins,fFirst,fLast);
168// - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
169// - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
170//
171Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList)
172{
173
174 TH1F *h = GetHGausHist();
175
176 h->SetName (fHistName.Data());
177 h->SetTitle(fHistTitle.Data());
178 h->SetXTitle(fHistXTitle.Data());
179 h->SetYTitle(fHistYTitle.Data());
180
181 h = GetHAbsTime();
182
183 h->SetName (fAbsHistName.Data());
184 h->SetTitle(fAbsHistTitle.Data());
185 h->SetXTitle(fAbsHistXTitle.Data());
186 h->SetYTitle(fAbsHistYTitle.Data());
187
188 MHCalibrationPix::InitBins();
189
190 fHAbsTime. SetBins(fAbsTimeNbins, fAbsTimeFirst, fAbsTimeLast);
191 fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
192
193 return kTRUE;
194
195}
196
197// --------------------------------------------------------------------------
198//
199// Gets or creates the pointers to:
200// - MExtractedSignalPINDiode
201// - MCalibrationChargePINDiode
202//
203Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
204{
205
206 fSigPIN = (MExtractedSignalPINDiode*)pList->FindCreateObj("MExtractedSignalPINDiode");
207 if (!fSigPIN)
208 {
209 *fLog << err << "MExtractedSignalPINDiode not found... aborting " << endl;
210 return kFALSE;
211 }
212
213 fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
214 if (!fPINDiode)
215 {
216 *fLog << err << "MCalibrationChargePINDiode not found... aborting " << endl;
217 return kFALSE;
218 }
219
220 return kTRUE;
221}
222
223// --------------------------------------------------------------------------
224//
225// Retrieves from MExtractedSignalPINDiode:
226// - Number of used FADC samples via MExtractedSignalPINDiode::GetNumFADCSamples()
227// - Extracted signal via MExtractedSignalPINDiode::GetExtractedSignal()
228// - Signal Rms MExtractedSignalPINDiode::GetExtractedRms()
229// - Arrival Time MExtractedSignalPINDiode::GetExtractedTime()
230//
231// Fills the following histograms:
232// - MHGausEvents::FillHistAndArray(signal)
233// - MHCalibrationChargePix::FillAbsTime(time);
234// - FillRmsCharge(rms);
235//
236Bool_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
237{
238
239 MExtractedSignalPINDiode *extractor = (MExtractedSignalPINDiode*)par;
240
241 if (!extractor)
242 {
243 *fLog << err << "No argument in MExtractedSignalPINDiode::Fill... abort." << endl;
244 return kFALSE;
245 }
246
247 Float_t slices = (Float_t)extractor->GetNumFADCSamples();
248
249 if (slices == 0.)
250 {
251 *fLog << err << "Number of used signal slices in MExtractedSignalPINDiode is zero ... abort."
252 << endl;
253 return kFALSE;
254 }
255
256 const Float_t signal = (float)extractor->GetExtractedSignal();
257 const Float_t time = extractor->GetExtractedTime();
258 const Float_t rms = extractor->GetExtractedRms();
259
260 FillHistAndArray(signal);
261 FillAbsTime(time);
262 FillRmsCharge(rms);
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 CreateFourierSpectrum();
302 fPINDiode->SetOscillating ( !IsFourierSpectrumOK() );
303
304 fPINDiode->SetMean ( fMean );
305 fPINDiode->SetMeanVar ( fMeanErr * fMeanErr );
306 fPINDiode->SetSigma ( fSigma );
307 fPINDiode->SetSigmaVar ( fSigmaErr * fMeanErr );
308 fPINDiode->SetProb ( fProb );
309
310 fPINDiode->SetAbsTimeMean( GetAbsTimeMean() );
311 fPINDiode->SetAbsTimeRms( GetAbsTimeRms() );
312
313 fPINDiode->SetRmsChargeMean( GetRmsChargeMean() );
314 fPINDiode->SetRmsChargeMeanErr( GetRmsChargeMeanErr() );
315 fPINDiode->SetRmsChargeSigma( GetRmsChargeSigma() );
316 fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr() );
317
318 fPINDiode->SetValid(kTRUE);
319
320 const Byte_t loweredge = fSigPIN->GetFirstUsedSlice();
321 const Byte_t upperedge = fSigPIN->GetLastUsedSlice();
322 const Float_t lowerlimit = (Float_t)loweredge + fTimeLowerLimit;
323 const Float_t upperlimit = (Float_t)upperedge + fTimeUpperLimit;
324
325 if (GetAbsTimeMean() < lowerlimit)
326 {
327 *fLog << warn << GetDescriptor()
328 << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," smaller than ",
329 lowerlimit," FADC slices from lower edge in PIN Diode") << endl;
330 *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
331 fPINDiode->SetValid(kFALSE);
332 }
333
334 if ( GetAbsTimeMean() > upperlimit )
335 {
336 *fLog << warn << GetDescriptor()
337 << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," bigger than ",
338 upperlimit," FADC slices from upper edge in PIN Diode") << endl;
339 *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
340 fPINDiode->SetValid(kFALSE);
341 }
342
343 return kTRUE;
344}
345
346// --------------------------------------------------------------------------
347//
348// Fills fHRmsCharge with q
349// Returns kFALSE, if overflow or underflow occurred, else kTRUE
350//
351Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
352{
353 return fHRmsCharge.Fill(q) > -1;
354}
355
356// -----------------------------------------------------------
357//
358// Fits -- not yet implemented
359//
360Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
361{
362 return 1;
363}
364
365
366// -------------------------------------------------------------------------
367//
368// Draw the histogram
369//
370// The following options can be chosen:
371//
372// "": displays the fHGausHist with fits and fHRmsCharge
373// "all": executes additionally MHCalibrationPix::Draw(), with option "fourierevents"
374//
375void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
376{
377
378 TString option(opt);
379 option.ToLower();
380
381 Int_t win = 1;
382
383 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
384 TVirtualPad *pad = NULL;
385
386 oldpad->SetBorderMode(0);
387
388 if (option.Contains("all"))
389 {
390 option.ReplaceAll("all","");
391 oldpad->Divide(2,1);
392 win = 2;
393 oldpad->cd(1);
394 TVirtualPad *newpad = gPad;
395 pad = newpad;
396 pad->Divide(1,2);
397 pad->cd(1);
398 }
399 else
400 {
401 pad = oldpad;
402 pad->Divide(1,2);
403 pad->cd(1);
404 }
405
406 if (IsEmpty())
407 return;
408
409 if (!IsOnlyOverflow() && !IsOnlyUnderflow())
410 gPad->SetLogy();
411
412 gPad->SetTicks();
413
414 fHGausHist.Draw(opt);
415 if (fFGausFit)
416 {
417 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
418 fFGausFit->Draw("same");
419 }
420
421 pad->cd(2);
422 fHRmsCharge.Draw(opt);
423
424 oldpad->cd(2);
425 MHCalibrationPix::Draw("fourierevents");
426}
427
428
429
430
Note: See TracBrowser for help on using the repository browser.