Plotting mulitple Ntuples on the same set of axes

Hello Forum,
I’m trying to do something that, in principle, sounds easy, but is proving challenging to me.
I have 3 Ntuples and would like to plot them on the same set of XY axes in the same style. I have written the following code to try to achieve this:

ntuple1->Draw(“Dose:Depth”, “”, “L”);
TH1F htemp = (TH1F)gPad->GetPrimitive(“htemp”);
htemp->SetTitle(“PDD of 6 MV Beam in PMMA”);
htemp->SetMarkerColor(4);
htemp->SetXTitle(“Depth (cm)”);
htemp->GetXaxis()->SetRangeUser(0,15);
htemp->GetXaxis()->CenterTitle();
htemp->SetYTitle(“PDD %”);
htemp->GetYaxis()->CenterTitle();
ntuple2->Draw(“Dose:Depth”,"", “same”);
ntuple3>Draw(“Dose:Depth”,"", “same”);

However this gives me only the first Ntuple plotted in the style “L”, as a solid line. The remaining Ntuples still appear as points on the plot. I would like all 3 Ntuples to appear in the style “L”.

Another more minor question is about “htemp->SetTitle(“PDD of 6 MV Beam in PMMA”)”. What is the command to center it?

Thanks in advance,
Ricardo

_ROOT Version: 5.34
_Platform:Ubuntu Not Provided
Compiler: Not Provided


Use ntuple2->Draw(“Dose:Depth”,"", “L same”); instead

Thanks @pamputtt. I’m trying now to change the individual line colors. To my surprise SetLineColor seems to have no effect as I used it below:

ntuple1->Draw(“Dose:Depth”, “”, “L”);
TH1F htemp = (TH1F)gPad->GetPrimitive(“htemp”);
htemp->SetTitle(“PDD of 6 MV Beam in PMMA”);
htemp->SetLineColor(kRed);
htemp->SetXTitle(“Depth (cm)”);
htemp->GetXaxis()->SetRangeUser(0,15);
htemp->GetXaxis()->CenterTitle();
htemp->SetYTitle(“PDD %”);
htemp->GetYaxis()->CenterTitle();

   ntuple2->Draw("Dose:Depth","", "L same");
   htemp->SetLineColor(3);
   ntuple3->Draw("Dose:Depth","",  "L same");
   htemp->SetLineCColor(2);

Perhap’s it’s because I’m a Newbie, but I find Ntuple very cumbersome for anything other than quickly filling data. Whenever one wants to do anything presentable with it, one has to cast it as a histogram which more or less reduces its role to a sort of middleman.

  ntuple1->Draw("Dose:Depth", "", "L");
  TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); // 2D axes
  htemp->SetTitle("PDD of 6 MV Beam in PMMA;Depth (cm);PDD %");
  htemp->GetXaxis()->CenterTitle(); htemp->GetYaxis()->CenterTitle();
  htemp->GetXaxis()->SetRangeUser(0., 15.); // "shrink" the X range
  htemp->GetYaxis()->SetRangeUser(0., 150.); // "shrink" the Y range
  TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph1"); graph->SetLineColor(4);
  ntuple2->Draw("Dose:Depth", "", "L SAME");
  graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph2"); graph->SetLineColor(3);
  ntuple3->Draw("Dose:Depth", "",  "L SAME");
  graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph3"); graph->SetLineColor(2);
  // gPad->ls();

Thanks, Wile_E_Coyote. I see that the main thing is to cast the Ntuple as a 2D histogram. I have 2 additional questions:

  1. How do I change the range of the Y-axis. I am unable to do it by the command
htemp->GetYaxis()->SetRangeUser(0., 150.);
  1. How do I center the main title ( “PDD of 6 MV Beam in PMMA”)

Thanks in advance,
RL

  1. It should work (note, however, that you can only “shrink” ranges).

  2. You can play with the “title”:

  gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
  TPaveText *title = (TPaveText*)gPad->GetPrimitive("title");
  title->Print();

Try htemp->SetMinimum(0.); htemp->SetMaximum(150.);

Thanks @pamputt and @Wile_E_Coyote. I tried the lines

htemp->SetMinimum(0.); htemp->SetMaximum(150.);

but to no effect.

It appears that I can only shrink the range on the Y-axis. But there must be some way to increase that range, since part of the data is cut out at the present. Any ideas?

  TH2F *htemp = new TH2F("htemp", "PDD of 6 MV Beam in PMMA;Depth (cm);PDD %", 2, 0., 15., 2, 0., 150.); // 2D axes
  htemp->GetXaxis()->CenterTitle(); htemp->GetYaxis()->CenterTitle();
  htemp->SetStats(kFALSE); htemp->DrawCopy(""); delete htemp; // no longer needed (cleanup)
  ntuple1->Draw("Dose:Depth", "", "L SAME");
  TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D data
  graph->SetName("Graph1"); graph->SetLineColor(4);
  // ...

Thanks @Wile_E_Coyote. That worked a charm.

Beep beep.