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

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