Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   std::string nsName = static_cast<std::string>(ns.name());
0015   // Header section of original DDHGCalWafer.h
0016   double waferSize = args.value<double>("WaferSize");
0017   int cellType = args.value<int>("CellType");
0018   int nColumns = args.value<int>("NColumns");
0019   int nBottomY = args.value<int>("NBottomY");
0020   std::vector<std::string> childNames = args.value<std::vector<std::string> >("ChildNames");
0021   std::vector<int> nCellsRow = args.value<std::vector<int> >("NCellsRow");
0022   std::vector<int> angleEdges = args.value<std::vector<int> >("AngleEdges");
0023   std::vector<int> detectorType = args.value<std::vector<int> >("DetectorType");
0024   std::string parentName = args.parentName();
0025   dd4hep::Volume mother = ns.volume(args.parentName());
0026 #ifdef EDM_ML_DEBUG
0027   edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
0028                                 << " positioned in " << nCellsRow.size() << " rows and " << nColumns
0029                                 << " columns with lowest column at " << nBottomY << " in mother " << parentName
0030                                 << " of size " << cms::convert2mm(waferSize);
0031   for (unsigned int k = 0; k < nCellsRow.size(); ++k)
0032     edm::LogVerbatim("HGCalGeom") << "[" << k << "] Ncells " << nCellsRow[k] << " Edge rotations " << angleEdges[2 * k]
0033                                   << ":" << angleEdges[2 * k + 1] << " Type of edge cells " << detectorType[2 * k]
0034                                   << ":" << detectorType[2 * k + 1];
0035 #endif
0036 
0037   static const int incAlongX = 2;
0038   static const int incAlongY = 6;
0039   double dx = 0.5 * waferSize / nColumns;
0040   double dy = 0.5 * dx * tan(30._deg);
0041   int ny = nBottomY;
0042   int kount(0);
0043 
0044   for (unsigned int ir = 0; ir < nCellsRow.size(); ++ir) {
0045     int nx = 1 - nCellsRow[ir];
0046     double ypos = dy * ny;
0047     for (int ic = 0; ic < nCellsRow[ir]; ++ic) {
0048       std::string name(childNames[0]);
0049       int irot(0);
0050       if (ic == 0) {
0051         name = childNames[detectorType[2 * ir]];
0052         irot = angleEdges[2 * ir];
0053       } else if (ic + 1 == nCellsRow[ir]) {
0054         name = childNames[detectorType[2 * ir + 1]];
0055         irot = angleEdges[2 * ir + 1];
0056       }
0057       dd4hep::Rotation3D rotation;
0058       if (irot != 0) {
0059 #ifdef EDM_ML_DEBUG
0060         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating rotation "
0061                                       << "\t90, " << irot << ", 90, " << (irot + 90) << ", 0, 0";
0062 #endif
0063         double phix = convertDegToRad(irot);
0064         double phiy = convertDegToRad(90 + irot);
0065         rotation = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);
0066       }
0067       std::string namx = nsName + name;
0068       double xpos = dx * nx;
0069       nx += incAlongX;
0070       dd4hep::Position tran(xpos, ypos, 0);
0071       int copy = HGCalTypes::packCellType6(cellType, kount);
0072       mother.placeVolume(ns.volume(namx), copy, dd4hep::Transform3D(rotation, tran));
0073       ++kount;
0074 #ifdef EDM_ML_DEBUG
0075       edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: " << name << " number " << copy << " positioned in " << parentName
0076                                     << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with "
0077                                     << rotation;
0078 #endif
0079     }
0080     ny += incAlongY;
0081   }
0082   return cms::s_executed;
0083 }
0084 
0085 // first argument is the type from the xml file
0086 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWafer, algorithm)