Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:59

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong
0003 
0004 //==========================================================================
0005 //  AIDA Detector description implementation
0006 //--------------------------------------------------------------------------
0007 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0008 // All rights reserved.
0009 //
0010 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0011 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0012 //
0013 // Author     : M.Frank
0014 //
0015 //==========================================================================
0016 //
0017 // Specialized generic detector constructor
0018 //
0019 //==========================================================================
0020 #include "DD4hep/DetFactoryHelper.h"
0021 
0022 using namespace std;
0023 using namespace dd4hep;
0024 using namespace dd4hep::detail;
0025 
0026 static Ref_t SimpleDiskDetector_create_detector(Detector& description, xml_h e,
0027                                                 SensitiveDetector sens) {
0028   xml_det_t x_det = e;
0029   Material air    = description.air();
0030   string det_name = x_det.nameStr();
0031   bool reflect    = x_det.reflect();
0032   DetElement sdet(det_name, x_det.id());
0033   Assembly assembly(det_name);
0034   PlacedVolume pv;
0035   int l_num          = 0;
0036   xml::Component pos = x_det.position();
0037 
0038   for (xml_coll_t i(x_det, _U(layer)); i; ++i, ++l_num) {
0039     xml_comp_t x_layer = i;
0040     string l_nam       = det_name + _toString(l_num, "_layer%d");
0041     double zmin        = x_layer.inner_z();
0042     double rmin        = x_layer.inner_r();
0043     double rmax        = x_layer.outer_r();
0044     double layerWidth  = 0.;
0045     int s_num          = 0;
0046 
0047     for (xml_coll_t j(x_layer, _U(slice)); j; ++j) {
0048       double thickness = xml_comp_t(j).thickness();
0049       layerWidth += thickness;
0050     }
0051     Tube l_tub(rmin, rmax, layerWidth / 2.0, 2 * M_PI);
0052     Volume l_vol(l_nam, l_tub, air);
0053     l_vol.setVisAttributes(description, x_layer.visStr());
0054     DetElement layer;
0055     PlacedVolume layer_pv;
0056     if (!reflect) {
0057       layer    = DetElement(sdet, l_nam + "_pos", l_num);
0058       layer_pv = assembly.placeVolume(l_vol, Position(0, 0, zmin + layerWidth / 2.));
0059       layer_pv.addPhysVolID("barrel", 3).addPhysVolID("layer", l_num);
0060       layer.setPlacement(layer_pv);
0061     } else {
0062       layer    = DetElement(sdet, l_nam + "_neg", l_num);
0063       layer_pv = assembly.placeVolume(
0064           l_vol, Transform3D(RotationY(M_PI), Position(0, 0, -zmin - layerWidth / 2)));
0065       layer_pv.addPhysVolID("barrel", 2).addPhysVolID("layer", l_num);
0066       layer.setPlacement(layer_pv);
0067       // DetElement layerR = layer.clone(l_nam+"_neg");
0068       // sdet.add(layerR.setPlacement(pv));
0069     }
0070 
0071     double tot_thickness = -layerWidth / 2.0;
0072     for (xml_coll_t j(x_layer, _U(slice)); j; ++j, ++s_num) {
0073       xml_comp_t x_slice = j;
0074       double thick       = x_slice.thickness();
0075       Material mat       = description.material(x_slice.materialStr());
0076       string s_nam       = l_nam + _toString(s_num, "_slice%d");
0077       Volume s_vol(s_nam, Tube(rmin, rmax, thick / 2.0), mat);
0078       if (!reflect) {
0079         s_nam += "_pos";
0080       } else {
0081         s_nam += "_neg";
0082       }
0083       DetElement slice_de(layer, s_nam, s_num);
0084       if (x_slice.isSensitive()) {
0085         sens.setType("tracker");
0086         s_vol.setSensitiveDetector(sens);
0087       }
0088       s_vol.setAttributes(description, x_slice.regionStr(), x_slice.limitsStr(), x_slice.visStr());
0089       pv = l_vol.placeVolume(s_vol, Position(0, 0, tot_thickness + thick / 2));
0090       pv.addPhysVolID("slice", s_num);
0091       slice_de.setPlacement(pv);
0092       tot_thickness = tot_thickness + thick;
0093     }
0094   }
0095   if (x_det.hasAttr(_U(combineHits))) {
0096     sdet.setCombineHits(x_det.attr<bool>(_U(combineHits)), sens);
0097   }
0098   pv =
0099       description.pickMotherVolume(sdet).placeVolume(assembly, Position(pos.x(), pos.y(), pos.z()));
0100   pv.addPhysVolID("system", x_det.id()); // Set the subdetector system ID.
0101   sdet.setPlacement(pv);
0102   return sdet;
0103 }
0104 
0105 DECLARE_DETELEMENT(epic_ref_SolenoidEndcap, SimpleDiskDetector_create_detector)
0106 DECLARE_DETELEMENT(epic_SolenoidEndcap, SimpleDiskDetector_create_detector)