Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:56

0001 /** \file
0002  *
0003  *  \author N. Amapane - CERN. 
0004  */
0005 
0006 #include <Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h>
0007 #include <Geometry/DTGeometry/interface/DTGeometry.h>
0008 #include <Geometry/DTGeometry/interface/DTChamber.h>
0009 #include <Geometry/DTGeometry/interface/DTLayer.h>
0010 
0011 #include <DetectorDescription/Core/interface/DDFilter.h>
0012 #include <DetectorDescription/Core/interface/DDFilteredView.h>
0013 #include <DetectorDescription/Core/interface/DDSolid.h>
0014 #include "DataFormats/Math/interface/GeantUnits.h"
0015 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0016 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0017 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
0018 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0019 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include <string>
0022 
0023 using namespace std;
0024 using namespace geant_units;
0025 using namespace geant_units::operators;
0026 
0027 #include <string>
0028 #include <utility>
0029 
0030 using namespace std;
0031 
0032 DTGeometryBuilderFromDDD::DTGeometryBuilderFromDDD() {}
0033 
0034 DTGeometryBuilderFromDDD::~DTGeometryBuilderFromDDD() {}
0035 
0036 void DTGeometryBuilderFromDDD::build(DTGeometry& theGeometry,
0037                                      const DDCompactView* cview,
0038                                      const MuonGeometryConstants& muonConstants) {
0039   //  cout << "DTGeometryBuilderFromDDD::build" << endl;
0040   //   static const string t0 = "DTGeometryBuilderFromDDD::build";
0041   //   TimeMe timer(t0,true);
0042 
0043   std::string attribute = "MuStructure";
0044   std::string value = "MuonBarrelDT";
0045 
0046   // Asking only for the Muon DTs
0047   DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
0048 
0049   DDFilteredView fview(*cview, filter);
0050   buildGeometry(theGeometry, fview, muonConstants);
0051 }
0052 
0053 void DTGeometryBuilderFromDDD::buildGeometry(DTGeometry& theGeometry,
0054                                              DDFilteredView& fv,
0055                                              const MuonGeometryConstants& muonConstants) const {
0056   edm::LogVerbatim("DTGeometryBuilder") << "(0) DTGeometryBuilder - DDD ";
0057 
0058   bool doChamber = fv.firstChild();
0059 
0060   // Loop on chambers
0061   int ChamCounter = 0;
0062   while (doChamber) {
0063     ChamCounter++;
0064     DDValue val("Type");
0065     const DDsvalues_type params(fv.mergedSpecifics());
0066     string type;
0067     if (DDfetch(&params, val))
0068       type = val.strings()[0];
0069     // FIXME
0070     val = DDValue("FEPos");
0071     string FEPos;
0072     if (DDfetch(&params, val))
0073       FEPos = val.strings()[0];
0074     DTChamber* chamber = buildChamber(fv, type, muonConstants);
0075 
0076     // Loop on SLs
0077     bool doSL = fv.firstChild();
0078     int SLCounter = 0;
0079     while (doSL) {
0080       SLCounter++;
0081       DTSuperLayer* sl = buildSuperLayer(fv, chamber, type, muonConstants);
0082       theGeometry.add(sl);
0083 
0084       bool doL = fv.firstChild();
0085       int LCounter = 0;
0086       // Loop on SLs
0087       while (doL) {
0088         LCounter++;
0089         DTLayer* layer = buildLayer(fv, sl, type, muonConstants);
0090         theGeometry.add(layer);
0091 
0092         fv.parent();
0093         doL = fv.nextSibling();  // go to next layer
0094       }                          // layers
0095 
0096       fv.parent();
0097       doSL = fv.nextSibling();  // go to next SL
0098     }                           // sls
0099     theGeometry.add(chamber);
0100 
0101     fv.parent();
0102     doChamber = fv.nextSibling();  // go to next chamber
0103   }                                // chambers
0104 }
0105 
0106 DTChamber* DTGeometryBuilderFromDDD::buildChamber(DDFilteredView& fv,
0107                                                   const string& type,
0108                                                   const MuonGeometryConstants& muonConstants) const {
0109   MuonGeometryNumbering mdddnum(muonConstants);
0110   DTNumberingScheme dtnum(muonConstants);
0111   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0112   DTChamberId detId(rawid);
0113 
0114   // Chamber specific parameter (size)
0115   // FIXME: some trouble for boolean solids?
0116   vector<double> par = extractParameters(fv);
0117 
0118   ///SL the definition of length, width, thickness depends on the local reference frame of the Det
0119   // width is along local X. r-phi  dimension - different in different chambers
0120   // length is along local Y. z      dimension - constant 125.55 cm
0121   // thickness is long local Z. radial thickness - almost constant about 18 cm
0122 
0123   edm::LogVerbatim("DTGeometryBuilder") << "(1) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0124                                         << " par[2]: " << par[2];
0125 
0126   RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0127 
0128   DTChamber* chamber = new DTChamber(detId, surf);
0129 
0130   return chamber;
0131 }
0132 
0133 DTSuperLayer* DTGeometryBuilderFromDDD::buildSuperLayer(DDFilteredView& fv,
0134                                                         DTChamber* chamber,
0135                                                         const std::string& type,
0136                                                         const MuonGeometryConstants& muonConstants) const {
0137   MuonGeometryNumbering mdddnum(muonConstants);
0138   DTNumberingScheme dtnum(muonConstants);
0139   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0140   DTSuperLayerId slId(rawid);
0141 
0142   // Slayer specific parameter (size)
0143   vector<double> par = extractParameters(fv);
0144 
0145   edm::LogVerbatim("DTGeometryBuilder") << "(2) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0146                                         << " par[2]: " << par[2];
0147 
0148   // r-phi  dimension - different in different chambers
0149   // z      dimension - constant 126.8 cm
0150   // radial thickness - almost constant about 20 cm
0151 
0152   // Ok this is the s-layer position...
0153   RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0154 
0155   DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
0156 
0157   //LocalPoint lpos(10,20,30);
0158   //GlobalPoint gpos=slayer->toGlobal(lpos);
0159 
0160   // add to the chamber
0161   chamber->add(slayer);
0162   return slayer;
0163 }
0164 
0165 DTLayer* DTGeometryBuilderFromDDD::buildLayer(DDFilteredView& fv,
0166                                               DTSuperLayer* sl,
0167                                               const std::string& type,
0168                                               const MuonGeometryConstants& muonConstants) const {
0169   MuonGeometryNumbering mdddnum(muonConstants);
0170   DTNumberingScheme dtnum(muonConstants);
0171   int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
0172   DTLayerId layId(rawid);
0173 
0174   // Layer specific parameter (size)
0175   vector<double> par = extractParameters(fv);
0176   // width -- r-phi  dimension - different in different chambers
0177   // length -- z      dimension - constant 126.8 cm
0178   // thickness -- radial thickness - almost constant about 20 cm
0179 
0180   RCPPlane surf(plane(fv, dtGeometryBuilder::getRecPlaneBounds(par.begin())));
0181 
0182   edm::LogVerbatim("DTGeometryBuilder") << "(3) detId: " << rawid << " par[0]: " << par[0] << " par[1]: " << par[1]
0183                                         << " par[2]: " << par[2];
0184 
0185   // Loop on wires
0186   bool doWire = fv.firstChild();
0187   int WCounter = 0;
0188   int firstWire = fv.copyno();
0189   par = extractParameters(fv);
0190   float wireLength = convertMmToCm(par[1]);
0191 
0192   edm::LogVerbatim("DTGeometryBuilder") << "(4) detId: " << rawid
0193                                         << " wireLenght in ddd, wpar[1] in dd4hep: " << wireLength
0194                                         << " firstWire: " << firstWire;
0195 
0196   while (doWire) {
0197     WCounter++;
0198     doWire = fv.nextSibling();  // next wire
0199   }
0200   //int lastWire=fv.copyno();
0201   DTTopology topology(firstWire, WCounter, wireLength);
0202 
0203   DTLayerType layerType;
0204 
0205   DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
0206 
0207   sl->add(layer);
0208   return layer;
0209 }
0210 
0211 vector<double> DTGeometryBuilderFromDDD::extractParameters(DDFilteredView& fv) const {
0212   vector<double> par;
0213   if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
0214     DDBooleanSolid bs(fv.logicalPart().solid());
0215     DDSolid A = bs.solidA();
0216     while (A.shape() != DDSolidShape::ddbox) {
0217       DDBooleanSolid bs(A);
0218       A = bs.solidA();
0219     }
0220     par = A.parameters();
0221   } else {
0222     par = fv.logicalPart().solid().parameters();
0223   }
0224   return par;
0225 }
0226 
0227 DTGeometryBuilderFromDDD::RCPPlane DTGeometryBuilderFromDDD::plane(const DDFilteredView& fv, Bounds* bounds) const {
0228   // extract the position
0229   const DDTranslation& trans(fv.translation());
0230 
0231   const Surface::PositionType posResult(
0232       float(convertMmToCm(trans.x())), float(convertMmToCm(trans.y())), float(convertMmToCm(trans.z())));
0233   LogTrace("DTGeometryBuilderFromDDD") << "DTGeometryBuilderFromDDD::plane "
0234                                        << " posResult: " << posResult << std::endl;
0235   // now the rotation
0236   //     'active' and 'passive' rotations are inverse to each other
0237   const DDRotationMatrix& rotation = fv.rotation();  //REMOVED .Inverse();
0238   DD3Vector x, y, z;
0239   rotation.GetComponents(x, y, z);
0240   //   std::cout << "INVERSE rotation by its own operator: "<< fv.rotation() << std::endl;
0241   //   std::cout << "INVERSE rotation manually: "
0242   //        << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
0243   //        << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
0244   //        << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
0245 
0246   Surface::RotationType rotResult(float(x.X()),
0247                                   float(x.Y()),
0248                                   float(x.Z()),
0249                                   float(y.X()),
0250                                   float(y.Y()),
0251                                   float(y.Z()),
0252                                   float(z.X()),
0253                                   float(z.Y()),
0254                                   float(z.Z()));
0255 
0256   //   std::cout << "rotation by its own operator: "<< tmp << std::endl;
0257   //   DD3Vector tx, ty,tz;
0258   //   tmp.GetComponents(tx, ty, tz);
0259   //   std::cout << "rotation manually: "
0260   //        << tx.X() << ", " << tx.Y() << ", " << tx.Z() << std::endl
0261   //        << ty.X() << ", " << ty.Y() << ", " << ty.Z() << std::endl
0262   //        << tz.X() << ", " << tz.Y() << ", " << tz.Z() << std::endl;
0263 
0264   return RCPPlane(new Plane(posResult, rotResult, bounds));
0265 }