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     vector<double> phiAngles = args.value<vector<double> >("phiAngleValues");
0028     vector<double> radiusValues = args.value<vector<double> >("radiusValues");
0029     vector<double> yawAngles = args.value<vector<double> >("yawAngleValues");
0030     bool isZPlus = args.value<int>("IsZPlus") == 1;
0031     double tiltAngle = args.value<double>("TiltAngle");
0032     bool isFlipped = args.value<int>("IsFlipped") == 1;
0033 
0034     edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parameters for position"
0035                                     << "ing:: n " << n << " Start, Range " << convertRadToDeg(startAngle) << " "
0036                                     << convertRadToDeg(rangeAngle) << " Radius " << radius << " Centre " << center[0]
0037                                     << ", " << center[1] << ", " << center[2];
0038 
0039     edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parent " << parentName << "\tChild "
0040                                     << childName << " NameSpace " << ns.name();
0041 
0042     Rotation3D flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix, phiOwnAxisRotMatrix;  // Identity matrix
0043 
0044     // flipMatrix calculus
0045     if (isFlipped) {
0046       edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
0047                                       << "\t90., 180., "
0048                                       << "90., 90., "
0049                                       << "180., 0.";
0050       flipMatrix = makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0._deg);
0051     }
0052     // tiltMatrix calculus
0053     if (isZPlus) {
0054       edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
0055                                       << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
0056                                       << convertRadToDeg(90._deg - tiltAngle) << ", 0.";
0057       tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0._deg);
0058       if (isFlipped) {
0059         tiltMatrix *= flipMatrix;
0060       }
0061     } else {
0062       edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
0063                                       << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
0064                                       << convertRadToDeg(90._deg + tiltAngle) << ", 0.";
0065       tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 0._deg, 90._deg + tiltAngle, 0._deg);
0066       if (isFlipped) {
0067         tiltMatrix *= flipMatrix;
0068       }
0069     }
0070 
0071     // Loops for all phi values
0072     double theta = 90._deg;
0073     int copy = startCopyNo;
0074 
0075     for (int i = 0; i < n; ++i) {
0076       // phiRotMatrix calculus
0077       double phix = convertDegToRad(phiAngles.at(i));
0078       double phix_ownaxis = convertDegToRad(yawAngles.at(i));
0079       radius = radiusValues.at(i);
0080       double phiy = phix + 90._deg;
0081       double phiy_ownaxis = phix_ownaxis + 90._deg;
0082       if (phix_ownaxis != 0.) {
0083         LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
0084                                 << "\t90., " << convertRadToDeg(phix_ownaxis) << ", 90.,"
0085                                 << convertRadToDeg(phiy_ownaxis) << ", 0., 0.";
0086         phiOwnAxisRotMatrix = makeRotation3D(theta, phix_ownaxis, theta, phiy_ownaxis, 0., 0.);
0087       }
0088       if (phix != 0.) {
0089         edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo 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 = phiOwnAxisRotMatrix * phiRotMatrix * tiltMatrix;
0096 
0097       // translation def
0098       double xpos = radius * cos(phix) + center[0];
0099       double ypos = radius * sin(phix) + 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") << "DDTrackerIrregularRingAlgo test " << child.data()->GetName() << " number "
0106                                       << copy << " positioned in " << mother.data()->GetName() << " at " << tran
0107                                       << " with " << globalRotMatrix;
0108 
0109       copy += incrCopyNo;
0110     }
0111     return s_executed;
0112   }
0113 }  // namespace
0114 // first argument is the type from the xml file
0115 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerIrregularRingAlgo, ::algorithm)