3 #include <FairLogger.h>
5 #include <Math/Point2D.h>
10 #include <boost/multi_array/base.hpp>
11 #include <boost/multi_array/extent_gen.hpp>
12 #include <boost/multi_array/multi_array_ref.hpp>
13 #include <boost/multi_array/subarray.hpp>
21 constexpr
auto cRED =
"\033[1;31m";
29 AtPadCoord.resize(boost::extents[numPads][4][2]);
31 std::cout <<
" SpecMAT Map initialized " << std::endl;
32 std::cout <<
" SpecMAT Pad Coordinates container initialized " << std::endl;
41 std::ofstream coordmap;
42 coordmap.open(
"coordmap_specmat.txt");
43 coordmap <<
" SpecMAT Triangular pad coordinates (centers) - Pad Index - (x,y)" << std::endl;
45 for (
index i = 0; i < 3174; ++i) {
48 coordmap << std::endl;
56 std::vector<double> allCoordinates;
60 int nElementsInSegment = nRaws * ((2 * firstElement + (nRaws - 1) * elementStep) / 2);
65 const int arrayLength = nElementsInSegment * nSegments;
66 std::vector<double> x0(arrayLength), x1(arrayLength), x2(arrayLength), xCentre(arrayLength), x0next(arrayLength),
67 x1next(arrayLength), x2next(arrayLength);
68 std::vector<double> y0(arrayLength), y1(arrayLength), y2(arrayLength), yCentre(arrayLength), y0next(arrayLength),
69 y1next(arrayLength), y2next(arrayLength);
72 for (
int i = 1; i < nRaws + 1; i++) {
74 for (
int j = 1; j < a + 1; j++) {
79 x1[counter] = -h / sqrt(3);
82 x2[counter] = h / sqrt(3);
85 xCentre[counter] = 0.;
86 yCentre[counter] = h / sqrt(3);
89 x0[counter] = x2[counter - 1];
90 y0[counter] = y2[counter - 1];
92 x1[counter] = x2[counter - a + 1];
93 y1[counter] = y2[counter - a + 1];
95 x2[counter] = x1[counter - a + 1];
96 y2[counter] = y1[counter - a + 1];
98 xCentre[counter] = x0[counter];
99 yCentre[counter] = y0[counter] - h / sqrt(3);
101 x0[counter] = x0next[i - 2] + (j - 1) * (h / sqrt(3));
102 y0[counter] = y0next[i - 2];
104 x1[counter] = x1next[i - 2] + (j - 1) * (h / sqrt(3));
105 y1[counter] = y1next[i - 2];
107 x2[counter] = x2next[i - 2] + (j - 1) * (h / sqrt(3));
108 y2[counter] = y2next[i - 2];
110 xCentre[counter] = x0[counter];
111 yCentre[counter] = y0[counter] + h / sqrt(3);
117 x0next[i - 1] = x0[counter - a] - h / sqrt(3);
118 y0next[i - 1] = y0[counter - a] + h;
120 x1next[i - 1] = x1[counter - a] - h / sqrt(3);
121 y1next[i - 1] = y1[counter - a] + h;
123 x2next[i - 1] = x2[counter - a] - h / sqrt(3);
124 y2next[i - 1] = y2[counter - a] + h;
127 for (
int i = 1; i < nSegments; i++) {
128 for (
int j = 0; j < nElementsInSegment; j++) {
129 x0[i * nElementsInSegment + j] =
130 0.5 * (x0[(i - 1) * nElementsInSegment + j] - 0) - sqrt(3) * 0.5 * (y0[(i - 1) * nElementsInSegment + j]);
131 y0[i * nElementsInSegment + j] =
132 sqrt(3) * 0.5 * (x0[(i - 1) * nElementsInSegment + j] - 0) + 0.5 * (y0[(i - 1) * nElementsInSegment + j]);
134 x1[i * nElementsInSegment + j] =
135 0.5 * (x1[(i - 1) * nElementsInSegment + j] - 0) - sqrt(3) * 0.5 * (y1[(i - 1) * nElementsInSegment + j]);
136 y1[i * nElementsInSegment + j] =
137 sqrt(3) * 0.5 * (x1[(i - 1) * nElementsInSegment + j] - 0) + 0.5 * (y1[(i - 1) * nElementsInSegment + j]);
139 x2[i * nElementsInSegment + j] =
140 0.5 * (x2[(i - 1) * nElementsInSegment + j] - 0) - sqrt(3) * 0.5 * (y2[(i - 1) * nElementsInSegment + j]);
141 y2[i * nElementsInSegment + j] =
142 sqrt(3) * 0.5 * (x2[(i - 1) * nElementsInSegment + j] - 0) + 0.5 * (y2[(i - 1) * nElementsInSegment + j]);
144 xCentre[i * nElementsInSegment + j] = 0.5 * (xCentre[(i - 1) * nElementsInSegment + j] - 0) -
145 sqrt(3) * 0.5 * (yCentre[(i - 1) * nElementsInSegment + j]);
146 yCentre[i * nElementsInSegment + j] = sqrt(3) * 0.5 * (xCentre[(i - 1) * nElementsInSegment + j] - 0) +
147 0.5 * (yCentre[(i - 1) * nElementsInSegment + j]);
151 for (
int i = 0; i < arrayLength; i++) {
152 allCoordinates.push_back(x0[i]);
153 allCoordinates.push_back(y0[i]);
154 allCoordinates.push_back(x1[i]);
155 allCoordinates.push_back(y1[i]);
156 allCoordinates.push_back(x2[i]);
157 allCoordinates.push_back(y2[i]);
158 allCoordinates.push_back(xCentre[i]);
159 allCoordinates.push_back(yCentre[i]);
161 return allCoordinates;
167 std::vector<double> arrayAllCoordinates2;
170 int nElementsInSegment3;
171 nElementsInSegment3 = arrayAllCoordinates2.size() / (6 * 8);
176 XY->SetTitle(
"PadPlane X vs Y");
178 XY->GetXaxis()->SetTitle(
"X (mm)");
179 XY->GetYaxis()->SetTitle(
"Y (mm)");
182 double InitialPoInt_X = 50;
183 double InitialPoInt_Y = 50;
184 double particleEnergy = 50;
186 double binXcentroid = 0;
187 double binYcentroid = 0;
190 XY->Fill(InitialPoInt_X, InitialPoInt_Y, particleEnergy);
194 currentBin = XY->FindBin(InitialPoInt_X, InitialPoInt_Y, 0);
196 if (currentBin < nElementsInSegment3) {
197 binXcentroid = arrayAllCoordinates2[8 * (currentBin) + 6];
198 binYcentroid = arrayAllCoordinates2[8 * (currentBin) + 7];
199 }
else if (currentBin >= nElementsInSegment3 && currentBin < nElementsInSegment3 * 2 - 1) {
200 binXcentroid = arrayAllCoordinates2[8 * (currentBin + 1) + 6];
201 binYcentroid = arrayAllCoordinates2[8 * (currentBin + 1) + 7];
202 }
else if (currentBin >= nElementsInSegment3 * 2 - 1 && currentBin < nElementsInSegment3 * 3 - 2) {
203 binXcentroid = arrayAllCoordinates2[8 * (currentBin + 2) + 6];
204 binYcentroid = arrayAllCoordinates2[8 * (currentBin + 2) + 7];
205 }
else if (currentBin >= nElementsInSegment3 * 3 - 2 && currentBin < nElementsInSegment3 * 4 - 3) {
206 binXcentroid = arrayAllCoordinates2[8 * (currentBin + 3) + 6];
207 binYcentroid = arrayAllCoordinates2[8 * (currentBin + 3) + 7];
208 }
else if (currentBin >= nElementsInSegment3 * 4 - 3 && currentBin < nElementsInSegment3 * 5 - 4) {
209 binXcentroid = arrayAllCoordinates2[8 * (currentBin + 4) + 6];
210 binYcentroid = arrayAllCoordinates2[8 * (currentBin + 4) + 7];
211 }
else if (currentBin >= nElementsInSegment3 * 5 - 4 && currentBin < nElementsInSegment3 * 6 - 5) {
212 binXcentroid = arrayAllCoordinates2[8 * (currentBin + 5) + 6];
213 binYcentroid = arrayAllCoordinates2[8 * (currentBin + 5) + 7];
216 std::cout <<
"Input" << std::endl;
217 std::cout <<
"X: " << InitialPoInt_X <<
" Y: " << InitialPoInt_Y << std::endl;
218 std::cout <<
"\nOutput" << std::endl;
219 std::cout <<
"Bin: " << currentBin <<
" binCentroidX: " << binXcentroid <<
" binCentroidY: " << binYcentroid
226 LOG(error) <<
"Skipping generation of pad plane, it is already parsed!";
230 std::cout <<
" SpecMAT Map : Generating the map geometry of SpecMAT " << std::endl;
232 std::vector<double> arrayAllCoord;
237 AtPadCoord[i][0][1] = arrayAllCoord[8 * i + 1];
238 AtPadCoord[i][1][0] = arrayAllCoord[8 * i + 2];
239 AtPadCoord[i][1][1] = arrayAllCoord[8 * i + 3];
240 AtPadCoord[i][2][0] = arrayAllCoord[8 * i + 4];
241 AtPadCoord[i][2][1] = arrayAllCoord[8 * i + 5];
242 AtPadCoord[i][3][0] = arrayAllCoord[8 * i + 6];
243 AtPadCoord[i][3][1] = arrayAllCoord[8 * i + 7];
246 std::cout <<
" A total of " <<
fNumberPads <<
" pads were generated " << std::endl;
253 int arrayAllCoordinatesSize = arrayAllCoordinates.size();
254 for (
int i2 = 0; i2 < arrayAllCoordinatesSize / 8; i2++) {
255 if (i2 != 0 && i2 != arrayAllCoordinatesSize * 1 / (6 * 8) && i2 != arrayAllCoordinatesSize * 2 / (6 * 8) &&
256 i2 != arrayAllCoordinatesSize * 3 / (6 * 8) && i2 != arrayAllCoordinatesSize * 4 / (6 * 8) &&
257 i2 != arrayAllCoordinatesSize * 5 / (6 * 8)) {
258 x[0] = arrayAllCoordinates[8 * i2];
259 y[0] = arrayAllCoordinates[8 * i2 + 1];
260 x[1] = arrayAllCoordinates[8 * i2 + 2];
261 y[1] = arrayAllCoordinates[8 * i2 + 3];
262 x[2] = arrayAllCoordinates[8 * i2 + 4];
263 y[2] = arrayAllCoordinates[8 * i2 + 5];
272 LOG(error) <<
" AtSpecMATMap::CalcPadCenter Error : Pad plane has not been generated or parsed";
273 return {-9999, -9999};
277 LOG(debug) <<
" AtSpecMATMap::CalcPadCenter Error : Pad not found";
278 return {-9999, -9999};
287 }
else if (PadRef >= 529 && PadRef < 529 * 2 - 1) {
290 }
else if (PadRef >= 529 * 2 - 1 && PadRef < 529 * 3 - 2) {
293 }
else if (PadRef >= 529 * 3 - 2 && PadRef < 529 * 4 - 3) {
296 }
else if (PadRef >= 529 * 4 - 3 && PadRef < 529 * 5 - 4) {
299 }
else if (PadRef >= 529 * 5 - 4 && PadRef < 529 * 6 - 5) {