CMS 3D CMS Logo

RPCGeometryParsFromDD.cc
Go to the documentation of this file.
1 /* Implementation of the RPCGeometryParsFromDD Class
2  * Build the RPCGeometry from the DDD and DD4hep description
3  *
4  * DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
5  * Author: Sergio Lo Meo (sergio.lo.meo@cern.ch)
6  * Created: Mon, 09 Nov 2020
7  *
8  */
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 #include <iostream>
21 #include <algorithm>
26 
28 
30 
31 // DD
33  const MuonGeometryConstants& muonConstants,
34  RecoIdealGeometry& rgeo) {
35  const std::string attribute = "ReadOutName";
36  const std::string value = "MuonRPCHits";
37 
38  // Asking only for the MuonRPC's
40  DDFilteredView fview(*cview, filter);
41 
42  this->buildGeometry(fview, muonConstants, rgeo);
43 }
44 
45 // DD4hep
46 
48  const MuonGeometryConstants& muonConstants,
49  RecoIdealGeometry& rgeo) {
50  const std::string attribute = "ReadOutName";
51  const std::string value = "MuonRPCHits";
52  const cms::DDFilter filter(attribute, value);
53  cms::DDFilteredView fview(*cview, filter);
54  this->buildGeometry(fview, muonConstants, rgeo);
55 }
56 
57 // DD
58 
60  const MuonGeometryConstants& muonConstants,
61  RecoIdealGeometry& rgeo) {
62  for (bool doSubDets = fview.firstChild(); doSubDets == true; doSubDets = fview.nextSibling()) {
63  // Get the Base Muon Number
64  MuonGeometryNumbering mdddnum(muonConstants);
65  MuonBaseNumber mbn = mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
66 
67  // Get the The Rpc det Id
68  RPCNumberingScheme rpcnum(muonConstants);
69  const int detid = rpcnum.baseNumberToUnitNumber(mbn);
70 
71  RPCDetId rpcid(detid);
72 
73  DDValue numbOfStrips("nStrips");
74 
75  std::vector<const DDsvalues_type*> specs(fview.specifics());
76  int nStrips = 0;
77  for (auto& spec : specs) {
78  if (DDfetch(spec, numbOfStrips)) {
79  nStrips = int(numbOfStrips.doubles()[0]);
80  }
81  }
82  if (nStrips == 0)
83  std::cout << "No strip found!!" << std::endl;
84 
85  const std::vector<double> dpar = fview.logicalPart().solid().parameters();
86 
87  const std::string name = fview.logicalPart().name().name();
88 
89  edm::LogVerbatim("RPCGeometryParsFromDD")
90  << " (1) "
91  << "detid: " << detid << " name: " << name << " number of Strips: " << nStrips;
92 
93  const std::vector<std::string> strpars = {name};
94  const DDTranslation& tran = fview.translation();
95 
96  const DDRotationMatrix& rota = fview.rotation(); //.Inverse();
97  DD3Vector x, y, z;
98  rota.GetComponents(x, y, z);
99  std::vector<double> pars;
100  if (dpar.size() == 3) {
101  const double width = dpar[0];
102  const double length = dpar[1];
103  const double thickness = dpar[2];
104  edm::LogVerbatim("RPCGeometryParsFromDD")
105  << " (2) dpar.size() == 3, width: " << width << " length: " << length << " thickness: " << thickness;
106  pars = {width, length, thickness, numbOfStrips.doubles()[0]};
107  } else {
108  const double dpar4 = dpar[4];
109  const double dpar8 = dpar[8];
110  const double dpar0 = dpar[0];
111  pars = {dpar4, dpar8, dpar0, 0.4, numbOfStrips.doubles()[0]};
112  edm::LogVerbatim("RPCGeometryParsFromDD")
113  << " (3), else, dpar[4]: " << dpar4 << " dpar[8]: " << dpar8 << " dpar[0]: " << dpar0;
114  }
115 
116  const std::vector<double> vtra = {tran.x(), tran.y(), tran.z()};
117 
118  edm::LogVerbatim("RPCGeometryParsFromDD")
119  << " (4), tran.x() " << tran.x() << " tran.y(): " << tran.y() << " tran.z(): " << tran.z();
120 
121  const std::vector<double> vrot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
122  edm::LogVerbatim("RPCGeometryParsFromDD")
123  << " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() " << x.X() << ", " << x.Y() << ", "
124  << x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
125  rgeo.insert(rpcid.rawId(), vtra, vrot, pars, strpars);
126  }
127 }
128 
129 // DD4hep
130 
132  const MuonGeometryConstants& muonConstants,
133  RecoIdealGeometry& rgeo) {
134  while (fview.firstChild()) {
135  MuonGeometryNumbering mdddnum(muonConstants);
136  RPCNumberingScheme rpcnum(muonConstants);
137  int rawidCh = rpcnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
138  RPCDetId rpcid = RPCDetId(rawidCh);
139 
140  auto nStrips = fview.get<double>("nStrips");
141 
142  std::vector<double> dpar = fview.parameters();
143 
144  std::string_view name = fview.name();
145 
146  edm::LogVerbatim("RPCGeometryParsFromDD")
147  << " (1), detid: " << rawidCh << " name: " << std::string(name) << " number of Strips: " << nStrips;
148 
149  const std::vector<std::string> strpars = {std::string(name)};
150 
151  std::vector<double> tran(3);
152  tran[0] = static_cast<double>(fview.translation().X()) / dd4hep::mm;
153  tran[1] = static_cast<double>(fview.translation().Y()) / dd4hep::mm;
154  tran[2] = static_cast<double>(fview.translation().Z()) / dd4hep::mm;
155 
156  DDRotationMatrix rota;
157  fview.rot(rota);
158  DD3Vector x, y, z;
159  rota.GetComponents(x, y, z);
160  const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
161 
162  if (dd4hep::isA<dd4hep::Box>(fview.solid())) {
163  const std::vector<double> pars = {
164  dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[2] / dd4hep::mm, double(nStrips)};
165  edm::LogVerbatim("RPCGeometryParsFromDD")
166  << " (2), dd4hep::Box, width: " << dpar[0] / dd4hep::mm << " length: " << dpar[1] / dd4hep::mm
167  << " thickness: " << dpar[2] / dd4hep::mm;
168  rgeo.insert(rpcid, tran, rot, pars, strpars);
169  } else {
170  const double ti = 0.4;
171  const std::vector<double> pars = {
172  dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[3] / dd4hep::mm, ti, double(nStrips)};
173  edm::LogVerbatim("RPCGeometryParsFromDD") << " (3), else, dpar[0] (i.e. dpar[4] for DD): " << dpar[0] / dd4hep::mm
174  << " dpar[1] (i.e. dpar[8] for DD): " << dpar[1] / dd4hep::mm
175  << " dpar[3] (i.e. dpar[0] for DD): " << dpar[3] / dd4hep::mm;
176  rgeo.insert(rpcid, tran, rot, pars, strpars);
177  }
178  edm::LogVerbatim("RPCGeometryParsFromDD")
179  << " (4), tran.x(): " << tran[0] << " tran.y(): " << tran[1] << " tran.z(): " << tran[2];
180  edm::LogVerbatim("RPCGeometryParsFromDD")
181  << " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z(): " << x.X() << ", " << x.Y() << ", "
182  << x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
183  }
184 }
Log< level::Info, true > LogVerbatim
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
bool nextSibling()
set the current node to the next sibling ...
int baseNumberToUnitNumber(const MuonBaseNumber &) const override
bool insert(DetId id, const std::vector< double > &trans, const std::vector< double > &rot, const std::vector< double > &pars)
const Double_t * rot() const
The absolute rotation of the current node.
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:125
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
void build(const DDCompactView *cview, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rgeo)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
std::string_view name() const
void buildGeometry(DDFilteredView &fview, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rgeo)
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const ExpandedNodes & history()
The numbering history of the current node.
Definition: value.py:1
bool firstChild()
set the current node to the first child
const N & name() const
Definition: DDBase.h:59
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
std::vector< const DDsvalues_type * > specifics() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
dd4hep::Solid solid() const
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
bool firstChild()
set the current node to the first child ...
const DDTranslation & translation() const
The absolute translation of the current node.
const std::vector< double > parameters() const
extract shape parameters
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history) const
const Translation translation() const