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

Last change on this file since 3444 was 3428, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.1 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.Draw(opt);
214 if (fFGausFit)
215 {
216 fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
217 fFGausFit->Draw("same");
218 }
219
220 pad->cd(2);
221 gPad->SetTicks();
222 fHAbsTime.Draw(opt);
223
224 if (win < 2)
225 return;
226
227 oldpad->cd(2);
228 MHGausEvents::Draw("fourierevents");
229
230}
231
232Bool_t MHCalibrationChargePix::RepeatFit(const Option_t *option)
233{
234
235 //
236 // Get new fitting ranges
237 //
238 Axis_t rmin = GetMean() - fPickupLimit * GetSigma();
239 Axis_t rmax = GetMean() + fPickupLimit * GetSigma();
240
241 GetFGausFit()->SetRange(rmin,rmax);
242
243 GetHGausHist()->Fit(GetFGausFit(),option);
244
245 SetMean ( GetFGausFit()->GetParameter(1) );
246 SetMeanErr ( GetFGausFit()->GetParameter(2) );
247 SetSigma ( GetFGausFit()->GetParError(1) );
248 SetSigmaErr ( GetFGausFit()->GetParError(2) );
249 SetProb ( GetFGausFit()->GetProb() );
250
251 //
252 // The fit result is accepted under condition:
253 // 1) The results are not nan's
254 // 2) The NDF is not smaller than fNDFLimit (5)
255 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
256 //
257 if ( TMath::IsNaN ( GetMean() )
258 || TMath::IsNaN ( GetMeanErr() )
259 || TMath::IsNaN ( GetProb() )
260 || TMath::IsNaN ( GetSigma() )
261 || TMath::IsNaN ( GetSigmaErr() )
262 || GetFGausFit()->GetNDF() < fNDFLimit
263 || GetProb() < fProbLimit )
264 return kFALSE;
265
266 SetGausFitOK(kTRUE);
267 return kTRUE;
268
269}
270
271void MHCalibrationChargePix::BypassFit()
272{
273
274 //
275 // In case, we do not obtain reasonable values
276 // with the fit, we take the histogram values
277 //
278 SetMean ( fHGausHist.GetMean() );
279 SetMeanErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() );
280 SetSigma ( fHGausHist.GetRMS() );
281 SetSigmaErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() / 2. );
282}
283
284void MHCalibrationChargePix::CountPickup()
285{
286 fPickup = (Int_t)GetHGausHist()->Integral(GetHGausHist()->GetXaxis()->FindBin(GetMean()+fPickupLimit*GetSigma()),
287 GetHGausHist()->GetXaxis()->GetLast(),
288 "width");
289}
290
291
292
293
294
295
Note: See TracBrowser for help on using the repository browser.