87 {
90 log << MSG::VERBOSE <<
" mdt cutouts are on " <<
endmsg;
91 }
92
93 int Ncuts = vcutdef.size();
94 bool cutoutsVsX {false}, cutoutsVsY{false};
95
96 float lastX{FLT_MAX}, lastY{FLT_MAX};
97 for (
int i = 0;
i <
Ncuts; ++
i) {
98 log<<MSG::DEBUG<<__FILE__
":"<<__LINE__
102 <<" lastX: "<<lastX
103 <<
" cutDef->dX "<<vcutdef[
i]->dx
104 <<" lastY: "<<lastY
105 <<
" dutDef->dY "<<vcutdef[
i]->dy<<
endmsg;
106
107 if (lastX != FLT_MAX && lastX * vcutdef[i]->dx < 0)
108 cutoutsVsX = true;
109 lastX = vcutdef[
i]->dx;
110 if (lastY != FLT_MAX && lastY * vcutdef[i]->dy < 0)
111 cutoutsVsY = true;
112 lastY = vcutdef[
i]->dy;
113 }
114 if (cutoutsVsX && cutoutsVsY) {
115 throw std::runtime_error(
116 Form("%s:%d \nMdt::build() - Found more than one cutout in amdb-x direction and more than one cutout in amdb-y direction, currently not supported",
117 __FILE__, __LINE__));
118 }
119
120 if (!cutoutsVsX) {
121 std::array<int, 5> cutoutNtubes{};
122 std::array<bool, 5> cutoutFullLength{};
123 std::array<double, 5> cutoutXtubes{};
124 std::array<double, 5> cutoutTubeLength{};
125 std::array<double, 5> cutoutYmax{};
126
127 for (
int i = 0;
i < 5;
i++) {
128 cutoutFullLength[
i] =
true;
129 cutoutTubeLength[
i] =
width;
130 }
131
132
133 for (
int i = 0;
i <
Ncuts;
i++) {
134 for (
int j = i + 1; j <
Ncuts; j++) {
135 if (vcutdef[j]->dy < vcutdef[i]->dy) {
136 Cutout *
c = vcutdef[
i];
137 vcutdef[
i] = vcutdef[j];
139 }
140 }
141 }
142
143
145 int cutLocationCode[3] = {0, 0, 0};
146 for (
int i = 0;
i <
Ncuts;
i++) {
147 if (vcutdef[i]->dy <= 0)
148 cutLocationCode[
i] = -1;
149 if (
round(vcutdef[i]->dy + vcutdef[i]->lengthY, 2) >=
round(
top, 2))
150 cutLocationCode[
i] = 1;
151 }
152
153
154 double twidth{0.},
xmin{0.},
xmax{0.};
155 bool cutAtAngle = false;
157 for (
int i = 0;
i <
Ncuts;
i++) {
158 Cutout *
c = vcutdef[
i];
160 cutAtAngle = true;
162 xmin = -twidth / 2. <
c->dx -
c->widthXs / 2. ? -twidth / 2. :
c->dx +
c->widthXs / 2.;
163 xmax = twidth / 2. >
c->dx +
c->widthXs / 2. ? twidth / 2. :
c->dx -
c->widthXs / 2.;
164 if (cutLocationCode[i] == -1) {
165 cutoutYmax[
Nsteps] =
c->lengthY;
168 cutoutFullLength[
Nsteps] =
false;
170 } else if (cutLocationCode[i] == 1) {
175 cutoutFullLength[
Nsteps] =
false;
176 } else {
179 cutoutYmax[
Nsteps] =
c->dy +
c->lengthY;
182 cutoutFullLength[
Nsteps] =
false;
184 }
185 }
188
189 double regionLength{0.}, low{0.};
190 int fullLengthCounter{0}, tubeCounter{0};
192 if (cutoutFullLength[i])
193 fullLengthCounter++;
194
195 regionLength = cutoutYmax[
i] - low;
197 if ((regionLength /
tubePitch - cutoutNtubes[i]) > 0.5)
198 cutoutNtubes[
i] += 1;
199
200 if (fullLengthCounter > 1)
203 tubeCounter += cutoutNtubes[
i];
204 }
205 if (tubeCounter >
layer->nrOfTubes)
206 --cutoutNtubes[
Nsteps - 1];
207
210 log << MSG::VERBOSE <<
" cutoutYmax[" <<
i <<
"] = " << cutoutYmax[
i] <<
" cutoutTubeLength[" <<
i <<
"] = " << cutoutTubeLength[
i] <<
" cutoutXtubes[" <<
i
211 <<
"] = " << cutoutXtubes[
i] <<
" cutoutFullLength[" <<
i <<
"] = " << cutoutFullLength[
i] <<
" cutoutNtubes[" <<
i <<
"] = " << cutoutNtubes[
i]
213 }
214 }
215
216
217
218
219
220
221
222 if (
logVolName.find(
"MDT10") != std::string::npos) {
223
224 if (vcutdef[0]->icut == 1) {
225 if (vcutdef[0]->dead1 > 0.)
227 else
229 } else if (vcutdef[0]->icut == 2) {
230 if (vcutdef[0]->dead1 > 0.)
232 else
234 } else if (vcutdef[0]->icut == 3) {
235 if (vcutdef[0]->dead1 > 0.)
237 else
239 } else {
240 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
241 std::abort();
242 }
243 }
else if (
logVolName.find(
"MDT11") != std::string::npos) {
244
245 if (vcutdef[0]->icut == 1) {
246 if (vcutdef[0]->dead1 > 0.)
248 else
250 } else if (vcutdef[0]->icut == 2) {
251 if (vcutdef[0]->dead1 > 0.)
253 else
255 } else if (vcutdef[0]->icut == 3) {
256 if (vcutdef[0]->dead1 > 0.)
258 else
260 } else {
261 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
262 std::abort();
263 }
264 }
else if (
logVolName.find(
"MDT12") != std::string::npos) {
265
266 if (vcutdef[0]->icut == 1) {
267 if (vcutdef[0]->dead1 > 0.)
269 else
271 } else if (vcutdef[0]->icut == 2) {
272 if (vcutdef[0]->dead1 > 0.)
274 else
276 } else if (vcutdef[0]->icut == 3) {
277 if (vcutdef[0]->dead1 > 0.)
279 else
281 } else {
282 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
283 std::abort();
284 }
285 }
else if (
logVolName.find(
"MDT13") != std::string::npos) {
286
287 if (vcutdef[0]->icut == 1) {
288 if (vcutdef[0]->dead1 > 0.)
290 else
292 } else if (vcutdef[0]->icut == 2) {
293 if (vcutdef[0]->dead1 > 0.)
295 else
297 } else if (vcutdef[0]->icut == 3) {
298 if (vcutdef[0]->dead1 > 0.)
300 else
302 } else {
303 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
304 std::abort();
305 }
306 }
307
308 if (
logVolName.find(
"MDT10") != std::string::npos ||
logVolName.find(
"MDT11") != std::string::npos ||
logVolName.find(
"MDT12") != std::string::npos ||
309 logVolName.find(
"MDT13") != std::string::npos) {
310
311 for (
int i = 0;
i < 5;
i++) {
313 cutoutFullLength[
i] =
true;
314 cutoutXtubes[
i] = 0.;
315 cutoutTubeLength[
i] =
width;
317 }
318 }
319
320
323 for (
int i = 0;
i < 5;
i++) {
324 layer->cutoutNtubes[
i] = cutoutNtubes[
i];
325 layer->cutoutTubeLength[
i] = cutoutTubeLength[
i];
326 layer->cutoutFullLength[
i] = cutoutFullLength[
i];
327 layer->cutoutXtubes[
i] = cutoutXtubes[
i];
328 layer->cutoutYmax[
i] = cutoutYmax[
i];
329 if (!cutoutFullLength[i])
331
332 }
333
334 layer->cutoutAtAngle = cutAtAngle;
335 } else {
336
337
339 throw std::runtime_error(Form("File: %s, Line: %d\nMdt::build() - only support cutouts along amdb-x for rectangular chambers", __FILE__, __LINE__));
340 }
341
342 std::vector<std::pair<double, double>> nonCutoutXSteps;
343 std::vector<std::pair<double, double>> nonCutoutYSteps;
344
345
346 std::sort(vcutdef.begin(),vcutdef.end(),[](
const Cutout *
a ,
const Cutout* b ){
347 return a->dx < b->dx;
348 });
349
352 double yminChamber = 0;
354
355 double latestXMax = xminChamber;
356
357 for (
int i = 0;
i <
Ncuts; ++
i) {
358 Cutout *
c = vcutdef[
i];
359 double lowerX =
round(
c->dx -
c->widthXs / 2, 2);
360 double xmin = std::max(lowerX, xminChamber);
361 log<<MSG::DEBUG<<__FILE__<<
":"<<__LINE__
364 <<" xminChamber: "<<xminChamber<<" xmaxChamber: "<<xmaxChamber
365 <<" ymaxChamber: "<<ymaxChamber
366 <<" yminChamber: "<<yminChamber
367 <<" latestXMax: "<<latestXMax
369 <<
" c->widthXs/2 "<<
c->widthXs / 2<<
endmsg;
370 if (
xmin < latestXMax) {
371 throw std::runtime_error(Form("File: %s, Line: %d\nMdt::build() - cannot have cutouts along amdb-x which overlap in amdb-x %f > %f",
372 __FILE__, __LINE__, latestXMax,
xmin));
373 }
374 if (i == 0 &&
xmin > xminChamber) {
375
376 nonCutoutXSteps.emplace_back(xminChamber, lowerX);
377 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
378 }
379 double upperX =
round(
c->dx +
c->widthXs / 2, 2);
380 double xmax = (upperX >= xmaxChamber) ? xmaxChamber : upperX;
381
382 double ymin =
round(
c->dy +
c->lengthY, 2) < ymaxChamber ?
c->dy +
c->lengthY : 0;
383 double ymax = ymaxChamber <=
round(
c->dy +
c->lengthY, 2) ?
c->dy : ymaxChamber;
384
385 if (latestXMax <
xmin) {
386
387 nonCutoutXSteps.emplace_back(latestXMax,
xmin);
388 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
389 }
390
391 nonCutoutXSteps.emplace_back(
xmin,
xmax);
392 nonCutoutYSteps.emplace_back(
ymin,
ymax);
393
394 if (i ==
Ncuts - 1 &&
xmax < xmaxChamber) {
395
396 nonCutoutXSteps.emplace_back(
xmax, xmaxChamber);
397 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
398 }
399
401 }
402
403
405 layer->cutoutNsteps = nonCutoutXSteps.size();
406 layer->m_nonCutoutXSteps = nonCutoutXSteps;
407 layer->m_nonCutoutYSteps = nonCutoutYSteps;
408 layer->cutoutAtAngle =
false;
409 }
410 }
float round(const float toRound, const unsigned int decimals)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.