Reading tree from root file and in one canvas three hist plotting

i need help for creating three Edep0 Edep1 Edep2 in one canvas , but it gives blank image , help me for it

#include "TFile.h"
#include "TF1.h"
#include "TH1.h"
#include "iostream.h"
void waqas() 
{

   gStyle->SetOptStat(0);
  
   gROOT->Reset();
   TCanvas *c1 = new TCanvas("c1","",0,0,500,400);
   //c1->Divide(3,1);

  {
//c1->cd(1);

//gPad->SetLogy();
//gPad->SetLogx();
 //gPad->Modified();
  
  TFile *f1 = new TFile("/home/waqas/Documents/25um/6GeV_25um__6000.root");
  //  TTree *tree = (TTree*)f1->Get("Edep0/phase/");
   TTree *tr=(TTree*)f1->Get("phase");
   TLeaf *l1=(TLeaf*)tr->GetLeaf("Edep0");
  // TH1F *TTree= (TH1F*)f1->Get("phase/Edep0"); 
//h1->GetXaxis()->SetTitle("P_{T}(GeV/c)");
//h1->RebinAxis(150, h1->GetXaxis());
   l1->SetLineWidth(2);
   l1->SetMarkerSize(5);
   l1->SetLineColor(kBlue);
  l1->SetLineStyle(3);*/
   //h1.Scale(2);

   l1->Draw(""); 
/*
TFile*f2 = new TFile("/ho me/waqas/Documents/25um/6GeV_25um__6000.root");
 TH1F*h2 = (TH1F*)f2->Get("phase/Edep1"); 
//h1->GetXaxis()->SetTitle("P_{T}(GeV/c)");
//h2->RebinAxis(100, h2->GetXaxis());
   h2->SetLineWidth(2);
   h2->SetMarkerSize(5);
   h2->SetLineColor(kRed);
   h2->SetLineStyle(3);

   h2->Draw("Hist SAME"); 

TFile*f5 = new TFile("/home/waqas/Documents/25um/6GeV_25um__6000.root");
      TH1F*h5 = (TH1F*)f5->Get("phase/Edep2"); 
//h1->GetXaxis()->SetTitle("P_{T}(GeV/c)");
//h2->RebinAxis(100, h2->GetXaxis());
   h5->SetLineWidth(2);
  h5->SetMarkerSize(5);
   h5->SetLineColor(kBlack);
  h5->SetLineStyle(3);

   h5->Draw("Hist SAME"); */

Why don’t you simply do:

tr->Draw("Edep0");

?

it is showing the plot but how to draw other two plot of Edep1 and Edep2 on same canvas.

Something like that:

tr->Draw("Edep0");
tr->Draw("Edep1","","SAME");
tr->Draw("Edep2","","SAME");

or:

 TCanvas *c1 = new TCanvas("c1","",0,0,500,400);
 c1->Divide(3,1);
 c1->cd(1); tr->Draw("Edep0");
 c1->cd(2); tr->Draw("Edep1");
 c1->cd(3); tr->Draw("Edep2");


i have manage to draw it but its completely overlapping which actually is not, is there specific to write

So you chose the first solution. May be try log scale along Y ?

Thank you so much it works ,
Now I want to set titles for xaxis and yaxis , how should I proceed

root [0] ntuple->Draw("px")
root [1] htemp->SetTitle("A;B;C")

Is it a root command, if yes I want proceed through macro

Yes, … is it a problem ?

this command doesn’t work ,tell me how to set my macro.C for it

tr->Draw("Edep0");
TH1 *h = (TH1*)gPad->GetPrimitive("htemp");
h->SetTitle("A;B;C")

its showing error, no plot

Can you be more precise and post here the errors you get ?

Can you copy/paste here the code of waqas.C ? ( no screen dump please !)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.