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): Thomas Bretz 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MMath
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MMath.h"
|
---|
31 |
|
---|
32 | ClassImp(MMath);
|
---|
33 |
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 | // --------------------------------------------------------------------------
|
---|
37 | //
|
---|
38 | // Calculate Significance as
|
---|
39 | // significance = (s-b)/sqrt(s+k*k*b) mit k=s/b
|
---|
40 | //
|
---|
41 | // s: total number of events in signal region
|
---|
42 | // b: number of background events in signal region
|
---|
43 | //
|
---|
44 | Double_t MMath::Significance(Double_t s, Double_t b)
|
---|
45 | {
|
---|
46 | const Double_t k = b==0 ? 0 : s/b;
|
---|
47 | const Double_t f = s+k*k*b;
|
---|
48 |
|
---|
49 | return f==0 ? 0 : (s-b)/Sqrt(f);
|
---|
50 | }
|
---|
51 |
|
---|
52 | // --------------------------------------------------------------------------
|
---|
53 | //
|
---|
54 | // Symmetrized significance - this is somehow analog to
|
---|
55 | // SignificanceLiMaSigned
|
---|
56 | //
|
---|
57 | // Returns Significance(s,b) if s>b otherwise -Significance(b, s);
|
---|
58 | //
|
---|
59 | Double_t MMath::SignificanceSym(Double_t s, Double_t b)
|
---|
60 | {
|
---|
61 | return s>b ? Significance(s, b) : -Significance(b, s);
|
---|
62 | }
|
---|
63 |
|
---|
64 | // --------------------------------------------------------------------------
|
---|
65 | //
|
---|
66 | // calculates the significance according to Li & Ma
|
---|
67 | // ApJ 272 (1983) 317, Formula 17
|
---|
68 | //
|
---|
69 | // s // s: number of on events
|
---|
70 | // b // b: number of off events
|
---|
71 | // alpha = t_on/t_off; // t: observation time
|
---|
72 | //
|
---|
73 | // The significance has the same (positive!) value for s>b and b>s.
|
---|
74 | //
|
---|
75 | // Returns -1 if sum<0 or alpha<0 or the argument of sqrt<0
|
---|
76 | // Returns 0 if s+b==0
|
---|
77 | //
|
---|
78 | Double_t MMath::SignificanceLiMa(Double_t s, Double_t b, Double_t alpha)
|
---|
79 | {
|
---|
80 | const Double_t sum = s+b;
|
---|
81 |
|
---|
82 | if (sum==0)
|
---|
83 | return 0;
|
---|
84 |
|
---|
85 | if (sum<0 || alpha<=0)
|
---|
86 | return -1;
|
---|
87 |
|
---|
88 | const Double_t l = s*Log(s/sum*(alpha+1)/alpha);
|
---|
89 | const Double_t m = b*Log(b/sum*(alpha+1) );
|
---|
90 |
|
---|
91 | return l+m<0 ? -1 : Sqrt((l+m)*2);
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // Calculates MMath::SignificanceLiMa(s, b, alpha). Returns 0 if the
|
---|
97 | // calculation has failed. Otherwise the Li/Ma significance which was
|
---|
98 | // calculated. If s<b a negative value is returned.
|
---|
99 | //
|
---|
100 | Double_t MMath::SignificanceLiMaSigned(Double_t s, Double_t b, Double_t alpha)
|
---|
101 | {
|
---|
102 | const Double_t sig = SignificanceLiMa(s, b, alpha);
|
---|
103 | if (sig<=0)
|
---|
104 | return 0;
|
---|
105 |
|
---|
106 | return Sign(sig, s-alpha*b);
|
---|
107 | }
|
---|
108 |
|
---|
109 | // --------------------------------------------------------------------------
|
---|
110 | //
|
---|
111 | // Returns: 2/(sigma*sqrt(2))*integral[0,x](exp(-(x-mu)^2/(2*sigma^2)))
|
---|
112 | //
|
---|
113 | Double_t MMath::GaussProb(Double_t x, Double_t sigma, Double_t mean)
|
---|
114 | {
|
---|
115 | static const Double_t sqrt2 = Sqrt(2.);
|
---|
116 | return Erf((x-mean)/(sigma*sqrt2));
|
---|
117 | }
|
---|
118 |
|
---|