ATLAS Offline Software
Loading...
Searching...
No Matches
Resplot Namespace Reference

Namespaces

namespace  generate

Classes

class  BasicRandom
class  Directory
class  Random
class  Resplot
class  StatVal
 simple struct to hold a value and it's associated uncertainty. More...
struct  tagname

Functions

TF1 * FitGaussian (TH1D *s, double a=-999, double b=-999)
 forward declation because we use this in the class ...
bool setoldrms95 (bool b)
bool setscalerms95 (bool b)
bool setnofit (bool b)
TF1 * FitInternal (TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
TF1 * FitRGaussian (TH1D *s, double a=-999, double b=-999)
TF1 * FitBreit (TH1D *s, double a=-999, double b=-999)
TF1 * FitRBreit (TH1D *s, double a=-999, double b=-999)
TF1 * FitATan (TH1D *s, double a=-999, double b=-999)
TF1 * FitNull (TH1D *s, double a=-999, double b=-999)
TF1 * FitPoisson (TH1D *s, double a=-999, double b=-999)
TF1 * FitXExp (TH1D *s, double a=-999, double b=-999)
TF1 * FitLandauGauss (TH1D *s, double a=-999, double b=-999)
TF1 * FitCentralGaussian (TH1D *s, double a=-999, double b=-999)
TF1 * FitNull95 (TH1D *s, double a=0, double b=0)
TF1 * FitNull95New (TH1D *s, double frac=0.95, bool useroot=false)
TF1 * FitNull95Obsolete (TH1D *s, double frac=0.95, bool useroot=false)
TF1 * FitNull95Central (TH1D *s)
Resplot operator* (double d, Resplot r)
StatVal operator* (double d, const StatVal &sv)
std::ostream & operator<< (std::ostream &s, const StatVal &sv)
std::ostream & operator<< (std::ostream &s, const Random &_r)
void binwidth (TH1D *h)
void ZeroErrors (TH1D *h)
void unZeroErrors (TH1D *h)
double getWeights (TH1D *h)
double getWeights (TH2D *h)
int GetStats (TH1D *h, std::vector< double > &stats)
std::string number (const double &x)
double NCounter (TH1D *h)
double FindMean (TH1D *s, double frac=0.95)
int findmax (TH1D *s)
Double_t langaufun (Double_t *x_par, Double_t *par)

Variables

bool s_mAddDirectoryStatus = false
bool s_interpolate_flag = true
bool s_nofit = false
bool s_oldrms95 = true
 use the new error estimates
bool s_scalerms95 = true

Function Documentation

◆ binwidth()

void Resplot::binwidth ( TH1D * h)

Definition at line 52 of file Resplot.cxx.

52 {
53
54 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) {
55 double d = h->GetBinLowEdge(i+1) - h->GetBinLowEdge(i);
56
57 h->SetBinContent(i, h->GetBinContent(i)/d );
58 h->SetBinError(i, h->GetBinError(i)/d );
59 }
60
61}
Header file for AthHistogramAlgorithm.

◆ findmax()

int Resplot::findmax ( TH1D * s)

find maximum bin

Definition at line 1201 of file Resplot.cxx.

1201 {
1202 int imax = 1;
1203 for ( int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1205 if ( s->GetBinContent(i)>s->GetBinContent(imax) ) imax = i;
1206 }
1207 return imax;
1208}
int imax(int i, int j)

◆ FindMean()

double Resplot::FindMean ( TH1D * s,
double frac = 0.95 )

Definition at line 1114 of file Resplot.cxx.

1114 {
1115
1116 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1117 double entries = generate::GetEntries(s,0,s->GetNbinsX()+1);
1118
1119 // std::cout << s->GetName() << "\tentries: " << entries << std::endl;
1120
1121 if ( entries==0 ) return 0;
1122
1123 // s->GetXaxis()->SetRangeUser(-100, 100);
1124 // s->GetXaxis()->UnZoom();
1125 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1126
1127 double mean = s->GetMean();
1128 double meane = s->GetMeanError();
1129
1130 int upperbin = 0;
1131 int lowerbin = 0;
1132
1133
1134 for ( int it=0 ; it<20 ; it++ ) {
1135
1136 // std::cout << it << "\tmean " << mean << " +- " << meane << std::endl;
1137
1138 int imax = s->GetXaxis()->FindBin(mean);
1139
1140 double sumn = s->GetBinContent(imax);
1141
1142 // double uppersum = 0;
1143 // double lowersum = 0;
1144
1145 upperbin = imax;
1146 lowerbin = imax;
1147
1148
1149 int i=1;
1150 while ( true ) {
1151
1152 const int upperbin_i = imax+i;
1153 const int lowerbin_i = imax-i;
1154
1155 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1156
1157 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1158
1159 if ( tsum>entries*frac ) {
1160 // uppersum = tsum/entries;
1161 break;
1162 }
1163
1164 // lowersum = tsum/entries;
1165
1166 sumn = tsum;
1167
1168 upperbin = upperbin_i;
1169 lowerbin = lowerbin_i;
1170
1171 i++;
1172 }
1173
1174 s->GetXaxis()->SetRange(lowerbin, upperbin);
1175
1176 double m = s->GetMean();
1177 double me = s->GetMeanError();
1178
1179 if ( it>0 ) {
1180 if ( mean==m ||
1181 std::fabs(mean-m)<me*1e-5 ||
1182 std::fabs(mean-m)<meane*1e-5 ) {
1183 mean = m;
1184 meane = me;
1185 break;
1186 }
1187 }
1188
1189 mean = m;
1190 meane = me;
1191
1192 }
1193
1194 // std::cout << "mean " << mean << " +- " << meane << "\tentries: " << generate::GetEntries(s) << "\tlower " << lowerbin << " - " << upperbin << std::endl;
1195
1196
1197 return mean;
1198}
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 entries
Definition listroot.cxx:49
double GetEntries(TH1D *h, int ilow, int ihi)
Definition rmsFrac.cxx:20

