52 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
53 double d =
h->GetBinLowEdge(
i+1) -
h->GetBinLowEdge(
i);
55 h->SetBinContent(
i,
h->GetBinContent(
i)/
d );
56 h->SetBinError(
i,
h->GetBinError(
i)/
d );
68 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
if (
h->GetBinContent(
i)==0)
h->SetBinError(
i,1);
74 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
if (
h->GetBinContent(
i)==0)
h->SetBinError(
i,0);
82 for (
int i=0 ;
i<
h->GetNbinsX()+1 ;
i++ ) {
83 sum +=
h->GetBinContent(
i);
84 sume2 +=
h->GetBinError(
i)*
h->GetBinError(
i);
86 if ( sume2!=0 )
return sum*
sum/sume2;
96 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
97 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
98 sum +=
h->GetBinContent(
i,j);
99 sume2 +=
h->GetBinError(
i,j)*
h->GetBinError(
i,j);
103 if ( sume2!=0 )
return sum*
sum/sume2;
118 TAxis& fXaxis = *
h->GetXaxis();
129 Int_t firstBinX = fXaxis.GetFirst();
130 Int_t lastBinX = fXaxis.GetLast();
136 for (
int binx = firstBinX; binx <= lastBinX; binx++) {
137 double x = fXaxis.GetBinCenter(binx);
138 double w = TMath::Abs(
h->GetBinContent(binx));
152 double rms = std::sqrt(
v);
153 double rmserror = std::sqrt(0.25*(sx4/
v-
v*
s))/
s;
165 std::cout <<
"GetStats() "
167 <<
"\trms " <<
stats[2] <<
" +- " <<
stats[3] <<
"\t(" << rmserror1 <<
")" <<
"\t root " << duff << std::endl;
195 int n1,
double a1,
double b1,
196 int n2,
double a2,
double b2) {
205 const std::string name_2d =
"2d";
206 const std::string name_1d =
"1d";
210 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(),
n1, a1, b1, n2, a2, b2);
211 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
216 const std::string name_mean =
"mean";
217 const std::string name_sigma =
"sigma";
218 const std::string name_chi2 =
"chi2";
220 const std::string name_entries =
"fractional uncertainty";
222 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(),
n1, a1, b1 );
225 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(),
n1, a1, b1 );
226 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(),
n1, a1, b1 );
227 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(),
n1, a1, b1 );
237 const std::vector<double>&
a,
238 int n2,
double a2,
double b2) {
244 const std::vector<double>&
a,
245 const std::vector<double>&
b ) {
252 int n1,
const double* a1,
253 int n2,
double a2,
double b2) {
260 const std::string name_2d =
"2d";
261 const std::string name_1d =
"1d";
267 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(),
n1, a1, n2, a2, b2);
268 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
273 const std::string name_mean =
"mean";
274 const std::string name_sigma =
"sigma";
275 const std::string name_chi2 =
"chi2";
277 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(),
n1, a1 );
278 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(),
n1, a1 );
279 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(),
n1, a1);
286 const std::string name_entries =
"fractional uncertainty";
288 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(),
n1, a1 );
297 int n1,
const double* a1,
298 int n2,
const double* a2) {
305 const std::string name_2d =
"2d";
306 const std::string name_1d =
"1d";
312 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(),
n1, a1, n2, a2 );
313 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
318 const std::string name_mean =
"mean";
319 const std::string name_sigma =
"sigma";
320 const std::string name_chi2 =
"chi2";
322 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(),
n1, a1 );
323 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(),
n1, a1 );
324 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(),
n1, a1);
331 const std::string name_entries =
"fractional uncertainty";
333 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(),
n1, a1 );
374 std::ostringstream
s;
382 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
N +=
h->GetBinContent(
i);
396 gStyle->SetOptFit(1111);
397 gStyle->SetOptStat(2211);
400 std::cerr <<
"Resplot::Finalise() " <<
m_name <<
" already called" << std::endl;
415 if (
i%1000==0 ) std::cout <<
"slice " <<
i <<
" of " <<
m_n_primary << std::endl;
418 double pllim =
m_mean->GetBinLowEdge(
i);
419 double pulim =
m_mean->GetBinLowEdge(
i+1);
423 std::string projname;
434 s->SetTitle(projname.c_str());
460 double N =
s->GetEffectiveEntries();
471 m_mean->SetBinContent(
i,
f1->GetParameter(1) );
472 m_mean->SetBinError(
i,
f1->GetParError(1) );
474 m_sigma->SetBinContent(
i, std::fabs(
f1->GetParameter(2)) );
477 int Ndof =
f1->GetNDF();
478 if ( Ndof )
m_chi2->SetBinContent(
i, std::fabs(
f1->GetChisquare())/Ndof );
527 std::string mname = std::string(
f2->GetParName(1));
528 std::string sname = std::string(
f2->GetParName(2));
532 if ( mname!=std::string(
"") ) {
m_mean->SetTitle(mname.c_str()); }
533 if ( sname!=std::string(
"") ) {
m_sigma->SetTitle(sname.c_str()); }
538 if ( !
s_nofit ) std::cerr <<
"null overall fit Resplot:" <<
m_name << std::endl;
550 std::cerr << __FUNCTION__ <<
" for " <<
m_name
551 <<
" :\tdistribution wider than histogram width " << std::endl;
554 std::cerr << __FUNCTION__ <<
" for " <<
m_name
555 <<
" :\tbins too wide: cannot calculate rms95 " << std::endl;
566 std::vector<double>
xbins;
567 std::vector<double>
ybins;
569 TH1D*
hy = (TH1D*)
h->ProjectionX(
"1dx", 1,
h->GetNbinsY());
570 TH1D*
hx = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
575 for (
int i=0 ;
i<=
hx->GetNbinsX()+1 ;
i++ )
xbins.push_back(
hx->GetBinLowEdge(
i+1) );
576 for (
int i=0 ;
i<=
hy->GetNbinsX()+1 ;
i++ )
ybins.push_back(
hy->GetBinLowEdge(
i+1) );
578 std::cout <<
"rotate:" << std::endl;
580 std::cout <<
"x: " <<
xbins[0] <<
" - " <<
xbins.back() << std::endl;
581 std::cout <<
"y: " <<
ybins[0] <<
" - " <<
ybins.back() << std::endl;
583 TH2D* h2 =
new TH2D(
"duff",
"duff",
hx->GetNbinsX(), &
xbins[0],
hy->GetNbinsX(), &
ybins[0] );
585 for (
int i=0 ;
i<
hx->GetNbinsX() ;
i++ ) {
586 for (
int j=0 ; j<
hy->GetNbinsX() ; j++ ) {
587 h2->SetBinContent(j+1,
i+1,
h->GetBinContent(
i+1,j+1));
588 h2->SetBinError(j+1,
i+1,
h->GetBinError(
i+1,j+1));
592 h2->SetEntries(
h->GetEntries() );
608 if (
N==0 )
return 0;
610 std::vector<double>
xbins;
611 std::vector<double>
ybins;
613 TH1D*
hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
614 TH1D*
hy = (TH1D*)
h->ProjectionY(
"r1dy", 1,
h->GetNbinsX());
619 for (
int i=0 ;
i<=
hx->GetNbinsX()+1 ;
i++ ) {
620 xbins.push_back(
hx->GetBinLowEdge(
i+1) );
621 if (
hx->GetBinLowEdge(
i+1)>
x )
for (
int k=1 ;
k<
N ;
k++,
i++ );
624 for (
int i=0 ;
i<=
hy->GetNbinsX()+1 ;
i++ )
ybins.push_back(
hy->GetBinLowEdge(
i+1) );
627 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " <<
xbins.size() <<
"\tN ybins: " <<
ybins.size() << std::endl;
631 std::cout <<
"x: " <<
xbins[0] <<
" - " <<
xbins.back() << std::endl;
632 std::cout <<
"y: " <<
ybins[0] <<
" - " <<
ybins.back() << std::endl;
638 for (
int j=0 ; j<
hy->GetNbinsX() ; j++ ) {
640 for (
int i=0 ;
i<
hx->GetNbinsX() ;
i++ ) {
641 double entries =
h->GetBinContent(
i+1,j+1);
642 double errorsq =
h->GetBinError(
i+1,j+1)*
h->GetBinError(
i+1,j+1);
643 if (
hx->GetBinLowEdge(
i+1)>
x ) {
644 for (
int k=1 ;
k<
N ;
k++,
i++ ) {
646 errorsq +=
h->GetBinError(
i+2,j+1)*
h->GetBinError(
i+2,j+1);
649 h2->SetBinContent(xbin, j+1,
entries);
650 h2->SetBinError(xbin++, j+1, std::sqrt(errorsq) );
654 h2->SetEntries(
h->GetEntries() );
669 if (
N==0 )
return 0;
671 std::vector<double>
xbins;
673 for (
int i=0 ;
i<=
h->GetNbinsX()+1 ;
i++ ) {
674 xbins.push_back(
h->GetBinLowEdge(
i+1) );
675 if (
h->GetBinLowEdge(
i+1)>
x )
for (
int k=1 ;
k<
N ;
k++,
i++ );
678 if (
xbins.size()==0 ) {
679 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " <<
xbins.size() << std::endl;
683 std::cout <<
"x: " <<
xbins[0] <<
" - " <<
xbins.back() << std::endl;
685 TH1D* h2 =
new TH1D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff",
xbins.size()-1, &
xbins[0] );
690 for (
int i=0 ;
i<
h->GetNbinsX() ;
i++ ) {
692 double errorsq =
h->GetBinError(
i+1)*
h->GetBinError(
i+1);
693 if (
h->GetBinLowEdge(
i+1)>
x ) {
694 for (
int k=1 ;
k<
N ;
k++,
i++ ) {
696 errorsq +=
h->GetBinError(
i+2)*
h->GetBinError(
i+2);
700 h2->SetBinContent(xbin,
entries);
701 h2->SetBinError(xbin++, std::sqrt(errorsq) );
704 h2->SetEntries(
h->GetEntries() );
717 std::cout <<
"combine" << std::endl;
721 std::vector<double>
xbins;
722 std::vector<double>
ybins;
724 std::cout <<
"projection" << std::endl;
726 TH1D*
hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
739 std::cout <<
"combining bins " << std::endl;
741 for (
int i=1 ;
i<=
hx->GetNbinsX() ;
i++ ) {
743 TH1D*
hy = (TH1D*)
h->ProjectionY(
"r1dy",
i,
i );
748 if (
xbins.size()==0 ) {
749 if (
N==0 )
continue;
750 else xbins.push_back(
hx->GetBinLowEdge(
i) );
753 if ( newbin )
xbins.push_back(
hx->GetBinLowEdge(
i+1) );
754 else xbins.back() =
hx->GetBinLowEdge(
i+1);
758 if (
xbins.size()>0 ) std::cout <<
i <<
"\tN " <<
N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" <<
xbins.back() << std::endl;
760 if (
N >= inveps2 ) {
766 std::cout <<
"finishsed " <<
xbins.size() << std::endl;
768 TH1D*
hy = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
770 for (
int i=0 ;
i<=
hy->GetNbinsX()+1 ;
i++ )
ybins.push_back(
hy->GetBinLowEdge(
i+1) );
772 std::cout <<
"combine" << std::endl;
773 std::cout <<
"x bins " <<
hx->GetNbinsX() <<
"\t y bins " <<
hy->GetNbinsX() << std::endl;
776 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " <<
xbins.size() <<
"\tN ybins: " <<
ybins.size() << std::endl;
780 std::cout <<
"x: " <<
xbins.size() <<
" " <<
xbins[0] <<
" - " <<
xbins.back() << std::endl;
781 std::cout <<
"y: " <<
ybins.size() <<
" " <<
ybins[0] <<
" - " <<
ybins.back() << std::endl;
783 TH2D* h2 =
new TH2D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff",
xbins.size()-1, &
xbins[0],
ybins.size()-1, &
ybins[0] );
787 for (
int j=1 ; j<=
hy->GetNbinsX() ; j++ ) {
791 for (
int i=1 ;
i<=
hx->GetNbinsX() ;
i++ ) {
793 while (
hx->GetBinCenter(
i)>
xbins[xbin+1] && xbin<(
xbins.size()-1) ) xbin++;
795 if (
hx->GetBinCenter(
i)>=
xbins[xbin] &&
hx->GetBinCenter(
i)<
xbins[xbin+1] ) {
798 double n =
h->GetBinContent(
i,j);
799 double nh = h2->GetBinContent(xbin+1, j);
800 h2->SetBinContent(xbin+1, j, nh+
n);
803 double ne =
h->GetBinError(
i,j);
804 double nhe = h2->GetBinError(xbin+1, j);
805 h2->SetBinError(xbin+1, j, std::sqrt( ne*ne + nhe*nhe ) );
812 h2->SetEntries(
h->GetEntries() );
840 std::cout <<
"combine" << std::endl;
844 std::vector<double>
xbins;
856 std::cout <<
"combining bins " << std::endl;
858 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
860 N +=
h->GetBinContent(
i);
862 if (
xbins.size()==0 ) {
863 if (
N==0 )
continue;
864 else xbins.push_back(
h->GetBinLowEdge(
i) );
867 if ( newbin )
xbins.push_back(
h->GetBinLowEdge(
i+1) );
868 else xbins.back() =
h->GetBinLowEdge(
i+1);
872 if (
xbins.size()>0 ) std::cout <<
i <<
"\tN " <<
N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" <<
xbins.back() << std::endl;
874 if (
N >= inveps2 ) {
880 std::cout <<
"finishsed " <<
xbins.size() << std::endl;
882 std::cout <<
"combine" << std::endl;
883 std::cout <<
"x bins " <<
h->GetNbinsX() << std::endl;
885 std::cout <<
"x: " <<
xbins.size() <<
" " <<
xbins[0] <<
" - " <<
xbins.back() << std::endl;
893 if (
xbins.size()==0 ) {
894 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " <<
xbins.size() << std::endl;
898 TH1D* h2 =
new TH1D(
"duff",
"duff",
xbins.size()-1, &
xbins[0] );
902 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
904 while (
h->GetBinCenter(
i)>
xbins[xbin+1] && xbin<(
xbins.size()-1) ) xbin++;
906 if (
h->GetBinCenter(
i)>=
xbins[xbin] &&
h->GetBinCenter(
i)<
xbins[xbin+1] ) {
907 double n =
h->GetBinContent(
i);
908 double nh = h2->GetBinContent(xbin+1);
909 h2->SetBinContent(xbin+1, nh+
n);
922 std::vector<double>
bins(
h->GetNbinsX()+1);
923 for (
int i=0 ;
i<
h->GetNbinsX()+1 ;
i++ )
bins[
i] =
h->GetBinLowEdge(
i+1);
937 for (
int i=0 ;
i<=
h->GetNbinsX()+1 ;
i++ ) {
938 total +=
h->GetBinContent(
i);
940 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
941 double x =
h->GetBinCenter(
i);
943 good +=
h->GetBinContent(
i);
947 v.value =
good/total;
948 v.error = sqrt(
v.value*(1-
v.value)/total);
963 TH1D*
e = (TH1D*)
m_mean->Clone();
964 e->SetName(
hname.c_str());
e->SetMarkerStyle(20);
971 e->SetBinContent(
i,
v.value);
972 e->SetBinError(
i,
v.error);
997 TH1D*
e = (TH1D*)
m_mean->Clone();
998 e->SetName(
hname.c_str());
e->SetMarkerStyle(20);
1009 e->SetBinContent(
i,
v.value);
1010 e->SetBinError(
i,
v.error);
1026 TF1*
f1 =
new TF1(
"gausr",
"gaus");
1032 TF1*
f1 =
new TF1(
"rgausr",
"[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
1037 TF1*
f1 =
new TF1(
"rbreitr",
"x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1039 f1->SetParName(0,
"Maximum");
1040 f1->SetParName(1,
"Median");
1041 f1->SetParName(2,
"Gamma");
1043 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1044 f1->SetParameter(1,
s->GetMean());
1045 f1->SetParameter(2,
s->GetRMS());
1053 if (
f1==0 )
return f1;
1056 f1->SetLineWidth(1);
1062 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1063 f1->SetParameter(1,
mean=
s->GetBinCenter(
s->GetMaximumBin()));
1064 f1->SetParameter(2,
sigma=
s->GetRMS());
1067 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j))
nbins++;
1070 if (
a==-999 ||
b==-999 )
s->Fit(
f1,
"Q");
1071 else s->Fit(
f1,
"Q",
"",
a,
b);
1073 else for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j, 0);
1081 TF1*
f1 =
new TF1(
"gausr",
"gaus");
1084 f1->SetLineWidth(1);
1090 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1091 f1->SetParameter(1,
mean=
s->GetBinCenter(
s->GetMaximumBin()));
1092 f1->SetParameter(2,
sigma=
s->GetRMS());
1095 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j))
nbins++;
1099 TH1D* s_tmp = (TH1D*)
s->Clone(
"duff");
1100 s_tmp->SetDirectory(0);
1124 double llim =
f1->GetParameter(1)-
frac*
f1->GetParameter(2);
1125 double ulim =
f1->GetParameter(1)+
frac*
f1->GetParameter(2);
1130 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinCenter(j)>llim &&
s->GetBinCenter(j)<ulim )
nbins++;
1138 else s->Fit(
f1,
"Q",
"", llim, ulim);
1141 else for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j, 0);
1150 else for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j, 0);
1162 TF1*
f1 =
new TF1(
"breitr",
"[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1164 f1->SetParName(0,
"Maximum");
1165 f1->SetParName(1,
"Median");
1166 f1->SetParName(2,
"Gamma");
1168 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1169 f1->SetParameter(1,
s->GetMean());
1170 f1->SetParameter(2,
s->GetRMS()*0.5);
1173 f1->SetLineWidth(1);
1175 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j)==0)
s->SetBinError(j, 1);
1179 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j)>0)
nbins++;
1183 if (
a==-999 ||
b==-999 )
s->Fit(
f1,
"Q");
1184 else s->Fit(
f1,
"Q",
"",
a,
b);
1187 for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j,0);
1190 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j)==0)
s->SetBinError(j, 0);
1223 std::cout <<
"Resplot::FitATan() " <<
s->GetName() <<
" " <<
s->GetTitle() << std::endl;
1229 TF1*
f1 =
new TF1(
name,
"100*pow( (0.01*[3]-sqrt(0.0001*[2]*[2]))*(0.5-(1/3.14159)*atan( [1]*(x-[0]) ) )+sqrt(0.0001*[2]*[2]) , [4] ) ", -100, 100);
1231 f1->SetParName(0,
"Mean");
1232 f1->SetParName(1,
"Gradient");
1233 f1->SetParName(2,
"Pedestal");
1234 f1->SetParName(3,
"Norm");
1235 f1->SetParName(4,
"Power");
1238 for (
int i=1 ;
i<=
s->GetNbinsX() ;
i++ )
if (
s->GetBinContent(maxn)<
s->GetBinContent(
i) ) maxn =
i;
1245 f1->SetParameter(0, 2 );
1246 f1->SetParameter(1, 10 );
1247 f1->SetParameter(2, 0.001 );
1248 f1->SetParameter(3, 100 );
1249 f1->SetParameter(4, 1 );
1251 f1->FixParameter(2, 0);
1252 f1->FixParameter(3, 100);
1256 f1->SetLineWidth(1);
1263 s->SetMarkerStyle(20);
1272 std::cout <<
"par0 = " <<
f1->GetParameter(0) << std::endl;
1273 std::cout <<
"par1 = " <<
f1->GetParameter(1) << std::endl;
1274 std::cout <<
"par2 = " <<
f1->GetParameter(2) << std::endl;
1275 std::cout <<
"par3 = " <<
f1->GetParameter(3) << std::endl;
1276 std::cout <<
"par4 = " <<
f1->GetParameter(4) << std::endl;
1292 TF1*
f=
new TF1(
"null",
"[0]+[1]+[2]");
1294 f->SetParName(0,
"Maximum");
1295 f->SetParName(1,
"Mean");
1296 f->SetParName(2,
"RMS");
1298 f->FixParameter(0,
s->GetMaximum());
f->SetParError(0, sqrt(
s->GetMaximum()));
1299 f->FixParameter(1,
s->GetMean());
f->SetParError(1,
s->GetMeanError());
1300 f->FixParameter(2,
s->GetRMS());
f->SetParError(2,
s->GetRMSError());
1320 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1322 double mean =
s->GetMean();
1323 double meane =
s->GetMeanError();
1329 for (
int it=0 ;
it<20 ;
it++ ) {
1333 int imax =
s->GetXaxis()->FindBin(
mean);
1335 double sumn =
s->GetBinContent(
imax);
1347 const int upperbin_i =
imax+
i;
1348 const int lowerbin_i =
imax-
i;
1350 if ( upperbin_i>
s->GetNbinsX() || lowerbin_i<1 )
break;
1352 double tsum = sumn +
s->GetBinContent(upperbin_i) +
s->GetBinContent(lowerbin_i);
1363 upperbin = upperbin_i;
1364 lowerbin = lowerbin_i;
1369 s->GetXaxis()->SetRange(lowerbin, upperbin);
1371 double m =
s->GetMean();
1372 double me =
s->GetMeanError();
1376 std::fabs(
mean-
m)<me*1
e-5 ||
1377 std::fabs(
mean-
m)<meane*1
e-5 ) {
1398 for (
int i=2 ;
i<=
s->GetNbinsX() ;
i++ ) {
1400 if (
s->GetBinContent(
i)>
s->GetBinContent(
imax) )
imax =
i;
1410 TF1*
f=
new TF1(
"null",
"[0]+[1]+[2]");
1412 f->SetParName(0,
"Maximum");
1413 f->SetParName(1,
"Mean");
1414 f->SetParName(2,
"RMS");
1416 f->SetParameter(0, 0);
1417 f->SetParameter(1, 0);
1418 f->SetParameter(2, 0);
1420 if (
s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " <<
s << std::endl;
return 0; }
1421 if (
s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " <<
s->GetName() << std::endl;
return 0; }
1425 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1428 std::cout <<
"FitNull95 " <<
s->GetName()
1456 int imax =
s->GetXaxis()->FindBin(
m);
1460 f->FixParameter(0,
s->GetMaximum());
f->SetParError(0, std::sqrt(
s->GetMaximum()));
1471 double sumn =
s->GetBinContent(
imax);
1473 int upperbin =
imax;
1474 int lowerbin =
imax;
1476 double uppersum = 0;
1477 double lowersum = 0;
1480 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1490 const int upperbin_i =
imax+
i;
1491 const int lowerbin_i =
imax-
i;
1493 if ( upperbin_i>
s->GetNbinsX() || lowerbin_i<1 )
break;
1495 double tsum = sumn +
s->GetBinContent(upperbin_i) +
s->GetBinContent(lowerbin_i);
1510 upperbin = upperbin_i;
1511 lowerbin = lowerbin_i;
1519 if ( uppersum==0 ) {
1520 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1536 double llim =
s->GetBinLowEdge(1);
1537 double ulim =
s->GetBinLowEdge(
s->GetNbinsX()+1);
1542 std::vector<double>
stats;
1549 s->GetXaxis()->SetRange(lowerbin, upperbin);
1568 rlower =
s->GetRMS();
1569 erlower =
s->GetRMSError();
1575 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1587 rupper =
s->GetRMS();
1588 erupper =
s->GetRMSError();
1598 rms = rlower + (
frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1599 erms = erlower + (
frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1603 s->GetXaxis()->SetRange(lowerbin, upperbin);
1611 erms =
s->GetRMSError();
1617 std::cout <<
"numbers " <<
s->GetName()
1621 std::cout <<
"fractions " <<
s->GetName()
1625 std::cout <<
"lowersum " <<
s->GetName() <<
"\t" << lowersum <<
"\tuppersum " << uppersum << std::endl;
1627 std::cout <<
"limits " <<
s->GetName() <<
"\t" <<
s->GetBinLowEdge(lowerbin) <<
" - " <<
s->GetBinLowEdge(upperbin+1) << std::endl;
1631 std::cout <<
"FitNULL95Obsolete() " <<
s->GetName() <<
"\t rms " <<
rms <<
" +- " << erms <<
"\t inv " << 1/
rms << std::endl;
1633 printf(
"rms %12.10lf inv %12.10lf\n",
rms, 1/
rms );
1635 printf(
"rms68 %12.10lf inv %12.10lf\n",
rms/0.5369760683,
rms*1.8622803865 );
1649 f->SetParError(2,
scale*erms);
1650 f->FixParameter(1,
s->GetMean());
1651 f->SetParError(1,
s->GetMeanError());
1653 s->GetXaxis()->SetRangeUser(llim, ulim);
1657 f->FixParameter(1, 0);
1658 f->SetParError(1, 0);
1659 f->FixParameter(2, 0);
1660 f->SetParError(2, 0);
1664 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1691 TF1*
f=
new TF1(
"null",
"[0]+[1]+[2]");
1693 f->SetParName(0,
"Maximum");
1694 f->SetParName(1,
"Mean");
1695 f->SetParName(2,
"RMS");
1697 f->SetParameter(0, 0);
1698 f->SetParameter(1, 0);
1699 f->SetParameter(2, 0);
1701 if (
s->GetEffectiveEntries()==0 )
return f;
1705 const double entries =
s->GetEffectiveEntries();
1733 f->FixParameter( 1,
e.hmean() );
1734 f->SetParError( 1,
e.mean_error() );
1736 f->FixParameter( 2,
scale*
e.hrms() );
1737 f->SetParError( 2,
scale*
e.rms_error() );
1756 TF1*
f=
new TF1(
"null",
"[0]+[1]+[2]");
1758 f->SetParName(0,
"Maximum");
1759 f->SetParName(1,
"Mean");
1760 f->SetParName(2,
"RMS");
1762 f->SetParameter(0, 0);
1763 f->SetParameter(1, 0);
1764 f->SetParameter(2, 0);
1766 if (
s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " <<
s << std::endl;
return 0; }
1767 if (
s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " <<
s->GetName() << std::endl;
return 0; }
1774 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1786 f->FixParameter(0,
s->GetMaximum());
f->SetParError(0, sqrt(
s->GetMaximum()));
1790 double entries =
s->GetEntries() +
s->GetBinContent(0) +
s->GetBinContent(
s->GetNbinsX()+1);
1794 double sumn =
s->GetBinContent(
imax);
1798 int upperbin =
imax;
1799 int lowerbin =
imax;
1801 double uppersum = 0;
1802 double lowersum = 0;
1809 const int upperbin_i =
imax+
i;
1810 const int lowerbin_i =
imax-
i;
1812 if ( upperbin_i>
s->GetNbinsX() || lowerbin_i<1 )
break;
1814 double tsum = sumn +
s->GetBinContent(upperbin_i) +
s->GetBinContent(lowerbin_i);
1822 upperbin = upperbin_i;
1823 lowerbin = lowerbin_i;
1837 if ( upperbin!=lowerbin ) {
1839 double llim =
s->GetBinLowEdge(1);
1840 double ulim =
s->GetBinLowEdge(
s->GetNbinsX()+1);
1845 std::vector<double>
stats;
1848 s->GetXaxis()->SetRange(lowerbin, upperbin);
1867 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1877 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1878 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1882 s->GetXaxis()->SetRange(lowerbin, upperbin);
1892 f->FixParameter(2,
rms);
1893 f->SetParError(2, erms);
1894 f->FixParameter(1,
s->GetMean());
1895 f->SetParError(1,
s->GetMeanError());
1897 s->GetXaxis()->SetRangeUser(llim, ulim);
1900 f->FixParameter(1, 0);
1901 f->SetParError(1, 0);
1902 f->FixParameter(2, 0);
1903 f->SetParError(2, 0);
1907 s->GetXaxis()->SetRange(1,
s->GetNbinsX());
1929 sprintf(fstring,
"sqrt([0]*[0])*pow(sqrt([1]*[1]*([2]*[2])),x*[2]-[3])*exp(-sqrt([1]*[1]*([2]*[2])))/TMath::Gamma((x*[2]-[3])+1)");
1930 TF1 *
f1 =
new TF1(
"poisson", fstring );
1933 f1->SetParName(0,
"Maximum");
1934 f1->SetParName(1,
"Mean");
1935 f1->SetParName(2,
"Scale");
1936 f1->SetParName(3,
"Offset");
1939 f1->SetLineWidth(1);
1940 f1->SetLineColor(
s->GetLineColor());
1943 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j)>0)
nbins++;
1945 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1946 f1->SetParameter(1,
s->GetBinCenter(
s->GetMaximumBin()));
1947 f1->SetParameter(2,1);
1948 f1->FixParameter(3,0);
1954 if (
a==-999 ||
b==-999 )
s->Fit(
f1);
1955 else s->Fit(
f1,
"",
"",
a,
b);
1958 for (
int j=0 ; j<4 ; j++ )
f1->SetParameter(j,0);
1971 TF1*
f1 =
new TF1(
"xexpr",
"[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1973 f1->SetParName(0,
"Normalisation");
1974 f1->SetParName(1,
"Power");
1975 f1->SetParName(2,
"Lifetime");
1976 f1->SetParName(3,
"offset");
1979 f1->SetParameter(0,
s->GetBinContent(
s->GetMaximumBin()) );
1981 f1->SetParameter(2,
s->GetRMS() );
1983 f1->SetParameter(1, 0);
1984 f1->SetParameter(3, 0);
1992 f1->SetLineWidth(1);
1995 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j)>0)
nbins++;
2001 if (
a==-999 ||
b==-999 )
s->Fit(
f1,
"Q");
2002 else s->Fit(
f1,
"Q",
"",
a,
b);
2005 for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j,0);
2032 Double_t invsq2pi = 0.3989422804014;
2033 Double_t mpshift = -0.22278298;
2039 double&
x = x_par[0];
2053 mpc =
par[1] - mpshift*
par[2];
2065 for(
i=1.0;
i<=
np/2;
i++) {
2066 xx = xlow + (
i-0.5)*
step;
2067 fland = TMath::Landau(xx,mpc,
par[2]) /
par[2];
2068 sum += fland * TMath::Gaus(
x,xx,
par[3]);
2070 xx = xupp - (
i-0.5)*
step;
2071 fland = TMath::Landau(xx,mpc,
par[2]) /
par[2];
2072 sum += fland * TMath::Gaus(
x,xx,
par[3]);
2086 TF1*
f1 =
new TF1(
"landgaus",
langaufun, 0, 1, 4);
2089 f1->SetLineWidth(1);
2092 double start_vals[4];
2094 start_vals[0] =
s->GetEntries();
2095 start_vals[1] =
s->GetBinCenter(
s->GetMaximumBin());
2096 start_vals[2] =
s->GetRMS();
2097 start_vals[3] = 0.5*start_vals[2];
2099 f1->SetParNames(
"Area",
"MP",
"Width",
"GSigma");
2100 f1->SetParameters(start_vals);
2106 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
2107 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
2110 for (
int j=1 ; j<=
s->GetNbinsX() ; j++)
if (
s->GetBinContent(j))
nbins++;
2113 if (
a==-999 ||
b==-999 )
s->Fit(
f1,
"Q");
2114 else s->Fit(
f1,
"Q",
"",
a,
b);
2118 else for (
int j=0 ; j<3 ; j++ )
f1->SetParameter(j, 0);