Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:22

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/CMSUnits.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 using namespace std;
0007 using namespace dd4hep;
0008 using namespace cms;
0009 using namespace cms_units::operators;
0010 
0011 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0012   cms::DDNamespace ns(ctxt, e, true);
0013   DDAlgoArguments args(ctxt, e);
0014   // Header section of original DDTrackerAngular.h
0015   int n = args.value<int>("N");
0016   int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1;
0017   int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1;
0018   double rangeAngle = args.value<double>("RangeAngle");           //Range in angle
0019   double startAngle = args.value<double>("StartAngle");           //Start anle
0020   double radius = args.value<double>("Radius");                   //Radius
0021   vector<double> center = args.value<vector<double> >("Center");  //Phi values
0022   Volume mother = ns.volume(args.parentName());
0023   Volume child = ns.volume(args.value<string>("ChildName"));
0024 
0025   double delta = 0e0;  //Increment in phi
0026   // Code section of original DDTrackerAngular.cc
0027   if (fabs(rangeAngle - 360.0_deg) < 0.001_deg) {
0028     delta = rangeAngle / double(n);
0029   } else if (n > 1) {
0030     delta = rangeAngle / double(n - 1);
0031   }
0032 
0033   edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular debug: Parameters for positioning:: n " << n
0034                                   << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
0035                                   << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(delta) << " Radius "
0036                                   << radius << " Centre " << center[0] << ", " << center[1] << ", " << center[2];
0037   edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular debug: Parent " << mother.name() << "\tChild " << child.name()
0038                                   << " NameSpace " << ns.name();
0039 
0040   double theta = 90._deg;
0041   int copy = startCopyNo;
0042   double phi = startAngle;
0043   for (int i = 0; i < n; i++) {
0044     double phix = phi;
0045     double phiy = phix + 90._deg;
0046     double phideg = convertRadToDeg(phix);
0047 
0048     Rotation3D rotation;
0049     if (phideg != 0) {
0050       string rotstr = ns.nsName(child.name()) + std::to_string(phideg * 10.);
0051       auto irot = ctxt.rotations.find(ns.prepend(rotstr));
0052       if (irot != ctxt.rotations.end()) {
0053         rotation = ns.rotation(ns.prepend(rotstr));
0054       } else {
0055         edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular Creating a new "
0056                                         << "rotation: " << rotstr << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0057                                         << convertRadToDeg(phiy) << ", 0, 0";
0058         RotationZYX rot;
0059         rotation = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
0060       }
0061     }
0062 
0063     double xpos = radius * cos(phi) + center[0];
0064     double ypos = radius * sin(phi) + center[1];
0065     double zpos = center[2];
0066     Position tran(xpos, ypos, zpos);
0067     mother.placeVolume(child, copy, Transform3D(rotation, tran));
0068     edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular test " << child.name() << " number " << copy
0069                                     << " positioned in " << mother.name() << " at " << tran << " with " << rotation;
0070     copy += incrCopyNo;
0071     phi += delta;
0072   }
0073   return 1;
0074 }
0075 
0076 // first argument is the type from the xml file
0077 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerAngular, algorithm)