◆ FitATan()

TF1 * Resplot::FitATan ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 1025 of file Resplot.cxx.

1025 {
1026 // static int counter = 0;
1027
1028 std::cout << "FitATan() " << s->GetName() << " " << s->GetTitle() << std::endl;
1029
1030 char name[8];
1031 // sprintf(name,"atan_%02d", counter); counter++;
1032
1033 // Cannot use "M_PI" here as root does not replace M_PI in the string expressions for function in TF1 definition
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);
1035
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");
1041
1042 int maxn=1;
1043 for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1044
1045
1046 // f1->SetParameter(0,s->GetBinContent(maxn) );
1047 // f1->SetParameter(1,s->GetBinCenter(s->GetNbinsX()/2) );
1048 // f1->SetParameter(2,0.25);
1049
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 );
1055
1056 f1->FixParameter(2, 0);
1057 f1->FixParameter(3, 100);
1058 // f1->FixParameter(4, 1);
1059
1060 f1->SetNpx(5000);
1061 f1->SetLineWidth(1);
1062
1063
1064 // int nbins=0;
1065
1066
1067 // ZeroErrors(s);
1068 s->SetMarkerStyle(20);
1069
1070
1071 // int n=0;
1072 // for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent() ) n++;
1073 // if ( n>2 ) s->Fit(f1,"Q");
1074
1075 s->Fit(f1,"Q");
1076
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;
1082
1083
1084 // unZeroErrors(s);
1085 // s->SetMaximum(f1->GetParameter(0)*1.1);
1086 // double range = s->GetBinLowEdge(s->GetNbinsX()+1) - s->GetBinLowEdge(1) ;
1087
1088 return f1;
1089}

◆ FitBreit()

TF1 * Resplot::Resplot::FitBreit ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 986 of file Resplot.cxx.

986 {
987
988 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
989 TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
990
991 f1->SetParName(0, "Maximum");
992 f1->SetParName(1, "Median");
993 f1->SetParName(2, "Gamma");
994
995 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
996 f1->SetParameter(1,s->GetMean());
997 f1->SetParameter(2,s->GetRMS()*0.5);
998
999 f1->SetNpx(5000);
1000 f1->SetLineWidth(1);
1001
1002 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1003
1004
1005 int nbins=0;
1006 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1007
1008 if (nbins>2) {
1009 // std::cout << "fitting " << f1 << std::endl;
1010 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1011 else s->Fit(f1,"Q", "", a, b);
1012 }
1013 else {
1014 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1015 }
1016
1017 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1018
1019 return f1;
1020}
static Double_t a
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ FitCentralGaussian()

TF1 * Resplot::FitCentralGaussian ( TH1D * s,
double a = -999,
double b = -999 )

if the fit is "bad" fit only to the central region

calculate difference from maximum of fit, and hist maximum

Definition at line 907 of file Resplot.cxx.

907 {
908 TF1* f1 = new TF1("gausr", "gaus");
909
910 f1->SetNpx(5000);
911 f1->SetLineWidth(1);
912
913 double mean = 0;
914 double sigma = 0;
915
916
917 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
918 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
919 f1->SetParameter(2,sigma=s->GetRMS());
920
921 int nbins=0;
922 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
923
924 if (nbins>2) {
925
926 TH1D* s_tmp = (TH1D*)s->Clone("duff");
927 s_tmp->SetDirectory(0);
928 s_tmp->Fit(f1,"Q");
929
930
932
934
935 // double sig = std::sqrt( f1->GetParError(0)*f1->GetParError(0) + s->GetBinError(s->GetMaximumBin())*s->GetBinError(s->GetMaximumBin()) );
936 // double diff = std::fabs( (f1->GetParameter(0) - s->GetBinContent(s->GetMaximumBin()) ) )/sig;
937
938 // std::cout << "diff " << diff << "\tfit " << f1->GetParameter(0) << "\thist " << s->GetBinContent(s->GetMaximumBin()) << std::endl;
939
940 // if ( diff>2 ) {
941
942
943 // double n = s->GetBinContent(s->GetMaximumBin());
944
945 double frac = 1.25;
946
947 // if ( n<25 ) {
948 // frac = 1.2*n/25.0 + 4.0*(25.0-n)/25.0;
949 // }
950
951 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
952 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
953
954
955
956 int nbins=0;
957 for (int j=1 ; j<=s->GetNbinsX() ; j++) if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
958
959 if ( nbins>2 ) {
960
961 // if ( frac>3 ) s->Fit(f1,"Q");
962 // else s->Fit(f1,"Q", "", llim, ulim);
963
964 if ( frac>3 ) s->Fit(f1,"Q");
965 else s->Fit(f1,"Q", "", llim, ulim);
966
967 }
968 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
969
970 delete s_tmp;
971
972
973
974 // std::cout << "Resplot::Finalise() " << s->GetName() << "\trange " << lower << " - " << upper << std::endl;
975
976 }
977 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
978
979 return f1;
980}

