CMS 3D CMS Logo

DDHCalFibreBundle.cc
Go to the documentation of this file.
1 // File: DDHCalFibreBundle.cc
3 // Description: Create & Position fibre bundles in mother
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
24 
25 //#define EDM_ML_DEBUG
26 using namespace angle_units::operators;
27 
28 class DDHCalFibreBundle : public DDAlgorithm {
29 public:
30  //Constructor and Destructor
32  ~DDHCalFibreBundle() override;
33 
34  void initialize(const DDNumericArguments& nArgs,
35  const DDVectorArguments& vArgs,
36  const DDMapArguments& mArgs,
37  const DDStringArguments& sArgs,
38  const DDStringVectorArguments& vsArgs) override;
39 
40  void execute(DDCompactView& cpv) override;
41 
42 private:
43  std::string idNameSpace; //Namespace of this and ALL sub-parts
44  std::string childPrefix; //Prefix to child name
45  std::string material; //Name of the material for bundles
46  double deltaZ; //Width in Z for mother
47  double deltaPhi; //Width in phi for mother
48  int numberPhi; //Number of sections in phi
49  double tilt; //Tilt angle of the readout box
50  std::vector<double> areaSection; //Area of a bundle
51  std::vector<double> rStart; //Radius at start
52  std::vector<double> rEnd; //Radius at End
53  std::vector<int> bundle; //Bundle to be positioned
54 };
55 
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating an instance";
59 #endif
60 }
61 
63 
65  const DDVectorArguments& vArgs,
66  const DDMapArguments&,
67  const DDStringArguments& sArgs,
68  const DDStringVectorArguments&) {
69  deltaPhi = nArgs["DeltaPhi"];
70  deltaZ = nArgs["DeltaZ"];
71  numberPhi = int(nArgs["NumberPhi"]);
72  material = sArgs["Material"];
73  areaSection = vArgs["AreaSection"];
74  rStart = vArgs["RadiusStart"];
75  rEnd = vArgs["RadiusEnd"];
76  bundle = dbl_to_int(vArgs["Bundles"]);
77  tilt = nArgs["TiltAngle"];
78 
79  idNameSpace = DDCurrentNamespace::ns();
80  childPrefix = sArgs["Child"];
81 #ifdef EDM_ML_DEBUG
82  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Parent " << parent().name() << " with " << bundle.size()
83  << " children with prefix " << childPrefix << ", material " << material << " with "
84  << numberPhi << " bundles along phi; width of"
85  << " mother " << deltaZ << " along Z, " << convertRadToDeg(deltaPhi)
86  << " along phi and with " << rStart.size() << " different bundle types";
87  for (unsigned int i = 0; i < areaSection.size(); ++i)
88  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Child[" << i << "] Area " << areaSection[i] << " R at Start "
89  << rStart[i] << " R at End " << rEnd[i];
90  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: NameSpace " << idNameSpace << " Tilt Angle "
91  << convertRadToDeg(tilt) << " Bundle type at different positions";
92  for (unsigned int i = 0; i < bundle.size(); ++i) {
93  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Position[" << i << "] "
94  << " with Type " << bundle[i];
95  }
96 #endif
97 }
98 
100  DDName mother = parent().name();
101  DDName matname(DDSplit(material).first, DDSplit(material).second);
102  DDMaterial matter(matname);
103 
104  // Create the rotation matrices
105  double dPhi = deltaPhi / numberPhi;
106  std::vector<DDRotation> rotation;
107  for (int i = 0; i < numberPhi; ++i) {
108  double phi = -0.5 * deltaPhi + (i + 0.5) * dPhi;
109  double phideg = convertRadToDeg(phi);
110  std::string rotstr = "R0" + std::to_string(phideg);
111  DDRotation rot = DDRotation(DDName(rotstr, idNameSpace));
112  if (!rot) {
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new "
115  << "rotation " << rotstr << "\t" << 90 << "," << phideg << "," << 90 << ","
116  << (phideg + 90) << ", 0, 0";
117 #endif
118  rot = DDrot(DDName(rotstr, idNameSpace), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
119  }
120  rotation.emplace_back(rot);
121  }
122 
123  // Create the solids and logical parts
124  std::vector<DDLogicalPart> logs;
125  for (unsigned int i = 0; i < areaSection.size(); ++i) {
126  double r0 = rEnd[i] / std::cos(tilt);
127  double dStart = areaSection[i] / (2 * dPhi * rStart[i]);
128  double dEnd = areaSection[i] / (2 * dPhi * r0);
129  std::string name = childPrefix + std::to_string(i);
130  DDSolid solid = DDSolidFactory::cons(DDName(name, idNameSpace),
131  0.5 * deltaZ,
132  rStart[i] - dStart,
133  rStart[i] + dStart,
134  r0 - dEnd,
135  r0 + dEnd,
136  -0.5 * dPhi,
137  dPhi);
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new solid " << name << " a cons with dZ " << deltaZ
140  << " rStart " << rStart[i] - dStart << ":" << rStart[i] + dStart << " rEnd "
141  << r0 - dEnd << ":" << r0 + dEnd << " Phi " << convertRadToDeg(-0.5 * dPhi) << ":"
142  << convertRadToDeg(0.5 * dPhi);
143 #endif
144  DDLogicalPart log(DDName(name, idNameSpace), matter, solid);
145  logs.emplace_back(log);
146  }
147 
148  // Now posiiton them
149  int copy = 0;
150  int nY = (int)(bundle.size()) / numberPhi;
151  for (unsigned int i = 0; i < bundle.size(); i++) {
152  DDTranslation tran(0, 0, 0);
153  int ir = (int)(i) / nY;
154  if (ir >= numberPhi)
155  ir = numberPhi - 1;
156  int ib = bundle[i];
157  copy++;
158  if (ib >= 0 && ib < (int)(logs.size())) {
159  cpv.position(logs[ib], mother, copy, tran, rotation[ir]);
160 #ifdef EDM_ML_DEBUG
161  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: " << logs[ib].name() << " number " << copy
162  << " positioned in " << mother << " at " << tran << " with " << rotation[ir];
163 #endif
164  }
165  }
166 }
167 
168 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalFibreBundle, "hcal:DDHCalFibreBundle");
Log< level::Info, true > LogVerbatim
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)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
static DDSolid cons(const DDName &name, double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double phiFrom, double deltaPhi)
Definition: DDSolid.cc:650
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
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
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
static std::string to_string(const XMLCh *ch)
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
~DDHCalFibreBundle() override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void execute(DDCompactView &cpv) override
std::vector< double > areaSection
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
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
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
std::vector< double > rEnd
std::vector< double > rStart
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< int > bundle
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
ib
Definition: cuy.py:661
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override