Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-23 08:24:43

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0010 
0011 #include <DD4hep/DetFactoryHelper.h>
0012 #include <DD4hep/Objects.h>
0013 #include <XML/Utilities.h>
0014 
0015 #include "DD4hepTestsHelper.hpp"
0016 
0017 using namespace dd4hep;
0018 using namespace Acts;
0019 using namespace ActsPlugins;
0020 using namespace ActsTests;
0021 
0022 /// Standard create_cylinder(...) create a simple cylinder
0023 ///
0024 /// @param dd the detector to which this is addedded
0025 /// @param xml the input xml element
0026 /// @param sens is ignored
0027 ///
0028 /// @return a reference counted DetElement
0029 static Ref_t create_cylinder(Detector &dd, xml_h xml,
0030                              SensitiveDetector /*sens*/) {
0031   xml_det_t x_det = xml;
0032   std::string detName = x_det.nameStr();
0033 
0034   // Make Volume
0035   xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0036 
0037   // Make DetElement
0038   DetElement cylinderElement(detName, x_det.id());
0039   dd4hep::xml::setDetectorTypeFlag(xml, cylinderElement);
0040 
0041   std::string shapeName = x_det_tubs.nameStr();
0042   double phiMin = getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0043   double phiMax = getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0044   Tube tubeShape(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0045                  x_det_tubs.dz(), phiMin, phiMax);
0046   Volume tubeVolume(detName, tubeShape, dd.material(x_det_tubs.materialStr()));
0047   tubeVolume.setVisAttributes(dd, x_det.visStr());
0048 
0049   // Place it in the mother
0050   Volume motherVolume = dd.pickMotherVolume(cylinderElement);
0051   PlacedVolume placedTube = motherVolume.placeVolume(
0052       tubeVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0053   placedTube.addPhysVolID(detName, cylinderElement.id());
0054   cylinderElement.setPlacement(placedTube);
0055 
0056   // And return the element for further parsing
0057   return cylinderElement;
0058 }
0059 
0060 DECLARE_DETELEMENT(Cylinder, create_cylinder)
0061 
0062 /// Standard create_disc(...) create a simple disc
0063 ///
0064 /// @param dd the detector to which this is addedded
0065 /// @param xml the input xml element
0066 /// @param sens is ignored
0067 ///
0068 /// @return a reference counted DetElement
0069 static Ref_t create_disc(Detector &dd, xml_h xml, SensitiveDetector /*sens*/) {
0070   xml_det_t x_det = xml;
0071   std::string detName = x_det.nameStr();
0072 
0073   // Make Volume
0074   xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0075 
0076   // Make DetElement
0077   DetElement discElement(detName, x_det.id());
0078   dd4hep::xml::setDetectorTypeFlag(xml, discElement);
0079 
0080   std::string shapeName = x_det_tubs.nameStr();
0081   double phiMin = getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0082   double phiMax = getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0083 
0084   Tube discShape = Tube(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0085                         x_det_tubs.dz(), phiMin, phiMax);
0086 
0087   Volume discVolume(detName, discShape, dd.material(x_det_tubs.materialStr()));
0088   discVolume.setVisAttributes(dd, x_det.visStr());
0089 
0090   // Place it in the mother
0091   Volume motherVolume = dd.pickMotherVolume(discElement);
0092   PlacedVolume placedTube = motherVolume.placeVolume(
0093       discVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0094   placedTube.addPhysVolID(detName, discElement.id());
0095   discElement.setPlacement(placedTube);
0096 
0097   // And return the element for further parsing
0098   return discElement;
0099 }
0100 
0101 DECLARE_DETELEMENT(Disc, create_disc)
0102 
0103 /// Standard create_rectangle(...) create a simple rectangle
0104 ///
0105 /// @param dd the detector to which this is addedded
0106 /// @param xml the input xml element
0107 /// @param sens is ignored
0108 ///
0109 /// @return a reference counted DetElement
0110 static Ref_t create_rectangle(Detector &dd, xml_h xml,
0111                               SensitiveDetector /*sens*/) {
0112   xml_det_t x_det = xml;
0113   std::string detName = x_det.nameStr();
0114 
0115   // Make Volume
0116   xml_comp_t x_det_box = x_det.child(_U(box));
0117 
0118   // Make DetElement
0119   DetElement rectElement(detName, x_det.id());
0120   dd4hep::xml::setDetectorTypeFlag(xml, rectElement);
0121 
0122   std::string shapeName = x_det_box.nameStr();
0123   Box rectShape(shapeName, 0.5 * x_det_box.dx(), 0.5 * x_det_box.dy(),
0124                 0.5 * x_det_box.dz());
0125 
0126   Volume rectVolume(detName, rectShape, dd.material(x_det_box.materialStr()));
0127   rectVolume.setVisAttributes(dd, x_det.visStr());
0128 
0129   // Place it in the mother
0130   Volume motherVolume = dd.pickMotherVolume(rectElement);
0131   PlacedVolume placedRect = motherVolume.placeVolume(
0132       rectVolume, DD4hepTestsHelper::createTransform(x_det_box));
0133   placedRect.addPhysVolID(detName, rectElement.id());
0134   rectElement.setPlacement(placedRect);
0135 
0136   // And return the element for further parsing
0137   return rectElement;
0138 }
0139 
0140 DECLARE_DETELEMENT(Rectangle, create_rectangle)
0141 
0142 /// Standard create_trapezoid (...) create a simple trapezoid
0143 ///
0144 /// @param dd the detector to which this is addedded
0145 /// @param xml the input xml element
0146 /// @param sens is ignored
0147 ///
0148 /// @return a reference counted DetElement
0149 static Ref_t create_trapezoid(Detector &dd, xml_h xml,
0150                               SensitiveDetector /*sens*/) {
0151   xml_det_t x_det = xml;
0152   std::string detName = x_det.nameStr();
0153 
0154   // Make Volume
0155   xml_comp_t x_det_trap = x_det.child(_U(trap));
0156 
0157   // Make DetElement
0158   DetElement trapElement(detName, x_det.id());
0159   dd4hep::xml::setDetectorTypeFlag(xml, trapElement);
0160 
0161   std::string shapeName = x_det_trap.nameStr();
0162 
0163   // Due to convention this causes an axis flip on x
0164   Trapezoid trapShape(x_det_trap.x1(), x_det_trap.x2(), 0.5 * x_det_trap.dz(),
0165                       0.5 * x_det_trap.dz(), 0.5 * x_det_trap.dy());
0166 
0167   Volume trapVolume(detName, trapShape, dd.material(x_det_trap.materialStr()));
0168   trapVolume.setVisAttributes(dd, x_det.visStr());
0169 
0170   // Place it in the mother
0171   Volume motherVolume = dd.pickMotherVolume(trapElement);
0172   PlacedVolume placedTrap = motherVolume.placeVolume(
0173       trapVolume, DD4hepTestsHelper::createTransform(x_det_trap));
0174   placedTrap.addPhysVolID(detName, trapElement.id());
0175   trapElement.setPlacement(placedTrap);
0176 
0177   // And return the element for further parsing
0178   return trapElement;
0179 }
0180 
0181 DECLARE_DETELEMENT(Trapezoid, create_trapezoid)