DDTrackerZPosAlgo

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
///////////////////////////////////////////////////////////////////////////////
// File: DDTrackerZPosAlgo.cc
// Description: Position n copies at given z-values
///////////////////////////////////////////////////////////////////////////////

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
#include "DetectorDescription/Core/interface/DDSplit.h"
#include "DetectorDescription/Core/interface/DDTypes.h"
#include "DetectorDescription/Core/interface/DDAlgorithm.h"
#include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"

#include <string>
#include <vector>

using namespace std;

class DDTrackerZPosAlgo : public DDAlgorithm {
public:
  //Constructor and Destructor
  DDTrackerZPosAlgo();
  ~DDTrackerZPosAlgo() override;

  void initialize(const DDNumericArguments& nArgs,
                  const DDVectorArguments& vArgs,
                  const DDMapArguments& mArgs,
                  const DDStringArguments& sArgs,
                  const DDStringVectorArguments& vsArgs) override;

  void execute(DDCompactView& cpv) override;

private:
  vector<double> zvec;    //Z positions
  vector<string> rotMat;  //Names of rotation matrices

  string idNameSpace;  //Namespace of this and ALL sub-parts
  string childName;    //Child name
  int startCopyNo;     //Start Copy number
  int incrCopyNo;      //Increment in Copy number
};

DDTrackerZPosAlgo::DDTrackerZPosAlgo() { LogDebug("TrackerGeom") << "DDTrackerZPosAlgo info: Creating an instance"; }

DDTrackerZPosAlgo::~DDTrackerZPosAlgo() {}

void DDTrackerZPosAlgo::initialize(const DDNumericArguments& nArgs,
                                   const DDVectorArguments& vArgs,
                                   const DDMapArguments&,
                                   const DDStringArguments& sArgs,
                                   const DDStringVectorArguments& vsArgs) {
  startCopyNo = int(nArgs["StartCopyNo"]);
  incrCopyNo = int(nArgs["IncrCopyNo"]);
  zvec = vArgs["ZPositions"];
  rotMat = vsArgs["Rotations"];

  idNameSpace = DDCurrentNamespace::ns();
  childName = sArgs["ChildName"];
  DDName parentName = parent().name();
  LogDebug("TrackerGeom") << "DDTrackerZPosAlgo debug: Parent " << parentName << "\tChild " << childName
                          << " NameSpace " << idNameSpace << "\tCopyNo (Start/Increment) " << startCopyNo << ", "
                          << incrCopyNo << "\tNumber " << zvec.size();
  for (int i = 0; i < (int)(zvec.size()); i++) {
    LogDebug("TrackerGeom") << "\t[" << i << "]\tZ = " << zvec[i] << ", Rot.Matrix = " << rotMat[i];
  }
}

void DDTrackerZPosAlgo::execute(DDCompactView& cpv) {
  int copy = startCopyNo;
  DDName mother = parent().name();
  DDName child(DDSplit(childName).first, DDSplit(childName).second);

  for (int i = 0; i < (int)(zvec.size()); i++) {
    DDTranslation tran(0, 0, zvec[i]);
    string rotstr = DDSplit(rotMat[i]).first;
    DDRotation rot;
    if (rotstr != "NULL") {
      string rotns = DDSplit(rotMat[i]).second;
      rot = DDRotation(DDName(rotstr, rotns));
    }
    cpv.position(child, mother, copy, tran, rot);
    LogDebug("TrackerGeom") << "DDTrackerZPosAlgo test: " << child << " number " << copy << " positioned in " << mother
                            << " at " << tran << " with " << rot;
    copy += incrCopyNo;
  }
}

DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerZPosAlgo, "track:DDTrackerZPosAlgo");