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 |
|
---|
38 | ClassImp(MCalibrationPINDiode);
|
---|
39 |
|
---|
40 | using namespace std;
|
---|
41 | // --------------------------------------------------------------------------
|
---|
42 | //
|
---|
43 | // Default Constructor.
|
---|
44 | //
|
---|
45 | MCalibrationPINDiode::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 |
|
---|
64 | MCalibrationPINDiode::~MCalibrationPINDiode()
|
---|
65 | {
|
---|
66 | delete fHist;
|
---|
67 | }
|
---|
68 |
|
---|
69 | // ------------------------------------------------------------------------
|
---|
70 | //
|
---|
71 | // Invalidate values
|
---|
72 | //
|
---|
73 | void 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 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | // --------------------------------------------------------------------------
|
---|
94 | //
|
---|
95 | // Set the pedestals from outside
|
---|
96 | //
|
---|
97 | void MCalibrationPINDiode::SetPedestal(Float_t ped, Float_t pedrms)
|
---|
98 | {
|
---|
99 |
|
---|
100 | fPed = ped;
|
---|
101 | fPedRms = pedrms;
|
---|
102 |
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // Set the Excluded Bit from outside
|
---|
108 | //
|
---|
109 | void MCalibrationPINDiode::SetExcluded(Bool_t b )
|
---|
110 | {
|
---|
111 | b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | // --------------------------------------------------------------------------
|
---|
116 | //
|
---|
117 | // Set the Excluded Bit from outside
|
---|
118 | //
|
---|
119 | void MCalibrationPINDiode::SetExcludeQualityCheck(Bool_t b )
|
---|
120 | {
|
---|
121 | b ? SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
|
---|
122 | }
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // Set the Excluded Bit from outside
|
---|
127 | //
|
---|
128 | void MCalibrationPINDiode::SetChargeFitValid(Bool_t b )
|
---|
129 | {
|
---|
130 | b ? SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid);
|
---|
131 | }
|
---|
132 |
|
---|
133 | // --------------------------------------------------------------------------
|
---|
134 | //
|
---|
135 | // Set the Excluded Bit from outside
|
---|
136 | //
|
---|
137 | void MCalibrationPINDiode::SetTimeFitValid(Bool_t b )
|
---|
138 | {
|
---|
139 | b ? SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid);
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Set the Excluded Bit from outside
|
---|
145 | //
|
---|
146 | void MCalibrationPINDiode::SetFitted(Bool_t b )
|
---|
147 | {
|
---|
148 | b ? SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
|
---|
149 | }
|
---|
150 |
|
---|
151 | Bool_t MCalibrationPINDiode::IsExcluded() const
|
---|
152 | {
|
---|
153 | return TESTBIT(fFlags,kExcluded);
|
---|
154 | }
|
---|
155 |
|
---|
156 | Bool_t MCalibrationPINDiode::IsChargeFitValid() const
|
---|
157 | {
|
---|
158 | return TESTBIT(fFlags, kChargeFitValid);
|
---|
159 | }
|
---|
160 |
|
---|
161 | Bool_t MCalibrationPINDiode::IsTimeFitValid() const
|
---|
162 | {
|
---|
163 | return TESTBIT(fFlags, kTimeFitValid);
|
---|
164 | }
|
---|
165 |
|
---|
166 | Bool_t MCalibrationPINDiode::IsFitted() const
|
---|
167 | {
|
---|
168 | return TESTBIT(fFlags, kFitted);
|
---|
169 | }
|
---|
170 |
|
---|
171 | Bool_t MCalibrationPINDiode::FitCharge()
|
---|
172 | {
|
---|
173 |
|
---|
174 | //
|
---|
175 | // 1) Return if the charge distribution is already succesfully fitted
|
---|
176 | // or if the histogram is empty
|
---|
177 | //
|
---|
178 | if (fHist->IsChargeFitOK() || fHist->IsEmpty())
|
---|
179 | return kTRUE;
|
---|
180 |
|
---|
181 | //
|
---|
182 | // 4) Fit the Lo Gain histograms with a Gaussian
|
---|
183 | //
|
---|
184 | if(fHist->FitCharge())
|
---|
185 | {
|
---|
186 | SETBIT(fFlags,kFitted);
|
---|
187 | }
|
---|
188 | else
|
---|
189 | {
|
---|
190 | *fLog << warn << "WARNING: Could not fit charges of PINDiode " << endl;
|
---|
191 | //
|
---|
192 | // 5) In case of failure print out the fit results
|
---|
193 | //
|
---|
194 | // fHist->PrintChargeFitResult();
|
---|
195 | CLRBIT(fFlags,kFitted);
|
---|
196 | }
|
---|
197 |
|
---|
198 | //
|
---|
199 | // 6) Retrieve the results and store them in this class
|
---|
200 | //
|
---|
201 | fCharge = fHist->GetChargeMean();
|
---|
202 | fErrCharge = fHist->GetChargeMeanErr();
|
---|
203 | fSigmaCharge = fHist->GetChargeSigma();
|
---|
204 | fErrSigmaCharge = fHist->GetChargeSigmaErr();
|
---|
205 | fChargeProb = fHist->GetChargeProb();
|
---|
206 |
|
---|
207 | if (CheckChargeFitValidity())
|
---|
208 | SETBIT(fFlags,kChargeFitValid);
|
---|
209 | else
|
---|
210 | {
|
---|
211 | CLRBIT(fFlags,kChargeFitValid);
|
---|
212 | return kFALSE;
|
---|
213 | }
|
---|
214 |
|
---|
215 | return kTRUE;
|
---|
216 |
|
---|
217 | }
|
---|
218 |
|
---|
219 | //
|
---|
220 | // The check return kTRUE if:
|
---|
221 | //
|
---|
222 | // 1) PINDiode has a fitted charge greater than 5*PedRMS
|
---|
223 | // 2) PINDiode has a fit error greater than 0.
|
---|
224 | // 3) PINDiode has a fitted charge greater its charge error
|
---|
225 | // 4) PINDiode has a fit Probability greater than 0.0001
|
---|
226 | // 5) PINDiode has a charge sigma bigger than its Pedestal RMS
|
---|
227 | //
|
---|
228 | Bool_t MCalibrationPINDiode::CheckChargeFitValidity()
|
---|
229 | {
|
---|
230 |
|
---|
231 | if (TESTBIT(fFlags,kExcludeQualityCheck))
|
---|
232 | return kTRUE;
|
---|
233 |
|
---|
234 | if (fCharge < fChargeLimit*GetPedRms())
|
---|
235 | {
|
---|
236 | *fLog << warn << "WARNING: Fitted Charge is smaller than "
|
---|
237 | << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
|
---|
238 | return kFALSE;
|
---|
239 | }
|
---|
240 |
|
---|
241 | if (fErrCharge < fChargeErrLimit)
|
---|
242 | {
|
---|
243 | *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
|
---|
244 | << fChargeErrLimit << " in PINDiode " << endl;
|
---|
245 | return kFALSE;
|
---|
246 | }
|
---|
247 |
|
---|
248 | if (fCharge < fChargeRelErrLimit*fErrCharge)
|
---|
249 | {
|
---|
250 | *fLog << warn << "WARNING: Fitted Charge is smaller than "
|
---|
251 | << fChargeRelErrLimit << "* its error in PINDiode " << endl;
|
---|
252 | return kFALSE;
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (!fHist->IsChargeFitOK())
|
---|
256 | {
|
---|
257 | *fLog << warn << "WARNING: Probability of Fitted Charge too low in PINDiode " << endl;
|
---|
258 | return kFALSE;
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (fSigmaCharge < GetPedRms())
|
---|
262 | {
|
---|
263 | *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
|
---|
264 | return kFALSE;
|
---|
265 | }
|
---|
266 | return kTRUE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | //
|
---|
270 | // The check returns kTRUE if:
|
---|
271 | //
|
---|
272 | // The mean arrival time is at least 1.0 slices from the used edge slices
|
---|
273 | //
|
---|
274 | Bool_t MCalibrationPINDiode::CheckTimeFitValidity()
|
---|
275 | {
|
---|
276 |
|
---|
277 | if (TESTBIT(fFlags,kExcludeQualityCheck))
|
---|
278 | return kTRUE;
|
---|
279 |
|
---|
280 | return kTRUE;
|
---|
281 | }
|
---|
282 |
|
---|