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 Dhevan Gangadharan
0003 
0004 //==========================================================================
0005 //
0006 // Places a chain of cylindrical beamline magnets
0007 //
0008 //==========================================================================
0009 
0010 #include "DD4hep/DetFactoryHelper.h"
0011 #include "DD4hep/Printout.h"
0012 #include "DD4hep/Shapes.h"
0013 #include "DDRec/DetectorData.h"
0014 #include "DDRec/Surface.h"
0015 #include "TMath.h"
0016 #include "XML/Layering.h"
0017 
0018 using namespace std;
0019 using namespace dd4hep;
0020 using namespace dd4hep::rec;
0021 using namespace ROOT::Math;
0022 
0023 static Ref_t create_magnet(Detector& description, xml_h e, SensitiveDetector /* sens */) {
0024   xml_det_t x_det = e;
0025   string det_name = x_det.nameStr();
0026   DetElement sdet(det_name, x_det.id());
0027   Assembly assembly(det_name + "_assembly");
0028   Material m_Iron = description.material("Iron");
0029   string vis_name = dd4hep::getAttrOrDefault<std::string>(x_det, _Unicode(vis), "FFMagnetVis");
0030 
0031   for (xml_coll_t magnet_coll(x_det, _Unicode(magnet)); magnet_coll; magnet_coll++) { // magnets
0032 
0033     xml_comp_t magnet(magnet_coll);
0034 
0035     string name   = getAttrOrDefault<string>(magnet, _Unicode(name), "");
0036     double x      = getAttrOrDefault<double>(magnet, _Unicode(x), 0);
0037     double y      = getAttrOrDefault<double>(magnet, _Unicode(y), 0);
0038     double z      = getAttrOrDefault<double>(magnet, _Unicode(z), 0);
0039     double theta  = getAttrOrDefault<double>(magnet, _Unicode(theta), 0);
0040     double length = getAttrOrDefault<double>(magnet, _Unicode(length), 0);
0041     double rin    = getAttrOrDefault<double>(magnet, _Unicode(rin), 0);
0042     double rout   = getAttrOrDefault<double>(magnet, _Unicode(rout), 0);
0043 
0044     // -- yoke
0045     Tube yoke_tube(rin, rout, 0.5 * length);
0046     Volume v_yoke("v_yoke_" + name, yoke_tube, m_Iron);
0047 
0048     v_yoke.setVisAttributes(description.visAttributes(vis_name));
0049 
0050     assembly.placeVolume(v_yoke, Transform3D(RotationY(theta), Position(x, y, z)));
0051   }
0052 
0053   // Final placement
0054   auto pv_assembly =
0055       description.pickMotherVolume(sdet).placeVolume(assembly, Position(0.0, 0.0, 0.0));
0056 
0057   sdet.setPlacement(pv_assembly);
0058 
0059   assembly->GetShape()->ComputeBBox();
0060 
0061   return sdet;
0062 }
0063 
0064 DECLARE_DETELEMENT(CylindricalMagnetChain, create_magnet)