CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDHGCalModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDHGCalModuleAlgo.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 << "DDHGCalModuleAlgo 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  wafer = vsArgs["WaferName"];
37 #ifdef EDM_ML_DEBUG
38  std::cout << "DDHGCalModuleAlgo: " << wafer.size() << " wafers" << std::endl;
39  for (unsigned int i=0; i<wafer.size(); ++i)
40  std::cout << "Wafer[" << i << "] " << wafer[i] << std::endl;
41 #endif
42  materials = vsArgs["MaterialNames"];
43  names = vsArgs["VolumeNames"];
44  thick = vArgs["Thickness"];
45  for (unsigned int i=0; i<materials.size(); ++i) {
46  copyNumber.push_back(1);
47  }
48 #ifdef EDM_ML_DEBUG
49  std::cout << "DDHGCalModuleAlgo: " << materials.size()
50  << " types of volumes" << std::endl;
51  for (unsigned int i=0; i<names.size(); ++i)
52  std::cout << "Volume [" << i << "] " << names[i] << " of thickness "
53  << thick[i] << " filled with " << materials[i]
54  << " first copy number " << copyNumber[i] << std::endl;
55 #endif
56  layers = dbl_to_int(vArgs["Layers"]);
57  layerThick = vArgs["LayerThick"];
58 #ifdef EDM_ML_DEBUG
59  std::cout << "DDHGCalModuleAlgo: " << layers.size() << " blocks" <<std::endl;
60  for (unsigned int i=0; i<layers.size(); ++i)
61  std::cout << "Block [" << i << "] of thickness " << layerThick[i]
62  << " with " << layers[i] << " layers" << std::endl;
63 #endif
64  layerType = dbl_to_int(vArgs["LayerType"]);
65  layerSense = dbl_to_int(vArgs["LayerSense"]);
66 #ifdef EDM_ML_DEBUG
67  std::cout << "DDHGCalModuleAlgo: " << layerType.size() << " layers"
68  << std::endl;
69  for (unsigned int i=0; i<layerType.size(); ++i)
70  std::cout << "Layer [" << i << "] with material type " << layerType[i]
71  << " sensitive class " << layerSense[i] << std::endl;
72 #endif
73  zMinBlock = nArgs["zMinBlock"];
74  rMaxFine = nArgs["rMaxFine"];
75  waferW = nArgs["waferW"];
76  sectors = (int)(nArgs["Sectors"]);
77 #ifdef EDM_ML_DEBUG
78  std::cout << "DDHGCalModuleAlgo: zStart " << zMinBlock << " rFineCoarse "
79  << rMaxFine << " wafer width " << waferW << " sectors " << sectors
80  << std::endl;
81 #endif
82  slopeB = vArgs["SlopeBottom"];
83  slopeT = vArgs["SlopeTop"];
84  zFront = vArgs["ZFront"];
85  rMaxFront = vArgs["RMaxFront"];
86 #ifdef EDM_ML_DEBUG
87  std::cout << "DDHGCalModuleAlgo: Bottom slopes " << slopeB[0] << ":"
88  << slopeB[1] << " and " << slopeT.size() << " slopes for top"
89  << std::endl;
90  for (unsigned int i=0; i<slopeT.size(); ++i)
91  std::cout << "Block [" << i << "] Zmin " << zFront[i] << " Rmax "
92  << rMaxFront[i] << " Slope " << slopeT[i] << std::endl;
93 #endif
95 #ifdef EDM_ML_DEBUG
96  std::cout << "DDHGCalModuleAlgo: NameSpace " << idNameSpace << std::endl;
97 #endif
98 }
99 
101 // DDHGCalModuleAlgo methods...
103 
105 
106 #ifdef EDM_ML_DEBUG
107  std::cout << "==>> Constructing DDHGCalModuleAlgo..." << std::endl;
108 #endif
109  copies.clear();
110  constructLayers (parent(), cpv);
111 #ifdef EDM_ML_DEBUG
112  std::cout << copies.size() << " different wafer copy numbers" << std::endl;
113 #endif
114  copies.clear();
115 #ifdef EDM_ML_DEBUG
116  std::cout << "<<== End of DDHGCalModuleAlgo construction ..." << std::endl;
117 #endif
118 }
119 
121  DDCompactView& cpv) {
122 
123 #ifdef EDM_ML_DEBUG
124  std::cout << "DDHGCalModuleAlgo test: \t\tInside Layers" << std::endl;
125 #endif
126  double zi(zMinBlock);
127  int laymin(0);
128  const double tol(0.01);
129  for (unsigned int i=0; i<layers.size(); i++) {
130  double zo = zi + layerThick[i];
131  double routF = rMax(zi);
132  int laymax = laymin+layers[i];
133  double zz = zi;
134  double thickTot(0);
135  for (int ly=laymin; ly<laymax; ++ly) {
136  int ii = layerType[ly];
137  int copy = copyNumber[ii];
138  double rinB = (layerSense[ly] == 0) ? (zo*slopeB[0]) : (zo*slopeB[1]);
139  zz += (0.5*thick[ii]);
140  thickTot += thick[ii];
141 
142  std::string name = "HGCal"+names[ii]+std::to_string(copy);
143 #ifdef EDM_ML_DEBUG
144  std::cout << "DDHGCalModuleAlgo test: Layer " << ly << ":" << ii
145  << " Front " << zi << ", " << routF << " Back " << zo << ", "
146  << rinB << " superlayer thickness " << layerThick[i]
147  << std::endl;
148 #endif
149  DDName matName(DDSplit(materials[ii]).first,
150  DDSplit(materials[ii]).second);
151  DDMaterial matter(matName);
152  DDLogicalPart glog;
153  if (layerSense[ly] == 0) {
154  double alpha = CLHEP::pi/sectors;
155  double rmax = routF*cos(alpha) - tol;
156  std::vector<double> pgonZ, pgonRin, pgonRout;
157  pgonZ.push_back(-0.5*thick[ii]); pgonZ.push_back(0.5*thick[ii]);
158  pgonRin.push_back(rinB); pgonRin.push_back(rinB);
159  pgonRout.push_back(rmax); pgonRout.push_back(rmax);
161  sectors, -alpha, CLHEP::twopi,
162  pgonZ, pgonRin, pgonRout);
163  glog = DDLogicalPart(solid.ddname(), matter, solid);
164 #ifdef EDM_ML_DEBUG
165  std::cout << "DDHGCalModuleAlgo test: " << solid.name()
166  << " polyhedra of " << sectors << " sectors covering "
167  << -alpha/CLHEP::deg << ":"
168  << (-alpha+CLHEP::twopi)/CLHEP::deg
169  << " with " << pgonZ.size() << " sections" << std::endl;
170  for (unsigned int k=0; k<pgonZ.size(); ++k)
171  std::cout << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k]
172  << ":" << pgonRout[k] << std::endl;
173 #endif
174  } else {
176  0.5*thick[ii], rinB, routF, 0.0,
177  CLHEP::twopi);
178  glog = DDLogicalPart(solid.ddname(), matter, solid);
179 #ifdef EDM_ML_DEBUG
180  std::cout << "DDHGCalModuleAlgo test: " << solid.name()
181  << " Tubs made of " << matName << " of dimensions " << rinB
182  << ", " << routF << ", " << 0.5*thick[ii] << ", 0.0, "
183  << CLHEP::twopi/CLHEP::deg << std::endl;
184 #endif
185  positionSensitive(glog,rinB,routF,cpv);
186  }
187  DDTranslation r1(0,0,zz);
188  DDRotation rot;
189  cpv.position(glog, module, copy, r1, rot);
190  ++copyNumber[ii];
191 #ifdef EDM_ML_DEBUG
192  std::cout << "DDHGCalModuleAlgo test: " << glog.name() << " number "
193  << copy << " positioned in " << module.name() << " at " << r1
194  << " with " << rot << std::endl;
195 #endif
196  zz += (0.5*thick[ii]);
197  } // End of loop over layers in a block
198  zi = zo;
199  laymin = laymax;
200  if (fabs(thickTot-layerThick[i]) < 0.00001) {
201  } else if (thickTot > layerThick[i]) {
202  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i]
203  << " is smaller than thickness " << thickTot
204  << " of all its components **** ERROR ****\n";
205  } else if (thickTot < layerThick[i]) {
206  edm::LogWarning("HGCalGeom") << "Thickness of the partition "
207  << layerThick[i] << " does not match with "
208  << thickTot << " of the components\n";
209  }
210  } // End of loop over blocks
211 }
212 
213 double DDHGCalModuleAlgo::rMax(double z) {
214  double r(0);
215 #ifdef EDM_ML_DEBUG
216  unsigned int ik(0);
217 #endif
218  for (unsigned int k=0; k<slopeT.size(); ++k) {
219  if (z < zFront[k]) break;
220  r = rMaxFront[k] + (z - zFront[k]) * slopeT[k];
221 #ifdef EDM_ML_DEBUG
222  ik = k;
223 #endif
224  }
225 #ifdef EDM_ML_DEBUG
226  std::cout << "rMax : " << z << ":" << ik << ":" << r << std::endl;
227 #endif
228  return r;
229 }
230 
232  double rout, DDCompactView& cpv) {
233  double dx = 0.5*waferW;
234  double dy = 3.0*dx*tan(30.0*CLHEP::deg);
235  double rr = 2.0*dx*tan(30.0*CLHEP::deg);
236  int ncol = (int)(2.0*rout/waferW) + 1;
237  int nrow = (int)(rout/(waferW*tan(30.0*CLHEP::deg))) + 1;
238  int incm(0), inrm(0), kount(0);
239  double xc[6], yc[6];
240 #ifdef EDM_ML_DEBUG
241  std::cout << glog.ddname() << " rout " << rout << " Row " << nrow
242  << " Column " << ncol << std::endl;
243 #endif
244  for (int nr=-nrow; nr <= nrow; ++nr) {
245  int inr = (nr >= 0) ? nr : -nr;
246  for (int nc=-ncol; nc <= ncol; ++nc) {
247  int inc = (nc >= 0) ? nc : -nc;
248  if (inr%2 == inc%2) {
249  double xpos = nc*dx;
250  double ypos = nr*dy;
251  xc[0] = xpos+dx; yc[0] = ypos-0.5*rr;
252  xc[1] = xpos+dx; yc[1] = ypos+0.5*rr;
253  xc[2] = xpos; yc[2] = ypos+rr;
254  xc[3] = xpos-dx; yc[3] = ypos+0.5*rr;
255  xc[4] = xpos+dx; yc[4] = ypos-0.5*rr;
256  xc[5] = xpos; yc[5] = ypos-rr;
257  bool cornerAll(true);
258  for (int k=0; k<6; ++k) {
259  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
260  if (rpos < rin || rpos > rout) cornerAll = false;
261  }
262  if (cornerAll) {
263  double rpos = std::sqrt(xpos*xpos+ypos*ypos);
264  DDTranslation tran(xpos, ypos, 0.0);
266  int copy = inr*100 + inc;
267  if (nc < 0) copy += 10000;
268  if (nr < 0) copy += 100000;
269  DDName name = (rpos < rMaxFine) ?
270  DDName(DDSplit(wafer[0]).first, DDSplit(wafer[0]).second) :
271  DDName(DDSplit(wafer[1]).first, DDSplit(wafer[1]).second);
272  cpv.position(name, glog.ddname(), copy, tran, rotation);
273  if (inc > incm) incm = inc;
274  if (inr > inrm) inrm = inr;
275  kount++;
276  if (copies.count(copy) == 0)
277  copies.insert(copy);
278 #ifdef EDM_ML_DEBUG
279  std::cout << "DDHGCalModuleAlgo: " << name << " number " << copy
280  << " positioned in " << glog.ddname() << " at " << tran
281  << " with " << rotation << std::endl;
282 #endif
283  }
284  }
285  }
286  }
287 #ifdef EDM_ML_DEBUG
288  std::cout << "DDHGCalModuleAlgo: # of columns " << incm << " # of rows "
289  << inrm << " and " << kount << " wafers for " << glog.ddname()
290  << std::endl;
291 #endif
292 }
std::vector< int > copyNumber
std::vector< double > thick
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
const N & name() const
Definition: DDBase.h:78
void positionSensitive(DDLogicalPart &glog, double rin, double rout, DDCompactView &cpv)
std::unordered_set< int > copies
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
void constructLayers(DDLogicalPart, DDCompactView &cpv)
std::vector< std::string > names
void position(const DDLogicalPart &self, const DDLogicalPart &parent, std::string copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=NULL)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:16
static std::string & ns()
int ii
Definition: cuy.py:588
type of data representation of DDCompactView
Definition: DDCompactView.h:90
float float float z
A DDSolid represents the shape of a part.
Definition: DDSolid.h:37
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
const Double_t pi
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
std::vector< std::string > materials
std::vector< double > rMaxFront
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
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
Definition: DDSolid.cc:823
std::vector< double > slopeB
std::string idNameSpace
std::vector< int > layerType
std::vector< int > layers
virtual ~DDHGCalModuleAlgo()
void execute(DDCompactView &cpv)
std::vector< double > slopeT
tuple cout
Definition: gather_cfg.py:145
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:4
std::vector< std::string > wafer
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs)
Definition: vlib.h:208
std::vector< double > zFront
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:708
std::vector< double > layerThick
double rMax(double z)
std::vector< int > layerSense
const N & ddname() const
Definition: DDBase.h:80