Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:43

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/angle_units.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 using namespace angle_units::operators;
0009 
0010 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0011   cms::DDNamespace ns(ctxt, e, true);
0012   cms::DDAlgoArguments args(ctxt, e);
0013   // Header section
0014   std::string idNameSpace = static_cast<std::string>(ns.name());  //Namespace of this and ALL sub-parts
0015   double eta = args.value<double>("Eta");                         //Eta at which beam is focussed
0016   double theta = 2.0 * atan(exp(-eta));                           //Corresponding theta value
0017   double shiftY = args.value<double>("ShiftX");                   //Shift along Y
0018   double shiftX = args.value<double>("ShiftY");                   //Shift along X
0019   double zoffset = args.value<double>("Zoffset");                 //Offset in z
0020   double dist = args.value<double>("Distance");                   //Radial distance
0021   double tilt = args.value<double>("TiltAngle");                  //Tilt with respect to y-axis
0022   int copyNumber = args.value<int>("Number");                     //Copy Number
0023   std::string childName = args.value<std::string>("ChildName");   //Children name
0024   if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
0025     childName = idNameSpace + childName;
0026 #ifdef EDM_ML_DEBUG
0027   edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parameters for positioning-- Eta " << eta << "\tTheta "
0028                                << convertRadToDeg(theta) << "\tShifts " << cms::convert2mm(shiftX) << ", "
0029                                << cms::convert2mm(shiftY) << " along x, y axes; \tZoffest " << cms::convert2mm(zoffset)
0030                                << "\tRadial Distance " << cms::convert2mm(dist) << "\tTilt angle "
0031                                << convertRadToDeg(tilt) << "\tcopyNumber " << copyNumber;
0032   edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parent " << args.parentName() << "\tChild " << childName
0033                                << " NameSpace " << idNameSpace;
0034 #endif
0035 
0036   dd4hep::Volume mother = ns.volume(args.parentName());
0037   dd4hep::Volume child = ns.volume(childName);
0038 
0039   // Create the rotation matrices
0040   double thetax = 90._deg - theta;
0041   double z = zoffset + dist * tan(thetax);
0042   double x = shiftX - shiftY * sin(tilt);
0043   double y = shiftY * cos(tilt);
0044   dd4hep::Position tran(x, y, z);
0045   dd4hep::Rotation3D rot;
0046   if (tilt != 0) {
0047 #ifdef EDM_ML_DEBUG
0048     edm::LogVerbatim("HCalGeom") << "DDHCalZposAlgo: Creating a rotation \t90, " << convertRadToDeg(tilt) << ",90,"
0049                                  << (90 + convertRadToDeg(tilt)) << ", 0, 0";
0050 #endif
0051     rot = dd4hep::RotationZ(tilt);
0052   }
0053   mother.placeVolume(child, copyNumber, dd4hep::Transform3D(rot, tran));
0054 #ifdef EDM_ML_DEBUG
0055   edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: " << child.name() << " number " << copyNumber << " positioned in "
0056                                << mother.name() << " at (" << cms::convert2mm(x) << ", " << cms::convert2mm(y) << ", "
0057                                << cms::convert2mm(z) << ") with " << rot;
0058 #endif
0059 
0060   return cms::s_executed;
0061 }
0062 
0063 // first argument is the type from the xml file
0064 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTBZposAlgo, algorithm);