CMS 3D CMS Logo

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  */
29 DetGeomDesc::DetGeomDesc(const DDFilteredView& fv, const bool isRun2)
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 
79 
80 void DetGeomDesc::addComponent(DetGeomDesc* det) { m_container.emplace_back(det); }
81 
83  m_rot = t.getRotationMatrix() * m_rot;
84  m_trans = t.getTranslation() + m_trans;
85 }
86 
87 void DetGeomDesc::print() const {
88  edm::LogVerbatim("DetGeomDesc::print") << "............................." << std::endl;
89  edm::LogVerbatim("DetGeomDesc::print") << "name = " << m_name << std::endl;
90  edm::LogVerbatim("DetGeomDesc::print") << "copy = " << m_copy << std::endl;
91  edm::LogVerbatim("DetGeomDesc::print") << "translation = " << std::fixed << std::setprecision(7) << m_trans
92  << std::endl;
93  edm::LogVerbatim("DetGeomDesc::print") << "rotation = " << std::fixed << std::setprecision(7) << m_rot << std::endl;
94 
95  if (m_isABox) {
96  edm::LogVerbatim("DetGeomDesc::print")
97  << "getDiamondDimensions() = " << std::fixed << std::setprecision(7) << getDiamondDimensions().xHalfWidth << " "
98  << getDiamondDimensions().yHalfWidth << " " << getDiamondDimensions().zHalfWidth << std::endl;
99  }
100 
101  edm::LogVerbatim("DetGeomDesc::print") << "sensorType = " << m_sensorType << std::endl;
102 
103  if (m_geographicalID() != 0) {
104  edm::LogVerbatim("DetGeomDesc::print") << "geographicalID() = " << m_geographicalID << std::endl;
105  }
106 
107  edm::LogVerbatim("DetGeomDesc::print") << "parentZPosition() = " << std::fixed << std::setprecision(7) << m_z
108  << std::endl;
109 }
110 
111 /*
112  * PRIVATE FUNCTIONS
113  */
114 
115 void DetGeomDesc::deleteComponents() { m_container.erase(m_container.begin(), m_container.end()); }
116 
118  for (auto& it : m_container) {
119  delete it; // the destructor calls deepDeleteComponents
120  }
121  clearComponents();
122 }
123 
124 std::string DetGeomDesc::computeNameWithNoNamespace(std::string_view nameFromView) const {
125  const auto& semiColonPos = nameFromView.find(":");
126  const std::string name{(semiColonPos != std::string::npos ? nameFromView.substr(semiColonPos + 1) : nameFromView)};
127  return name;
128 }
129 
130 /*
131  * Compute DD4hep shape parameters.
132  */
133 std::vector<double> DetGeomDesc::computeParameters(const cms::DDFilteredView& fv) const {
134  auto myShape = fv.solid();
135  const std::vector<double>& parameters = myShape.dimensions(); // default unit from DD4hep (cm)
136  return parameters;
137 }
138 
139 /*
140  * Compute diamond dimensions.
141  * The diamond sensors are represented by the Box shape parameters.
142  * oldDD: params are already in mm.
143  * DD4hep: convert params from DD4hep unit to mm (mm is legacy expected by PPS reco software).
144  */
146  const bool isDD4hep,
147  const std::vector<double>& params) const {
148  DiamondDimensions boxShapeParameters{};
149  if (isABox) {
150  if (!isDD4hep) {
151  // mm (old DD)
152  boxShapeParameters = {params.at(0), params.at(1), params.at(2)};
153  } else {
154  // convert from DD4hep unit to mm (mm is legacy expected by PPS reco software)
155  boxShapeParameters = {params.at(0) / dd4hep::mm, params.at(1) / dd4hep::mm, params.at(2) / dd4hep::mm};
156  }
157  }
158  return boxShapeParameters;
159 }
160 
161 /*
162  * old DD DetId computation.
163  * Relies on name and volumes copy numbers.
164  */
166  const std::vector<int>& copyNos,
167  const unsigned int copyNum,
168  const bool isRun2) const {
169  DetId geoID;
170 
171  // strip sensors
173  // check size of copy numbers vector
174  if (copyNos.size() < 3)
175  throw cms::Exception("DDDTotemRPConstruction")
176  << "size of copyNumbers for strip sensor is " << copyNos.size() << ". It must be >= 3.";
177 
178  // extract information
179  const unsigned int decRPId = copyNos[copyNos.size() - 3];
180  const unsigned int arm = decRPId / 100;
181  const unsigned int station = (decRPId % 100) / 10;
182  const unsigned int rp = decRPId % 10;
183  const unsigned int detector = copyNos[copyNos.size() - 1];
184  geoID = TotemRPDetId(arm, station, rp, detector);
185  }
186 
187  // strip and pixels RPs
189  unsigned int decRPId = copyNum;
190 
191  // check if it is a pixel RP
192  if (decRPId >= 10000) {
193  decRPId = decRPId % 10000;
194  const unsigned int armIdx = (decRPId / 100) % 10;
195  const unsigned int stIdx = (decRPId / 10) % 10;
196  const unsigned int rpIdx = decRPId % 10;
197  geoID = CTPPSPixelDetId(armIdx, stIdx, rpIdx);
198  } else {
199  const unsigned int armIdx = (decRPId / 100) % 10;
200  const unsigned int stIdx = (decRPId / 10) % 10;
201  const unsigned int rpIdx = decRPId % 10;
202  geoID = TotemRPDetId(armIdx, stIdx, rpIdx);
203  }
204  }
205 
206  else if (std::regex_match(name, std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL))) {
207  // check size of copy numbers vector
208  if (copyNos.size() < 4)
209  throw cms::Exception("DDDTotemRPConstruction")
210  << "size of copyNumbers for TOTEM timing sensor is " << copyNos.size() << ". It must be >= 4.";
211 
212  const unsigned int decRPId = copyNos[copyNos.size() - 4];
213  const unsigned int arm = decRPId / 100, station = (decRPId % 100) / 10, rp = decRPId % 10;
214  const unsigned int plane = copyNos[copyNos.size() - 2], channel = copyNos[copyNos.size() - 1];
215  geoID = TotemTimingDetId(arm, station, rp, plane, channel);
216  }
217 
218  else if (name == DDD_TOTEM_TIMING_RP_NAME) {
219  const unsigned int arm = copyNum / 100, station = (copyNum % 100) / 10, rp = copyNum % 10;
220  geoID = TotemTimingDetId(arm, station, rp);
221  }
222 
223  // pixel sensors
225  // check size of copy numbers vector
226  if (copyNos.size() < 4)
227  throw cms::Exception("DDDTotemRPConstruction")
228  << "size of copyNumbers for pixel sensor is " << copyNos.size() << ". It must be >= 4.";
229 
230  // extract information
231  const unsigned int decRPId = copyNos[copyNos.size() - 4] % 10000;
232  const unsigned int arm = decRPId / 100;
233  const unsigned int station = (decRPId % 100) / 10;
234  const unsigned int rp = decRPId % 10;
235  const unsigned int detector = copyNos[copyNos.size() - 2] - 1;
236  geoID = CTPPSPixelDetId(arm, station, rp, detector);
237  }
238 
239  // diamond/UFSD sensors
241  // check size of copy numbers vector
242  if (copyNos.size() < 2)
243  throw cms::Exception("DDDTotemRPConstruction")
244  << "size of copyNumbers for diamond segments is " << copyNos.size() << ". It must be >= 2.";
245  const unsigned int decRPId = copyNos[1];
246  unsigned int arm, station, rp;
247  if (isRun2) {
248  arm = decRPId - 1;
249  station = 1;
250  rp = 6;
251  } else {
252  arm = (decRPId % 1000) / 100;
253  station = (decRPId % 100) / 10;
254  rp = decRPId % 10;
255  }
256  const unsigned int id = copyNos[copyNos.size() - 1];
257  const unsigned int plane = id / 100;
258  const unsigned int channel = id % 100;
259  geoID = CTPPSDiamondDetId(arm, station, rp, plane, channel);
260  }
261 
262  // diamond/UFSD RPs
263  else if (name == DDD_CTPPS_DIAMONDS_RP_NAME) {
264  // check size of copy numbers vector
265  if (copyNos.size() < 2)
266  throw cms::Exception("DDDTotemRPConstruction")
267  << "size of copyNumbers for diamond RP is " << copyNos.size() << ". It must be >= 2.";
268 
269  const unsigned int decRPId = copyNos[1];
270  unsigned int arm, station, rp;
271  if (isRun2) {
272  arm = decRPId - 1;
273  station = 1;
274  rp = 6;
275  } else {
276  arm = (decRPId % 1000) / 100;
277  station = (decRPId % 100) / 10;
278  rp = decRPId % 10;
279  }
280  geoID = CTPPSDiamondDetId(arm, station, rp);
281  }
282 
283  return geoID;
284 }
285 
286 /*
287  * DD4hep DetId computation.
288  */
290  const std::vector<int>& copyNos,
291  const unsigned int copyNum,
292  const bool isRun2) const {
293  std::vector<int> copyNosOldDD = {copyNos.rbegin() + 1, copyNos.rend()};
294 
295  return computeDetID(name, copyNosOldDD, copyNum, isRun2);
296 }
297 
298 /*
299  * Sensor type computation.
300  * Find out from the namespace (from DB) or the volume name (from XMLs), whether a sensor type is 2x2.
301  */
304 
305  // Case A: Construction from DB.
306  // Namespace is present, and allow identification of 2x2 sensor type: just look for "2x2:RPixWafer" in name.
307  const auto& foundFromDB = name.find(DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2 + ":" + DDD_CTPPS_PIXELS_SENSOR_NAME);
308  if (foundFromDB != std::string::npos) {
310  }
311 
312  // Case B: Construction from XMLs.
313  // Volume name allows identification of 2x2 sensor type: just look whether name is "RPixWafer2x2".
314  const auto& foundFromXML = name.find(DDD_CTPPS_PIXELS_SENSOR_NAME_2x2);
315  if (foundFromXML != std::string::npos) {
317  }
318 
319  return sensorType;
320 }
DiamondDimensions
Geometrical description of a sensor.
Definition: DetGeomDesc.h:43
DiamondDimensions::zHalfWidth
double zHalfWidth
Definition: DetGeomDesc.h:46
DetGeomDesc::applyAlignment
void applyAlignment(const CTPPSRPAlignmentCorrectionData &)
Definition: DetGeomDesc.cc:81
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
DDD_CTPPS_UFSD_SEGMENT_NAME
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:18
DDSolidShape
DDSolidShape
Definition: DDSolidShapes.h:6
MessageLogger.h
DDD_CTPPS_PIXELS_SENSOR_NAME
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:14
funct::false
false
Definition: Factorize.h:29
DetGeomDesc::addComponent
void addComponent(DetGeomDesc *)
Definition: DetGeomDesc.cc:79
DetGeomDesc::m_isABox
bool m_isABox
Definition: DetGeomDesc.h:138
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
relativeConstraints.station
station
Definition: relativeConstraints.py:67
CTPPSPixelDetId.h
DetGeomDesc::deepDeleteComponents
void deepDeleteComponents()
Definition: DetGeomDesc.cc:116
DetGeomDesc::m_copy
int m_copy
Definition: DetGeomDesc.h:133
DetGeomDesc::m_sensorType
std::string m_sensorType
Definition: DetGeomDesc.h:140
DetGeomDesc::computeDiamondDimensions
DiamondDimensions computeDiamondDimensions(const bool isABox, const bool isDD4hep, const std::vector< double > &params) const
Definition: DetGeomDesc.cc:144
DetGeomDesc::m_container
Container m_container
Definition: DetGeomDesc.h:143
DDD_CTPPS_PIXELS_RP_NAME
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:23
DetGeomDesc::~DetGeomDesc
virtual ~DetGeomDesc()
Definition: DetGeomDesc.cc:77
DetGeomDesc::m_name
std::string m_name
Definition: DetGeomDesc.h:132
DDD_TOTEM_TIMING_RP_NAME
const std::string DDD_TOTEM_TIMING_RP_NAME
Definition: CTPPSDDDNames.h:26
DetGeomDesc::sensorType
const std::string & sensorType() const
Definition: DetGeomDesc.h:94
cms::DDFilteredView
Definition: DDFilteredView.h:70
DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2
const std::string DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2
Definition: CTPPSDDDNames.h:16
DetGeomDesc::m_params
std::vector< double > m_params
Definition: DetGeomDesc.h:137
DetGeomDesc::clearComponents
void clearComponents()
Definition: DetGeomDesc.h:115
DetGeomDesc::m_z
float m_z
Definition: DetGeomDesc.h:144
DetGeomDesc::CopyMode
CopyMode
Definition: DetGeomDesc.h:64
DDD_CTPPS_DIAMONDS_SEGMENT_NAME
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:17
cms::DDFilteredView::solid
dd4hep::Solid solid() const
Definition: DDFilteredView.cc:862
DetId
Definition: DetId.h:17
DetGeomDesc::computeDetID
DetId computeDetID(const std::string &name, const std::vector< int > &copyNos, const unsigned int copyNum, const bool isRun2) const
Definition: DetGeomDesc.cc:164
TotemTimingDetId.h
DetGeomDesc::getDiamondDimensions
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:85
DDSolidShapes.h
DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
Definition: CTPPSDDDNames.h:15
DDSolid.h
geometryPPS_CMSxz_fromDD_2016_cfi.isRun2
isRun2
Definition: geometryPPS_CMSxz_fromDD_2016_cfi.py:14
DiamondDimensions::xHalfWidth
double xHalfWidth
Definition: DetGeomDesc.h:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSRPAlignmentCorrectionData.h
DetGeomDesc::isDD4hep
bool isDD4hep() const
Definition: DetGeomDesc.h:72
TotemTimingDetId
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...
Definition: TotemTimingDetId.h:26
funct::true
true
Definition: Factorize.h:173
CTPPSDiamondDetId.h
DetGeomDesc::m_diamondBoxParams
DiamondDimensions m_diamondBoxParams
Definition: DetGeomDesc.h:139
CTPPSDiamondDetId
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
Definition: CTPPSDiamondDetId.h:24
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
DetGeomDesc.h
DDD_CTPPS_DIAMONDS_RP_NAME
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:25
DetGeomDesc::isABox
bool isABox() const
Definition: DetGeomDesc.h:84
DetGeomDesc::name
const std::string & name() const
Definition: DetGeomDesc.h:68
DDD_TOTEM_TIMING_SENSOR_TMPL
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:19
DetGeomDesc
Definition: DetGeomDesc.h:49
DiamondDimensions::yHalfWidth
double yHalfWidth
Definition: DetGeomDesc.h:45
DDD_TOTEM_RP_RP_NAME
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:22
CTPPSDDDNames.h
CTPPSPixelDetId
Definition: CTPPSPixelDetId.h:16
DetGeomDesc::print
void print() const
Definition: DetGeomDesc.cc:86
DetGeomDesc::m_isDD4hep
bool m_isDD4hep
Definition: DetGeomDesc.h:134
protons_cff.arm
arm
Definition: protons_cff.py:43
DetGeomDesc::deleteComponents
void deleteComponents()
Definition: DetGeomDesc.cc:114
DDSolidShape::ddbox
DetGeomDesc::computeSensorType
std::string computeSensorType(std::string_view name)
Definition: DetGeomDesc.cc:301
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dd4hep
Definition: DDPlugins.h:8
DDD_TOTEM_RP_SENSOR_NAME
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:13
protons_cff.decRPId
decRPId
Definition: protons_cff.py:60
TotemRPDetId.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DetGeomDesc::params
const std::vector< double > & params() const
Definition: DetGeomDesc.h:83
DetGeomDesc::computeParameters
std::vector< double > computeParameters(const cms::DDFilteredView &fv) const
Definition: DetGeomDesc.cc:132
DetGeomDesc::cmWithChildren
Definition: DetGeomDesc.h:64
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
DDFilteredView
Definition: DDFilteredView.h:20
DetGeomDesc::m_geographicalID
DetId m_geographicalID
Definition: DetGeomDesc.h:141
CTPPSRPAlignmentCorrectionData
Alignment correction for an element of the CT-PPS detector. Within the geometry description,...
Definition: CTPPSRPAlignmentCorrectionData.h:58
cms::Exception
Definition: Exception.h:70
DetGeomDesc::DetGeomDesc
DetGeomDesc(const DDFilteredView &fv, const bool isRun2)
Definition: DetGeomDesc.cc:28
DetGeomDesc::computeNameWithNoNamespace
std::string computeNameWithNoNamespace(std::string_view nameFromView) const
Definition: DetGeomDesc.cc:123
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
TotemRPDetId
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:29
DetGeomDesc::computeDetIDFromDD4hep
DetId computeDetIDFromDD4hep(const std::string &name, const std::vector< int > &copyNos, const unsigned int copyNum, const bool isRun2) const
Definition: DetGeomDesc.cc:288
DetGeomDesc::m_trans
Translation m_trans
Definition: DetGeomDesc.h:135
DetGeomDesc::m_rot
RotationMatrix m_rot
Definition: DetGeomDesc.h:136