source: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc@ 3677

Last change on this file since 3677 was 3672, checked in by gaug, 21 years ago
*** empty log message ***
File size: 12.8 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//
27// MCalibrationChargePINDiode
28//
29// Storage container of the fit results of the PIN Diode signal
30// (from MHCalibrationChargePINDiode). The PIN Diode is not yet working, so
31// is the documentation for the moment.
32//
33// The Flux is calculated in photons per mm^2 in the camera plane.
34//
35// Currently, the following numbers are implemented:
36//
37// Area of PIN Diode Ap: 100.000 +- 10 mm^2
38//
39// Ratio of areas:
40//
41// Distance of PIN Diode to pulser D1: 1.5 +- 0.3 m
42// Distance of Inner Pixel to pulser D2: 18.0 +- 0.5 m
43//
44// D1*D1
45// gkSolidAngleRatio = -------- = 0.00007
46// Ap*D2*D2
47//
48// gkSolidAngleRatioErr = 0.00002
49//
50/////////////////////////////////////////////////////////////////////////////
51#include "MCalibrationChargePINDiode.h"
52#include "MCalibrationChargePix.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57ClassImp(MCalibrationChargePINDiode);
58
59using namespace std;
60
61const Float_t MCalibrationChargePINDiode::fgChargeToPhotons = -1.;
62const Float_t MCalibrationChargePINDiode::fgChargeToPhotonsErr = -1.;
63const Float_t MCalibrationChargePINDiode::gkSolidAngleRatio = 0.00007;
64const Float_t MCalibrationChargePINDiode::gkSolidAngleRatioErr = 0.00002;
65const Float_t MCalibrationChargePINDiode::gkPINDiodeQEGreen = -1.0;
66const Float_t MCalibrationChargePINDiode::gkPINDiodeQEBlue = -1.0;
67const Float_t MCalibrationChargePINDiode::gkPINDiodeQEUV = -1.0;
68const Float_t MCalibrationChargePINDiode::gkPINDiodeQECT1 = -1.0;
69const Float_t MCalibrationChargePINDiode::gkPINDiodeQEGreenErr = -1.0;
70const Float_t MCalibrationChargePINDiode::gkPINDiodeQEBlueErr = -1.0;
71const Float_t MCalibrationChargePINDiode::gkPINDiodeQEUVErr = -1.0;
72const Float_t MCalibrationChargePINDiode::gkPINDiodeQECT1Err = -1.0;
73// --------------------------------------------------------------------------
74//
75// Default Constructor.
76//
77// Sets:
78// - fCalibFlags to 0
79// - fChargeToPhotons to fgChargeToPhotons
80// - fChargeToPhotonsVar to fgChargeToPhotonsErr*fgChargeToPhotonsErr
81//
82// Calls:
83// - Clear()
84//
85MCalibrationChargePINDiode::MCalibrationChargePINDiode(const char *name, const char *title)
86 : fCalibFlags(0)
87{
88
89 fName = name ? name : "MCalibrationChargePINDiode";
90 fTitle = title ? title : "Container of the fit results of MHCalibrationChargePINDiode";
91
92 SetChargeToPhotons();
93 SetChargeToPhotonsErr();
94
95 Clear();
96
97}
98
99// ------------------------------------------------------------------------
100//
101// Sets:
102// - all flags to kFALSE
103// - all variables to -1.
104//
105// Calls:
106// - MCalibrationPix::Clear()
107//
108void MCalibrationChargePINDiode::Clear(Option_t *o)
109{
110
111 SetOscillating ( kFALSE );
112 SetChargeFitValid ( kFALSE );
113 SetTimeFitValid ( kFALSE );
114
115 fAbsTimeMean = -1.;
116 fAbsTimeRms = -1.;
117 fFluxOutsidePlexiglass = -1.;
118 fFluxOutsidePlexiglassVar = -1.;
119 fNumPhotons = -1.;
120 fNumPhotonsVar = -1.;
121 fPed = -1.;
122 fPedRms = -1.;
123 fRmsChargeMean = -1.;
124 fRmsChargeMeanErr = -1.;
125 fRmsChargeSigma = -1.;
126 fRmsChargeSigmaErr = -1.;
127
128 MCalibrationPix::Clear();
129}
130
131
132// --------------------------------------------------------------------------
133//
134// Set the pedestals from outside
135//
136void MCalibrationChargePINDiode::SetPedestal(Float_t ped, Float_t pedrms)
137{
138
139 fPed = ped;
140 fPedRms = pedrms;
141
142}
143
144// --------------------------------------------------------------------------
145//
146// Set the Oscillating Bit from outside
147//
148void MCalibrationChargePINDiode::SetOscillating( const Bool_t b)
149{
150 b ? SETBIT(fCalibFlags,kOscillating) : CLRBIT(fCalibFlags,kOscillating);
151}
152
153
154// --------------------------------------------------------------------------
155//
156// Set the ChargeFitValid Bit from outside
157//
158void MCalibrationChargePINDiode::SetChargeFitValid(Bool_t b )
159{
160 b ? SETBIT(fCalibFlags, kChargeFitValid) : CLRBIT(fCalibFlags, kChargeFitValid);
161}
162
163// --------------------------------------------------------------------------
164//
165// Set the TimeFitValid Bit from outside
166//
167void MCalibrationChargePINDiode::SetTimeFitValid(Bool_t b )
168{
169 b ? SETBIT(fCalibFlags, kTimeFitValid) : CLRBIT(fCalibFlags, kTimeFitValid);
170}
171
172// --------------------------------------------------------------------------
173//
174// Set the FluxOutsidePlexiglassAvailable Bit from outside
175//
176void MCalibrationChargePINDiode::SetFluxOutsidePlexiglassAvailable (const Bool_t b)
177{
178 b ? SETBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable)
179 : CLRBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable);
180}
181
182// --------------------------------------------------------------------------
183//
184// Return -1 if fFluxOutsidePlexiglassVar is smaller than 0.
185// Return square root of fFluxOutsidePlexiglassVar
186//
187Float_t MCalibrationChargePINDiode::GetFluxOutsidePlexiglassErr() const
188{
189 if (fFluxOutsidePlexiglassVar < 0.)
190 return -1.;
191
192 return TMath::Sqrt(fFluxOutsidePlexiglassVar);
193}
194
195// --------------------------------------------------------------------------
196//
197// Return -1 if fNumPhotonsVar is smaller than 0.
198// Return square root of fNumPhotonsVar
199//
200Float_t MCalibrationChargePINDiode::GetNumPhotonsErr() const
201{
202 if (fNumPhotonsVar < 0.)
203 return -1.;
204
205 return TMath::Sqrt(fNumPhotonsVar);
206}
207
208// --------------------------------------------------------------------------
209//
210// Return -1 if fNumPhotonsVar is smaller than 0.
211// Return -1 if fNumPhotons is 0.
212// Return fNumPhotonsVar / (fNumPhotons^2 )
213//
214Float_t MCalibrationChargePINDiode::GetNumPhotonsRelVar() const
215{
216 if (fNumPhotonsVar < 0.)
217 return -1.;
218
219 if (fNumPhotons == 0.)
220 return -1.;
221
222 return fNumPhotonsVar / fNumPhotons / fNumPhotons ;
223}
224
225
226// --------------------------------------------------------------------------
227//
228// Return -1 if gkPINDiodeQEGreenErr is smaller than 0.
229// Return -1 if gkPINDiodeQEGreen is 0.
230// Return gkPINDiodeQEGreenErr^2 / (gkPINDiodeQEGreen^2 )
231//
232const Float_t MCalibrationChargePINDiode::GetPINDiodeQEGreenRelVar() const
233{
234 if (gkPINDiodeQEGreenErr < 0.)
235 return -1.;
236
237 if (gkPINDiodeQEGreen == 0.)
238 return -1.;
239
240 return gkPINDiodeQEGreenErr * gkPINDiodeQEGreenErr / gkPINDiodeQEGreen / gkPINDiodeQEGreen ;
241}
242
243// --------------------------------------------------------------------------
244//
245// Return -1 if gkPINDiodeQEBlueErr is smaller than 0.
246// Return -1 if gkPINDiodeQEBlue is 0.
247// Return gkPINDiodeQEBlueErr^2 / gkPINDiodeQEBlue^2
248//
249const Float_t MCalibrationChargePINDiode::GetPINDiodeQEBlueRelVar() const
250{
251 if (gkPINDiodeQEBlueErr < 0.)
252 return -1.;
253
254 if (gkPINDiodeQEBlue == 0.)
255 return -1.;
256
257 return gkPINDiodeQEBlueErr * gkPINDiodeQEBlueErr / gkPINDiodeQEBlue / gkPINDiodeQEBlue ;
258}
259
260// --------------------------------------------------------------------------
261//
262// Return -1 if gkPINDiodeQEUVErr is smaller than 0.
263// Return -1 if gkPINDiodeQEUV is 0.
264// Return gkPINDiodeQEUVErr ^2 / gkPINDiodeQEUV^2
265//
266const Float_t MCalibrationChargePINDiode::GetPINDiodeQEUVRelVar() const
267{
268 if (gkPINDiodeQEUVErr < 0.)
269 return -1.;
270
271 if (gkPINDiodeQEUV == 0.)
272 return -1.;
273
274 return gkPINDiodeQEUVErr * gkPINDiodeQEUVErr / gkPINDiodeQEUV / gkPINDiodeQEUV ;
275}
276
277// --------------------------------------------------------------------------
278//
279// Return -1 if gkPINDiodeQECT1Err is smaller than 0.
280// Return -1 if gkPINDiodeQECT1 is 0.
281// Return gkPINDiodeQECT1Err ^2 / gkPINDiodeQECT1^2
282//
283const Float_t MCalibrationChargePINDiode::GetPINDiodeQECT1RelVar() const
284{
285 if (gkPINDiodeQECT1Err < 0.)
286 return -1.;
287
288 if (gkPINDiodeQECT1 == 0.)
289 return -1.;
290
291 return gkPINDiodeQECT1Err * gkPINDiodeQECT1Err / gkPINDiodeQECT1 / gkPINDiodeQECT1 ;
292}
293
294// --------------------------------------------------------------------------
295//
296// Return -1 if gkSolidAngleRatioErr is smaller than 0.
297// Return -1 if gkSolidAngleRatio is 0.
298// Return gkSolidAngleRatioErr ^2 / gkSolidAngleRatio^2
299//
300const Float_t MCalibrationChargePINDiode::GetSolidAngleRatioRelVar() const
301{
302 if (gkSolidAngleRatioErr < 0.)
303 return -1.;
304
305 if (gkSolidAngleRatio == 0.)
306 return -1.;
307
308 return gkSolidAngleRatioErr * gkSolidAngleRatioErr / gkSolidAngleRatio / gkSolidAngleRatio ;
309}
310
311
312// --------------------------------------------------------------------------
313//
314// Test bit kChargeFitValid
315//
316Bool_t MCalibrationChargePINDiode::IsChargeFitValid() const
317{
318 return TESTBIT(fCalibFlags, kChargeFitValid);
319}
320
321// --------------------------------------------------------------------------
322//
323// Test bit kFluxOutsidePlexiglassAvailable
324//
325Bool_t MCalibrationChargePINDiode::IsFluxOutsidePlexiglassAvailable() const
326{
327 return TESTBIT(fFlags,kFluxOutsidePlexiglassAvailable);
328}
329
330
331// --------------------------------------------------------------------------
332//
333// Test bit kTimeFitValid
334//
335Bool_t MCalibrationChargePINDiode::IsTimeFitValid() const
336{
337 return TESTBIT(fCalibFlags, kTimeFitValid);
338}
339
340// --------------------------------------------------------------------------
341//
342// Test bit kOscillating
343//
344Bool_t MCalibrationChargePINDiode::IsOscillating() const
345{
346 return TESTBIT(fCalibFlags, kOscillating);
347}
348
349// --------------------------------------------------------------------------
350//
351// Return kFALSE if IsChargeFitValid() is kFALSE
352//
353// Calculate fFluxOutsidePlexiglass with the formula:
354// - fFluxOutsidePlexiglass = fNumPhotons*gkSolidAngleRatio / gkPINDiodeQE (of the corr. colour)
355// - fFluxOutsidePlexiglassVar = sqrt( fNumPhotonsVar / ( fNumPhotons * fNumPhotons )
356// + ( gkSolidAngleRatioErr * gkSolidAngleRatioErr / gkSolidAngleRatio / gkSolidAngleRatio )
357// + ( gkPINDiodeQEErr * gkPINDiodeQEErr / gkPINDiodeQE / gkPINDiodeQE )
358// ) * fFluxOutsidePlexiglass * * fFluxOutsidePlexiglass
359//
360// If the fFluxOutsidePlexiglass is smaller than 0., return kFALSE
361// If the Variance is smaller than 0., return kFALSE
362//
363// SetFluxOutsidePlexiglassAvailable() and return kTRUE
364//
365Bool_t MCalibrationChargePINDiode::CalcFluxOutsidePlexiglass()
366{
367
368 if (IsChargeFitValid())
369 return kFALSE;
370
371 //
372 // Start calculation of number of photons per mm^2 on an inner pixel:
373 // Correct for the distance between camera and PIN Diode and for different areas.
374 //
375 switch (fColor)
376 {
377 case kGREEN:
378 fFluxOutsidePlexiglass = fNumPhotons * gkSolidAngleRatio * gkPINDiodeQEGreen;
379 fFluxOutsidePlexiglassVar = GetNumPhotonsRelVar() + GetSolidAngleRatioRelVar() + GetPINDiodeQEGreenRelVar();
380 break;
381 case kBLUE:
382 fFluxOutsidePlexiglass = fNumPhotons * gkSolidAngleRatio * gkPINDiodeQEBlue;
383 fFluxOutsidePlexiglassVar = GetNumPhotonsRelVar() + GetSolidAngleRatioRelVar() + GetPINDiodeQEBlueRelVar();
384 break;
385 case kUV:
386 fFluxOutsidePlexiglass = fNumPhotons * gkSolidAngleRatio * gkPINDiodeQEUV;
387 fFluxOutsidePlexiglassVar = GetNumPhotonsRelVar() + GetSolidAngleRatioRelVar() + GetPINDiodeQEUVRelVar();
388 break;
389 case kCT1:
390 default:
391 fFluxOutsidePlexiglass = fNumPhotons * gkSolidAngleRatio * gkPINDiodeQECT1;
392 fFluxOutsidePlexiglassVar = GetNumPhotonsRelVar() + GetSolidAngleRatioRelVar() + GetPINDiodeQECT1RelVar();
393 break;
394 }
395
396 //
397 // Finish calculation of errors -> convert from relative variance to absolute variance
398 //
399 fFluxOutsidePlexiglassVar *= fFluxOutsidePlexiglass * fFluxOutsidePlexiglass;
400
401 if (fFluxOutsidePlexiglass < 0.)
402 return kFALSE;
403
404 if (fFluxOutsidePlexiglassVar < 0.)
405 return kFALSE;
406
407 SetFluxOutsidePlexiglassAvailable();
408
409 *fLog << inf << endl;
410 *fLog << inf << " Mean Photon flux [ph/mm^2] outside Plexiglass: "
411 << Form("%5.3f%s%5.3f",fFluxOutsidePlexiglass," +- ",GetFluxOutsidePlexiglassErr()) << endl;
412
413 return kTRUE;
414}
Note: See TracBrowser for help on using the repository browser.