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 namespace {
0012   long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0013     DDNamespace ns(ctxt, e, true);
0014     DDAlgoArguments args(ctxt, e);
0015     Volume mother = ns.volume(args.parentName());
0016     string childName = args.value<string>("ChildName");
0017     Volume child = ns.volume(childName);
0018 
0019     string parentName = args.parentName();
0020     int n = args.value<int>("N");
0021     int startCopyNo = args.value<int>("StartCopyNo");
0022     int incrCopyNo = args.value<int>("IncrCopyNo");
0023     double rangeAngle = args.value<double>("RangeAngle");
0024     double startAngle = args.value<double>("StartAngle");
0025     double radius = args.value<double>("Radius");
0026     vector<double> center = args.value<vector<double> >("Center");
0027     bool isZPlus = args.value<int>("IsZPlus") == 1;
0028     double tiltAngle = args.value<double>("TiltAngle");
0029     bool isFlipped = args.value<int>("IsFlipped") == 1;
0030     double delta = 0.;
0031 
0032     if (abs(rangeAngle - 360.0_deg) < 0.001_deg) {
0033       delta = rangeAngle / double(n);
0034     } else {
0035       if (n > 1) {
0036         delta = rangeAngle / double(n - 1);
0037       } else {
0038         delta = 0.;
0039       }
0040     }
0041 
0042     edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
0043                                     << "ing:: n " << n << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
0044                                     << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(delta) << " Radius "
0045                                     << radius << " Centre " << center[0] << ", " << center[1] << ", " << center[2];
0046 
0047     edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName << "\tChild " << childName
0048                                     << " NameSpace " << ns.name();
0049 
0050     Rotation3D flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix;  // Identity matrix
0051 
0052     // flipMatrix calculus
0053     if (isFlipped) {
0054       edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
0055                                       << "\t90., 180., "
0056                                       << "90., 90., "
0057                                       << "180., 0.";
0058       flipMatrix = makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0._deg);
0059     }
0060     // tiltMatrix calculus
0061     if (isZPlus) {
0062       edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
0063                                       << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
0064                                       << convertRadToDeg(90._deg - tiltAngle) << ", 0.";
0065       tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0._deg);
0066       if (isFlipped) {
0067         tiltMatrix *= flipMatrix;
0068       }
0069     } else {
0070       edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
0071                                       << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
0072                                       << convertRadToDeg(90._deg + tiltAngle) << ", 0.";
0073       tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 0._deg, 90._deg + tiltAngle, 0._deg);
0074       if (isFlipped) {
0075         tiltMatrix *= flipMatrix;
0076       }
0077     }
0078 
0079     // Loops for all phi values
0080     double theta = 90._deg;
0081     int copy = startCopyNo;
0082     double phi = startAngle;
0083 
0084     for (int i = 0; i < n; ++i) {
0085       // phiRotMatrix calculus
0086       double phix = phi;
0087       double phiy = phix + 90._deg;
0088       if (phix != 0.) {
0089         edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
0090                                         << "\t90., " << convertRadToDeg(phix) << ", 90.," << convertRadToDeg(phiy)
0091                                         << ", 0., 0.";
0092         phiRotMatrix = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
0093       }
0094 
0095       globalRotMatrix = phiRotMatrix * tiltMatrix;
0096 
0097       // translation def
0098       double xpos = radius * cos(phi) + center[0];
0099       double ypos = radius * sin(phi) + center[1];
0100       double zpos = center[2];
0101       Position tran(xpos, ypos, zpos);
0102 
0103       // Positions child with respect to parent
0104       mother.placeVolume(child, copy, Transform3D(globalRotMatrix, tran));
0105       edm::LogVerbatim("TrackerGeom") << "DDTrackerRingAlgo test " << child.data()->GetName() << " number " << copy
0106                                       << " positioned in " << mother.data()->GetName() << " at " << tran << " with "
0107                                       << globalRotMatrix;
0108 
0109       copy += incrCopyNo;
0110       phi += delta;
0111     }
0112     return s_executed;
0113   }
0114 }  // namespace
0115 // first argument is the type from the xml file
0116 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerRingAlgo, ::algorithm)