◆ FitGaussian()

TF1 * Resplot::FitGaussian ( TH1D * s,
double a = -999,
double b = -999 )

forward declation because we use this in the class ...

Definition at line 852 of file Resplot.cxx.

852 {
853 TF1* f1 = new TF1("gausr", "gaus");
854 return FitInternal( s, a, b, f1 );
855 // s->GetXaxis()->SetRangeUser(-1, 1);
856}
TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
Definition Resplot.cxx:878

◆ FitInternal()

TF1 * Resplot::FitInternal ( TH1D * s,
double a = -999,
double b = -999,
TF1 * f1 = 0 )

Definition at line 878 of file Resplot.cxx.

878 {
879
880 if ( f1==0 ) return f1;
881
882 f1->SetNpx(5000);
883 f1->SetLineWidth(1);
884
885 double mean = 0;
886 double sigma = 0;
887
888
889 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
890 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
891 f1->SetParameter(2,sigma=s->GetRMS());
892
893 int nbins=0;
894 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
895
896 if (nbins>2) {
897 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
898 else s->Fit(f1,"Q", "", a, b);
899 }
900 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
901
902 return f1;
903}

◆ FitLandauGauss()

TF1 * Resplot::FitLandauGauss ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 1882 of file Resplot.cxx.

1882 {
1883 // TF1* f1 = new TF1("landgaus", "landgaus");
1884 // root is STUPID and you have to specify the FIT RANGE if you
1885 // want to specify the number of fit parameters!!!
1886 TF1* f1 = new TF1("landgaus", langaufun, 0, 1, 4);
1887
1888 f1->SetNpx(5000);
1889 f1->SetLineWidth(1);
1890
1891 // parameter starting values
1892 double start_vals[4]; // = { 0.1, 3.0, 1.0, 0.3 };
1893
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];
1898
1899 f1->SetParNames("Area", "MP", "Width", "GSigma");
1900 f1->SetParameters(start_vals);
1901
1902 // parameter low and high values for the fit
1903 // double par_lo[4] = { 0.0, -20.0, 0.0, 0.00 };
1904 // double par_hi[4] = { 20000.0, 50000.0, 50.0, 0.01 };
1905 // for ( int i=0 ; i<4 ; i++ ) f1->SetParLimits(i, par_lo[i], par_hi[i]);
1906 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
1907 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
1908
1909 int nbins=0;
1910 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
1911
1912 if (nbins>2) {
1913 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1914 else s->Fit(f1,"Q", "", a, b);
1915 // if ( a==-999 || b==-999 ) s->Fit(f1);
1916 // else s->Fit(f1,"", "", a, b);
1917 }
1918 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1919
1920 return f1;
1921}
Double_t langaufun(Double_t *x_par, Double_t *par)
Definition Resplot.cxx:1818

◆ FitNull()

TF1 * Resplot::FitNull ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 1093 of file Resplot.cxx.

1093 {
1094
1095 // unZeroErrors(s);
1096
1097 TF1* f=new TF1("null", "[0]+[1]+[2]");
1098
1099 f->SetParName(0, "Maximum");
1100 f->SetParName(1, "Mean");
1101 f->SetParName(2, "RMS");
1102
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());
1106
1107 // std::cout << gDirectory->GetName() << " " << s->GetName() << "\tFitNull mean: " << f->GetParameter(1) << "\tsigma: " << f->GetParameter(2) << std::endl;
1108
1109 return f;
1110}

◆ FitNull95()

TF1 * Resplot::Resplot::FitNull95 ( TH1D * s,
double a = 0,
double b = 0 )

Definition at line 1472 of file Resplot.cxx.

1472 {
1473 if ( s_oldrms95 ) return FitNull95Obsolete( s, 0.95 );
1474 else return FitNull95New(s);
1475}
TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1480
bool s_oldrms95
use the new error estimates
Definition Resplot.cxx:46
TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1213

◆ FitNull95Central()

TF1 * Resplot::Resplot::FitNull95Central ( TH1D * s)

NB: try to find with respect to maximum bin, rather than the mean. double m = s->GetMean();

double m = FindMean(s); int imax = s->GetXaxis()->FindBin(m);

root does not calculate the uncertainty on the rms correctly

Definition at line 1553 of file Resplot.cxx.

