ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/MathTools/src/MathUtils.cc
Revision: 1.9
Committed: Mon Jul 20 04:55:44 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_008
Changes since 1.8: +3 -1 lines
Log Message:
Changes for docu

File Contents

# Content
1 // $Id: MathUtils.cc,v 1.8 2009/06/24 14:51:05 loizides Exp $
2
3 #include "MitCommon/MathTools/interface/MathUtils.h"
4 #include <TError.h>
5 #include <TH1D.h>
6 #include <TGraphAsymmErrors.h>
7
8 ClassImp(mithep::MathUtils)
9
10 using namespace mithep;
11
12 //--------------------------------------------------------------------------------------------------
13 Double_t MathUtils::AddInQuadrature(Double_t a, Double_t b)
14 {
15 // Add quantities in quadrature.
16
17 return(TMath::Sqrt(a*a + b*b));
18 }
19
20 //--------------------------------------------------------------------------------------------------
21 void MathUtils::CalcRatio(Double_t n1, Double_t n2, Double_t &r, Double_t &rlow, Double_t &rup)
22 {
23 // Calculate ratio and lower/upper errors from given values using Bayes.
24
25 if (n1>n2) {
26 Error("CalcRatio", "First value should be smaller than second: %f > %f", n1, n2);
27 r = n1/n2;
28 rlow = 0;
29 rup = 0;
30 return;
31 }
32
33 TH1D h1("dummy1","",1,1,2);
34 h1.SetBinContent(1,n1);
35
36 TH1D h2("dummy2","",1,1,2);
37 h2.SetBinContent(1,n2);
38
39 TGraphAsymmErrors g;
40 g.BayesDivide(&h1,&h2);
41 r = g.GetY()[0];
42 rup = g.GetErrorYhigh(0);
43 rlow = g.GetErrorYlow(0);
44 }
45
46 //--------------------------------------------------------------------------------------------------
47 Double_t MathUtils::DeltaPhi(Double_t phi1, Double_t phi2)
48 {
49 // Compute DeltaPhi between two given angles. Results is in [-pi/2,pi/2].
50
51 Double_t dphi = TMath::Abs(phi1-phi2);
52 while (dphi>TMath::Pi())
53 dphi = TMath::Abs(dphi - TMath::TwoPi());
54 return(dphi);
55 }
56
57 //--------------------------------------------------------------------------------------------------
58 Double_t MathUtils::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
59 {
60 // Compute DeltaR between two given points in the eta/phi plane.
61
62 Double_t dR = TMath::Sqrt(DeltaR2(phi1,eta1,phi2,eta2));
63 return(dR);
64 }
65
66 //--------------------------------------------------------------------------------------------------
67 Double_t MathUtils::DeltaR2(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
68 {
69 // Compute DeltaR between two given points in the eta/phi plane.
70
71 Double_t dphi = DeltaPhi(phi1, phi2);
72 Double_t deta = eta1-eta2;
73 Double_t dR = dphi*dphi + deta*deta;
74 return(dR);
75 }
76
77 //--------------------------------------------------------------------------------------------------
78 Double_t MathUtils::Eta2Theta(Double_t eta)
79 {
80 // Compute theta from given eta value.
81
82 return 2.*TMath::ATan(exp(-eta));
83 }
84
85 //--------------------------------------------------------------------------------------------------
86 Double_t MathUtils::Theta2Eta(Double_t theta)
87 {
88 // Compute eta from given theta value.
89
90 return -TMath::Log(TMath::Tan(theta/2.));
91 }