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

Last change on this file since 3324 was 3290, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.5 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 Int_t MHCalibrationChargePix::fgPickupLimit = 5;
60const Int_t MHCalibrationChargePix::fgPulserFrequency = 200;
61// --------------------------------------------------------------------------
62//
63// Default Constructor.
64//
65MHCalibrationChargePix::MHCalibrationChargePix(const char *name, const char *title)
66 : fHAbsTime()
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 fHAbsTime.UseCurrentStyle();
83 fHAbsTime.SetDirectory(NULL);
84
85 Clear();
86
87 SetPulserFrequency();
88}
89
90void MHCalibrationChargePix::Init()
91{
92
93 fHGausHist.SetName("HCalibrationCharge");
94 fHGausHist.SetTitle("Distribution of Summed FADC slices Pixel");
95 fHGausHist.SetXTitle("Sum FADC Slices");
96 fHGausHist.SetYTitle("Nr. of events");
97 fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
98 fHGausHist.Sumw2();
99
100 fHAbsTime.SetName("HAbsTimePixel");
101 fHAbsTime.SetTitle("Distribution of Absolute Arrival Times Pixel ");
102 fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
103 fHAbsTime.SetYTitle("Nr. of events");
104 fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
105
106}
107
108
109void MHCalibrationChargePix::Clear(Option_t *o)
110{
111
112 fPixId = -1;
113 fSaturated = 0;
114 fPickup = 0;
115
116 MHGausEvents::Clear();
117 return;
118}
119
120
121void MHCalibrationChargePix::Reset()
122{
123}
124
125
126void MHCalibrationChargePix::ChangeHistId(Int_t id)
127{
128
129 fPixId = id;
130
131 fHGausHist.SetName(Form("%s%d", fHGausHist.GetName(), id));
132 fHGausHist.SetTitle(Form("%s%d", fHGausHist.GetTitle(), id));
133
134 fHAbsTime.SetName(Form("%s%d", fHAbsTime.GetName(), id));
135 fHAbsTime.SetTitle(Form("%s%d", fHAbsTime.GetTitle(), id));
136}
137
138
139const Float_t MHCalibrationChargePix::GetIntegral() const
140{
141 return fHGausHist.Integral("width");
142}
143
144const Float_t MHCalibrationChargePix::GetAbsTimeMean() const
145{
146 return fHAbsTime.GetMean();
147}
148
149const Float_t MHCalibrationChargePix::GetAbsTimeRms() const
150{
151 return fHAbsTime.GetRMS();
152}
153
154void MHCalibrationChargePix::SetPulserFrequency(Float_t f)
155{
156 SetEventFrequency(f);
157}
158
159Bool_t MHCalibrationChargePix::FillAbsTime(Float_t t)
160{
161 return fHAbsTime.Fill(t) > -1;
162}
163
164
165void MHCalibrationChargePix::Draw(const Option_t *opt)
166{
167
168 TString option(opt);
169 option.ToLower();
170
171 Int_t win = 1;
172
173 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this,600, 600);
174
175 pad->SetTicks();
176 pad->SetBorderMode(0);
177
178 if (option.Contains("time"))
179 {
180 option.ReplaceAll("events","");
181 win++;
182 }
183
184 pad->SetTicks();
185 pad->SetBorderMode(0);
186 pad->Divide(1,win);
187 pad->cd(1);
188
189 if (!IsEmpty())
190 pad->SetLogy();
191
192 MHGausEvents::Draw(opt);
193
194 if (win > 1)
195 {
196 pad->cd(2);
197 fHAbsTime.Draw(opt);
198 }
199}
200
201Bool_t MHCalibrationChargePix::RepeatFit(const Option_t *option)
202{
203
204 //
205 // Get new fitting ranges
206 //
207 Axis_t rmin = GetMean() - fPickupLimit * GetSigma();
208 Axis_t rmax = GetMean() + fPickupLimit * GetSigma();
209
210 GetFGausFit()->SetRange(rmin,rmax);
211
212 GetHGausHist()->Fit(GetFGausFit(),option);
213
214 SetMean ( GetFGausFit()->GetParameter(1) );
215 SetMeanErr ( GetFGausFit()->GetParameter(2) );
216 SetSigma ( GetFGausFit()->GetParError(1) );
217 SetSigmaErr ( GetFGausFit()->GetParError(2) );
218 SetProb ( GetFGausFit()->GetProb() );
219
220 //
221 // The fit result is accepted under condition:
222 // 1) The results are not nan's
223 // 2) The NDF is not smaller than fNDFLimit (5)
224 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
225 //
226 if ( TMath::IsNaN ( GetMean() )
227 || TMath::IsNaN ( GetMeanErr() )
228 || TMath::IsNaN ( GetProb() )
229 || TMath::IsNaN ( GetSigma() )
230 || TMath::IsNaN ( GetSigmaErr() )
231 || GetFGausFit()->GetNDF() < fNDFLimit
232 || GetProb() < fProbLimit )
233 return kFALSE;
234
235 SetGausFitOK(kTRUE);
236 return kTRUE;
237
238}
239
240void MHCalibrationChargePix::BypassFit()
241{
242
243 //
244 // In case, we do not obtain reasonable values
245 // with the fit, we take the histogram values
246 //
247 SetMean ( fHGausHist.GetMean() );
248 SetMeanErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() );
249 SetSigma ( fHGausHist.GetRMS() );
250 SetSigmaErr ( fHGausHist.GetRMS() / fHGausHist.GetEntries() / 2. );
251}
252
253void MHCalibrationChargePix::CountPickup()
254{
255 fPickup = (Int_t)GetHGausHist()->Integral(GetHGausHist()->GetXaxis()->FindBin(GetMean()+fPickupLimit*GetSigma()),
256 GetHGausHist()->GetXaxis()->GetLast(),
257 "width");
258}
259
260
261
262
263
264
Note: See TracBrowser for help on using the repository browser.