2D array of TH2D Histograms

Hi all,

I am currently trying to create a 2D array of TH2D histograms and I am getting an illeagal pointer to class error when I try to fill an array.

I define the histograms as follows:

TH2D *sinogram_u2[NRING][NRING];
char hname[20];
for (j=0; j < NRING-1; j++);
{
for (k=0; k < NRING-1; k++);
{
sprintf(hname,“S_I%d_%d”,j,k);
sinogram_u2[j][k] = new TH2D(hname,“Unsigned Short Integer Sinogram”,NDET,-550,+550.,NDET,0.,pi);
}
}

Where NRING is a constant. This portion of the code seems to work. However, when I try to fill one of these histograms the routine dies.
I am using the following lines to fill the histograms:

sinogram_u2[j][k]->Fill(s,theta);

Does anyone have any ideas?

Thanks,

ross

Please send a real and short script showing the problem

Rene

Hi Rene,

Thanks for the help. Here is a simplified version of the code where I try to fill one histogram and get the illegal pointer error.

{
gROOT->Reset();
#include <math.h>

Float_t theta;
Float_t s;
Float_t pi = 3.141592653589793;
Int_t NRING = 18;
Int_t NDET = 336;
Float_t globalPosX1;
Float_t globalPosX2;
Float_t globalPosY1;
Float_t globalPosY2;

Int_t j=0,k=0;
TH2D *sinogram_u2[NRING+1][NRING+1];
char hname[20];
for (j=0; j < NRING; j++);
{
for (k=0; k < NRING; k++);
{
sprintf(hname,“S_I%d_%d”,j,k);
sinogram_u2[j][k] = new TH2D(hname,“Unsigned Short Integer Sinogram”,NDET/2,-550,+550.,NDET/2,0.,pi);
}
}

Int_t i = 0;
Int_t nentries = 1000;
for (i = 0; i < nentries; i++) 
  {

globalPosX1 = gRandom->Rndm();
globalPosY1 = gRandom->Rndm();
globalPosX2 = gRandom->Rndm();
globalPosY2 = gRandom->Rndm();

theta = atan2((globalPosX1 - globalPosX2),(globalPosY2 - globalPosY1));
    s = globalPosX1*cos(theta) + globalPosY1*sin(theta);

    sinogram_u2[1][1]->Fill(s,theta);
  }

}

You have two C++ errors in your code. Replace the lines:
for (j=0; j < NRING; j++);
{
for (k=0; k < NRING; k++);
{

by

for (j=0; j < NRING; j++){
for (k=0; k < NRING; k++){

Rene

Thanks René, I deservedly feel quite stupid. I thank you for your patience.

ross