16 #include <GaudiKernel/IMessageSvc.h>
17 #include <GaudiKernel/MsgStream.h>
23 #define verbose_mdt false
27 float round(
const float toRound,
const unsigned int decimals) {
28 unsigned int factor =
std::pow(10, decimals);
44 layer = std::make_unique<MultiLayer>(mysql,
s->name);
45 layer->logVolName = lVName;
46 layer->cutoutNsteps = 0;
62 layer->cutoutNsteps = 1;
63 return layer->build(matManager, mysql);
68 std::vector<Cutout *>& vcutdef) {
71 int Ncuts = vcutdef.size();
75 return layer->build(matManager, mysql);
78 return build(matManager, mysql);
93 int Ncuts = vcutdef.size();
94 bool cutoutsVsX {
false}, cutoutsVsY{
false};
96 float lastX{FLT_MAX}, lastY{FLT_MAX};
103 <<
" cutDef->dX "<<vcutdef[
i]->dx
105 <<
" dutDef->dY "<<vcutdef[
i]->dy<<
endmsg;
107 if (lastX != FLT_MAX && lastX * vcutdef[
i]->
dx < 0)
109 lastX = vcutdef[
i]->dx;
110 if (lastY != FLT_MAX && lastY * vcutdef[
i]->
dy < 0)
112 lastY = vcutdef[
i]->dy;
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__));
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{};
127 for (
int i = 0;
i < 5;
i++) {
128 cutoutFullLength[
i] =
true;
129 cutoutTubeLength[
i] =
width;
134 for (
int j =
i + 1; j <
Ncuts; j++) {
135 if (vcutdef[j]->
dy < vcutdef[
i]->
dy) {
137 vcutdef[
i] = vcutdef[j];
145 int cutLocationCode[3] = {0, 0, 0};
147 if (vcutdef[
i]->
dy <= 0)
148 cutLocationCode[
i] = -1;
150 cutLocationCode[
i] = 1;
154 double twidth{0.},
xmin{0.},
xmax{0.};
155 bool cutAtAngle =
false;
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;
179 cutoutYmax[
Nsteps] =
c->dy +
c->lengthY;
182 cutoutFullLength[
Nsteps] =
false;
189 double regionLength{0.}, low{0.};
190 int fullLengthCounter{0}, tubeCounter{0};
192 if (cutoutFullLength[
i])
195 regionLength = cutoutYmax[
i] - low;
197 if ((regionLength /
tubePitch - cutoutNtubes[
i]) > 0.5)
198 cutoutNtubes[
i] += 1;
200 if (fullLengthCounter > 1)
203 tubeCounter += cutoutNtubes[
i];
205 if (tubeCounter >
layer->nrOfTubes)
206 --cutoutNtubes[
Nsteps - 1];
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]
222 if (
logVolName.find(
"MDT10") != std::string::npos) {
224 if (vcutdef[0]->icut == 1) {
225 if (vcutdef[0]->dead1 > 0.)
229 }
else if (vcutdef[0]->icut == 2) {
230 if (vcutdef[0]->dead1 > 0.)
234 }
else if (vcutdef[0]->icut == 3) {
235 if (vcutdef[0]->dead1 > 0.)
240 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
243 }
else if (
logVolName.find(
"MDT11") != std::string::npos) {
245 if (vcutdef[0]->icut == 1) {
246 if (vcutdef[0]->dead1 > 0.)
250 }
else if (vcutdef[0]->icut == 2) {
251 if (vcutdef[0]->dead1 > 0.)
255 }
else if (vcutdef[0]->icut == 3) {
256 if (vcutdef[0]->dead1 > 0.)
261 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
264 }
else if (
logVolName.find(
"MDT12") != std::string::npos) {
266 if (vcutdef[0]->icut == 1) {
267 if (vcutdef[0]->dead1 > 0.)
271 }
else if (vcutdef[0]->icut == 2) {
272 if (vcutdef[0]->dead1 > 0.)
276 }
else if (vcutdef[0]->icut == 3) {
277 if (vcutdef[0]->dead1 > 0.)
282 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
285 }
else if (
logVolName.find(
"MDT13") != std::string::npos) {
287 if (vcutdef[0]->icut == 1) {
288 if (vcutdef[0]->dead1 > 0.)
292 }
else if (vcutdef[0]->icut == 2) {
293 if (vcutdef[0]->dead1 > 0.)
297 }
else if (vcutdef[0]->icut == 3) {
298 if (vcutdef[0]->dead1 > 0.)
303 log << MSG::ERROR <<
"massive error with MDT10 (BMG chambers)" <<
endmsg;
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) {
311 for (
int i = 0;
i < 5;
i++) {
313 cutoutFullLength[
i] =
true;
314 cutoutXtubes[
i] = 0.;
315 cutoutTubeLength[
i] =
width;
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])
334 layer->cutoutAtAngle = cutAtAngle;
339 throw std::runtime_error(Form(
"File: %s, Line: %d\nMdt::build() - only support cutouts along amdb-x for rectangular chambers", __FILE__, __LINE__));
342 std::vector<std::pair<double, double>> nonCutoutXSteps;
343 std::vector<std::pair<double, double>> nonCutoutYSteps;
346 std::sort(vcutdef.begin(),vcutdef.end(),[](
const Cutout *
a ,
const Cutout*
b ){
347 return a->dx < b->dx;
352 double yminChamber = 0;
355 double latestXMax = xminChamber;
359 double lowerX =
round(
c->dx -
c->widthXs / 2, 2);
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));
374 if (
i == 0 &&
xmin > xminChamber) {
376 nonCutoutXSteps.emplace_back(xminChamber, lowerX);
377 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
379 double upperX =
round(
c->dx +
c->widthXs / 2, 2);
380 double xmax = (upperX >= xmaxChamber) ? xmaxChamber : upperX;
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;
385 if (latestXMax <
xmin) {
387 nonCutoutXSteps.emplace_back(latestXMax,
xmin);
388 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
391 nonCutoutXSteps.emplace_back(
xmin,
xmax);
392 nonCutoutYSteps.emplace_back(
ymin,
ymax);
396 nonCutoutXSteps.emplace_back(
xmax, xmaxChamber);
397 nonCutoutYSteps.emplace_back(yminChamber, ymaxChamber);
405 layer->cutoutNsteps = nonCutoutXSteps.size();
406 layer->m_nonCutoutXSteps = nonCutoutXSteps;
407 layer->m_nonCutoutYSteps = nonCutoutYSteps;
408 layer->cutoutAtAngle =
false;