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  std::cout << "HcalGeomParameters::HcalGeomParameters ( const DDCompactView& cpv ) constructor" << std::endl;
23 #endif
24 }
25 
27 #ifdef EDM_ML_DEBUG
28  std::cout << "HcalGeomParameters::destructed!!!" << std::endl;
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  std::cout << "HcalGeomParameters::getEta " << r << " " << z << " ==> "
67  << tmp << std::endl;
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() == 1) {
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() == 3) {
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() == 2) {
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  std::cout << "HB " << sol.name() << " Shape " << sol.shape()
126  << " Layer " << lay << " R " << t.Rho() << std::endl;
127 #endif
128  if (lay >=0 && lay < 20) {
129  ib[lay]++;
130  rb[lay] += t.Rho();
131  if (thkb[lay] <= 0) {
132  if (lay < 17) thkb[lay] = dx;
133  else thkb[lay] = std::min(dx,dy);
134  }
135  if (lay < 17) {
136  bool found = false;
137  for (double k : rxb) {
138  if (std::abs(k-t.Rho()) < 0.01) {
139  found = true;
140  break;
141  }
142  }
143  if (!found) {
144  rxb.emplace_back(t.Rho());
145  php.rhoxHB.emplace_back(t.Rho()*std::cos(t.phi()));
146  php.zxHB.emplace_back(std::abs(t.z()));
147  php.dyHB.emplace_back(2.*dy);
148  php.dxHB.emplace_back(2.*dz);
149  php.layHB.emplace_back(lay);
150  }
151  }
152  }
153  if (lay == 2) {
154  int iz = copy[nsiz-5];
155  int fi = copy[nsiz-4];
156  unsigned int it1 = find(iz, izb);
157  if (it1 == izb.size()) izb.emplace_back(iz);
158  unsigned int it2 = find(fi, phib);
159  if (it2 == phib.size()) phib.emplace_back(fi);
160  }
161  if (lay == 18) {
162  int ifi=-1, ich=-1;
163  if (nsiz>2) ifi = copy[nsiz-3];
164  if (nsiz>3) ich = copy[nsiz-4];
165  double z1 = std::abs((t.z()) + dz);
166  double z2 = std::abs((t.z()) - dz);
167  if (std::abs(z1-z2) < 0.01) z1 = 0;
168  if (ifi == 1 && ich == 4) {
169  if (z1 > z2) {
170  double tmp = z1;
171  z1 = z2;
172  z2 = tmp;
173  }
174  bool sok = true;
175  for (unsigned int kk=0; kk<php.zHO.size(); kk++) {
176  if (std::abs(z2-php.zHO[kk]) < 0.01) {
177  sok = false;
178  break;
179  } else if (z2 < php.zHO[kk]) {
180  php.zHO.resize(php.zHO.size()+2);
181  for (unsigned int kz=php.zHO.size()-1; kz>kk+1; kz=kz-2) {
182  php.zHO[kz] = php.zHO[kz-2];
183  php.zHO[kz-1] = php.zHO[kz-3];
184  }
185  php.zHO[kk+1] = z2;
186  php.zHO[kk] = z1;
187  sok = false;
188  break;
189  }
190  }
191  if (sok) {
192  php.zHO.emplace_back(z1);
193  php.zHO.emplace_back(z2);
194  }
195 #ifdef EDM_ML_DEBUG
196  std::cout << "Detector " << idet << " Lay " << lay << " fi " << ifi
197  << " " << ich << " z " << z1 << " " << z2 << std::endl;
198 #endif
199  }
200  }
201  } else if (idet == 4) {
202  // HE
203 #ifdef EDM_ML_DEBUG
204  std::cout << "HE " << sol.name() << " Shape " << sol.shape()
205  << " Layer " << lay << " Z " << t.z() << std::endl;
206 #endif
207  if (lay >=0 && lay < 20) {
208  ie[lay]++;
209  ze[lay] += std::abs(t.z());
210  if (thke[lay] <= 0) thke[lay] = dz;
211 #ifdef EDM_ML_DEBUG
212  double rinHE = t.Rho()*cos(alp) - dy;
213  double routHE = t.Rho()*cos(alp) + dy;
214  rminHE[lay] += rinHE;
215  rmaxHE[lay] += routHE;
216 #endif
217  bool found = false;
218  for (double k : php.zxHE) {
219  if (std::abs(k-std::abs(t.z())) < 0.01) {
220  found = true;
221  break;
222  }
223  }
224  if (!found) {
225  php.zxHE.emplace_back(std::abs(t.z()));
226  php.rhoxHE.emplace_back(t.Rho()*std::cos(t.phi()));
227  php.dyHE.emplace_back(dy*std::cos(t.phi()));
228  dx1 -= 0.5*(t.rho()-dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
229  dx2 -= 0.5*(t.rho()+dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
230  php.dx1HE.emplace_back(-dx1);
231  php.dx2HE.emplace_back(-dx2);
232  php.layHE.emplace_back(lay);
233  }
234  }
235  if (copy[nsiz-1] == 21 || copy[nsiz-1] == 71) {
236  int iz = copy[nsiz-7];
237  int fi = copy[nsiz-5];
238  unsigned int it1 = find(iz, ize);
239  if (it1 == ize.size()) ize.emplace_back(iz);
240  unsigned int it2 = find(fi, phie);
241  if (it2 == phie.size()) phie.emplace_back(fi);
242  }
243  } else if (idet == 5) {
244  // HF
245  if (!hf) {
246  const std::vector<double> & paras = sol.parameters();
247 #ifdef EDM_ML_DEBUG
248  std::cout << "HF " << sol.name() << " Shape " << sol.shape()
249  << " Z " << t.z() << " with " << paras.size()
250  << " Parameters" << std::endl;
251  for (unsigned j=0; j<paras.size(); j++)
252  std::cout << "HF Parameter[" << j << "] = " << paras[j] << std::endl;
253 #endif
254  if (sol.shape() == ddpolycone_rrz) {
255  int nz = (int)(paras.size())-3;
256  dzVcal = 0.5*(paras[nz]-paras[3]);
257  hf = true;
258  } else if (sol.shape() == ddtubs || sol.shape() == ddcons) {
259  dzVcal = paras[0];
260  hf = true;
261  }
262  }
263 #ifdef EDM_ML_DEBUG
264  } else {
265  std::cout << "Unknown Detector " << idet << " for " << sol.name()
266  << " Shape " << sol.shape() << " R " << t.Rho() << " Z "
267  << t.z() << std::endl;
268 #endif
269  }
270  dodet = fv.next();
271  }
272 
273  int ibmx = 0, iemx = 0;
274  for (int i = 0; i < 20; i++) {
275  if (ib[i]>0) {
276  rb[i] /= (double)(ib[i]);
277  ibmx = i+1;
278  }
279  if (ie[i]>0) {
280  ze[i] /= (double)(ie[i]);
281  iemx = i+1;
282  }
283 #ifdef EDM_ML_DEBUG
284  if (ie[i]> 0) {
285  rminHE[i] /= (double)(ie[i]);
286  rmaxHE[i] /= (double)(ie[i]);
287  }
288  std::cout << "Index " << i << " Barrel " << ib[i] << " "
289  << rb[i] << " Endcap " << ie[i] << " " << ze[i] << ":"
290  << rminHE[i] << ":" << rmaxHE[i] << std::endl;
291 #endif
292  }
293  for (int i = 4; i >= 0; i--) {
294  if (ib[i] == 0) {rb[i] = rb[i+1]; thkb[i] = thkb[i+1];}
295  if (ie[i] == 0) {ze[i] = ze[i+1]; thke[i] = thke[i+1];}
296 #ifdef EDM_ML_DEBUG
297  if (ib[i] == 0 || ie[i] == 0)
298  std::cout << "Index " << i << " Barrel " << ib[i] << " "
299  << rb[i] << " Endcap " << ie[i] << " " << ze[i] << std::endl;
300 #endif
301  }
302 
303 #ifdef EDM_ML_DEBUG
304  for (unsigned int k=0; k<php.layHB.size(); ++k)
305  std::cout << "HB: " << php.layHB[k] << " R " << rxb[k] << " " << php.rhoxHB[k] << " Z " << php.zxHB[k] << " DY " << php.dyHB[k] << " DZ " << php.dxHB[k] << "\n";
306  for (unsigned int k=0; k<php.layHE.size(); ++k)
307  std::cout << "HE: " << php.layHE[k] << " R " << php.rhoxHE[k] << " Z " << php.zxHE[k] << " X1|X2 " << php.dx1HE[k] << "|" << php.dx2HE[k] << " DY " << php.dyHE[k] << "\n";
308  std::cout << "HcalGeomParameters: Maximum Layer for HB " << ibmx << " for HE "
309  << iemx << " extent " << dzVcal << std::endl;
310 #endif
311 
312  if (ibmx > 0) {
313  php.rHB.resize(ibmx);
314  php.drHB.resize(ibmx);
315  for (int i=0; i<ibmx; i++) {
316  php.rHB[i] = rb[i];
317  php.drHB[i] = thkb[i];
318 #ifdef EDM_ML_DEBUG
319  std::cout << "HcalGeomParameters: php.rHB[" << i << "] = " << php.rHB[i]
320  << " php.drHB[" << i << "] = " << php.drHB[i] << std::endl;
321 #endif
322  }
323  }
324  if (iemx > 0) {
325  php.zHE.resize(iemx);
326  php.dzHE.resize(iemx);
327  for (int i=0; i<iemx; i++) {
328  php.zHE[i] = ze[i];
329  php.dzHE[i] = thke[i];
330 #ifdef EDM_ML_DEBUG
331  std::cout << "HcalGeomParameters: php.zHE[" << i << "] = " << php.zHE[i]
332  << " php.dzHE[" << i << "] = " << php.dzHE[i] << std::endl;
333 #endif
334  }
335  }
336 
337  nzHB = (int)(izb.size());
338  nmodHB = (int)(phib.size());
339 #ifdef EDM_ML_DEBUG
340  std::cout << "HcalGeomParameters::loadGeometry: " << nzHB
341  << " barrel half-sectors" << std::endl;
342  for (int i=0; i<nzHB; i++)
343  std::cout << "Section " << i << " Copy number " << izb[i] << std::endl;
344  std::cout << "HcalGeomParameters::loadGeometry: " << nmodHB
345  << " barrel modules" << std::endl;
346  for (int i=0; i<nmodHB; i++)
347  std::cout << "Module " << i << " Copy number " << phib[i] << std::endl;
348 #endif
349 
350  nzHE = (int)(ize.size());
351  nmodHE = (int)(phie.size());
352 #ifdef EDM_ML_DEBUG
353  std::cout << "HcalGeomParameters::loadGeometry: " << nzHE
354  << " endcap half-sectors" << std::endl;
355  for (int i=0; i<nzHE; i++)
356  std::cout << "Section " << i << " Copy number " << ize[i] << std::endl;
357  std::cout << "HcalGeomParameters::loadGeometry: " << nmodHE
358  << " endcap modules" << std::endl;
359  for (int i=0; i<nmodHE; i++)
360  std::cout << "Module " << i << " Copy number " << phie[i] << std::endl;
361 #endif
362 
363 #ifdef EDM_ML_DEBUG
364  std::cout << "HO has Z of size " << php.zHO.size() << std::endl;
365  for (unsigned int kk=0; kk<php.zHO.size(); kk++)
366  std::cout << "ZHO[" << kk << "] = " << php.zHO[kk] << std::endl;
367 #endif
368  if (ibmx > 17 && php.zHO.size() > 4) {
369  rminHO = php.rHB[17]-100.0;
370  etaHO[0] = getEta(0.5*(php.rHB[17]+php.rHB[18]), php.zHO[1]);
371  etaHO[1] = getEta(php.rHB[18]+php.drHB[18], php.zHO[2]);
372  etaHO[2] = getEta(php.rHB[18]-php.drHB[18], php.zHO[3]);
373  etaHO[3] = getEta(php.rHB[18]+php.drHB[18], php.zHO[4]);
374  } else {
375  rminHO =-1.0;
376  etaHO[0] = etaHO[1] = etaHO[2] = etaHO[3] = 0;
377  }
378 #ifdef EDM_ML_DEBUG
379  std::cout << "HO Eta boundaries " << etaHO[0] << " " << etaHO[1]
380  << " " << etaHO[2] << " " << etaHO[3] << std::endl;
381  std::cout << "HO Parameters " << rminHO << " " << php.zHO.size();
382  for (int i=0; i<4; ++i) std::cout << " eta[" << i << "] = " << etaHO[i];
383  for (unsigned int i=0; i<php.zHO.size(); ++i) std::cout << " zho[" << i << "] = " << php.zHO[i];
384  std::cout << std::endl;
385 #endif
386 }
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:150
double halfZ(void) const
half of the z-Axis
Definition: DDSolid.cc:165
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:280
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:177
const N & name() const
Definition: DDBase.h:78
double halfY(void) const
Definition: DDSolid.cc:276
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:38
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:192
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:79
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:174
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:144
T min(T a, T b)
Definition: MathUtil.h:58
double rOut(void) const
Definition: DDSolid.cc:611
int k[5][pyjets_maxn]
std::vector< double > dyHB
double halfX(void) const
Definition: DDSolid.cc:272
Interface to a Box.
Definition: DDSolid.h:164
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:183
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:195
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:180
double zhalf(void) const
Definition: DDSolid.cc:605
double getEta(double r, double z) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
if(dp >Float(M_PI)) dp-
std::vector< double > drHB
double y2(void) const
Half-length along y of the face at +pDz.
Definition: DDSolid.cc:186
const DDTranslation & translation() const
The absolute translation of the current node.
double rIn(void) const
Definition: DDSolid.cc:608
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:189
ib
Definition: cuy.py:660