1553 {
1554
1555 TF1* f=new TF1("null", "[0]+[1]+[2]");
1556
1557 f->SetParName(0, "Maximum");
1558 f->SetParName(1, "Mean");
1559 f->SetParName(2, "RMS");
1560
1561 f->SetParameter(0, 0);
1562 f->SetParameter(1, 0);
1563 f->SetParameter(2, 0);
1564
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; }
1567
1568 // std::cout << "FitNull " << s->GetName() << " " << generate::GetEntries(s) << std::endl;
1569
1570 if ( generate::GetEntries(s)<20 ) return f;
1571 // if ( s->GetEffectiveEntries<20 ) return f;
1572
1573 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1574 // s->GetXaxis()->UnZoom();
1575
1576
1579
1582
1583 int imax = findmax(s);
1584
1585 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1586 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1587
1588
1589 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1590
1591 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1592 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1593 double sumn = s->GetBinContent(imax);
1594
1595 double frac = 0.95;
1596
1597 int upperbin = imax;
1598 int lowerbin = imax;
1599
1600 double uppersum = 0;
1601 double lowersum = 0;
1602
1603 if ( entries>0 ) {
1604
1605 int i=1;
1606 while ( true ) {
1607
1608 const int upperbin_i = imax+i;
1609 const int lowerbin_i = imax-i;
1610
1611 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1612
1613 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1614
1615 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1616
1617 lowersum = tsum/entries;
1618
1619 sumn = tsum;
1620
1621 upperbin = upperbin_i;
1622 lowerbin = lowerbin_i;
1623
1624 i++;
1625 }
1626 }
1627
1628 // std::cout << "FitNull95 " << s->GetName() << " " << upperbin << " " << lowerbin << std::endl;
1629
1630 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1631 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1632 // << std::endl;
1633
1634 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1635
1636 if ( upperbin!=lowerbin ) {
1637
1638 double llim = s->GetBinLowEdge(1);
1639 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1640
1641 double rms = 0;
1642 double erms = 0;
1643
1644 std::vector<double> stats;
1645
1646 if ( s_interpolate_flag ) {
1647 s->GetXaxis()->SetRange(lowerbin, upperbin);
1648
1649
1650 double rlower;
1651 double erlower;
1652
1653 double rupper;
1654 double erupper;
1655
1656
1658
1659 GetStats( s, stats );
1660 rlower = stats[2];
1661 erlower = stats[3];
1662
1663 // std::cout << "FitNULL95() " << s->GetName() << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1664 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1665
1666 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1667
1668 GetStats( s, stats );
1669 rupper = stats[2];
1670 erupper = stats[3];
1671
1672 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1673
1674 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1675
1676 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1677 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1678
1679 }
1680 else {
1681 s->GetXaxis()->SetRange(lowerbin, upperbin);
1682 GetStats( s, stats );
1683
1684 rms = stats[2];
1685 erms = stats[3];
1686
1687 }
1688
1689
1690 // f->FixParameter(2, s->GetRMS());
1691 // f->SetParError(2, s->GetRMSError());
1692 f->FixParameter(2, rms);
1693 f->SetParError(2, erms);
1694 f->FixParameter(1, s->GetMean());
1695 f->SetParError(1, s->GetMeanError());
1696 // std::cout << s->GetName() << " " << s->GetTitle() << "\t 95% inter rms " << rms << " +- " << erms << std::endl;
1697 s->GetXaxis()->SetRangeUser(llim, ulim);
1698 }
1699 else {
1700 f->FixParameter(1, 0);
1701 f->SetParError(1, 0);
1702 f->FixParameter(2, 0);
1703 f->SetParError(2, 0);
1704 // std::cout << " 95% rms " << 0 << " +- " << 0 << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1705 }
1706
1707 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1708
1709 return f;
1710}
int GetStats(TH1D *h, std::vector< double > &stats)
Definition Resplot.cxx:115
bool s_interpolate_flag
Definition Resplot.cxx:42
int findmax(TH1D *s)
Definition Resplot.cxx:1201

◆ FitNull95New()

TF1 * Resplot::FitNull95New ( TH1D * s,
double frac = 0.95,
bool useroot = false )

calculate the

a "corrected" rms of the inner 0.95% of the data, corrected such that for a gaussian, will return 1.

Definition at line 1480 of file Resplot.cxx.

1480 { // double frac, bool useroot ) {
1481
1482 // std::cout << "---------------------------------------\nFN95 " << std::endl;
1483
1484 TF1* f=new TF1("null", "[0]+[1]+[2]");
1485
1486 f->SetParName(0, "Maximum");
1487 f->SetParName(1, "Mean");
1488 f->SetParName(2, "RMS");
1489
1490 f->SetParameter(0, 0);
1491 f->SetParameter(1, 0);
1492 f->SetParameter(2, 0);
1493
1494 if ( s->GetEffectiveEntries()==0 ) return f;
1495
1496
1497 // double _entries = getWeights( s );
1498 const double entries = s->GetEffectiveEntries();
1499
1500 int nexperiments_ = 0;
1501 int nexperiments_max = 40;
1502 int nexperiments_min = 20;
1503
1504
1505 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1506 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1507 int nexperiments = 20+int(1000/entries);
1508
1509
1510
1511 if ( nexperiments_!=0 ) nexperiments = nexperiments_;
1512
1513
1514 if ( nexperiments>nexperiments_max ) nexperiments = nexperiments_max;
1515 if ( nexperiments<nexperiments_min ) nexperiments = nexperiments_min;
1516
1517 // std::cout << "FitNull95 entries " << entries << "\tnexperiments " << nexperiments << std::endl;
1518
1519 // std::cout << "experiments " << nexperiments_ << std::endl;
1520
1521 // std::cout << "h entries " << s->GetEntries() << "\tn experiments " << nexperiments << "\tN " << s->GetEntries()*nexperiments << std::endl;
1522
1524 generate::experiment e( s, nexperiments, entries );
1525
1528 double scale = 1;
1529 if ( s_scalerms95 ) scale = 1.1479538518;
1530
1531 // f->FixParameter( 1, s->GetMean() );
1532 f->FixParameter( 1, e.hmean() );
1533 f->SetParError( 1, e.mean_error() );
1534
1535 f->FixParameter( 2, scale*e.hrms() );
1536 f->SetParError( 2, scale*e.rms_error() );
1537
1538 // s->GetXaxis()->SetRange(1, s->GetNbinsX());
1539
1540 // s->GetXaxis()->SetRangeUser(-1, 1);
1541
1542 return f;
1543}
given a histogram, get a generator for the distribution in that histogram, then run some pseudo-exper...
Definition generate.h:134
bool s_scalerms95
Definition Resplot.cxx:47

