CMS 3D CMS Logo

DDAHcalModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDAHcalModuleAlgo.cc
3 // Description: Geometry factory class for HGCal (EE and HESil)
5 
6 #include <cmath>
7 #include <algorithm>
8 
17 #include "CLHEP/Units/GlobalPhysicalConstants.h"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 
20 //#define EDM_ML_DEBUG
21 
23 #ifdef EDM_ML_DEBUG
24  std::cout << "DDAHcalModuleAlgo info: Creating an instance" << std::endl;
25 #endif
26 }
27 
29 
31  const DDVectorArguments & vArgs,
32  const DDMapArguments & ,
33  const DDStringArguments & sArgs,
34  const DDStringVectorArguments &vsArgs){
35 
36  tile = sArgs["TileName"];
37 #ifdef EDM_ML_DEBUG
38  std::cout << "DDAHcalModuleAlgo: Tile " << tile << std::endl;
39 #endif
40  materials = vsArgs["MaterialNames"];
41  names = vsArgs["VolumeNames"];
42  thick = vArgs["Thickness"];
43  for (unsigned int i=0; i<materials.size(); ++i) {
44  copyNumber.emplace_back(1);
45  }
46 #ifdef EDM_ML_DEBUG
47  std::cout << "DDAHcalModuleAlgo: " << materials.size()
48  << " types of volumes" << std::endl;
49  for (unsigned int i=0; i<names.size(); ++i)
50  std::cout << "Volume [" << i << "] " << names[i] << " of thickness "
51  << thick[i] << " filled with " << materials[i]
52  << " first copy number " << copyNumber[i] << std::endl;
53 #endif
54  layers = dbl_to_int(vArgs["Layers"]);
55  layerThick = vArgs["LayerThick"];
56 #ifdef EDM_ML_DEBUG
57  std::cout << "DDAHcalModuleAlgo: " << layers.size() << " blocks" <<std::endl;
58  for (unsigned int i=0; i<layers.size(); ++i)
59  std::cout << "Block [" << i << "] of thickness " << layerThick[i]
60  << " with " << layers[i] << " layers" << std::endl;
61 #endif
62  layerType = dbl_to_int(vArgs["LayerType"]);
63  layerSense = dbl_to_int(vArgs["LayerSense"]);
64 #ifdef EDM_ML_DEBUG
65  std::cout << "DDAHcalModuleAlgo: " << layerType.size() << " layers"
66  << std::endl;
67  for (unsigned int i=0; i<layerType.size(); ++i)
68  std::cout << "Layer [" << i << "] with material type " << layerType[i]
69  << " sensitive class " << layerSense[i] << std::endl;
70 #endif
71  widths = vArgs["Widths"];
72  heights = vArgs["Heights"];
73 #ifdef EDM_ML_DEBUG
74  std::cout << "DDAHcalModuleAlgo: " << widths.size() << " sizes for width "
75  << "and height:";
76  for (unsigned int i=0; i<widths.size(); ++i)
77  std::cout << " [" << i << "] " << widths[i] << ":" << heights[i];
78  std::cout << std::endl;
79 #endif
80  tileN = dbl_to_int(vArgs["TileN"]);
81  tileStep = vArgs["TileStep"];
82 #ifdef EDM_ML_DEBUG
83  std::cout << "DDAHcalModuleAlgo: " << tileN.size() << " tile positioning "
84  << "parameters:";
85  for (unsigned int i=0; i<tileN.size(); ++i)
86  std::cout << " [" << i << "] " << tileN[i] << ":" << tileStep[i];
87  std::cout << std::endl;
88 #endif
89  zMinBlock = nArgs["zMinBlock"];
91 #ifdef EDM_ML_DEBUG
92  std::cout << "DDAHcalModuleAlgo: NameSpace " << idNameSpace << std::endl;
93 #endif
94 }
95 
97 // DDAHcalModuleAlgo methods...
99 
101 
102 #ifdef EDM_ML_DEBUG
103  std::cout << "==>> Constructing DDAHcalModuleAlgo..." << std::endl;
104 #endif
105  constructLayers (parent(), cpv);
106 #ifdef EDM_ML_DEBUG
107  std::cout << "<<== End of DDAHcalModuleAlgo construction ..." << std::endl;
108 #endif
109 }
110 
112  DDCompactView& cpv) {
113 
114 #ifdef EDM_ML_DEBUG
115  std::cout << "DDAHcalModuleAlgo test: \t\tInside Layers" << std::endl;
116 #endif
117  double zi(zMinBlock);
118  int laymin(0);
119  for (unsigned int i=0; i<layers.size(); i++) {
120  double zo = zi + layerThick[i];
121  int laymax = laymin+layers[i];
122  double zz = zi;
123  double thickTot(0);
124  for (int ly=laymin; ly<laymax; ++ly) {
125  int ii = layerType[ly];
126  int copy = copyNumber[ii];
127  zz += (0.5*thick[ii]);
128  thickTot += thick[ii];
129 
130  std::string name = "HGCal"+names[ii]+std::to_string(copy);
131 #ifdef EDM_ML_DEBUG
132  std::cout << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii
133  << " Front " << zi << " Back " << zo
134  << " superlayer thickness " << layerThick[i] << std::endl;
135 #endif
136  DDName matName(DDSplit(materials[ii]).first,
137  DDSplit(materials[ii]).second);
138  DDMaterial matter(matName);
139  DDLogicalPart glog;
140  if (layerSense[ly] == 0) {
142  0.5*widths[0], 0.5*heights[0],
143  0.5*thick[ii]);
144  glog = DDLogicalPart(solid.ddname(), matter, solid);
145 #ifdef EDM_ML_DEBUG
146  std::cout << "DDAHcalModuleAlgo test: " << solid.name()
147  << " Box made of " << matName << " of dimensions "
148  << 0.5*widths[0] << ", " << 0.5*heights[0] << ", "
149  << 0.5*thick[ii] << std::endl;
150 #endif
151  } else {
153  0.5*widths[1], 0.5*heights[1],
154  0.5*thick[ii]);
155  glog = DDLogicalPart(solid.ddname(), matter, solid);
156 #ifdef EDM_ML_DEBUG
157  std::cout << "DDAHcalModuleAlgo test: " << solid.name()
158  << " Box made of " << matName << " of dimensions "
159  << 0.5*widths[1] << ", " << 0.5*heights[1] << ", "
160  << 0.5*thick[ii] << std::endl;
161 #endif
162  positionSensitive(glog,cpv);
163  }
164  DDTranslation r1(0,0,zz);
165  DDRotation rot;
166  cpv.position(glog, module, copy, r1, rot);
167  ++copyNumber[ii];
168 #ifdef EDM_ML_DEBUG
169  std::cout << "DDAHcalModuleAlgo test: " << glog.name() << " number "
170  << copy << " positioned in " << module.name() << " at " << r1
171  << " with " << rot << std::endl;
172 #endif
173  zz += (0.5*thick[ii]);
174  } // End of loop over layers in a block
175  zi = zo;
176  laymin = laymax;
177  if (fabs(thickTot-layerThick[i]) < 0.00001) {
178  } else if (thickTot > layerThick[i]) {
179  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i]
180  << " is smaller than thickness " << thickTot
181  << " of all its components **** ERROR ****\n";
182  } else if (thickTot < layerThick[i]) {
183  edm::LogWarning("HGCalGeom") << "Thickness of the partition "
184  << layerThick[i] << " does not match with "
185  << thickTot << " of the components\n";
186  }
187  } // End of loop over blocks
188 }
189 
191  DDCompactView& cpv) {
192  int ncol = tileN[0]/2;
193  int nrow = tileN[1]/2;
194 #ifdef EDM_ML_DEBUG
195  int kount(0);
196  std::cout << glog.ddname() << " Row " << nrow << " Column " << ncol
197  << std::endl;
198 #endif
199  for (int nr=-nrow; nr <= nrow; ++nr) {
200  int inr = (nr >= 0) ? nr : -nr;
201  double ypos = (nr >= 0) ? (inr-0.5)*tileStep[1] : -(inr-0.5)*tileStep[1];
202  for (int nc=-ncol; nc <= ncol; ++nc) {
203  int inc = (nc >= 0) ? nc : -nc;
204  double xpos = (nc >= 0) ? (inc-0.5)*tileStep[0] : -(inc-0.5)*tileStep[0];
205  if (nr != 0 && nc != 0) {
206  DDTranslation tran(xpos, ypos, 0.0);
208  int copy = inr*10 + inc;
209  if (nc < 0) copy += 100;
210  if (nr < 0) copy += 1000;
212  cpv.position(name, glog.ddname(), copy, tran, rotation);
213 #ifdef EDM_ML_DEBUG
214  kount++;
215  std::cout << "DDAHcalModuleAlgo: " << name << " number " << copy
216  << " positioned in " << glog.ddname() << " at " << tran
217  << " with " << rotation << std::endl;
218 #endif
219  }
220  }
221  }
222 #ifdef EDM_ML_DEBUG
223  std::cout << "DDAHcalModuleAlgo: " << kount << " tiles for "
224  << glog.ddname() << std::endl;
225 #endif
226 }
std::vector< int > layerType
std::vector< std::string > materials
std::vector< double > widths
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
const N & name() const
Definition: DDBase.h:78
std::vector< int > copyNumber
def copy(args, dbName)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
~DDAHcalModuleAlgo() override
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
std::vector< double > heights
void execute(DDCompactView &cpv) override
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:67
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
std::vector< double > thick
std::vector< std::string > names
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:92
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:705
ii
Definition: cuy.py:589
std::vector< double > layerThick
std::vector< double > tileStep
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::vector< int > layers
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 > tileN
Definition: vlib.h:208
std::vector< int > layerSense
void positionSensitive(DDLogicalPart &glog, DDCompactView &cpv)
std::string idNameSpace
const N & ddname() const
Definition: DDBase.h:80