Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Jaroslav Adam, Wouter Deconinck
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 createDetector(Detector& lccdd, xml_h e, SensitiveDetector /*sens*/) {
0013 
0014   xml_det_t x_det = e;
0015 
0016   // EightPointSolid -> TGeoArb8 -> G4GenericTrap
0017   // generic trapezoid native coordinates: 4 xy points plane at -dz, 4 xy points plane at +dz, both clockwise
0018   // rotation by +pi/2 about x from generic trapezoid coordinates to detector frame: y -> z,  z -> y
0019 
0020   // start and end in z
0021   double z0 = dd4hep::getAttrOrDefault<double>(x_det, _Unicode(z0), 0);
0022   double z1 = dd4hep::getAttrOrDefault<double>(x_det, _Unicode(z1), 0);
0023 
0024   // full length in z and center position along z
0025   double zsiz = z0 - z1;
0026   double zcen = (z0 + z1) / 2;
0027 
0028   xml::Component points = x_det.child(_Unicode(points));
0029 
0030   double dX0 = points.attr<double>(_Unicode(dX0));
0031   double dY0 = points.attr<double>(_Unicode(dY0));
0032   double dX1 = points.attr<double>(_Unicode(dX1));
0033   double dY1 = points.attr<double>(_Unicode(dY1));
0034 
0035   printout(DEBUG, "BackwardsLumiVac", "dX0: %f", dX0);
0036   printout(DEBUG, "BackwardsLumiVac", "dY0: %f", dY0);
0037   printout(DEBUG, "BackwardsLumiVac", "dX1: %f", dX1);
0038   printout(DEBUG, "BackwardsLumiVac", "dY1: %f", dY1);
0039 
0040   // vertices for the trapezoid
0041   double ver[16];
0042 
0043   // plane at lower z
0044   ver[0] = -dX1;
0045   ver[1] = -dY1;
0046 
0047   ver[2] = -dX1;
0048   ver[3] = dY1;
0049 
0050   ver[4] = dX1;
0051   ver[5] = dY1;
0052 
0053   ver[6] = dX1;
0054   ver[7] = -dY1;
0055 
0056   // plane at higher z
0057   ver[8] = -dX0;
0058   ver[9] = -dY0;
0059 
0060   ver[10] = -dX0;
0061   ver[11] = dY0;
0062 
0063   ver[12] = dX0;
0064   ver[13] = dY0;
0065 
0066   ver[14] = dX0;
0067   ver[15] = -dY0;
0068 
0069   EightPointSolid shape(zsiz / 2, ver);
0070 
0071   Volume vol(x_det.nameStr() + "_vol", shape, lccdd.material("Vacuum"));
0072   vol.setVisAttributes(x_det.visStr());
0073 
0074   DetElement det(x_det.nameStr(), x_det.id());
0075 
0076   Transform3D pos(RotationZYX(0, 0, 0), Position(0, 0, zcen));
0077   PlacedVolume pv = lccdd.pickMotherVolume(det).placeVolume(vol, pos);
0078   det.setPlacement(pv);
0079 
0080   return det;
0081 }
0082 
0083 DECLARE_DETELEMENT(BackwardsLumiVac, createDetector)