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