CMS 3D CMS Logo

HcalGeomParameters.cc
Go to the documentation of this file.
2 
5 
15 #include "CLHEP/Units/GlobalPhysicalConstants.h"
16 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 
18 //#define EDM_ML_DEBUG
19 
21 #ifdef EDM_ML_DEBUG
22  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::HcalGeomParameters ( const DDCompactView& cpv ) constructor";
23 #endif
24 }
25 
27 #ifdef EDM_ML_DEBUG
28  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::destructed!!!";
29 #endif
30 }
31 
32 void HcalGeomParameters::getConstRHO( std::vector<double>& rHO ) const {
33 
34  rHO.emplace_back(rminHO);
35  for (double i : etaHO) rHO.emplace_back(i);
36 }
37 
38 std::vector<int> HcalGeomParameters::getModHalfHBHE(const int type) const {
39 
40  std::vector<int> modHalf;
41  if (type == 0) {
42  modHalf.emplace_back(nmodHB); modHalf.emplace_back(nzHB);
43  } else {
44  modHalf.emplace_back(nmodHE); modHalf.emplace_back(nzHE);
45  }
46  return modHalf;
47 }
48 
49 unsigned int HcalGeomParameters::find(int element,
50  std::vector<int>& array) const {
51  unsigned int id = array.size();
52  for (unsigned int i = 0; i < array.size(); i++) {
53  if (element == array[i]) {
54  id = i;
55  break;
56  }
57  }
58  return id;
59 }
60 
61 double HcalGeomParameters::getEta(double r, double z) const {
62 
63  double tmp = 0;
64  if (z != 0) tmp = -log(tan(0.5*atan(r/z)));
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::getEta " << r << " "
67  << z << " ==> " << tmp;
68 #endif
69  return tmp;
70 }
71 
73  HcalParameters& php) {
74 
75  DDFilteredView fv = _fv;
76  bool dodet=true, hf=false;
77  std::vector<double> rb(20,0.0), ze(20,0.0), thkb(20,-1.0), thke(20,-1.0);
78  std::vector<int> ib(20,0), ie(20,0);
79  std::vector<int> izb, phib, ize, phie;
80  std::vector<double> rxb;
81 #ifdef EDM_ML_DEBUG
82  std::vector<double> rminHE(20,0.0), rmaxHE(20,0.0);
83 #endif
84  php.rhoxHB.clear(); php.zxHB.clear(); php.dyHB.clear(); php.dxHB.clear();
85  php.layHB.clear(); php.layHE.clear();
86  php.zxHE.clear(); php.rhoxHE.clear(); php.dyHE.clear(); php.dx1HE.clear(); php.dx2HE.clear();
87  dzVcal = -1.;
88 
89  while (dodet) {
91  std::vector<int> copy = fv.copyNumbers();
92  const DDSolid & sol = fv.logicalPart().solid();
93  int idet = 0, lay = -1;
94  int nsiz = (int)(copy.size());
95  if (nsiz>0) lay = copy[nsiz-1]/10;
96  if (nsiz>1) idet = copy[nsiz-2]/1000;
97  double dx=0, dy=0, dz=0, dx1=0, dx2=0;
98 #ifdef EDM_ML_DEBUG
99  double alp(0);
100 #endif
101  if (sol.shape() == DDSolidShape::ddbox) {
102  const DDBox & box = static_cast<DDBox>(fv.logicalPart().solid());
103  dx = box.halfX();
104  dy = box.halfY();
105  dz = box.halfZ();
106  } else if (sol.shape() == DDSolidShape::ddtrap) {
107  const DDTrap & trp = static_cast<DDTrap>(fv.logicalPart().solid());
108  dx1= trp.x1();
109  dx2= trp.x2();
110  dx = 0.25*(trp.x1()+trp.x2()+trp.x3()+trp.x4());
111  dy = 0.5*(trp.y1()+trp.y2());
112  dz = trp.halfZ();
113 #ifdef EDM_ML_DEBUG
114  alp= 0.5*(trp.alpha1()+trp.alpha2());
115 #endif
116  } else if (sol.shape() == DDSolidShape::ddtubs) {
117  const DDTubs & tub = static_cast<DDTubs>(fv.logicalPart().solid());
118  dx = tub.rIn();
119  dy = tub.rOut();
120  dz = tub.zhalf();
121  }
122  if (idet == 3) {
123  // HB
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HCalGeom") << "HB " << sol.name() << " Shape "
126  << sol.shape() << " Layer " << lay << " R "
127  << t.Rho();
128 #endif
129  if (lay >=0 && lay < 20) {
130  ib[lay]++;
131  rb[lay] += t.Rho();
132  if (thkb[lay] <= 0) {
133  if (lay < 17) thkb[lay] = dx;
134  else thkb[lay] = std::min(dx,dy);
135  }
136  if (lay < 17) {
137  bool found = false;
138  for (double k : rxb) {
139  if (std::abs(k-t.Rho()) < 0.01) {
140  found = true;
141  break;
142  }
143  }
144  if (!found) {
145  rxb.emplace_back(t.Rho());
146  php.rhoxHB.emplace_back(t.Rho()*std::cos(t.phi()));
147  php.zxHB.emplace_back(std::abs(t.z()));
148  php.dyHB.emplace_back(2.*dy);
149  php.dxHB.emplace_back(2.*dz);
150  php.layHB.emplace_back(lay);
151  }
152  }
153  }
154  if (lay == 2) {
155  int iz = copy[nsiz-5];
156  int fi = copy[nsiz-4];
157  unsigned int it1 = find(iz, izb);
158  if (it1 == izb.size()) izb.emplace_back(iz);
159  unsigned int it2 = find(fi, phib);
160  if (it2 == phib.size()) phib.emplace_back(fi);
161  }
162  if (lay == 18) {
163  int ifi=-1, ich=-1;
164  if (nsiz>2) ifi = copy[nsiz-3];
165  if (nsiz>3) ich = copy[nsiz-4];
166  double z1 = std::abs((t.z()) + dz);
167  double z2 = std::abs((t.z()) - dz);
168  if (std::abs(z1-z2) < 0.01) z1 = 0;
169  if (ifi == 1 && ich == 4) {
170  if (z1 > z2) {
171  double tmp = z1;
172  z1 = z2;
173  z2 = tmp;
174  }
175  bool sok = true;
176  for (unsigned int kk=0; kk<php.zHO.size(); kk++) {
177  if (std::abs(z2-php.zHO[kk]) < 0.01) {
178  sok = false;
179  break;
180  } else if (z2 < php.zHO[kk]) {
181  php.zHO.resize(php.zHO.size()+2);
182  for (unsigned int kz=php.zHO.size()-1; kz>kk+1; kz=kz-2) {
183  php.zHO[kz] = php.zHO[kz-2];
184  php.zHO[kz-1] = php.zHO[kz-3];
185  }
186  php.zHO[kk+1] = z2;
187  php.zHO[kk] = z1;
188  sok = false;
189  break;
190  }
191  }
192  if (sok) {
193  php.zHO.emplace_back(z1);
194  php.zHO.emplace_back(z2);
195  }
196 #ifdef EDM_ML_DEBUG
197  edm::LogVerbatim("HCalGeom") << "Detector " << idet << " Lay "
198  << lay << " fi " << ifi << " " << ich
199  << " z " << z1 << " " << z2;
200 #endif
201  }
202  }
203  } else if (idet == 4) {
204  // HE
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HCalGeom") << "HE " << sol.name() << " Shape "
207  << sol.shape() << " Layer " << lay << " Z "
208  << t.z();
209 #endif
210  if (lay >=0 && lay < 20) {
211  ie[lay]++;
212  ze[lay] += std::abs(t.z());
213  if (thke[lay] <= 0) thke[lay] = dz;
214 #ifdef EDM_ML_DEBUG
215  double rinHE = t.Rho()*cos(alp) - dy;
216  double routHE = t.Rho()*cos(alp) + dy;
217  rminHE[lay] += rinHE;
218  rmaxHE[lay] += routHE;
219 #endif
220  bool found = false;
221  for (double k : php.zxHE) {
222  if (std::abs(k-std::abs(t.z())) < 0.01) {
223  found = true;
224  break;
225  }
226  }
227  if (!found) {
228  php.zxHE.emplace_back(std::abs(t.z()));
229  php.rhoxHE.emplace_back(t.Rho()*std::cos(t.phi()));
230  php.dyHE.emplace_back(dy*std::cos(t.phi()));
231  dx1 -= 0.5*(t.rho()-dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
232  dx2 -= 0.5*(t.rho()+dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
233  php.dx1HE.emplace_back(-dx1);
234  php.dx2HE.emplace_back(-dx2);
235  php.layHE.emplace_back(lay);
236  }
237  }
238  if (copy[nsiz-1] == 21 || copy[nsiz-1] == 71) {
239  int iz = copy[nsiz-7];
240  int fi = copy[nsiz-5];
241  unsigned int it1 = find(iz, ize);
242  if (it1 == ize.size()) ize.emplace_back(iz);
243  unsigned int it2 = find(fi, phie);
244  if (it2 == phie.size()) phie.emplace_back(fi);
245  }
246  } else if (idet == 5) {
247  // HF
248  if (!hf) {
249  const std::vector<double> & paras = sol.parameters();
250 #ifdef EDM_ML_DEBUG
251  edm::LogVerbatim("HCalGeom") << "HF " << sol.name() << " Shape "
252  << sol.shape() << " Z " << t.z()
253  << " with " << paras.size()
254  << " Parameters";
255  for (unsigned j=0; j<paras.size(); j++)
256  edm::LogVerbatim("HCalGeom") << "HF Parameter[" << j << "] = "
257  << paras[j];
258 #endif
259  if (sol.shape() == DDSolidShape::ddpolycone_rrz) {
260  int nz = (int)(paras.size())-3;
261  dzVcal = 0.5*(paras[nz]-paras[3]);
262  hf = true;
263  } else if (sol.shape() == DDSolidShape::ddtubs || sol.shape() == DDSolidShape::ddcons) {
264  dzVcal = paras[0];
265  hf = true;
266  }
267  }
268 #ifdef EDM_ML_DEBUG
269  } else {
270  edm::LogVerbatim("HCalGeom") << "Unknown Detector " << idet << " for "
271  << sol.name() << " Shape " << sol.shape()
272  << " R " << t.Rho() << " Z " << t.z();
273 #endif
274  }
275  dodet = fv.next();
276  }
277 
278  int ibmx = 0, iemx = 0;
279  for (int i = 0; i < 20; i++) {
280  if (ib[i]>0) {
281  rb[i] /= (double)(ib[i]);
282  ibmx = i+1;
283  }
284  if (ie[i]>0) {
285  ze[i] /= (double)(ie[i]);
286  iemx = i+1;
287  }
288 #ifdef EDM_ML_DEBUG
289  if (ie[i]> 0) {
290  rminHE[i] /= (double)(ie[i]);
291  rmaxHE[i] /= (double)(ie[i]);
292  }
293  edm::LogVerbatim("HCalGeom") << "Index " << i << " Barrel " << ib[i] << " "
294  << rb[i] << " Endcap " << ie[i] << " "
295  << ze[i] << ":" << rminHE[i] << ":"
296  << rmaxHE[i];
297 #endif
298  }
299  for (int i = 4; i >= 0; i--) {
300  if (ib[i] == 0) {rb[i] = rb[i+1]; thkb[i] = thkb[i+1];}
301  if (ie[i] == 0) {ze[i] = ze[i+1]; thke[i] = thke[i+1];}
302 #ifdef EDM_ML_DEBUG
303  if (ib[i] == 0 || ie[i] == 0)
304  edm::LogVerbatim("HCalGeom") << "Index " << i << " Barrel " << ib[i]
305  << " " << rb[i] << " Endcap " << ie[i]
306  << " " << ze[i];
307 #endif
308  }
309 
310 #ifdef EDM_ML_DEBUG
311  for (unsigned int k=0; k<php.layHB.size(); ++k)
312  edm::LogVerbatim("HCalGeom") << "HB: " << php.layHB[k] << " R " << rxb[k]
313  << " " << php.rhoxHB[k] << " Z "
314  << php.zxHB[k] << " DY " << php.dyHB[k]
315  << " DZ " << php.dxHB[k];
316  for (unsigned int k=0; k<php.layHE.size(); ++k)
317  edm::LogVerbatim("HCalGeom") << "HE: " << php.layHE[k] << " R "
318  << php.rhoxHE[k] << " Z " << php.zxHE[k]
319  << " X1|X2 " << php.dx1HE[k] << "|"
320  << php.dx2HE[k] << " DY " << php.dyHE[k];
321  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters: Maximum Layer for HB "
322  << ibmx << " for HE " << iemx << " extent "
323  << dzVcal;
324 #endif
325 
326  if (ibmx > 0) {
327  php.rHB.resize(ibmx);
328  php.drHB.resize(ibmx);
329  for (int i=0; i<ibmx; i++) {
330  php.rHB[i] = rb[i];
331  php.drHB[i] = thkb[i];
332 #ifdef EDM_ML_DEBUG
333  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters: php.rHB[" << i
334  << "] = " << php.rHB[i] << " php.drHB["
335  << i << "] = " << php.drHB[i];
336 #endif
337  }
338  }
339  if (iemx > 0) {
340  php.zHE.resize(iemx);
341  php.dzHE.resize(iemx);
342  for (int i=0; i<iemx; i++) {
343  php.zHE[i] = ze[i];
344  php.dzHE[i] = thke[i];
345 #ifdef EDM_ML_DEBUG
346  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters: php.zHE[" << i
347  << "] = " << php.zHE[i] << " php.dzHE["
348  << i << "] = " << php.dzHE[i];
349 #endif
350  }
351  }
352 
353  nzHB = (int)(izb.size());
354  nmodHB = (int)(phib.size());
355 #ifdef EDM_ML_DEBUG
356  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::loadGeometry: " << nzHB
357  << " barrel half-sectors";
358  for (int i=0; i<nzHB; i++)
359  edm::LogVerbatim("HCalGeom") << "Section " << i << " Copy number "
360  << izb[i];
361  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::loadGeometry: "
362  << nmodHB << " barrel modules";
363  for (int i=0; i<nmodHB; i++)
364  edm::LogVerbatim("HCalGeom") << "Module " << i << " Copy number "
365  << phib[i];
366 #endif
367 
368  nzHE = (int)(ize.size());
369  nmodHE = (int)(phie.size());
370 #ifdef EDM_ML_DEBUG
371  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::loadGeometry: " << nzHE
372  << " endcap half-sectors";
373  for (int i=0; i<nzHE; i++)
374  edm::LogVerbatim("HCalGeom") << "Section " << i << " Copy number "
375  << ize[i];
376  edm::LogVerbatim("HCalGeom") << "HcalGeomParameters::loadGeometry: "
377  << nmodHE << " endcap modules";
378  for (int i=0; i<nmodHE; i++)
379  edm::LogVerbatim("HCalGeom") << "Module " << i << " Copy number "
380  << phie[i];
381 #endif
382 
383 #ifdef EDM_ML_DEBUG
384  edm::LogVerbatim("HCalGeom") << "HO has Z of size " << php.zHO.size();
385  for (unsigned int kk=0; kk<php.zHO.size(); kk++)
386  edm::LogVerbatim("HCalGeom") << "ZHO[" << kk << "] = " << php.zHO[kk];
387 #endif
388  if (ibmx > 17 && php.zHO.size() > 4) {
389  rminHO = php.rHB[17]-100.0;
390  etaHO[0] = getEta(0.5*(php.rHB[17]+php.rHB[18]), php.zHO[1]);
391  etaHO[1] = getEta(php.rHB[18]+php.drHB[18], php.zHO[2]);
392  etaHO[2] = getEta(php.rHB[18]-php.drHB[18], php.zHO[3]);
393  etaHO[3] = getEta(php.rHB[18]+php.drHB[18], php.zHO[4]);
394  } else {
395  rminHO =-1.0;
396  etaHO[0] = etaHO[1] = etaHO[2] = etaHO[3] = 0;
397  }
398 #ifdef EDM_ML_DEBUG
399  edm::LogVerbatim("HCalGeom") << "HO Eta boundaries " << etaHO[0] << " "
400  << etaHO[1] << " " << etaHO[2] << " "
401  << etaHO[3];
402  edm::LogVerbatim("HCalGeom") << "HO Parameters " << rminHO << " "
403  << php.zHO.size();
404  for (unsigned int i=0; i<php.zHO.size(); ++i)
405  edm::LogVerbatim("HCalGeom") << " zho[" << i << "] = " << php.zHO[i];
406 #endif
407 }
type
Definition: HCALResponse.h:21
std::vector< double > zHO
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:144
double halfZ(void) const
half of the z-Axis
Definition: DDSolid.cc:159
void loadGeometry(const DDFilteredView &_fv, HcalParameters &php)
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
double halfZ(void) const
Definition: DDSolid.cc:274
std::vector< int > layHE
double x1(void) const
Half-length along x of the side at y=-pDy1 of the face at -pDz.
Definition: DDSolid.cc:171
const N & name() const
Definition: DDBase.h:74
double halfY(void) const
Definition: DDSolid.cc:270
def copy(args, dbName)
std::vector< double > rHB
nav_type copyNumbers() const
return the stack of copy numbers
unsigned find(int element, std::vector< int > &array) const
std::vector< double > rhoxHB
std::vector< int > getModHalfHBHE(const int type) const
std::vector< double > dx2HE
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
void getConstRHO(std::vector< double > &) const
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
std::vector< double > rhoxHE
std::vector< double > zxHE
std::vector< double > zHE
std::vector< double > dyHE
std::vector< double > zxHB
double x4(void) const
Half-length along x of the side at y=+pDy2 of the face at +pDz.
Definition: DDSolid.cc:186
bool next()
set current node to the next node in the filtered tree
std::vector< double > dx1HE
std::vector< double > dzHE
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Interface to a Trapezoid.
Definition: DDSolid.h:78
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double y1(void) const
Half-length along y of the face at -pDz.
Definition: DDSolid.cc:168
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
T min(T a, T b)
Definition: MathUtil.h:58
double rOut(void) const
Definition: DDSolid.cc:584
int k[5][pyjets_maxn]
std::vector< double > dyHB
double halfX(void) const
Definition: DDSolid.cc:266
Interface to a Box.
Definition: DDSolid.h:163
double alpha1(void) const
Angle with respect to the y axis from the centre of the side at y=-pDy1 to the centre at y=+pDy1 of t...
Definition: DDSolid.cc:177
double alpha2(void) const
Angle with respect to the y axis from the centre of the side at y=-pDy2 to the centre at y=+pDy2 of t...
Definition: DDSolid.cc:189
std::vector< double > dxHB
double x2(void) const
Half-length along x of the side at y=+pDy1 of the face at -pDz.
Definition: DDSolid.cc:174
double zhalf(void) const
Definition: DDSolid.cc:578
double getEta(double r, double z) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< double > drHB
double y2(void) const
Half-length along y of the face at +pDz.
Definition: DDSolid.cc:180
const DDTranslation & translation() const
The absolute translation of the current node.
double rIn(void) const
Definition: DDSolid.cc:581
std::vector< int > layHB
double x3(void) const
Half-length along x of the side at y=-pDy2 of the face at +pDz.
Definition: DDSolid.cc:183
ib
Definition: cuy.py:662