plotting histograms in ROOT with varying variable names
- by user66890
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.