CMS 3D CMS Logo

DDHGCalTBModule.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <algorithm>
3 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
15 //#define EDM_ML_DEBUG
16 
18 #ifdef EDM_ML_DEBUG
19  std::cout << "DDHGCalTBModule info: Creating an instance" << std::endl;
20 #endif
21 }
22 
24 
26  const DDVectorArguments & vArgs,
27  const DDMapArguments & ,
28  const DDStringArguments & sArgs,
29  const DDStringVectorArguments &vsArgs){
30 
31  wafer_ = vsArgs["WaferName"];
32  covers_ = vsArgs["CoverName"];
33 #ifdef EDM_ML_DEBUG
34  std::cout << "DDHGCalTBModule: " << wafer_.size() << " wafers" << std::endl;
35  unsigned int i(0);
36  for (auto wafer : wafer_) {
37  std::cout << "Wafer[" << i << "] " << wafer << std::endl; ++i;}
38  std::cout << "DDHGCalTBModule: " << covers_.size() << " covers" << std::endl;
39  i = 0;
40  for (auto cover : covers_) {
41  std::cout << "Cover[" << i << "] " << cover << std::endl; ++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_.emplace_back(1);
48  }
49 #ifdef EDM_ML_DEBUG
50  std::cout << "DDHGCalTBModule: " << materials_.size()
51  << " types of volumes" << std::endl;
52  for (unsigned int i=0; i<names_.size(); ++i)
53  std::cout << "Volume [" << i << "] " << names_[i] << " of thickness "
54  << thick_[i] << " filled with " << materials_[i]
55  << " first copy number " << copyNumber_[i] << std::endl;
56 #endif
57  layers_ = dbl_to_int(vArgs["Layers"]);
58  layerThick_ = vArgs["LayerThick"];
59 #ifdef EDM_ML_DEBUG
60  std::cout << "DDHGCalTBModule: " << layers_.size() << " blocks" <<std::endl;
61  for (unsigned int i=0; i<layers_.size(); ++i)
62  std::cout << "Block [" << i << "] of thickness " << layerThick_[i]
63  << " with " << layers_[i] << " layers" << std::endl;
64 #endif
65  layerType_ = dbl_to_int(vArgs["LayerType"]);
66  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
67 #ifdef EDM_ML_DEBUG
68  std::cout << "DDHGCalTBModule: " << layerType_.size() << " layers"
69  << std::endl;
70  for (unsigned int i=0; i<layerType_.size(); ++i)
71  std::cout << "Layer [" << i << "] with material type " << layerType_[i]
72  << " sensitive class " << layerSense_[i] << std::endl;
73 #endif
74  zMinBlock_ = nArgs["zMinBlock"];
75  rMaxFine_ = nArgs["rMaxFine"];
76  waferW_ = nArgs["waferW"];
77  waferGap_ = nArgs["waferGap"];
78  absorbW_ = nArgs["absorberW"];
79  absorbH_ = nArgs["absorberH"];
80  sectors_ = (int)(nArgs["Sectors"]);
81 #ifdef EDM_ML_DEBUG
82  std::cout << "DDHGCalTBModule: zStart " << zMinBlock_ << " rFineCoarse "
83  << rMaxFine_ << " wafer width " << waferW_ << " gap among wafers "
84  << waferGap_ << " absorber width " << absorbW_ <<" absorber height "
85  << absorbH_ << " sectors " << sectors_ << std::endl;
86 #endif
87  slopeB_ = vArgs["SlopeBottom"];
88  slopeT_ = vArgs["SlopeTop"];
89  zFront_ = vArgs["ZFront"];
90  rMaxFront_ = vArgs["RMaxFront"];
91 #ifdef EDM_ML_DEBUG
92  std::cout << "DDHGCalTBModule: Bottom slopes " << slopeB_[0] << ":"
93  << slopeB_[1] << " and " << slopeT_.size() << " slopes for top"
94  << std::endl;
95  for (unsigned int i=0; i<slopeT_.size(); ++i)
96  std::cout << "Block [" << i << "] Zmin " << zFront_[i] << " Rmax "
97  << rMaxFront_[i] << " Slope " << slopeT_[i] << std::endl;
98 #endif
100 #ifdef EDM_ML_DEBUG
101  std::cout << "DDHGCalTBModule: NameSpace " << idNameSpace_ << std::endl;
102 #endif
103 }
104 
106 // DDHGCalTBModule methods...
108 
110 
111 #ifdef EDM_ML_DEBUG
112  std::cout << "==>> Constructing DDHGCalTBModule..." << std::endl;
113 #endif
114  copies_.clear();
115  constructLayers (parent(), cpv);
116 #ifdef EDM_ML_DEBUG
117  std::cout << copies_.size() << " different wafer copy numbers" << std::endl;
118 #endif
119  copies_.clear();
120 #ifdef EDM_ML_DEBUG
121  std::cout << "<<== End of DDHGCalTBModule construction ..." << std::endl;
122 #endif
123 }
124 
126  DDCompactView& cpv) {
127 
128 #ifdef EDM_ML_DEBUG
129  std::cout << "DDHGCalTBModule test: \t\tInside Layers" << std::endl;
130 #endif
131  double zi(zMinBlock_);
132  int laymin(0);
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  double thickTot(0);
139  for (int ly=laymin; ly<laymax; ++ly) {
140  int ii = layerType_[ly];
141  int copy = copyNumber_[ii];
142  double rinB = (layerSense_[ly] == 0) ? (zo*slopeB_[0]) : (zo*slopeB_[1]);
143  zz += (0.5*thick_[ii]);
144  thickTot += thick_[ii];
145 
146  std::string name = "HGCal"+names_[ii]+std::to_string(copy);
147 #ifdef EDM_ML_DEBUG
148  std::cout << "DDHGCalTBModule test: Layer " << ly << ":" << ii
149  << " Front " << zi << ", " << routF << " Back " << zo << ", "
150  << rinB << " superlayer thickness " << layerThick_[i]
151  << std::endl;
152 #endif
153  DDName matName(DDSplit(materials_[ii]).first,
154  DDSplit(materials_[ii]).second);
155  DDMaterial matter(matName);
156  DDLogicalPart glog;
157  if (layerSense_[ly] == 0) {
159  absorbW_, absorbH_, 0.5*thick_[ii]);
160  glog = DDLogicalPart(solid.ddname(), matter, solid);
161 #ifdef EDM_ML_DEBUG
162  std::cout << "DDHGCalTBModule test: " << solid.name()
163  << " box of dimension " << absorbW_ << ":" << absorbH_
164  << ":" << 0.5*thick_[ii] << std::endl;
165 #endif
166  } else {
168  0.5*thick_[ii], rinB, routF, 0.0,
169  CLHEP::twopi);
170  glog = DDLogicalPart(solid.ddname(), matter, solid);
171 #ifdef EDM_ML_DEBUG
172  std::cout << "DDHGCalTBModule test: " << solid.name()
173  << " Tubs made of " << matName << " of dimensions " << rinB
174  << ", " << routF << ", " << 0.5*thick_[ii] << ", 0.0, "
175  << CLHEP::twopi/CLHEP::deg << std::endl;
176 #endif
177  positionSensitive(glog,layerSense_[ly],rinB,routF,cpv);
178  }
179  DDTranslation r1(0,0,zz);
180  DDRotation rot;
181  cpv.position(glog, module, copy, r1, rot);
182  ++copyNumber_[ii];
183 #ifdef EDM_ML_DEBUG
184  std::cout << "DDHGCalTBModule test: " << glog.name() << " number "
185  << copy << " positioned in " << module.name() << " at " << r1
186  << " with " << rot << std::endl;
187 #endif
188  zz += (0.5*thick_[ii]);
189  } // End of loop over layers in a block
190  zi = zo;
191  laymin = laymax;
192  if (fabs(thickTot-layerThick_[i]) < 0.00001) {
193  } else if (thickTot > layerThick_[i]) {
194  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i]
195  << " is smaller than thickness " << thickTot
196  << " of all its components **** ERROR ****\n";
197  } else if (thickTot < layerThick_[i]) {
198  edm::LogWarning("HGCalGeom") << "Thickness of the partition "
199  << layerThick_[i] << " does not match with "
200  << thickTot << " of the components\n";
201  }
202  } // End of loop over blocks
203 }
204 
205 double DDHGCalTBModule::rMax(double z) {
206  double r(0);
207 #ifdef EDM_ML_DEBUG
208  unsigned int ik(0);
209 #endif
210  for (unsigned int k=0; k<slopeT_.size(); ++k) {
211  if (z < zFront_[k]) break;
212  r = rMaxFront_[k] + (z - zFront_[k]) * slopeT_[k];
213 #ifdef EDM_ML_DEBUG
214  ik = k;
215 #endif
216  }
217 #ifdef EDM_ML_DEBUG
218  std::cout << "rMax : " << z << ":" << ik << ":" << r << std::endl;
219 #endif
220  return r;
221 }
222 
224  double rin, double rout,
225  DDCompactView& cpv) {
226  double ww = (waferW_+waferGap_);
227  double dx = 0.5*ww;
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/ww) + 1;
231  int nrow = (int)(rout/(ww*tan(30.0*CLHEP::deg))) + 1;
232  int incm(0), inrm(0), kount(0);
233  double xc[6], yc[6];
234 #ifdef EDM_ML_DEBUG
235  std::cout << glog.ddname() << " rout " << rout << " Row " << nrow
236  << " Column " << ncol << std::endl;
237 #endif
238  for (int nr=-nrow; nr <= nrow; ++nr) {
239  int inr = (nr >= 0) ? nr : -nr;
240  for (int nc=-ncol; nc <= ncol; ++nc) {
241  int inc = (nc >= 0) ? nc : -nc;
242  if (inr%2 == inc%2) {
243  double xpos = nc*dx;
244  double ypos = nr*dy;
245  xc[0] = xpos+dx; yc[0] = ypos-0.5*rr;
246  xc[1] = xpos+dx; yc[1] = ypos+0.5*rr;
247  xc[2] = xpos; yc[2] = ypos+rr;
248  xc[3] = xpos-dx; yc[3] = ypos+0.5*rr;
249  xc[4] = xpos+dx; yc[4] = ypos-0.5*rr;
250  xc[5] = xpos; yc[5] = ypos-rr;
251  bool cornerAll(true);
252  for (int k=0; k<6; ++k) {
253  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
254  if (rpos < rin || rpos > rout) cornerAll = false;
255  }
256  if (cornerAll) {
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;
264  if (type == 1) {
265  name = (rpos < rMaxFine_) ?
266  DDName(DDSplit(wafer_[0]).first, DDSplit(wafer_[0]).second) :
267  DDName(DDSplit(wafer_[1]).first, DDSplit(wafer_[1]).second);
268  } else {
269  name = DDName(DDSplit(covers_[type-2]).first,
270  DDSplit(covers_[type-2]).second);
271  }
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 && type == 1)
277  copies_.insert(copy);
278 #ifdef EDM_ML_DEBUG
279  std::cout << "DDHGCalTBModule: " << 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 << "DDHGCalTBModule: # of columns " << incm << " # of rows "
289  << inrm << " and " << kount << " wafers for " << glog.ddname()
290  << std::endl;
291 #endif
292 }
type
Definition: HCALResponse.h:21
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< std::string > names_
std::vector< std::string > wafer_
const N & name() const
Definition: DDBase.h:78
std::vector< double > layerThick_
def copy(args, dbName)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
~DDHGCalTBModule() override
void positionSensitive(DDLogicalPart &glog, int type, double rin, double rout, DDCompactView &cpv)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
static std::string & ns()
type of data representation of DDCompactView
Definition: DDCompactView.h:90
std::vector< double > rMaxFront_
std::vector< int > layerSense_
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 > zFront_
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< int > layerType_
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:986
std::vector< int > copyNumber_
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:819
std::vector< double > slopeT_
ii
Definition: cuy.py:588
int k[5][pyjets_maxn]
std::string idNameSpace_
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
std::vector< int > layers_
void execute(DDCompactView &cpv) override
std::vector< std::string > covers_
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 > slopeB_
std::vector< double > thick_
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 > materials_
Definition: vlib.h:208
std::unordered_set< int > copies_
double rMax(double z)
const N & ddname() const
Definition: DDBase.h:80