CMS 3D CMS Logo

DDTECOptoHybAlgo.cc
Go to the documentation of this file.
1 // File: DDTECOptoHybAlgo.cc
3 // Description: Placing cooling pieces in the petal material of a TEC petal
5 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.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 DDTECOptoHybAlgo : public DDAlgorithm {
24 public:
25  //Constructor and Destructor
27  ~DDTECOptoHybAlgo() 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 parts
39  string childName; //Child name
40  double rpos; //r Position
41  double zpos; //Z position of the OptoHybrid
42  double optoHeight; // Height of the OptoHybrid
43  double optoWidth; // Width of the OptoHybrid
44  int startCopyNo; //Start copy number
45  vector<double> angles; //Angular position of Hybrid
46 };
47 
49  LogDebug("TECGeom") << "DDTECOptoHybAlgo info: Creating an instance";
50 }
51 
53 
55  const DDVectorArguments& vArgs,
56  const DDMapArguments&,
57  const DDStringArguments& sArgs,
58  const DDStringVectorArguments&) {
60  childName = sArgs["ChildName"];
61 
62  DDName parentName = parent().name();
63 
64  LogDebug("TECGeom") << "DDTECOptoHybAlgo debug: Parent " << parentName << " Child " << childName << " NameSpace "
65  << idNameSpace;
66 
67  optoHeight = nArgs["OptoHeight"];
68  optoWidth = nArgs["OptoWidth"];
69  rpos = nArgs["Rpos"];
70  zpos = nArgs["Zpos"];
71  startCopyNo = int(nArgs["StartCopyNo"]);
72  angles = vArgs["Angles"];
73 
74  LogDebug("TECGeom") << "DDTECOptoHybAlgo debug: Height of the Hybrid " << optoHeight << " and Width " << optoWidth
75  << "Rpos " << rpos << " Zpos " << zpos << " StartCopyNo " << startCopyNo << " Number "
76  << angles.size();
77 
78  for (int i = 0; i < (int)(angles.size()); i++)
79  LogDebug("TECGeom") << "\tAngles[" << i << "] = " << angles[i];
80 }
81 
83  LogDebug("TECGeom") << "==>> Constructing DDTECOptoHybAlgo...";
84 
85  DDName mother = parent().name();
87 
88  // given r positions are for the lower left corner
89  rpos += optoHeight / 2;
90  int copyNo = startCopyNo;
91  for (double angle : angles) {
92  double phix = -angle;
93  // given phi positions are for the lower left corner
94  phix += asin(optoWidth / 2 / rpos);
95  double xpos = rpos * cos(phix);
96  double ypos = rpos * sin(phix);
97  DDTranslation tran(xpos, ypos, zpos);
98 
100  double phiy = phix + 90. * CLHEP::deg;
101  double phideg = phix / CLHEP::deg;
102  if (phideg != 0) {
103  string rotstr = DDSplit(childName).first + to_string(phideg * 1000.);
105  if (!rotation) {
106  double theta = 90. * CLHEP::deg;
107  LogDebug("TECGeom") << "DDTECOptoHybAlgo test: Creating a new "
108  << "rotation: " << rotstr << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
109  << ", 0, 0";
110  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
111  }
112  }
113 
114  cpv.position(child, mother, copyNo, tran, rotation);
115  LogDebug("TECGeom") << "DDTECOptoHybAlgo test " << child << " number " << copyNo << " positioned in " << mother
116  << " at " << tran << " with " << rotation;
117  copyNo++;
118  }
119 
120  LogDebug("TECGeom") << "<<== End of DDTECOptoHybAlgo construction ...";
121 }
122 
123 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECOptoHybAlgo, "track:DDTECOptoHybAlgo");
static AlgebraicMatrix initialize()
vector< double > angles
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) 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
~DDTECOptoHybAlgo() override
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
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 execute(DDCompactView &cpv) 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
Geom::Theta< T > theta() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
#define LogDebug(id)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11