source: trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc@ 2987

Last change on this file since 2987 was 2931, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.0 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 11/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MCalibrationPINDiode //
28// //
29// This is the storage container to hold informations about the pedestal //
30// (offset) value of one Pixel (PMT). //
31// //
32/////////////////////////////////////////////////////////////////////////////
33#include "MCalibrationPINDiode.h"
34
35#include "MLog.h"
36#include "MLogManip.h"
37
38ClassImp(MCalibrationPINDiode);
39
40using namespace std;
41// --------------------------------------------------------------------------
42//
43// Default Constructor.
44//
45MCalibrationPINDiode::MCalibrationPINDiode(const char *name, const char *title)
46 : fChargeLimit(3.),
47 fChargeErrLimit(0.),
48 fChargeRelErrLimit(1.),
49 fFlags(0)
50{
51
52 fName = name ? name : "MCalibrationPINDiode";
53 fTitle = title ? title : "Container of the MHCalibrationPINDiode and the fit results";
54
55 fHist = new MHCalibrationPINDiode();
56
57 if (!fHist)
58 *fLog << warn << dbginf << " Could not create MHCalibrationPINDiode " << endl;
59
60 Clear();
61
62}
63
64MCalibrationPINDiode::~MCalibrationPINDiode()
65{
66 delete fHist;
67}
68
69// ------------------------------------------------------------------------
70//
71// Invalidate values
72//
73void MCalibrationPINDiode::Clear(Option_t *o)
74{
75 fHist->Reset();
76
77 CLRBIT(fFlags, kExcluded);
78 CLRBIT(fFlags, kFitValid);
79 CLRBIT(fFlags, kFitted);
80
81 fCharge = -1.;
82 fErrCharge = -1.;
83 fSigmaCharge = -1.;
84 fErrSigmaCharge = -1.;
85 fRSigmaSquare = -1.;
86 fChargeProb = -1.;
87 fPed = -1.;
88 fPedRms = -1.;
89 fTime = -1.;
90 fSigmaTime = -1.;
91 fTimeChiSquare = -1.;
92
93}
94
95
96// --------------------------------------------------------------------------
97//
98// Set the pedestals from outside
99//
100void MCalibrationPINDiode::SetPedestal(Float_t ped, Float_t pedrms)
101{
102
103 fPed = ped;
104 fPedRms = pedrms;
105
106}
107
108// --------------------------------------------------------------------------
109//
110// Set the Excluded Bit from outside
111//
112void MCalibrationPINDiode::SetExcluded(Bool_t b )
113{
114 b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
115}
116
117
118// --------------------------------------------------------------------------
119//
120// Set the Excluded Bit from outside
121//
122void MCalibrationPINDiode::SetExcludeQualityCheck(Bool_t b )
123{
124 b ? SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
125}
126
127// --------------------------------------------------------------------------
128//
129// Set the Excluded Bit from outside
130//
131void MCalibrationPINDiode::SetFitValid(Bool_t b )
132{
133 b ? SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid);
134}
135
136// --------------------------------------------------------------------------
137//
138// Set the Excluded Bit from outside
139//
140void MCalibrationPINDiode::SetFitted(Bool_t b )
141{
142 b ? SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
143}
144
145Bool_t MCalibrationPINDiode::IsExcluded() const
146 {
147 return TESTBIT(fFlags,kExcluded);
148 }
149
150Bool_t MCalibrationPINDiode::IsFitValid() const
151{
152 return TESTBIT(fFlags, kFitValid);
153}
154
155Bool_t MCalibrationPINDiode::IsFitted() const
156{
157 return TESTBIT(fFlags, kFitted);
158}
159
160Bool_t MCalibrationPINDiode::FitCharge()
161{
162
163 //
164 // 1) Return if the charge distribution is already succesfully fitted
165 // or if the histogram is empty
166 //
167 if (fHist->IsFitOK() || fHist->IsEmpty())
168 return kTRUE;
169
170 //
171 // 4) Fit the Lo Gain histograms with a Gaussian
172 //
173 if(fHist->FitCharge())
174 {
175 SETBIT(fFlags,kFitted);
176 }
177 else
178 {
179 *fLog << warn << "WARNING: Could not fit charges of PINDiode " << endl;
180 //
181 // 5) In case of failure print out the fit results
182 //
183 // fHist->PrintChargeFitResult();
184 CLRBIT(fFlags,kFitted);
185 }
186
187 //
188 // 6) Retrieve the results and store them in this class
189 //
190 fCharge = fHist->GetChargeMean();
191 fErrCharge = fHist->GetChargeMeanErr();
192 fSigmaCharge = fHist->GetChargeSigma();
193 fErrSigmaCharge = fHist->GetChargeSigmaErr();
194 fChargeProb = fHist->GetChargeProb();
195
196 if (CheckChargeFitValidity())
197 SETBIT(fFlags,kFitValid);
198 else
199 {
200 CLRBIT(fFlags,kFitValid);
201 return kFALSE;
202 }
203
204 return kTRUE;
205
206}
207
208//
209// The check return kTRUE if:
210//
211// 1) PINDiode has a fitted charge greater than 5*PedRMS
212// 2) PINDiode has a fit error greater than 0.
213// 3) PINDiode has a fitted charge greater its charge error
214// 4) PINDiode has a fit Probability greater than 0.0001
215// 5) PINDiode has a charge sigma bigger than its Pedestal RMS
216//
217Bool_t MCalibrationPINDiode::CheckChargeFitValidity()
218{
219
220 if (TESTBIT(fFlags,kExcludeQualityCheck))
221 return kTRUE;
222
223 if (fCharge < fChargeLimit*GetPedRms())
224 {
225 *fLog << warn << "WARNING: Fitted Charge is smaller than "
226 << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
227 return kFALSE;
228 }
229
230 if (fErrCharge < fChargeErrLimit)
231 {
232 *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
233 << fChargeErrLimit << " in PINDiode " << endl;
234 return kFALSE;
235 }
236
237 if (fCharge < fChargeRelErrLimit*fErrCharge)
238 {
239 *fLog << warn << "WARNING: Fitted Charge is smaller than "
240 << fChargeRelErrLimit << "* its error in PINDiode " << endl;
241 return kFALSE;
242 }
243
244 if (!fHist->IsFitOK())
245 {
246 *fLog << warn << "WARNING: Probability of Fitted Charge too low in PINDiode " << endl;
247 return kFALSE;
248 }
249
250 if (fSigmaCharge < GetPedRms())
251 {
252 *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
253 return kFALSE;
254 }
255 return kTRUE;
256}
257
258
259// --------------------------------------------------------------------------
260//
261// 1) Fit the arrival times
262// 2) Retrieve the results
263// 3) Note that because of the low number of bins, the NDf is sometimes 0, so
264// Root does not give a reasonable Probability, the Chisquare is more significant
265//
266Bool_t MCalibrationPINDiode::FitTime()
267{
268
269 if(!fHist->FitTimeHiGain())
270 {
271 *fLog << warn << "WARNING: Could not fit Hi Gain times of PIN Diode" << endl;
272 fHist->PrintTimeFitResult();
273 return kFALSE;
274 }
275
276 fTime = fHist->GetTimeMean();
277 fSigmaTime = fHist->GetTimeSigma();
278 fTimeChiSquare = fHist->GetTimeChiSquare();
279 fTimeProb = fHist->GetTimeProb();
280
281 if (CheckTimeFitValidity())
282 SETBIT(fFlags,kFitValid);
283 else
284 CLRBIT(fFlags,kFitValid);
285
286 return kTRUE;
287}
288
289//
290// The check returns kTRUE if:
291//
292// The mean arrival time is at least 1.0 slices from the used edge slices
293//
294Bool_t MCalibrationPINDiode::CheckTimeFitValidity()
295{
296
297 if (TESTBIT(fFlags,kExcludeQualityCheck))
298 return kTRUE;
299
300 return kTRUE;
301}
302
Note: See TracBrowser for help on using the repository browser.