CMS 3D CMS Logo

DDPixFwdDiskAlgo.cc
Go to the documentation of this file.
1 // File: DDPixFwdDiskAlgo.cc
3 // Description: Position n copies at given z-values
5 
12 #include "CLHEP/Units/PhysicalConstants.h"
13 #include "CLHEP/Units/SystemOfUnits.h"
14 
15 #include <cmath>
16 #include <algorithm>
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 using namespace std;
22 
23 class DDPixFwdDiskAlgo : public DDAlgorithm {
24 public:
25  //Constructor and Destructor
27  ~DDPixFwdDiskAlgo() override;
28 
29  void initialize(const DDNumericArguments& nArgs,
30  const DDVectorArguments& vArgs,
31  const DDMapArguments& mArgs,
32  const DDStringArguments& sArgs,
33  const DDStringVectorArguments& vsArgs) override;
34 
35  void execute(DDCompactView& cpv) override;
36 
37 private:
38  string idNameSpace; //Namespace of this and ALL sub-parts
39  string childName; //Child name
40  string rotName; //Name of the base rotation matrix
41  string flagString; //Flag if a blade is present
42  int nBlades; //Number of blades
43  int startCopyNo; //Start Copy number
44  double bladeAngle; //Angle of blade rotation aroung y-axis
45  double zPlane; //Common shift in z for all blades
46  vector<double> bladeZShift; //Shift in Z of individual blades
47  double anchorR; //Distance of beam line to anchor point
48  double bladeTilt; //Tilt of the blade around x-axis
49 };
50 
51 DDPixFwdDiskAlgo::DDPixFwdDiskAlgo() { LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo info: Creating an instance"; }
52 
54 
56  const DDVectorArguments& vArgs,
57  const DDMapArguments&,
58  const DDStringArguments& sArgs,
59  const DDStringVectorArguments& vsArgs) {
60  startCopyNo = int(nArgs["StartCopyNo"]);
61  nBlades = int(nArgs["NumberOfBlades"]);
62  bladeAngle = nArgs["BladeAngle"];
63  bladeTilt = nArgs["BladeTilt"];
64  zPlane = nArgs["BladeCommonZ"];
65  bladeZShift = vArgs["BladeZShift"];
66  anchorR = nArgs["AnchorRadius"];
67 
68  idNameSpace = DDCurrentNamespace::ns();
69  childName = sArgs["ChildName"];
70  rotName = sArgs["RotationName"];
71  flagString = sArgs["FlagString"];
72  DDName parentName = parent().name();
73  LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
74  << idNameSpace << "\tRot Name " << rotName << "\tCopyNo (Start/Total) " << startCopyNo << ", "
75  << nBlades << "\tAngles " << bladeAngle / CLHEP::deg << ", " << bladeTilt / CLHEP::deg
76  << "\tZshifts " << zPlane << "\tAmnchor Radius " << anchorR;
77 
78  for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
79  LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo: Blade " << iBlade << " flag " << flagString[iBlade] << " zshift "
80  << bladeZShift[iBlade];
81  }
82 }
83 
85  int copy = startCopyNo;
86  DDName mother = parent().name();
87  DDName child(DDSplit(childName).first, DDSplit(childName).second);
88  string flagSelector = "Y";
89 
90  double deltaPhi = (360. / nBlades) * CLHEP::deg;
91  string rotns = DDSplit(rotName).second;
92  for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
93  if (flagString[iBlade] == flagSelector[0]) {
94  string rotstr = DDSplit(rotName).first + to_string(double(copy));
95 
96  double phi = (iBlade + 0.5) * deltaPhi;
97  // double phi = (iBlade+0.5)*deltaPhi - 90.*CLHEP::deg;
98  double phix = atan2(sin(phi) * cos(bladeAngle), cos(phi) * cos(bladeAngle));
99  double thetx = acos(-sin(bladeAngle));
100  double phiy = atan2((cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)),
101  (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)));
102  double thety = acos(cos(bladeAngle) * sin(bladeTilt));
103  double phiz = atan2((-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)),
104  (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)));
105  double thetz = acos(cos(bladeAngle) * cos(bladeTilt));
106  DDRotation rot = DDRotation(DDName(rotstr, rotns));
107  if (!rot) {
108  LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo test: Creating a new "
109  << "rotation: " << rotstr << "\t" << thetx / CLHEP::deg << ", " << phix / CLHEP::deg
110  << ", " << thety / CLHEP::deg << ", " << phiy / CLHEP::deg << ", " << thetz / CLHEP::deg
111  << ", " << phiz / CLHEP::deg;
112  LogDebug("TrackerGeom") << "Rotation Matrix (" << phi / CLHEP::deg << ", " << bladeAngle / CLHEP::deg << ", "
113  << bladeTilt / CLHEP::deg << ") " << cos(phi) * cos(bladeAngle) << ", "
114  << (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)) << ", "
115  << (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)) << ", "
116  << sin(phi) * cos(bladeAngle) << ", "
117  << (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)) << ", "
118  << (-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)) << ", "
119  << -sin(bladeAngle) << ", " << cos(bladeAngle) * sin(bladeTilt) << ", "
120  << cos(bladeAngle) * cos(bladeTilt);
121  rot = DDrot(DDName(rotstr, rotns), thetx, phix, thety, phiy, thetz, phiz);
122  }
123  double xpos = anchorR * (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt));
124  double ypos = anchorR * (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt));
125  double zpos = anchorR * (cos(bladeAngle) * sin(bladeTilt)) + zPlane + bladeZShift[iBlade];
126  DDTranslation tran(xpos, ypos, zpos);
127  cpv.position(child, mother, copy, tran, rot);
128  LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo test: " << child << " number " << copy << " positioned in " << mother
129  << " at " << tran << " with " << rot;
130  }
131  copy++;
132  }
133 }
134 
135 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDPixFwdDiskAlgo, "track:DDPixFwdDiskAlgo");
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
static AlgebraicMatrix initialize()
~DDPixFwdDiskAlgo() override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
std::string to_string(const V &value)
Definition: OMSAccess.h:77
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
U second(std::pair< T, U > const &p)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
vector< double > bladeZShift
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void execute(DDCompactView &cpv) override
#define LogDebug(id)