Writing loop for already initialised array of histograms

Hi All,

I am having trouble with writing loop for initialised array of histograms. I could successfully use the array objects individually (i.e //emptyENu[0]->Fill(5);//emptyENu[0]->Draw();). However, when I use the histogram pointer(emptyENu[reE]) again in another loop, I am having trouble executing the file. (.L filename.C+ didn’t give me any error messages).

void run(){
TH1F *h1= new TH1F(“h1”,“h1”,10,0.,100.);
TH1F *h1Bar= new TH1F(“h1Bar”,“h1Bar”,10,0.,100.);
TH1F *emptyENu[10];
TH1F *emptyENuBar[10];

for(int i=0; i<10; i++){
//Initialising arrays of histograms
emptyENu[i]=(TH1F*)h1->Clone(Form(“emptyENu_%d”,i));
cout<<(emptyENu[i])->GetName()<<endl;
emptyENuBar[i]=(TH1F*)h1Bar->Clone(Form(“emptyENuBar_%d”,i));
cout<<(emptyENuBar[i])->GetName()<<endl;
}

//emptyENu[0]->Fill(5);
//emptyENu[0]->Draw();

for(int i=0; i<10; i++){
emptyENu[i]->Fill(5);
}
emptyENu[0]->Draw();

}

Many Thanks,

Sarah

And what’s the “trouble” exactly?

The problem is the 2nd loop:

for(int i=0; i<reE; i++){
emptyENu[i]->Fill(5);
}
emptyENu[0]->Draw();

that emptyENu[0]->Draw(); doesn’t draw the histogram when the function (i.e. run() ) is executed, ROOT just crashes without giving any error messages.

I tried ROOT 5.34/25 and I get no problems.

BTW. Note that the original macro in your first post above correctly contains “for(int i=0; i<10; i++){” while now you have “for(int i=0; i<reE; i++){”, so are you sure that “reE” <= 10?