CMS 3D CMS Logo

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