How to draw histograms in a loop?

I want to look histograms in a loop one by one. But I found the histograms can’t be drawn until the end of the loop. So I can only see the last histogram. How can I draw histograms one by one in a loop? Thank you very much!

The following is a very simple program. If you run it, you will find what I mean.

#include
#include

void drawhists(){

TH1F *faststrip[11], *slowstrip[11];
char fIndex[20];
char sIndex[20];
char index[5];

for (UInt_t i=1; i<11; i++){
sprintf(fIndex, “faststrip”);
sprintf(sIndex, “slowstrip”);
sprintf(index, “%u”, i);
strcat(fIndex, index);
faststrip[i] = new TH1F(fIndex, fIndex, 4096, 0, 4095);
sprintf(index, “%u”, i);
strcat(sIndex, index);
slowstrip[i] = new TH1F(sIndex, sIndex, 4096, 0, 4095);
}

Double_t yes;
for (UInt_t i = 1; i < 5; i++){
faststrip[i]->Draw();
cout<<“say a number”;
cin>>yes;
}

}

do:

gPad->Update();

after the Draw();

Thank you very much!

Now I get the histograms. But the pad is “dead” and I can’t do operation on the pad and histograms. How can I “activate” it so that I can operate it?

Could you send the shortest possible running script reproducing your problem?

Rene

You could use the same script that I posted above.
When you get the first histogram, you will find that you could do no operations on the pad. For example, you can’t change the axis range with mouse. When you switch to another window (if you use linux) and switch back, you’ll find that everything on pad is gone. The pad becomes a totally white board. In other word, the pad is not “active”.

Sorry, when you use the script that I posted above, you have to add “gPad->Update();” after " faststrip[i]->Draw(); "

Thank you very much for your help!
Or you can use the following script that is even shorter that the one posted.

#include
#include

void drawhists(){

TH1F *faststrip[11];
char fIndex[20];
char sIndex[20];
char index[5];

for (UInt_t i=1; i<11; i++){
sprintf(fIndex, “faststrip”);
sprintf(index, “%u”, i);
strcat(fIndex, index);
faststrip[i] = new TH1F(fIndex, fIndex, 4096, 0, 4095);
}

Double_t yes;
for (UInt_t i = 1; i < 5; i++){
faststrip[i]->Draw();
gPad->Update();
cout<<“say a number”;
cin>>yes;
}

}

Hi,

add

gSystem->ProcessEvents()

to the code.

Hope that helps

Lutz