GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
TDPAD.cc
Go to the documentation of this file.
1#include <TMinuit.h>
2
3#include "TDPAD.hh"
4
5namespace GamR {
6 namespace AngDist {
26
37 TH1D *RatioFunction(TH1 *h1, TH1 *h2)
38 {
39 TH1D *ratio = new TH1D("", "", h1->GetNbinsX(), h1->GetXaxis()->GetXmin(), h1->GetXaxis()->GetXmax());
40 for (int i = 0; i < h1->GetNbinsX(); ++i) {
41 double A = h1->GetBinContent(i);
42 double B = h2->GetBinContent(i);
43
44 // so ratio function is (A-B)/(A+B)
45 double delA = 0;
46 double delB = 0;
47 if (A + B > 0) {
48 delA = 2 * B / pow(A + B, 2);
49 delB = 2 * A / pow(A + B, 2);
50 ratio->SetBinContent(i, (A - B) / (A + B));
51 }
52 // error is given by sqrt((delA*σ_A)^2+(delB*σ_B)^2)
53 double sigma_A = h1->GetBinError(i);
54 double sigma_B = h2->GetBinError(i);
55 ratio->SetBinError(i, sqrt(pow(delA * sigma_A, 2) + pow(delB * sigma_B, 2)));
56 }
57 return ratio;
58 }
59
60 TH1D *RatioFunction(TH1 *h1, TH1 *h2, const char *name)
61 {
62 TH1D *ratio = RatioFunction(h1, h2);
63 ratio->SetName(name);
64 return ratio;
65 }
66
67 TH1D *RatioFunction(TH2 *h1, TH2 *h2, GamR::TK::Gate peak, GamR::TK::Gate background) {
68 TH1D *hTotal1 = peak.ApplyX(h1, "hTotal1");
69 TH1D *hBackground1 = background.ApplyX(h1, "hBackground1");
70 TH1D *hTotal2 = peak.ApplyX(h2, "hTotal2");
71 TH1D *hBackground2 = background.ApplyX(h2, "hBackground2");
72 TH1D *hEnergy = h1->ProjectionX();
73
74 TH1D *hDifference = (TH1D*)hTotal1->Clone("difference");
75 TH1D *hSum = (TH1D*)hTotal1->Clone("sum");
76 hDifference->Add(hTotal2, -1.);
77 hSum->Add(hTotal2, 1.);
78 double scale = (double)peak.GetBinWidth(hEnergy)/(double)background.GetBinWidth(hEnergy);
79 hSum->Add(hBackground1, -scale);
80 hSum->Add(hBackground2, -scale);
81 TH1D *hRatio = (TH1D*)hDifference->Clone("ratio_func");
82 hRatio->Divide(hSum);
83
84 int Nbins=hTotal1->GetNbinsX();
85 for ( int i=1; i <=Nbins; i=i+1 ) {
86 double sigT1 = hTotal1->GetBinError(i);
87 double sigT2 = hTotal2->GetBinError(i);
88 double sigB1 = hBackground1->GetBinError(i);
89 double sigB2 = hBackground2->GetBinError(i);
90 double T1 = hTotal1->GetBinContent(i);
91 double T2 = hTotal2->GetBinContent(i);
92 double B1 = hBackground1->GetBinContent(i);
93 double B2 = hBackground2->GetBinContent(i);
94 double denom = pow((T1+T2-scale*B1 - scale*B2), 2);
95 if ( denom == 0 ){
96 hRatio->SetBinError(i, 0);
97 }
98 else {
99 double delT1 = ( 2*T2 - scale*B1 - scale*B2 )/denom;
100 double delT2 = ( 2*T1 - scale*B1 - scale*B2 )/denom;
101 double delB1 = ( scale*(T1-T2) )/denom;
102 double delB2 = ( scale*(T1-T2) )/denom;
103 hRatio->SetBinError(i, sqrt( pow(sigT1*delT1, 2) + pow(sigT2*delT2, 2) + pow(sigB1*delB1, 2) + pow(sigB2*delB2, 2) ) );
104 }
105 }
106
107 delete hDifference;
108 delete hSum;
109 delete hTotal1;
110 delete hTotal2;
111 delete hBackground1;
112 delete hBackground2;
113
114 return hRatio;
115 }
116
117 TH1D *RatioFunction(TH2 *h1, TH2 *h2, GamR::TK::Gate peak, GamR::TK::Gate background, const char *name) {
118 TH1D *hRatio = RatioFunction(h1, h2, peak, background);
119 hRatio->SetName(name);
120 return hRatio;
121 }
122
123 TH1D *RatioFunction(TH2 *h1, TH2 *h2, GamR::Nucleus::Transition peak) {
124 TH1D *hRatio = RatioFunction(h1, h2, *(peak.GetGate()), *(peak.GetGateBG()));
125 return hRatio;
126 }
127
128 TH1D *RatioFunction(TH2 *h1, TH2 *h2, GamR::Nucleus::Transition peak, const char *name) {
129 TH1D *hRatio = RatioFunction(h1, h2, *(peak.GetGate()), *(peak.GetGateBG()), name);
130 return hRatio;
131 }
132
142 TH1D *AutoCorrelation(TH1 *h1, double start, double stop)
143 {
144 int k1 = h1->FindBin(start);
145 int k2 = h1->FindBin(stop);
146
147 TH1D *out = new TH1D("", "", k2 - k1 + 1, -h1->GetBinWidth(0)/2.0, h1->GetBinLowEdge(k2) + h1->GetBinWidth(k2) - h1->GetBinLowEdge(k1) - h1->GetBinWidth(0)/2.0);
148 double mean = 0;
149
150 // find mean value
151 for (int k = k1; k <= k2; ++k) {
152 mean = mean + h1->GetBinContent(k);
153 }
154 mean = mean / (k2 - k1 + 1);
155
156 // find normalisation constant
157 double B = 0; // normalisation constant
158 for (int k = k1; k <= k2; ++k) {
159 B = B + (h1->GetBinContent(k) - mean) * (h1->GetBinContent(k) - mean) / (k2 - k1 + 1);
160 }
161
162 // calculate function value for each t
163 for (int t = 0; t < k2 - k1; ++t) {
164 double A = 0; // A is the sum
165 // calculate sum from k=k1 to k=k2-t
166 for (int k = k1; k <= k2 - t; ++k) {
167 A = A + (h1->GetBinContent(k) - mean) * (h1->GetBinContent(k + t) - mean) / (k2 - k1 - t + 1);
168 }
169 double X = A / B; // normalise, X is the final value of the function
170 if (X > 1) {
171 // cout << "value of X = " << X << ", at t = " << t << ", with A = " << A
172 // << ", and B = " << B << endl;
173 }
174 // fill relevant bin with correct value
175 out->SetBinContent(t + 1, X);
176 }
177 // calculate errors
178 for (int t = 0; t < k2 - k1; ++t) { // deal with each bin of (out) histogram one at a time
179 // cout << "calculating error for t = " << t << endl;
180 double A = 0;
181 for (int k = k1; k <= k2 - t; ++k) {
182 A = A + (h1->GetBinContent(k) - mean) * (h1->GetBinContent(k + t) - mean) / (k2 - k1 - t + 1);
183 }
184 double sigsquaredX = 0;
185 for (int i = k1; i <= k2; ++i) { // need to sum error from each component (i.e. bin in h1)
186 // cout << "calculating contribution from bin " << i << endl;
187 double xipt;
188 double ximt;
189 if (k1 <= i + t && i + t <= k2 - t) {
190 xipt = h1->GetBinContent(i + t); // x_{i+t}
191 } else {
192 xipt = 0;
193 }
194 if (k1 <= i - t && i - t <= k2 - t) {
195 ximt = h1->GetBinContent(i - t); // x_{i-t}
196 } else {
197 ximt = 0;
198 }
199 // double xi=h1->GetBinContent(i);
200 double delA = (xipt + ximt) / (k2 - k1 - t + 1);
201 double delB = 0; // 2*xi/(k2-k1);
202 double delX = (delA * B - delB * A) / (B * B);
203 sigsquaredX = sigsquaredX + pow(delX * h1->GetBinError(i), 2);
204 }
205 out->SetBinError(t + 1, sqrt(sigsquaredX));
206 }
207 return out;
208 }
209
210 TH1D *AutoCorrelation(TH1 *h1)
211 {
212 return AutoCorrelation(h1, h1->GetBinCenter(1), h1->GetBinCenter(h1->GetNbinsX() - 1));
213 }
214
215 TH1D *AutoCorrelation(TH1 *h1, const char *name)
216 {
217 TH1D *out = AutoCorrelation(h1, h1->GetBinCenter(1), h1->GetBinCenter(h1->GetNbinsX() - 1));
218 out->SetName(name);
219 out->SetTitle(name);
220 return out;
221 }
222
223 TH1D *AutoCorrelation(TH1 *h1, double start, double stop, const char *name)
224 {
225 TH1D *out = AutoCorrelation(h1, start, stop);
226 out->SetName(name);
227 out->SetTitle(name);
228 return out;
229 }
230
243 SpinPrec::SpinPrec(double g, double a, double thet, double b, double ts, bool td)
244 {
245 func = new TF1("", "[0]*cos(2.*([1] - (-[2]*[3]*[4]*0.01/[5])*[6]*(x - [7])))", 0, 8192);
246 SetG(g);
247 SetAmp(a);
248 SetTheta(thet);
249 SetB(b);
250 SetTStart(ts);
251 SetTDir(td);
252 func->FixParameter(3, mun);
253 func->FixParameter(5, hbar);
254 func->SetParNames("amp", "theta", "g", "mun", "B", "hbar", "tdir", "tstart");
255 }
256
258 {
259 TF1 *funcclone = (TF1 *)func->Clone();
260 return funcclone;
261 }
262
263
264 } // namespace AngDist
265} // namespace GamR
double SetB(double b)
Definition TDPAD.hh:60
SpinPrec(double g, double a, double thet, double b, double ts, bool td)
Definition TDPAD.cc:243
bool SetTDir(bool dir)
Definition TDPAD.hh:78
double SetTStart(double ts)
Definition TDPAD.hh:72
double SetTheta(double ang)
Definition TDPAD.hh:48
double SetG(double g)
Definition TDPAD.hh:54
double SetAmp(double a)
Definition TDPAD.hh:66
const GamR::TK::Gate * GetGate() const
Definition Transition.hh:39
const GamR::TK::Gate * GetGateBG() const
Definition Transition.hh:40
int GetBinWidth(TH1 *hist) const
Definition Gate.hh:75
TH1D * ApplyX(TH2 *hist) const
Definition Gate.cc:218
TH1D * RatioFunction(TH1 *h1, TH1 *h2)
Definition TDPAD.cc:37
TH1D * AutoCorrelation(TH1 *h1, double start, double stop)
Definition TDPAD.cc:142
Definition Gain.cc:19