Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0002 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "DD4hep/DetFactoryHelper.h"
0005 
0006 //#define EDM_ML_DEBUG
0007 
0008 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0009   cms::DDNamespace ns(ctxt, e, true);
0010   cms::DDAlgoArguments args(ctxt, e);
0011   // Header section of original DDHCalLinearXY.h
0012   int numberX = args.value<int>("NumberX");      //Slices along X
0013   int numberY = args.value<int>("NumberY");      //Slices along Y
0014   double deltaX = args.value<double>("DeltaX");  //Step along X
0015   double deltaY = args.value<double>("DeltaY");  //Step along Y
0016   std::vector<double> centre = args.value<std::vector<double> >("Center");
0017   dd4hep::Volume parent = ns.volume(args.parentName());
0018   std::vector<std::string> childName = args.value<std::vector<std::string> >("Child");
0019 
0020 #ifdef EDM_ML_DEBUG
0021   edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Parent " << parent.name() << " \twith " << childName.size()
0022                                << " children";
0023   unsigned int k(0);
0024   for (auto const& child : childName) {
0025     edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Child[" << k << "] = " << child;
0026     ++k;
0027   }
0028   edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Number along X/Y " << numberX << "/" << numberY
0029                                << "\tDelta along X/Y " << cms::convert2mm(deltaX) << "/" << cms::convert2mm(deltaY)
0030                                << "\tCentre (" << cms::convert2mm(centre[0]) << ", " << cms::convert2mm(centre[1])
0031                                << "," << cms::convert2mm(centre[2]);
0032 #endif
0033   double xoff = centre[0] - (numberX - 1) * 0.5 * deltaX;
0034   double yoff = centre[1] - (numberY - 1) * 0.5 * deltaY;
0035   unsigned int copy = 0;
0036   for (int i = 0; i < numberX; ++i) {
0037     for (int j = 0; j < numberY; ++j) {
0038       unsigned int k = (childName.size() == 1) ? 0 : copy;
0039       ++copy;
0040       if (k < childName.size() && (childName[k] != " " && childName[k] != "Null")) {
0041         std::string child = childName[k];
0042         dd4hep::Position tran(xoff + i * deltaX, yoff + j * deltaY, centre[2]);
0043         parent.placeVolume(ns.volume(child), copy, tran);
0044 #ifdef EDM_ML_DEBUG
0045         edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: " << child << " number " << copy << " positioned in "
0046                                      << parent.name() << " at (" << cms::convert2mm((xoff + i * deltaX)) << ", "
0047                                      << cms::convert2mm((yoff + j * deltaY)) << ", " << cms::convert2mm(centre[2])
0048                                      << ") with no rotation";
0049 #endif
0050       } else {
0051 #ifdef EDM_ML_DEBUG
0052         edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: no child placed for [" << copy << "]";
0053 #endif
0054       }
0055     }
0056   }
0057   return cms::s_executed;
0058 }
0059 
0060 // first argument is the type from the xml file
0061 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalLinearXY, algorithm)