7 |
|
#include "TH1D.h" |
8 |
|
#include "TString.h" |
9 |
|
#include <iostream> |
10 |
+ |
#include "TMath.h" |
11 |
+ |
|
12 |
+ |
#include <cassert> |
13 |
|
|
14 |
|
namespace jmt { |
15 |
|
|
17 |
|
//gets rid of = > < from cuts in order to be better included in file names |
18 |
|
TString fortranize(TString cut) { |
19 |
|
|
20 |
+ |
cut.ReplaceAll(" ",""); //remove all spaces |
21 |
+ |
|
22 |
|
cut.ReplaceAll("==","eq"); |
23 |
|
cut.ReplaceAll(">=","gte"); |
24 |
|
cut.ReplaceAll("<=","lte"); |
26 |
|
cut.ReplaceAll(">","gt"); |
27 |
|
cut.ReplaceAll("<","lt"); |
28 |
|
|
29 |
+ |
cut.ReplaceAll("&&","and"); |
30 |
+ |
cut.ReplaceAll("||","or"); |
31 |
+ |
|
32 |
|
cut.ReplaceAll("/","Over"); |
33 |
|
cut.ReplaceAll("+","Plus"); |
34 |
|
cut.ReplaceAll("*","Times"); |
35 |
|
|
28 |
– |
cut.ReplaceAll("*","Times"); |
29 |
– |
|
36 |
|
//this is pretty ugly |
37 |
|
cut.ReplaceAll("(","L"); |
38 |
|
cut.ReplaceAll(")","R"); |
66 |
|
|
67 |
|
|
68 |
|
Double_t weightedMean(Int_t n, Double_t *a, Double_t *e, const bool returnError=false) { |
69 |
+ |
using namespace std; |
70 |
|
|
71 |
|
Double_t numerator=0; |
72 |
|
Double_t denominator=0; |
89 |
|
|
90 |
|
} |
91 |
|
|
92 |
+ |
//deal with the annoyance of logical booleans that are stored in an ntuple as double |
93 |
+ |
bool doubleToBool( double a) { |
94 |
+ |
using namespace std; |
95 |
+ |
|
96 |
+ |
int i = TMath::Nint(a); |
97 |
+ |
if (i==0) return false; |
98 |
+ |
else if (i==1) return true; |
99 |
+ |
|
100 |
+ |
cout<<"[doubleToBool] Something weird going on! "<<a<<"\t"<<i<<endl; |
101 |
+ |
if (i>1) return true; |
102 |
+ |
return false; |
103 |
+ |
} |
104 |
+ |
|
105 |
+ |
//delta phi calculations are pretty commonplace, so put it here |
106 |
+ |
double deltaPhi(double phi1, double phi2) { |
107 |
+ |
double result = phi1 - phi2; |
108 |
+ |
while (result > TMath::Pi()) result -= 2*TMath::Pi(); |
109 |
+ |
while (result <= -TMath::Pi()) result += 2*TMath::Pi(); |
110 |
+ |
return fabs(result); |
111 |
+ |
} |
112 |
+ |
|
113 |
+ |
double deltaR2(double eta1, double phi1, double eta2, double phi2) { |
114 |
+ |
double deta = eta1 - eta2; |
115 |
+ |
double dphi = deltaPhi(phi1, phi2); |
116 |
+ |
return deta*deta + dphi*dphi; |
117 |
+ |
} |
118 |
+ |
|
119 |
+ |
double deltaR(double eta1, double phi1, double eta2, double phi2) { |
120 |
+ |
return TMath::Sqrt(deltaR2 (eta1, phi1, eta2, phi2)); |
121 |
+ |
} |
122 |
+ |
|
123 |
|
// == error propagation == |
124 |
|
|
125 |
|
//because not all versions of ROOT have it built in |
138 |
|
|
139 |
|
//return error on a/b |
140 |
|
double errAoverB(double a, double aerr, double b, double berr) { |
141 |
< |
if (b==0 || a==0) { |
142 |
< |
cout<<"Warning in errAoverB -- a or b is zero!"<<endl; |
141 |
> |
using namespace std; |
142 |
> |
if (b==0) { |
143 |
> |
cout<<"Warning in errAoverB -- b is zero!"<<endl; |
144 |
|
return -1; |
145 |
|
} |
146 |
< |
return (a/b)*sqrt( pow( aerr/a, 2) + pow( berr/b, 2) ); |
146 |
> |
return (1/b)*sqrt( aerr*aerr + a*a*berr*berr/(b*b) ); |
147 |
|
} |
148 |
|
|
149 |
|
//return error on a*b |
150 |
|
double errAtimesB(double a, double aerr, double b, double berr) { |
151 |
< |
if (b==0 || a==0) { |
113 |
< |
cout<<"Warning in errAtimesB -- a or b is zero!"<<endl; |
114 |
< |
return -1; |
115 |
< |
} |
116 |
< |
|
117 |
< |
return a*b*sqrt( pow( aerr/a, 2) + pow( berr/b, 2) ); |
151 |
> |
return sqrt( b*b*aerr*aerr + a*a*berr*berr); |
152 |
|
} |
153 |
|
|
154 |
|
//======== container for run, lumisection, event number ========= |