CMS 3D CMS Logo

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