1 |
// $Id: MathUtils.cc,v 1.5 2009/02/18 15:38:26 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 dphi = DeltaPhi(phi1, phi2);
|
32 |
Double_t deta = eta1-eta2;
|
33 |
Double_t dR = TMath::Sqrt(dphi*dphi + deta*deta);
|
34 |
return(dR);
|
35 |
}
|
36 |
|
37 |
//--------------------------------------------------------------------------------------------------
|
38 |
Double_t MathUtils::Eta2Theta(Double_t eta)
|
39 |
{
|
40 |
// Compute theta from given eta value.
|
41 |
|
42 |
return 2.*TMath::ATan(exp(-eta));
|
43 |
}
|
44 |
|
45 |
//--------------------------------------------------------------------------------------------------
|
46 |
Double_t MathUtils::Theta2Eta(Double_t theta)
|
47 |
{
|
48 |
// Compute eta from given theta value.
|
49 |
|
50 |
return -TMath::Log(TMath::Tan(theta/2.));
|
51 |
}
|