DDTrackerLinear

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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
///////////////////////////////////////////////////////////////////////////////
// File: DDTrackerLinear.cc
// Description: Position n copies at given intervals along an axis
///////////////////////////////////////////////////////////////////////////////

#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 <CLHEP/Units/GlobalPhysicalConstants.h>
#include <CLHEP/Units/SystemOfUnits.h>

#include <string>
#include <vector>

using namespace std;

class DDTrackerLinear : public DDAlgorithm {
public:
  //Constructor and Destructor
  DDTrackerLinear();
  ~DDTrackerLinear() 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:
  string idNameSpace;     //Namespace of this and ALL sub-parts
  string childName;       //Child name
  int number;             //Number of positioning
  int startcn;            //Start copy no index
  int incrcn;             //Increment of copy no.
  double theta;           //Direction of translation
  double phi;             //  ......
  double offset;          //Offset    along (theta,phi) direction
  double delta;           //Increment     ................
  vector<double> centre;  //Centre
  string rotMat;          //Rotation matrix
};

DDTrackerLinear::DDTrackerLinear() : startcn(1), incrcn(1) {
  LogDebug("TrackerGeom") << "DDTrackerLinear info: Creating an instance";
}

DDTrackerLinear::~DDTrackerLinear() {}

void DDTrackerLinear::initialize(const DDNumericArguments& nArgs,
                                 const DDVectorArguments& vArgs,
                                 const DDMapArguments&,
                                 const DDStringArguments& sArgs,
                                 const DDStringVectorArguments&) {
  number = int(nArgs["Number"]);
  theta = nArgs["Theta"];
  phi = nArgs["Phi"];
  offset = nArgs["Offset"];
  delta = nArgs["Delta"];
  centre = vArgs["Center"];
  rotMat = sArgs["Rotation"];
  if (nArgs.find("StartCopyNo") != nArgs.end()) {
    startcn = size_t(nArgs["StartCopyNo"]);
  } else {
    startcn = 1;
  }
  if (nArgs.find("IncrCopyNo") != nArgs.end()) {
    incrcn = int(nArgs["IncrCopyNo"]);
  } else {
    incrcn = 1;
  }

  idNameSpace = DDCurrentNamespace::ns();
  childName = sArgs["ChildName"];
  DDName parentName = parent().name();
  LogDebug("TrackerGeom") << "DDTrackerLinear debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
                          << idNameSpace << "\tNumber " << number << "\tAxis (theta/phi) " << theta / CLHEP::deg << ", "
                          << phi / CLHEP::deg << "\t(Offset/Delta) " << offset << ", " << delta << "\tCentre "
                          << centre[0] << ", " << centre[1] << ", " << centre[2] << "\tRotation " << rotMat;
}

void DDTrackerLinear::execute(DDCompactView& cpv) {
  DDName mother = parent().name();
  DDName child(DDSplit(childName).first, DDSplit(childName).second);
  DDTranslation direction(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
  DDTranslation base(centre[0], centre[1], centre[2]);
  string rotstr = DDSplit(rotMat).first;
  DDRotation rot;
  if (rotstr != "NULL") {
    string rotns = DDSplit(rotMat).second;
    rot = DDRotation(DDName(rotstr, rotns));
  }
  int ci = startcn;
  for (int i = 0; i < number; i++) {
    DDTranslation tran = base + (offset + double(i) * delta) * direction;
    cpv.position(child, mother, ci, tran, rot);
    LogDebug("TrackerGeom") << "DDTrackerLinear test: " << child << " number " << ci << " positioned in " << mother
                            << " at " << tran << " with " << rot;
    ++ci;
  }
}

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