Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:11

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 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0007 
0008 //#define EDM_ML_DEBUG
0009 using namespace angle_units::operators;
0010 
0011 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0012   cms::DDNamespace ns(ctxt, e, true);
0013   cms::DDAlgoArguments args(ctxt, e);
0014 
0015   // Header section of original DDHGCalWafer.h
0016   const auto& cellSize = args.value<double>("CellSize");                         // Cell Size
0017   const auto& cellType = args.value<int>("CellType");                            // Type (1 fine; 2 coarse)
0018   const auto& childNames = args.value<std::vector<std::string> >("ChildNames");  // Names of children
0019   const auto& positionX = args.value<std::vector<int> >("PositionX");            // Position in X
0020   const auto& positionY = args.value<std::vector<int> >("PositionY");            // Position in Y
0021   const auto& angles = args.value<std::vector<double> >("Angles");               // Rotation angle
0022   const auto& detectorType = args.value<std::vector<int> >("DetectorType");      // Detector type
0023 #ifdef EDM_ML_DEBUG
0024   edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
0025                                 << " positioned " << positionX.size() << " times with cell size " << cellSize;
0026   for (unsigned int k = 0; k < positionX.size(); ++k)
0027     edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << cms::convert2mm(positionX[k]) << " y "
0028                                   << cms::convert2mm(positionY[k]) << " angle " << angles[k] << " detector "
0029                                   << detectorType[k];
0030 
0031   std::string idName = args.parentName();  // Name of the "parent" volume.
0032   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << idName << " NameSpace " << ns.name();
0033 #endif
0034 
0035   dd4hep::Volume mother = ns.volume(args.parentName());
0036   double dx = 0.5 * cellSize;
0037   double dy = 0.5 * dx * tan(30._deg);
0038 
0039   for (unsigned int k = 0; k < positionX.size(); ++k) {
0040     std::string name(childNames[detectorType[k]]);
0041     name = ns.prepend(name);
0042     dd4hep::Rotation3D rotation;
0043     if (angles[k] != 0) {
0044       double phi = convertDegToRad(angles[k]);
0045 #ifdef EDM_ML_DEBUG
0046       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation \t90, " << angles[k] << ", 90, "
0047                                     << (angles[k] + 90) << ", 0, 0";
0048 #endif
0049       rotation = cms::makeRotation3D(90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0050     }
0051     double xpos = dx * positionX[k];
0052     double ypos = dy * positionY[k];
0053     dd4hep::Position tran(xpos, ypos, 0);
0054     int copy = HGCalTypes::packCellType6(cellType, k);
0055     mother.placeVolume(ns.volume(name), copy, dd4hep::Transform3D(rotation, tran));
0056 #ifdef EDM_ML_DEBUG
0057     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << name << " number " << copy << " positioned in " << idName
0058                                   << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with "
0059                                   << rotation;
0060 #endif
0061   }
0062 
0063   return cms::s_executed;
0064 }
0065 
0066 // first argument is the type from the xml file
0067 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferAlgo, algorithm)