source: trunk/Mars/mcalib/MCalibrationPix.cc@ 15766

Last change on this file since 15766 was 8907, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 12.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// MCalibrationPix
26//
27// Base Storage container for a calibration pixel. Holds mean and sigmas,
28// their errors, the fit probability and the number of pickup events for
29// the high-gain and the low-gain derived values.
30//
31// Errors are stored internally as variances, but are returned and filled
32// as square root of the variances.
33//
34// Calls to GetMean(), GetMeanErr(), GetSigma(), GetSigmaErr(), GetProb() or
35// GetNumPickup() and GetNumBlackout() test first the bit kHiGainSaturation
36// before returning the high-gain or low-gain value, analogue for the
37// corr. Setters.
38//
39// The three flags: kValid, kExcluded and kHiGainSaturation may be set.
40// The colors: kGREEN, kBLUE, kUV and kCT1 may be set.
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MCalibrationPix.h"
44
45#include <TMath.h>
46
47ClassImp(MCalibrationPix);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Default Constructor:
54//
55// Sets:
56// - fPixId to -1
57// - fFlags to 0
58//
59// Calls:
60// - Clear()
61//
62MCalibrationPix::MCalibrationPix(const char *name, const char *title)
63 : fPixId(-1),
64 fFlags(0)
65{
66
67 fName = name ? name : "MCalibrationPix";
68 fTitle = title ? title : "Container of the fit results of MHCalibrationPixs ";
69
70 Clear();
71
72}
73
74// ------------------------------------------------------------------------
75//
76// Sets:
77// - all variables to -1
78// - all flags to kFALSE
79//
80void MCalibrationPix::Clear(Option_t *o)
81{
82
83 fHiGainNumBlackout = -1 ;
84 fHiGainNumPickup = -1 ;
85 fHiGainMean = -1.;
86 fHiGainMeanVar = -1.;
87 fHiGainProb = -1.;
88 fHiGainRms = -1.;
89 fHiGainSigma = -1.;
90 fHiGainSigmaVar = -1.;
91
92 fLoGainNumBlackout = -1 ;
93 fLoGainNumPickup = -1 ;
94 fLoGainMean = -1.;
95 fLoGainMeanVar = -1.;
96 fLoGainProb = -1.;
97 fLoGainRms = -1.;
98 fLoGainSigma = -1.;
99 fLoGainSigmaVar = -1.;
100
101 SetHiGainSaturation ( kFALSE );
102 SetExcluded ( kFALSE );
103 SetValid ( kFALSE );
104 SetDebug ( kFALSE );
105
106}
107
108
109// -----------------------------------------------------
110//
111// copy 'constructor'
112//
113void MCalibrationPix::Copy(TObject& object) const
114{
115
116 MCalibrationPix &pix = (MCalibrationPix&)object;
117
118 //
119 // Copy the data members
120 //
121 pix.fPixId = fPixId;
122 pix.fFlags = fFlags;
123 pix.fHiGainMean = fHiGainMean;
124 pix.fHiGainMeanVar = fHiGainMeanVar;
125 pix.fHiGainNumBlackout = fHiGainNumBlackout;
126 pix.fHiGainNumPickup = fHiGainNumPickup;
127 pix.fHiGainSigma = fHiGainSigma;
128 pix.fHiGainSigmaVar = fHiGainSigmaVar;
129 pix.fHiGainProb = fHiGainProb;
130 pix.fLoGainMean = fLoGainMean;
131 pix.fLoGainMeanVar = fLoGainMeanVar;
132 pix.fLoGainNumBlackout = fLoGainNumBlackout;
133 pix.fLoGainNumPickup = fLoGainNumPickup;
134 pix.fLoGainSigma = fLoGainSigma;
135 pix.fLoGainSigmaVar = fLoGainSigmaVar;
136 pix.fLoGainProb = fLoGainProb;
137
138}
139
140
141// --------------------------------------------------------------------------
142//
143// Set the Hi Gain Saturation Bit from outside
144//
145void MCalibrationPix::SetHiGainSaturation(Bool_t b)
146{
147 b ? SETBIT(fFlags, kHiGainSaturation) : CLRBIT(fFlags, kHiGainSaturation);
148}
149
150// --------------------------------------------------------------------------
151//
152// Set the Valid Bit from outside
153//
154void MCalibrationPix::SetDebug(Bool_t b )
155{
156 b ? SETBIT(fFlags, kDebug) : CLRBIT(fFlags, kDebug);
157}
158
159// --------------------------------------------------------------------------
160//
161// Set the Excluded Bit from outside
162//
163void MCalibrationPix::SetExcluded(Bool_t b )
164{
165 b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
166}
167
168// --------------------------------------------------------------------------
169//
170// Set the Valid Bit from outside
171//
172void MCalibrationPix::SetValid(Bool_t b )
173{
174 b ? SETBIT(fFlags, kValid) : CLRBIT(fFlags, kValid);
175}
176
177
178// --------------------------------------------------------------------------
179//
180// Return -1, if IsHiGainSaturation()
181// Return -1, if the LoGain Mean is smaller than 0.5
182// Return -1, if the HiGain Mean is -1. (has not yet been set)
183// Return fHiGainMean / fLoGainMean
184//
185Float_t MCalibrationPix::GetHiLoMeansDivided() const
186{
187
188 if (IsHiGainSaturation())
189 return -1.;
190
191 if (fLoGainMean <= 0.5)
192 return -1.;
193
194 if (fHiGainMean == -1.)
195 return -1.;
196
197 return fHiGainMean / fLoGainMean;
198
199}
200
201// ----------------------------------------------------------------------------------
202//
203// Return -1, if IsHiGainSaturation()
204// Return -1, if the LoGain Mean or its variance is smaller than 0.5 (has not yet been set)
205// Return -1, if the HiGain Mean or its variance is -1. (has not yet been set)
206// Return propagated error of GetHiLoMeansDivided()
207//
208Float_t MCalibrationPix::GetHiLoMeansDividedErr() const
209{
210
211 if (IsHiGainSaturation())
212 return -1.;
213
214 if (fLoGainMean <= 0.5)
215 return -1.;
216
217 if (fHiGainMean == -1.)
218 return -1.;
219
220 if (fLoGainMeanVar <= 0.)
221 return -1.;
222
223 if (fHiGainMeanVar <= 0.)
224 return -1.;
225
226 const Float_t lomeansquare = fLoGainMean * fLoGainMean;
227 const Float_t deltaHi = fHiGainMeanVar / lomeansquare;
228 const Float_t deltaLo = fLoGainMeanVar / (lomeansquare * lomeansquare) * fHiGainMean * fHiGainMean;
229
230 return TMath::Sqrt(deltaHi + deltaLo);
231
232}
233
234// --------------------------------------------------------------------------
235//
236// Return -1, if IsHiGainSaturation()
237// Return -1, if the LoGain Sigma is smaller than 0.01
238// Return -1, if the HiGain Sigma is -1. (has not yet been set)
239// Return fHiGainSigma / fLoGainSigma
240//
241Float_t MCalibrationPix::GetHiLoSigmasDivided() const
242{
243
244 if (IsHiGainSaturation())
245 return -1.;
246
247 if (fLoGainSigma <= 0.01)
248 return -1.;
249
250 if (fHiGainSigma == -1.)
251 return -1.;
252
253 return fHiGainSigma / fLoGainSigma;
254
255}
256
257// ----------------------------------------------------------------------------------
258//
259// Return -1, if IsHiGainSaturation()
260// Return -1, if the LoGain Sigma variance is smaller than 0.
261// Return -1, if the LoGain Sigma is smaller than 0.01
262// Return -1, if the HiGain Sigma or its variance is -1. (has not yet been set)
263// Return propagated error of GetHiLoSigmasDivided()
264//
265Float_t MCalibrationPix::GetHiLoSigmasDividedErr() const
266{
267
268 if (IsHiGainSaturation())
269 return -1.;
270
271 if (fLoGainSigma <= 0.01)
272 return -1.;
273
274 if (fHiGainSigma == -1.)
275 return -1.;
276
277 if (fLoGainSigmaVar <= 0.)
278 return -1.;
279
280 if (fHiGainSigmaVar <= 0.)
281 return -1.;
282
283 const Float_t losigmasquare = fLoGainSigma * fLoGainSigma;
284 const Float_t deltaHi = fHiGainSigmaVar / losigmasquare;
285 const Float_t deltaLo = fLoGainSigmaVar / (losigmasquare * losigmasquare) * fHiGainSigma * fHiGainSigma;
286
287 return TMath::Sqrt(deltaHi + deltaLo);
288
289}
290
291
292// --------------------------------------------------------------------------
293//
294// Get the Relative Variance of either High Gain or Low Gain Mean
295// depending on IsHighGainSaturation()
296//
297// If variance is smaller than 0. return -1.
298//
299Float_t MCalibrationPix::GetMeanRelVar() const
300{
301
302 if (IsHiGainSaturation())
303 if (fLoGainMeanVar < 0. || fLoGainMean < 0.)
304 return -1.;
305 else
306 return fLoGainMeanVar / (fLoGainMean * fLoGainMean);
307 else
308 if (fHiGainMeanVar < 0. || fHiGainMean < 0.)
309 return -1.;
310 else
311 return fHiGainMeanVar / (fHiGainMean * fHiGainMean);
312}
313
314// --------------------------------------------------------------------------
315//
316// Get the Square of either High Gain or Low Gain Mean
317// depending on IsHighGainSaturation()
318//
319Float_t MCalibrationPix::GetMeanSquare() const
320{
321
322 if (IsHiGainSaturation())
323 return fLoGainMean == -1. ? -1. : fLoGainMean * fLoGainMean;
324 else
325 return fHiGainMean == -1. ? -1. : fHiGainMean * fHiGainMean;
326}
327
328
329// --------------------------------------------------------------------------
330//
331// Get the Relative Variance of either High Gain or Low Gain Sigma
332// depending on IsHighGainSaturation()
333//
334// If variance is smaller than 0. return -1.
335//
336Float_t MCalibrationPix::GetSigmaRelVar() const
337{
338
339 if (IsHiGainSaturation())
340 if (fLoGainSigmaVar < 0.)
341 return -1.;
342 else
343 return fLoGainSigmaVar / (fLoGainSigma * fLoGainSigma);
344 else
345 if (fHiGainSigmaVar < 0.)
346 return -1.;
347 else
348 return fHiGainSigmaVar / (fHiGainSigma * fHiGainSigma);
349}
350
351// --------------------------------------------------------------------------
352//
353// Get the High Gain Mean Error: Takes square root of fHiGainMeanVar
354//
355Float_t MCalibrationPix::GetHiGainMeanErr() const
356{
357 if (fHiGainMeanVar < 0.)
358 return -1.;
359
360 return TMath::Sqrt(fHiGainMeanVar);
361}
362
363
364// --------------------------------------------------------------------------
365//
366// Get the High Gain Sigma Error: Takes square root of fHiGainSigmaVar
367//
368Float_t MCalibrationPix::GetHiGainSigmaErr() const
369{
370 if (fHiGainSigmaVar < 0.)
371 return -1.;
372
373 return TMath::Sqrt(fHiGainSigmaVar);
374}
375
376// --------------------------------------------------------------------------
377//
378// Get the Low Gain Mean Error: Takes square root of fLoGainMeanVar
379//
380Float_t MCalibrationPix::GetLoGainMeanErr() const
381{
382 if (fLoGainMeanVar < 0.)
383 return -1.;
384
385 return TMath::Sqrt(fLoGainMeanVar);
386}
387
388// --------------------------------------------------------------------------
389//
390// Get the Low Gain Mean Rel Variance
391//
392Float_t MCalibrationPix::GetLoGainMeanRelVar() const
393{
394 if (fLoGainMeanVar < 0.)
395 return -1.;
396 if (fLoGainMean == 0.)
397 return -1.;
398
399 return fLoGainMeanVar / ( fLoGainMean * fLoGainMean);
400}
401
402// --------------------------------------------------------------------------
403//
404// Get the High Gain Mean Rel Variance
405//
406Float_t MCalibrationPix::GetHiGainMeanRelVar() const
407{
408 if (fHiGainMeanVar < 0.)
409 return -1.;
410 if (fHiGainMean == 0.)
411 return -1.;
412
413 return fHiGainMeanVar / ( fHiGainMean * fHiGainMean);
414}
415
416// --------------------------------------------------------------------------
417//
418// Get the Low Gain Sigma Error: Takes square root of fHiGainSigmaVar
419//
420Float_t MCalibrationPix::GetLoGainSigmaErr() const
421{
422 if (fLoGainSigmaVar < 0.)
423 return -1.;
424
425 return TMath::Sqrt(fLoGainSigmaVar);
426}
427
428// --------------------------------------------------------------------------
429//
430// Test bit kHiGainSaturation
431//
432Bool_t MCalibrationPix::IsHiGainSaturation() const
433{
434 return TESTBIT(fFlags,kHiGainSaturation);
435}
436
437// --------------------------------------------------------------------------
438//
439// Test bit kDebug
440//
441Bool_t MCalibrationPix::IsDebug() const
442{
443 return TESTBIT(fFlags,kDebug);
444}
445
446// --------------------------------------------------------------------------
447//
448// Test bit kExcluded
449//
450Bool_t MCalibrationPix::IsExcluded() const
451{
452 return TESTBIT(fFlags,kExcluded);
453}
454
455// --------------------------------------------------------------------------
456//
457// Test bit kValid
458//
459Bool_t MCalibrationPix::IsValid() const
460{
461 return TESTBIT(fFlags,kValid);
462}
463
Note: See TracBrowser for help on using the repository browser.