Setting axis limits with ntuples

Hi!

I’m trying to set the limits of my axes when using an ntuple, but I can’t figure out how. Can someone help me?

For example, this is part of what I have right now:

[code]c1 = new TCanvas(“c1”,“Ntuples of stats”,100,50,750,400);
c1->SetGrid();

ntuple = new TNtuple(“ntuple”,“Stats”,“randRange:sigma:x1:y1:z1”);

ifstream fin;
fin.open(“stats.txt”);
while(!fin.eof())
{
fin >> randRange >> sigma >> x1 >> y1 >> z1;
ntuple->Fill(randRange, sigma, x1, y1, z1);
}
fin.close();

//black markers
ntuple->SetMarkerColor(1);
ntuple->SetMarkerStyle(3);
ntuple->Draw(“x1:sigma”,“randRange < 10 && sigma < 35”);[/code]

I tried doing ntuple->GetYaxis()->SetLimits(0, 0.5); but it doesn’t work.

Thanks for your help!

~Marc

[quote]I tried doing ntuple->GetYaxis()->SetLimits(0, 0.5); but it doesn’t work. [/quote]The axis (and its limit) are not a properly of the ntuple. It is a property of the histogram.

ntuple->Draw("x1:sigma","randRange < 10 && sigma < 35"); htemp->GetYaxis()->SetLimits(0, 0.5);(but actually I think you mean to call htemp->SetMinimum and htemp->SetMaximum).

Cheers,
Philippe.

Thanks, but I don’t understand.

In my code, I don’t define any histogram, I just create the ntuple and use the Draw() function. Where should I define the histogram? And how do I draw my ntuple on it?

Nevermind, I found what I was looking for by. Thank you for the heads up, though!

For people wondering the same thing as I did, here’s how to access the axes when drawing an ntuple:

TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); // for 2D graphs; empty, but has axes TAxis *yaxis = htemp->GetYaxis(); TAxis *xaxis = htemp->GetXaxis(); yaxis->SetLimits(0, 0.5); xaxis->SetLimits(0, 15);

[quote]In my code, I don’t define any histogram[/quote]As you discovered, you indirectly defined an histogram named htemp when calling Draw.

Also CINT has a shortcut that let you replaceTH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); // for 2D graphs; empty, but has axes TAxis *yaxis = htemp->GetYaxis(); with just TAxis *yaxis = htemp->GetYaxis(); (i.e. CINT can do the variable declaration and GetPrimitive automatically).

Cheers,
Philippe.

I am still struggling to understand this… by TAxis you mean your tuple or how to relate the tuple to the histogram. Please help