354{
355 using namespace Acts::VectorHelpers;
356
357
358 double rmin_at_center = std::numeric_limits<double>::max();
359 double rmin_at_choke = std::numeric_limits<double>::max();
360 double rmax = std::numeric_limits<double>::lowest();
361 double zmin = std::numeric_limits<double>::max();
362 double zmax = std::numeric_limits<double>::lowest();
363 double cutout_zmin_abs = std::numeric_limits<double>::max();
364
365
366
367
368
369 for (const auto& box : boxStore) {
370 Acts::Vector3
vmin = box->min().cast<
double>();
371 Acts::Vector3
vmax = box->max().cast<
double>();
372
373 double vrmin =
perp(vmin);
374 double vrmax =
perp(vmax);
375
376 rmin_at_choke = std::min(rmin_at_choke, std::min(vrmin, vrmax));
377
378 rmax = std::max(rmax, std::max(vrmin, vrmax));
381
382 if (std::abs(
vmin.z()) < 100) {
383 rmin_at_center = std::min(vrmin, rmin_at_center);
384 }
385 if (std::abs(
vmax.z()) < 100) {
386 rmin_at_center = std::min(vrmax, rmin_at_center);
387 }
388 }
389
390 for (const auto& box : boxStore) {
391 Acts::Vector3
vmin = box->min().cast<
double>();
392 Acts::Vector3
vmax = box->max().cast<
double>();
393 double vrmin =
perp(vmin);
394 double vrmax =
perp(vmax);
395
396 if (vrmin < rmin_at_center * 0.9) {
397 cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(
vmin.z()));
398 }
399 if (vrmax < rmin_at_center * 0.9) {
400 cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(
vmax.z()));
401 }
402 }
403
405 double dz2 = cutout_zmin_abs;
406
407
408 double envZ = 5;
409 double envR = 5;
410 dz1 += envZ;
411 dz2 -= envZ;
412 rmax += envR;
413 if(rmin_at_choke > envR) rmin_at_choke -= envR;
414 rmin_at_center -= envR;
415
416
418 << " rmin at choke: " << rmin_at_choke
419 << " rmax: " << rmax << " zmin: " << zmin << " zmax: " << zmax
420 << " coutout_zmin_abs: " << cutout_zmin_abs);
421
422
423
424
425
426
427 auto idCylBds
428 = dynamic_cast<const Acts::CylinderVolumeBounds*>(&insideVolume->volumeBounds());
429 if (idCylBds == nullptr) {
430 ATH_MSG_ERROR(
"Unable to dynamic cast volume bounds to Acts::CylinderVolumeBounds");
431 throw std::runtime_error("Error casting to CylinderVolumeBounds");
432 }
433
434 double idRMax = idCylBds->get(CVBBV::eMaxR);
435 double idRMin = idCylBds->get(CVBBV::eMinR);
436 double idHlZ = idCylBds->get(CVBBV::eHalfLengthZ);
437
439
440 ATH_MSG_VERBOSE(
"Inside volume transform: \n" << insideVolume->transform().matrix());
441
442 if (!insideVolume->transform().isApprox(Acts::Transform3::Identity())) {
444
445
446
447
448 const auto&
trf = insideVolume->transform();
449
450 Acts::RotationMatrix3 rot =
trf.rotation();
451 bool unityRot = rot.isApprox(Acts::RotationMatrix3::Identity());
452
454
455
456 const Acts::Vector3 trl =
trf.translation();
457 bool transZOnly = std::abs(1 - std::abs(Acts::Vector3::UnitZ().
dot(trl.normalized()))) < 1
e-6;
458
460 ATH_MSG_VERBOSE(
"TRL "<< trl.normalized().dot(Acts::Vector3::UnitZ()));
461
462 if(!unityRot || !transZOnly) {
463 ATH_MSG_ERROR(
"The ID appears to be shifted from the origin. I cannot handle this.");
465 throw std::runtime_error("Error building calo");
466 }
467 else {
468 ATH_MSG_VERBOSE(
"Checked: non unitarity is ONLY due to shift along z axis: that's ok");
469 double prevIdHlZ = idHlZ;
470 idHlZ += std::abs(trl.z());
471 ATH_MSG_VERBOSE(
"Modifying effective half length of ID cylinder: " << prevIdHlZ <<
" => " << idHlZ);
472 }
473 }
474
475
476 if (idRMax > rmin_at_center || idHlZ > dz2 || (idRMin > rmin_at_choke && idRMin != 0.)) {
478 ATH_MSG_ERROR(
"This can be because the ID overlaps into the calo volume");
479 ATH_MSG_ERROR(
"Or because the Calo choke radius is SMALLER than the ID inner radius");
480 ATH_MSG_ERROR(
"Currently, I can only make the choke radius smaller, I can not make it larger");
481 ATH_MSG_ERROR(
"nor can I manipulate the ID volume bounds at this point.");
482 ATH_MSG_ERROR(
"ID rMax: " << idRMax <<
" Calo rMin@center: " << rmin_at_center);
483 ATH_MSG_ERROR(
"ID hlZ: " << idHlZ <<
" Calo inner Z hl: " << dz2);
484 ATH_MSG_ERROR(
"ID rMin: " << idRMin <<
" Calo rMin@choke: " << rmin_at_choke);
486 throw std::runtime_error("Error building calo");
487 }
488
489
490
491
492 rmin_at_choke = idRMin;
493
494 std::shared_ptr<Acts::CutoutCylinderVolumeBounds> volBds = nullptr;
495 volBds = std::make_shared<Acts::CutoutCylinderVolumeBounds>(
496 rmin_at_choke, rmin_at_center, rmax, dz1, dz2);
497
499
500 return volBds;
501}
Scalar perp() const
perp method - perpendicular length
#define ATH_MSG_VERBOSE(x)
dot(G, fn, nodesToHighlight=[])