54 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
55 double d =
h->GetBinLowEdge(i+1) -
h->GetBinLowEdge(i);
57 h->SetBinContent(i,
h->GetBinContent(i)/d );
58 h->SetBinError(i,
h->GetBinError(i)/d );
70 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ )
if (
h->GetBinContent(i)==0)
h->SetBinError(i,1);
76 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ )
if (
h->GetBinContent(i)==0)
h->SetBinError(i,0);
84 for (
int i=0 ; i<
h->GetNbinsX()+1 ; i++ ) {
85 sum +=
h->GetBinContent(i);
86 sume2 +=
h->GetBinError(i)*
h->GetBinError(i);
88 if ( sume2!=0 )
return sum*sum/sume2;
98 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
99 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
100 sum +=
h->GetBinContent(i,j);
101 sume2 +=
h->GetBinError(i,j)*
h->GetBinError(i,j);
105 if ( sume2!=0 )
return sum*sum/sume2;
121 TAxis& fXaxis = *
h->GetXaxis();
126 Int_t firstBinX = fXaxis.GetFirst();
127 Int_t lastBinX = fXaxis.GetLast();
129 int del = lastBinX - firstBinX;
131 if ( del<1 )
return errorstate = 1;
148 for (
int binx = firstBinX; binx <= lastBinX; binx++) {
149 double x = fXaxis.GetBinCenter(binx);
150 double w = TMath::Abs(
h->GetBinContent(binx));
156 std::cerr <<
"\tUnphysical denominator zero or less in GetStats()\n";
157 return errorstate = 2;
162 for (
int binx = firstBinX; binx <= lastBinX; binx++) {
163 double x = fXaxis.GetBinCenter(binx);
164 double w = TMath::Abs(
h->GetBinContent(binx));
178 if ( v<=0 )
return errorstate = 3;
180 double rms0 = std::sqrt(v);
183 double r2 = 0.25*(sr4/v-sr2);
185 if ( r2>0 ) rmserror = std::sqrt(r2)/s;
191 stats[1] = std::sqrt(v/s);
197 std::cout <<
"GetStats() "
199 <<
"\trms " << stats[2] <<
" +- " << stats[3] <<
"\t(" << rmserror1 <<
")" <<
"\t root " << duff << std::endl;
227 int n1,
double a1,
double b1,
228 int n2,
double a2,
double b2) {
237 const std::string name_2d =
"2d";
238 const std::string name_1d =
"1d";
242 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, b1, n2, a2, b2);
243 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
248 const std::string name_mean =
"mean";
249 const std::string name_sigma =
"sigma";
250 const std::string name_chi2 =
"chi2";
252 const std::string name_entries =
"fractional uncertainty";
254 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1, b1 );
257 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1, b1 );
258 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1, b1 );
259 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1, b1 );
269 const std::vector<double>&
a,
270 int n2,
double a2,
double b2) {
276 const std::vector<double>&
a,
277 const std::vector<double>& b ) {
284 int n1,
const double* a1,
285 int n2,
double a2,
double b2) {
292 const std::string name_2d =
"2d";
293 const std::string name_1d =
"1d";
299 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2, b2);
300 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
305 const std::string name_mean =
"mean";
306 const std::string name_sigma =
"sigma";
307 const std::string name_chi2 =
"chi2";
309 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
310 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
311 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
318 const std::string name_entries =
"fractional uncertainty";
320 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
329 int n1,
const double* a1,
330 int n2,
const double* a2) {
337 const std::string name_2d =
"2d";
338 const std::string name_1d =
"1d";
344 m_h2d =
new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2 );
345 m_h1d =
new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
350 const std::string name_mean =
"mean";
351 const std::string name_sigma =
"sigma";
352 const std::string name_chi2 =
"chi2";
354 m_mean =
new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
355 m_sigma =
new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
356 m_chi2 =
new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
363 const std::string name_entries =
"fractional uncertainty";
365 m_Nentries =
new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
380 TDirectory*
cwd = gDirectory;
395 gDirectory->mkdir(
"slices")->cd();
411 std::ostringstream s;
419 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) N +=
h->GetBinContent(i);
434 std::cerr <<
"Resplot::Finalise() " <<
m_name <<
" already called" << std::endl;
451 if ( i%1000==0 ) std::cout <<
"slice " << i <<
" of " <<
m_n_primary << std::endl;
454 double pllim =
m_mean->GetBinLowEdge(i);
455 double pulim =
m_mean->GetBinLowEdge(i+1);
459 std::string projname;
472 s->SetTitle(projname.c_str());
498 double N = s->GetEffectiveEntries();
509 m_mean->SetBinContent(i, f1->GetParameter(1) );
510 m_mean->SetBinError(i, f1->GetParError(1) );
512 m_sigma->SetBinContent(i, std::fabs(f1->GetParameter(2)) );
513 m_sigma->SetBinError(i, f1->GetParError(2) );
515 int Ndof = f1->GetNDF();
516 if ( Ndof )
m_chi2->SetBinContent( i, std::fabs(f1->GetChisquare())/Ndof );
517 m_chi2->SetBinError(i, 0 );
522 m_mean->SetBinContent(i,0);
526 m_chi2->SetBinContent(i,0);
564 std::string mname = std::string(f2->GetParName(1));
565 std::string sname = std::string(f2->GetParName(2));
569 if ( mname!=std::string(
"") ) {
m_mean->SetTitle(mname.c_str()); }
570 if ( sname!=std::string(
"") ) {
m_sigma->SetTitle(sname.c_str()); }
575 if ( !
s_nofit ) std::cerr <<
"\tnull overall fit Resplot:" <<
m_name << std::endl;
587 if ( s_ErrorSet!=
OK ) {
589 std::cerr << __FUNCTION__ <<
" for " <<
m_name
590 <<
" :\tdistribution wider than histogram width " << std::endl;
593 std::cerr << __FUNCTION__ <<
" for " <<
m_name
594 <<
" :\tbins too wide: cannot calculate rms95 " << std::endl;
606 std::vector<double> xbins =
getLimits(
h->GetXaxis() );
607 std::vector<double> ybins =
getLimits(
h->GetYaxis() );
613 std::string
name = s;
614 if ( s.empty() )
name =
"duff";
616 TH2D* h2 =
new TH2D(
name.c_str(),
"", ybins.size()-1, &ybins[0], xbins.size()-1, &xbins[0] );
619 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
620 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
621 h2->SetBinContent(j,i,
h->GetBinContent(i,j));
622 h2->SetBinError(j,i,
h->GetBinError(i,j));
626 h2->SetEntries(
h->GetEntries() );
635 std::vector<double> xbins =
getLimits(
h->GetXaxis() );
636 std::vector<double> ybins =
getLimits(
h->GetYaxis() );
642 std::string
name = s;
643 if ( s.empty() )
name =
"duff";
645 TH2D* h2 =
new TH2D(
name.c_str(),
"", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
648 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
649 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
650 h2->SetBinContent(i,j,
h->GetBinContent(i,j));
651 h2->SetBinError(i,j,
h->GetBinError(i,j));
655 h2->SetEntries(
h->GetEntries() );
668 std::vector<double> xbins;
681 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
683 N +=
h->GetBinContent(i);
685 if ( xbins.size()==0 ) {
686 if ( N==0 )
continue;
687 else xbins.push_back(
h->GetBinLowEdge(i) );
690 if ( newbin ) xbins.push_back(
h->GetBinLowEdge(i+1) );
691 else xbins.back() =
h->GetBinLowEdge(i+1);
697 if ( N >= inveps2 ) {
716 if ( xbins.size()==0 ) {
717 std::cerr <<
"Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
721 TH1D* h2 =
new TH1D(
"duff",
"duff", xbins.size()-1, &xbins[0] );
725 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
727 while (
h->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
729 if (
h->GetBinCenter(i)>=xbins[xbin] &&
h->GetBinCenter(i)<xbins[xbin+1] ) {
730 double n =
h->GetBinContent(i);
731 double nh = h2->GetBinContent(xbin+1);
732 h2->SetBinContent(xbin+1, nh+n);
745 std::vector<double>
bins(
h->GetNbinsX()+1);
746 for (
int i=0 ; i<
h->GetNbinsX()+1 ; i++ )
bins[i] =
h->GetBinLowEdge(i+1);
760 for (
int i=0 ; i<=
h->GetNbinsX()+1 ; i++ ) {
761 total +=
h->GetBinContent(i);
763 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
764 double x =
h->GetBinCenter(i);
766 good +=
h->GetBinContent(i);
770 v.value = good/total;
771 v.error = sqrt(v.value*(1-v.value)/total);
786 TH1D* e = (TH1D*)
m_mean->Clone();
787 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
796 e->SetBinContent(i, v.value);
797 e->SetBinError(i, v.error);
822 TH1D* e = (TH1D*)
m_mean->Clone();
823 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
831 double sigma =
m_sigma->GetBinContent(i);
836 e->SetBinContent(i, v.value);
837 e->SetBinError(i, v.error);
853 TF1* f1 =
new TF1(
"gausr",
"gaus");
859 TF1* f1 =
new TF1(
"rgausr",
"[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
864 TF1* f1 =
new TF1(
"rbreitr",
"x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
866 f1->SetParName(0,
"Maximum");
867 f1->SetParName(1,
"Median");
868 f1->SetParName(2,
"Gamma");
870 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
871 f1->SetParameter(1,s->GetMean());
872 f1->SetParameter(2,s->GetRMS());
880 if ( f1==0 )
return f1;
889 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
890 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
891 f1->SetParameter(2,sigma=s->GetRMS());
894 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
897 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
898 else s->Fit(f1,
"Q",
"",
a, b);
900 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
908 TF1* f1 =
new TF1(
"gausr",
"gaus");
917 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
918 f1->SetParameter(1,
mean=s->GetBinCenter(s->GetMaximumBin()));
919 f1->SetParameter(2,sigma=s->GetRMS());
922 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
926 TH1D* s_tmp = (TH1D*)s->Clone(
"duff");
927 s_tmp->SetDirectory(0);
951 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
952 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
957 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
964 if ( frac>3 ) s->Fit(f1,
"Q");
965 else s->Fit(f1,
"Q",
"", llim, ulim);
968 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
977 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
989 TF1* f1 =
new TF1(
"breitr",
"[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
991 f1->SetParName(0,
"Maximum");
992 f1->SetParName(1,
"Median");
993 f1->SetParName(2,
"Gamma");
995 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
996 f1->SetParameter(1,s->GetMean());
997 f1->SetParameter(2,s->GetRMS()*0.5);
1000 f1->SetLineWidth(1);
1002 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1006 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1010 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1011 else s->Fit(f1,
"Q",
"",
a, b);
1014 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1017 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1028 std::cout <<
"FitATan() " << s->GetName() <<
" " << s->GetTitle() << std::endl;
1034 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);
1036 f1->SetParName(0,
"Mean");
1037 f1->SetParName(1,
"Gradient");
1038 f1->SetParName(2,
"Pedestal");
1039 f1->SetParName(3,
"Norm");
1040 f1->SetParName(4,
"Power");
1043 for (
int i=1 ; i<=s->GetNbinsX() ; i++ )
if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1050 f1->SetParameter(0, 2 );
1051 f1->SetParameter(1, 10 );
1052 f1->SetParameter(2, 0.001 );
1053 f1->SetParameter(3, 100 );
1054 f1->SetParameter(4, 1 );
1056 f1->FixParameter(2, 0);
1057 f1->FixParameter(3, 100);
1061 f1->SetLineWidth(1);
1068 s->SetMarkerStyle(20);
1077 std::cout <<
"par0 = " << f1->GetParameter(0) << std::endl;
1078 std::cout <<
"par1 = " << f1->GetParameter(1) << std::endl;
1079 std::cout <<
"par2 = " << f1->GetParameter(2) << std::endl;
1080 std::cout <<
"par3 = " << f1->GetParameter(3) << std::endl;
1081 std::cout <<
"par4 = " << f1->GetParameter(4) << std::endl;
1097 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1099 f->SetParName(0,
"Maximum");
1100 f->SetParName(1,
"Mean");
1101 f->SetParName(2,
"RMS");
1103 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1104 f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1105 f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1125 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1127 double mean = s->GetMean();
1128 double meane = s->GetMeanError();
1134 for (
int it=0 ; it<20 ; it++ ) {
1138 int imax = s->GetXaxis()->FindBin(
mean);
1140 double sumn = s->GetBinContent(
imax);
1152 const int upperbin_i =
imax+i;
1153 const int lowerbin_i =
imax-i;
1155 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1157 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1168 upperbin = upperbin_i;
1169 lowerbin = lowerbin_i;
1174 s->GetXaxis()->SetRange(lowerbin, upperbin);
1176 double m = s->GetMean();
1177 double me = s->GetMeanError();
1181 std::fabs(
mean-m)<me*1e-5 ||
1182 std::fabs(
mean-m)<meane*1e-5 ) {
1203 for (
int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1205 if ( s->GetBinContent(i)>s->GetBinContent(
imax) )
imax = i;
1215 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1217 f->SetParName(0,
"Maximum");
1218 f->SetParName(1,
"Mean");
1219 f->SetParName(2,
"RMS");
1221 f->SetParameter(0, 0);
1222 f->SetParameter(1, 0);
1223 f->SetParameter(2, 0);
1225 if ( s==0 ) { std::cerr <<
"FitNull95() histogram s = " << s << std::endl;
return 0; }
1226 if ( s->GetXaxis()==0) { std::cerr <<
"FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1230 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1233 std::cout <<
"FitNull95 " << s->GetName()
1261 int imax = s->GetXaxis()->FindBin(m);
1265 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1276 double sumn = s->GetBinContent(
imax);
1278 int upperbin =
imax;
1279 int lowerbin =
imax;
1281 double uppersum = 0;
1282 double lowersum = 0;
1285 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1295 const int upperbin_i =
imax+i;
1296 const int lowerbin_i =
imax-i;
1298 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1300 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1315 upperbin = upperbin_i;
1316 lowerbin = lowerbin_i;
1324 if ( uppersum==0 ) {
1325 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1339 if ( upperbin!=lowerbin ) {
1341 double llim = s->GetBinLowEdge(1);
1342 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1347 std::vector<double> stats;
1354 s->GetXaxis()->SetRange(lowerbin, upperbin);
1376 rlower = s->GetRMS();
1377 erlower = s->GetRMSError();
1380 if ( errorflag==0 ) {
1384 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1396 rupper = s->GetRMS();
1397 erupper = s->GetRMSError();
1403 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1404 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1408 s->GetXaxis()->SetRange(lowerbin, upperbin);
1416 erms = s->GetRMSError();
1422 std::cout <<
"numbers " << s->GetName()
1426 std::cout <<
"fractions " << s->GetName()
1430 std::cout <<
"lowersum " << s->GetName() <<
"\t" << lowersum <<
"\tuppersum " << uppersum << std::endl;
1432 std::cout <<
"limits " << s->GetName() <<
"\t" << s->GetBinLowEdge(lowerbin) <<
" - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1434 std::cout <<
"FitNULL95Obsolete() " << s->GetName() <<
"\t rms " << rms <<
" +- " << erms <<
"\t inv " << 1/rms << std::endl;
1436 printf(
"rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1438 printf(
"rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1449 f->FixParameter(2, scale*rms);
1450 f->SetParError(2, scale*erms);
1451 f->FixParameter(1, s->GetMean());
1452 f->SetParError(1, s->GetMeanError());
1453 s->GetXaxis()->SetRangeUser(llim, ulim);
1457 f->FixParameter(1, 0);
1458 f->SetParError(1, 0);
1459 f->FixParameter(2, 0);
1460 f->SetParError(2, 0);
1463 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1484 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1486 f->SetParName(0,
"Maximum");
1487 f->SetParName(1,
"Mean");
1488 f->SetParName(2,
"RMS");
1490 f->SetParameter(0, 0);
1491 f->SetParameter(1, 0);
1492 f->SetParameter(2, 0);
1494 if ( s->GetEffectiveEntries()==0 )
return f;
1498 const double entries = s->GetEffectiveEntries();
1500 int nexperiments_ = 0;
1501 int nexperiments_max = 40;
1502 int nexperiments_min = 20;
1507 int nexperiments = 20+int(1000/
entries);
1511 if ( nexperiments_!=0 ) nexperiments = nexperiments_;
1514 if ( nexperiments>nexperiments_max ) nexperiments = nexperiments_max;
1515 if ( nexperiments<nexperiments_min ) nexperiments = nexperiments_min;
1532 f->FixParameter( 1, e.hmean() );
1533 f->SetParError( 1, e.mean_error() );
1535 f->FixParameter( 2, scale*e.hrms() );
1536 f->SetParError( 2, scale*e.rms_error() );
1555 TF1* f=
new TF1(
"null",
"[0]+[1]+[2]");
1557 f->SetParName(0,
"Maximum");
1558 f->SetParName(1,
"Mean");
1559 f->SetParName(2,
"RMS");
1561 f->SetParameter(0, 0);
1562 f->SetParameter(1, 0);
1563 f->SetParameter(2, 0);
1565 if ( s==0 ) { std::cerr <<
"FitNull95() histogram s = " << s << std::endl;
return 0; }
1566 if ( s->GetXaxis()==0) { std::cerr <<
"FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl;
return 0; }
1573 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1585 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1589 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1593 double sumn = s->GetBinContent(
imax);
1597 int upperbin =
imax;
1598 int lowerbin =
imax;
1600 double uppersum = 0;
1601 double lowersum = 0;
1608 const int upperbin_i =
imax+i;
1609 const int lowerbin_i =
imax-i;
1611 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 )
break;
1613 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1621 upperbin = upperbin_i;
1622 lowerbin = lowerbin_i;
1636 if ( upperbin!=lowerbin ) {
1638 double llim = s->GetBinLowEdge(1);
1639 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1644 std::vector<double> stats;
1647 s->GetXaxis()->SetRange(lowerbin, upperbin);
1666 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1676 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1677 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1681 s->GetXaxis()->SetRange(lowerbin, upperbin);
1692 f->FixParameter(2, rms);
1693 f->SetParError(2, erms);
1694 f->FixParameter(1, s->GetMean());
1695 f->SetParError(1, s->GetMeanError());
1697 s->GetXaxis()->SetRangeUser(llim, ulim);
1700 f->FixParameter(1, 0);
1701 f->SetParError(1, 0);
1702 f->FixParameter(2, 0);
1703 f->SetParError(2, 0);
1707 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1729 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)");
1730 TF1 *f1 =
new TF1(
"poisson", fstring );
1733 f1->SetParName(0,
"Maximum");
1734 f1->SetParName(1,
"Mean");
1735 f1->SetParName(2,
"Scale");
1736 f1->SetParName(3,
"Offset");
1739 f1->SetLineWidth(1);
1740 f1->SetLineColor(s->GetLineColor());
1743 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1745 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1746 f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1747 f1->SetParameter(2,1);
1748 f1->FixParameter(3,0);
1754 if (
a==-999 || b==-999 ) s->Fit(f1);
1755 else s->Fit(f1,
"",
"",
a, b);
1758 for (
int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1771 TF1* f1 =
new TF1(
"xexpr",
"[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1773 f1->SetParName(0,
"Normalisation");
1774 f1->SetParName(1,
"Power");
1775 f1->SetParName(2,
"Lifetime");
1776 f1->SetParName(3,
"offset");
1779 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1781 f1->SetParameter(2, s->GetRMS() );
1783 f1->SetParameter(1, 0);
1784 f1->SetParameter(3, 0);
1792 f1->SetLineWidth(1);
1795 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)>0) nbins++;
1801 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1802 else s->Fit(f1,
"Q",
"",
a, b);
1805 for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1832 Double_t invsq2pi = 0.3989422804014;
1833 Double_t mpshift = -0.22278298;
1839 double&
x = x_par[0];
1853 mpc = par[1] - mpshift*par[2];
1859 xlow =
x -
sc * par[3];
1860 xupp =
x +
sc * par[3];
1862 step = (xupp-xlow) / np;
1865 for(i=1.0; i<=np/2; i++) {
1866 xx = xlow + (i-0.5)*step;
1867 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
1868 sum += fland * TMath::Gaus(
x,xx,par[3]);
1870 xx = xupp - (i-0.5)*step;
1871 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
1872 sum += fland * TMath::Gaus(
x,xx,par[3]);
1875 return (par[0] * step * sum * invsq2pi / par[3]);
1886 TF1* f1 =
new TF1(
"landgaus",
langaufun, 0, 1, 4);
1889 f1->SetLineWidth(1);
1892 double start_vals[4];
1894 start_vals[0] = s->GetEntries();
1895 start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
1896 start_vals[2] = s->GetRMS();
1897 start_vals[3] = 0.5*start_vals[2];
1899 f1->SetParNames(
"Area",
"MP",
"Width",
"GSigma");
1900 f1->SetParameters(start_vals);
1906 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
1907 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
1910 for (
int j=1 ; j<=s->GetNbinsX() ; j++)
if (s->GetBinContent(j)) nbins++;
1913 if (
a==-999 || b==-999 ) s->Fit(f1,
"Q");
1914 else s->Fit(f1,
"Q",
"",
a, b);
1918 else for (
int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
static const std::vector< std::string > bins
void clear()
Empty the pool.
Header file for AthHistogramAlgorithm.
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 TH2D * rotate(const TH2 *h, const std::string &s="")
flip the x and y axes
StatVal GetEfficiency(TH1D *h, double lower, double upper)
TH1D * GetEfficiencies(const std::string &hname, double lower, double upper)
static std::vector< double > findbins(const TH1 *h, double epsilon)
static TH2D * copy(const TH2 *h, const std::string &s="")
copy a TH2
static const std::string s_rversion
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
void SetSecondary(int n, double a, double b)
static std::vector< double > getbins(const TH1 *h)
static TH1D * projectionY(TH2 *h2d, int col, const std::vector< double > &ylimits, const std::string &tagname)
actual local projections ...
static std::vector< double > getLimits(const TAxis *axis)
projection utilities ... NB: In athena, for some reason the destuctors for histograms created using T...
const std::string & Name(const std::string &s)
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...
const std::string & name() const
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=FitGaussian)
void SetPrimary(int n, const double *)
std::vector< TH1D * > m_slices
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
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)
TF1 * FitRGaussian(TH1D *s, double a=-999, double b=-999)
TF1 * FitCentralGaussian(TH1D *s, double a=-999, double b=-999)
int GetStats(TH1D *h, std::vector< double > &stats)
TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
void unZeroErrors(TH1D *h)
TF1 * FitGaussian(TH1D *s, double a=-999, double b=-999)
forward declation because we use this in the class ...
TF1 * FitRBreit(TH1D *s, double a=-999, double b=-999)
bool s_oldrms95
use the new error estimates
TF1 * FitNull95Central(TH1D *s)
TF1 * FitLandauGauss(TH1D *s, double a=-999, double b=-999)
TF1 * FitXExp(TH1D *s, double a=-999, double b=-999)
TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
double getWeights(TH1D *h)
Double_t langaufun(Double_t *x_par, Double_t *par)
std::string number(const double &x)
TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
double FindMean(TH1D *s, double frac=0.95)
TF1 * FitNull95(TH1D *s, double a=0, double b=0)
TF1 * FitPoisson(TH1D *s, double a=-999, double b=-999)
bool s_mAddDirectoryStatus
TF1 * FitATan(TH1D *s, double a=-999, double b=-999)
TF1 * FitBreit(TH1D *s, double a=-999, double b=-999)