51 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
52 double d =
h->GetBinLowEdge(i+1) -
h->GetBinLowEdge(i);
54 h->SetBinContent(i,
h->GetBinContent(i)/d );
55 h->SetBinError(i,
h->GetBinError(i)/d );
67 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ )
if (
h->GetBinContent(i)==0)
h->SetBinError(i,1);
73 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ )
if (
h->GetBinContent(i)==0)
h->SetBinError(i,0);
81 for (
int i=0 ; i<
h->GetNbinsX()+1 ; i++ ) {
82 sum +=
h->GetBinContent(i);
83 sume2 +=
h->GetBinError(i)*
h->GetBinError(i);
85 if ( sume2!=0 )
return sum*sum/sume2;
95 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
96 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
97 sum +=
h->GetBinContent(i,j);
98 sume2 +=
h->GetBinError(i,j)*
h->GetBinError(i,j);
102 if ( sume2!=0 )
return sum*sum/sume2;
117 TAxis& fXaxis = *
h->GetXaxis();
128 Int_t firstBinX = fXaxis.GetFirst();
129 Int_t lastBinX = fXaxis.GetLast();
135 for (
int binx = firstBinX; binx <= lastBinX; binx++) {
136 double x = fXaxis.GetBinCenter(binx);
137 double w = TMath::Abs(
h->GetBinContent(binx));
149 double v = sx2/s-mu*mu;
151 double rms = std::sqrt(v);
152 double rmserror = std::sqrt(0.25*(sx4/v-v*s))/s;
156 stats[1] = std::sqrt(v/s);
164 std::cout <<
"GetStats() "
166 <<
"\trms " << stats[2] <<
" +- " << stats[3] <<
"\t(" << rmserror1 <<
")" <<
"\t root " << duff << std::endl;
194 int n1,
double a1,
double b1,
195 int n2,
double a2,
double b2) {
204 const std::string name_2d =
"2d";
205 const std::string name_1d =
"1d";
209 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, b1, n2, a2, b2);
210 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
215 const std::string name_mean =
"mean";
216 const std::string name_sigma =
"sigma";
217 const std::string name_chi2 =
"chi2";
219 const std::string name_entries =
"fractional uncertainty";
221 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1, b1 );
224 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1, b1 );
225 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1, b1 );
226 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1, b1 );
236 const std::vector<double>&
a,
237 int n2,
double a2,
double b2) {
243 const std::vector<double>&
a,
244 const std::vector<double>& b ) {
245 Initialise(name,
a.size()-1, &
a[0], b.size()-1, &b[0] );
251 int n1,
const double* a1,
252 int n2,
double a2,
double b2) {
259 const std::string name_2d =
"2d";
260 const std::string name_1d =
"1d";
266 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2, b2);
267 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
272 const std::string name_mean =
"mean";
273 const std::string name_sigma =
"sigma";
274 const std::string name_chi2 =
"chi2";
276 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
277 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
278 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
285 const std::string name_entries =
"fractional uncertainty";
287 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
296 int n1,
const double* a1,
297 int n2,
const double* a2) {
304 const std::string name_2d =
"2d";
305 const std::string name_1d =
"1d";
311 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2 );
312 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
317 const std::string name_mean =
"mean";
318 const std::string name_sigma =
"sigma";
319 const std::string name_chi2 =
"chi2";
321 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
322 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
323 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
330 const std::string name_entries =
"fractional uncertainty";
332 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
345 TDirectory*
cwd = gDirectory;
360 gDirectory->mkdir(
"slices")->cd();
373 std::ostringstream s;
381 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) N +=
h->GetBinContent(i);
395 gStyle->SetOptFit(1111);
396 gStyle->SetOptStat(2211);
399 std::cerr <<
"Resplot::Finalise() " <<
m_name <<
" already called" << std::endl;
414 if ( i%1000==0 ) std::cout <<
"slice " << i <<
" of " <<
m_n_primary << std::endl;
417 double pllim =
m_mean->GetBinLowEdge(i);
418 double pulim =
m_mean->GetBinLowEdge(i+1);
422 std::string projname;
433 s->SetTitle(projname.c_str());
459 double N = s->GetEffectiveEntries();
470 m_mean->SetBinContent(i, f1->GetParameter(1) );
471 m_mean->SetBinError(i, f1->GetParError(1) );
473 m_sigma->SetBinContent(i, std::fabs(f1->GetParameter(2)) );
474 m_sigma->SetBinError(i, f1->GetParError(2) );
476 int Ndof = f1->GetNDF();
477 if ( Ndof )
m_chi2->SetBinContent( i, std::fabs(f1->GetChisquare())/Ndof );
478 m_chi2->SetBinError(i, 0 );
483 m_mean->SetBinContent(i,0);
487 m_chi2->SetBinContent(i,0);
526 std::string mname = std::string(f2->GetParName(1));
527 std::string sname = std::string(f2->GetParName(2));
531 if ( mname!=std::string(
"") ) {
m_mean->SetTitle(mname.c_str()); }
532 if ( sname!=std::string(
"") ) {
m_sigma->SetTitle(sname.c_str()); }
537 if ( !
s_nofit ) std::cerr <<
"null overall fit Resplot:" <<
m_name << std::endl;
549 std::cerr << __FUNCTION__ <<
" for " <<
m_name
550 <<
" :\tdistribution wider than histogram width " << std::endl;
553 std::cerr << __FUNCTION__ <<
" for " <<
m_name
554 <<
" :\tbins too wide: cannot calculate rms95 " << std::endl;
565 std::vector<double> xbins;
566 std::vector<double> ybins;
568 TH1D* hy = (TH1D*)
h->ProjectionX(
"1dx", 1,
h->GetNbinsY());
569 TH1D* hx = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
574 for (
int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) xbins.push_back( hx->GetBinLowEdge(i+1) );
575 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
577 std::cout <<
"rotate:" << std::endl;
579 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
580 std::cout <<
"y: " << ybins[0] <<
" - " << ybins.back() << std::endl;
582 TH2D* h2 =
new TH2D(
"duff",
"duff", hx->GetNbinsX(), &xbins[0], hy->GetNbinsX(), &ybins[0] );
584 for (
int i=0 ; i<hx->GetNbinsX() ; i++ ) {
585 for (
int j=0 ; j<hy->GetNbinsX() ; j++ ) {
586 h2->SetBinContent(j+1,i+1,
h->GetBinContent(i+1,j+1));
587 h2->SetBinError(j+1,i+1,
h->GetBinError(i+1,j+1));
591 h2->SetEntries(
h->GetEntries() );
607 if ( N==0 )
return 0;
609 std::vector<double> xbins;
610 std::vector<double> ybins;
612 TH1D* hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
613 TH1D* hy = (TH1D*)
h->ProjectionY(
"r1dy", 1,
h->GetNbinsX());
618 for (
int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) {
619 xbins.push_back( hx->GetBinLowEdge(i+1) );
620 if ( hx->GetBinLowEdge(i+1)>
x )
for (
int k=1 ; k<N ; k++, i++ );
623 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
625 if ( xbins.size()==0 || ybins.size()==0 ) {
626 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() <<
"\tN ybins: " << ybins.size() << std::endl;
630 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
631 std::cout <<
"y: " << ybins[0] <<
" - " << ybins.back() << std::endl;
633 TH2D* h2 =
new TH2D(
"duff",
"duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
637 for (
int j=0 ; j<hy->GetNbinsX() ; j++ ) {
639 for (
int i=0 ; i<hx->GetNbinsX() ; i++ ) {
640 double entries =
h->GetBinContent(i+1,j+1);
641 double errorsq =
h->GetBinError(i+1,j+1)*
h->GetBinError(i+1,j+1);
642 if ( hx->GetBinLowEdge(i+1)>
x ) {
643 for (
int k=1 ; k<N ; k++, i++ ) {
644 entries +=
h->GetBinContent(i+2,j+1);
645 errorsq +=
h->GetBinError(i+2,j+1)*
h->GetBinError(i+2,j+1);
648 h2->SetBinContent(xbin, j+1,
entries);
649 h2->SetBinError(xbin++, j+1, std::sqrt(errorsq) );
653 h2->SetEntries(
h->GetEntries() );
668 if ( N==0 )
return 0;
670 std::vector<double> xbins;
672 for (
int i=0 ; i<=
h->GetNbinsX()+1 ; i++ ) {
673 xbins.push_back(
h->GetBinLowEdge(i+1) );
674 if (
h->GetBinLowEdge(i+1)>
x )
for (
int k=1 ; k<N ; k++, i++ );
677 if ( xbins.size()==0 ) {
678 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
682 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
684 TH1D* h2 =
new TH1D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff", xbins.size()-1, &xbins[0] );
689 for (
int i=0 ; i<
h->GetNbinsX() ; i++ ) {
690 double entries =
h->GetBinContent(i+1);
691 double errorsq =
h->GetBinError(i+1)*
h->GetBinError(i+1);
692 if (
h->GetBinLowEdge(i+1)>
x ) {
693 for (
int k=1 ; k<N ; k++, i++ ) {
695 errorsq +=
h->GetBinError(i+2)*
h->GetBinError(i+2);
699 h2->SetBinContent(xbin,
entries);
700 h2->SetBinError(xbin++, std::sqrt(errorsq) );
703 h2->SetEntries(
h->GetEntries() );
716 std::cout <<
"combine" << std::endl;
720 std::vector<double> xbins;
721 std::vector<double> ybins;
723 std::cout <<
"projection" << std::endl;
725 TH1D* hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
738 std::cout <<
"combining bins " << std::endl;
740 for (
int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
742 TH1D* hy = (TH1D*)
h->ProjectionY(
"r1dy", i, i );
747 if ( xbins.size()==0 ) {
748 if ( N==0 )
continue;
749 else xbins.push_back( hx->GetBinLowEdge(i) );
752 if ( newbin ) xbins.push_back( hx->GetBinLowEdge(i+1) );
753 else xbins.back() = hx->GetBinLowEdge(i+1);
757 if ( xbins.size()>0 ) std::cout << i <<
"\tN " << N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" << xbins.back() << std::endl;
759 if ( N >= inveps2 ) {
765 std::cout <<
"finishsed " << xbins.size() << std::endl;
767 TH1D* hy = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
769 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
771 std::cout <<
"combine" << std::endl;
772 std::cout <<
"x bins " << hx->GetNbinsX() <<
"\t y bins " << hy->GetNbinsX() << std::endl;
774 if ( xbins.size()==0 || ybins.size()==0 ) {
775 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() <<
"\tN ybins: " << ybins.size() << std::endl;
779 std::cout <<
"x: " << xbins.size() <<
" " << xbins[0] <<
" - " << xbins.back() << std::endl;
780 std::cout <<
"y: " << ybins.size() <<
" " << ybins[0] <<
" - " << ybins.back() << std::endl;
782 TH2D* h2 =
new TH2D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
786 for (
int j=1 ; j<=hy->GetNbinsX() ; j++ ) {
790 for (
int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
792 while ( hx->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
794 if ( hx->GetBinCenter(i)>=xbins[xbin] && hx->GetBinCenter(i)<xbins[xbin+1] ) {
797 double n =
h->GetBinContent(i,j);
798 double nh = h2->GetBinContent(xbin+1, j);
799 h2->SetBinContent(xbin+1, j, nh+n);
802 double ne =
h->GetBinError(i,j);
803 double nhe = h2->GetBinError(xbin+1, j);
804 h2->SetBinError(xbin+1, j, std::sqrt( ne*ne + nhe*nhe ) );
811 h2->SetEntries(
h->GetEntries() );
839 std::cout <<
"combine" << std::endl;
843 std::vector<double> xbins;
855 std::cout <<
"combining bins " << std::endl;
857 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
859 N +=
h->GetBinContent(i);
861 if ( xbins.size()==0 ) {
862 if ( N==0 )
continue;
863 else xbins.push_back(
h->GetBinLowEdge(i) );
866 if ( newbin ) xbins.push_back(
h->GetBinLowEdge(i+1) );
867 else xbins.back() =
h->GetBinLowEdge(i+1);
871 if ( xbins.size()>0 ) std::cout << i <<
"\tN " << N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" << xbins.back() << std::endl;
873 if ( N >= inveps2 ) {
879 std::cout <<
"finishsed " << xbins.size() << std::endl;
881 std::cout <<
"combine" << std::endl;
882 std::cout <<
"x bins " <<
h->GetNbinsX() << std::endl;
884 std::cout <<
"x: " << xbins.size() <<
" " << xbins[0] <<
" - " << xbins.back() << std::endl;
892 if ( xbins.size()==0 ) {
893 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
897 TH1D* h2 =
new TH1D(
"duff",
"duff", xbins.size()-1, &xbins[0] );
901 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
903 while (
h->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
905 if (
h->GetBinCenter(i)>=xbins[xbin] &&
h->GetBinCenter(i)<xbins[xbin+1] ) {
906 double n =
h->GetBinContent(i);
907 double nh = h2->GetBinContent(xbin+1);
908 h2->SetBinContent(xbin+1, nh+n);
921 std::vector<double>
bins(
h->GetNbinsX()+1);
922 for (
int i=0 ; i<
h->GetNbinsX()+1 ; i++ )
bins[i] =
h->GetBinLowEdge(i+1);
936 for (
int i=0 ; i<=
h->GetNbinsX()+1 ; i++ ) {
937 total +=
h->GetBinContent(i);
939 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
940 double x =
h->GetBinCenter(i);
942 good +=
h->GetBinContent(i);
946 v.value = good/total;
947 v.error = sqrt(v.value*(1-v.value)/total);
962 TH1D* e = (TH1D*)
m_mean->Clone();
963 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
968 TH1D* s =
m_h2d->ProjectionY(
tagname(hname,i), i, i,
"e");
970 e->SetBinContent(i, v.value);
971 e->SetBinError(i, v.error);
996 TH1D* e = (TH1D*)
m_mean->Clone();
997 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
1004 double sigma =
m_sigma->GetBinContent(i);
1006 TH1D* s =
m_h2d->ProjectionY(
tagname(hname,i), i, i,
"e");
1008 e->SetBinContent(i, v.value);
1009 e->SetBinError(i, v.error);
1025 TF1* f1 =
new TF1(
"gausr",
"gaus");
1031 TF1* f1 =
new TF1(
"rgausr",
"[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
1036 TF1* f1 =
new TF1(
"rbreitr",
"x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1038 f1->SetParName(0,
"Maximum");
1039 f1->SetParName(1,
"Median");
1040 f1->SetParName(2,
"Gamma");
1042 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1043 f1->SetParameter(1,s->GetMean());
1044 f1->SetParameter(2,s->GetRMS());
1052 if ( f1==0 )
return f1;
1055 f1->SetLineWidth(1);
1061 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1062 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
1063 f1->SetParameter(2,sigma=s->GetRMS());
1066 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
1069 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1070 else s->Fit(f1,
"Q",
"",
a, b);
1072 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1080 TF1* f1 =
new TF1(
"gausr",
"gaus");
1083 f1->SetLineWidth(1);
1089 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1090 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
1091 f1->SetParameter(2,sigma=s->GetRMS());
1094 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
1098 TH1D* s_tmp = (TH1D*)s->Clone(
"duff");
1099 s_tmp->SetDirectory(0);
1123 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
1124 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
1129 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
1136 if ( frac>3 ) s->Fit(f1,
"Q");
1137 else s->Fit(f1,
"Q",
"", llim, ulim);
1140 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1149 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1161 TF1* f1 =
new TF1(
"breitr",
"[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1163 f1->SetParName(0,
"Maximum");
1164 f1->SetParName(1,
"Median");
1165 f1->SetParName(2,
"Gamma");
1167 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1168 f1->SetParameter(1,s->GetMean());
1169 f1->SetParameter(2,s->GetRMS()*0.5);
1172 f1->SetLineWidth(1);
1174 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1178 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1182 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1183 else s->Fit(f1,
"Q",
"",
a, b);
1186 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1189 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1220 static int counter = 0;
1222 std::cout <<
"Resplot::FitATan() " << s->GetName() <<
" " << s->GetTitle() << std::endl;
1225 sprintf(name,
"atan_%02d", counter); counter++;
1228 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);
1230 f1->SetParName(0,
"Mean");
1231 f1->SetParName(1,
"Gradient");
1232 f1->SetParName(2,
"Pedestal");
1233 f1->SetParName(3,
"Norm");
1234 f1->SetParName(4,
"Power");
1237 for (
int i=1 ; i<=s->GetNbinsX() ; i++ )
if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1244 f1->SetParameter(0, 2 );
1245 f1->SetParameter(1, 10 );
1246 f1->SetParameter(2, 0.001 );
1247 f1->SetParameter(3, 100 );
1248 f1->SetParameter(4, 1 );
1250 f1->FixParameter(2, 0);
1251 f1->FixParameter(3, 100);
1255 f1->SetLineWidth(1);
1262 s->SetMarkerStyle(20);
1271 std::cout <<
"par0 = " << f1->GetParameter(0) << std::endl;
1272 std::cout <<
"par1 = " << f1->GetParameter(1) << std::endl;
1273 std::cout <<
"par2 = " << f1->GetParameter(2) << std::endl;
1274 std::cout <<
"par3 = " << f1->GetParameter(3) << std::endl;
1275 std::cout <<
"par4 = " << f1->GetParameter(4) << std::endl;
1291 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1293 f->SetParName(0,
"Maximum");
1294 f->SetParName(1,
"Mean");
1295 f->SetParName(2,
"RMS");
1297 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1298 f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1299 f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1319 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1321 double mean = s->GetMean();
1322 double meane = s->GetMeanError();
1328 for (
int it=0 ; it<20 ; it++ ) {
1332 int imax = s->GetXaxis()->FindBin(
mean);
1334 double sumn = s->GetBinContent(
imax);
1346 const int upperbin_i =
imax+i;
1347 const int lowerbin_i =
imax-i;
1349 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1351 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1362 upperbin = upperbin_i;
1363 lowerbin = lowerbin_i;
1368 s->GetXaxis()->SetRange(lowerbin, upperbin);
1370 double m = s->GetMean();
1371 double me = s->GetMeanError();
1375 std::fabs(
mean-m)<me*1e-5 ||
1376 std::fabs(
mean-m)<meane*1e-5 ) {
1397 for (
int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1399 if ( s->GetBinContent(i)>s->GetBinContent(
imax) )
imax = i;
1409 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1411 f->SetParName(0,
"Maximum");
1412 f->SetParName(1,
"Mean");
1413 f->SetParName(2,
"RMS");
1415 f->SetParameter(0, 0);
1416 f->SetParameter(1, 0);
1417 f->SetParameter(2, 0);
1419 if ( s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " << s << std::endl;
return 0; }
1420 if ( s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1424 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1427 std::cout <<
"FitNull95 " << s->GetName()
1455 int imax = s->GetXaxis()->FindBin(m);
1459 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1470 double sumn = s->GetBinContent(
imax);
1472 int upperbin =
imax;
1473 int lowerbin =
imax;
1475 double uppersum = 0;
1476 double lowersum = 0;
1479 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1489 const int upperbin_i =
imax+i;
1490 const int lowerbin_i =
imax-i;
1492 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1494 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1509 upperbin = upperbin_i;
1510 lowerbin = lowerbin_i;
1518 if ( uppersum==0 ) {
1519 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1535 double llim = s->GetBinLowEdge(1);
1536 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1541 std::vector<double> stats;
1548 s->GetXaxis()->SetRange(lowerbin, upperbin);
1567 rlower = s->GetRMS();
1568 erlower = s->GetRMSError();
1574 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1586 rupper = s->GetRMS();
1587 erupper = s->GetRMSError();
1597 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1598 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1602 s->GetXaxis()->SetRange(lowerbin, upperbin);
1610 erms = s->GetRMSError();
1616 std::cout <<
"numbers " << s->GetName()
1620 std::cout <<
"fractions " << s->GetName()
1624 std::cout <<
"lowersum " << s->GetName() <<
"\t" << lowersum <<
"\tuppersum " << uppersum << std::endl;
1626 std::cout <<
"limits " << s->GetName() <<
"\t" << s->GetBinLowEdge(lowerbin) <<
" - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1630 std::cout <<
"FitNULL95Obsolete() " << s->GetName() <<
"\t rms " << rms <<
" +- " << erms <<
"\t inv " << 1/rms << std::endl;
1632 printf(
"rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1634 printf(
"rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1647 f->FixParameter(2, scale*rms);
1648 f->SetParError(2, scale*erms);
1649 f->FixParameter(1, s->GetMean());
1650 f->SetParError(1, s->GetMeanError());
1652 s->GetXaxis()->SetRangeUser(llim, ulim);
1656 f->FixParameter(1, 0);
1657 f->SetParError(1, 0);
1658 f->FixParameter(2, 0);
1659 f->SetParError(2, 0);
1663 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1690 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1692 f->SetParName(0,
"Maximum");
1693 f->SetParName(1,
"Mean");
1694 f->SetParName(2,
"RMS");
1696 f->SetParameter(0, 0);
1697 f->SetParameter(1, 0);
1698 f->SetParameter(2, 0);
1700 if ( s->GetEffectiveEntries()==0 )
return f;
1704 const double entries = s->GetEffectiveEntries();
1709 int nexperiments = 20+int(1000/
entries);
1732 f->FixParameter( 1, e.hmean() );
1733 f->SetParError( 1, e.mean_error() );
1735 f->FixParameter( 2, scale*e.hrms() );
1736 f->SetParError( 2, scale*e.rms_error() );
1755 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1757 f->SetParName(0,
"Maximum");
1758 f->SetParName(1,
"Mean");
1759 f->SetParName(2,
"RMS");
1761 f->SetParameter(0, 0);
1762 f->SetParameter(1, 0);
1763 f->SetParameter(2, 0);
1765 if ( s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " << s << std::endl;
return 0; }
1766 if ( s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1773 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1785 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1789 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1793 double sumn = s->GetBinContent(
imax);
1797 int upperbin =
imax;
1798 int lowerbin =
imax;
1800 double uppersum = 0;
1801 double lowersum = 0;
1808 const int upperbin_i =
imax+i;
1809 const int lowerbin_i =
imax-i;
1811 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1813 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1821 upperbin = upperbin_i;
1822 lowerbin = lowerbin_i;
1836 if ( upperbin!=lowerbin ) {
1838 double llim = s->GetBinLowEdge(1);
1839 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1844 std::vector<double> stats;
1847 s->GetXaxis()->SetRange(lowerbin, upperbin);
1866 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1876 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1877 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1881 s->GetXaxis()->SetRange(lowerbin, upperbin);
1891 f->FixParameter(2, rms);
1892 f->SetParError(2, erms);
1893 f->FixParameter(1, s->GetMean());
1894 f->SetParError(1, s->GetMeanError());
1896 s->GetXaxis()->SetRangeUser(llim, ulim);
1899 f->FixParameter(1, 0);
1900 f->SetParError(1, 0);
1901 f->FixParameter(2, 0);
1902 f->SetParError(2, 0);
1906 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1928 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)");
1929 TF1 *f1 =
new TF1(
"poisson", fstring );
1932 f1->SetParName(0,
"Maximum");
1933 f1->SetParName(1,
"Mean");
1934 f1->SetParName(2,
"Scale");
1935 f1->SetParName(3,
"Offset");
1938 f1->SetLineWidth(1);
1939 f1->SetLineColor(s->GetLineColor());
1942 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1944 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1945 f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1946 f1->SetParameter(2,1);
1947 f1->FixParameter(3,0);
1953 if (
a==-999 || b==-999 ) s->Fit(f1);
1954 else s->Fit(f1,
"",
"",
a, b);
1957 for (
int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1970 TF1* f1 =
new TF1(
"xexpr",
"[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1972 f1->SetParName(0,
"Normalisation");
1973 f1->SetParName(1,
"Power");
1974 f1->SetParName(2,
"Lifetime");
1975 f1->SetParName(3,
"offset");
1978 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1980 f1->SetParameter(2, s->GetRMS() );
1982 f1->SetParameter(1, 0);
1983 f1->SetParameter(3, 0);
1991 f1->SetLineWidth(1);
1994 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
2000 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
2001 else s->Fit(f1,
"Q",
"",
a, b);
2004 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
2031 Double_t invsq2pi = 0.3989422804014;
2032 Double_t mpshift = -0.22278298;
2038 double&
x = x_par[0];
2052 mpc = par[1] - mpshift*par[2];
2058 xlow =
x -
sc * par[3];
2059 xupp =
x +
sc * par[3];
2061 step = (xupp-xlow) / np;
2064 for(i=1.0; i<=np/2; i++) {
2065 xx = xlow + (i-0.5)*step;
2066 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2067 sum += fland * TMath::Gaus(
x,xx,par[3]);
2069 xx = xupp - (i-0.5)*step;
2070 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2071 sum += fland * TMath::Gaus(
x,xx,par[3]);
2074 return (par[0] * step * sum * invsq2pi / par[3]);
2085 TF1* f1 =
new TF1(
"landgaus",
langaufun, 0, 1, 4);
2088 f1->SetLineWidth(1);
2091 double start_vals[4];
2093 start_vals[0] = s->GetEntries();
2094 start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
2095 start_vals[2] = s->GetRMS();
2096 start_vals[3] = 0.5*start_vals[2];
2098 f1->SetParNames(
"Area",
"MP",
"Width",
"GSigma");
2099 f1->SetParameters(start_vals);
2105 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
2106 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
2109 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
2112 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
2113 else s->Fit(f1,
"Q",
"",
a, b);
2117 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
static const std::vector< std::string > bins
ClassImp(xAOD::Experimental::RFileChecker) namespace xAOD
double FindMean(TH1D *s, double frac=0.95)
void unZeroErrors(TH1D *h)
Double_t langaufun(Double_t *x_par, Double_t *par)
double getWeights(TH1D *h)
void GetStats(TH1D *h, std::vector< double > &stats)
std::string number(const double &x)
Header file for AthHistogramAlgorithm.
static TH2D * rotate(const TH2 *h)
flip the x and y axes
static TF1 * FitRGaussian(TH1D *s, double a=-999, double b=-999)
static std::vector< double > getbins(const TH1 *h)
const std::string & Name() const
static TF1 * FitCentralGaussian(TH1D *s, double a=-999, double b=-999)
std::vector< TH1D * > m_slices
static TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
static TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
static const std::string s_rversion
static TF1 * FitGaussian(TH1D *s, double a=-999, double b=-999)
static TF1 * FitRBreit(TH1D *s, double a=-999, double b=-999)
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Int_t Write(const char *=0, Int_t=0, Int_t=0) const
Hooray, this stupidity is to overwride both the const and non-const TObject Write methods Fixme: shou...
static TF1 * FitBreit(TH1D *s, double a=-999, double b=-999)
static bool AddDirectoryStatus()
void SetSecondary(int n, double a, double b)
static TF1 * FitLandauGauss(TH1D *s, double a=-999, double b=-999)
static TF1 * FitXExp(TH1D *s, double a=-999, double b=-999)
static bool s_oldrms95
temporarily allow toggeling between old and new rms95 error estimates
void SetDirectory(TDirectory *=0)
static TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
static bool s_interpolate_flag
static TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
StatVal GetEfficiency(TH1D *h, double lower, double upper)
void SetPrimary(int n, const double *)
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
static TH2D * combine(const TH2 *h, double x, int N)
combine bins along the x axis after value x, combine each N bins into a single bin
static TF1 * FitPoisson(TH1D *s, double a=-999, double b=-999)
Int_t DWrite(TDirectory *g=0) const
boooo, need to use the stupid Int_t class because I foolishly gave this function the same name as TOb...
static bool s_mAddDirectoryStatus
static TF1 * FitATan(TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull95Central(TH1D *s)
TH1D * GetEfficiencies(const std::string &hname, double lower, double upper)
static std::vector< double > findbins(const TH1 *h, double epsilon)
simple struct to hold a value and it's associated uncertainty.
given a histogram, get a generator for the distribution in that histogram, then run some pseudo-exper...
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
double GetEntries(TH1D *h, int ilow, int ihi)
std::string number(const double &d, const std::string &s)