Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Alex Jentsch, Wouter Deconinck, Whitney Armstrong
0003 
0004 #include "DD4hep/DetFactoryHelper.h"
0005 #include "DD4hep/Printout.h"
0006 #include "DD4hep/Shapes.h"
0007 #include "DDRec/DetectorData.h"
0008 #include "DDRec/Surface.h"
0009 #include "TMath.h"
0010 #include "XML/Layering.h"
0011 
0012 using namespace std;
0013 using namespace dd4hep;
0014 using namespace dd4hep::rec;
0015 using namespace ROOT::Math;
0016 
0017 static Ref_t build_magnet(Detector& dtor, xml_h e, SensitiveDetector /* sens */) {
0018   xml_det_t x_det     = e;
0019   int det_id          = x_det.id();
0020   string det_name     = x_det.nameStr();
0021   xml_dim_t pos       = x_det.child(_U(placement));
0022   double pos_x        = pos.x();
0023   double pos_y        = pos.y();
0024   double pos_z        = pos.z();
0025   double pos_theta    = pos.attr<double>(_U(theta));
0026   xml_dim_t dims      = x_det.dimensions();
0027   double dim_r        = dims.r();
0028   double dim_z        = dims.z();
0029   xml_dim_t apperture = x_det.child(_Unicode(apperture));
0030   double app_r        = apperture.r();
0031   Material iron       = dtor.material("Iron");
0032 
0033   DetElement sdet(det_name, det_id);
0034   Assembly assembly(det_name + "_assembly");
0035 
0036   const string module_name = "Quad_magnet";
0037 
0038   const string yoke_vis =
0039       dd4hep::getAttrOrDefault<std::string>(x_det, _Unicode(vis), "FFMagnetVis");
0040 
0041   sdet.setAttributes(dtor, assembly, x_det.regionStr(), x_det.limitsStr(), yoke_vis);
0042 
0043   // -- yoke
0044   Tube yoke_tube(app_r, dim_r, 0.5 * dim_z);
0045   Volume yoke_vol("yoke_vol", yoke_tube, iron);
0046   auto yoke_pv = assembly.placeVolume(yoke_vol);
0047   yoke_pv.addPhysVolID("element", 1);
0048   DetElement yoke_de(sdet, "yoke_de", 1);
0049   yoke_de.setPlacement(yoke_pv);
0050   yoke_de.setAttributes(dtor, yoke_vol, x_det.regionStr(), x_det.limitsStr(), yoke_vis);
0051 
0052   // -- finishing steps
0053   auto final_pos = Transform3D(Translation3D(pos_x, pos_y, pos_z) * RotationY(pos_theta));
0054   auto pv        = dtor.pickMotherVolume(sdet).placeVolume(assembly, final_pos);
0055   pv.addPhysVolID("system", det_id);
0056   sdet.setPlacement(pv);
0057 
0058   assembly->GetShape()->ComputeBBox();
0059   return sdet;
0060 }
0061 
0062 DECLARE_DETELEMENT(ip6_CylindricalDipoleMagnet, build_magnet)