CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DetGeomDesc.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of the TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 * CMSSW developers (based on GeometricDet class)
7 *
8 ****************************************************************************/
9 
10 #include <utility>
11 
15 
18 
23 #include <DD4hep/DD4hepUnits.h>
25 
26 /*
27  * Constructor from old DD DDFilteredView, also using the SpecPars to access 2x2 wafers info.
28  */
30  : m_name(computeNameWithNoNamespace(fv.name())),
31  m_copy(fv.copyno()),
32  m_isDD4hep(false),
33  m_trans(fv.translation()), // mm (legacy)
34  m_rot(fv.rotation()),
35  m_params(fv.parameters()), // default unit from old DD (mm)
36  m_isABox(fv.shape() == DDSolidShape::ddbox),
37  m_diamondBoxParams(computeDiamondDimensions(m_isABox, m_isDD4hep, m_params)), // mm (legacy)
38  m_sensorType(computeSensorType(fv.logicalPart().name().fullname())),
39  m_geographicalID(computeDetID(m_name, fv.copyNumbers(), fv.copyno(), isRun2)),
40  m_z(fv.translation().z()) // mm (legacy)
41 {}
42 
43 /*
44  * Constructor from DD4hep DDFilteredView, also using the SpecPars to access 2x2 wafers info.
45  */
47  : m_name(computeNameWithNoNamespace(fv.name())),
48  m_copy(fv.copyNum()),
49  m_isDD4hep(true),
50  m_trans(fv.translation() / dd4hep::mm), // converted from DD4hep unit to mm
51  m_rot(fv.rotation()),
52  m_params(computeParameters(fv)), // default unit from DD4hep
53  m_isABox(dd4hep::isA<dd4hep::Box>(fv.solid())),
54  m_diamondBoxParams(computeDiamondDimensions(m_isABox, m_isDD4hep, m_params)), // converted from DD4hep unit to mm
55  m_sensorType(computeSensorType(fv.name())),
56  m_geographicalID(computeDetIDFromDD4hep(m_name, fv.copyNos(), fv.copyNum(), isRun2)),
57  m_z(fv.translation().z() / dd4hep::mm) // converted from DD4hep unit to mm
58 {}
59 
61  m_name = ref.m_name;
62  m_copy = ref.m_copy;
63  m_isDD4hep = ref.m_isDD4hep;
64  m_trans = ref.m_trans;
65  m_rot = ref.m_rot;
66  m_params = ref.m_params;
67  m_isABox = ref.m_isABox;
71 
72  if (cm == cmWithChildren)
74 
75  m_z = ref.m_z;
76 }
77 
78 // Constructor from DB object PDetGeomDesc::Item
80  : m_name(item.name_),
81  m_copy(item.copy_),
82  m_isDD4hep(true),
83  m_params(item.params_), // default unit from DD4hep
84  m_sensorType(item.sensorType_),
85  m_geographicalID(item.geographicalID_),
86  m_z(item.z_) // converted from DD4hep to mm
87 {
88  Translation trans(item.dx_, item.dy_, item.dz_);
89  m_trans = trans;
90  RotationMatrix rot(item.axx_, item.axy_, item.axz_, item.ayx_, item.ayy_, item.ayz_, item.azx_, item.azy_, item.azz_);
91  m_rot = rot;
92  // Set the m_isABox flag for the box shaped sensors, so that m_params are properly set
95  m_name.substr(0, 7) == DDD_TOTEM_TIMING_SENSOR_TMPL.substr(0, 7)) &&
96  m_params.size() > 2)
97  m_isABox = true;
98  else
99  m_isABox = false;
101 }
102 
104  for (const auto& i : pd.container_) {
105  DetGeomDesc* gd = new DetGeomDesc(i);
106  this->addComponent(gd);
107  }
108 }
109 
111 
112 void DetGeomDesc::addComponent(DetGeomDesc* det) { m_container.emplace_back(det); }
113 
115  m_rot = t.getRotationMatrix() * m_rot;
117 }
118 
119 void DetGeomDesc::print() const {
120  edm::LogVerbatim("DetGeomDesc::print") << "............................." << std::endl;
121  edm::LogVerbatim("DetGeomDesc::print") << "name = " << m_name << std::endl;
122  edm::LogVerbatim("DetGeomDesc::print") << "copy = " << m_copy << std::endl;
123  edm::LogVerbatim("DetGeomDesc::print") << "translation = " << std::fixed << std::setprecision(7) << m_trans
124  << std::endl;
125  edm::LogVerbatim("DetGeomDesc::print") << "rotation = " << std::fixed << std::setprecision(7) << m_rot << std::endl;
126 
127  if (m_isABox) {
128  edm::LogVerbatim("DetGeomDesc::print")
129  << "getDiamondDimensions() = " << std::fixed << std::setprecision(7) << getDiamondDimensions().xHalfWidth << " "
130  << getDiamondDimensions().yHalfWidth << " " << getDiamondDimensions().zHalfWidth << std::endl;
131  }
132 
133  edm::LogVerbatim("DetGeomDesc::print") << "sensorType = " << m_sensorType << std::endl;
134 
135  if (m_geographicalID() != 0) {
136  edm::LogVerbatim("DetGeomDesc::print") << "geographicalID() = " << m_geographicalID << std::endl;
137  }
138 
139  edm::LogVerbatim("DetGeomDesc::print") << "parentZPosition() = " << std::fixed << std::setprecision(7) << m_z
140  << std::endl;
141 }
142 
143 /*
144  * PRIVATE FUNCTIONS
145  */
146 
148 
150  for (auto& it : m_container) {
151  delete it; // the destructor calls deepDeleteComponents
152  }
153  clearComponents();
154 }
155 
156 std::string DetGeomDesc::computeNameWithNoNamespace(std::string_view nameFromView) const {
157  const auto& semiColonPos = nameFromView.find(':');
158  const std::string name{(semiColonPos != std::string::npos ? nameFromView.substr(semiColonPos + 1) : nameFromView)};
159  return name;
160 }
161 
162 /*
163  * Compute DD4hep shape parameters.
164  */
165 std::vector<double> DetGeomDesc::computeParameters(const cms::DDFilteredView& fv) const {
166  auto myShape = fv.solid();
167  const std::vector<double>& parameters = myShape.dimensions(); // default unit from DD4hep (cm)
168  return parameters;
169 }
170 
171 /*
172  * Compute diamond dimensions.
173  * The diamond sensors are represented by the Box shape parameters.
174  * oldDD: params are already in mm.
175  * DD4hep: convert params from DD4hep unit to mm (mm is legacy expected by PPS reco software).
176  */
178  const bool isDD4hep,
179  const std::vector<double>& params) const {
180  DiamondDimensions boxShapeParameters{};
181  if (isABox) {
182  if (!isDD4hep) {
183  // mm (old DD)
184  boxShapeParameters = {params.at(0), params.at(1), params.at(2)};
185  } else {
186  // convert from DD4hep unit to mm (mm is legacy expected by PPS reco software)
187  boxShapeParameters = {params.at(0) / dd4hep::mm, params.at(1) / dd4hep::mm, params.at(2) / dd4hep::mm};
188  }
189  }
190  return boxShapeParameters;
191 }
192 
193 /*
194  * old DD DetId computation.
195  * Relies on name and volumes copy numbers.
196  */
198  const std::vector<int>& copyNos,
199  const unsigned int copyNum,
200  const bool isRun2) const {
201  DetId geoID;
202 
203  // strip sensors
204  if (name == DDD_TOTEM_RP_SENSOR_NAME) {
205  // check size of copy numbers vector
206  if (copyNos.size() < 3)
207  throw cms::Exception("DDDTotemRPConstruction")
208  << "size of copyNumbers for strip sensor is " << copyNos.size() << ". It must be >= 3.";
209 
210  // extract information
211  const unsigned int decRPId = copyNos[copyNos.size() - 3];
212  const unsigned int arm = decRPId / 100;
213  const unsigned int station = (decRPId % 100) / 10;
214  const unsigned int rp = decRPId % 10;
215  const unsigned int detector = copyNos[copyNos.size() - 1];
216  geoID = TotemRPDetId(arm, station, rp, detector);
217  }
218 
219  // strip and pixels RPs
220  else if (name == DDD_TOTEM_RP_RP_NAME || name == DDD_CTPPS_PIXELS_RP_NAME) {
221  unsigned int decRPId = copyNum;
222 
223  // check if it is a pixel RP
224  if (decRPId >= 10000) {
225  decRPId = decRPId % 10000;
226  const unsigned int armIdx = (decRPId / 100) % 10;
227  const unsigned int stIdx = (decRPId / 10) % 10;
228  const unsigned int rpIdx = decRPId % 10;
229  geoID = CTPPSPixelDetId(armIdx, stIdx, rpIdx);
230  } else {
231  const unsigned int armIdx = (decRPId / 100) % 10;
232  const unsigned int stIdx = (decRPId / 10) % 10;
233  const unsigned int rpIdx = decRPId % 10;
234  geoID = TotemRPDetId(armIdx, stIdx, rpIdx);
235  }
236  }
237 
238  else if (std::regex_match(name, std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL))) {
239  // check size of copy numbers vector
240  if (copyNos.size() < 4)
241  throw cms::Exception("DDDTotemRPConstruction")
242  << "size of copyNumbers for TOTEM timing sensor is " << copyNos.size() << ". It must be >= 4.";
243 
244  const unsigned int decRPId = copyNos[copyNos.size() - 4];
245  const unsigned int arm = decRPId / 100, station = (decRPId % 100) / 10, rp = decRPId % 10;
246  const unsigned int plane = copyNos[copyNos.size() - 2], channel = copyNos[copyNos.size() - 1];
247  geoID = TotemTimingDetId(arm, station, rp, plane, channel);
248  }
249 
250  else if (name == DDD_TOTEM_TIMING_RP_NAME) {
251  const unsigned int arm = copyNum / 100, station = (copyNum % 100) / 10, rp = copyNum % 10;
252  geoID = TotemTimingDetId(arm, station, rp);
253  }
254 
255  // pixel sensors
257  // check size of copy numbers vector
258  if (copyNos.size() < 4)
259  throw cms::Exception("DDDTotemRPConstruction")
260  << "size of copyNumbers for pixel sensor is " << copyNos.size() << ". It must be >= 4.";
261 
262  // extract information
263  const unsigned int decRPId = copyNos[copyNos.size() - 4] % 10000;
264  const unsigned int arm = decRPId / 100;
265  const unsigned int station = (decRPId % 100) / 10;
266  const unsigned int rp = decRPId % 10;
267  const unsigned int detector = copyNos[copyNos.size() - 2] - 1;
268  geoID = CTPPSPixelDetId(arm, station, rp, detector);
269  }
270 
271  // diamond/UFSD sensors
272  else if (name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || name == DDD_CTPPS_UFSD_SEGMENT_NAME) {
273  // check size of copy numbers vector
274  if (copyNos.size() < 2)
275  throw cms::Exception("DDDTotemRPConstruction")
276  << "size of copyNumbers for diamond segments is " << copyNos.size() << ". It must be >= 2.";
277  const unsigned int decRPId = copyNos[1];
278  unsigned int arm, station, rp;
279  if (isRun2) {
280  arm = decRPId - 1;
281  station = 1;
282  rp = 6;
283  } else {
284  arm = (decRPId % 1000) / 100;
285  station = (decRPId % 100) / 10;
286  rp = decRPId % 10;
287  }
288  const unsigned int id = copyNos[copyNos.size() - 1];
289  const unsigned int plane = id / 100;
290  const unsigned int channel = id % 100;
291  geoID = CTPPSDiamondDetId(arm, station, rp, plane, channel);
292  }
293 
294  // diamond/UFSD RPs
295  else if (name == DDD_CTPPS_DIAMONDS_RP_NAME) {
296  // check size of copy numbers vector
297  if (copyNos.size() < 2)
298  throw cms::Exception("DDDTotemRPConstruction")
299  << "size of copyNumbers for diamond RP is " << copyNos.size() << ". It must be >= 2.";
300 
301  const unsigned int decRPId = copyNos[1];
302  unsigned int arm, station, rp;
303  if (isRun2) {
304  arm = decRPId - 1;
305  station = 1;
306  rp = 6;
307  } else {
308  arm = (decRPId % 1000) / 100;
309  station = (decRPId % 100) / 10;
310  rp = decRPId % 10;
311  }
312  geoID = CTPPSDiamondDetId(arm, station, rp);
313  }
314 
315  return geoID;
316 }
317 
318 /*
319  * DD4hep DetId computation.
320  */
322  const std::vector<int>& copyNos,
323  const unsigned int copyNum,
324  const bool isRun2) const {
325  std::vector<int> copyNosOldDD = {copyNos.rbegin() + 1, copyNos.rend()};
326 
327  return computeDetID(name, copyNosOldDD, copyNum, isRun2);
328 }
329 
330 /*
331  * Sensor type computation.
332  * Find out from the namespace (from DB) or the volume name (from XMLs), whether a sensor type is 2x2.
333  */
336 
337  // Case A: Construction from DB.
338  // Namespace is present, and allow identification of 2x2 sensor type: just look for "2x2:RPixWafer" in name.
339  const auto& foundFromDB = name.find(DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2 + ":" + DDD_CTPPS_PIXELS_SENSOR_NAME);
340  if (foundFromDB != std::string::npos) {
342  }
343 
344  // Case B: Construction from XMLs.
345  // Volume name allows identification of 2x2 sensor type: just look whether name is "RPixWafer2x2".
346  const auto& foundFromXML = name.find(DDD_CTPPS_PIXELS_SENSOR_NAME_2x2);
347  if (foundFromXML != std::string::npos) {
349  }
350 
351  return sensorType;
352 }
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
Log< level::Info, true > LogVerbatim
Translation m_trans
Definition: DetGeomDesc.h:140
const std::vector< double > & params() const
Definition: DetGeomDesc.h:88
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:24
const std::string & sensorType() const
Definition: DetGeomDesc.h:99
Container m_container
Definition: DetGeomDesc.h:148
std::string m_name
Definition: DetGeomDesc.h:137
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:90
void applyAlignment(const CTPPSRPAlignmentCorrectionData &)
Definition: DetGeomDesc.cc:114
std::string computeNameWithNoNamespace(std::string_view nameFromView) const
Definition: DetGeomDesc.cc:156
void clearComponents()
Definition: DetGeomDesc.h:120
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >> Translation
Definition: DetGeomDesc.h:55
std::string m_sensorType
Definition: DetGeomDesc.h:145
ROOT::Math::Rotation3D getRotationMatrix() const
const std::string DDD_TOTEM_TIMING_RP_NAME
Definition: CTPPSDDDNames.h:27
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
Definition: CTPPSDDDNames.h:16
const std::string DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2
Definition: CTPPSDDDNames.h:17
void deepDeleteComponents()
Definition: DetGeomDesc.cc:149
float float float z
std::vector< double > m_params
Definition: DetGeomDesc.h:142
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:18
virtual ~DetGeomDesc()
Definition: DetGeomDesc.cc:110
DiamondDimensions m_diamondBoxParams
Definition: DetGeomDesc.h:144
tuple dd4hep
Definition: dd4hep_cff.py:3
DiamondDimensions computeDiamondDimensions(const bool isABox, const bool isDD4hep, const std::vector< double > &params) const
Definition: DetGeomDesc.cc:177
Geometrical description of a sensor.
Definition: DetGeomDesc.h:45
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:20
std::vector< Item > container_
Definition: PDetGeomDesc.h:26
DetId computeDetIDFromDD4hep(const std::string &name, const std::vector< int > &copyNos, const unsigned int copyNum, const bool isRun2) const
Definition: DetGeomDesc.cc:321
std::string computeSensorType(std::string_view name)
Definition: DetGeomDesc.cc:334
const std::string & name() const
Definition: DetGeomDesc.h:73
Definition: DetId.h:17
void deleteComponents()
Definition: DetGeomDesc.cc:147
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:23
DetId computeDetID(const std::string &name, const std::vector< int > &copyNos, const unsigned int copyNum, const bool isRun2) const
Definition: DetGeomDesc.cc:197
bool isABox() const
Definition: DetGeomDesc.h:89
DDSolidShape
Definition: DDSolidShapes.h:6
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:26
bool isDD4hep() const
Definition: DetGeomDesc.h:77
bool m_isDD4hep
Definition: DetGeomDesc.h:139
void print() const
Definition: DetGeomDesc.cc:119
DetId m_geographicalID
Definition: DetGeomDesc.h:146
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:14
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:15
std::vector< double > computeParameters(const cms::DDFilteredView &fv) const
Definition: DetGeomDesc.cc:165
void addComponent(DetGeomDesc *)
Definition: DetGeomDesc.cc:112
DetGeomDesc(const DDFilteredView &fv, const bool isRun2)
Definition: DetGeomDesc.cc:29
RotationMatrix m_rot
Definition: DetGeomDesc.h:141
ROOT::Math::Rotation3D RotationMatrix
Definition: DetGeomDesc.h:54
dd4hep::Solid solid() const
Alignment correction for an element of the CT-PPS detector. Within the geometry description, every sensor (more generally every element) is given its translation and rotation. These two quantities shall be understood in local-to-global coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global, then it holds.
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:19
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...