9 #ifndef GLOBAL_FUNCTIONS_HH 10 #define GLOBAL_FUNCTIONS_HH 26 if ( (val != 0.0) && (val + val == val) && (val == val) )
return 1;
34 if (val != val)
return 1;
46 template <
class typeToString> std::string
makeString(
const typeToString& thingToString)
48 std::ostringstream ss;
55 template <
class arrayType> std::vector<arrayType>
gVectorFromArray(arrayType* a,
int size){
57 std::vector<arrayType> returnVector;
58 for (
int i = 0; i < size; i++) returnVector.push_back(a[i]);
65 inline void gQuadraticSolver(
double a,
double b,
double c,
double& sol1,
double& sol2){
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);
81 inline TH1D
gDivideTH1D(TH1D
const* hist1, TH1D
const* hist2, TString name){
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);
108 inline TH2D
gDivideTH2D(TH2D
const* hist1, TH2D
const* hist2, TString name){
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);
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));
148 inline TH1D
gPullTH1D(TH1D
const* hist1, TH1D
const* hist2, TString name){
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);
171 inline TH1D
gMultiplyTH1D(TH1D
const* hist1, TH1D
const* hist2, TString name){
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);
197 inline TH2D
gMultiplyTH2D(TH2D
const* hist1, TH2D
const* hist2, TString name){
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);
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);
244 inline TH1D
gAddTH1D(TH1D
const* hist1, TH1D
const* hist2, TString name){
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);
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) {
286 inline TH2D
gAddTH2D(TH2D
const* hist1, TH2D
const* hist2, TString name){
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);
309 inline TH1D
gMinusTH1D(TH1D
const* hist1, TH1D
const* hist2, TString name){
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);
331 inline TH2D
gMinusTH2D(TH2D
const* hist1, TH2D
const* hist2, TString name){
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);
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()));
std::vector< arrayType > gVectorFromArray(arrayType *a, int size)
double radiansToDegrees(double radians)
TH2D gMinusTH2D(TH2D const *hist1, TH2D const *hist2, TString name)
double shiftAngleToDomain(double angle, int degrees=1)
TH2D gMultiplyTH2D(TH2D const *hist1, TH2D const *hist2, TString name)
void gQuadraticSolver(double a, double b, double c, double &sol1, double &sol2)
std::string makeString(const typeToString &thingToString)
double degreesToRadians(double degrees)
TH1D gMinusTH1D(TH1D const *hist1, TH1D const *hist2, TString name)
TH1D gMultiplyTH1D(TH1D const *hist1, TH1D const *hist2, TString name)
TH2D gAddTH2D(TH2D const *hist1, TH2D const *hist2, TString name)
bool printInterationStatus(int interation, int total)
TH2D gDivideTH2D(TH2D const *hist1, TH2D const *hist2, TString name)
TH1D hardCopyTH1D(TH1D const *hist, TString name)
TH1D gDivideTH1D(TH1D const *hist1, TH1D const *hist2, TString name)
TH1D gAddTH1D(TH1D const *hist1, TH1D const *hist2, TString name)
TH1D gSqrtTH1D(TH1D const *hist1, TString name)
TH1D gPullTH1D(TH1D const *hist1, TH1D const *hist2, TString name)