◆ FitNull95Obsolete()

TF1 * Resplot::Resplot::FitNull95Obsolete ( TH1D * s,
double frac = 0.95,
bool useroot = false )

this line causes a crash, even though s->GetXaxis() returns the x axis ok

root does not calculate the uncertainty on the rms correctly

a "corrected" rms of the inner 0.95% of the data, corrected such that for a gaussian, will return 1.

Definition at line 1213 of file Resplot.cxx.

1213 {
1214
1215 TF1* f=new TF1("null", "[0]+[1]+[2]");
1216
1217 f->SetParName(0, "Maximum");
1218 f->SetParName(1, "Mean");
1219 f->SetParName(2, "RMS");
1220
1221 f->SetParameter(0, 0);
1222 f->SetParameter(1, 0);
1223 f->SetParameter(2, 0);
1224
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; }
1227
1228 unZeroErrors(s);
1229
1230 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1231
1232#if 0
1233 std::cout << "FitNull95 " << s->GetName()
1234 << " " << generate::GetEntries(s)
1235 << " " << generate::GetEntries(s, 0, s->GetNbinsX()+1)
1236 << std::endl;
1237#endif
1238
1239
1240 if ( generate::GetEntries(s)<10 ) return f;
1241
1242 // std::cout << "---------------------------------------\nFN95O frac: " << frac << " " << s << std::endl;
1243
1244 // std::cout << __LINE__ << std::endl;
1245
1246
1247
1248 // std::cout << __LINE__ << " " << s->GetXaxis() << std::endl;
1249
1252 // s->GetXaxis()->UnZoom();
1253
1254 // std::cout << __LINE__ << std::endl;
1255
1256 // double m = s->GetMean();
1257 double m = FindMean(s,frac);
1258
1259 // std::cout << __LINE__ << std::endl;
1260
1261 int imax = s->GetXaxis()->FindBin(m);
1262
1263 // std::cout << "mean " << m << " " << imax << " max " << s->GetBinCenter(findmax(s)) << " " << findmax(s) << std::endl;
1264
1265 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1266 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1267
1268 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1269 double entries = generate::GetEntries(s,0,(s->GetNbinsX()+1));
1270
1271 // std::cout << "entries: " << entries << "\t" << generate::GetEntries(s) << "\t" << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1272
1273 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1274 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1275
1276 double sumn = s->GetBinContent(imax);
1277
1278 int upperbin = imax;
1279 int lowerbin = imax;
1280
1281 double uppersum = 0;
1282 double lowersum = 0;
1283
1284 if ( sumn>entries*frac ) {
1285 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1286 // ErrorSet = BINWIDTH;
1287 return f;
1288 }
1289
1290 if ( entries>0 ) {
1291
1292 int i=1;
1293 while ( true ) {
1294
1295 const int upperbin_i = imax+i;
1296 const int lowerbin_i = imax-i;
1297
1298 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1299
1300 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1301
1302 // std::cout << i << " frac: " << lowersum
1303 // << "\tx " << s->GetBinCenter(lowerbin)
1304 // << "\t " << s->GetBinCenter(upperbin)
1305 // << "\ttsum " << tsum
1306 // << "\tentries " << entries
1307 // << std::endl;
1308
1309 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1310
1311 lowersum = tsum/entries;
1312
1313 sumn = tsum;
1314
1315 upperbin = upperbin_i;
1316 lowerbin = lowerbin_i;
1317
1318 // if ( std::fabs(lowersum-frac)<0.1 )
1319
1320 i++;
1321 }
1322 }
1323
1324 if ( uppersum==0 ) {
1325 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1326 // ErrorSet = HISTOWIDTH;
1327 return f;
1328 }
1329
1330 // std::cout << "FitNull95 " << s->GetName() << "\tlower bin " << lowerbin << "\t upper bin " << upperbin << std::endl;
1331
1332 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1333 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1334 // << std::endl;
1335
1336 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1337
1338 // if ( true ) { // technically wrong - 95% contained in only 3 bins, so RMS of the "central" bin is not defined
1339 if ( upperbin!=lowerbin ) {
1340
1341 double llim = s->GetBinLowEdge(1);
1342 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1343
1344 double rms = 0;
1345 double erms = 0;
1346
1347 std::vector<double> stats;
1348
1349 // double sentries = generate::GetEntries(s);
1350
1351 // std::cout << "GetEntries " << s->GetName() << " " << sentries << std::endl;
1352
1353 if ( s_interpolate_flag ) {
1354 s->GetXaxis()->SetRange(lowerbin, upperbin);
1355
1356 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin,upperbin)/sentries << std::endl;
1357
1358 double rlower;
1359 double erlower;
1360
1361 double rupper;
1362 double erupper;
1363
1364 int errorflag = 0;
1365
1367 //certain values (rlower, erlower, rupper, erupper) are overwritten before they are used
1368 //due to the commented 'else'; add notation to indicate this is intentional.
1369 if ( !useroot ) {
1370 errorflag = GetStats( s, stats );
1371 rlower = stats[2];
1372 erlower = stats[3];
1373 // std::cout << "mu: " << stats[0] << " " << s->GetMean() << "\trlower: " << rlower << "\t+- " << erlower << "\troot: " << s->GetRMS() << " +- " << s->GetRMSError() << "\t(errorflags: " << errorflag << ")" << std::endl;
1374 }
1375 else {
1376 rlower = s->GetRMS();
1377 erlower = s->GetRMSError();
1378 }
1379
1380 if ( errorflag==0 ) {
1381 // std::cout << "FitNULL95() " << s->GetName() << "\tmean " << m << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1382 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1383
1384 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1385
1386 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin-1,upperbin+1)/sentries << std::endl;
1387 // std::cout << "Range " << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1388
1389 if ( !useroot ) {
1390 errorflag = GetStats( s, stats );
1391 rupper = stats[2];
1392 erupper = stats[3];
1393 // std::cout << "mu: " << stats[0] << " " << s->GetMean() << "\trlower: " << rupper << "\t+- " << erupper << "\troot: " << s->GetRMS() << " +- " << s->GetRMSError() << "\t(errorflag: " << errorflag << ") II" << std::endl;
1394 }
1395 else {
1396 rupper = s->GetRMS();
1397 erupper = s->GetRMSError();
1398 }
1399
1400 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1401 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1402
1403 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1404 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1405 }
1406 }
1407 else {
1408 s->GetXaxis()->SetRange(lowerbin, upperbin);
1409 if ( !useroot ) {
1410 GetStats( s, stats );
1411 rms = stats[2];
1412 erms = stats[3];
1413 }
1414 else {
1415 rms = s->GetRMS();
1416 erms = s->GetRMSError();
1417 }
1418 }
1419
1420#if 0
1421
1422 std::cout << "numbers " << s->GetName()
1423 << " " << generate::GetEntries(s,lowerbin,upperbin)
1424 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1) << "\ttotal " << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1425
1426 std::cout << "fractions " << s->GetName()
1427 << "\t" << generate::GetEntries(s,lowerbin,upperbin)/generate::GetEntries(s,0,s->GetNbinsX()+1)
1428 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1)/generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1429
1430 std::cout << "lowersum " << s->GetName() << "\t" << lowersum << "\tuppersum " << uppersum << std::endl;
1431
1432 std::cout << "limits " << s->GetName() << "\t" << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1433
1434 std::cout << "FitNULL95Obsolete() " << s->GetName() << "\t rms " << rms << " +- " << erms << "\t inv " << 1/rms << std::endl;
1435
1436 printf("rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1437
1438 printf("rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1439#endif
1440
1441
1444 double scale = 1;
1445 if ( s_scalerms95 ) scale = 1.1479538518;
1446
1447 // f->FixParameter(2, s->GetRMS());
1448 // f->SetParError(2, s->GetRMSError());
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);
1454
1455 }
1456 else {
1457 f->FixParameter(1, 0);
1458 f->SetParError(1, 0);
1459 f->FixParameter(2, 0);
1460 f->SetParError(2, 0);
1461 }
1462
1463 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1464
1465 return f;
1466}
void unZeroErrors(TH1D *h)
Definition Resplot.cxx:75
double FindMean(TH1D *s, double frac=0.95)
Definition Resplot.cxx:1114

