File indexing completed on 2024-09-07 04:36:29
0001
0002
0003
0004
0005
0006 #include <Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h>
0007 #include <Geometry/DTGeometry/interface/DTGeometry.h>
0008 #include <Geometry/DTGeometry/interface/DTChamber.h>
0009 #include <Geometry/DTGeometry/interface/DTLayer.h>
0010
0011 #include <DetectorDescription/Core/interface/DDFilter.h>
0012 #include <DetectorDescription/Core/interface/DDFilteredView.h>
0013 #include <DetectorDescription/Core/interface/DDSolid.h>
0014 #include "DataFormats/Math/interface/GeantUnits.h"
0015 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0016 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0017 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
0018 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0019 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include <string>
0022 #include <utility>
0023
0024 using namespace geant_units;
0025 using namespace geant_units::operators;
0026
0027
0028
0029 DTGeometryBuilderFromDDD::DTGeometryBuilderFromDDD() {}
0030
0031 DTGeometryBuilderFromDDD::~DTGeometryBuilderFromDDD() {}
0032
0033 void DTGeometryBuilderFromDDD::build(DTGeometry& theGeometry,
0034 const DDCompactView* cview,
0035 const MuonGeometryConstants& muonConstants) {
0036 #ifdef EDM_ML_DEBUG
0037 edm::LogVerbatim("DTGeometry") << "DTGeometryBuilderFromDDD::build";
0038 #endif
0039
0040 std::string attribute = "MuStructure";
0041 std::string value = "MuonBarrelDT";
0042
0043
0044 DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
0045
0046 DDFilteredView fview(*cview, filter);
0047 buildGeometry(theGeometry, fview, muonConstants);
0048 }
0049
0050 void DTGeometryBuilderFromDDD::buildGeometry(DTGeometry& theGeometry,
0051 DDFilteredView& fv,
0052 const MuonGeometryConstants& muonConstants) const {
0053 edm::LogVerbatim("DTGeometryBuilder") << "(0) DTGeometryBuilder - DDD ";
0054
0055 bool doChamber = fv.firstChild();
0056
0057
0058 while (doChamber) {
0059 DDValue val("Type");
0060 const DDsvalues_type params(fv.mergedSpecifics());
0061 std::string type;
0062 if (DDfetch(¶ms, val))
0063 type = val.strings()[0];
0064
0065 val = DDValue("FEPos");
0066 std::string FEPos;
0067 if (DDfetch(¶ms, val))
0068 FEPos = val.strings()[0];
0069 DTChamber* chamber = buildChamber(fv, type, muonConstants);
0070
0071
0072 bool doSL = fv.firstChild();
0073 while (doSL) {
0074 DTSuperLayer* sl = buildSuperLayer(fv, chamber, type, muonConstants);
0075 theGeometry.add(sl);
0076
0077 bool doL = fv.firstChild();
0078
0079 while (doL) {
0080 DTLayer* layer = buildLayer(fv, sl, type, muonConstants);
0081 theGeometry.add(layer);
0082
0083 fv.parent();
0084 doL = fv.nextSibling();
0085 }
0086
0087 fv.parent();
0088 doSL = fv.nextSibling();
0089 }
0090 theGeometry.add(chamber);
0091
0092 fv.parent();
0093 doChamber = fv.nextSibling();
0094 }
0095 }
0096
0097 DTChamber* DTGeometryBuilderFromDDD::buildChamber(DDFilteredView& fv,
0098 const std::string& type,
0099 const MuonGeometryConstants& muonConstants) const {
0100 MuonGeometryNumbering mdddnum(muonConstants);
0101 DTNumberingScheme dtnum(muonConstants);
0102 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0103 DTChamberId detId(rawid);
0104
0105
0106
0107 std::vector<double> par = extractParameters(fv);
0108
0109
0110
0111
0112
0113
0114 edm::LogVerbatim("DTGeometryBuilder") << "(1) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0115 << " par[2]: " << par[2];
0116
0117 RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0118
0119 DTChamber* chamber = new DTChamber(detId, surf);
0120
0121 return chamber;
0122 }
0123
0124 DTSuperLayer* DTGeometryBuilderFromDDD::buildSuperLayer(DDFilteredView& fv,
0125 DTChamber* chamber,
0126 const std::string& type,
0127 const MuonGeometryConstants& muonConstants) const {
0128 MuonGeometryNumbering mdddnum(muonConstants);
0129 DTNumberingScheme dtnum(muonConstants);
0130 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0131 DTSuperLayerId slId(rawid);
0132
0133
0134 std::vector<double> par = extractParameters(fv);
0135
0136 edm::LogVerbatim("DTGeometryBuilder") << "(2) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0137 << " par[2]: " << par[2];
0138
0139
0140
0141
0142
0143
0144 RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0145
0146 DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
0147
0148
0149
0150
0151
0152 chamber->add(slayer);
0153 return slayer;
0154 }
0155
0156 DTLayer* DTGeometryBuilderFromDDD::buildLayer(DDFilteredView& fv,
0157 DTSuperLayer* sl,
0158 const std::string& type,
0159 const MuonGeometryConstants& muonConstants) const {
0160 MuonGeometryNumbering mdddnum(muonConstants);
0161 DTNumberingScheme dtnum(muonConstants);
0162 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0163 DTLayerId layId(rawid);
0164
0165
0166 std::vector<double> par = extractParameters(fv);
0167
0168
0169
0170
0171 RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0172
0173 edm::LogVerbatim("DTGeometryBuilder") << "(3) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0174 << " par[2]: " << par[2];
0175
0176
0177 bool doWire = fv.firstChild();
0178 int WCounter = 0;
0179 int firstWire = fv.copyno();
0180 par = extractParameters(fv);
0181 float wireLength = convertMmToCm(par[1]);
0182
0183 edm::LogVerbatim("DTGeometryBuilder") << "(4) detId: " << rawid
0184 << " wireLenght in ddd, wpar[1] in dd4hep: " << wireLength
0185 << " firstWire: " << firstWire;
0186
0187 while (doWire) {
0188 WCounter++;
0189 doWire = fv.nextSibling();
0190 }
0191
0192 DTTopology topology(firstWire, WCounter, wireLength);
0193
0194 DTLayerType layerType;
0195
0196 DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
0197
0198 sl->add(layer);
0199 return layer;
0200 }
0201
0202 std::vector<double> DTGeometryBuilderFromDDD::extractParameters(DDFilteredView& fv) const {
0203 std::vector<double> par;
0204 if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
0205 DDBooleanSolid bs(fv.logicalPart().solid());
0206 DDSolid A = bs.solidA();
0207 while (A.shape() != DDSolidShape::ddbox) {
0208 DDBooleanSolid bs(A);
0209 A = bs.solidA();
0210 }
0211 par = A.parameters();
0212 } else {
0213 par = fv.logicalPart().solid().parameters();
0214 }
0215 return par;
0216 }
0217
0218 DTGeometryBuilderFromDDD::RCPPlane DTGeometryBuilderFromDDD::plane(const DDFilteredView& fv, Bounds* bounds) const {
0219
0220 const DDTranslation& trans(fv.translation());
0221
0222 const Surface::PositionType posResult(
0223 float(convertMmToCm(trans.x())), float(convertMmToCm(trans.y())), float(convertMmToCm(trans.z())));
0224 LogTrace("DTGeometryBuilderFromDDD") << "DTGeometryBuilderFromDDD::plane posResult: " << posResult;
0225
0226
0227 const DDRotationMatrix& rotation = fv.rotation();
0228 DD3Vector x, y, z;
0229 rotation.GetComponents(x, y, z);
0230 #ifdef EDM_ML_DEBUG
0231 edm::LogVerbatim("DTGeometry") << "INVERSE rotation by its own operator: " << fv.rotation();
0232 edm::LogVerbatim("DTGeometry") << "INVERSE rotation manually: " << x.X() << ", " << x.Y() << ", " << x.Z()
0233 << std::endl
0234 << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
0235 << z.X() << ", " << z.Y() << ", " << z.Z();
0236 #endif
0237 Surface::RotationType rotResult(float(x.X()),
0238 float(x.Y()),
0239 float(x.Z()),
0240 float(y.X()),
0241 float(y.Y()),
0242 float(y.Z()),
0243 float(z.X()),
0244 float(z.Y()),
0245 float(z.Z()));
0246
0247 return RCPPlane(new Plane(posResult, rotResult, bounds));
0248 }