plotting histograms in ROOT with varying variable names
Posted
by
user66890
on Programmers
See other posts from Programmers
or by user66890
Published on 2012-10-04T15:10:55Z
Indexed on
2012/10/04
15:51 UTC
Read the original article
Hit count: 259
c++
I am not sure how to phrase this question correctly, but this is what I am trying to do.
A single histogram can be plotted using cern ROOT with a following command,
(TH1F*)electron->Draw();
But I have tens of histograms named in a sequence, such as electron1, elecron2, electron3, etc, and I want to write a simple loop to plot them all. I tried using sprintf and a simple for loop, but ROOT doesn't like it.
char name[20];
(TH1F*)electron->Draw();
for(int j=0;j<5;j++){
sprintf(name, "%s%d","electron",j);
(TH1F*)name->Draw("same");
}
What am I doing wrong?
Thanks in advance.
© Programmers or respective owner