6 #include "CLHEP/Units/GlobalPhysicalConstants.h"
7 #include "CLHEP/Units/GlobalSystemOfUnits.h"
16 : hpar(
hp), hcons(hc) {
18 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants::HcalDDDRecConstants (const HcalParameters* hp) constructor";
35 if (it->layer ==
eta + 1)
36 return it->layerGroup;
37 if (it->layer >
eta + 1)
38 return last->layerGroup;
41 return last->layerGroup;
46 for (
unsigned int lay = 0; lay <
layers.size(); ++lay)
55 const unsigned int&
eta)
const {
62 for (
unsigned int lay = 0; lay <
layers.size(); ++lay)
69 std::vector<HcalDDDRecConstants::HcalEtaBin>
bins;
70 unsigned int type = (itype == 0) ? 0 : 1;
72 std::vector<int> phiSp;
75 for (
int iz = 0; iz < 2; ++iz) {
76 int zside = 2 * iz - 1;
78 std::vector<std::pair<int, double>> phis =
getPhis(subdet,
ieta);
79 std::vector<std::pair<int, double>> phiUse;
81 if (subdet == subdetSp) {
82 for (
auto&
phi : phis) {
84 phiUse.emplace_back(
phi);
88 phiUse.insert(phiUse.end(), phis.begin(), phis.end());
94 if (subdetSp == subdet) {
96 std::vector<std::pair<int, double>> phis =
getPhis(subdet,
ieta);
97 for (
int iz = 0; iz < 2; ++iz) {
98 int zside = 2 * iz - 1;
99 std::vector<std::pair<int, double>> phiUse;
100 for (
int i : phiSp) {
101 for (
auto&
phi : phis) {
103 phiUse.emplace_back(
phi);
108 if (!phiUse.empty()) {
117 for (
unsigned int i = 0;
i <
bins.size(); ++
i) {
119 <<
bins[
i].etaMax <<
"), Zside = " <<
bins[
i].zside <<
", phis = ("
120 <<
bins[
i].phis.size() <<
":" <<
bins[
i].dphi <<
") and " <<
bins[
i].layer.size()
121 <<
" depths (start) " <<
bins[
i].depthStart;
122 for (
unsigned int k = 0;
k <
bins[
i].layer.size(); ++
k)
125 for (
unsigned int k = 0;
k <
bins[
i].phis.size(); ++
k)
136 (subdet == static_cast<int>(
HcalOuter))) {
141 phi = foff + (kphi - 0.5) *
phibin[ietaAbs - 1];
145 int kphi = (
unit == 4) ? ((
iphi - 3) / 4 + 1) : ((
iphi - 1) / 2 + 1);
155 edm::LogVerbatim(
"HcalGeom") <<
"getEtaPhi: subdet|ieta|iphi " << subdet <<
"|" <<
ieta <<
"|" <<
iphi <<
" eta|phi "
158 return std::pair<double, double>(
eta,
phi);
162 int ieta = (keta > 0) ? keta : -keta;
163 int zside = (keta > 0) ? 1 : -1;
165 if ((subdet == static_cast<int>(
HcalOuter)) ||
174 phi0 = (
iphi + 1) / 2;
176 }
else if (
unit == 4) {
177 phi0 = (
iphi + 1) / 4;
196 kphi = (kphi - 1) % 4 + 1;
197 if (kphi == 2 || kphi == 3)
205 << lay <<
" output " <<
eta <<
":" <<
phi <<
":" <<
depth;
211 std::vector<HcalDDDRecConstants::HFCellParameters>
cells;
214 for (
unsigned int k = 0;
k <
nEta; ++
k) {
217 int iphi = (dphi == 4) ? 3 : 1;
218 int nphi = 72 / dphi;
240 for (
unsigned int k = 0;
k <
nEta; ++
k) {
243 int iphi = (dphi == 4) ? 3 : 1;
244 int nphi = 72 / dphi;
255 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants returns " <<
cells.size() <<
" HF cell parameters";
256 for (
unsigned int k = 0;
k <
cells.size(); ++
k)
272 for (std::map<int, int>::iterator itr =
layers.begin(); itr !=
layers.end(); ++itr)
278 int subdet = (idet == 1) ? 1 : 2;
283 if (layBack < 0 && eta <= hpar->
etaMax[1]) {
291 if (layBack < 0 || layBack > laymax)
295 <<
" Output " << layBack;
301 int subdet = (idet == 1) ? 1 : 2;
306 if ((layFront < 0) || ((subdet == static_cast<int>(
HcalEndcap)) && (
eta == 16))) {
307 if ((subdet == static_cast<int>(
HcalEndcap)) && (
eta == 16)) {
309 }
else if (eta <= hpar->
etaMax[1]) {
312 if ((
int)(
k) >= laymin) {
320 if (layFront < laymin)
325 <<
" Output " << layFront;
331 unsigned int type = (itype == 0) ? 0 : 1;
348 <<
" Output " << lmax;
358 }
else if (itype == 3) {
361 unsigned int type = (itype == 0) ? 0 : 1;
374 std::vector<std::pair<int, double>> phis;
378 double fioff = ficons.first;
380 int nphi =
int((2._pi + 0.1 * dphi) / dphi);
382 for (
int ifi = 0; ifi <
nphi; ++ifi) {
383 double phi = -fioff + (ifi + 0.5) * dphi;
385 phis.emplace_back(std::pair<int, double>(
iphi,
phi));
388 edm::LogVerbatim(
"HcalGeom") <<
"getEtaPhi: subdet|ieta|iphi " << subdet <<
"|" <<
ieta <<
" with " << phis.size()
390 for (
unsigned int k = 0;
k < phis.size(); ++
k)
403 int zside = (
k > 0) ? 1 : -1;
404 int phi = (
k > 0) ?
k : -
k;
405 phiz.emplace_back(std::pair<int, int>(
phi,
zside));
409 edm::LogVerbatim(
"HcalGeom") <<
"Special RBX for detector " << subdet <<
" with " << phiz.size() <<
" phi/z bins";
410 for (
unsigned int k = 0;
k < phiz.size(); ++
k)
411 edm::LogVerbatim(
"HcalGeom") <<
" [" <<
k <<
"] " << phiz[
k].first <<
":" << phiz[
k].second;
426 <<
depth <<
" lay|rz " << layf <<
"|" << rz;
442 int subdet =
id.subdetId();
443 int ieta =
id.ieta();
444 int iphi =
id.iphi();
445 int depth =
id.depth();
448 double rzf = (layf < 0)
453 double rzb = (layb < 0)
459 <<
depth <<
" lay|rz (front) " << layf <<
"|" << rzf <<
" lay|rz (back) " << layb <<
"|"
462 return std::pair<double, double>(rzf, rzb);
466 std::vector<HcalDDDRecConstants::HcalActiveLength> actives;
469 unsigned int kount(0);
474 int stype = (
bin.phis.size() > 4) ? 0 : 1;
477 double eta = 0.5 * (
bin.etaMin +
bin.etaMax);
483 <<
":" << layl <<
":" <<
bin.layer.size();
484 for (
auto ll :
bin.layer)
489 for (
unsigned int i = 0;
i <
bin.layer.size(); ++
i) {
493 for (
int j = lmin;
j <= lmax; ++
j) {
501 edm::LogVerbatim(
"HcalGeom") <<
"Type " <<
type <<
" L " << lmin <<
":" << lmax <<
" T " << thick;
503 thick *= (2. *
scale);
506 active.
iphis.emplace_back(
phi.first);
507 actives.emplace_back(active);
512 <<
" zside " << active.
zside <<
" depth " << active.
depth <<
" type " << active.
stype
513 <<
" thick " << active.
thick;
522 std::vector<HcalCellType>
cells;
525 std::vector<int> missPhi;
526 for (
const auto& etabin :
etabins) {
527 std::vector<HcalCellType>
temp;
528 std::vector<int>
count;
529 std::vector<double> dmin, dmax;
530 for (
unsigned int il = 0; il < etabin.layer.size(); ++il) {
532 temp.emplace_back(cell);
533 count.emplace_back(0);
534 dmin.emplace_back(0);
535 dmax.emplace_back(0);
537 int ieta = etabin.ieta;
540 for (
unsigned int il = 0; il < etabin.layer.size(); ++il) {
541 for (
auto& ic : cellsm) {
542 if (ic.depthSegment() >= etabin.layer[il].first && ic.depthSegment() <= etabin.layer[il].second &&
543 ic.etaBin() ==
temp[il].etaBin() && ic.zside() ==
temp[il].zside()) {
544 if (
count[il] == 0) {
546 dmin[il] = ic.depthMin();
547 dmax[il] = ic.depthMax();
550 if (ic.depthMin() < dmin[il])
551 dmin[il] = ic.depthMin();
552 if (ic.depthMax() > dmax[il])
553 dmax[il] = ic.depthMax();
558 for (
unsigned int il = 0; il < etabin.layer.size(); ++il) {
559 int depth = etabin.depthStart + (
int)(il);
560 temp[il].setEta(
ieta, etabin.etaMin, etabin.etaMax);
561 temp[il].setDepth(
depth, dmin[il], dmax[il]);
564 temp[il].setPhi(etabin.phis, missPhi, foff, etabin.dphi,
unit);
569 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants: found " <<
cells.size() <<
" cells for sub-detector type "
571 for (
unsigned int ic = 0; ic <
cells.size(); ++ic)
601 depths.reserve(depthMax - depthMin + 1);
610 unsigned int num = 0;
612 for (
auto& cellType : cellTypes) {
613 num += (
unsigned int)(cellType.nPhiBins());
616 edm::LogInfo(
"HCalGeom") <<
"HcalDDDRecConstants:numberOfCells " << cellTypes.size() <<
" " <<
num
617 <<
" for subdetector " << subdet;
629 unsigned int ncell(0);
631 ncell += ((etabin.phis.size()) * (etabin.layer.size()));
648 std::map<HcalDetId, HcalDetId>::const_iterator itr =
detIdSp_.find(
id);
657 std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr =
detIdSpR_.find(
id);
659 hid =
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi(), (itr->second)[0].
depth());
665 std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr =
detIdSpR_.find(
id);
667 hid =
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi(), (itr->second).back().depth());
673 std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr =
detIdSpR_.find(
id);
675 ids.emplace_back(
id);
677 for (
auto k : itr->second) {
679 ids.emplace_back(hid);
685 for (
auto k : idsOld) {
686 std::map<HcalDetId, HcalDetId>::const_iterator itr =
detIdSp_.find(
k);
688 idsNew.emplace_back(
k);
690 idsNew.emplace_back(itr->second);
696 std::map<HcalDetId, HcalDetId>::const_iterator itr;
698 ids.emplace_back(itr->first);
700 std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr;
702 ids.emplace_back(itr->first);
704 return (!ids.empty());
711 std::map<int, int>&
layers,
713 std::vector<HcalDDDRecConstants::HcalEtaBin>&
bins)
const {
719 etabin.
phis.insert(etabin.
phis.end(), phis.begin(), phis.end());
725 int lmin(0), lmax(0);
727 std::map<int, int>::iterator itr =
layers.begin();
729 int dep = itr->second;
732 unsigned lymx0 = (
layers.size() > lymax) ? lymax :
layers.size();
735 <<
":" << lymax <<
" Depth " << dep <<
":" << itr->second;
738 edm::LogVerbatim(
"HcalGeom") <<
"Layer [" <<
l <<
"] " << itr->first <<
":" << itr->second;
740 for (
unsigned int l = 0;
l < phis.size(); ++
l)
743 for (itr =
layers.begin(); itr !=
layers.end(); ++itr) {
744 if (itr->first <= (
int)(lymx0)) {
745 if (itr->second == dep) {
749 }
else if (itr->second > dep) {
752 int lmax0 = (lmax >= lmin) ? lmax : lmin;
754 etabin0.
layer.emplace_back(std::pair<int, int>(lmin, lmax0));
756 etabin.
layer.emplace_back(std::pair<int, int>(lmin, lmax0));
768 if (itr->first == (
int)(lymx0))
774 etabin0.
layer.emplace_back(std::pair<int, int>(lmin, lmax));
775 etabin0.
phis.insert(etabin0.
phis.end(), phis.begin(), phis.end());
776 bins.emplace_back(etabin0);
779 <<
":" << lmin <<
":" << lmax <<
" phis " << phis.size();
780 for (
unsigned int k = 0;
k < etabin0.
layer.size(); ++
k)
785 etabin.
layer.emplace_back(std::pair<int, int>(lmin, lmax));
792 bins.emplace_back(etabin);
795 << lmin <<
":" << lmax <<
" phis " << etabin.
phis.size();
796 for (
unsigned int k = 0;
k < etabin.
layer.size(); ++
k)
805 edm::LogError(
"HCalGeom") <<
"HcalDDDRecConstants: sizes of the vectors "
808 throw cms::Exception(
"DDException") <<
"HcalDDDRecConstants: inconsistent array sizes" <<
nEta <<
":"
818 int ieta(0), ietaHB(0), ietaHE(0), ietaHEM(0);
820 for (
int i = 0;
i <
nEta; ++
i) {
825 <<
" at index " <<
i <<
" of etaTable from SimConstant";
827 <<
"HcalDDDRecConstants: Going beyond the array boundary " <<
hpar->
etaTable.size() <<
" at index " <<
i
828 <<
" of etaTable from SimConstant";
835 if (ieta <= hpar->
etaMax[0])
837 if (ieta <= hpar->
etaMin[1])
839 if (ieta <= hpar->
etaMax[1])
848 for (
unsigned int k = 0;
k < 4; ++
k)
853 for (
int i = 0;
i <
nEta; ++
i) {
855 phibin.emplace_back(dphi);
856 int nphi = (
int)((2._pi + 0.001) / dphi);
872 int nphi = (
int)((2._pi + 0.001) /
i);
877 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants: Modified eta/deltaphi table for " <<
nEta <<
" bins";
895 for (
int i = 0;
i <
nEta; ++
i) {
897 int laymax = (imx > 0) ?
layerGroup(
i, imx - 1) : 0;
899 int laymax0 = (imx > 16) ?
layerGroup(
i, 16) : laymax;
903 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants:HB " <<
i <<
" " << imx <<
" " << laymax <<
" " << laymax0;
910 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants:HE " <<
i <<
" " << imx <<
" " << laymax;
917 for (
int i = 0;
i < 4; ++
i)
925 for (
unsigned int i = 0;
i <
hpar->
rHB.size(); ++
i) {
930 <<
" halves and " <<
gconsHB.size() <<
" layers";
931 for (
unsigned int i = 0;
i <
gconsHB.size(); ++
i)
936 for (
unsigned int i = 0;
i <
hpar->
zHE.size(); ++
i) {
941 <<
" halves and " <<
gconsHE.size() <<
" layers";
942 for (
unsigned int i = 0;
i <
gconsHE.size(); ++
i)
960 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants:Detector type and maximum depth for all RBX "
966 std::vector<int> phis;
971 int phi = (phis[0] > 0) ? phis[0] : -phis[0];
972 int zside = (phis[0] > 0) ? 1 : -1;
976 std::map<int, std::pair<int, int>> oldDep;
979 for (
int lay = 0; lay < lymax; ++lay) {
983 oldDep[
depth] = std::pair<int, int>(lmin, lay - 1);
989 oldDep[
depth] = std::pair<int, int>(lmin, lymax - 1);
992 <<
" with " << oldDep.size() <<
" old Depths";
994 for (
std::map<
int, std::pair<int, int>>::const_iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++
kk)
995 edm::LogVerbatim(
"HcalGeom") <<
"[" <<
kk <<
"] " << itr->first <<
" --> " << itr->second.first <<
":"
996 << itr->second.second;
1003 std::vector<int>
count(oldDep.size(), 0);
1006 for (
int lay = layFront; lay <= layBack; ++lay) {
1008 for (
std::map<
int, std::pair<int, int>>::iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++
l) {
1009 if (lay >= (itr->second).first && lay <= (itr->second).
second) {
1015 int odepth(0), maxlay(0);
1017 for (
std::map<
int, std::pair<int, int>>::iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++
l) {
1019 odepth = itr->first;
1025 <<
" max " << maxlay;
1027 for (
int k : phis) {
1028 zside = (
k > 0) ? 1 : -1;
1035 std::vector<HcalDetId> ids;
1036 std::map<HcalDetId, std::vector<HcalDetId>>::iterator itr =
detIdSpR_.find(oldId);
1039 ids.emplace_back(newId);
1046 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants:Map for merging new channels to old channel"
1047 <<
" IDs with " <<
detIdSp_.size() <<
" entries";
1050 edm::LogVerbatim(
"HcalGeom") <<
"[" <<
l <<
"] Special " << itr.first <<
" Standard " << itr.second;
1053 edm::LogVerbatim(
"HcalGeom") <<
"HcalDDDRecConstants:Reverse Map for mapping old to new IDs with "
1057 edm::LogVerbatim(
"HcalGeom") <<
"[" <<
l <<
"] Standard " << itr.first <<
" Special";
1058 for (
auto itr1 : itr.second)
1069 if (it.layer == (
unsigned int)(
eta + 1)) {
1070 return it.layerGroup.size();
1072 if (it.layer > (
unsigned int)(
eta + 1))
1074 k = it.layerGroup.size();
1082 if (it.layer == (
unsigned int)(
eta + 1)) {
1083 return it.layerGroup.at(
i);
1085 if (it.layer > (
unsigned int)(
eta + 1))
1087 k = it.layerGroup.at(
i);