CMS 3D CMS Logo

DDTIDRingAlgo.cc
Go to the documentation of this file.
1 // File: DDTIDRingAlgo.cc
3 // Description: Position n copies of detectors in alternate positions and
4 // also associated ICC's
5 // Em 17Sep07: Cool inserts moved to DDTIDModulePosAlgo.h
7 
14 #include "CLHEP/Units/GlobalPhysicalConstants.h"
15 #include "CLHEP/Units/GlobalSystemOfUnits.h"
16 
17 #include <string>
18 #include <vector>
19 
20 using namespace std;
21 
22 class DDTIDRingAlgo : public DDAlgorithm {
23 public:
24  //Constructor and Destructor
25  DDTIDRingAlgo();
26  ~DDTIDRingAlgo() override;
27 
28  void initialize(const DDNumericArguments& nArgs,
29  const DDVectorArguments& vArgs,
30  const DDMapArguments& mArgs,
31  const DDStringArguments& sArgs,
32  const DDStringVectorArguments& vsArgs) override;
33 
34  void execute(DDCompactView& cpv) override;
35 
36 private:
37  string idNameSpace; //Namespace of this & ALL subparts
38  vector<string> moduleName; //Name of the module
39  string iccName; //Name of the ICC
40 
41  int number; //Number of copies
42  double startAngle; //Phi offset
43  double rModule; //Location of module in R
44  vector<double> zModule; // in Z
45  double rICC; //Location of ICC in R
46  double sICC; //Shift of ICC per to R
47  vector<double> zICC; // in Z
48 };
49 
50 DDTIDRingAlgo::DDTIDRingAlgo() { LogDebug("TIDGeom") << "DDTIDRingAlgo info: Creating an instance"; }
51 
53 
55  const DDVectorArguments& vArgs,
56  const DDMapArguments&,
57  const DDStringArguments& sArgs,
58  const DDStringVectorArguments& vsArgs) {
59  idNameSpace = DDCurrentNamespace::ns();
60  moduleName = vsArgs["ModuleName"];
61  iccName = sArgs["ICCName"];
62  DDName parentName = parent().name();
63  LogDebug("TIDGeom") << "DDTIDRingAlgo debug: Parent " << parentName << "\tModule " << moduleName[0] << ", "
64  << moduleName[1] << "\tICC " << iccName << "\tNameSpace " << idNameSpace;
65 
66  number = int(nArgs["Number"]);
67  startAngle = nArgs["StartAngle"];
68  rModule = nArgs["ModuleR"];
69  zModule = vArgs["ModuleZ"];
70  rICC = nArgs["ICCR"];
71  sICC = nArgs["ICCShift"];
72  zICC = vArgs["ICCZ"];
73 
74  LogDebug("TIDGeom") << "DDTIDRingAlgo debug: Parameters for positioning--"
75  << " StartAngle " << startAngle / CLHEP::deg << " Copy Numbers " << number << " Modules at R "
76  << rModule << " Z " << zModule[0] << ", " << zModule[1] << " ICCs at R " << rICC << " Z "
77  << zICC[0] << ", " << zICC[1];
78 }
79 
81  double theta = 90. * CLHEP::deg;
82  double phiy = 0. * CLHEP::deg;
83  double dphi = CLHEP::twopi / number;
84 
85  DDName mother = parent().name();
86  DDName module;
87  DDName icc(DDSplit(iccName).first, DDSplit(iccName).second);
88 
89  //Loop over modules
90  for (int i = 0; i < number; i++) {
91  //First the module
92  double phiz = startAngle + i * dphi;
93  double xpos = rModule * cos(phiz);
94  double ypos = rModule * sin(phiz);
95  double zpos, thetay, phix;
96  if (i % 2 == 0) {
97  phix = phiz + 90. * CLHEP::deg;
98  thetay = 0 * CLHEP::deg;
99  zpos = zModule[0];
101  } else {
102  phix = phiz - 90. * CLHEP::deg;
103  thetay = 180 * CLHEP::deg;
104  zpos = zModule[1];
106  }
107 
108  // stereo face inside toward structure, rphi face outside
109  phix = phix - 180. * CLHEP::deg;
110  thetay = thetay + 180. * CLHEP::deg;
111  //
112 
113  DDTranslation trmod(xpos, ypos, zpos);
114  double phideg = phiz / CLHEP::deg;
116  string rotstr = mother.name() + to_string(phideg * 10.);
117  rotation = DDRotation(DDName(rotstr, idNameSpace));
118  if (!rotation) {
119  LogDebug("TIDGeom") << "DDTIDRingAlgo test: Creating a new rotation " << rotstr << "\t" << theta / CLHEP::deg
120  << ", " << phix / CLHEP::deg << ", " << thetay / CLHEP::deg << ", " << phiy / CLHEP::deg
121  << ", " << theta / CLHEP::deg << ", " << phiz / CLHEP::deg;
122  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, thetay, phiy, theta, phiz);
123  }
124 
125  cpv.position(module, mother, i + 1, trmod, rotation);
126  LogDebug("TIDGeom") << "DDTIDRingAlgo test: " << module << " number " << i + 1 << " positioned in " << mother
127  << " at " << trmod << " with " << rotation;
128 
129  //Now the ICC
130  if (i % 2 == 0) {
131  zpos = zICC[0];
132  xpos = rICC * cos(phiz) + sICC * sin(phiz);
133  ypos = rICC * sin(phiz) - sICC * cos(phiz);
134  } else {
135  zpos = zICC[1];
136  xpos = rICC * cos(phiz) - sICC * sin(phiz);
137  ypos = rICC * sin(phiz) + sICC * cos(phiz);
138  }
139  DDTranslation tricc(xpos, ypos, zpos);
140  cpv.position(icc, mother, i + 1, tricc, rotation);
141  LogDebug("TIDGeom") << "DDTIDRingAlgo test: " << icc << " number " << i + 1 << " positioned in " << mother << " at "
142  << tricc << " with " << rotation;
143  }
144 }
145 
146 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTIDRingAlgo, "track:DDTIDRingAlgo");
static AlgebraicMatrix initialize()
vector< double > zModule
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
std::string to_string(const V &value)
Definition: OMSAccess.h:71
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
U second(std::pair< T, U > const &p)
string idNameSpace
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
~DDTIDRingAlgo() override
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< string > moduleName
vector< double > zICC
#define DEFINE_EDM_PLUGIN(factory, type, name)
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
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)