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 DebugLog
21 
23 #ifdef DebugLog
24  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo info: Creating an instance";
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 DebugLog
38  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: " << wafer.size()
39  << " wafers";
40  for (unsigned int i=0; i<wafer.size(); ++i)
41  edm::LogInfo("HGCalGeom") << "Wafer[" << i << "] " << wafer[i];
42 #endif
43  materials = vsArgs["MaterialNames"];
44  names = vsArgs["VolumeNames"];
45  thick = vArgs["Thickness"];
46  for (unsigned int i=0; i<materials.size(); ++i) {
47  copyNumber.push_back(1);
48  }
49 #ifdef DebugLog
50  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: " << materials.size()
51  << " types of volumes";
52  for (unsigned int i=0; i<names.size(); ++i)
53  edm::LogInfo("HGCalGeom") << "Volume [" << i << "] " << names[i]
54  << " of thickness " << thick[i]
55  << " filled with " << materials[i]
56  << " first copy number " << copyNumber[i];
57 #endif
58  layers = dbl_to_int(vArgs["Layers"]);
59  layerThick = vArgs["LayerThick"];
60 #ifdef DebugLog
61  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: " << layers.size()
62  << " blocks";
63  for (unsigned int i=0; i<layers.size(); ++i)
64  edm::LogInfo("HGCalGeom") << "Block [" << i << "] of thickness "
65  << layerThick[i] << " with " << layers[i]
66  << " layers";
67 #endif
68  layerType = dbl_to_int(vArgs["LayerType"]);
69  layerSense = dbl_to_int(vArgs["LayerSense"]);
70 #ifdef DebugLog
71  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: " << layerType.size()
72  << " layers";
73  for (unsigned int i=0; i<layerType.size(); ++i)
74  edm::LogInfo("HGCalGeom") << "Layer [" << i << "] with material type "
75  << layerType[i] << " sensitive class "
76  << layerSense[i];
77 #endif
78  zMinBlock = nArgs["zMinBlock"];
79  rMaxFine = nArgs["rMaxFine"];
80  waferW = nArgs["waferW"];
81  sectors = (int)(nArgs["Sectors"]);
82 #ifdef DebugLog
83  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: zStart " << zMinBlock
84  << " rFineCoarse " << rMaxFine << " wafer width "
85  << waferW << " sectors " << sectors;
86 #endif
87  slopeB = vArgs["SlopeBottom"];
88  slopeT = vArgs["SlopeTop"];
89  zFront = vArgs["ZFront"];
90  rMaxFront = vArgs["RMaxFront"];
91 #ifdef DebugLog
92  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: Bottom slopes " << slopeB[0]
93  << ":" << slopeB[1] << " and " << slopeT.size()
94  << " slopes for top";
95  for (unsigned int i=0; i<slopeT.size(); ++i)
96  edm::LogInfo("HGCalGeom") << "Block [" << i << "] Zmin " << zFront[i]
97  << " Rmax " << rMaxFront[i] << " Slope "
98  << slopeT[i];
99 #endif
101 #ifdef DebugLog
102  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: NameSpace " << idNameSpace;
103 #endif
104 }
105 
107 // DDHGCalModuleAlgo methods...
109 
111 
112 #ifdef DebugLog
113  edm::LogInfo("HGCalGeom") << "==>> Constructing DDHGCalModuleAlgo...";
114 #endif
115  copies.clear();
116  constructLayers (parent(), cpv);
117  edm::LogInfo("HGCalGeom") << copies.size() << " different wafer copy numbers";
118  copies.clear();
119 #ifdef DebugLog
120  edm::LogInfo("HGCalGeom") << "<<== End of DDHGCalModuleAlgo construction ...";
121 #endif
122 }
123 
125  DDCompactView& cpv) {
126 
127 #ifdef DebugLog
128  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo test: \t\tInside Layers";
129 #endif
130  double zi(zMinBlock);
131  int laymin(0);
132  const double tol(0.01);
133  for (unsigned int i=0; i<layers.size(); i++) {
134  double zo = zi + layerThick[i];
135  double routF = rMax(zi);
136  int laymax = laymin+layers[i];
137  double zz = zi;
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 
144  std::string name = "HGCal"+names[ii]+dbl_to_string(copy);
145 #ifdef DebugLog
146  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo test: Layer " << ly << ":"
147  << ii << " Front " << zi << ", " << routF
148  << " Back " << zo << ", " << rinB
149  << " superlayer thickness " << layerThick[i];
150 #endif
151  DDName matName(DDSplit(materials[ii]).first,
152  DDSplit(materials[ii]).second);
153  DDMaterial matter(matName);
154  DDLogicalPart glog;
155  if (layerSense[ly] == 0) {
156  double alpha = CLHEP::pi/sectors;
157  double rmax = routF*cos(alpha) - tol;
158  std::vector<double> pgonZ, pgonRin, pgonRout;
159  pgonZ.push_back(-0.5*thick[ii]); pgonZ.push_back(0.5*thick[ii]);
160  pgonRin.push_back(rinB); pgonRin.push_back(rinB);
161  pgonRout.push_back(rmax); pgonRout.push_back(rmax);
163  sectors, -alpha, CLHEP::twopi,
164  pgonZ, pgonRin, pgonRout);
165  glog = DDLogicalPart(solid.ddname(), matter, solid);
166 #ifdef DebugLog
167  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo test: "
168  << solid.name() << " polyhedra of " << sectors
169  << " sectors covering " << -alpha/CLHEP::deg
170  << ":" << (-alpha+CLHEP::twopi)/CLHEP::deg
171  << " with " << pgonZ.size() << " sections";
172  for (unsigned int k=0; k<pgonZ.size(); ++k)
173  edm::LogInfo("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R "
174  << pgonRin[k] << ":" << pgonRout[k];
175 #endif
176  } else {
178  0.5*thick[ii], rinB, routF, 0.0,
179  CLHEP::twopi);
180  glog = DDLogicalPart(solid.ddname(), matter, solid);
181 #ifdef DebugLog
182  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo test: "
183  << solid.name() << " Tubs made of " << matName
184  << " of dimensions " << rinB << ", " << routF
185  << ", " << 0.5*thick[ii] << ", 0.0, "
186  << CLHEP::twopi/CLHEP::deg;
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 DebugLog
195  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo test: " << glog.name()
196  << " number " << copy << " positioned in "
197  << module.name() << " at " << r1 << " with "
198  << rot;
199 #endif
200  zz += (0.5*thick[ii]);
201  } // End of loop over layers in a block
202  zi = zo;
203  laymin = laymax;
204  } // End of loop over blocks
205 }
206 
207 double DDHGCalModuleAlgo::rMax(double z) {
208  double r(0);
209 #ifdef DebugLog
210  unsigned int ik(0);
211 #endif
212  for (unsigned int k=0; k<slopeT.size(); ++k) {
213  if (z < zFront[k]) break;
214  r = rMaxFront[k] + (z - zFront[k]) * slopeT[k];
215 #ifdef DebugLog
216  ik = k;
217 #endif
218  }
219 #ifdef DebugLog
220  edm::LogInfo("HGCalGeom") << "rMax : " << z << ":" << ik << ":" << r ;
221 #endif
222  return r;
223 }
224 
226  double rout, DDCompactView& cpv) {
227  double dx = 0.5*waferW;
228  double dy = 3.0*dx*tan(30.0*CLHEP::deg);
229  double rr = 2.0*dx*tan(30.0*CLHEP::deg);
230  int ncol = (int)(2.0*rout/waferW) + 1;
231  int nrow = (int)(rout/(waferW*tan(30.0*CLHEP::deg))) + 1;
232  int incm(0), inrm(0), kount(0);
233 #ifdef DebugLog
234  edm::LogInfo("HGCalGeom") << glog.ddname() << " rout " << rout << " Row "
235  << nrow << " Column " << ncol;
236 #endif
237  for (int nr=-nrow; nr <= nrow; ++nr) {
238  int inr = (nr >= 0) ? nr : -nr;
239  for (int nc=-ncol; nc <= ncol; ++nc) {
240  int inc = (nc >= 0) ? nc : -nc;
241  if (inr%2 == inc%2) {
242  double xpos = nc*dx;
243  double ypos = nr*dy;
244  double rpos = std::sqrt(xpos*xpos+ypos*ypos);
245  if (rpos-rr >= rin && rpos+rr <= rout) {
246  DDTranslation tran(xpos, ypos, 0.0);
248  int copy = inr*100 + inc;
249  if (nc < 0) copy += 10000;
250  if (nr < 0) copy += 100000;
251  DDName name = (rpos < rMaxFine) ?
252  DDName(DDSplit(wafer[0]).first, DDSplit(wafer[0]).second) :
253  DDName(DDSplit(wafer[1]).first, DDSplit(wafer[1]).second);
254  cpv.position(name, glog.ddname(), copy, tran, rotation);
255  if (inc > incm) incm = inc;
256  if (inr > inrm) inrm = inr;
257  kount++;
258  if ( copies.count(copy) == 0 )
259  copies.insert(copy);
260 #ifdef DebugLog
261  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: "
262  << name << " number " << copy
263  << " positioned in " << glog.ddname()
264  << " at " << tran << " with " << rotation;
265 #endif
266  }
267  }
268  }
269  }
270  edm::LogInfo("HGCalGeom") << "DDHGCalModuleAlgo: # of columns " << incm
271  << " # of rows " << inrm << " and " << kount
272  << " wafers for " <<glog.ddname();
273 }
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:14
static std::string & ns()
std::string dbl_to_string(const double &in)
Converts only the integer part of a double to a string.
Definition: DDutils.cc:12
int ii
Definition: cuy.py:588
type of data representation of DDCompactView
Definition: DDCompactView.h:77
float float float z
A DDSolid represents the shape of a part.
Definition: DDSolid.h:35
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.cc:4
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:88
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
Definition: DDSolid.cc:788
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
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:673
std::vector< double > layerThick
double rMax(double z)
std::vector< int > layerSense
const N & ddname() const
Definition: DDBase.h:80