source: trunk/MagicSoft/Mars/mbase/MMath.cc@ 4321

Last change on this file since 4321 was 3666, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.2 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): 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
32ClassImp(MMath);
33
34using 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//
44Double_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)/TMath::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//
59Double_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//
78Double_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*TMath::Log(s/sum*(alpha+1)/alpha);
89 const Double_t m = b*TMath::Log(b/sum*(alpha+1) );
90
91 return l+m<0 ? -1 : TMath::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//
100Double_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 TMath::Sign(sig, s-b);
107}
Note: See TracBrowser for help on using the repository browser.