How to make 2 graphs from file using ntuple?

Hi dear rooters

The title is exactly the question, you’ll see I have a macro like this:

{
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

FILE *fp1, *fp2,
float ptmp,p[30];
int i, iline=0;
ntuple = new TNtuple(“ntuple”,“NTUPLE”,“x:y:z”);
ntuple1 = new TNtuple(“ntuple1”,“NTUPLE”,“x:y:z”);

fp = fopen(“file1”,“r”);
while ( fscanf(fp,"%f",&ptmp) != EOF ){
p[i++]=ptmp;
if (i==3)
{
i=0; iline++;
ntuple->Fill(p[0],p[1],p[2]);
}
}

fp1 =fopen(“file2”,“r”);
while ( fscanf(fp1,"%f",&ptmp) != EOF ){
p[i++]=ptmp;
if (i==3)
{
i=0; iline++;
ntuple1->Fill(p[0],p[1],p[2]);
}
}

ntuple.Draw(“z:x”,"","");
ntuple1.Draw(“z:x”,"",“same”);
}

but I want to have these plots in 2 different pads on same canvas, one after another, same x axis and different y axis. Any comment or hint about it would be appreciated.
Thanks in advance.
Alma

Hi Alma,

the answer is not related to tuples since you need to adopt the general way to draw on different pads in the same canvas. The steps are: create a canvas, partition it, access the individual partitions. In code:

TCanvas c;
c.Divide(2,1);
c.cd(1);
h1.Draw();
c.cd(2);
h2.Draw();

Cheers,
D

1 Like

OMG!

That is working so well Danilo, I can’t believe how easy this was :flushed:, for sure I have to read more and look for some general options in every plot, like same range at x axis, legends and other stuff like that.
Thank you so much!!! :v:
Have a nice day!
Alma

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