#include "Riostream.h"
// Create the neighbors maps from a txt file and store it in two 3D arrays. One for the X coordinates of the neighbors, the other one for the Y coordinates. The first dimension is the X coordinate of the center considered while the second one is the Y coordinate of this center. The third dimension correspond to the neighbors number. It's maximum value is 8. When there is less than 8 neighbors both X and Y coordinates of the neighbors are set to 0.
// For example to access to the neighbors of the crystal X=-6, Y=2 call NeighborsX[-6+decX][2+decY][ind] and NeighborsY[-6+decX][2+decY][ind], where ind variates from 0 to 7. You will see that this crystal has 5 neighbors. decX and decY are constants introduced to have no negative values in the array.
// author : Gabriel Charles
// contact : [log in to unmask]
void NeighborsMap() {
const int ecal_NLayX=46+1; // number of crystal layers in X direction, +1 because there is an empty line of crystals
const int ecal_NLayY=11; // number of crystal layers in Y direction
const int decX=23; // for crystal index to start at 0
const int decY=5;
// Opening the neighbors file
ifstream in;
in.open("neighbors.txt");
// Defining the arrays that will contain the neighbors
Int_t NeighborsX[ecal_NLayX][ecal_NLayY][8];
Int_t NeighborsY[ecal_NLayX][ecal_NLayY][8];
// A few necessary variables
Int_t x,y,z,x_c,y_c;
Int_t ind;
// Initialization of the neighbors array
for(int i=0;i> z >> x >> y;
if (!in.good()) break;
if (z==-444){
NeighborsX[x_c+decX][y_c+decY][ind]=x;
NeighborsY[x_c+decX][y_c+decY][ind]=y;
ind++;
}
else{ x_c=x; y_c=y; NCenter++; ind=0;}
}
in.close();
//--end of filling the neighbors array
// In case you would like to separate this file from your main function, you can create a function returning just the 8 lines you need in one array to access neighbors. You can use the following method. Create two arrays of dimension 8 then concatenate the NeighborsX and Y array
Int_t NeighboX[8];
Int_t NeighboY[8];
Neighbox=NeighborsX[8+decX][1+decY]; // it is a one dimension array containing the 8 X coordinates of the neighbors
NeighboY=NeighborsY[8+decX][1+decY]; // it is a one dimension array containing the 8 Y coordinates of the neighbors
// for(int i=0;i<8;i++) cout << Neighbox[i] << endl;
}