source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePix.cc@ 3551

Last change on this file since 3551 was 3551, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.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// MHCalibrationChargePix
27//
28// Histogram class for charge calibration analysis. Holds the histogrammed
29// summed FADC slices and some rough absolute timing. Calculates the mean
30// sum of FADC slices and its sigma
31//
32//////////////////////////////////////////////////////////////////////////////
33#include "MHCalibrationChargePix.h"
34
35#include <TH1.h>
36#include <TF1.h>
37
38#include <TVirtualPad.h>
39#include <TCanvas.h>
40#include <TPad.h>
41#include <TGraph.h>
42
43#include "MH.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48ClassImp(MHCalibrationChargePix);
49
50using namespace std;
51
52const Int_t MHCalibrationChargePix::fgChargeNbins = 2000;
53const Axis_t MHCalibrationChargePix::fgChargeFirst = -0.5;
54const Axis_t MHCalibrationChargePix::fgChargeLast = 1999.5;
55const Int_t MHCalibrationChargePix::fgAbsTimeNbins = 15;
56const Axis_t MHCalibrationChargePix::fgAbsTimeFirst = -0.5;
57const Axis_t MHCalibrationChargePix::fgAbsTimeLast = 14.5;
58
59const Float_t MHCalibrationChargePix::fgPickupLimit = 5.;
60const Int_t MHCalibrationChargePix::fgPulserFrequency = 500;
61// --------------------------------------------------------------------------
62//
63// Default Constructor.
64//
65MHCalibrationChargePix::MHCalibrationChargePix(const char *name, const char *title)
66 : fHAbsTime(), fFlags(0)
67{
68
69 fName = name ? name : "MHCalibrationChargePix";
70 fTitle = title ? title : "Fill the FADC sums of calibration events and perform the fits";
71
72 SetChargeNbins();
73 SetChargeFirst();
74 SetChargeLast();
75
76 SetAbsTimeNbins();
77 SetAbsTimeFirst();
78 SetAbsTimeLast();
79
80 SetPickupLimit();
81
82 fHGausHist.SetName("HCalibrationCharge");
83 fHGausHist.SetTitle("Distribution of Summed FADC slices Pixel");
84 fHGausHist.SetXTitle("Sum FADC Slices");
85 fHGausHist.SetYTitle("Nr. of events");
86
87 fHAbsTime.SetName("HAbsTimePixel");
88 fHAbsTime.SetTitle("Distribution of Absolute Arrival Times Pixel ");
89 fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
90 fHAbsTime.SetYTitle("Nr. of events");
91
92 fHAbsTime.UseCurrentStyle();
93 fHAbsTime.SetDirectory(NULL);
94
95 Clear();
96
97 SetPulserFrequency();
98}
99
100void MHCalibrationChargePix::Init()
101{
102
103 fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
104 fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
105}
106
107
108void MHCalibrationChargePix::Clear(Option_t *o)
109{
110
111 fPixId = -1;
112 fSaturated = 0.;
113 fPickup = 0.;
114
115 SetExcluded ( kFALSE );
116
117 MHGausEvents::Clear();
118 return;
119}
120
121
122void MHCalibrationChargePix::Reset()
123{
124}
125
126
127void MHCalibrationChargePix::ChangeHistId(Int_t id)
128{
129
130 fPixId = id;
131
132 fHGausHist.SetName(Form("%s%d", fHGausHist.GetName(), id));
133 fHGausHist.SetTitle(Form("%s%d", fHGausHist.GetTitle(), id));
134
135 fHAbsTime.SetName(Form("%s%d", fHAbsTime.GetName(), id));
136 fHAbsTime.SetTitle(Form("%s%d", fHAbsTime.GetTitle(), id));
137
138 fName = Form("%s%d", fName.Data(), id);
139 fTitle = Form("%s%d", fTitle.Data(), id);
140}
141
142void MHCalibrationChargePix::SetPulserFrequency(Float_t f)
143{
144 SetEventFrequency(f);
145}
146
147
148void MHCalibrationChargePix::SetExcluded(const Bool_t b)
149{
150 b ? SETBIT(fFlags,kExcluded) : CLRBIT(fFlags,kExcluded);
151}
152
153const Float_t MHCalibrationChargePix::GetIntegral() const
154{
155 return fHGausHist.Integral("width");
156}
157
158const Float_t MHCalibrationChargePix::GetAbsTimeMean() const
159{
160 return fHAbsTime.GetMean();
161}
162
163const Float_t MHCalibrationChargePix::GetAbsTimeRms() const
164{
165 return fHAbsTime.GetRMS();
166}
167
168Bool_t MHCalibrationChargePix::IsExcluded() const
169{
170 return TESTBIT(fFlags,kExcluded);
171}
172
173Bool_t MHCalibrationChargePix::FillAbsTime(Float_t t)
174{
175 return fHAbsTime.Fill(t) > -1;
176}
177
178
179void MHCalibrationChargePix::Draw(const Option_t *opt)
180{
181
182 TString option(opt);
183 option.ToLower();
184
185 Int_t win = 1;
186
187 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,600, 600);
188 TVirtualPad *pad = NULL;
189
190 if (option.Contains("all"))
191 {
192 option.ReplaceAll("all","");
193 oldpad->Divide(2,1);
194 win = 2;
195 oldpad->cd(1);
196 TVirtualPad *newpad = gPad;
197 pad = newpad;
198 pad->Divide(1,2);
199 pad->cd(1);
200 }
201 else
202 {
203 pad = oldpad;
204 pad->Divide(1,2);
205 pad->cd(1);
206 }
207
208 if (!IsEmpty())
209 gPad->SetLogy();
210
211 gPad->SetTicks();
212
213 fHGausHist.GetXaxis()->SetLabelSize(0.06);
214 fHGausHist.GetYaxis()->SetLabelSize(0.07);
215 fHGausHist.GetXaxis()->SetLabelOffset(0.01);
216 fHGausHist.GetYaxis()->SetLabelOffset(0.01);
217 fHGausHist.GetXaxis()->SetTitleSize(0.065);
218 fHGausHist.GetYaxis()->SetTitleSize(0.07);
219 fHGausHist.GetXaxis()->SetTitleOffset(0.6);
220 fHGausHist.GetYaxis()->SetTitleOffset(0.6);
221 fHGausHist.Draw(opt);
222 if (fFGausFit)
223 {
224 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
225 fFGausFit->Draw("same");
226 }
227
228 pad->cd(2);
229 gPad->SetTicks();
230
231 fHAbsTime.GetXaxis()->SetLabelSize(0.06);
232 fHAbsTime.GetYaxis()->SetLabelSize(0.07);
233 fHAbsTime.GetXaxis()->SetLabelOffset(0.01);
234 fHAbsTime.GetYaxis()->SetLabelOffset(0.01);
235 fHAbsTime.GetXaxis()->SetTitleSize(0.065);
236 fHAbsTime.GetYaxis()->SetTitleSize(0.07);
237 fHAbsTime.GetXaxis()->SetTitleOffset(0.6);
238 fHAbsTime.GetYaxis()->SetTitleOffset(0.6);
239 fHAbsTime.Draw(opt);
240
241 if (win < 2)
242 return;
243
244 oldpad->cd(2);
245 MHGausEvents::Draw("fourierevents");
246
247}
248
249Bool_t MHCalibrationChargePix::RepeatFit(const Option_t *option)
250{
251
252 //
253 // Get new fitting ranges
254 //
255 Axis_t rmin = GetMean() - fPickupLimit * GetSigma();
256 Axis_t rmax = GetMean() + fPickupLimit * GetSigma();
257
258 GetFGausFit()->SetRange(rmin,rmax);
259
260 GetHGausHist()->Fit(GetFGausFit(),option);
261
262 SetMean ( GetFGausFit()->GetParameter(1) );
263 SetMeanErr ( GetFGausFit()->GetParameter(2) );
264 SetSigma ( GetFGausFit()->GetParError(1) );
265 SetSigmaErr ( GetFGausFit()->GetParError(2) );
266 SetProb ( GetFGausFit()->GetProb() );
267
268 //
269 // The fit result is accepted under condition:
270 // 1) The results are not nan's
271 // 2) The NDF is not smaller than fNDFLimit (5)
272 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
273 //
274 if ( TMath::IsNaN ( GetMean() )
275 || TMath::IsNaN ( GetMeanErr() )
276 || TMath::IsNaN ( GetProb() )
277 || TMath::IsNaN ( GetSigma() )
278 || TMath::IsNaN ( GetSigmaErr() )
279 || GetFGausFit()->GetNDF() < fNDFLimit
280 || GetProb() < fProbLimit )
281 return kFALSE;
282
283 SetGausFitOK(kTRUE);
284 return kTRUE;
285
286}
287
288void MHCalibrationChargePix::BypassFit()
289{
290
291 //
292 // In case, we do not obtain reasonable values
293 // with the fit, we take the histogram values
294 //
295 SetMean ( fHGausHist.GetMean() );
296 SetMeanErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() );
297 SetSigma ( fHGausHist.GetRMS() );
298 SetSigmaErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() / 2. );
299}
300
301void MHCalibrationChargePix::CountPickup()
302{
303 fPickup = (Int_t)GetHGausHist()->Integral(GetHGausHist()->GetXaxis()->FindBin(GetMean()+fPickupLimit*GetSigma()),
304 GetHGausHist()->GetXaxis()->GetLast(),
305 "width");
306}
307
308
309
310
311
312
Note: See TracBrowser for help on using the repository browser.