1 Double_t gausBack (Double_t *x, Double_t *par)
3 Double_t sigma = par[3];
4 Double_t mean = par[2];
5 Double_t sigfrac = par[1];
6 Double_t backfrac = 1.-sigfrac;
10 Double_t gaus = 1./(sqrt(2.*3.14159265)*sigma*TMath::Erf(sqrt(2)))*
11 exp(-0.5*(x[0]-mean)*(x[0]-mean)/(sigma*sigma));
12 Double_t back = 1./(4.*sigma);
14 Double_t fitval = amp*(backfrac*back + sigfrac*gaus);
17 Double_t erfBack (Double_t *x, Double_t *par)
19 Double_t sigma = par[3];
20 Double_t mean = par[2];
21 Double_t sigfrac = par[1];
22 Double_t backfrac = 1.-sigfrac;
23 Double_t amp = par[0];
24 Double_t blah1 = TMath::Erf(-(x[0]-0.4-mean)/sigma);
25 Double_t blah2 = TMath::Erf((x[0]+0.4-mean)/sigma);
26 Double_t gaus = 0.5*(blah1+blah2);
28 Double_t fitval =amp*(backfrac + sigfrac*gaus);
33 fitSlice (
void* func,TH2D* hist, Int_t nhists)
35 TGraphErrors** retGraphs =
new TGraphErrors*[5];
36 TH1D** hists =
new TH1D*[nhists];
37 Int_t nbins = hist->GetNbinsX();
38 Double_t* x =
new Double_t[nhists];
39 Double_t* ex =
new Double_t[nhists];
41 for (Int_t i=0; i< nhists; ++i) {
42 Int_t low = i*(nbins/nhists)+1;
43 Int_t high = (i+1)*(nbins/nhists);
44 Double_t xlow = hist->GetXaxis()->GetBinLowEdge(low);
45 Double_t xhigh = hist->GetXaxis()->GetBinUpEdge(high);
46 x[i] = (xlow + xhigh)/2.;
47 ex[i] = (xhigh-xlow)/2.;
49 Char_t* blah =
new Char_t[100];
50 Char_t* blah2 = hist->GetName();
52 sprintf(blah,
"%s_proj%d",blah2,i);
54 hists[i] = hist->ProjectionY(blah,low,high,
"E");
57 TF1* gausBack =
new TF1(
"gausBack",func,-3,3,4);
58 gausBack->SetParNames(
"2 Sigma Sum",
"2 Sigma Signal Fraction",
"Mean",
"Sigma");
59 Double_t* amp =
new Double_t[nhists];
60 Double_t* sigfrac =
new Double_t[nhists];
61 Double_t* mean =
new Double_t[nhists];
62 Double_t* sigma =
new Double_t[nhists];
63 Double_t* chisq =
new Double_t[nhists];
65 Double_t* eamp =
new Double_t[nhists];
66 Double_t* esigfrac =
new Double_t[nhists];
67 Double_t* emean =
new Double_t[nhists];
68 Double_t* esigma =
new Double_t[nhists];
69 Double_t* echisq =
new Double_t[nhists];
71 for (Int_t i=0; i< nhists; ++i) {
72 TH1D* histslice = hists[i];
73 gausBack->SetParameters(histslice->GetMaximum()*histslice->GetRMS(),1,
74 histslice->GetMean(),histslice->GetRMS());
75 printf(
"Original parameters: %f %f %f %f",histslice->GetMaximum()*histslice->GetRMS(),
76 1,histslice->GetMean(),histslice->GetRMS());
78 if (histslice->GetMaximum()>4.) {
80 histslice->Fit(
"gausBack",
"EL");
81 amp[i] = gausBack->GetParameter(0);
82 sigfrac[i] = gausBack->GetParameter(1);
83 mean[i] = gausBack->GetParameter(2);
84 sigma[i] = gausBack->GetParameter(3);
85 chisq[i] = gausBack->GetChisquare();
87 eamp[i] = gausBack->GetParError(0);
88 esigfrac[i] = gausBack->GetParError(1);
89 emean[i] = gausBack->GetParError(2);
90 esigma[i] = gausBack->GetParError(3);
109 retGraphs[0] =
new TGraphErrors(nhists,x,amp,ex,eamp);
110 retGraphs[1] =
new TGraphErrors(nhists,x,sigfrac,ex,esigfrac);
111 retGraphs[2] =
new TGraphErrors(nhists,x,mean,ex,emean);
112 retGraphs[3] =
new TGraphErrors(nhists,x,sigma,ex,esigma);
113 retGraphs[4] =
new TGraphErrors(nhists,x,chisq,ex,echisq);
114 retGraphs[0]->SetTitle(
"2 Sigma Sum");
115 retGraphs[1]->SetTitle(
"2 Sigma Signal Fraction");
116 retGraphs[2]->SetTitle(
"Mean");
117 retGraphs[3]->SetTitle(
"Sigma");
118 retGraphs[4]->SetTitle(
"Chi-squared");
125 gausSlice (TH2D* hist, Int_t nhists)
128 TGraphErrors** retval = fitSlice(gausBack,hist,nhists);
132 erfSlice (TH2D* hist, Int_t nhists)
135 TGraphErrors** retval = fitSlice(erfBack,hist,nhists);
140 funcFit (
void* func,TH1D* histslice)
142 TGraphErrors** retGraphs =
new TGraphErrors*[5];
146 TF1* gausBack =
new TF1(
"gausBack",func,-3,3,4);
147 gausBack->SetParNames(
"2 Sigma Sum",
"2 Sigma Signal Fraction",
"Mean",
"Sigma");
148 Double_t* amp =
new Double_t[nhists];
149 Double_t* sigfrac =
new Double_t[nhists];
150 Double_t* mean =
new Double_t[nhists];
151 Double_t* sigma =
new Double_t[nhists];
152 Double_t* chisq =
new Double_t[nhists];
154 Double_t* eamp =
new Double_t[nhists];
155 Double_t* esigfrac =
new Double_t[nhists];
156 Double_t* emean =
new Double_t[nhists];
157 Double_t* esigma =
new Double_t[nhists];
158 Double_t* echisq =
new Double_t[nhists];
159 gausBack->SetParameters(histslice->GetMaximum()*histslice->GetRMS(),1,
160 histslice->GetMean(),histslice->GetRMS());
162 printf(
"Original parameters: %f %f %f %f",histslice->GetMaximum(),
163 1,histslice->GetMean(),histslice->GetRMS());
165 if (histslice->GetMaximum()) {
167 histslice->Fit(
"gausBack");
168 amp[i] = gausBack->GetParameter(0);
169 sigfrac[i] = gausBack->GetParameter(1);
170 mean[i] = gausBack->GetParameter(2);
171 sigma[i] = gausBack->GetParameter(3);
172 chisq[i] = gausBack->GetChisquare();
174 eamp[i] = gausBack->GetParError(0);
175 esigfrac[i] = gausBack->GetParError(1);
176 emean[i] = gausBack->GetParError(2);
177 esigma[i] = gausBack->GetParError(3);
203 TGraphErrors** retval = funcFit(erfBack,hist);
210 TGraphErrors** retval = funcFit(gausBack,hist);