92 if(fithist ==
nullptr) {
93 std::cout <<
"No histogram is associated yet, no initial guesses made" << std::endl;
99 GetRange(xlow, xhigh);
101 Int_t binlow = fithist->GetXaxis()->FindBin(xlow);
102 Int_t binhigh = fithist->GetXaxis()->FindBin(xhigh);
104 Double_t highy = fithist->GetBinContent(binlow);
105 Double_t lowy = fithist->GetBinContent(binhigh);
106 for(
int x = 1; x < 5; x++) {
107 highy += fithist->GetBinContent(binlow - x);
108 lowy += fithist->GetBinContent(binhigh + x);
114 std::swap(lowy, highy);
117 double largestx = 0.0;
118 double largesty = 0.0;
120 for(; i <= binhigh; i++) {
121 if(fithist->GetBinContent(i) > largesty) {
122 largesty = fithist->GetBinContent(i);
123 largestx = fithist->GetXaxis()->GetBinCenter(i);
134 TF1::SetParLimits(0, 0, largesty * 2);
135 TF1::SetParLimits(1, xlow, xhigh);
136 TF1::SetParLimits(2, 0, xhigh - xlow);
139 TF1::SetParameter(0, largesty);
140 TF1::SetParameter(1, largestx);
141 TF1::SetParameter(2, (largestx * .01) / 2.35);
143 TF1::SetParError(0, 0.10 * largesty);
144 TF1::SetParError(1, 0.25);
145 TF1::SetParError(2, 0.10 * ((largestx * .01) / 2.35));
153 if(fithist ==
nullptr) {
156 TString options = opt;
160 TVirtualFitter::SetMaxIterations(100000);
162 bool verbose = !options.Contains(
"Q");
163 bool noprint = options.Contains(
"no-print");
165 options.ReplaceAll(
"no-print",
"");
168 if(fithist->GetSumw2()->fN != fithist->GetNbinsX() + 2) {
172 TFitResultPtr fitres = fithist->Fit(
this, Form(
"%sRSME", options.Data()));
174 if(!fitres.Get()->IsValid()) {
176 std::cout <<
RED <<
"fit has failed, trying refit... " <<
RESET_COLOR;
178 fithist->GetListOfFunctions()->Last()->Delete();
179 fitres = fithist->Fit(
this, Form(
"%sRSME", options.Data()));
180 if(fitres.Get()->IsValid()) {
181 if(!verbose && !noprint) {
185 if(!verbose && !noprint) {
186 std::cout <<
DRED <<
" refit also failed :( " <<
RESET_COLOR << std::endl;
193 TF1::GetRange(xlow, xhigh);
195 std::array<double, 2> bgpars = {TF1::GetParameters()[3], TF1::GetParameters()[4]};
197 fBGFit.SetParameters(bgpars.data());
199 fArea = Integral(xlow, xhigh) / fithist->GetBinWidth(1);
200 double bgArea =
fBGFit.Integral(xlow, xhigh) / fithist->GetBinWidth(1);
205 std::swap(xlow, xhigh);
207 fSum = fithist->Integral(fithist->GetXaxis()->FindBin(xlow),
208 fithist->GetXaxis()->FindBin(xhigh));
209 std::cout <<
"sum between markers: " <<
fSum << std::endl;
212 std::cout <<
"sum after subtraction: " <<
fSum << std::endl;
214 if(!verbose && !noprint) {
218 Copy(*fithist->GetListOfFunctions()->FindObject(GetName()));
219 fithist->GetListOfFunctions()->Add(
fBGFit.Clone());
259 if(
hist ==
nullptr) {
262 if(
fChi2 < 0.000000001) {
263 std::cout <<
"No fit performed" << std::endl;
268 GetRange(xlow, xhigh);
269 Int_t nbins =
hist->GetXaxis()->GetNbins();
270 auto* res =
new Double_t[nbins];
271 auto* bin =
new Double_t[nbins];
273 for(
int i = 1; i <= nbins; i++) {
274 if(
hist->GetBinCenter(i) <= xlow ||
hist->GetBinCenter(i) >= xhigh) {
277 res[points] = (
hist->GetBinContent(i) - Eval(
hist->GetBinCenter(i))) + GetParameter(
"Height") / 2;
278 bin[points] =
hist->GetBinCenter(i);
282 auto* residuals =
new TGraph(points, bin, res);
283 residuals->Draw(
"*AC");