1 |
loizides |
1.9 |
// $Id: MathUtils.cc,v 1.8 2009/06/24 14:51:05 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.9 |
ClassImp(mithep::MathUtils)
|
9 |
|
|
|
10 |
loizides |
1.3 |
using namespace mithep;
|
11 |
sixie |
1.1 |
|
12 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
13 |
loizides |
1.4 |
Double_t MathUtils::AddInQuadrature(Double_t a, Double_t b)
|
14 |
loizides |
1.2 |
{
|
15 |
loizides |
1.5 |
// Add quantities in quadrature.
|
16 |
|
|
|
17 |
loizides |
1.2 |
return(TMath::Sqrt(a*a + b*b));
|
18 |
|
|
}
|
19 |
sixie |
1.1 |
|
20 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
21 |
loizides |
1.8 |
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 |
loizides |
1.4 |
Double_t MathUtils::DeltaPhi(Double_t phi1, Double_t phi2)
|
48 |
sixie |
1.1 |
{
|
49 |
loizides |
1.5 |
// Compute DeltaPhi between two given angles. Results is in [-pi/2,pi/2].
|
50 |
|
|
|
51 |
loizides |
1.4 |
Double_t dphi = TMath::Abs(phi1-phi2);
|
52 |
|
|
while (dphi>TMath::Pi())
|
53 |
|
|
dphi = TMath::Abs(dphi - TMath::TwoPi());
|
54 |
|
|
return(dphi);
|
55 |
sixie |
1.1 |
}
|
56 |
|
|
|
57 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
58 |
loizides |
1.4 |
Double_t MathUtils::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
|
59 |
|
|
{
|
60 |
loizides |
1.5 |
// Compute DeltaR between two given points in the eta/phi plane.
|
61 |
|
|
|
62 |
loizides |
1.7 |
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 |
loizides |
1.4 |
Double_t dphi = DeltaPhi(phi1, phi2);
|
72 |
|
|
Double_t deta = eta1-eta2;
|
73 |
loizides |
1.7 |
Double_t dR = dphi*dphi + deta*deta;
|
74 |
sixie |
1.1 |
return(dR);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
78 |
loizides |
1.4 |
Double_t MathUtils::Eta2Theta(Double_t eta)
|
79 |
loizides |
1.2 |
{
|
80 |
loizides |
1.5 |
// Compute theta from given eta value.
|
81 |
|
|
|
82 |
loizides |
1.2 |
return 2.*TMath::ATan(exp(-eta));
|
83 |
sixie |
1.1 |
}
|
84 |
|
|
|
85 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
86 |
loizides |
1.4 |
Double_t MathUtils::Theta2Eta(Double_t theta)
|
87 |
loizides |
1.2 |
{
|
88 |
loizides |
1.5 |
// Compute eta from given theta value.
|
89 |
|
|
|
90 |
loizides |
1.2 |
return -TMath::Log(TMath::Tan(theta/2.));
|
91 |
sixie |
1.1 |
}
|