◆ FitPoisson()

TF1 * Resplot::Resplot::FitPoisson ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 1726 of file Resplot.cxx.

1726 {
1727
1728 char fstring[1024];
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 );
1731 // TF1* f1 = new TF1("poiss","[0]*TMath::Poisson(x*[2],[1])");
1732
1733 f1->SetParName(0, "Maximum");
1734 f1->SetParName(1, "Mean");
1735 f1->SetParName(2, "Scale");
1736 f1->SetParName(3, "Offset");
1737
1738 f1->SetNpx(5000);
1739 f1->SetLineWidth(1);
1740 f1->SetLineColor(s->GetLineColor());
1741
1742 int nbins=0;
1743 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1744
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);
1749
1750 if (nbins>2) {
1751 // std::cout << "fitting " << f1 << std::endl;
1752 // if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1753 // else s->Fit(f1,"Q", "", a, b);
1754 if ( a==-999 || b==-999 ) s->Fit(f1);
1755 else s->Fit(f1,"", "", a, b);
1756 }
1757 else {
1758 for ( int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1759 }
1760
1761 return f1;
1762}

◆ FitRBreit()

TF1 * Resplot::FitRBreit ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 863 of file Resplot.cxx.

863 {
864 TF1* f1 = new TF1("rbreitr", "x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
865
866 f1->SetParName(0, "Maximum");
867 f1->SetParName(1, "Median");
868 f1->SetParName(2, "Gamma");
869
870 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
871 f1->SetParameter(1,s->GetMean());
872 f1->SetParameter(2,s->GetRMS());
873
874 return FitInternal( s, a, b, f1 );
875}

◆ FitRGaussian()

TF1 * Resplot::FitRGaussian ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 858 of file Resplot.cxx.

858 {
859 TF1* f1 = new TF1("rgausr", "[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
860 return FitInternal( s, a, b, f1 );
861}

◆ FitXExp()

TF1 * Resplot::FitXExp ( TH1D * s,
double a = -999,
double b = -999 )

Definition at line 1766 of file Resplot.cxx.

1766 {
1767
1768 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
1769 // TF1* f1 = new TF1("xexpr", "[0]*(pow([2]*x,[1])*exp(-[2]*x))+[3]");
1770 // TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*(x-[3]),[1])*exp(-(1.0/[2])*(x-[3])))");
1771 TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1772
1773 f1->SetParName(0, "Normalisation");
1774 f1->SetParName(1, "Power");
1775 f1->SetParName(2, "Lifetime");
1776 f1->SetParName(3, "offset");
1777
1778 // f1->SetParameter(0, 1e-156);
1779 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1780 // f1->SetParameter(1, -1*(s->GetBinCenter(s->GetMaximumBin())) );
1781 f1->SetParameter(2, s->GetRMS() );
1782 // f1->SetParameter(1, 0);
1783 f1->SetParameter(1, 0);
1784 f1->SetParameter(3, 0);
1785
1786 // f1->FixParameter(0, 1);
1787 // f1->FixParameter(1, 25);
1788 // f1->FixParameter(1, 0);
1789 // f1->FixParameter(3, 0);
1790
1791 f1->SetNpx(5000);
1792 f1->SetLineWidth(1);
1793
1794 int nbins=0;
1795 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1796
1797 // std::cout << "starting exp fit p1=" << f1->GetParameter(1) << std::endl;
1798
1799 if (nbins>2) {
1800 // std::cout << "fitting " << f1 << std::endl;
1801 if ( a==-999 || b==-999 ) s->Fit(f1, "Q");
1802 else s->Fit(f1, "Q", "", a, b);
1803 }
1804 else {
1805 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1806 }
1807
1808 // std::cout << "done" << std::endl;
1809
1810 return f1;
1811}

◆ GetStats()

int Resplot::GetStats ( TH1D * h,
std::vector< double > & stats )

what all these egregious root versions of standard types and standard functions, uint32_t, std::fabs etc

calculate the rms and rms error ...

Definition at line 115 of file Resplot.cxx.

115 {
116
117 int errorstate = 0;
118
119 stats.assign(4,0);
120
121 TAxis& fXaxis = *h->GetXaxis();
122
125
126 Int_t firstBinX = fXaxis.GetFirst();
127 Int_t lastBinX = fXaxis.GetLast();
128
129 int del = lastBinX - firstBinX;
130
131 if ( del<1 ) return errorstate = 1;
132
133 double s = 0;
134 double sx = 0;
135
136 double sr2 = 0;
137 double sr4 = 0;
138
139 // if ( fXaxis.TestBit(TAxis::kAxisRange) ) {
140 // for (bin=0;bin<4;bin++) stats[bin] = 0;
141
142 // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
143 // if (fgStatOverflows && !fXaxis.TestBit(TAxis::kAxisRange)) {
144 // if (firstBinX == 1) firstBinX = 0;
145 // if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
146 // }
147
148 for (int binx = firstBinX; binx <= lastBinX; binx++) {
149 double x = fXaxis.GetBinCenter(binx);
150 double w = TMath::Abs(h->GetBinContent(binx));
151 s += w;
152 sx += w*x;
153 }
154
155 if (s<=0){
156 std::cerr << "\tUnphysical denominator zero or less in GetStats()\n";
157 return errorstate = 2;
158 }
159
160 double mu = sx/s;
161
162 for (int binx = firstBinX; binx <= lastBinX; binx++) {
163 double x = fXaxis.GetBinCenter(binx);
164 double w = TMath::Abs(h->GetBinContent(binx));
165 double r = (x-mu);
166 sr2 += w*r*r;
167 sr4 += w*r*r*r*r;
168 }
169
170
171 double v = sr2/s;
172
173 double rms = 0;
174 double rmserror = 0;
175
177
178 if ( v<=0 ) return errorstate = 3;
179
180 double rms0 = std::sqrt(v);
181
182 rms = rms0;
183 double r2 = 0.25*(sr4/v-sr2);
184
185 if ( r2>0 ) rmserror = std::sqrt(r2)/s;
186 else errorstate = 4;
187
188 // prepare return values ...
189
190 stats[0] = mu;
191 stats[1] = std::sqrt(v/s);
192
193 stats[2] = rms;
194 stats[3] = rmserror;
195
196#if 0
197 std::cout << "GetStats() "
198 // << "\tmean " << stats[0] << " +- " << stats[1]
199 << "\trms " << stats[2] << " +- " << stats[3] << "\t(" << rmserror1 << ")" << "\t root " << duff << std::endl;
200#endif
201
202 return errorstate;
203}
#define x
int r
Definition globals.cxx:22

◆ getWeights() [1/2]

double Resplot::getWeights ( TH1D * h)

Definition at line 81 of file Resplot.cxx.

81 {
82 double sum = 0;
83 double sume2 = 0;
84 for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) {
85 sum += h->GetBinContent(i);
86 sume2 += h->GetBinError(i)*h->GetBinError(i);
87 }
88 if ( sume2!=0 ) return sum*sum/sume2;
89 return 0;
90}

◆ getWeights() [2/2]

double Resplot::getWeights ( TH2D * h)

Definition at line 93 of file Resplot.cxx.

93 {
94
95 double sum = 0;
96 double sume2 = 0;
97
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);
102 }
103 }
104
105 if ( sume2!=0 ) return sum*sum/sume2;
106
107 return 0;
108}

