Bin Labels on Projected Hist

Hello,
I created a 2D histogram. I relabeled the bins on one axis. I didn’t relabel each bin because drawing the 2D hist would label each bin and become unreadable. I then take a projection on this axis. Drawing the projection puts the labels on the wrong bins.
i.e. if there are 64 bins and I label every fifth bin, the projected 1D hist takes those 12 labels and puts them on the first 12 bins of the projection.
I have two questions. First, if I label each bin is there a way to draw the hist while only displaying a fraction of the labels (I didn’t see a member function that would do this, although I may have missed it)? Second, is the fact that the projection puts the labels on the wrong bins a bug in the code?
Thanks,
james

Can you provide a small example reproducing the problem ?

While the bin labels here are actual numbers, and thus could be resolved by changing the bounds of the TH2F during instantiation, this example does illustrate my problem.

#include <string>
#include "TH2F.h"
#include "TH1D.h"
#include "TCanvas.h"
#include "TRandom.h"

void projection()
{
  char buffer[50];
  TH2F *testResultsByROC = new TH2F("Raw Data for ROC", "Raw Data for ROC",
                                     64, -0.5, 63 + 0.5, 10, -0.5, 9.5);
  testResultsByROC->GetXaxis()->SetTitle("Delay");
  testResultsByROC->GetYaxis()->SetTitle("DAC Values");
  for(unsigned int j = 0; j <= 63; j += 5){
    int tempInt = sprintf(buffer, "%.1f", float(j / 2.));
    string tempString = buffer;
    testResultsByROC->GetXaxis()->SetBinLabel(j + 1, tempString.c_str());
  }

  TRandom tmp;
  for(unsigned int i = 0; i <= 63; ++i){
    for(unsigned int j = 1; j <= 10; ++j){
      testResultsByROC->Fill(i, j - 1, tmp.Gaus(0, 7));
    }
  }

  TH1D *collapsedTestResultsByROC = testResultsByROC->ProjectionX("Projection onto Delay for ROC", 0, -1);
  collapsedTestResultsByROC->SetNameTitle("Projection onto Delay for ROC", "Projection onto Delay for ROC");

  TCanvas *my_canvas = new TCanvas("my_canvas","my_canvas",350,100,600,600);
  my_canvas->cd();
  collapsedTestResultsByROC->Draw();
  my_canvas->Update();
}


Thanks. I see what you mean.
Just one question, why to you need alphanumeric labels ? your axis looks numeric…
The labels are equidistant, nothing justify the use of alphanumeric labels seems to be … may be you have other cases where you need them ?

It was an oversight when I wrote the code. I can rewrite the code to avoid this problem, it just seemed easier to relabel the bins (i.e. fewer lines of code changes), rather than alter the numerous for loops necessary for my analysis.
so, i thought i’d ask here if there was a way to display only a few alphanumeric labels (instead of all of them) and to find out if this was a possible bug in the code (in case it needs to be corrected in a future version).

Clearly there is a problem with the alphanumeric labels on projected histogram but if your histograms are numeric I would strongly suggest to not use alpha numeric labels because you will surely hit some limitations at some point. You can change the number of axis division to control the number of labels that much simpler !!!