Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-12 09:07:39

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTrackerIrregularRingAlgo.cc
0003 // Description:  Tilts and positions n copies of a module at prescribed phi
0004 // values within a ring. The module can also be flipped if requested.
0005 ///////////////////////////////////////////////////////////////////////////////
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0009 #include "DetectorDescription/Core/interface/DDSplit.h"
0010 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0011 #include "DetectorDescription/Core/interface/DDTransform.h"
0012 #include "DetectorDescription/Core/interface/DDTypes.h"
0013 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0014 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0015 #include "DataFormats/Math/interface/angle_units.h"
0016 
0017 #include <string>
0018 #include <vector>
0019 
0020 /*
0021   Tilts and positions n copies of a module at prescribed phi values
0022   within a ring. The module can also be flipped if requested.
0023 
0024   (radius, Phi, Z) refers to the cylindrical coordinates in the global frame of reference.
0025   
0026   A module's tilt angle is defined with respect to the global frame of reference's Z axis.
0027   Example, in the outer tracker : For a straight barrel module, tiltAngle = 0°.
0028   For a module in the endcaps, tiltAngle = 90°.
0029   tiltAngle ∈ [0, 90°].
0030   Please note that parameter tiltAngle has to be set regardless of any sign consideration,
0031   to the absolute value of the module's tilt angle.
0032 
0033   == Example of use : ==
0034 
0035   <Algorithm name="track:DDTrackerIrregularRingAlgo">
0036   <rParent name="tracker:Ring5Layer1Plus"/>
0037   <String name="ChildName" value="tracker:BModule5Layer1"/>
0038   <Numeric name="N" value="9"/>
0039   <Numeric name="StartCopyNo" value="1"/>
0040   <Numeric name="IncrCopyNo" value="2"/>
0041   <Numeric name="RangeAngle" value="360*deg"/>
0042   <Numeric name="StartAngle" value="90*deg"/>
0043   <Numeric name="Radius" value="247"/>
0044   <Vector name="Center" type="numeric" nEntries="3">0,0,-5.45415</Vector>
0045   <Numeric name="IsZPlus" value="1"/>
0046   <Numeric name="TiltAngle" value="47*deg"/>
0047   <Numeric name="IsFlipped" value="1"/>
0048   </Algorithm>
0049 */
0050 
0051 using namespace std;
0052 using namespace angle_units::operators;
0053 
0054 class DDTrackerIrregularRingAlgo : public DDAlgorithm {
0055 public:
0056   // Constructor and Destructor
0057   DDTrackerIrregularRingAlgo();
0058   ~DDTrackerIrregularRingAlgo() override;
0059 
0060   void initialize(const DDNumericArguments& nArgs,
0061                   const DDVectorArguments& vArgs,
0062                   const DDMapArguments& mArgs,
0063                   const DDStringArguments& sArgs,
0064                   const DDStringVectorArguments& vsArgs) override;
0065 
0066   void execute(DDCompactView& cpv) override;
0067 
0068 private:
0069   int n;                  //Number of copies
0070   int startCopyNo;        //Start Copy number
0071   int incrCopyNo;         //Increment in Copy number
0072   double rangeAngle;      //Range in Phi angle
0073   double startAngle;      //Start Phi angle
0074   double radius;          //Radius
0075   vector<double> center;  //Phi values
0076   vector<double> phiAngles;
0077   vector<double> radiusValues;
0078   vector<double> yawAngles;
0079   bool isZPlus;      //Is Z positive ?
0080   double tiltAngle;  //Module's tilt angle (absolute value)
0081   bool isFlipped;    //Is the module flipped ?
0082 
0083   string idNameSpace;  //Namespace of this and ALL sub-parts
0084   string childName;    //Child name
0085 };
0086 
0087 DDTrackerIrregularRingAlgo::DDTrackerIrregularRingAlgo() {
0088   LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo info: Creating an instance";
0089 }
0090 
0091 DDTrackerIrregularRingAlgo::~DDTrackerIrregularRingAlgo() = default;
0092 
0093 void DDTrackerIrregularRingAlgo::initialize(const DDNumericArguments& nArgs,
0094                                             const DDVectorArguments& vArgs,
0095                                             const DDMapArguments&,
0096                                             const DDStringArguments& sArgs,
0097                                             const DDStringVectorArguments&) {
0098   n = int(nArgs["N"]);
0099   startCopyNo = int(nArgs["StartCopyNo"]);
0100   incrCopyNo = int(nArgs["IncrCopyNo"]);
0101   rangeAngle = nArgs["RangeAngle"];
0102   startAngle = nArgs["StartAngle"];
0103   radius = nArgs["Radius"];
0104   center = vArgs["Center"];
0105   yawAngles = vArgs["yawAngleValues"];
0106   phiAngles = vArgs["phiAngleValues"];
0107   radiusValues = vArgs["radiusValues"];
0108   isZPlus = bool(nArgs["IsZPlus"]);
0109   tiltAngle = nArgs["TiltAngle"];
0110   isFlipped = bool(nArgs["IsFlipped"]);
0111 
0112   LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parameters for position"
0113                           << "ing:: n " << n << " Start, Range " << convertRadToDeg(startAngle) << " "
0114                           << convertRadToDeg(rangeAngle) << " Radius " << radius << " Centre " << center[0] << ", "
0115                           << center[1] << ", " << center[2];
0116 
0117   idNameSpace = DDCurrentNamespace::ns();
0118   childName = sArgs["ChildName"];
0119 
0120   DDName parentName = parent().name();
0121   LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parent " << parentName << "\tChild " << childName
0122                           << " NameSpace " << idNameSpace;
0123 }
0124 
0125 void DDTrackerIrregularRingAlgo::execute(DDCompactView& cpv) {
0126   DDRotation flipRot, tiltRot, phiOwnAxisRot, phiRot, globalRot;                                // Identity
0127   DDRotationMatrix flipMatrix, tiltMatrix, phiOwnAxisRotMatrix, phiRotMatrix, globalRotMatrix;  // Identity matrix
0128   string rotstr = "RTrackerRingAlgo";
0129 
0130   // flipMatrix calculus
0131   if (isFlipped) {
0132     string flipRotstr = rotstr + "Flip";
0133     flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
0134     if (!flipRot) {
0135       LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << flipRotstr
0136                               << "\t90., 180., "
0137                               << "90., 90., "
0138                               << "180., 0.";
0139       flipRot = DDrot(DDName(flipRotstr, idNameSpace), 90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0.);
0140     }
0141     flipMatrix = flipRot.matrix();
0142   }
0143   // tiltMatrix calculus
0144   if (isZPlus) {
0145     string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZPlus";
0146     tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0147     if (!tiltRot) {
0148       LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
0149                               << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
0150                               << 90. - convertRadToDeg(tiltAngle) << ", 0.";
0151       tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0.);
0152     }
0153     tiltMatrix = tiltRot.matrix();
0154     if (isFlipped) {
0155       tiltMatrix *= flipMatrix;
0156     }
0157   } else {
0158     string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZMinus";
0159     tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0160     if (!tiltRot) {
0161       LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
0162                               << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
0163                               << 90. + convertRadToDeg(tiltAngle) << ", 0.";
0164       tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 0., 90._deg + tiltAngle, 0.);
0165     }
0166     tiltMatrix = tiltRot.matrix();
0167     if (isFlipped) {
0168       tiltMatrix *= flipMatrix;
0169     }
0170   }
0171 
0172   // Loops for all phi values
0173   DDName mother = parent().name();
0174   DDName child(DDSplit(childName).first, DDSplit(childName).second);
0175   double theta = 90._deg;
0176   int copy = startCopyNo;
0177   //double phi = startAngle;
0178 
0179   for (int i = 0; i < n; i++) {
0180     // phiRotMatrix calculus
0181     //double phix = phi;
0182     //double phix_ownaxis = 0._deg;
0183     double phix = convertDegToRad(phiAngles.at(i));
0184     double phix_ownaxis = convertDegToRad(yawAngles.at(i));
0185     radius = radiusValues.at(i);
0186     double phiy = phix + 90._deg;
0187     double phiy_ownaxis = phix_ownaxis + 90._deg;
0188     double phideg = convertRadToDeg(phix);
0189     double phideg_ownaxis = convertRadToDeg(phix_ownaxis);
0190     if (phideg_ownaxis != 0) {
0191       string phiOwnAxisRotstr = rotstr + "PhiOwnAxis" + to_string(phideg_ownaxis * 10.);
0192       phiOwnAxisRot = DDRotation(DDName(phiOwnAxisRotstr, idNameSpace));
0193       if (!phiOwnAxisRot) {
0194         LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiOwnAxisRotstr
0195                                 << "\t90., " << convertRadToDeg(phix_ownaxis) << ", 90.,"
0196                                 << convertRadToDeg(phiy_ownaxis) << ", 0., 0.";
0197         phiOwnAxisRot = DDrot(DDName(phiOwnAxisRotstr, idNameSpace), theta, phix_ownaxis, theta, phiy_ownaxis, 0., 0.);
0198       }
0199       phiOwnAxisRotMatrix = phiOwnAxisRot.matrix();
0200     }
0201     if (phideg != 0) {
0202       string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
0203       phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
0204       if (!phiRot) {
0205         LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiRotstr
0206                                 << "\t90., " << convertRadToDeg(phix) << ", 90.," << convertRadToDeg(phiy)
0207                                 << ", 0., 0.";
0208         phiRot = DDrot(DDName(phiRotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
0209       }
0210       phiRotMatrix = phiRot.matrix();
0211     }
0212 
0213     // globalRot def
0214     string globalRotstr = rotstr + "Phi" + to_string(phideg * 10.) + "Tilt" + to_string(convertRadToDeg(tiltAngle));
0215     if (isZPlus) {
0216       globalRotstr += "ZPlus";
0217       if (isFlipped) {
0218         globalRotstr += "Flip";
0219       }
0220     } else {
0221       globalRotstr += "ZMinus";
0222       if (isFlipped) {
0223         globalRotstr += "Flip";
0224       }
0225     }
0226     globalRot = DDRotation(DDName(globalRotstr, idNameSpace));
0227     if (!globalRot) {
0228       LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new "
0229                               << "rotation: " << globalRotstr;
0230       globalRotMatrix = phiOwnAxisRotMatrix * phiRotMatrix * tiltMatrix;
0231       globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
0232     }
0233 
0234     // translation def
0235     double xpos = radius * cos(phix) + center[0];
0236     double ypos = radius * sin(phix) + center[1];
0237     double zpos = center[2];
0238     DDTranslation tran(xpos, ypos, zpos);
0239 
0240     // Positions child with respect to parent
0241     cpv.position(child, mother, copy, tran, globalRot);
0242     LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test " << child << " number " << copy << " positioned in "
0243                             << mother << " at " << tran << " with " << globalRot;
0244 
0245     copy += incrCopyNo;
0246   }
0247 }
0248 
0249 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerIrregularRingAlgo, "track:DDTrackerIrregularRingAlgo");