◆ langaufun()

Double_t Resplot::langaufun ( Double_t * x_par,
Double_t * par )

Definition at line 1818 of file Resplot.cxx.

1818 {
1819
1820 //Fit parameters:
1821 //par[0]=Total area (integral -inf to inf, normalization constant)
1822 //par[1]=Most Probable (MP, location) parameter of Landau density
1823 //par[2]=Width (scale) parameter of Landau density
1824 //par[3]=Width (sigma) of convoluted Gaussian function
1825 //
1826 //In the Landau distribution (represented by the CERNLIB approximation),
1827 //the maximum is located at x=-0.22278298 with the location parameter=0.
1828 //This shift is corrected within this function, so that the actual
1829 //maximum is identical to the MP parameter.
1830
1831 // Numeric constants
1832 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
1833 Double_t mpshift = -0.22278298; // Landau maximum location
1834
1835 // Control constants
1836 Double_t np = 500; // number of convolution steps
1837 Double_t sc = 5; // convolution extends to +-sc Gaussian sigmas
1838
1839 double& x = x_par[0];
1840
1841 // Variables
1842 Double_t xx;
1843 Double_t mpc;
1844 Double_t fland;
1845 Double_t sum = 0.0;
1846 Double_t xlow,xupp;
1847 Double_t step;
1848 Double_t i;
1849
1850 // if ( par[2]<0.1*par[3] ) return 0;
1851
1852 // correct the most probable bin position as described above
1853 mpc = par[1] - mpshift*par[2];
1854
1855 // Range of convolution integral
1856
1857 // if ( par[3]<par[2] ) np = np*par[2]/par[3];
1858
1859 xlow = x - sc * par[3];
1860 xupp = x + sc * par[3];
1861
1862 step = (xupp-xlow) / np;
1863
1864 // Convolution integral of Landau and Gaussian by sum
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]);
1869
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]);
1873 }
1874
1875 return (par[0] * step * sum * invsq2pi / par[3]);
1876}
static Double_t sc

