Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:30:07

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 radius = args.value<double>("Radius");                   //Pointing distance from front surface
0016   double offset = args.value<double>("Offset");                   //Offset along Z
0017   double dx = args.value<double>("Dx");                           //Half size along x
0018   double dz = args.value<double>("Dz");                           //Half size along z
0019   double angwidth = args.value<double>("AngWidth");               //Angular width
0020   int iaxis = args.value<int>("Axis");                            //Axis of rotation
0021   std::vector<std::string> names = args.value<std::vector<std::string> >("Names");  //Names for rotation matrices
0022   std::string idName = args.value<std::string>("ChildName");                        //Children name
0023 #ifdef EDM_ML_DEBUG
0024   edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo::Parameters for positioning: Axis " << iaxis << "\tRadius "
0025                                << cms::convert2mm(radius) << "\tOffset " << offset << "\tDx " << cms::convert2mm(dx)
0026                                << "\tDz " << cms::convert2mm(dz) << "\tAngWidth " << convertRadToDeg(angwidth)
0027                                << "\tNumbers " << names.size();
0028   for (unsigned int i = 0; i < names.size(); i++)
0029     edm::LogVerbatim("HCalGeom") << "\tnames[" << i << "] = " << names[i];
0030   edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Parent " << args.parentName() << "\tChild " << idName
0031                                << " NameSpace " << idNameSpace;
0032 #endif
0033 
0034   dd4hep::Volume parent = ns.volume(args.parentName());
0035 
0036   double theta[3], phi[3], pos[3];
0037   phi[0] = 0;
0038   phi[1] = 90._deg;
0039   theta[1 - iaxis] = 90._deg;
0040   pos[1 - iaxis] = 0;
0041   int number = (int)(names.size());
0042   for (int i = 0; i < number; i++) {
0043     double angle = 0.5 * angwidth * (2 * i + 1 - number);
0044     theta[iaxis] = 90._deg + angle;
0045     if (angle > 0) {
0046       theta[2] = angle;
0047       phi[2] = iaxis * 90._deg;
0048     } else {
0049       theta[2] = -angle;
0050       phi[2] = (2 - 3 * iaxis) * 90._deg;
0051     }
0052     pos[iaxis] = angle * (dz + radius);
0053     pos[2] = dx * std::abs(sin(angle)) + offset;
0054 
0055     if (strchr(idName.c_str(), NAMESPACE_SEP) == nullptr)
0056       idName = idNameSpace + idName;
0057     dd4hep::Volume glog = ns.volume(idName);
0058     dd4hep::Position tran(pos[0], pos[1], pos[2]);
0059     dd4hep::Rotation3D rotation;
0060 
0061     static const double tol = 0.01_deg;  // 0.01 degree
0062     if (std::abs(angle) > tol) {
0063 #ifdef EDM_ML_DEBUG
0064       edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Creating a rotation \t" << convertRadToDeg(theta[0]) << ","
0065                                    << convertRadToDeg(phi[0]) << "," << convertRadToDeg(theta[1]) << ","
0066                                    << convertRadToDeg(phi[1]) << "," << convertRadToDeg(theta[2]) << ","
0067                                    << convertRadToDeg(phi[2]);
0068 #endif
0069       rotation = cms::makeRotation3D(theta[0], phi[0], theta[1], phi[1], theta[2], phi[2]);
0070     }
0071     parent.placeVolume(glog, i + 1, dd4hep::Transform3D(rotation, tran));
0072 #ifdef EDM_ML_DEBUG
0073     edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: " << glog.name() << " number " << i + 1 << " positioned in "
0074                                  << parent.name() << " at (" << cms::convert2mm(pos[0]) << ","
0075                                  << cms::convert2mm(pos[1]) << "," << cms::convert2mm(pos[2]) << " with " << rotation;
0076 #endif
0077   }
0078 
0079   return cms::s_executed;
0080 }
0081 
0082 // first argument is the type from the xml file
0083 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalXtalAlgo, algorithm);