Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-06 04:13:37

0001 // -*- C++ -*-
0002 //
0003 // Package:    Geometry/DTGeometryBuilder
0004 // Class:      DTGeometryBuilderFromDD4hep
0005 //
0006 /**\class DTGeometryBuilderFromDD4hep
0007 
0008  Description: DT Geometry builder from DD4hep
0009 
0010  Implementation:
0011      DT Geometry Builder iterates over a Detector Tree and
0012      retrvieves DT chambers, super layers, layers and wires.
0013 */
0014 //
0015 // Original Author:  Ianna Osborne
0016 //         Created:  Wed, 16 Jan 2019 10:19:37 GMT
0017 //         Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Mon, 31 August 2020
0018 //
0019 //
0020 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0021 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0022 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0023 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0024 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
0025 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
0026 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorExtendedRcd.h"
0027 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0028 #include "Geometry/Records/interface/DTRecoGeometryRcd.h"
0029 #include "DataFormats/GeometrySurface/interface/Plane.h"
0030 #include "DataFormats/GeometrySurface/interface/Bounds.h"
0031 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0032 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0033 #include "Geometry/Records/interface/MuonNumberingRecord.h"
0034 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0035 #include "Geometry/Records/interface/GeometryFileRcd.h"
0036 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0037 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0038 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
0039 #include "DTGeometryBuilderFromDD4hep.h"
0040 #include "DD4hep/Detector.h"
0041 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0042 
0043 #include <memory>
0044 #include <string>
0045 #include <string_view>
0046 
0047 using namespace edm;
0048 using namespace std;
0049 
0050 void DTGeometryBuilderFromDD4hep::buildGeometry(cms::DDFilteredView& fview,
0051                                                 DTGeometry& geom,
0052                                                 const MuonGeometryConstants& num) const {
0053   edm::LogVerbatim("DTGeometryBuilder") << "(0) DTGeometryBuilder - DD4hep ";
0054 
0055   bool doChamber = fview.firstChild();
0056 
0057   while (doChamber) {
0058     DTChamber* chamber = buildChamber(fview, num);
0059 
0060     bool doSL = fview.nextSibling();
0061     while (doSL) {
0062       DTSuperLayer* sl = buildSuperLayer(fview, chamber, num);
0063 
0064       fview.down();
0065       bool doLayers = fview.sibling();
0066       while (doLayers) {
0067         DTLayer* l = buildLayer(fview, sl, num);
0068         geom.add(l);
0069 
0070         doLayers = fview.sibling();
0071       }
0072 
0073       geom.add(sl);
0074       doSL = fview.nextSibling();
0075     }
0076     geom.add(chamber);
0077 
0078     fview.parent();
0079     doChamber = fview.firstChild();
0080   }
0081 }
0082 
0083 DTGeometryBuilderFromDD4hep::RCPPlane DTGeometryBuilderFromDD4hep::plane(const cms::DDFilteredView& fview,
0084                                                                          Bounds* bounds) const {
0085   const Double_t* tr = fview.trans();
0086   const Double_t* rot = fview.rot();
0087 
0088   return RCPPlane(
0089       new Plane(Surface::PositionType(tr[0] / dd4hep::cm, tr[1] / dd4hep::cm, tr[2] / dd4hep::cm),
0090                 Surface::RotationType(rot[0], rot[3], rot[6], rot[1], rot[4], rot[7], rot[2], rot[5], rot[8]),
0091                 bounds));
0092 }
0093 
0094 DTChamber* DTGeometryBuilderFromDD4hep::buildChamber(cms::DDFilteredView& fview,
0095                                                      const MuonGeometryConstants& muonConstants) const {
0096   MuonGeometryNumbering mdddnum(muonConstants);
0097   DTNumberingScheme dtnum(muonConstants);
0098   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0099 
0100   DTChamberId detId(rawid);
0101   auto const& par = fview.parameters();
0102 
0103   RCPPlane surf(
0104       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0105 
0106   edm::LogVerbatim("DTGeometryBuilder") << "(1) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0107                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0108 
0109   DTChamber* chamber = new DTChamber(detId, surf);
0110 
0111   return chamber;
0112 }
0113 
0114 DTSuperLayer* DTGeometryBuilderFromDD4hep::buildSuperLayer(cms::DDFilteredView& fview,
0115                                                            DTChamber* chamber,
0116                                                            const MuonGeometryConstants& muonConstants) const {
0117   MuonGeometryNumbering mdddnum(muonConstants);
0118   DTNumberingScheme dtnum(muonConstants);
0119   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0120 
0121   DTSuperLayerId slId(rawid);
0122 
0123   auto const& par = fview.parameters();
0124 
0125   RCPPlane surf(
0126       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0127 
0128   edm::LogVerbatim("DTGeometryBuilder") << "(2) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0129                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0130 
0131   DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
0132 
0133   chamber->add(slayer);
0134 
0135   return slayer;
0136 }
0137 
0138 DTLayer* DTGeometryBuilderFromDD4hep::buildLayer(cms::DDFilteredView& fview,
0139                                                  DTSuperLayer* sl,
0140                                                  const MuonGeometryConstants& muonConstants) const {
0141   MuonGeometryNumbering mdddnum(muonConstants);
0142   DTNumberingScheme dtnum(muonConstants);
0143   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0144 
0145   DTLayerId layId(rawid);
0146 
0147   auto const& par = fview.parameters();
0148 
0149   RCPPlane surf(
0150       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0151 
0152   edm::LogVerbatim("DTGeometryBuilder") << "(3) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0153                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0154 
0155   fview.down();
0156   bool doWire = fview.sibling();
0157   int firstWire = fview.volume()->GetNumber();
0158   auto const& wpar = fview.parameters();
0159   float wireLength = wpar[1] / dd4hep::cm;
0160 
0161   edm::LogVerbatim("DTGeometryBuilder") << "(4) detId: " << rawid << " wpar[1]: " << wpar[1] / dd4hep::cm
0162                                         << " firstWire: " << firstWire;
0163 
0164   int WCounter = 0;
0165   while (doWire) {
0166     doWire = fview.checkChild();
0167     WCounter++;
0168   }
0169   fview.up();
0170 
0171   DTTopology topology(firstWire, WCounter, wireLength);
0172 
0173   DTLayerType layerType;
0174 
0175   DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
0176 
0177   sl->add(layer);
0178   return layer;
0179 }
0180 
0181 void DTGeometryBuilderFromDD4hep::build(DTGeometry& geom,
0182                                         const cms::DDDetector* det,
0183                                         const MuonGeometryConstants& num,
0184                                         const dd4hep::SpecParRefs& refs) {
0185   cms::Volume top = det->worldVolume();
0186   cms::DDFilteredView fview(det, top);
0187   fview.mergedSpecifics(refs);
0188   buildGeometry(fview, geom, num);
0189 }