◆ NCounter()

double Resplot::NCounter ( TH1D * h)

Definition at line 417 of file Resplot.cxx.

417 {
418 double N=0;
419 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) N += h->GetBinContent(i);
420 return N;
421}

◆ number()

std::string Resplot::number ( const double & x)

Definition at line 410 of file Resplot.cxx.

410 {
411 std::ostringstream s;
412 s << x;
413 return s.str();
414}

◆ operator*() [1/2]

StatVal Resplot::operator* ( double d,
const StatVal & sv )
inline

Definition at line 52 of file StatVal.h.

52{ return sv*d; }

◆ operator*() [2/2]

Resplot Resplot::operator* ( double d,
Resplot r )
inline

Definition at line 770 of file Resplot.h.

770{ return (r*=d); }

◆ operator<<() [1/2]

std::ostream & Resplot::operator<< ( std::ostream & s,
const Random & _r )
inline

Definition at line 51 of file TrigAnalysis/TrigInDetAnalysisUser/Resplot/src/Random.h.

51 {
52 return s;
53}

◆ operator<<() [2/2]

std::ostream & Resplot::operator<< ( std::ostream & s,
const StatVal & sv )
inline

Definition at line 55 of file StatVal.h.

55 {
56 return s << sv.value << "+-" << sv.error;
57}

◆ setnofit()

bool Resplot::setnofit ( bool b)
inline

Definition at line 724 of file Resplot.h.

724{ return s_nofit=b; }
bool s_nofit
Definition Resplot.cxx:43

◆ setoldrms95()

bool Resplot::setoldrms95 ( bool b)
inline

Definition at line 722 of file Resplot.h.

722{ return s_oldrms95=b; }

◆ setscalerms95()

bool Resplot::setscalerms95 ( bool b)
inline

Definition at line 723 of file Resplot.h.

723{ return s_scalerms95=b; }

◆ unZeroErrors()

void Resplot::unZeroErrors ( TH1D * h)

Definition at line 75 of file Resplot.cxx.

75 {
76 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,0);
77}

◆ ZeroErrors()

void Resplot::ZeroErrors ( TH1D * h)

Definition at line 69 of file Resplot.cxx.

69 {
70 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,1);
71}

Variable Documentation

◆ s_interpolate_flag

bool Resplot::s_interpolate_flag = true

Definition at line 42 of file Resplot.cxx.

◆ s_mAddDirectoryStatus

bool Resplot::s_mAddDirectoryStatus = false

Definition at line 40 of file Resplot.cxx.

◆ s_nofit

bool Resplot::s_nofit = false

Definition at line 43 of file Resplot.cxx.

◆ s_oldrms95

bool Resplot::Resplot::s_oldrms95 = true

use the new error estimates

Definition at line 46 of file Resplot.cxx.

◆ s_scalerms95

bool Resplot::s_scalerms95 = true

Definition at line 47 of file Resplot.cxx.