-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_functions.cpp~
111 lines (92 loc) · 2.35 KB
/
my_functions.cpp~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// myfunctions.cpp
#include <iostream>
#include "my_functions.h"
// ==================== CLASS METHODS/DECLARATIONS ====================
Complex::Complex()
{
real = imag = magnitude = 0;
}
Complex::Complex(Float_t re, Float_t im)
{
real = re;
imag = im;
magnitude = TMath::Sqrt(re*re + im*im);
}
Float_t Complex::GetReal() const
{
return real;
}
Float_t Complex::GetImag() const
{
return imag;
}
Float_t Complex::GetMagnitude() const
{
return magnitude;
}
void Complex::set_mag()
{
magnitude = TMath::Sqrt(real*real + imag*imag);
}
Complex Complex::operator+(const Complex & c) const
{
Complex sum;
sum.real = real + c.real;
sum.imag = imag + c.imag;
sum.set_mag();
return sum;
}
Complex Complex::operator-(const Complex & c) const
{
Complex diff;
diff.real = real - c.real;
diff.imag = imag - c.imag;
diff.set_mag();
return diff;
}
Complex Complex::operator/(const Complex & c) const
{
Complex result;
result.real = (real*c.real + imag*c.imag) / (c.real*c.real + c.imag*c.imag);
result.imag = (imag*c.real - real*c.imag) / (c.real*c.real + c.imag*c.imag);
result.set_mag();
return result;
}
// ==================== INDEPENDENT FUNCTIONS =========================
// puts file reader at beginning of desired line
std::fstream& GotoLine(std::fstream& file, int num)
{
file.seekg(std::ios::beg);
for(int i=0; i < num - 1; ++i)
{
file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
return file;
}
// pion two point correlation cosh fitter function
Double_t Cosh(Double_t *x, Double_t *par)
{
Float_t xx = x[0];
Double_t f = par[0]*TMath::CosH(par[1]*(xx - 28)) + par[2];
return f;
}
// takes a hist array and averages over n files at specific inputBin
Float_t AverageOverFiles(TH1F** histArray, Int_t inputBin, const Int_t n)
{
Float_t result(0);
for (Int_t i = 0; i < n; i++)
{
result += histArray[i]->GetBinContent(inputBin);
}
return result / (Float_t)n;
}
Float_t ErrorOverFiles(TH1F** histArray, Int_t inputBin, const Int_t n, const Float_t avg)
{
Float_t result(0), bin_content(0);
for (Int_t i = 0; i < n; i++)
{
bin_content = histArray[i]->GetBinContent(inputBin);
result += TMath::Power(bin_content - avg, 2);
}
return TMath::Sqrt(result * Float_t(n-1)/n);
}