shiftHistFit.cxx
Go to the documentation of this file.
1 // shiftHistFit.cxx
2 
4 #include "quietHistFit.h"
5 #include "TFitResult.h"
6 
7 #include "TF1.h"
8 #include "TH1F.h"
9 
10 //**********************************************************************
11 
12 int shiftHistFit(TH1* ph, TF1* pf, std::string fopt, int ipar, double xshift) {
13  if ( ipar < 0 || ipar >= pf->GetNpar() ) return 101;
14  // Shift the histogram
15  TAxis* pax = ph->GetXaxis();
16  double xh1Min = pax->GetXmin();
17  double xh1Max = pax->GetXmax();
18  double xh2Min = xh1Min - xshift;
19  double xh2Max = xh1Max - xshift;
20  pax->SetLimits(xh2Min, xh2Max);
21  // Shift the function.
22  double xf1Min = pf->GetXmin();
23  double xf1Max = pf->GetXmax();
24  double xf1Par = pf->GetParameter(ipar);
25  double xf1Llo = 0.0;
26  double xf1Lhi = 0.0;
27  pf->GetParLimits(ipar, xf1Llo, xf1Lhi);
28  bool haveLimits = xf1Llo || xf1Lhi;
29  double xf2Min = xf1Min - xshift;
30  double xf2Max = xf1Max - xshift;
31  double xf2Par = xf1Par - xshift;
32  double xf2Llo = xf1Llo - xshift;
33  double xf2Lhi = xf1Lhi - xshift;
34  pf->SetRange(xf2Min, xf2Max);
35  pf->SetParameter(ipar, xf2Par);
36  if ( haveLimits ) pf->SetParLimits(ipar, xf2Llo, xf2Lhi);
37  // Perform fit.
38  int fstat = quietHistFit(ph, pf, fopt);
39  // Shift function back.
40  xf2Par = pf->GetParameter(ipar);
41  xf1Min = xf2Min + xshift;
42  xf1Max = xf2Max + xshift;
43  xf1Par = xf2Par + xshift;
44  pf->SetRange(xf1Min, xf1Max);
45  pf->SetParameter(ipar, xf1Par);
46  if ( haveLimits ) pf->SetParLimits(ipar, xf1Llo, xf1Lhi);
47  // Shift histogram back.
48  pax->SetLimits(xh1Min, xh1Max);
49  return fstat;
50 }
51 
52 //**********************************************************************
53 
54 int shiftHistFit(TH1* ph, TF1* pf, std::string fopt, std::string spar, double xshift) {
55  int ipar = pf->GetParNumber(spar.c_str());
56  return shiftHistFit(ph, pf, fopt, ipar, xshift);
57 }
58 
59 //**********************************************************************
std::string string
Definition: nybbler.cc:12
int shiftHistFit(TH1 *ph, TF1 *pf, std::string fopt, int ipar, double xshift)
int quietHistFit(TH1 *ph, std::string fname, std::string fopt)