本文整理汇总了C++中TAxis::GetLabels方法的典型用法代码示例。如果您正苦于以下问题:C++ TAxis::GetLabels方法的具体用法?C++ TAxis::GetLabels怎么用?C++ TAxis::GetLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TAxis
的用法示例。
在下文中一共展示了TAxis::GetLabels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VariableSizeRebin
TH1* VariableSizeRebin(TH1* inhisto, unsigned int nbinsx,
double *xbins, TString axisname="x",
TString newhistoname="newhist")
{
if ( nbinsx == 0 ) {
cout << "Error! nbinsx must be non-zero." << endl; return 0; }
if ( inhisto == 0 ) {
cout << "Error! Input histogram pointer is null." << endl; return 0; }
if ( axisname == "y" && !inhisto->InheritsFrom("TH2") ) {
cout << "No y-axis defined for " << inhisto->GetName() << endl; return 0; }
if ( newhistoname == "" ) {
cout << "Error! Output histogram name is null."<< endl; return 0; }
double *edgeArr = new double[nbinsx+2]; // an extra bin for safety
TAxis *axis = (axisname=="y" ? inhisto->GetYaxis() : inhisto->GetXaxis());
unsigned int nbins = 0; // number of bins for the new histogram
unsigned int j = 0; // dummy bin index (to be used as a pointer)
for ( unsigned int i=0; i<=axis->GetNbins()+1; ++i ) {
if ( j > nbinsx ) break;
double ble = axis->GetBinLowEdge(i);
if ( xbins[j] > ble ) continue;
edgeArr[nbins] = ble; j++; nbins++;
if ( xbins[j-1] < ble ) {
cout << "Warning! Bin edge at " << xbins[j-1] << " does not align with"
<< " input histo. Realigning at " << ble << ".\n";
// check if the upcoming bin edges become obsolete after realigning.
while ( j<=nbinsx && xbins[j] <= ble ) j++;
}
}
// if we finished the loop normally, ie. not 'break'ing out, it must be
// that the input histogram xrange is shorter than what the new binning
// tried to get. So handle that.
if ( j <= nbinsx ) {
double xmax = axis->GetBinLowEdge(axis->GetNbins()+1);
if ( xmax>edgeArr[nbins-1] ) {
edgeArr[nbins]=xmax;
cout << "Warning! Input histo reached max value of its x-range. "
<< "Last bin to be closed at " << edgeArr[nbins] << "." << endl;
nbins++; }
}
// we go out of the loop when index j overshoots. So our nbins is
// always one more than actual number of bins. Fix that.
nbins--;
if ( nbinsx != nbins )
cout << "Warning! nbinsx set to " << nbins
<< " instead of " << nbinsx << "." << endl;
//for ( unsigned int i=0; i<=nbins; i++ )
// cout << "For bin " << i+1 << "\tlowedge= " << edgeArr[i] << endl;
// Now generate the new histogram
TH1 *newhist = 0;
if ( !inhisto->InheritsFrom("TH2") )
newhist = inhisto->Rebin(nbins,newhistoname.Data(),edgeArr);
else {
// Copy the perpendicular axis as it is.
TAxis *axisp = (axisname=="y" ? inhisto->GetXaxis() : inhisto->GetYaxis());
unsigned int nbinsp = axisp->GetNbins();
double *edgeArrp = new double[nbinsp+1];
for ( unsigned int i=1; i<=nbinsp+1; ++i )
edgeArrp[i] = axisp->GetBinLowEdge(i);
if ( axisname == "y" ) {
if ( axisp->IsVariableBinSize() )
newhist = new TH2D(newhistoname, inhisto->GetTitle(),
nbinsp, edgeArrp, nbins, edgeArr);
else
newhist = new TH2D(newhistoname, inhisto->GetTitle(),
nbinsp, edgeArrp[0], edgeArrp[nbinsp+1],
nbins, edgeArr);
if ( axisp->GetLabels() )
for ( unsigned int i=1; i<=nbinsp; ++i )
newhist->GetXaxis()->SetBinLabel(i, axisp->GetBinLabel(i));
}
else
// ToDo: Have not yet implemented the above nice stuff for axisname=="x"
newhist = new TH2D(newhistoname, inhisto->GetTitle(),
nbins, edgeArr, nbinsp, edgeArrp);
//.........这里部分代码省略.........