ddcms_det_element_DDCMS_hcal_DDHCalAngular

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include "DataFormats/Math/interface/angle_units.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/DDutils.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DD4hep/DetFactoryHelper.h"

//#define EDM_ML_DEBUG
using namespace angle_units::operators;

static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
  cms::DDNamespace ns(ctxt, e, true);
  cms::DDAlgoArguments args(ctxt, e);
  // Header section of original DDHCalAngular.h
  int n = args.value<int>("n");
  int startCopyNo = args.value<int>("startCopyNo");
  int incrCopyNo = args.value<int>("incrCopyNo");
  double rangeAngle = args.value<double>("rangeAngle");  //Angular range
  double startAngle = args.value<double>("startAngle");  //Start anle
  double shiftX = args.value<double>("shiftX");          //x Shift
  double shiftY = args.value<double>("shiftY");          //y Shift
  double zoffset = args.value<double>("zoffset");        //z offset
  dd4hep::Volume mother = ns.volume(args.parentName());
  std::string childName = args.value<std::string>("ChildName");
  childName = ns.prepend(childName);
  dd4hep::Volume child = ns.volume(childName);

  // Increment
  double dphi = rangeAngle / n;
#ifdef EDM_ML_DEBUG
  edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parameters for positioning::"
                               << " n " << n << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
                               << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(dphi) << " Shift "
                               << cms::convert2mm(shiftX) << ":" << cms::convert2mm(shiftY) << "\n Parent "
                               << mother.name() << "\tChild " << child.name() << " NameSpace " << ns.name();
#endif
  int copy = startCopyNo;
  double phix = startAngle;
  for (int ii = 0; ii < n; ++ii) {
    if (phix >= 2._pi)
      phix -= 2._pi;
    else if (phix < 0)
      phix += 2._pi;
    dd4hep::Rotation3D rotation;
    if (std::abs(phix) >= 0.1_deg) {
#ifdef EDM_ML_DEBUG
      edm::LogVerbatim("HCalGeom") << "DDHCalAngular::Creating a rotation:"
                                   << "\t90., " << convertRadToDeg(phix) << ", 90.," << (90.0 + convertRadToDeg(phix))
                                   << ", 0, 0";
#endif
      rotation = dd4hep::RotationZ(phix);
    }

    double xpos = shiftX * cos(phix) - shiftY * sin(phix);
    double ypos = shiftX * sin(phix) + shiftY * cos(phix);
    dd4hep::Position tran(xpos, ypos, zoffset);
    mother.placeVolume(child, copy, dd4hep::Transform3D(rotation, tran));
#ifdef EDM_ML_DEBUG
    edm::LogVerbatim("HCalGeom") << "DDHCalAngular:: " << child.name() << " number " << copy << " positioned in "
                                 << mother.name() << " at (" << cms::convert2mm(xpos) << ", " << cms::convert2mm(ypos)
                                 << ", " << cms::convert2mm(zoffset) << ") with rotation matrix: " << rotation;
#endif
    copy += incrCopyNo;
    phix += dphi;
  }
  return cms::s_executed;
}

// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalAngular, algorithm)