Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:20:52

0001 /* Implementation of the  RPCGeometryParsFromDD Class
0002  *  Build the RPCGeometry from the DDD and DD4hep description
0003  *  
0004  *  DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
0005  *  Author:  Sergio Lo Meo (sergio.lo.meo@cern.ch) 
0006  *  Created:  Mon, 09 Nov 2020 
0007  *
0008  */
0009 #include "Geometry/RPCGeometryBuilder/interface/RPCGeometryParsFromDD.h"
0010 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0011 #include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
0012 #include <DetectorDescription/Core/interface/DDFilter.h>
0013 #include <DetectorDescription/Core/interface/DDFilteredView.h>
0014 #include <DetectorDescription/Core/interface/DDSolid.h>
0015 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0016 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0017 #include "Geometry/MuonNumbering/interface/RPCNumberingScheme.h"
0018 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0019 #include <CLHEP/Units/SystemOfUnits.h>
0020 #include <iostream>
0021 #include <algorithm>
0022 #include <DetectorDescription/DDCMS/interface/DDFilteredView.h>
0023 #include <DetectorDescription/DDCMS/interface/DDCompactView.h>
0024 #include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 
0027 RPCGeometryParsFromDD::RPCGeometryParsFromDD() {}
0028 
0029 RPCGeometryParsFromDD::~RPCGeometryParsFromDD() {}
0030 
0031 // DD
0032 void RPCGeometryParsFromDD::build(const DDCompactView* cview,
0033                                   const MuonGeometryConstants& muonConstants,
0034                                   RecoIdealGeometry& rgeo) {
0035   const std::string attribute = "ReadOutName";
0036   const std::string value = "MuonRPCHits";
0037 
0038   // Asking only for the MuonRPC's
0039   DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
0040   DDFilteredView fview(*cview, filter);
0041 
0042   this->buildGeometry(fview, muonConstants, rgeo);
0043 }
0044 
0045 // DD4hep
0046 
0047 void RPCGeometryParsFromDD::build(const cms::DDCompactView* cview,
0048                                   const MuonGeometryConstants& muonConstants,
0049                                   RecoIdealGeometry& rgeo) {
0050   const std::string attribute = "ReadOutName";
0051   const std::string value = "MuonRPCHits";
0052   const cms::DDFilter filter(attribute, value);
0053   cms::DDFilteredView fview(*cview, filter);
0054   this->buildGeometry(fview, muonConstants, rgeo);
0055 }
0056 
0057 // DD
0058 
0059 void RPCGeometryParsFromDD::buildGeometry(DDFilteredView& fview,
0060                                           const MuonGeometryConstants& muonConstants,
0061                                           RecoIdealGeometry& rgeo) {
0062   for (bool doSubDets = fview.firstChild(); doSubDets == true; doSubDets = fview.nextSibling()) {
0063     // Get the Base Muon Number
0064     MuonGeometryNumbering mdddnum(muonConstants);
0065     MuonBaseNumber mbn = mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
0066 
0067     // Get the The Rpc det Id
0068     RPCNumberingScheme rpcnum(muonConstants);
0069     const int detid = rpcnum.baseNumberToUnitNumber(mbn);
0070 
0071     RPCDetId rpcid(detid);
0072 
0073     DDValue numbOfStrips("nStrips");
0074 
0075     std::vector<const DDsvalues_type*> specs(fview.specifics());
0076     int nStrips = 0;
0077     for (auto& spec : specs) {
0078       if (DDfetch(spec, numbOfStrips)) {
0079         nStrips = int(numbOfStrips.doubles()[0]);
0080       }
0081     }
0082     if (nStrips == 0)
0083       edm::LogVerbatim("RPCGeometryParsFromDD") << "No strip found!!";
0084 
0085     const std::vector<double> dpar = fview.logicalPart().solid().parameters();
0086 
0087     const std::string name = fview.logicalPart().name().name();
0088 
0089     edm::LogVerbatim("RPCGeometryParsFromDD")
0090         << " (1) "
0091         << "detid: " << detid << " name: " << name << " number of Strips: " << nStrips;
0092 
0093     const std::vector<std::string> strpars = {name};
0094     const DDTranslation& tran = fview.translation();
0095 
0096     const DDRotationMatrix& rota = fview.rotation();  //.Inverse();
0097     DD3Vector x, y, z;
0098     rota.GetComponents(x, y, z);
0099     std::vector<double> pars;
0100     if (dpar.size() == 3) {
0101       const double width = dpar[0];
0102       const double length = dpar[1];
0103       const double thickness = dpar[2];
0104       edm::LogVerbatim("RPCGeometryParsFromDD")
0105           << " (2) dpar.size() == 3, width: " << width << " length: " << length << " thickness: " << thickness;
0106       pars = {width, length, thickness, numbOfStrips.doubles()[0]};
0107     } else {
0108       const double dpar4 = dpar[4];
0109       const double dpar8 = dpar[8];
0110       const double dpar0 = dpar[0];
0111       pars = {dpar4, dpar8, dpar0, 0.4, numbOfStrips.doubles()[0]};
0112       edm::LogVerbatim("RPCGeometryParsFromDD")
0113           << " (3), else, dpar[4]: " << dpar4 << " dpar[8]: " << dpar8 << " dpar[0]: " << dpar0;
0114     }
0115 
0116     const std::vector<double> vtra = {tran.x(), tran.y(), tran.z()};
0117 
0118     edm::LogVerbatim("RPCGeometryParsFromDD")
0119         << " (4), tran.x() " << tran.x() << " tran.y(): " << tran.y() << " tran.z(): " << tran.z();
0120 
0121     const std::vector<double> vrot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
0122     edm::LogVerbatim("RPCGeometryParsFromDD")
0123         << " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() " << x.X() << ", " << x.Y() << ", "
0124         << x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
0125     rgeo.insert(rpcid.rawId(), vtra, vrot, pars, strpars);
0126   }
0127 }
0128 
0129 // DD4hep
0130 
0131 void RPCGeometryParsFromDD::buildGeometry(cms::DDFilteredView& fview,
0132                                           const MuonGeometryConstants& muonConstants,
0133                                           RecoIdealGeometry& rgeo) {
0134   while (fview.firstChild()) {
0135     MuonGeometryNumbering mdddnum(muonConstants);
0136     RPCNumberingScheme rpcnum(muonConstants);
0137     int rawidCh = rpcnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
0138     RPCDetId rpcid = RPCDetId(rawidCh);
0139 
0140     auto nStrips = fview.get<double>("nStrips");
0141 
0142     std::vector<double> dpar = fview.parameters();
0143 
0144     std::string_view name = fview.name();
0145 
0146     edm::LogVerbatim("RPCGeometryParsFromDD")
0147         << " (1), detid: " << rawidCh << " name: " << std::string(name) << " number of Strips: " << nStrips;
0148 
0149     const std::vector<std::string> strpars = {std::string(name)};
0150 
0151     std::vector<double> tran(3);
0152     tran[0] = static_cast<double>(fview.translation().X()) / dd4hep::mm;
0153     tran[1] = static_cast<double>(fview.translation().Y()) / dd4hep::mm;
0154     tran[2] = static_cast<double>(fview.translation().Z()) / dd4hep::mm;
0155 
0156     DDRotationMatrix rota;
0157     fview.rot(rota);
0158     DD3Vector x, y, z;
0159     rota.GetComponents(x, y, z);
0160     const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
0161 
0162     if (dd4hep::isA<dd4hep::Box>(fview.solid())) {
0163       const std::vector<double> pars = {
0164           dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[2] / dd4hep::mm, double(nStrips)};
0165       edm::LogVerbatim("RPCGeometryParsFromDD")
0166           << " (2), dd4hep::Box, width: " << dpar[0] / dd4hep::mm << " length: " << dpar[1] / dd4hep::mm
0167           << " thickness: " << dpar[2] / dd4hep::mm;
0168       rgeo.insert(rpcid, tran, rot, pars, strpars);
0169     } else {
0170       const double ti = 0.4;
0171       const std::vector<double> pars = {
0172           dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[3] / dd4hep::mm, ti, double(nStrips)};
0173       edm::LogVerbatim("RPCGeometryParsFromDD") << " (3), else, dpar[0] (i.e. dpar[4] for DD): " << dpar[0] / dd4hep::mm
0174                                                 << " dpar[1] (i.e. dpar[8] for DD): " << dpar[1] / dd4hep::mm
0175                                                 << " dpar[3] (i.e. dpar[0] for DD): " << dpar[3] / dd4hep::mm;
0176       rgeo.insert(rpcid, tran, rot, pars, strpars);
0177     }
0178     edm::LogVerbatim("RPCGeometryParsFromDD")
0179         << " (4), tran.x(): " << tran[0] << " tran.y(): " << tran[1] << " tran.z(): " << tran[2];
0180     edm::LogVerbatim("RPCGeometryParsFromDD")
0181         << " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z(): " << x.X() << ", " << x.Y() << ", "
0182         << x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
0183   }
0184 }