20 #include <unordered_set> 30 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalTBGeomParameters::HGCalTBGeomParameters " 44 std::map<int, HGCalTBGeomParameters::layerParameters>
layers;
45 std::vector<HGCalTBParameters::hgtrform> trforms;
46 std::vector<bool> trformUse;
52 int nsiz =
static_cast<int>(
copy.size());
53 int lay = (nsiz > 0) ?
copy[nsiz - 1] : 0;
54 int zp = (nsiz > 2) ?
copy[nsiz - 3] : -1;
58 throw cms::Exception(
"DDException") <<
"Funny layer # " << lay <<
" zp " << zp <<
" in " << nsiz <<
" components";
61 php.
layer_.emplace_back(lay);
62 auto itr =
layers.find(lay);
64 double rin(0), rout(0);
68 const std::vector<double>& rmin = polyhedra.
rMinVec();
69 const std::vector<double>& rmax = polyhedra.
rMaxVec();
82 const CLHEP::HepRep3x3
rotation(
x.X(),
y.X(),
z.X(),
x.Y(),
y.Y(),
z.Y(),
x.Z(),
y.Z(),
z.Z());
83 const CLHEP::HepRotation hr(
rotation);
91 const CLHEP::Hep3Vector h3v(
xx,
yy,
zz);
99 trforms.emplace_back(mytrf);
100 trformUse.emplace_back(
false);
109 std::unordered_map<int32_t, int32_t> copies;
111 std::vector<int32_t> wafer2copy;
112 std::vector<HGCalTBGeomParameters::cellParameters> wafers;
114 DDValue val1(attribute, sdTag2, 0.0);
119 throw cms::Exception(
"DDException") <<
"Attribute " << val1 <<
" not found but needed.";
122 std::unordered_set<std::string>
names;
127 int nsiz =
static_cast<int>(
copy.size());
128 int wafer = (nsiz > 0) ?
copy[nsiz - 1] : 0;
129 int layer = (nsiz > 1) ?
copy[nsiz - 2] : 0;
131 throw cms::Exception(
"DDException") <<
"Funny wafer # " << wafer <<
" in " << nsiz <<
" components";
132 }
else if (
layer > static_cast<int>(
layers.size())) {
134 <<
" among " << nsiz <<
" components";
136 auto itr = copies.find(wafer);
137 auto cpy = copiesInLayers[
layer].find(wafer);
138 if (itr != copies.end() && cpy == copiesInLayers[
layer].end()) {
139 copiesInLayers[
layer][wafer] = itr->second;
141 if (itr == copies.end()) {
142 copies[wafer] = wafer2copy.size();
143 copiesInLayers[
layer][wafer] = wafer2copy.size();
150 wafer2copy.emplace_back(wafer);
153 wafers.emplace_back(cell);
155 std::vector<double>
zv, rv;
190 std::map<int, int> wafertype;
191 std::map<int, HGCalTBGeomParameters::cellParameters> cellsf, cellsc;
192 DDValue val2(attribute, sdTag3, 0.0);
197 throw cms::Exception(
"DDException") <<
"Attribute " << val2 <<
" not found but needed.";
204 int nsiz =
static_cast<int>(
copy.size());
205 int cellx = (nsiz > 0) ?
copy[nsiz - 1] : 0;
206 int wafer = (nsiz > 1) ?
copy[nsiz - 2] : 0;
211 <<
"Funny cell # " << cell <<
" type " <<
type <<
" in " << nsiz <<
" components";
213 auto ktr = wafertype.find(wafer);
214 if (ktr == wafertype.end())
215 wafertype[wafer] =
type;
217 std::map<int, HGCalTBGeomParameters::cellParameters>::iterator itr;
220 itr = cellsf.find(cell);
221 newc = (itr == cellsf.end());
223 itr = cellsc.find(cell);
224 newc = (itr == cellsc.end());
228 bool half = (
name.find(
"Half") != std::string::npos);
241 edm::LogVerbatim(
"HGCalGeom") <<
"Wafer " << wafer <<
" Type " <<
type <<
" Cell " << cellx <<
" local " 242 <<
xx <<
":" <<
yy <<
" new " <<
p1 <<
":" <<
p2;
258 layers, trforms, trformUse, copies, copiesInLayers, wafer2copy, wafers, wafertype, cellsf, cellsc, php);
269 std::map<int, HGCalTBGeomParameters::layerParameters>
layers;
270 std::vector<HGCalTBParameters::hgtrform> trforms;
271 std::vector<bool> trformUse;
272 std::vector<std::pair<int, int> > trused;
275 const std::vector<double>& pars = fv.
parameters();
278 int nsiz =
static_cast<int>(
copy.size());
279 int lay = (nsiz > 0) ?
copy[0] : 0;
280 int zp = (nsiz > 2) ?
copy[2] : -1;
284 throw cms::Exception(
"DDException") <<
"Funny layer # " << lay <<
" zp " << zp <<
" in " << nsiz <<
" components";
287 php.
layer_.emplace_back(lay);
288 auto itr =
layers.find(lay);
290 if (itr ==
layers.end()) {
291 double rin(0), rout(0);
292 if (dd4hep::isA<dd4hep::Polyhedra>(fv.
solid())) {
295 }
else if (dd4hep::isA<dd4hep::Tube>(fv.
solid())) {
296 dd4hep::Tube tubeSeg(fv.
solid());
303 std::pair<int, int> layz(lay, zp);
304 if (
std::find(trused.begin(), trused.end(), layz) == trused.end()) {
305 trused.emplace_back(layz);
308 const CLHEP::HepRep3x3
rotation(
x.X(),
y.X(),
z.X(),
x.Y(),
y.Y(),
z.Y(),
x.Z(),
y.Z(),
z.Z());
309 const CLHEP::HepRotation hr(
rotation);
317 const CLHEP::Hep3Vector h3v(
xx,
yy,
zz);
325 trforms.emplace_back(mytrf);
326 trformUse.emplace_back(
false);
335 std::unordered_map<int32_t, int32_t> copies;
337 std::vector<int32_t> wafer2copy;
338 std::vector<HGCalTBGeomParameters::cellParameters> wafers;
343 throw cms::Exception(
"DDException") <<
"Attribute " << sdTag2 <<
" not found but needed.";
346 std::unordered_set<std::string>
names;
350 int nsiz =
static_cast<int>(
copy.size());
351 int wafer = (nsiz > 0) ?
copy[0] : 0;
354 throw cms::Exception(
"DDException") <<
"Funny wafer # " << wafer <<
" in " << nsiz <<
" components";
355 }
else if (
layer > static_cast<int>(
layers.size())) {
357 <<
" among " << nsiz <<
" components";
359 auto itr = copies.find(wafer);
360 auto cpy = copiesInLayers[
layer].find(wafer);
361 if (itr != copies.end() && cpy == copiesInLayers[
layer].end()) {
362 copiesInLayers[
layer][wafer] = itr->second;
364 if (itr == copies.end()) {
365 copies[wafer] = wafer2copy.size();
366 copiesInLayers[
layer][wafer] = wafer2copy.size();
373 wafer2copy.emplace_back(wafer);
376 wafers.emplace_back(cell);
379 const std::vector<double>& pars = fv1.
parameters();
414 std::map<int, int> wafertype;
415 std::map<int, HGCalTBGeomParameters::cellParameters> cellsf, cellsc;
420 throw cms::Exception(
"DDException") <<
"Attribute " << sdTag3 <<
" not found but needed.";
426 int nsiz =
static_cast<int>(
copy.size());
427 int cellx = (nsiz > 0) ?
copy[0] : 0;
428 int wafer = (nsiz > 1) ?
copy[1] : 0;
433 <<
"Funny cell # " << cell <<
" type " <<
type <<
" in " << nsiz <<
" components";
435 auto ktr = wafertype.find(wafer);
436 if (ktr == wafertype.end())
437 wafertype[wafer] =
type;
439 std::map<int, HGCalTBGeomParameters::cellParameters>::iterator itr;
442 itr = cellsf.find(cell);
443 newc = (itr == cellsf.end());
445 itr = cellsc.find(cell);
446 newc = (itr == cellsc.end());
450 bool half = (
name.find(
"Half") != std::string::npos);
463 edm::LogVerbatim(
"HGCalGeom") <<
"Wafer " << wafer <<
" Type " <<
type <<
" Cell " << cellx <<
" local " 464 <<
xx <<
":" <<
yy <<
" new " <<
p1 <<
":" <<
p2;
480 layers, trforms, trformUse, copies, copiesInLayers, wafer2copy, wafers, wafertype, cellsf, cellsc, php);
484 std::vector<HGCalTBParameters::hgtrform>& trforms,
485 std::vector<bool>& trformUse,
486 const std::unordered_map<int32_t, int32_t>& copies,
488 const std::vector<int32_t>& wafer2copy,
489 const std::vector<HGCalTBGeomParameters::cellParameters>& wafers,
490 const std::map<int, int>& wafertype,
491 const std::map<int, HGCalTBGeomParameters::cellParameters>& cellsf,
492 const std::map<int, HGCalTBGeomParameters::cellParameters>& cellsc,
494 if (((cellsf.size() + cellsc.size()) == 0) || (wafers.empty()) || (
layers.empty())) {
495 throw cms::Exception(
"DDException") <<
"HGCalTBGeomParameters: mismatch between geometry and specpar: cells " 496 << cellsf.size() <<
":" << cellsc.size() <<
" wafers " << wafers.size()
497 <<
" layers " <<
layers.size();
500 for (
unsigned int i = 0;
i <
layers.size(); ++
i) {
512 for (
unsigned int i = 0;
i < php.
layer_.size(); ++
i) {
513 for (
unsigned int i1 = 0;
i1 < trforms.size(); ++
i1) {
514 if (!trformUse[
i1] && php.
layerGroup_[trforms[
i1].lay - 1] == static_cast<int>(
i + 1)) {
516 trforms[
i1].lay = (
i + 1);
517 trformUse[
i1] =
true;
520 for (
unsigned int i2 =
i1 + 1;
i2 < trforms.size(); ++
i2) {
521 if (!trformUse[
i2] && trforms[
i2].zp == trforms[
i1].zp &&
522 php.
layerGroup_[trforms[
i2].lay - 1] == static_cast<int>(
i + 1)) {
525 trformUse[
i2] =
true;
536 for (
unsigned i = 0;
i < wafer2copy.size(); ++
i) {
540 auto ktr = wafertype.find(wafer2copy[
i]);
541 int typet = (ktr == wafertype.end()) ? 0 : (ktr->second);
543 double r = wafers[
i].xyz.perp();
545 for (
int k = 1;
k < 4; ++
k) {
556 std::vector<HGCalTBGeomParameters::cellParameters>::const_iterator itrf = wafers.end();
557 for (
unsigned int i = 0;
i < cellsf.size(); ++
i) {
558 auto itr = cellsf.find(
i);
559 if (itr == cellsf.end()) {
560 throw cms::Exception(
"DDException") <<
"HGCalTBGeomParameters: missing info for fine cell number " <<
i;
562 double xx = (itr->second).xyz.x();
563 double yy = (itr->second).xyz.y();
564 int waf = (itr->second).wafer;
572 for (
unsigned int i = 0;
i < cellsc.size(); ++
i) {
573 auto itr = cellsc.find(
i);
574 if (itr == cellsc.end()) {
575 throw cms::Exception(
"DDException") <<
"HGCalTBGeomParameters: missing info for coarse cell number " <<
i;
577 double xx = (itr->second).xyz.x();
578 double yy = (itr->second).xyz.y();
579 int waf = (itr->second).wafer;
592 php.
depth_.emplace_back(
i + 1);
632 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalTBGeomParameters: wafer radius " << php.
waferR_ <<
" and dimensions of the " 646 <<
" coarse cells in a wafer";
665 for (std::unordered_map<int, int>::const_iterator itr = theModules.begin(); itr != theModules.end(); ++itr, ++
k2) {
666 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k2 <<
"] " << itr->first <<
":" << itr->second;
717 php.
boundR_ = fv.
get<std::vector<double> >(sdTag4,
"RadiusBound");
719 php.
rLimit_ = fv.
get<std::vector<double> >(sdTag4,
"RadiusLimits");
727 php.
slopeMin_ = fv.
get<std::vector<double> >(sdTag4,
"Slope");
732 const auto&
dummy = fv.
get<std::vector<double> >(sdTag2,
"WaferSize");
736 php.
cellSize_ = fv.
get<std::vector<double> >(sdTag3,
"CellSize");
744 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalTBGeomParameters: wafer radius ranges" 745 <<
" for cell grouping " << php.
boundR_[0] <<
":" << php.
boundR_[1] <<
":" 751 <<
" and layer groupings " 752 <<
"for the 3 ranges:";
768 edm::LogVerbatim(
"HGCalGeom") <<
"Input waferWidth " << waferW <<
":" << rmin <<
" R Limits: " << rin <<
":" << rout
769 <<
" Fine " << rMaxFine;
777 double dx = 0.5 * waferW;
778 double dy = 3.0 *
dx *
tan(30._deg);
779 double rr = 2.0 *
dx *
tan(30._deg);
780 int ncol =
static_cast<int>(2.0 * rout / waferW) + 1;
781 int nrow =
static_cast<int>(rout / (waferW *
tan(30._deg))) + 1;
782 int ns2 = (2 * ncol + 1) * (2 * nrow + 1) * php.
layer_.size();
783 int incm(0), inrm(0);
787 int kount(0),
ntot(0);
790 for (
int nr = -nrow;
nr <= nrow; ++
nr) {
791 int inr = (
nr >= 0) ?
nr : -
nr;
792 for (
int nc = -ncol; nc <= ncol; ++nc) {
793 int inc = (nc >= 0) ? nc : -nc;
794 if (inr % 2 == inc % 2) {
795 double xpos = nc *
dx;
796 double ypos =
nr *
dy;
798 double rpos =
std::sqrt(xpos * xpos + ypos * ypos);
799 int typet = (rpos < rMaxFine) ? 1 : 2;
801 for (
int k = 1;
k < 4; ++
k) {
802 if ((rpos + rmin) <= php.
boundR_[
k]) {
819 <<
" Location " <<
corner.first <<
" Position " << xpos <<
":" << ypos
820 <<
" Layers " << php.
layer_.size();
827 for (
unsigned int il = 0; il < php.
layer_.size(); ++il) {
828 std::pair<int, int>
corner =
831 auto cpy = copiesInLayers[php.
layer_[il]].find(
copy);
832 if (cpy == copiesInLayers[php.
layer_[il]].end())
850 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalWaferHexagon: # of columns " << incm <<
" # of rows " << inrm <<
" and " 851 << kount <<
":" <<
ntot <<
" wafers; R " << rin <<
":" << rout;
853 for (
unsigned int k = 0;
k < copiesInLayers.size(); ++
k) {
854 const auto& theModules = copiesInLayers[
k];
857 for (std::unordered_map<int, int>::const_iterator itr = theModules.begin(); itr != theModules.end(); ++itr, ++
k2) {
858 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k2 <<
"] " << itr->first <<
":" << itr->second;
880 for (
auto const&
it : vmap) {
881 if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(
it.first),
"waferFine")) {
882 for (
const auto&
i :
it.second)
884 }
else if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(
it.first),
"waferCoarse")) {
885 for (
const auto&
i :
it.second)
909 const std::vector<double>& fvec =
value.doubles();
910 int nval = fvec.size();
914 <<
"HGCalTBGeomParameters: # of " <<
str <<
" bins " << nval <<
" < " <<
nmin <<
" ==> illegal";
917 if (nval < 1 &&
nmin == 0) {
919 <<
"HGCalTBGeomParameters: # of " <<
str <<
" bins " << nval <<
" < 1 ==> illegal" 920 <<
" (nmin=" <<
nmin <<
")";
926 throw cms::Exception(
"DDException") <<
"HGCalTBGeomParameters: cannot get array " <<
str;
928 std::vector<double> fvec;
934 const std::vector<HGCalTBGeomParameters::cellParameters>& wafers,
935 std::vector<HGCalTBGeomParameters::cellParameters>::const_iterator& itrf,
939 if (itrf == wafers.end()) {
940 for (std::vector<HGCalTBGeomParameters::cellParameters>::const_iterator itr = wafers.begin(); itr != wafers.end();
942 if (itr->wafer == wafer) {
949 if (itrf != wafers.end()) {
950 dx = (
xx - itrf->xyz.x());
953 dy = (
yy - itrf->xyz.y());
957 return std::make_pair(
dx,
dy);
961 std::for_each(
v.begin(),
v.end(), [
s](
double&
n) {
n *=
s; });
std::vector< double > moduleBlS_
Log< level::Info, true > LogVerbatim
std::vector< double > cellFineX_
nav_type copyNumbers() const
return the stack of copy numbers
std::vector< double > rMinVec(void) const
void rescale(std::vector< double > &, const double s)
std::vector< int > layer_
std::vector< bool > cellCoarseHalf_
const std::vector< int > copyNos() const
The list of the volume copy numbers.
std::vector< int > waferCopy_
static constexpr double k_ScaleFromDDD
static int32_t getUnpackedCell6(int id)
std::vector< double > rMaxLayHex_
std::vector< double > trformRotZY_
std::vector< double > xVec(void) const
std::vector< double > const & vector(std::string_view iKey) const
returns an empty container if not found
std::vector< double > zVec(void) const
std::vector< double > moduleHS_
std::vector< double > trformRotZX_
void loadWaferHexagon(HGCalTBParameters &php)
std::vector< double > moduleTlS_
Global3DPoint GlobalPoint
std::vector< double > rMaxVec(void) const
std::vector< std::unordered_map< int32_t, int32_t > > layer_map
static constexpr double k_ScaleFromDD4hepToG4
static constexpr double k_ScaleFromDD4hep
std::vector< double > trformTranX_
void resetZero(std::vector< double > &)
std::vector< int > waferTypeL_
std::vector< double > cellCoarseY_
std::vector< int > moduleLayR_
static constexpr uint32_t k_CornerSize
std::vector< double > moduleHR_
std::vector< double > boundR_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Compact representation of the geometrical detector hierarchy.
std::vector< int > layerIndex_
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
std::vector< double > cellCoarseX_
const std::string names[nVars_]
std::vector< double > slopeMin_
std::vector< double > moduleAlphaR_
std::vector< int > cellFine_
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
A DDSolid represents the shape of a part.
std::vector< double > trformRotYZ_
std::vector< double > waferPosX_
std::vector< double > zVec(void) const
static constexpr double k_ScaleFromDDDToG4
static int32_t getUnpackedCellType6(int id)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
std::vector< int > depthIndex_
std::string_view name() const
std::vector< double > moduleAlphaS_
std::vector< double > zLayerHex_
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
static constexpr double tol
const std::string & name() const
Returns the name.
std::vector< int > cellCoarse_
void fillTrForm(const hgtrform &mytr)
bool next()
set current node to the next node in the filtered tree
std::vector< int > waferTypeT_
Tan< T >::type tan(const T &t)
std::vector< double > moduleDzR_
Abs< T >::type abs(const T &t)
void loadCellParsHexagon(const DDCompactView *cpv, HGCalTBParameters &php)
std::vector< double > getDDDArray(const std::string &str, const DDsvalues_type &sv, const int nmin)
static constexpr double tan30deg_
std::vector< double > trformTranZ_
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::vector< double > moduleBlR_
bool firstChild()
set the current node to the first child
std::vector< int > levelT_
std::vector< int > layerGroup_
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
std::vector< int > moduleLayS_
std::vector< double > trformRotXX_
DDsvalues_type mergedSpecifics() const
void fillModule(const hgtrap &mytr, bool reco)
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
std::vector< double > trformRotYX_
std::vector< double > rMinLayHex_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double > > XYZPointD
point in space with cartesian internal representation
std::vector< int > layerGroupM_
std::vector< double > trformRotZZ_
std::vector< double > cellFineY_
std::vector< double > cellSize_
std::vector< double > trformRotYY_
std::unordered_map< int32_t, std::pair< int32_t, int32_t > > waferT_map
void addTrForm(const CLHEP::Hep3Vector &h3v)
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
dd4hep::Solid solid() const
std::pair< double, double > cellPosition(const std::vector< cellParameters > &wafers, std::vector< cellParameters >::const_iterator &itrf, int wafer, double xx, double yy)
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
layer_map copiesInLayers_
const RotationMatrix rotation() const
std::vector< double > trformTranY_
std::vector< int > depth_
std::vector< uint32_t > trformIndex_
std::vector< int > depthLayerF_
void loadSpecParsHexagon(const DDFilteredView &fv, HGCalTBParameters &php, const DDCompactView *cpv, const std::string &sdTag1, const std::string &sdTag2)
std::vector< double > trformRotXY_
bool firstChild()
set the current node to the first child ...
std::vector< double > moduleTlR_
void loadGeometryHexagon(const DDFilteredView &_fv, HGCalTBParameters &php, const std::string &sdTag1, const DDCompactView *cpv, const std::string &sdTag2, const std::string &sdTag3, HGCalGeometryMode::WaferMode mode)
std::vector< bool > cellFineHalf_
std::vector< double > trformRotXZ_
static int32_t packTypeUV(int type, int u, int v)
std::vector< int > layerGroupO_
Log< level::Warning, false > LogWarning
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< double > moduleDzS_
const std::vector< double > parameters() const
extract shape parameters
std::vector< double > waferPosY_
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
std::vector< double > rLimit_
const Translation translation() const
hgtrap getModule(unsigned int k, bool reco) const