Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-09 23:31:58

0001 /* Implementation of the  ME0GeometryParsFromDD Class
0002  *  Build the ME0Geometry 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:  Thu, 25 Feb 2021 
0007  *
0008  */
0009 #include "Geometry/GEMGeometryBuilder/interface/ME0GeometryParsFromDD.h"
0010 #include "DataFormats/MuonDetId/interface/ME0DetId.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/ME0NumberingScheme.h"
0018 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0019 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0020 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0021 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0022 #include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
0023 
0024 #include <iostream>
0025 #include <algorithm>
0026 
0027 // DD
0028 
0029 void ME0GeometryParsFromDD::build(const DDCompactView* cview,
0030                                   const MuonGeometryConstants& muonConstants,
0031                                   RecoIdealGeometry& rgeo) {
0032   std::string attribute = "MuStructure";
0033   std::string value = "MuonEndCapME0";
0034 
0035   // Asking only for the MuonME0's
0036   DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
0037   DDFilteredView fview(*cview, filter);
0038 
0039   this->buildGeometry(fview, muonConstants, rgeo);
0040 }
0041 
0042 void ME0GeometryParsFromDD::buildGeometry(DDFilteredView& fv,
0043                                           const MuonGeometryConstants& muonConstants,
0044                                           RecoIdealGeometry& rgeo) {
0045   LogDebug("ME0GeometryParsFromDD") << "Building the geometry service";
0046   LogDebug("ME0GeometryParsFromDD") << "About to run through the ME0 structure\n"
0047                                     << " First logical part " << fv.logicalPart().name().name();
0048 
0049   edm::LogVerbatim("ME0GeometryParsFromDD") << "(0) ME0GeometryParsFromDD - DDD ";
0050   MuonGeometryNumbering muonDDDNumbering(muonConstants);
0051   ME0NumberingScheme me0Numbering(muonConstants);
0052 
0053   bool doChambers = fv.firstChild();
0054   LogDebug("ME0GeometryParsFromDD") << "doChamber = " << doChambers;
0055   // loop over superchambers
0056   while (doChambers) {
0057     // getting chamber id from eta partitions
0058     fv.firstChild();
0059     fv.firstChild();
0060     ME0DetId detIdCh =
0061         ME0DetId(me0Numbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
0062     // back to chambers
0063     fv.parent();
0064     fv.parent();
0065 
0066     buildChamber(fv, detIdCh, rgeo);
0067 
0068     // loop over chambers
0069     // only 1 chamber
0070     bool doLayers = fv.firstChild();
0071     while (doLayers) {
0072       // get layer ID
0073       fv.firstChild();
0074       ME0DetId detIdLa =
0075           ME0DetId(me0Numbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
0076       fv.parent();
0077       // build layer
0078       buildLayer(fv, detIdLa, rgeo);
0079 
0080       // loop over ME0EtaPartitions
0081       bool doEtaPart = fv.firstChild();
0082       while (doEtaPart) {
0083         ME0DetId detId =
0084             ME0DetId(me0Numbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
0085         buildEtaPartition(fv, detId, rgeo);
0086 
0087         doEtaPart = fv.nextSibling();
0088       }
0089       fv.parent();
0090       doLayers = fv.nextSibling();
0091     }
0092     fv.parent();
0093     doChambers = fv.nextSibling();
0094   }
0095 }
0096 
0097 void ME0GeometryParsFromDD::buildChamber(DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0098   LogDebug("ME0GeometryParsFromDD") << "buildChamber " << fv.logicalPart().name().name() << " " << detId << std::endl;
0099 
0100   std::vector<double> pars = getDimension(fv);
0101   std::vector<double> vtra = getTranslation(fv);
0102   std::vector<double> vrot = getRotation(fv);
0103   edm::LogVerbatim("ME0GeometryParsFromDD")
0104       << "(4) DDD, Chamber DetID " << detId.chamberId().rawId() << " Name " << fv.logicalPart().name().name();
0105 
0106   rgeo.insert(detId.chamberId().rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
0107 }
0108 
0109 void ME0GeometryParsFromDD::buildLayer(DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0110   LogDebug("ME0GeometryParsFromDD") << "buildLayer " << fv.logicalPart().name().name() << " " << detId << std::endl;
0111 
0112   std::vector<double> pars = getDimension(fv);
0113   std::vector<double> vtra = getTranslation(fv);
0114   std::vector<double> vrot = getRotation(fv);
0115 
0116   edm::LogVerbatim("ME0GeometryParsFromDD")
0117       << "(5) DDD, Layer DetID " << detId.layerId().rawId() << " Name " << fv.logicalPart().name().name();
0118   rgeo.insert(detId.layerId().rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
0119 }
0120 
0121 void ME0GeometryParsFromDD::buildEtaPartition(DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0122   LogDebug("ME0GeometryParsFromDD") << "buildEtaPartition " << fv.logicalPart().name().name() << " " << detId
0123                                     << std::endl;
0124 
0125   // EtaPartition specific parameter (nstrips and npads)
0126   DDValue numbOfStrips("nStrips");
0127   DDValue numbOfPads("nPads");
0128   const std::vector<const DDsvalues_type*>& specs = fv.specifics();
0129   double nStrips = 0., nPads = 0.;
0130   for (auto const& is : specs) {
0131     if (DDfetch(is, numbOfStrips))
0132       nStrips = numbOfStrips.doubles()[0];
0133     if (DDfetch(is, numbOfPads))
0134       nPads = numbOfPads.doubles()[0];
0135   }
0136   LogDebug("ME0GeometryParsFromDD") << ((nStrips == 0.) ? ("No nStrips found!!")
0137                                                         : ("Number of strips: " + std::to_string(nStrips)));
0138   LogDebug("ME0GeometryParsFromDD") << ((nPads == 0.) ? ("No nPads found!!")
0139                                                       : ("Number of pads: " + std::to_string(nPads)));
0140 
0141   std::vector<double> pars = getDimension(fv);
0142   pars.emplace_back(nStrips);
0143   pars.emplace_back(nPads);
0144   std::vector<double> vtra = getTranslation(fv);
0145   std::vector<double> vrot = getRotation(fv);
0146 
0147   edm::LogVerbatim("ME0GeometryParsFromDD")
0148       << "(6) DDD, Eta Partion DetID " << detId.rawId() << " Name " << fv.logicalPart().name().name() << " nStrips "
0149       << nStrips << " nPads " << nPads;
0150 
0151   rgeo.insert(detId.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
0152 }
0153 
0154 std::vector<double> ME0GeometryParsFromDD::getDimension(DDFilteredView& fv) {
0155   std::vector<double> dpar = fv.logicalPart().solid().parameters();
0156   //dpar[4] bottom width is along local X
0157   //dpar[8] top width is along local X
0158   //dpar[3] thickness is long local Z
0159   //dpar[0] length is along local Y
0160   LogDebug("ME0GeometryParsFromDD") << "dimension dx1 " << dpar[4] << ", dx2 " << dpar[8] << ", dy " << dpar[0]
0161                                     << ", dz " << dpar[3];
0162   edm::LogVerbatim("ME0GeometryParsFromDD")
0163       << "(1) DDD, dimension dx1 " << dpar[4] << ", dx2 " << dpar[8] << ", dy " << dpar[0] << ", dz " << dpar[3];
0164   return {dpar[4], dpar[8], dpar[0], dpar[3]};
0165 }
0166 
0167 std::vector<double> ME0GeometryParsFromDD::getTranslation(DDFilteredView& fv) {
0168   const DDTranslation& tran = fv.translation();
0169   edm::LogVerbatim("ME0GeometryParsFromDD")
0170       << "(2) DDD, tran vector " << tran.x() << "  " << tran.y() << "  " << tran.z();
0171   return {tran.x(), tran.y(), tran.z()};
0172 }
0173 
0174 std::vector<double> ME0GeometryParsFromDD::getRotation(DDFilteredView& fv) {
0175   const DDRotationMatrix& rota = fv.rotation();  //.Inverse();
0176   DD3Vector x, y, z;
0177   rota.GetComponents(x, y, z);
0178   edm::LogVerbatim("ME0GeometryParsFromDD")
0179       << "(3) DDD, rot matrix " << x.X() << "  " << x.Y() << "  " << x.Z() << " " << y.X() << "  " << y.Y() << "  "
0180       << y.Z() << " " << z.X() << "  " << z.Y() << "  " << z.Z();
0181   return {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
0182 }
0183 
0184 // DD4hep
0185 
0186 void ME0GeometryParsFromDD::build(const cms::DDCompactView* cview,
0187                                   const MuonGeometryConstants& muonConstants,
0188                                   RecoIdealGeometry& rgeo) {
0189   std::string attribute = "MuStructure";
0190   std::string value = "MuonEndCapME0";
0191   const cms::DDFilter filter(attribute, value);
0192   cms::DDFilteredView fview(*cview, filter);
0193   this->buildGeometry(fview, muonConstants, rgeo);
0194 }
0195 
0196 void ME0GeometryParsFromDD::buildGeometry(cms::DDFilteredView& fv,
0197                                           const MuonGeometryConstants& muonConstants,
0198                                           RecoIdealGeometry& rgeo) {
0199   edm::LogVerbatim("ME0GeometryParsFromDD") << "(0) ME0GeometryParsFromDD - DD4hep ";
0200 
0201   MuonGeometryNumbering mdddnum(muonConstants);
0202   ME0NumberingScheme me0Num(muonConstants);
0203 
0204   static constexpr uint32_t levelChamber = 7;
0205   static constexpr uint32_t levelLayer = 8;
0206   uint32_t theLevelPart = muonConstants.getValue("level");
0207   uint32_t theSectorLevel = muonConstants.getValue("m0_sector") / theLevelPart;
0208 
0209   while (fv.firstChild()) {
0210     const auto& history = fv.history();
0211     MuonBaseNumber num(mdddnum.geoHistoryToBaseNumber(history));
0212     ME0DetId detId(me0Num.baseNumberToUnitNumber(num));
0213 
0214     if (fv.level() == levelChamber) {
0215       buildChamber(fv, detId, rgeo);
0216     } else if (fv.level() == levelLayer) {
0217       buildLayer(fv, detId, rgeo);
0218     } else if (history.tags.size() > theSectorLevel) {
0219       buildEtaPartition(fv, detId, rgeo);
0220     }
0221   }  // end while
0222 }  // end buildGeometry
0223 
0224 void ME0GeometryParsFromDD::buildChamber(cms::DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0225   std::string_view name = fv.name();
0226   std::vector<double> pars = getDimension(fv);
0227   std::vector<double> vtra = getTranslation(fv);
0228   std::vector<double> vrot = getRotation(fv);
0229 
0230   edm::LogVerbatim("ME0GeometryParsFromDD")
0231       << "(4) DD4hep, Chamber DetID " << detId.chamberId().rawId() << " Name " << std::string(name);
0232 
0233   rgeo.insert(detId.chamberId().rawId(), vtra, vrot, pars, {std::string(name)});
0234 }
0235 
0236 void ME0GeometryParsFromDD::buildLayer(cms::DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0237   std::string_view name = fv.name();
0238   std::vector<double> pars = getDimension(fv);
0239   std::vector<double> vtra = getTranslation(fv);
0240   std::vector<double> vrot = getRotation(fv);
0241 
0242   edm::LogVerbatim("ME0GeometryParsFromDD")
0243       << "(5) DD4hep, Layer DetID " << detId.layerId().rawId() << " Name " << std::string(name);
0244   rgeo.insert(detId.layerId().rawId(), vtra, vrot, pars, {std::string(name)});
0245 }
0246 
0247 void ME0GeometryParsFromDD::buildEtaPartition(cms::DDFilteredView& fv, ME0DetId detId, RecoIdealGeometry& rgeo) {
0248   auto nStrips = fv.get<double>("nStrips");
0249   auto nPads = fv.get<double>("nPads");
0250   std::string_view name = fv.name();
0251   std::vector<double> pars = getDimension(fv);
0252   pars.emplace_back(nStrips);
0253   pars.emplace_back(nPads);
0254   std::vector<double> vtra = getTranslation(fv);
0255   std::vector<double> vrot = getRotation(fv);
0256 
0257   edm::LogVerbatim("ME0GeometryParsFromDD") << "(6) DD4hep, Eta Partion DetID " << detId.rawId() << " Name "
0258                                             << std::string(name) << " nStrips " << nStrips << " nPads " << nPads;
0259 
0260   rgeo.insert(detId.rawId(), vtra, vrot, pars, {std::string(name)});
0261 }
0262 
0263 std::vector<double> ME0GeometryParsFromDD::getDimension(cms::DDFilteredView& fv) {
0264   std::vector<double> dpar = fv.parameters();
0265 
0266   edm::LogVerbatim("ME0GeometryParsFromDD")
0267       << "(1) DD4hep, dimension dx1 " << dpar[0] / dd4hep::mm << ", dx2 " << dpar[1] / dd4hep::mm << ", dy "
0268       << dpar[3] / dd4hep::mm << ", dz " << dpar[2] / dd4hep::mm;
0269 
0270   return {dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[3] / dd4hep::mm, dpar[2] / dd4hep::mm};
0271 }
0272 
0273 std::vector<double> ME0GeometryParsFromDD::getTranslation(cms::DDFilteredView& fv) {
0274   std::vector<double> tran(3);
0275   tran[0] = static_cast<double>(fv.translation().X()) / dd4hep::mm;
0276   tran[1] = static_cast<double>(fv.translation().Y()) / dd4hep::mm;
0277   tran[2] = static_cast<double>(fv.translation().Z()) / dd4hep::mm;
0278 
0279   edm::LogVerbatim("ME0GeometryParsFromDD")
0280       << "(2) DD4hep, tran vector " << tran[0] << "  " << tran[1] << "  " << tran[2];
0281   return {tran[0], tran[1], tran[2]};
0282 }
0283 
0284 std::vector<double> ME0GeometryParsFromDD::getRotation(cms::DDFilteredView& fv) {
0285   DDRotationMatrix rota;
0286   fv.rot(rota);
0287   DD3Vector x, y, z;
0288   rota.GetComponents(x, y, z);
0289   const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
0290   edm::LogVerbatim("ME0GeometryParsFromDD")
0291       << "(3) DD4hep, rot matrix " << rot[0] << "  " << rot[1] << "  " << rot[2] << " " << rot[3] << "  " << rot[4]
0292       << "  " << rot[5] << " " << rot[6] << "  " << rot[7] << "  " << rot[8];
0293   return {rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]};
0294 }