Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:03

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTrackerRingAlgo.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 "CLHEP/Units/GlobalPhysicalConstants.h"
0016 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0017 
0018 #include <string>
0019 #include <vector>
0020 
0021 /*
0022   Tilts and positions n copies of a module at prescribed phi values
0023   within a ring. The module can also be flipped if requested.
0024 
0025   (radius, Phi, Z) refers to the cylindrical coordinates in the global frame of reference.
0026   
0027   A module's tilt angle is defined with respect to the global frame of reference's Z axis.
0028   Example, in the outer tracker : For a straight barrel module, tiltAngle = 0°.
0029   For a module in the endcaps, tiltAngle = 90°.
0030   tiltAngle ∈ [0, 90°].
0031   Please note that parameter tiltAngle has to be set regardless of any sign consideration,
0032   to the absolute value of the module's tilt angle.
0033 
0034   == Example of use : ==
0035 
0036   <Algorithm name="track:DDTrackerRingAlgo">
0037   <rParent name="tracker:Ring5Layer1Plus"/>
0038   <String name="ChildName" value="tracker:BModule5Layer1"/>
0039   <Numeric name="N" value="9"/>
0040   <Numeric name="StartCopyNo" value="1"/>
0041   <Numeric name="IncrCopyNo" value="2"/>
0042   <Numeric name="RangeAngle" value="360*deg"/>
0043   <Numeric name="StartAngle" value="90*deg"/>
0044   <Numeric name="Radius" value="247"/>
0045   <Vector name="Center" type="numeric" nEntries="3">0,0,-5.45415</Vector>
0046   <Numeric name="IsZPlus" value="1"/>
0047   <Numeric name="TiltAngle" value="47*deg"/>
0048   <Numeric name="IsFlipped" value="1"/>
0049   </Algorithm>
0050 */
0051 
0052 using namespace std;
0053 
0054 class DDTrackerRingAlgo : public DDAlgorithm {
0055 public:
0056   // Constructor and Destructor
0057   DDTrackerRingAlgo();
0058   ~DDTrackerRingAlgo() 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   bool isZPlus;           //Is Z positive ?
0077   double tiltAngle;       //Module's tilt angle (absolute value)
0078   bool isFlipped;         //Is the module flipped ?
0079   double delta;           //Increment in Phi
0080 
0081   string idNameSpace;  //Namespace of this and ALL sub-parts
0082   string childName;    //Child name
0083 };
0084 
0085 DDTrackerRingAlgo::DDTrackerRingAlgo() { LogDebug("TrackerGeom") << "DDTrackerRingAlgo info: Creating an instance"; }
0086 
0087 DDTrackerRingAlgo::~DDTrackerRingAlgo() {}
0088 
0089 void DDTrackerRingAlgo::initialize(const DDNumericArguments& nArgs,
0090                                    const DDVectorArguments& vArgs,
0091                                    const DDMapArguments&,
0092                                    const DDStringArguments& sArgs,
0093                                    const DDStringVectorArguments&) {
0094   n = int(nArgs["N"]);
0095   startCopyNo = int(nArgs["StartCopyNo"]);
0096   incrCopyNo = int(nArgs["IncrCopyNo"]);
0097   rangeAngle = nArgs["RangeAngle"];
0098   startAngle = nArgs["StartAngle"];
0099   radius = nArgs["Radius"];
0100   center = vArgs["Center"];
0101   isZPlus = bool(nArgs["IsZPlus"]);
0102   tiltAngle = nArgs["TiltAngle"];
0103   isFlipped = bool(nArgs["IsFlipped"]);
0104 
0105   if (fabs(rangeAngle - 360.0 * CLHEP::deg) < 0.001 * CLHEP::deg) {
0106     delta = rangeAngle / double(n);
0107   } else {
0108     if (n > 1) {
0109       delta = rangeAngle / double(n - 1);
0110     } else {
0111       delta = 0.;
0112     }
0113   }
0114 
0115   LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
0116                           << "ing:: n " << n << " Start, Range, Delta " << startAngle / CLHEP::deg << " "
0117                           << rangeAngle / CLHEP::deg << " " << delta / CLHEP::deg << " Radius " << radius << " Centre "
0118                           << center[0] << ", " << center[1] << ", " << center[2];
0119 
0120   idNameSpace = DDCurrentNamespace::ns();
0121   childName = sArgs["ChildName"];
0122 
0123   DDName parentName = parent().name();
0124   LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName << "\tChild " << childName
0125                           << " NameSpace " << idNameSpace;
0126 }
0127 
0128 void DDTrackerRingAlgo::execute(DDCompactView& cpv) {
0129   DDRotation flipRot, tiltRot, phiRot, globalRot;                          // Identity
0130   DDRotationMatrix flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix;  // Identity matrix
0131   string rotstr = "RTrackerRingAlgo";
0132 
0133   // flipMatrix calculus
0134   if (isFlipped) {
0135     string flipRotstr = rotstr + "Flip";
0136     flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
0137     if (!flipRot) {
0138       LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << flipRotstr << "\t90., 180., "
0139                               << "90., 90., "
0140                               << "180., 0.";
0141       flipRot = DDrot(DDName(flipRotstr, idNameSpace),
0142                       90. * CLHEP::deg,
0143                       180. * CLHEP::deg,
0144                       90. * CLHEP::deg,
0145                       90. * CLHEP::deg,
0146                       180. * CLHEP::deg,
0147                       0.);
0148     }
0149     flipMatrix = flipRot.matrix();
0150   }
0151   // tiltMatrix calculus
0152   if (isZPlus) {
0153     string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZPlus";
0154     tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0155     if (!tiltRot) {
0156       LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
0157                               << tiltAngle / CLHEP::deg << ", 180., " << 90. - tiltAngle / CLHEP::deg << ", 0.";
0158       tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
0159                       90. * CLHEP::deg,
0160                       90. * CLHEP::deg,
0161                       tiltAngle,
0162                       180. * CLHEP::deg,
0163                       90. * CLHEP::deg - tiltAngle,
0164                       0.);
0165     }
0166     tiltMatrix = tiltRot.matrix();
0167     if (isFlipped) {
0168       tiltMatrix *= flipMatrix;
0169     }
0170   } else {
0171     string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZMinus";
0172     tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0173     if (!tiltRot) {
0174       LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
0175                               << tiltAngle / CLHEP::deg << ", 0., " << 90. + tiltAngle / CLHEP::deg << ", 0.";
0176       tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
0177                       90. * CLHEP::deg,
0178                       90. * CLHEP::deg,
0179                       tiltAngle,
0180                       0.,
0181                       90. * CLHEP::deg + tiltAngle,
0182                       0.);
0183     }
0184     tiltMatrix = tiltRot.matrix();
0185     if (isFlipped) {
0186       tiltMatrix *= flipMatrix;
0187     }
0188   }
0189 
0190   // Loops for all phi values
0191   DDName mother = parent().name();
0192   DDName child(DDSplit(childName).first, DDSplit(childName).second);
0193   double theta = 90. * CLHEP::deg;
0194   int copy = startCopyNo;
0195   double phi = startAngle;
0196 
0197   for (int i = 0; i < n; i++) {
0198     // phiRotMatrix calculus
0199     double phix = phi;
0200     double phiy = phix + 90. * CLHEP::deg;
0201     double phideg = phix / CLHEP::deg;
0202     if (phideg != 0) {
0203       string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
0204       phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
0205       if (!phiRot) {
0206         LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << phiRotstr << "\t90., "
0207                                 << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 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(tiltAngle / CLHEP::deg);
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") << "DDTrackerRingAlgo test: Creating a new "
0229                               << "rotation: " << globalRotstr;
0230       globalRotMatrix = phiRotMatrix * tiltMatrix;
0231       globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
0232     }
0233 
0234     // translation def
0235     double xpos = radius * cos(phi) + center[0];
0236     double ypos = radius * sin(phi) + 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") << "DDTrackerRingAlgo test " << child << " number " << copy << " positioned in " << mother
0243                             << " at " << tran << " with " << globalRot;
0244 
0245     copy += incrCopyNo;
0246     phi += delta;
0247   }
0248 }
0249 
0250 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerRingAlgo, "track:DDTrackerRingAlgo");