Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-16 07:07:03

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2023 Justin Chan
0003 
0004 #include "DD4hep/DetFactoryHelper.h"
0005 #include "DD4hep/Printout.h"
0006 #include "TMath.h"
0007 #include <XML/Helper.h>
0008 
0009 using namespace std;
0010 using namespace dd4hep;
0011 
0012 static Ref_t create_detector(Detector& det, xml_h e, SensitiveDetector /* sens */) {
0013 
0014   using namespace ROOT::Math;
0015   xml_det_t x_det = e;
0016   string det_name = x_det.nameStr();
0017   DetElement sdet(det_name, x_det.id());
0018   Assembly assembly(det_name + "_assembly");
0019   Material m_Iron   = det.material("Iron");
0020   Material m_Copper = det.material("Copper");
0021   const string vis1 = getAttrOrDefault<string>(x_det, _Unicode(vis_name1), "AnlGreen");
0022   const string vis2 = getAttrOrDefault<string>(x_det, _Unicode(vis_name2), "AnlRed");
0023   const string vis3 = getAttrOrDefault<string>(x_det, _Unicode(vis_name3), "AnlGray");
0024 
0025   // Creates the outer box for the main body
0026   xml::Component box_dim = x_det.child(_Unicode(dimensions_mainbody_outer));
0027   double height          = box_dim.attr<double>(_Unicode(y));
0028   double width           = box_dim.attr<double>(_Unicode(x));
0029   double depth           = box_dim.attr<double>(_Unicode(z));
0030 
0031   Box box_outer(width / 2., height / 2., depth / 2.);
0032 
0033   // Creates the innner box for the main body
0034   xml::Component box_dim_2 = x_det.child(_Unicode(dimensions_mainbody_inner));
0035   double height_2          = box_dim_2.attr<double>(_Unicode(y));
0036   double width_2           = box_dim_2.attr<double>(_Unicode(x));
0037   double depth_2           = box_dim_2.attr<double>(_Unicode(z));
0038 
0039   Box box_inner(width_2 / 2., height_2 / 2., depth_2 / 2.);
0040 
0041   // Creates the outer box for the shape of the coils
0042   xml::Component box_dim_3 = x_det.child(_Unicode(dimensions_coils_outer));
0043   double height_3          = box_dim_3.attr<double>(_Unicode(y));
0044   double width_3           = box_dim_3.attr<double>(_Unicode(x));
0045   double depth_3           = box_dim_3.attr<double>(_Unicode(z));
0046 
0047   Box coils_outer(width_3 / 2., height_3 / 2., depth_3 / 2.);
0048 
0049   // Creates the first inner box for the shape of the coils
0050   xml::Component box_dim_4 = x_det.child(_Unicode(dimensions_coils_inner_1));
0051   double height_4          = box_dim_4.attr<double>(_Unicode(y));
0052   double width_4           = box_dim_4.attr<double>(_Unicode(x));
0053   double depth_4           = box_dim_4.attr<double>(_Unicode(z));
0054 
0055   Box coils_inner_1(width_4 / 2., height_4 / 2., depth_4 / 2.);
0056 
0057   // Creates the second inner box for the shape of the coils
0058   xml::Component box_dim_5 = x_det.child(_Unicode(dimensions_coils_inner_2));
0059   double height_5          = box_dim_5.attr<double>(_Unicode(y));
0060   double width_5           = box_dim_5.attr<double>(_Unicode(x));
0061   double depth_5           = box_dim_5.attr<double>(_Unicode(z));
0062 
0063   Box coils_inner_2(width_5 / 2., height_5 / 2., depth_5 / 2.);
0064 
0065   // Creates the outer box for the shape of the yoke
0066   xml::Component box_dim_6 = x_det.child(_Unicode(dimensions_yoke_outer));
0067   double height_6          = box_dim_6.attr<double>(_Unicode(y));
0068   double width_6           = box_dim_6.attr<double>(_Unicode(x));
0069   double depth_6           = box_dim_6.attr<double>(_Unicode(z));
0070 
0071   Box yoke_outer(width_6 / 2., height_6 / 2., depth_6 / 2.);
0072 
0073   // Creates the first inner box for the shape of the coils
0074   xml::Component box_dim_7 = x_det.child(_Unicode(dimensions_yoke_inner));
0075   double height_7          = box_dim_7.attr<double>(_Unicode(y));
0076   double width_7           = box_dim_7.attr<double>(_Unicode(x));
0077   double depth_7           = box_dim_7.attr<double>(_Unicode(z));
0078 
0079   Box yoke_inner(width_7 / 2., height_7 / 2., depth_7 / 2.);
0080 
0081   // Creates the outer box for the shape of the legs
0082   xml::Component box_dim_8 = x_det.child(_Unicode(dimensions_leg_outer));
0083   double height_8          = box_dim_8.attr<double>(_Unicode(y));
0084   double width_8           = box_dim_8.attr<double>(_Unicode(x));
0085   double depth_8           = box_dim_8.attr<double>(_Unicode(z));
0086 
0087   Box leg_outer(width_8 / 2., height_8 / 2., depth_8 / 2.);
0088 
0089   // Creates the inner box for the shape of the legs
0090   xml::Component box_dim_9 = x_det.child(_Unicode(dimensions_leg_inner));
0091   double height_9          = box_dim_9.attr<double>(_Unicode(y));
0092   double width_9           = box_dim_9.attr<double>(_Unicode(x));
0093   double depth_9           = box_dim_9.attr<double>(_Unicode(z));
0094 
0095   Box leg_inner(width_9 / 2., height_9 / 2., depth_9 / 2.);
0096 
0097   // Sets box position
0098   xml::Component box_pos = x_det.child(_Unicode(position));
0099   double x               = box_pos.attr<double>(_Unicode(x));
0100   double y               = box_pos.attr<double>(_Unicode(y));
0101   double z               = box_pos.attr<double>(_Unicode(z));
0102 
0103   // Subtractes the volume of the inner box from the outer box for the main body
0104   BooleanSolid main_body = SubtractionSolid(box_outer, box_inner);
0105   Volume v_main_body(det_name + "_vol_main_body", main_body, m_Iron);
0106   sdet.setAttributes(det, v_main_body, x_det.regionStr(), x_det.limitsStr(), vis1);
0107   assembly.placeVolume(v_main_body, Position(x, y, z));
0108 
0109   // Creates panels by subtracting the inner boxes of the coils from the outer box of the coilss
0110   BooleanSolid coils_1 = SubtractionSolid(coils_outer, coils_inner_1);
0111   BooleanSolid coils   = SubtractionSolid(coils_1, coils_inner_2);
0112   Volume v_coils(det_name + "_vol_coils", coils, m_Copper);
0113   sdet.setAttributes(det, v_coils, x_det.regionStr(), x_det.limitsStr(), vis2);
0114   assembly.placeVolume(v_coils, Position(x, y, z));
0115 
0116   // Creates coils by subtracting the inner box of the yoke from the outer box of the yoke
0117   BooleanSolid yoke = SubtractionSolid(yoke_outer, yoke_inner);
0118   Volume v_yoke(det_name + "_vol_yoke", yoke, m_Iron);
0119   sdet.setAttributes(det, v_yoke, x_det.regionStr(), x_det.limitsStr(), vis1);
0120   assembly.placeVolume(v_yoke, Position(x, y, z));
0121 
0122   // Creates the legs by subtracting the inner box of the legs from the outer box of the legs
0123   BooleanSolid legs = SubtractionSolid(leg_outer, leg_inner);
0124   Volume v_legs(det_name + "_vol_legs", legs, m_Iron);
0125   sdet.setAttributes(det, v_legs, x_det.regionStr(), x_det.limitsStr(), vis3);
0126   assembly.placeVolume(v_legs, Position(x, y - height_9 / 2. - height / 2., z));
0127 
0128   // Final placement
0129   auto pv_assembly = det.pickMotherVolume(sdet).placeVolume(
0130       assembly, Transform3D(RotationZYX(0.0, 0.0, 0.0), Position(0, 0, 0)));
0131 
0132   sdet.setPlacement(pv_assembly);
0133 
0134   assembly->GetShape()->ComputeBBox();
0135 
0136   return sdet;
0137 }
0138 
0139 DECLARE_DETELEMENT(LumiMagnets, create_detector)