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

Last change on this file since 3007 was 3007, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.4 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, kChargeFitValid);
79 CLRBIT(fFlags, kChargeFitValid);
80 CLRBIT(fFlags, kFitted);
81
82 fCharge = -1.;
83 fErrCharge = -1.;
84 fSigmaCharge = -1.;
85 fErrSigmaCharge = -1.;
86 fRSigmaSquare = -1.;
87 fChargeProb = -1.;
88 fPed = -1.;
89 fPedRms = -1.;
90 fTime = -1.;
91 fSigmaTime = -1.;
92 fTimeChiSquare = -1.;
93
94}
95
96
97// --------------------------------------------------------------------------
98//
99// Set the pedestals from outside
100//
101void MCalibrationPINDiode::SetPedestal(Float_t ped, Float_t pedrms)
102{
103
104 fPed = ped;
105 fPedRms = pedrms;
106
107}
108
109// --------------------------------------------------------------------------
110//
111// Set the Excluded Bit from outside
112//
113void MCalibrationPINDiode::SetExcluded(Bool_t b )
114{
115 b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
116}
117
118
119// --------------------------------------------------------------------------
120//
121// Set the Excluded Bit from outside
122//
123void MCalibrationPINDiode::SetExcludeQualityCheck(Bool_t b )
124{
125 b ? SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
126}
127
128// --------------------------------------------------------------------------
129//
130// Set the Excluded Bit from outside
131//
132void MCalibrationPINDiode::SetChargeFitValid(Bool_t b )
133{
134 b ? SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid);
135}
136
137// --------------------------------------------------------------------------
138//
139// Set the Excluded Bit from outside
140//
141void MCalibrationPINDiode::SetTimeFitValid(Bool_t b )
142{
143 b ? SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid);
144}
145
146// --------------------------------------------------------------------------
147//
148// Set the Excluded Bit from outside
149//
150void MCalibrationPINDiode::SetFitted(Bool_t b )
151{
152 b ? SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
153}
154
155Bool_t MCalibrationPINDiode::IsExcluded() const
156 {
157 return TESTBIT(fFlags,kExcluded);
158 }
159
160Bool_t MCalibrationPINDiode::IsChargeFitValid() const
161{
162 return TESTBIT(fFlags, kChargeFitValid);
163}
164
165Bool_t MCalibrationPINDiode::IsTimeFitValid() const
166{
167 return TESTBIT(fFlags, kTimeFitValid);
168}
169
170Bool_t MCalibrationPINDiode::IsFitted() const
171{
172 return TESTBIT(fFlags, kFitted);
173}
174
175Bool_t MCalibrationPINDiode::FitCharge()
176{
177
178 //
179 // 1) Return if the charge distribution is already succesfully fitted
180 // or if the histogram is empty
181 //
182 if (fHist->IsChargeFitOK() || fHist->IsEmpty())
183 return kTRUE;
184
185 //
186 // 4) Fit the Lo Gain histograms with a Gaussian
187 //
188 if(fHist->FitCharge())
189 {
190 SETBIT(fFlags,kFitted);
191 }
192 else
193 {
194 *fLog << warn << "WARNING: Could not fit charges of PINDiode " << endl;
195 //
196 // 5) In case of failure print out the fit results
197 //
198 // fHist->PrintChargeFitResult();
199 CLRBIT(fFlags,kFitted);
200 }
201
202 //
203 // 6) Retrieve the results and store them in this class
204 //
205 fCharge = fHist->GetChargeMean();
206 fErrCharge = fHist->GetChargeMeanErr();
207 fSigmaCharge = fHist->GetChargeSigma();
208 fErrSigmaCharge = fHist->GetChargeSigmaErr();
209 fChargeProb = fHist->GetChargeProb();
210
211 if (CheckChargeFitValidity())
212 SETBIT(fFlags,kChargeFitValid);
213 else
214 {
215 CLRBIT(fFlags,kChargeFitValid);
216 return kFALSE;
217 }
218
219 return kTRUE;
220
221}
222
223//
224// The check return kTRUE if:
225//
226// 1) PINDiode has a fitted charge greater than 5*PedRMS
227// 2) PINDiode has a fit error greater than 0.
228// 3) PINDiode has a fitted charge greater its charge error
229// 4) PINDiode has a fit Probability greater than 0.0001
230// 5) PINDiode has a charge sigma bigger than its Pedestal RMS
231//
232Bool_t MCalibrationPINDiode::CheckChargeFitValidity()
233{
234
235 if (TESTBIT(fFlags,kExcludeQualityCheck))
236 return kTRUE;
237
238 if (fCharge < fChargeLimit*GetPedRms())
239 {
240 *fLog << warn << "WARNING: Fitted Charge is smaller than "
241 << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
242 return kFALSE;
243 }
244
245 if (fErrCharge < fChargeErrLimit)
246 {
247 *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
248 << fChargeErrLimit << " in PINDiode " << endl;
249 return kFALSE;
250 }
251
252 if (fCharge < fChargeRelErrLimit*fErrCharge)
253 {
254 *fLog << warn << "WARNING: Fitted Charge is smaller than "
255 << fChargeRelErrLimit << "* its error in PINDiode " << endl;
256 return kFALSE;
257 }
258
259 if (!fHist->IsChargeFitOK())
260 {
261 *fLog << warn << "WARNING: Probability of Fitted Charge too low in PINDiode " << endl;
262 return kFALSE;
263 }
264
265 if (fSigmaCharge < GetPedRms())
266 {
267 *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
268 return kFALSE;
269 }
270 return kTRUE;
271}
272
273
274// --------------------------------------------------------------------------
275//
276// 1) Fit the arrival times
277// 2) Retrieve the results
278// 3) Note that because of the low number of bins, the NDf is sometimes 0, so
279// Root does not give a reasonable Probability, the Chisquare is more significant
280//
281Bool_t MCalibrationPINDiode::FitTime()
282{
283
284 if(!fHist->FitTime())
285 {
286 *fLog << warn << "WARNING: Could not fit Hi Gain times of PIN Diode" << endl;
287 fHist->PrintTimeFitResult();
288 return kFALSE;
289 }
290
291 fTime = fHist->GetRelTimeMean();
292 fSigmaTime = fHist->GetRelTimeSigma();
293 fTimeProb = fHist->GetRelTimeProb();
294
295 if (CheckTimeFitValidity())
296 SETBIT(fFlags,kTimeFitValid);
297 else
298 CLRBIT(fFlags,kTimeFitValid);
299
300 return kTRUE;
301}
302
303//
304// The check returns kTRUE if:
305//
306// The mean arrival time is at least 1.0 slices from the used edge slices
307//
308Bool_t MCalibrationPINDiode::CheckTimeFitValidity()
309{
310
311 if (TESTBIT(fFlags,kExcludeQualityCheck))
312 return kTRUE;
313
314 return kTRUE;
315}
316
Note: See TracBrowser for help on using the repository browser.