{ double bins[] = { -1, -0.5, 0, 0.5, 1}; int nbins = 4; // TH1D * h = new TH1D( "h", "h", 20, -1, 1); TH1D * h = new TH1D( "h", "h", nbins, bins); h->FillRandom( "gaus", 1000); cout << "h after being created - nbinsX: " << h->GetNbinsX() << endl; //let's set the bin labels char label[10]; for( int i = 0; i < h->GetNbinsX(); ++i ) { sprintf( label, "Lab%i", i); h->GetXaxis()->SetBinLabel( i+1, label ); } cout << "h after SetBinLabel - nbinsX: " << h->GetNbinsX() << endl; //set the overflow to zero (PS: using ClearUnderflowsAndOverflows seems to work ok) h->SetBinContent( h->GetNbinsX()+1, 0); h->SetBinError( h->GetNbinsX()+1, 0); cout << "h after 0 overflow - nbinsX: " << h->GetNbinsX() << endl; delete h; //TH2D check: // TH2D * h2 = new TH2D( "h2", "h2", 20, -1, 1, 20, -1, 1); TH2D * h2 = new TH2D( "h2", "h2", nbins, bins, nbins, bins); cout << "h2 after being created - nbinsX: " << h2->GetNbinsX() << ", nbinsY " << h2->GetNbinsY() << endl; //let's make a projection h = h2->ProjectionY(); cout << "h (projection) - nbinsX: " << h->GetNbinsX() << endl; //let's do the same after setting the bin labels delete h; for( int i = 0; i < h2->GetNbinsX(); ++i ) { sprintf( label, "Lab%i", i); h2->GetXaxis()->SetBinLabel( i+1, label ); h2->GetYaxis()->SetBinLabel( i+1, label ); } h = h2->ProjectionY(); cout << "h (projection) after bin labels - nbinsX: " << h->GetNbinsX() << endl; delete h2; }