Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:05:22

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTrackerXYZPosAlgo.cc
0003 // Description: Position n copies at given x-values, y-values and z-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 
0013 #include <string>
0014 #include <vector>
0015 
0016 using namespace std;
0017 
0018 class DDTrackerXYZPosAlgo : public DDAlgorithm {
0019 public:
0020   //Constructor and Destructor
0021   DDTrackerXYZPosAlgo();
0022   ~DDTrackerXYZPosAlgo() override;
0023 
0024   void initialize(const DDNumericArguments& nArgs,
0025                   const DDVectorArguments& vArgs,
0026                   const DDMapArguments& mArgs,
0027                   const DDStringArguments& sArgs,
0028                   const DDStringVectorArguments& vsArgs) override;
0029 
0030   void execute(DDCompactView& cpv) override;
0031 
0032 private:
0033   vector<double> xvec;    //X positions
0034   vector<double> yvec;    //Y positions
0035   vector<double> zvec;    //Z positions
0036   vector<string> rotMat;  //Names of rotation matrices
0037 
0038   string idNameSpace;  //Namespace of this and ALL sub-parts
0039   string childName;    //Child name
0040   int startCopyNo;     //Start Copy number
0041   int incrCopyNo;      //Increment in Copy number
0042 };
0043 
0044 DDTrackerXYZPosAlgo::DDTrackerXYZPosAlgo() {
0045   LogDebug("TrackerGeom") << "DDTrackerXYZPosAlgo info: Creating an instance";
0046 }
0047 
0048 DDTrackerXYZPosAlgo::~DDTrackerXYZPosAlgo() {}
0049 
0050 void DDTrackerXYZPosAlgo::initialize(const DDNumericArguments& nArgs,
0051                                      const DDVectorArguments& vArgs,
0052                                      const DDMapArguments&,
0053                                      const DDStringArguments& sArgs,
0054                                      const DDStringVectorArguments& vsArgs) {
0055   startCopyNo = int(nArgs["StartCopyNo"]);
0056   incrCopyNo = int(nArgs["IncrCopyNo"]);
0057   xvec = vArgs["XPositions"];
0058   yvec = vArgs["YPositions"];
0059   zvec = vArgs["ZPositions"];
0060   rotMat = vsArgs["Rotations"];
0061 
0062   idNameSpace = DDCurrentNamespace::ns();
0063   childName = sArgs["ChildName"];
0064   DDName parentName = parent().name();
0065   LogDebug("TrackerGeom") << "DDTrackerXYZPosAlgo debug: Parent " << parentName << "\tChild " << childName
0066                           << " NameSpace " << idNameSpace << "\tCopyNo (Start/Increment) " << startCopyNo << ", "
0067                           << incrCopyNo << "\tNumber " << xvec.size() << ", " << yvec.size() << ", " << zvec.size();
0068   for (int i = 0; i < (int)(zvec.size()); i++) {
0069     LogDebug("TrackerGeom") << "\t[" << i << "]\tX = " << xvec[i] << "\t[" << i << "]\tY = " << yvec[i] << "\t[" << i
0070                             << "]\tZ = " << zvec[i] << ", Rot.Matrix = " << rotMat[i];
0071   }
0072 }
0073 
0074 void DDTrackerXYZPosAlgo::execute(DDCompactView& cpv) {
0075   int copy = startCopyNo;
0076   DDName mother = parent().name();
0077   DDName child(DDSplit(childName).first, DDSplit(childName).second);
0078 
0079   for (int i = 0; i < (int)(zvec.size()); i++) {
0080     DDTranslation tran(xvec[i], yvec[i], zvec[i]);
0081     string rotstr = DDSplit(rotMat[i]).first;
0082     DDRotation rot;
0083     if (rotstr != "NULL") {
0084       string rotns = DDSplit(rotMat[i]).second;
0085       rot = DDRotation(DDName(rotstr, rotns));
0086     }
0087     cpv.position(child, mother, copy, tran, rot);
0088     LogDebug("TrackerGeom") << "DDTrackerXYZPosAlgo test: " << child << " number " << copy << " positioned in "
0089                             << mother << " at " << tran << " with " << rot;
0090     copy += incrCopyNo;
0091   }
0092 }
0093 
0094 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerXYZPosAlgo, "track:DDTrackerXYZPosAlgo");