CMS 3D CMS Logo

DDHCalForwardAlgo.cc
Go to the documentation of this file.
1 // File: DDHCalForwardAlgo.cc
3 // Description: Cable mockup between barrel and endcap gap
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
23 
24 //#define EDM_ML_DEBUG
25 
26 class DDHCalForwardAlgo : public DDAlgorithm {
27 public:
28  //Constructor and Destructor
29  DDHCalForwardAlgo(); //const std::string & name);
30  ~DDHCalForwardAlgo() override;
31 
32  void initialize(const DDNumericArguments& nArgs,
33  const DDVectorArguments& vArgs,
34  const DDMapArguments& mArgs,
35  const DDStringArguments& sArgs,
36  const DDStringVectorArguments& vsArgs) override;
37 
38  void execute(DDCompactView& cpv) override;
39 
40 private:
41  std::string cellMat; //Cell material
42  double cellDx, cellDy, cellDz; //Cell size
43  double startY; //Starting Y for Cell
44  std::vector<std::string> childName; //Children name
45  std::vector<int> number; //Number of cells
46  std::vector<int> size; //Number of children
47  std::vector<int> type; //First child
48 
49  std::string idNameSpace; //Namespace for aLL sub-parts
50 };
51 
53 #ifdef EDM_ML_DEBUG
54  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Creating an instance";
55 #endif
56 }
57 
59 
61  const DDVectorArguments& vArgs,
62  const DDMapArguments&,
63  const DDStringArguments& sArgs,
64  const DDStringVectorArguments& vsArgs) {
65  cellMat = sArgs["CellMaterial"];
66  cellDx = nArgs["CellDx"];
67  cellDy = nArgs["CellDy"];
68  cellDz = nArgs["CellDz"];
69  startY = nArgs["StartY"];
70 
71  childName = vsArgs["Child"];
72  number = dbl_to_int(vArgs["Number"]);
73  size = dbl_to_int(vArgs["Size"]);
74  type = dbl_to_int(vArgs["Type"]);
75 
76 #ifdef EDM_ML_DEBUG
77  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Cell material " << cellMat << "\tCell Size " << cellDx << ", "
78  << cellDy << ", " << cellDz << "\tStarting Y " << startY << "\tChildren " << childName[0]
79  << ", " << childName[1] << "\n "
80  << " Cell positioning done for " << number.size() << " times";
81  for (unsigned int i = 0; i < number.size(); i++)
82  edm::LogVerbatim("HCalGeom") << "\t" << i << " Number of children " << size[i] << " occurence " << number[i]
83  << " first child index " << type[i];
84 #endif
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo debug: Parent " << parent().name() << " NameSpace " << idNameSpace;
88 #endif
89 }
90 
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalForwardAlgo...";
94 #endif
95  DDName parentName = parent().name();
96  double ypos = startY;
97  int box = 0;
98 
99  for (unsigned int i = 0; i < number.size(); i++) {
100  double dx = cellDx * size[i];
101  int indx = type[i];
102  for (int j = 0; j < number[i]; j++) {
103  box++;
104  std::string name = parentName.name() + std::to_string(box);
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << DDName(name, idNameSpace) << " Box made of " << cellMat
108  << " of Size " << dx << ", " << cellDy << ", " << cellDz;
109 #endif
111  DDMaterial matter(matname);
112  DDLogicalPart genlogic(solid.ddname(), matter, solid);
113 
114  DDTranslation r0(0.0, ypos, 0.0);
115  DDRotation rot;
116  cpv.position(solid.ddname(), parentName, box, r0, rot);
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.ddname() << " number " << box << " positioned in "
119  << parentName << " at " << r0 << " with " << rot;
120 #endif
121  DDName child(DDSplit(childName[indx]).first, DDSplit(childName[indx]).second);
122  double xpos = -dx + cellDx;
123  ypos += 2 * cellDy;
124  indx = 1 - indx;
125 
126  for (int k = 0; k < size[i]; k++) {
127  DDTranslation r1(xpos, 0.0, 0.0);
128  cpv.position(child, solid.ddname(), k + 1, r1, rot);
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << child << " number " << k + 1 << " positioned in "
131  << solid.ddname() << " at " << r1 << " with " << rot;
132 #endif
133  xpos += 2 * cellDx;
134  }
135  }
136  }
137 #ifdef EDM_ML_DEBUG
138  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalForwardAlgo construction";
139 #endif
140 }
141 
142 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalForwardAlgo, "hcal:DDHCalForwardAlgo");
type
Definition: HCALResponse.h:21
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
~DDHCalForwardAlgo() override
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::vector< int > type
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:533
std::vector< int > size
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::string > childName
void execute(DDCompactView &cpv) override
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
std::vector< int > number
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
const N & ddname() const
Definition: DDBase.h:61