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));
147 std::cerr<<
"Denominator of zero in GetStats()\n";
152 double v = sx2/s-mu*mu;
154 double rms = std::sqrt(v);
155 double rmserror = std::sqrt(0.25*(sx4/v-v*s))/s;
159 stats[1] = std::sqrt(v/s);
167 std::cout <<
"GetStats() "
169 <<
"\trms " << stats[2] <<
" +- " << stats[3] <<
"\t(" << rmserror1 <<
")" <<
"\t root " << duff << std::endl;
196 int n1,
double a1,
double b1,
197 int n2,
double a2,
double b2) {
206 const std::string name_2d =
"2d";
207 const std::string name_1d =
"1d";
211 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, b1, n2, a2, b2);
212 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
217 const std::string name_mean =
"mean";
218 const std::string name_sigma =
"sigma";
219 const std::string name_chi2 =
"chi2";
221 const std::string name_entries =
"fractional uncertainty";
223 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1, b1 );
226 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1, b1 );
227 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1, b1 );
228 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1, b1 );
238 const std::vector<double>&
a,
239 int n2,
double a2,
double b2) {
245 const std::vector<double>&
a,
246 const std::vector<double>& b ) {
247 Initialise(name,
a.size()-1, &
a[0], b.size()-1, &b[0] );
253 int n1,
const double* a1,
254 int n2,
double a2,
double b2) {
261 const std::string name_2d =
"2d";
262 const std::string name_1d =
"1d";
268 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2, b2);
269 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
274 const std::string name_mean =
"mean";
275 const std::string name_sigma =
"sigma";
276 const std::string name_chi2 =
"chi2";
278 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
279 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
280 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
287 const std::string name_entries =
"fractional uncertainty";
289 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
298 int n1,
const double* a1,
299 int n2,
const double* a2) {
306 const std::string name_2d =
"2d";
307 const std::string name_1d =
"1d";
313 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2 );
314 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
319 const std::string name_mean =
"mean";
320 const std::string name_sigma =
"sigma";
321 const std::string name_chi2 =
"chi2";
323 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
324 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
325 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
332 const std::string name_entries =
"fractional uncertainty";
334 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
347 TDirectory*
cwd = gDirectory;
362 gDirectory->mkdir(
"slices")->cd();
375 std::ostringstream s;
383 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) N +=
h->GetBinContent(i);
397 gStyle->SetOptFit(1111);
398 gStyle->SetOptStat(2211);
401 std::cerr <<
"Resplot::Finalise() " <<
m_name <<
" already called" << std::endl;
416 if ( i%1000==0 ) std::cout <<
"slice " << i <<
" of " <<
m_n_primary << std::endl;
419 double pllim =
m_mean->GetBinLowEdge(i);
420 double pulim =
m_mean->GetBinLowEdge(i+1);
424 std::string projname;
435 s->SetTitle(projname.c_str());
461 double N = s->GetEffectiveEntries();
472 m_mean->SetBinContent(i, f1->GetParameter(1) );
473 m_mean->SetBinError(i, f1->GetParError(1) );
475 m_sigma->SetBinContent(i, std::fabs(f1->GetParameter(2)) );
476 m_sigma->SetBinError(i, f1->GetParError(2) );
478 int Ndof = f1->GetNDF();
479 if ( Ndof )
m_chi2->SetBinContent( i, std::fabs(f1->GetChisquare())/Ndof );
480 m_chi2->SetBinError(i, 0 );
485 m_mean->SetBinContent(i,0);
489 m_chi2->SetBinContent(i,0);
528 std::string mname = std::string(f2->GetParName(1));
529 std::string sname = std::string(f2->GetParName(2));
533 if ( mname!=std::string(
"") ) {
m_mean->SetTitle(mname.c_str()); }
534 if ( sname!=std::string(
"") ) {
m_sigma->SetTitle(sname.c_str()); }
539 if ( !
s_nofit ) std::cerr <<
"null overall fit Resplot:" <<
m_name << std::endl;
551 std::cerr << __FUNCTION__ <<
" for " <<
m_name
552 <<
" :\tdistribution wider than histogram width " << std::endl;
555 std::cerr << __FUNCTION__ <<
" for " <<
m_name
556 <<
" :\tbins too wide: cannot calculate rms95 " << std::endl;
567 std::vector<double> xbins;
568 std::vector<double> ybins;
570 TH1D* hy = (TH1D*)
h->ProjectionX(
"1dx", 1,
h->GetNbinsY());
571 TH1D* hx = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
576 for (
int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) xbins.push_back( hx->GetBinLowEdge(i+1) );
577 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
579 std::cout <<
"rotate:" << std::endl;
581 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
582 std::cout <<
"y: " << ybins[0] <<
" - " << ybins.back() << std::endl;
584 TH2D* h2 =
new TH2D(
"duff",
"duff", hx->GetNbinsX(), &xbins[0], hy->GetNbinsX(), &ybins[0] );
586 for (
int i=0 ; i<hx->GetNbinsX() ; i++ ) {
587 for (
int j=0 ; j<hy->GetNbinsX() ; j++ ) {
588 h2->SetBinContent(j+1,i+1,
h->GetBinContent(i+1,j+1));
589 h2->SetBinError(j+1,i+1,
h->GetBinError(i+1,j+1));
593 h2->SetEntries(
h->GetEntries() );
609 if ( N==0 )
return 0;
611 std::vector<double> xbins;
612 std::vector<double> ybins;
614 TH1D* hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
615 TH1D* hy = (TH1D*)
h->ProjectionY(
"r1dy", 1,
h->GetNbinsX());
620 for (
int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) {
621 xbins.push_back( hx->GetBinLowEdge(i+1) );
622 if ( hx->GetBinLowEdge(i+1)>
x )
for (
int k=1 ; k<N ; k++, i++ );
625 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
627 if ( xbins.size()==0 || ybins.size()==0 ) {
628 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() <<
"\tN ybins: " << ybins.size() << std::endl;
632 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
633 std::cout <<
"y: " << ybins[0] <<
" - " << ybins.back() << std::endl;
635 TH2D* h2 =
new TH2D(
"duff",
"duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
639 for (
int j=0 ; j<hy->GetNbinsX() ; j++ ) {
641 for (
int i=0 ; i<hx->GetNbinsX() ; i++ ) {
642 double entries =
h->GetBinContent(i+1,j+1);
643 double errorsq =
h->GetBinError(i+1,j+1)*
h->GetBinError(i+1,j+1);
644 if ( hx->GetBinLowEdge(i+1)>
x ) {
645 for (
int k=1 ; k<N ; k++, i++ ) {
646 entries +=
h->GetBinContent(i+2,j+1);
647 errorsq +=
h->GetBinError(i+2,j+1)*
h->GetBinError(i+2,j+1);
650 h2->SetBinContent(xbin, j+1,
entries);
651 h2->SetBinError(xbin++, j+1, std::sqrt(errorsq) );
655 h2->SetEntries(
h->GetEntries() );
670 if ( N==0 )
return 0;
672 std::vector<double> xbins;
674 for (
int i=0 ; i<=
h->GetNbinsX()+1 ; i++ ) {
675 xbins.push_back(
h->GetBinLowEdge(i+1) );
676 if (
h->GetBinLowEdge(i+1)>
x )
for (
int k=1 ; k<N ; k++, i++ );
679 if ( xbins.size()==0 ) {
680 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
684 std::cout <<
"x: " << xbins[0] <<
" - " << xbins.back() << std::endl;
686 TH1D* h2 =
new TH1D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff", xbins.size()-1, &xbins[0] );
691 for (
int i=0 ; i<
h->GetNbinsX() ; i++ ) {
692 double entries =
h->GetBinContent(i+1);
693 double errorsq =
h->GetBinError(i+1)*
h->GetBinError(i+1);
694 if (
h->GetBinLowEdge(i+1)>
x ) {
695 for (
int k=1 ; k<N ; k++, i++ ) {
697 errorsq +=
h->GetBinError(i+2)*
h->GetBinError(i+2);
701 h2->SetBinContent(xbin,
entries);
702 h2->SetBinError(xbin++, std::sqrt(errorsq) );
705 h2->SetEntries(
h->GetEntries() );
718 std::cout <<
"combine" << std::endl;
722 std::vector<double> xbins;
723 std::vector<double> ybins;
725 std::cout <<
"projection" << std::endl;
727 TH1D* hx = (TH1D*)
h->ProjectionX(
"r1dx", 1,
h->GetNbinsY());
740 std::cout <<
"combining bins " << std::endl;
742 for (
int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
744 TH1D* hy = (TH1D*)
h->ProjectionY(
"r1dy", i, i );
749 if ( xbins.size()==0 ) {
750 if ( N==0 )
continue;
751 else xbins.push_back( hx->GetBinLowEdge(i) );
754 if ( newbin ) xbins.push_back( hx->GetBinLowEdge(i+1) );
755 else xbins.back() = hx->GetBinLowEdge(i+1);
759 if ( xbins.size()>0 ) std::cout << i <<
"\tN " << N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" << xbins.back() << std::endl;
761 if ( N >= inveps2 ) {
767 std::cout <<
"finishsed " << xbins.size() << std::endl;
769 TH1D* hy = (TH1D*)
h->ProjectionY(
"1dy", 1,
h->GetNbinsX());
771 for (
int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
773 std::cout <<
"combine" << std::endl;
774 std::cout <<
"x bins " << hx->GetNbinsX() <<
"\t y bins " << hy->GetNbinsX() << std::endl;
776 if ( xbins.size()==0 || ybins.size()==0 ) {
777 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() <<
"\tN ybins: " << ybins.size() << std::endl;
781 std::cout <<
"x: " << xbins.size() <<
" " << xbins[0] <<
" - " << xbins.back() << std::endl;
782 std::cout <<
"y: " << ybins.size() <<
" " << ybins[0] <<
" - " << ybins.back() << std::endl;
784 TH2D* h2 =
new TH2D( (std::string(
h->GetName())+
"-duff").c_str(),
"duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
788 for (
int j=1 ; j<=hy->GetNbinsX() ; j++ ) {
792 for (
int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
794 while ( hx->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
796 if ( hx->GetBinCenter(i)>=xbins[xbin] && hx->GetBinCenter(i)<xbins[xbin+1] ) {
799 double n =
h->GetBinContent(i,j);
800 double nh = h2->GetBinContent(xbin+1, j);
801 h2->SetBinContent(xbin+1, j, nh+n);
804 double ne =
h->GetBinError(i,j);
805 double nhe = h2->GetBinError(xbin+1, j);
806 h2->SetBinError(xbin+1, j, std::sqrt( ne*ne + nhe*nhe ) );
813 h2->SetEntries(
h->GetEntries() );
841 std::cout <<
"combine" << std::endl;
845 std::vector<double> xbins;
857 std::cout <<
"combining bins " << std::endl;
859 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
861 N +=
h->GetBinContent(i);
863 if ( xbins.size()==0 ) {
864 if ( N==0 )
continue;
865 else xbins.push_back(
h->GetBinLowEdge(i) );
868 if ( newbin ) xbins.push_back(
h->GetBinLowEdge(i+1) );
869 else xbins.back() =
h->GetBinLowEdge(i+1);
873 if ( xbins.size()>0 ) std::cout << i <<
"\tN " << N <<
" " <<
" (" << inveps2 <<
")" <<
"\t" << xbins.back() << std::endl;
875 if ( N >= inveps2 ) {
881 std::cout <<
"finishsed " << xbins.size() << std::endl;
883 std::cout <<
"combine" << std::endl;
884 std::cout <<
"x bins " <<
h->GetNbinsX() << std::endl;
886 std::cout <<
"x: " << xbins.size() <<
" " << xbins[0] <<
" - " << xbins.back() << std::endl;
894 if ( xbins.size()==0 ) {
895 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
899 TH1D* h2 =
new TH1D(
"duff",
"duff", xbins.size()-1, &xbins[0] );
903 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
905 while (
h->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
907 if (
h->GetBinCenter(i)>=xbins[xbin] &&
h->GetBinCenter(i)<xbins[xbin+1] ) {
908 double n =
h->GetBinContent(i);
909 double nh = h2->GetBinContent(xbin+1);
910 h2->SetBinContent(xbin+1, nh+n);
923 std::vector<double>
bins(
h->GetNbinsX()+1);
924 for (
int i=0 ; i<
h->GetNbinsX()+1 ; i++ )
bins[i] =
h->GetBinLowEdge(i+1);
938 for (
int i=0 ; i<=
h->GetNbinsX()+1 ; i++ ) {
939 total +=
h->GetBinContent(i);
941 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
942 double x =
h->GetBinCenter(i);
944 good +=
h->GetBinContent(i);
948 v.value = good/total;
949 v.error = sqrt(v.value*(1-v.value)/total);
964 TH1D* e = (TH1D*)
m_mean->Clone();
965 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
970 TH1D* s =
m_h2d->ProjectionY(
tagname(hname,i), i, i,
"e");
972 e->SetBinContent(i, v.value);
973 e->SetBinError(i, v.error);
998 TH1D* e = (TH1D*)
m_mean->Clone();
999 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
1006 double sigma =
m_sigma->GetBinContent(i);
1008 TH1D* s =
m_h2d->ProjectionY(
tagname(hname,i), i, i,
"e");
1010 e->SetBinContent(i, v.value);
1011 e->SetBinError(i, v.error);
1027 TF1* f1 =
new TF1(
"gausr",
"gaus");
1033 TF1* f1 =
new TF1(
"rgausr",
"[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
1038 TF1* f1 =
new TF1(
"rbreitr",
"x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1040 f1->SetParName(0,
"Maximum");
1041 f1->SetParName(1,
"Median");
1042 f1->SetParName(2,
"Gamma");
1044 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1045 f1->SetParameter(1,s->GetMean());
1046 f1->SetParameter(2,s->GetRMS());
1054 if ( f1==0 )
return f1;
1057 f1->SetLineWidth(1);
1063 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1064 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
1065 f1->SetParameter(2,sigma=s->GetRMS());
1068 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
1071 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1072 else s->Fit(f1,
"Q",
"",
a, b);
1074 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1082 TF1* f1 =
new TF1(
"gausr",
"gaus");
1085 f1->SetLineWidth(1);
1091 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1092 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
1093 f1->SetParameter(2,sigma=s->GetRMS());
1096 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
1100 TH1D* s_tmp = (TH1D*)s->Clone(
"duff");
1101 s_tmp->SetDirectory(0);
1125 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
1126 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
1131 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
1138 if ( frac>3 ) s->Fit(f1,
"Q");
1139 else s->Fit(f1,
"Q",
"", llim, ulim);
1142 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1151 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1163 TF1* f1 =
new TF1(
"breitr",
"[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1165 f1->SetParName(0,
"Maximum");
1166 f1->SetParName(1,
"Median");
1167 f1->SetParName(2,
"Gamma");
1169 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1170 f1->SetParameter(1,s->GetMean());
1171 f1->SetParameter(2,s->GetRMS()*0.5);
1174 f1->SetLineWidth(1);
1176 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1180 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1184 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1185 else s->Fit(f1,
"Q",
"",
a, b);
1188 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1191 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1200 static int counter = 0;
1202 std::cout <<
"Resplot::FitATan() " << s->GetName() <<
" " << s->GetTitle() << std::endl;
1205 sprintf(name,
"atan_%02d", counter); counter++;
1208 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);
1210 f1->SetParName(0,
"Mean");
1211 f1->SetParName(1,
"Gradient");
1212 f1->SetParName(2,
"Pedestal");
1213 f1->SetParName(3,
"Norm");
1214 f1->SetParName(4,
"Power");
1217 for (
int i=1 ; i<=s->GetNbinsX() ; i++ )
if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1224 f1->SetParameter(0, 2 );
1225 f1->SetParameter(1, 10 );
1226 f1->SetParameter(2, 0.001 );
1227 f1->SetParameter(3, 100 );
1228 f1->SetParameter(4, 1 );
1230 f1->FixParameter(2, 0);
1231 f1->FixParameter(3, 100);
1235 f1->SetLineWidth(1);
1242 s->SetMarkerStyle(20);
1251 std::cout <<
"par0 = " << f1->GetParameter(0) << std::endl;
1252 std::cout <<
"par1 = " << f1->GetParameter(1) << std::endl;
1253 std::cout <<
"par2 = " << f1->GetParameter(2) << std::endl;
1254 std::cout <<
"par3 = " << f1->GetParameter(3) << std::endl;
1255 std::cout <<
"par4 = " << f1->GetParameter(4) << std::endl;
1271 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1273 f->SetParName(0,
"Maximum");
1274 f->SetParName(1,
"Mean");
1275 f->SetParName(2,
"RMS");
1277 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1278 f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1279 f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1299 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1301 double mean = s->GetMean();
1302 double meane = s->GetMeanError();
1308 for (
int it=0 ; it<20 ; it++ ) {
1312 int imax = s->GetXaxis()->FindBin(
mean);
1314 double sumn = s->GetBinContent(
imax);
1326 const int upperbin_i =
imax+i;
1327 const int lowerbin_i =
imax-i;
1329 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1331 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1342 upperbin = upperbin_i;
1343 lowerbin = lowerbin_i;
1348 s->GetXaxis()->SetRange(lowerbin, upperbin);
1350 double m = s->GetMean();
1351 double me = s->GetMeanError();
1355 std::fabs(
mean-m)<me*1e-5 ||
1356 std::fabs(
mean-m)<meane*1e-5 ) {
1377 for (
int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1379 if ( s->GetBinContent(i)>s->GetBinContent(
imax) )
imax = i;
1389 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1391 f->SetParName(0,
"Maximum");
1392 f->SetParName(1,
"Mean");
1393 f->SetParName(2,
"RMS");
1395 f->SetParameter(0, 0);
1396 f->SetParameter(1, 0);
1397 f->SetParameter(2, 0);
1399 if ( s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " << s << std::endl;
return 0; }
1400 if ( s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1404 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1407 std::cout <<
"FitNull95 " << s->GetName()
1435 int imax = s->GetXaxis()->FindBin(m);
1439 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1450 double sumn = s->GetBinContent(
imax);
1452 int upperbin =
imax;
1453 int lowerbin =
imax;
1455 double uppersum = 0;
1456 double lowersum = 0;
1459 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1469 const int upperbin_i =
imax+i;
1470 const int lowerbin_i =
imax-i;
1472 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1474 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1489 upperbin = upperbin_i;
1490 lowerbin = lowerbin_i;
1498 if ( uppersum==0 ) {
1499 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1515 double llim = s->GetBinLowEdge(1);
1516 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1521 std::vector<double> stats;
1528 s->GetXaxis()->SetRange(lowerbin, upperbin);
1547 rlower = s->GetRMS();
1548 erlower = s->GetRMSError();
1554 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1566 rupper = s->GetRMS();
1567 erupper = s->GetRMSError();
1577 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1578 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1582 s->GetXaxis()->SetRange(lowerbin, upperbin);
1590 erms = s->GetRMSError();
1596 std::cout <<
"numbers " << s->GetName()
1600 std::cout <<
"fractions " << s->GetName()
1604 std::cout <<
"lowersum " << s->GetName() <<
"\t" << lowersum <<
"\tuppersum " << uppersum << std::endl;
1606 std::cout <<
"limits " << s->GetName() <<
"\t" << s->GetBinLowEdge(lowerbin) <<
" - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1610 std::cout <<
"FitNULL95Obsolete() " << s->GetName() <<
"\t rms " << rms <<
" +- " << erms <<
"\t inv " << 1/rms << std::endl;
1612 printf(
"rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1614 printf(
"rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1627 f->FixParameter(2, scale*rms);
1628 f->SetParError(2, scale*erms);
1629 f->FixParameter(1, s->GetMean());
1630 f->SetParError(1, s->GetMeanError());
1632 s->GetXaxis()->SetRangeUser(llim, ulim);
1636 f->FixParameter(1, 0);
1637 f->SetParError(1, 0);
1638 f->FixParameter(2, 0);
1639 f->SetParError(2, 0);
1643 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1670 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1672 f->SetParName(0,
"Maximum");
1673 f->SetParName(1,
"Mean");
1674 f->SetParName(2,
"RMS");
1676 f->SetParameter(0, 0);
1677 f->SetParameter(1, 0);
1678 f->SetParameter(2, 0);
1680 if ( s->GetEffectiveEntries()==0 )
return f;
1684 const double entries = s->GetEffectiveEntries();
1689 int nexperiments = 20+int(1000/
entries);
1712 f->FixParameter( 1, e.hmean() );
1713 f->SetParError( 1, e.mean_error() );
1715 f->FixParameter( 2, scale*e.hrms() );
1716 f->SetParError( 2, scale*e.rms_error() );
1735 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1737 f->SetParName(0,
"Maximum");
1738 f->SetParName(1,
"Mean");
1739 f->SetParName(2,
"RMS");
1741 f->SetParameter(0, 0);
1742 f->SetParameter(1, 0);
1743 f->SetParameter(2, 0);
1745 if ( s==0 ) { std::cerr <<
"Resplot::FitNull95() histogram s = " << s << std::endl;
return 0; }
1746 if ( s->GetXaxis()==0) { std::cerr <<
"Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1753 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1765 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1769 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1773 double sumn = s->GetBinContent(
imax);
1777 int upperbin =
imax;
1778 int lowerbin =
imax;
1780 double uppersum = 0;
1781 double lowersum = 0;
1788 const int upperbin_i =
imax+i;
1789 const int lowerbin_i =
imax-i;
1791 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1793 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1801 upperbin = upperbin_i;
1802 lowerbin = lowerbin_i;
1816 if ( upperbin!=lowerbin ) {
1818 double llim = s->GetBinLowEdge(1);
1819 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1824 std::vector<double> stats;
1827 s->GetXaxis()->SetRange(lowerbin, upperbin);
1846 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1856 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1857 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1861 s->GetXaxis()->SetRange(lowerbin, upperbin);
1871 f->FixParameter(2, rms);
1872 f->SetParError(2, erms);
1873 f->FixParameter(1, s->GetMean());
1874 f->SetParError(1, s->GetMeanError());
1876 s->GetXaxis()->SetRangeUser(llim, ulim);
1879 f->FixParameter(1, 0);
1880 f->SetParError(1, 0);
1881 f->FixParameter(2, 0);
1882 f->SetParError(2, 0);
1886 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1908 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)");
1909 TF1 *f1 =
new TF1(
"poisson", fstring );
1912 f1->SetParName(0,
"Maximum");
1913 f1->SetParName(1,
"Mean");
1914 f1->SetParName(2,
"Scale");
1915 f1->SetParName(3,
"Offset");
1918 f1->SetLineWidth(1);
1919 f1->SetLineColor(s->GetLineColor());
1922 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1924 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1925 f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1926 f1->SetParameter(2,1);
1927 f1->FixParameter(3,0);
1933 if (
a==-999 || b==-999 ) s->Fit(f1);
1934 else s->Fit(f1,
"",
"",
a, b);
1937 for (
int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1950 TF1* f1 =
new TF1(
"xexpr",
"[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1952 f1->SetParName(0,
"Normalisation");
1953 f1->SetParName(1,
"Power");
1954 f1->SetParName(2,
"Lifetime");
1955 f1->SetParName(3,
"offset");
1958 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1960 f1->SetParameter(2, s->GetRMS() );
1962 f1->SetParameter(1, 0);
1963 f1->SetParameter(3, 0);
1971 f1->SetLineWidth(1);
1974 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1980 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1981 else s->Fit(f1,
"Q",
"",
a, b);
1984 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
2011 Double_t invsq2pi = 0.3989422804014;
2012 Double_t mpshift = -0.22278298;
2018 double&
x = x_par[0];
2032 mpc = par[1] - mpshift*par[2];
2038 xlow =
x -
sc * par[3];
2039 xupp =
x +
sc * par[3];
2041 step = (xupp-xlow) / np;
2044 for(i=1.0; i<=np/2; i++) {
2045 xx = xlow + (i-0.5)*step;
2046 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2047 sum += fland * TMath::Gaus(
x,xx,par[3]);
2049 xx = xupp - (i-0.5)*step;
2050 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2051 sum += fland * TMath::Gaus(
x,xx,par[3]);
2054 return (par[0] * step * sum * invsq2pi / par[3]);
2065 TF1* f1 =
new TF1(
"landgaus",
langaufun, 0, 1, 4);
2068 f1->SetLineWidth(1);
2071 double start_vals[4];
2073 start_vals[0] = s->GetEntries();
2074 start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
2075 start_vals[2] = s->GetRMS();
2076 start_vals[3] = 0.5*start_vals[2];
2078 f1->SetParNames(
"Area",
"MP",
"Width",
"GSigma");
2079 f1->SetParameters(start_vals);
2085 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
2086 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
2089 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
2092 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
2093 else s->Fit(f1,
"Q",
"",
a, b);
2097 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)