Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \class DTGeometryParsFromDD
0002  *
0003  *  Build the RPCGeometry from the DDD and DD4hep description
0004  *  
0005  *  DD4hep part added to the original old file (DD version) made by Stefano Lacaprara (INFN LNL)
0006  *  \author:  Sergio Lo Meo (sergio.lo.meo@cern.ch) 
0007  *  Created:  Tue, 26 Jan 2021 
0008  *
0009  */
0010 #include <Geometry/DTGeometryBuilder/interface/DTGeometryParsFromDD.h>
0011 #include <Geometry/DTGeometry/interface/DTGeometry.h>
0012 #include <Geometry/DTGeometry/interface/DTChamber.h>
0013 #include <Geometry/DTGeometry/interface/DTLayer.h>
0014 #include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
0015 #include <DetectorDescription/Core/interface/DDFilter.h>
0016 #include <DetectorDescription/Core/interface/DDFilteredView.h>
0017 #include <DetectorDescription/Core/interface/DDSolid.h>
0018 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0019 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0020 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
0021 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0022 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0023 #include "DataFormats/Math/interface/GeantUnits.h"
0024 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0025 #include <DetectorDescription/DDCMS/interface/DDFilteredView.h>
0026 #include <DetectorDescription/DDCMS/interface/DDCompactView.h>
0027 #include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include <iostream>
0030 #include <algorithm>
0031 #include <string>
0032 
0033 using namespace std;
0034 using namespace geant_units;
0035 using namespace geant_units::operators;
0036 
0037 DTGeometryParsFromDD::DTGeometryParsFromDD() {}
0038 
0039 DTGeometryParsFromDD::~DTGeometryParsFromDD() {}
0040 
0041 // DD
0042 void DTGeometryParsFromDD::build(const DDCompactView* cview,
0043                                  const MuonGeometryConstants& muonConstants,
0044                                  RecoIdealGeometry& rig) {
0045   //  cout << "DTGeometryParsFromDD::build" << endl;
0046   //   static const string t0 = "DTGeometryParsFromDD::build";
0047   //   TimeMe timer(t0,true);
0048 
0049   std::string attribute = "MuStructure";
0050   std::string value = "MuonBarrelDT";
0051 
0052   // Asking only for the Muon DTs
0053   DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
0054   DDFilteredView fview(*cview, filter);
0055   buildGeometry(fview, muonConstants, rig);
0056   //cout << "RecoIdealGeometry " << rig.size() << endl;
0057 }
0058 
0059 // DD4hep
0060 
0061 void DTGeometryParsFromDD::build(const cms::DDCompactView* cview,
0062                                  const MuonGeometryConstants& muonConstants,
0063                                  RecoIdealGeometry& rgeo) {
0064   const std::string attribute = "MuStructure";
0065   const std::string value = "MuonBarrelDT";
0066   const cms::DDFilter filter(attribute, value);
0067   cms::DDFilteredView fview(*cview, filter);
0068   buildGeometry(fview, muonConstants, rgeo);
0069 }
0070 
0071 // DD
0072 void DTGeometryParsFromDD::buildGeometry(DDFilteredView& fv,
0073                                          const MuonGeometryConstants& muonConstants,
0074                                          RecoIdealGeometry& rig) const {
0075   // static const string t0 = "DTGeometryParsFromDD::buildGeometry";
0076   // TimeMe timer(t0,true);
0077 
0078   edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DDD ";
0079 
0080   bool doChamber = fv.firstChild();
0081 
0082   // Loop on chambers
0083   int ChamCounter = 0;
0084   while (doChamber) {
0085     ChamCounter++;
0086     DDValue val("Type");
0087     const DDsvalues_type params(fv.mergedSpecifics());
0088     string type;
0089     if (DDfetch(&params, val))
0090       type = val.strings()[0];
0091     // FIXME
0092     val = DDValue("FEPos");
0093     string FEPos;
0094     if (DDfetch(&params, val))
0095       FEPos = val.strings()[0];
0096     insertChamber(fv, type, muonConstants, rig);
0097 
0098     // Loop on SLs
0099     bool doSL = fv.firstChild();
0100     int SLCounter = 0;
0101     while (doSL) {
0102       SLCounter++;
0103       insertSuperLayer(fv, type, muonConstants, rig);
0104 
0105       bool doL = fv.firstChild();
0106       int LCounter = 0;
0107       // Loop on SLs
0108       while (doL) {
0109         LCounter++;
0110         insertLayer(fv, type, muonConstants, rig);
0111 
0112         // fv.parent();
0113         doL = fv.nextSibling();  // go to next layer
0114       }                          // layers
0115 
0116       fv.parent();
0117       doSL = fv.nextSibling();  // go to next SL
0118     }                           // sls
0119 
0120     fv.parent();
0121     doChamber = fv.nextSibling();  // go to next chamber
0122   }                                // chambers
0123 }
0124 
0125 void DTGeometryParsFromDD::insertChamber(DDFilteredView& fv,
0126                                          const string& type,
0127                                          const MuonGeometryConstants& muonConstants,
0128                                          RecoIdealGeometry& rig) const {
0129   MuonGeometryNumbering mdddnum(muonConstants);
0130   DTNumberingScheme dtnum(muonConstants);
0131   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0132   DTChamberId detId(rawid);
0133   //cout << "inserting Chamber " << detId << endl;
0134 
0135   // Chamber specific parameter (size)
0136   vector<double> par;
0137   par.emplace_back(DTChamberTag);
0138   vector<double> size = extractParameters(fv);
0139   par.insert(par.end(), size.begin(), size.end());
0140   edm::LogVerbatim("DTGeometryParsFromDD")
0141       << "(1) DDD, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
0142   ///SL the definition of length, width, thickness depends on the local reference frame of the Det
0143   // width is along local X
0144   // length is along local Y
0145   // thickness is long local Z
0146 
0147   PosRotPair posRot(plane(fv));
0148   rig.insert(rawid, posRot.first, posRot.second, par);
0149 }
0150 
0151 void DTGeometryParsFromDD::insertSuperLayer(DDFilteredView& fv,
0152                                             const std::string& type,
0153                                             const MuonGeometryConstants& muonConstants,
0154                                             RecoIdealGeometry& rig) const {
0155   MuonGeometryNumbering mdddnum(muonConstants);
0156   DTNumberingScheme dtnum(muonConstants);
0157   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0158   DTSuperLayerId slId(rawid);
0159   //cout << "inserting SuperLayer " << slId << endl;
0160 
0161   // Slayer specific parameter (size)
0162   vector<double> par;
0163   par.emplace_back(DTSuperLayerTag);
0164   vector<double> size = extractParameters(fv);
0165   par.insert(par.end(), size.begin(), size.end());
0166   edm::LogVerbatim("DTGeometryParsFromDD")
0167       << "(2) DDD, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
0168   // Ok this is the slayer position...
0169   PosRotPair posRot(plane(fv));
0170   rig.insert(slId, posRot.first, posRot.second, par);
0171 }
0172 
0173 void DTGeometryParsFromDD::insertLayer(DDFilteredView& fv,
0174                                        const std::string& type,
0175                                        const MuonGeometryConstants& muonConstants,
0176                                        RecoIdealGeometry& rig) const {
0177   MuonGeometryNumbering mdddnum(muonConstants);
0178   DTNumberingScheme dtnum(muonConstants);
0179   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0180   DTLayerId layId(rawid);
0181   //cout << "inserting Layer " << layId << endl;
0182 
0183   // Layer specific parameter (size)
0184   vector<double> par;
0185   par.emplace_back(DTLayerTag);
0186   vector<double> size = extractParameters(fv);
0187   par.insert(par.end(), size.begin(), size.end());
0188 
0189   // Loop on wires
0190   bool doWire = fv.firstChild();
0191   int WCounter = 0;
0192   int firstWire = fv.copyno();
0193   //float wireLength = par[1]/cm;
0194   while (doWire) {
0195     WCounter++;
0196     doWire = fv.nextSibling();  // next wire
0197   }
0198   vector<double> sensSize = extractParameters(fv);
0199   //int lastWire=fv.copyno();
0200   par.emplace_back(firstWire);
0201   par.emplace_back(WCounter);
0202   par.emplace_back(sensSize[1]);
0203   fv.parent();
0204 
0205   PosRotPair posRot(plane(fv));
0206 
0207   edm::LogVerbatim("DTGeometryParsFromDD")
0208       << "(3) DDD, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
0209       << par[4] << " " << par[5] << " " << par[6];
0210   rig.insert(layId, posRot.first, posRot.second, par);
0211 }
0212 
0213 vector<double> DTGeometryParsFromDD::extractParameters(DDFilteredView& fv) const {
0214   vector<double> par;
0215   if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
0216     DDBooleanSolid bs(fv.logicalPart().solid());
0217     DDSolid A = bs.solidA();
0218     while (A.shape() != DDSolidShape::ddbox) {
0219       DDBooleanSolid bs(A);
0220       A = bs.solidA();
0221     }
0222     par = A.parameters();
0223   } else {
0224     par = fv.logicalPart().solid().parameters();
0225   }
0226   return par;
0227 }
0228 
0229 DTGeometryParsFromDD::PosRotPair DTGeometryParsFromDD::plane(const DDFilteredView& fv) const {
0230   // extract the position
0231   const DDTranslation& trans(fv.translation());
0232 
0233   std::vector<double> gtran(3);
0234   gtran[0] = convertMmToCm(trans.x());
0235   gtran[1] = convertMmToCm(trans.y());
0236   gtran[2] = convertMmToCm(trans.z());
0237 
0238   edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DDD, Position "
0239                                            << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
0240   // now the rotation
0241   //     'active' and 'passive' rotations are inverse to each other
0242   const DDRotationMatrix& rotation = fv.rotation();  //REMOVED .Inverse();
0243   DD3Vector x, y, z;
0244   rotation.GetComponents(x, y, z);
0245 
0246   std::vector<double> grmat(9);
0247   grmat[0] = x.X();
0248   grmat[1] = x.Y();
0249   grmat[2] = x.Z();
0250 
0251   grmat[3] = y.X();
0252   grmat[4] = y.Y();
0253   grmat[5] = y.Z();
0254 
0255   grmat[6] = z.X();
0256   grmat[7] = z.Y();
0257   grmat[8] = z.Z();
0258 
0259   return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
0260 }
0261 
0262 // DD4hep
0263 
0264 void DTGeometryParsFromDD::buildGeometry(cms::DDFilteredView& fv,
0265                                          const MuonGeometryConstants& muonConstants,
0266                                          RecoIdealGeometry& rig) const {
0267   edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DD4hep ";
0268 
0269   bool doChamber = fv.firstChild();
0270 
0271   while (doChamber) {
0272     insertChamber(fv, muonConstants, rig);
0273 
0274     bool doSL = fv.nextSibling();
0275     while (doSL) {
0276       insertSuperLayer(fv, muonConstants, rig);
0277 
0278       fv.down();
0279       bool doLayers = fv.sibling();
0280       while (doLayers) {
0281         insertLayer(fv, muonConstants, rig);
0282 
0283         doLayers = fv.sibling();
0284       }
0285 
0286       doSL = fv.nextSibling();
0287     }
0288 
0289     fv.parent();
0290     doChamber = fv.firstChild();
0291   }
0292 }
0293 
0294 DTGeometryParsFromDD::PosRotPair DTGeometryParsFromDD::plane(const cms::DDFilteredView& fv) const {
0295   const Double_t* tr = fv.trans();
0296 
0297   std::vector<double> gtran(3);
0298 
0299   gtran[0] = tr[0] / dd4hep::cm;
0300   gtran[1] = tr[1] / dd4hep::cm;
0301   gtran[2] = tr[2] / dd4hep::cm;
0302 
0303   edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DD4hep, Position "
0304                                            << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
0305 
0306   DDRotationMatrix rotation = fv.rotation();
0307   DD3Vector x, y, z;
0308   rotation.GetComponents(x, y, z);
0309 
0310   std::vector<double> grmat(9);
0311 
0312   grmat[0] = x.X();
0313   grmat[1] = x.Y();
0314   grmat[2] = x.Z();
0315 
0316   grmat[3] = y.X();
0317   grmat[4] = y.Y();
0318   grmat[5] = y.Z();
0319 
0320   grmat[6] = z.X();
0321   grmat[7] = z.Y();
0322   grmat[8] = z.Z();
0323 
0324   return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
0325 }
0326 
0327 void DTGeometryParsFromDD::insertChamber(cms::DDFilteredView& fv,
0328                                          const MuonGeometryConstants& muonConstants,
0329                                          RecoIdealGeometry& rig) const {
0330   MuonGeometryNumbering mdddnum(muonConstants);
0331   DTNumberingScheme dtnum(muonConstants);
0332   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
0333   DTChamberId detId(rawid);
0334 
0335   vector<double> par_temp = fv.parameters();
0336   vector<double> par(4);
0337   par[0] = DTChamberTag;  //DTChamberTag is the ID of a Chamber
0338   par[1] = par_temp[0] / dd4hep::mm;
0339   par[2] = par_temp[1] / dd4hep::mm;
0340   par[3] = par_temp[2] / dd4hep::mm;
0341 
0342   edm::LogVerbatim("DTGeometryParsFromDD")
0343       << "(1) DD4hep, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
0344   PosRotPair posRot(plane(fv));
0345   rig.insert(rawid, posRot.first, posRot.second, par);
0346 }
0347 
0348 void DTGeometryParsFromDD::insertSuperLayer(cms::DDFilteredView& fv,
0349                                             const MuonGeometryConstants& muonConstants,
0350                                             RecoIdealGeometry& rig) const {
0351   MuonGeometryNumbering mdddnum(muonConstants);
0352   DTNumberingScheme dtnum(muonConstants);
0353   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
0354   DTSuperLayerId slId(rawid);
0355 
0356   vector<double> par_temp = fv.parameters();
0357   vector<double> par(4);
0358   par[0] = DTSuperLayerTag;  //DTSuperLayerTag is the ID of a SuperLayer
0359   par[1] = par_temp[0] / dd4hep::mm;
0360   par[2] = par_temp[1] / dd4hep::mm;
0361   par[3] = par_temp[2] / dd4hep::mm;
0362 
0363   edm::LogVerbatim("DTGeometryParsFromDD")
0364       << "(2) DD4hep, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
0365   PosRotPair posRot(plane(fv));
0366   rig.insert(slId, posRot.first, posRot.second, par);
0367 }
0368 
0369 void DTGeometryParsFromDD::insertLayer(cms::DDFilteredView& fv,
0370                                        const MuonGeometryConstants& muonConstants,
0371                                        RecoIdealGeometry& rig) const {
0372   MuonGeometryNumbering mdddnum(muonConstants);
0373   DTNumberingScheme dtnum(muonConstants);
0374   int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
0375   DTLayerId layId(rawid);
0376 
0377   vector<double> par_temp = fv.parameters();
0378   vector<double> par(4);
0379   par[0] = DTLayerTag;  //DTLayerTag is the ID of a Layer
0380   par[1] = par_temp[0] / dd4hep::mm;
0381   par[2] = par_temp[1] / dd4hep::mm;
0382   par[3] = par_temp[2] / dd4hep::mm;
0383 
0384   fv.down();
0385   bool doWire = fv.sibling();
0386   int firstWire = fv.volume()->GetNumber();
0387   auto const& wpar = fv.parameters();
0388   float wireLength = wpar[1] / dd4hep::mm;
0389 
0390   int WCounter = 0;
0391   while (doWire) {
0392     doWire = fv.checkChild();
0393     WCounter++;
0394   }
0395 
0396   par.emplace_back(firstWire);
0397   par.emplace_back(WCounter);
0398   par.emplace_back(wireLength);
0399 
0400   fv.up();
0401 
0402   PosRotPair posRot(plane(fv));
0403 
0404   edm::LogVerbatim("DTGeometryParsFromDD")
0405       << "(3) DD4hep, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
0406       << par[4] << " " << par[5] << " " << par[6];
0407   rig.insert(layId, posRot.first, posRot.second, par);
0408 }