Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:08

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 "Acts/Plugins/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 
0019 /// Standard create_cylinder(...) create a simple cylinder
0020 ///
0021 /// @param dd the detector to which this is addedded
0022 /// @param xml the input xml element
0023 /// @param sens is ignored
0024 ///
0025 /// @return a reference counted DetElement
0026 static Ref_t create_cylinder(Detector &dd, xml_h xml,
0027                              SensitiveDetector /*sens*/) {
0028   xml_det_t x_det = xml;
0029   std::string detName = x_det.nameStr();
0030 
0031   // Make Volume
0032   xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0033 
0034   // Make DetElement
0035   DetElement cylinderElement(detName, x_det.id());
0036   dd4hep::xml::setDetectorTypeFlag(xml, cylinderElement);
0037 
0038   std::string shapeName = x_det_tubs.nameStr();
0039   double phiMin = Acts::getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0040   double phiMax = Acts::getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0041   Tube tubeShape(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0042                  x_det_tubs.dz(), phiMin, phiMax);
0043   Volume tubeVolume(detName, tubeShape, dd.material(x_det_tubs.materialStr()));
0044   tubeVolume.setVisAttributes(dd, x_det.visStr());
0045 
0046   // Place it in the mother
0047   Volume motherVolume = dd.pickMotherVolume(cylinderElement);
0048   PlacedVolume placedTube = motherVolume.placeVolume(
0049       tubeVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0050   placedTube.addPhysVolID(detName, cylinderElement.id());
0051   cylinderElement.setPlacement(placedTube);
0052 
0053   // And return the element for further parsing
0054   return cylinderElement;
0055 }
0056 
0057 DECLARE_DETELEMENT(Cylinder, create_cylinder)
0058 
0059 /// Standard create_disc(...) create a simple disc
0060 ///
0061 /// @param dd the detector to which this is addedded
0062 /// @param xml the input xml element
0063 /// @param sens is ignored
0064 ///
0065 /// @return a reference counted DetElement
0066 static Ref_t create_disc(Detector &dd, xml_h xml, SensitiveDetector /*sens*/) {
0067   xml_det_t x_det = xml;
0068   std::string detName = x_det.nameStr();
0069 
0070   // Make Volume
0071   xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0072 
0073   // Make DetElement
0074   DetElement discElement(detName, x_det.id());
0075   dd4hep::xml::setDetectorTypeFlag(xml, discElement);
0076 
0077   std::string shapeName = x_det_tubs.nameStr();
0078   double phiMin = Acts::getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0079   double phiMax = Acts::getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0080 
0081   Tube discShape = Tube(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0082                         x_det_tubs.dz(), phiMin, phiMax);
0083 
0084   Volume discVolume(detName, discShape, dd.material(x_det_tubs.materialStr()));
0085   discVolume.setVisAttributes(dd, x_det.visStr());
0086 
0087   // Place it in the mother
0088   Volume motherVolume = dd.pickMotherVolume(discElement);
0089   PlacedVolume placedTube = motherVolume.placeVolume(
0090       discVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0091   placedTube.addPhysVolID(detName, discElement.id());
0092   discElement.setPlacement(placedTube);
0093 
0094   // And return the element for further parsing
0095   return discElement;
0096 }
0097 
0098 DECLARE_DETELEMENT(Disc, create_disc)
0099 
0100 /// Standard create_rectangle(...) create a simple rectangle
0101 ///
0102 /// @param dd the detector to which this is addedded
0103 /// @param xml the input xml element
0104 /// @param sens is ignored
0105 ///
0106 /// @return a reference counted DetElement
0107 static Ref_t create_rectangle(Detector &dd, xml_h xml,
0108                               SensitiveDetector /*sens*/) {
0109   xml_det_t x_det = xml;
0110   std::string detName = x_det.nameStr();
0111 
0112   // Make Volume
0113   xml_comp_t x_det_box = x_det.child(_U(box));
0114 
0115   // Make DetElement
0116   DetElement rectElement(detName, x_det.id());
0117   dd4hep::xml::setDetectorTypeFlag(xml, rectElement);
0118 
0119   std::string shapeName = x_det_box.nameStr();
0120   Box rectShape(shapeName, 0.5 * x_det_box.dx(), 0.5 * x_det_box.dy(),
0121                 0.5 * x_det_box.dz());
0122 
0123   Volume rectVolume(detName, rectShape, dd.material(x_det_box.materialStr()));
0124   rectVolume.setVisAttributes(dd, x_det.visStr());
0125 
0126   // Place it in the mother
0127   Volume motherVolume = dd.pickMotherVolume(rectElement);
0128   PlacedVolume placedRect = motherVolume.placeVolume(
0129       rectVolume, DD4hepTestsHelper::createTransform(x_det_box));
0130   placedRect.addPhysVolID(detName, rectElement.id());
0131   rectElement.setPlacement(placedRect);
0132 
0133   // And return the element for further parsing
0134   return rectElement;
0135 }
0136 
0137 DECLARE_DETELEMENT(Rectangle, create_rectangle)
0138 
0139 /// Standard create_trapezoid (...) create a simple trapezoid
0140 ///
0141 /// @param dd the detector to which this is addedded
0142 /// @param xml the input xml element
0143 /// @param sens is ignored
0144 ///
0145 /// @return a reference counted DetElement
0146 static Ref_t create_trapezoid(Detector &dd, xml_h xml,
0147                               SensitiveDetector /*sens*/) {
0148   xml_det_t x_det = xml;
0149   std::string detName = x_det.nameStr();
0150 
0151   // Make Volume
0152   xml_comp_t x_det_trap = x_det.child(_U(trap));
0153 
0154   // Make DetElement
0155   DetElement trapElement(detName, x_det.id());
0156   dd4hep::xml::setDetectorTypeFlag(xml, trapElement);
0157 
0158   std::string shapeName = x_det_trap.nameStr();
0159 
0160   // Due to convention this causes an axis flip on x
0161   Trapezoid trapShape(x_det_trap.x1(), x_det_trap.x2(), 0.5 * x_det_trap.dz(),
0162                       0.5 * x_det_trap.dz(), 0.5 * x_det_trap.dy());
0163 
0164   Volume trapVolume(detName, trapShape, dd.material(x_det_trap.materialStr()));
0165   trapVolume.setVisAttributes(dd, x_det.visStr());
0166 
0167   // Place it in the mother
0168   Volume motherVolume = dd.pickMotherVolume(trapElement);
0169   PlacedVolume placedTrap = motherVolume.placeVolume(
0170       trapVolume, DD4hepTestsHelper::createTransform(x_det_trap));
0171   placedTrap.addPhysVolID(detName, trapElement.id());
0172   trapElement.setPlacement(placedTrap);
0173 
0174   // And return the element for further parsing
0175   return trapElement;
0176 }
0177 
0178 DECLARE_DETELEMENT(Trapezoid, create_trapezoid)