#include <string>
#include <sstream>
#include <vector>
#include "TH1D.h"
#include "TH2D.h"
#include <cmath>
#include "TMath.h"
#include <limits>
Go to the source code of this file.
|
bool | isInf (double val) |
|
bool | isNaN (double val) |
|
bool | isError (double val) |
|
template<class typeToString > |
std::string | makeString (const typeToString &thingToString) |
|
template<class arrayType > |
std::vector< arrayType > | gVectorFromArray (arrayType *a, int size) |
|
void | gQuadraticSolver (double a, double b, double c, double &sol1, double &sol2) |
|
TH1D | gDivideTH1D (TH1D const *hist1, TH1D const *hist2, TString name) |
|
TH2D | gDivideTH2D (TH2D const *hist1, TH2D const *hist2, TString name) |
|
TH1D | hardCopyTH1D (TH1D const *hist, TString name) |
|
TH1D | gPullTH1D (TH1D const *hist1, TH1D const *hist2, TString name) |
|
TH1D | gMultiplyTH1D (TH1D const *hist1, TH1D const *hist2, TString name) |
|
TH2D | gMultiplyTH2D (TH2D const *hist1, TH2D const *hist2, TString name) |
|
TH1D | gSqrtTH1D (TH1D const *hist1, TString name) |
|
TH1D | gAddTH1D (TH1D const *hist1, TH1D const *hist2, TString name) |
|
bool | printInterationStatus (int interation, int total) |
|
TH2D | gAddTH2D (TH2D const *hist1, TH2D const *hist2, TString name) |
|
TH1D | gMinusTH1D (TH1D const *hist1, TH1D const *hist2, TString name) |
|
TH2D | gMinusTH2D (TH2D const *hist1, TH2D const *hist2, TString name) |
|
double | degreesToRadians (double degrees) |
|
double | radiansToDegrees (double radians) |
|
double | shiftAngleToDomain (double angle, int degrees=1) |
|
◆ degreesToRadians()
double degreesToRadians |
( |
double |
degrees | ) |
|
|
inline |
Convert degrees to radians
Definition at line 354 of file GlobalFunctions.h.
354 {
return (degrees*TMath::Pi())/180.0; }
◆ gAddTH1D()
TH1D gAddTH1D |
( |
TH1D const * |
hist1, |
|
|
TH1D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Add two TH1D's
Definition at line 244 of file GlobalFunctions.h.
246 TH1D outputHist(name,name, hist1->GetNbinsX(), hist1->GetXaxis()->GetXbins()->GetArray() );
248 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
249 double cont1 = hist1->GetBinContent(bin);
250 double cont2 = hist2->GetBinContent(bin);
251 double err1 = hist1->GetBinError(bin);
252 double err2 = hist2->GetBinError(bin);
253 double cont = cont1 + cont2;
254 double err = sqrt(err1*err1 + err2*err2);
255 outputHist.SetBinContent(bin, cont);
256 outputHist.SetBinError(bin, err);
◆ gAddTH2D()
TH2D gAddTH2D |
( |
TH2D const * |
hist1, |
|
|
TH2D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Add two TH2D's
Definition at line 286 of file GlobalFunctions.h.
288 TH2D outputHist(*hist1);
289 outputHist.SetName(name);
291 for(
int binX = 1; binX <= hist1->GetNbinsX(); binX++){
292 for(
int binY = 1; binY <= hist1->GetNbinsY(); binY++){
293 double cont1 = hist1->GetBinContent(binX, binY);
294 double cont2 = hist2->GetBinContent(binX, binY);
295 double err1 = hist1->GetBinError(binX, binY);
296 double err2 = hist2->GetBinError(binX, binY);
297 double cont = cont1 + cont2;
298 double err = sqrt(err1*err1 + err2*err2);
299 outputHist.SetBinContent(binX, binY, cont);
300 outputHist.SetBinError(binX, binY, err);
◆ gDivideTH1D()
TH1D gDivideTH1D |
( |
TH1D const * |
hist1, |
|
|
TH1D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Divide two TH1D's (don't trust ROOT)
Definition at line 81 of file GlobalFunctions.h.
83 TH1D outputHist(*hist1 );
84 outputHist.SetName(name);
86 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
87 double cont1 = hist1->GetBinContent(bin);
88 double cont2 = hist2->GetBinContent(bin);
89 double err1 = hist1->GetBinError(bin);
90 double err2 = hist2->GetBinError(bin);
91 double frac1 = err1/cont1;
92 double frac2 = err2/cont2;
93 double cont = cont1/cont2;
94 double err = cont*sqrt(frac1*frac1 + frac2*frac2);
95 if (cont != cont) {cont = 0.0;err = 0.0;}
96 if (cont2 == 0.0) {cont = 0.0;err = 0.0;}
97 if (err != err) {err = 0.0;}
98 outputHist.SetBinContent(bin, cont);
99 outputHist.SetBinError(bin, err);
◆ gDivideTH2D()
TH2D gDivideTH2D |
( |
TH2D const * |
hist1, |
|
|
TH2D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Divide two TH2D's (don't trust ROOT)
Definition at line 108 of file GlobalFunctions.h.
110 TH2D outputHist(*hist1 );
111 outputHist.SetName(name);
113 for(
int binX = 1; binX <= hist1->GetNbinsX(); binX++){
114 for(
int binY = 1; binY <= hist1->GetNbinsY(); binY++){
115 double cont1 = hist1->GetBinContent(binX, binY);
116 double cont2 = hist2->GetBinContent(binX, binY);
117 double err1 = hist1->GetBinError(binX, binY);
118 double err2 = hist2->GetBinError(binX, binY);
119 double frac1 = err1/cont1;
120 double frac2 = err2/cont2;
121 double cont = cont1/cont2;
122 double err = cont*sqrt(frac1*frac1 + frac2*frac2);
123 if (cont != cont) {cont = 0.0;err = 0.0;}
124 if (cont2 == 0.0) {cont = 0.0;err = 0.0;}
125 if (err != err) {err = 0.0;}
126 outputHist.SetBinContent(binX, binY, cont);
127 outputHist.SetBinError(binX, binY, err);
◆ gMinusTH1D()
TH1D gMinusTH1D |
( |
TH1D const * |
hist1, |
|
|
TH1D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Minus two TH1D's (hist1 - hist2)
Definition at line 309 of file GlobalFunctions.h.
312 TH1D outputHist(name,name, hist1->GetNbinsX(), hist1->GetXaxis()->GetXbins()->GetArray() );
313 outputHist.SetName(name);
315 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
316 double cont1 = hist1->GetBinContent(bin);
317 double cont2 = hist2->GetBinContent(bin);
318 double err1 = hist1->GetBinError(bin);
319 double err2 = hist2->GetBinError(bin);
320 double cont = cont1 - cont2;
321 double err = sqrt(err1*err1 + err2*err2);
322 outputHist.SetBinContent(bin, cont);
323 outputHist.SetBinError(bin, err);
◆ gMinusTH2D()
TH2D gMinusTH2D |
( |
TH2D const * |
hist1, |
|
|
TH2D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Minus two TH2D's (hist1 - hist2)
Definition at line 331 of file GlobalFunctions.h.
333 TH2D outputHist(*hist1);
334 outputHist.SetName(name);
336 for(
int binX = 1; binX <= hist1->GetNbinsX(); binX++){
337 for(
int binY = 1; binY <= hist1->GetNbinsY(); binY++){
338 double cont1 = hist1->GetBinContent(binX, binY);
339 double cont2 = hist2->GetBinContent(binX, binY);
340 double err1 = hist1->GetBinError(binX, binY);
341 double err2 = hist2->GetBinError(binX, binY);
342 double cont = cont1 - cont2;
343 double err = sqrt(err1*err1 + err2*err2);
344 outputHist.SetBinContent(binX, binY, cont);
345 outputHist.SetBinError(binX, binY, err);
◆ gMultiplyTH1D()
TH1D gMultiplyTH1D |
( |
TH1D const * |
hist1, |
|
|
TH1D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Multiply two TH1D's
Definition at line 171 of file GlobalFunctions.h.
174 TH1D outputHist( *hist1 );
176 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
177 double cont1 = hist1->GetBinContent(bin);
178 double cont2 = hist2->GetBinContent(bin);
179 double err1 = hist1->GetBinError(bin);
180 double err2 = hist2->GetBinError(bin);
181 double frac1 = err1/cont1;
182 double frac2 = err2/cont2;
183 double cont = cont1*cont2;
184 double err = cont*sqrt(frac1*frac1 + frac2*frac2);
185 outputHist.SetBinContent(bin, cont);
186 outputHist.SetBinError(bin, err);
189 outputHist.SetName(name);
◆ gMultiplyTH2D()
TH2D gMultiplyTH2D |
( |
TH2D const * |
hist1, |
|
|
TH2D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Multiply two TH2D's
Definition at line 197 of file GlobalFunctions.h.
199 TH2D outputHist( *hist1 );
201 for(
int binX = 1; binX <= hist1->GetNbinsX(); binX++){
202 for(
int binY = 1; binY <= hist1->GetNbinsY(); binY++){
203 double cont1 = hist1->GetBinContent(binX, binY);
204 double cont2 = hist2->GetBinContent(binX, binY);
205 double err1 = hist1->GetBinError(binX, binY);
206 double err2 = hist2->GetBinError(binX, binY);
207 double frac1 = err1/cont1;
208 double frac2 = err2/cont2;
209 double cont = cont1*cont2;
210 double err = cont*sqrt(frac1*frac1 + frac2*frac2);
211 outputHist.SetBinContent(binX, binY, cont);
212 outputHist.SetBinError(binX, binY, err);
216 outputHist.SetName(name);
◆ gPullTH1D()
TH1D gPullTH1D |
( |
TH1D const * |
hist1, |
|
|
TH1D const * |
hist2, |
|
|
TString |
name |
|
) |
| |
|
inline |
Make a pull histogram between two TH1D's
Definition at line 148 of file GlobalFunctions.h.
150 TH1D outputHist( *hist1 );
151 outputHist.SetName(name);
153 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
154 double cont1 = hist1->GetBinContent(bin);
155 double cont2 = hist2->GetBinContent(bin);
156 double err1 = hist1->GetBinError(bin);
157 double err2 = hist2->GetBinError(bin);
158 double err1minus2 = sqrt(err1*err1 + err2*err2);
159 double cont = (cont1 - cont2)/err1minus2;
161 outputHist.SetBinContent(bin, cont);
162 outputHist.SetBinError(bin, err);
◆ gQuadraticSolver()
void gQuadraticSolver |
( |
double |
a, |
|
|
double |
b, |
|
|
double |
c, |
|
|
double & |
sol1, |
|
|
double & |
sol2 |
|
) |
| |
|
inline |
Solve a quadratic equation
Definition at line 65 of file GlobalFunctions.h.
67 double root = b*b - 4.0*a*c;
69 sol1 = (-b + sqrt(root))/(2.0*a);
70 sol2 = (-b - sqrt(root))/(2.0*a);
◆ gSqrtTH1D()
TH1D gSqrtTH1D |
( |
TH1D const * |
hist1, |
|
|
TString |
name |
|
) |
| |
|
inline |
Square root of a TH1D
Definition at line 224 of file GlobalFunctions.h.
227 TH1D outputHist( *hist1 );
229 for(
int bin = 1; bin <= hist1->GetNbinsX(); bin++){
230 double cont = hist1->GetBinContent(bin);
231 double err = hist1->GetBinError(bin);
232 outputHist.SetBinContent(bin, sqrt(cont));
233 outputHist.SetBinError(bin, err/(2.0*sqrt(cont)));
236 outputHist.SetName(name);
◆ gVectorFromArray()
template<class arrayType >
std::vector<arrayType> gVectorFromArray |
( |
arrayType * |
a, |
|
|
int |
size |
|
) |
| |
Convert an array into a vector
Definition at line 55 of file GlobalFunctions.h.
57 std::vector<arrayType> returnVector;
58 for (
int i = 0; i < size; i++) returnVector.push_back(a[i]);
◆ hardCopyTH1D()
TH1D hardCopyTH1D |
( |
TH1D const * |
hist, |
|
|
TString |
name |
|
) |
| |
|
inline |
Make a hard copy of a TH1D - probably not needed
Definition at line 137 of file GlobalFunctions.h.
138 TH1D temp(name,name,hist->GetNbinsX(),hist->GetXaxis()->GetXbins()->GetArray());
139 for(
int bin = 1; bin <= hist->GetNbinsX(); bin++){
140 temp.SetBinContent(bin, hist->GetBinContent(bin));
141 temp.SetBinError (bin, hist->GetBinError (bin));
◆ isError()
bool isError |
( |
double |
val | ) |
|
|
inline |
◆ isInf()
Check if a double is inf or -inf
Definition at line 23 of file GlobalFunctions.h.
26 if ( (val != 0.0) && (val + val == val) && (val == val) )
return 1;
◆ isNaN()
Check if a double is NaN
Definition at line 32 of file GlobalFunctions.h.
34 if (val != val)
return 1;
◆ makeString()
template<class typeToString >
std::string makeString |
( |
const typeToString & |
thingToString | ) |
|
Convert things into strings
Definition at line 46 of file GlobalFunctions.h.
48 std::ostringstream ss;
◆ printInterationStatus()
bool printInterationStatus |
( |
int |
interation, |
|
|
int |
total |
|
) |
| |
|
inline |
Function for printing the status of a loop
Definition at line 264 of file GlobalFunctions.h.
266 int frequency = pow( 10, floor(log10(total)) - 1);
268 double nPrints = double(total)/double(frequency);
270 if (nPrints > 50) frequency *= 5;
271 else if (nPrints > 20) frequency *= 2;
277 else if (interation % frequency == 0) {
◆ radiansToDegrees()
double radiansToDegrees |
( |
double |
radians | ) |
|
|
inline |
Convert radians to degrees
Definition at line 358 of file GlobalFunctions.h.
358 {
return (radians/TMath::Pi())*180.0; }
◆ shiftAngleToDomain()
double shiftAngleToDomain |
( |
double |
angle, |
|
|
int |
degrees = 1 |
|
) |
| |
|
inline |
Shift angle to the domain [0, 360] / [0,2pi] (use degrees = 0 for radians)
Definition at line 362 of file GlobalFunctions.h.
365 if ((angle >= 0.0) && (angle < 360.0)) {
369 double val = angle - 360.0*floor(angle/360.0);
374 if ((angle >= 0.0) && (angle < 2.0*TMath::Pi())) {
378 double val = angle - 2.0*TMath::Pi()*floor(angle/(2.0*TMath::Pi()));