File indexing completed on 2023-03-17 13:02:56
0001 #include "Geometry/EcalTestBeam/plugins/EcalTBHodoscopeGeometryLoaderFromDDD.h"
0002
0003 #include "Geometry/EcalTestBeam/interface/EcalTBHodoscopeGeometry.h"
0004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0005
0006 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0007 #include "DetectorDescription/Core/interface/DDFilter.h"
0008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0009 #include "DetectorDescription/Core/interface/DDSolid.h"
0010 #include "DetectorDescription/Core/interface/DDTransform.h"
0011 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0012 #include "DetectorDescription/Core/interface/DDName.h"
0013
0014 typedef CaloCellGeometry::CCGFloat CCGFloat;
0015
0016 #include <iostream>
0017 #include <utility>
0018 #include <vector>
0019 #include <memory>
0020
0021 std::unique_ptr<CaloSubdetectorGeometry> EcalTBHodoscopeGeometryLoaderFromDDD::load(const DDCompactView* cpv) {
0022 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: start the construction of EcalTBHodoscope" << std::endl;
0023
0024 std::unique_ptr<CaloSubdetectorGeometry> ebg(new EcalTBHodoscopeGeometry());
0025
0026 makeGeometry(cpv, ebg.get());
0027
0028 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: Returning EcalTBHodoscopeGeometry" << std::endl;
0029
0030 return ebg;
0031 }
0032
0033 void EcalTBHodoscopeGeometryLoaderFromDDD::makeGeometry(const DDCompactView* cpv, CaloSubdetectorGeometry* ebg) {
0034 if (ebg->cornersMgr() == nullptr)
0035 ebg->allocateCorners(EBDetId::kSizeForDenseIndexing);
0036 if (ebg->parMgr() == nullptr)
0037 ebg->allocatePar(10, 3);
0038
0039 std::unique_ptr<DDFilter> filter{getDDFilter()};
0040
0041 DDFilteredView fv(*cpv, *filter);
0042
0043 bool doSubDets;
0044 for (doSubDets = fv.firstChild(); doSubDets; doSubDets = fv.nextSibling()) {
0045 #if 0
0046 std::string answer = getDDDString("ReadOutName",&fv);
0047 if (answer != "EcalTBH4BeamHits")
0048 continue;
0049 #endif
0050
0051 const DDSolid& solid = fv.logicalPart().solid();
0052
0053 if (solid.shape() != DDSolidShape::ddbox) {
0054 throw cms::Exception("DDException")
0055 << std::string(__FILE__)
0056 << "\n CaloGeometryEcalTBHodoscope::upDate(...): currently only box fiber shapes supported ";
0057 edm::LogWarning("EcalTBHodoscopeGeometry") << "Wrong shape for sensitive volume!" << solid;
0058 }
0059
0060 std::vector<double> pv = solid.parameters();
0061
0062
0063
0064
0065 DD3Vector x, y, z;
0066 fv.rotation().GetComponents(x, y, z);
0067 CLHEP::Hep3Vector hx(x.X(), x.Y(), x.Z());
0068 CLHEP::Hep3Vector hy(y.X(), y.Y(), y.Z());
0069 CLHEP::Hep3Vector hz(z.X(), z.Y(), z.Z());
0070 CLHEP::HepRotation hrot(hx, hy, hz);
0071 CLHEP::Hep3Vector htran(fv.translation().X(), fv.translation().Y(), fv.translation().Z());
0072
0073 const HepGeom::Transform3D ht3d(hrot,
0074 CaloCellGeometry::k_ScaleFromDDDtoGeant * htran);
0075
0076 const HepGeom::Point3D<float> ctr(ht3d * HepGeom::Point3D<float>(0, 0, 0));
0077
0078 const GlobalPoint refPoint(ctr.x(), ctr.y(), ctr.z());
0079
0080 std::vector<CCGFloat> vv;
0081 vv.reserve(pv.size() + 1);
0082 for (unsigned int i(0); i != pv.size(); ++i) {
0083 vv.emplace_back(CaloCellGeometry::k_ScaleFromDDDtoGeant * pv[i]);
0084 }
0085 vv.emplace_back(0.);
0086 const CCGFloat* pP(CaloCellGeometry::getParmPtr(vv, ebg->parMgr(), ebg->parVecVec()));
0087
0088 const DetId detId(getDetIdForDDDNode(fv));
0089
0090
0091
0092 ebg->newCell(refPoint, refPoint, refPoint, pP, detId);
0093 }
0094 }
0095
0096 unsigned int EcalTBHodoscopeGeometryLoaderFromDDD::getDetIdForDDDNode(const DDFilteredView& fv) {
0097
0098
0099 DDGeoHistory parents = fv.geoHistory();
0100
0101 assert(parents.size() >= 3);
0102
0103 EcalBaseNumber baseNumber;
0104
0105
0106 for (unsigned int i = 1; i <= parents.size(); i++) {
0107 baseNumber.addLevel(parents[parents.size() - i].logicalPart().name().name(), parents[parents.size() - i].copyno());
0108 }
0109
0110 return _scheme.getUnitID(baseNumber);
0111 }
0112
0113 DDFilter* EcalTBHodoscopeGeometryLoaderFromDDD::getDDFilter() {
0114 return new DDAndFilter<DDSpecificsMatchesValueFilter, DDSpecificsMatchesValueFilter>(
0115 DDSpecificsMatchesValueFilter{DDValue("SensitiveDetector", "EcalTBH4BeamDetector", 0)},
0116 DDSpecificsMatchesValueFilter{DDValue("ReadOutName", "EcalTBH4BeamHits", 0)});
0117 }