Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    DetectorDescription/DTGeometryBuilder
0004 // Class:      DTGeometryBuilder
0005 //
0006 /**\class DTGeometryBuilder
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 "DetectorDescription/DDCMS/interface/DDDetector.h"
0037 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0038 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0039 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0040 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
0041 #include "DTGeometryBuilder.h"
0042 #include "DD4hep/Detector.h"
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044 
0045 #include <memory>
0046 #include <string>
0047 #include <string_view>
0048 
0049 using namespace edm;
0050 using namespace std;
0051 using namespace cms;
0052 
0053 void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, const MuonGeometryConstants& num) const {
0054   edm::LogVerbatim("DTGeometryBuilder") << "(0) DTGeometryBuilder - DD4hep ";
0055 
0056   bool doChamber = fview.firstChild();
0057 
0058   while (doChamber) {
0059     DTChamber* chamber = buildChamber(fview, num);
0060 
0061     bool doSL = fview.nextSibling();
0062     while (doSL) {
0063       DTSuperLayer* sl = buildSuperLayer(fview, chamber, num);
0064 
0065       fview.down();
0066       bool doLayers = fview.sibling();
0067       while (doLayers) {
0068         DTLayer* l = buildLayer(fview, sl, num);
0069         geom.add(l);
0070 
0071         doLayers = fview.sibling();
0072       }
0073 
0074       geom.add(sl);
0075       doSL = fview.nextSibling();
0076     }
0077     geom.add(chamber);
0078 
0079     fview.parent();
0080     doChamber = fview.firstChild();
0081   }
0082 }
0083 
0084 DTGeometryBuilder::RCPPlane DTGeometryBuilder::plane(const DDFilteredView& fview, 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* DTGeometryBuilder::buildChamber(DDFilteredView& fview, const MuonGeometryConstants& muonConstants) const {
0095   MuonGeometryNumbering mdddnum(muonConstants);
0096   DTNumberingScheme dtnum(muonConstants);
0097   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0098 
0099   DTChamberId detId(rawid);
0100   auto const& par = fview.parameters();
0101 
0102   edm::LogVerbatim("DTGeometryBuilder") << "(1) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0103                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0104 
0105   RCPPlane surf(
0106       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0107 
0108   DTChamber* chamber = new DTChamber(detId, surf);
0109 
0110   return chamber;
0111 }
0112 
0113 DTSuperLayer* DTGeometryBuilder::buildSuperLayer(DDFilteredView& fview,
0114                                                  DTChamber* chamber,
0115                                                  const MuonGeometryConstants& muonConstants) const {
0116   MuonGeometryNumbering mdddnum(muonConstants);
0117   DTNumberingScheme dtnum(muonConstants);
0118   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0119 
0120   DTSuperLayerId slId(rawid);
0121 
0122   auto const& par = fview.parameters();
0123 
0124   edm::LogVerbatim("DTGeometryBuilder") << "(2) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0125                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0126 
0127   RCPPlane surf(
0128       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0129 
0130   DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
0131 
0132   chamber->add(slayer);
0133 
0134   return slayer;
0135 }
0136 
0137 DTLayer* DTGeometryBuilder::buildLayer(DDFilteredView& fview,
0138                                        DTSuperLayer* sl,
0139                                        const MuonGeometryConstants& muonConstants) const {
0140   MuonGeometryNumbering mdddnum(muonConstants);
0141   DTNumberingScheme dtnum(muonConstants);
0142   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0143 
0144   DTLayerId layId(rawid);
0145 
0146   auto const& par = fview.parameters();
0147 
0148   edm::LogVerbatim("DTGeometryBuilder") << "(3) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
0149                                         << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
0150 
0151   RCPPlane surf(
0152       plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
0153 
0154   fview.down();
0155   bool doWire = fview.sibling();
0156   int firstWire = fview.volume()->GetNumber();
0157   auto const& wpar = fview.parameters();
0158   float wireLength = wpar[1] / dd4hep::cm;
0159 
0160   edm::LogVerbatim("DTGeometryBuilder") << "(4) detId: " << rawid << " wpar[1]: " << wpar[1] / dd4hep::cm
0161                                         << " firstWire: " << firstWire;
0162 
0163   int WCounter = 0;
0164   while (doWire) {
0165     doWire = fview.checkChild();
0166     WCounter++;
0167   }
0168   fview.up();
0169 
0170   DTTopology topology(firstWire, WCounter, wireLength);
0171 
0172   DTLayerType layerType;
0173 
0174   DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
0175 
0176   sl->add(layer);
0177   return layer;
0178 }
0179 
0180 void DTGeometryBuilder::build(DTGeometry& geom,
0181                               const DDDetector* det,
0182                               const MuonGeometryConstants& num,
0183                               const dd4hep::SpecParRefs& refs) {
0184   Volume top = det->worldVolume();
0185   DDFilteredView fview(det, top);
0186   fview.mergedSpecifics(refs);
0187   buildGeometry(fview, geom, num);
0188 }