ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/MathTools/src/MathUtils.cc
Revision: 1.7
Committed: Mon May 11 08:23:06 2009 UTC (15 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009c, Mit_009b, Mit_009a
Changes since 1.6: +11 -2 lines
Log Message:
Added DeltaR2 to save computation of SQRT if possible.

File Contents

# Content
1 // $Id: MathUtils.cc,v 1.6 2009/03/20 13:33:19 loizides Exp $
2
3 #include "MitCommon/MathTools/interface/MathUtils.h"
4
5 using namespace mithep;
6
7 //--------------------------------------------------------------------------------------------------
8 Double_t MathUtils::AddInQuadrature(Double_t a, Double_t b)
9 {
10 // Add quantities in quadrature.
11
12 return(TMath::Sqrt(a*a + b*b));
13 }
14
15 //--------------------------------------------------------------------------------------------------
16 Double_t MathUtils::DeltaPhi(Double_t phi1, Double_t phi2)
17 {
18 // Compute DeltaPhi between two given angles. Results is in [-pi/2,pi/2].
19
20 Double_t dphi = TMath::Abs(phi1-phi2);
21 while (dphi>TMath::Pi())
22 dphi = TMath::Abs(dphi - TMath::TwoPi());
23 return(dphi);
24 }
25
26 //--------------------------------------------------------------------------------------------------
27 Double_t MathUtils::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
28 {
29 // Compute DeltaR between two given points in the eta/phi plane.
30
31 Double_t dR = TMath::Sqrt(DeltaR2(phi1,eta1,phi2,eta2));
32 return(dR);
33 }
34
35 //--------------------------------------------------------------------------------------------------
36 Double_t MathUtils::DeltaR2(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
37 {
38 // Compute DeltaR between two given points in the eta/phi plane.
39
40 Double_t dphi = DeltaPhi(phi1, phi2);
41 Double_t deta = eta1-eta2;
42 Double_t dR = dphi*dphi + deta*deta;
43 return(dR);
44 }
45
46 //--------------------------------------------------------------------------------------------------
47 Double_t MathUtils::Eta2Theta(Double_t eta)
48 {
49 // Compute theta from given eta value.
50
51 return 2.*TMath::ATan(exp(-eta));
52 }
53
54 //--------------------------------------------------------------------------------------------------
55 Double_t MathUtils::Theta2Eta(Double_t theta)
56 {
57 // Compute eta from given theta value.
58
59 return -TMath::Log(TMath::Tan(theta/2.));
60 }