SetAxisRange dependent upon TFile location

Dear Root talk,

I just wanted to understand why this was happening.

I am reading in a root file and then creating some histograms. I use SetAxisRange to zoom in on a particular region by default.

When I have TFile above the definitions for the histograms the SetAxisRange works. However, as soon as I place it beneath the definitions it no longer works. Instead it goes to the default range.

Any ideas way?

Thanks

Quick_plot()
{

  TCanvas *c1 = new TCanvas("c1", "Quick Plots");

  TH1F *h1, *h2, *histup, *histdown;

  h1 = (TH1F*)gROOT->FindObject("histup");
  if(h1) h1->Delete();

  h2 = (TH1F*)gROOT->FindObject("histdown");
  if(h2) h2->Delete();

  TFile *file1 = new TFile("test2_data_run.root", "update");

  TH1F *histup = new TH1F("histup", "UP Decays", 300, 1, 300);
  histup->SetAxisRange(1, 300);

  TH1F *histdown = new TH1F("histdown", "DOWN Decays", 300, 1, 300);
  histdown->SetAxisRange(1, 300);

  c1->Divide(0,2);

  c1->cd(1);
  TDC1_ntuple->Draw("UP_time >> histup");
 
  c1->cd(2);
  TDC2_ntuple->Draw("DOWN_time >> histdown");
 
}

This is the expected behaviour. The statement

TDC2_ntuple->Draw("DOWN_time >> histdown"); looks for a histogram “histdown” in the current directory. If none exists it creates one automatically. When TFile is called before the creation of the histogram, the histogram is registered to this directory/file and it will be found by ntuple->Draw.

Rene

Oh, I see.

When I call TFile I am automatically placed inside of that “directory”. If I define the histograms (in Rint) before TFile ROOT looks in the current directory - which is the root file and no longer Rint.

Thanks :slight_smile: