Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:20:54

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTECPhiAlgo.cc
0003 // Description: Position n copies inside and outside Z at alternate phi values
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTypes.h"
0010 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0012 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0013 #include <CLHEP/Units/SystemOfUnits.h>
0014 
0015 #include <cmath>
0016 #include <algorithm>
0017 #include <map>
0018 #include <string>
0019 #include <vector>
0020 
0021 using namespace std;
0022 
0023 class DDTECPhiAlgo : public DDAlgorithm {
0024 public:
0025   //Constructor and Destructor
0026   DDTECPhiAlgo();
0027   ~DDTECPhiAlgo() override;
0028 
0029   void initialize(const DDNumericArguments& nArgs,
0030                   const DDVectorArguments& vArgs,
0031                   const DDMapArguments& mArgs,
0032                   const DDStringArguments& sArgs,
0033                   const DDStringVectorArguments& vsArgs) override;
0034 
0035   void execute(DDCompactView& cpv) override;
0036 
0037 private:
0038   double startAngle;  //Start angle
0039   double incrAngle;   //Increment in angle
0040   double zIn;         //z position for the even ones
0041   double zOut;        //z position for the odd  ones
0042   int number;         //Number of copies
0043   int startCopyNo;    //Start copy number
0044   int incrCopyNo;     //Increment in copy number
0045 
0046   string idNameSpace;  //Namespace of this and ALL sub-parts
0047   string childName;    //Child name
0048 };
0049 
0050 DDTECPhiAlgo::DDTECPhiAlgo() { LogDebug("TECGeom") << "DDTECPhiAlgo info: Creating an instance"; }
0051 
0052 DDTECPhiAlgo::~DDTECPhiAlgo() {}
0053 
0054 void DDTECPhiAlgo::initialize(const DDNumericArguments& nArgs,
0055                               const DDVectorArguments&,
0056                               const DDMapArguments&,
0057                               const DDStringArguments& sArgs,
0058                               const DDStringVectorArguments&) {
0059   startAngle = nArgs["StartAngle"];
0060   incrAngle = nArgs["IncrAngle"];
0061   zIn = nArgs["ZIn"];
0062   zOut = nArgs["ZOut"];
0063   number = int(nArgs["Number"]);
0064   startCopyNo = int(nArgs["StartCopyNo"]);
0065   incrCopyNo = int(nArgs["IncrCopyNo"]);
0066 
0067   LogDebug("TECGeom") << "DDTECPhiAlgo debug: Parameters for "
0068                       << "positioning--"
0069                       << "\tStartAngle " << startAngle / CLHEP::deg << "\tIncrAngle " << incrAngle / CLHEP::deg
0070                       << "\tZ in/out " << zIn << ", " << zOut << "\tCopy Numbers " << number << " Start/Increment "
0071                       << startCopyNo << ", " << incrCopyNo;
0072 
0073   idNameSpace = DDCurrentNamespace::ns();
0074   childName = sArgs["ChildName"];
0075   DDName parentName = parent().name();
0076   LogDebug("TECGeom") << "DDTECPhiAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
0077                       << idNameSpace;
0078 }
0079 
0080 void DDTECPhiAlgo::execute(DDCompactView& cpv) {
0081   if (number > 0) {
0082     double theta = 90. * CLHEP::deg;
0083     int copyNo = startCopyNo;
0084 
0085     DDName mother = parent().name();
0086     DDName child(DDSplit(childName).first, DDSplit(childName).second);
0087     for (int i = 0; i < number; i++) {
0088       double phix = startAngle + i * incrAngle;
0089       double phiy = phix + 90. * CLHEP::deg;
0090       double phideg = phix / CLHEP::deg;
0091 
0092       DDRotation rotation;
0093       string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
0094       rotation = DDRotation(DDName(rotstr, idNameSpace));
0095       if (!rotation) {
0096         LogDebug("TECGeom") << "DDTECPhiAlgo test: Creating a new "
0097                             << "rotation " << rotstr << "\t" << theta / CLHEP::deg << ", " << phix / CLHEP::deg << ", "
0098                             << theta / CLHEP::deg << ", " << phiy / CLHEP::deg << ", 0, 0";
0099         rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
0100       }
0101 
0102       double zpos = zOut;
0103       if (i % 2 == 0)
0104         zpos = zIn;
0105       DDTranslation tran(0., 0., zpos);
0106 
0107       cpv.position(child, mother, copyNo, tran, rotation);
0108       LogDebug("TECGeom") << "DDTECPhiAlgo test: " << child << " number " << copyNo << " positioned in " << mother
0109                           << " at " << tran << " with " << rotation;
0110       copyNo += incrCopyNo;
0111     }
0112   }
0113 }
0114 
0115 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECPhiAlgo, "track:DDTECPhiAlgo");