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 
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())),
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(geant_units::operators::convertCmToMm(fv.translation())), // converted from cm (DD4hep) to mm
51  m_rot(fv.rotation()),
52  m_params(computeParameters(fv)), // default unit from DD4hep (cm)
53  m_isABox(dd4hep::isA<dd4hep::Box>(fv.solid())),
54  m_diamondBoxParams(computeDiamondDimensions(m_isABox, m_isDD4hep, m_params)), // converted from cm (DD4hep) to mm
55  m_sensorType(computeSensorType(fv.name())),
56  m_geographicalID(computeDetIDFromDD4hep(m_name, fv.copyNos(), fv.copyNum())),
57  m_z(geant_units::operators::convertCmToMm(fv.translation().z())) // converted from cm (DD4hep) 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 cm (DD4hep) to mm (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 (legacy)
152  boxShapeParameters = {params.at(0), params.at(1), params.at(2)};
153  } else {
154  // convert cm (DD4hep) to mm (legacy expected by PPS reco software)
155  boxShapeParameters = {geant_units::operators::convertCmToMm(params.at(0)),
158  }
159  }
160  return boxShapeParameters;
161 }
162 
163 /*
164  * old DD DetId computation.
165  * Relies on name and volumes copy numbers.
166  */
167 DetId DetGeomDesc::computeDetID(const std::string& name, const std::vector<int>& copyNos, unsigned int copyNum) const {
168  DetId geoID;
169 
170  // strip sensors
172  // check size of copy numbers array
173  if (copyNos.size() < 3)
174  throw cms::Exception("DDDTotemRPContruction")
175  << "size of copyNumbers for strip sensor is " << copyNos.size() << ". It must be >= 3.";
176 
177  // extract information
178  const unsigned int decRPId = copyNos[copyNos.size() - 3];
179  const unsigned int arm = decRPId / 100;
180  const unsigned int station = (decRPId % 100) / 10;
181  const unsigned int rp = decRPId % 10;
182  const unsigned int detector = copyNos[copyNos.size() - 1];
183  geoID = TotemRPDetId(arm, station, rp, detector);
184  }
185 
186  // strip and pixels RPs
188  unsigned int decRPId = copyNum;
189 
190  // check if it is a pixel RP
191  if (decRPId >= 10000) {
192  decRPId = decRPId % 10000;
193  const unsigned int armIdx = (decRPId / 100) % 10;
194  const unsigned int stIdx = (decRPId / 10) % 10;
195  const unsigned int rpIdx = decRPId % 10;
196  geoID = CTPPSPixelDetId(armIdx, stIdx, rpIdx);
197  } else {
198  const unsigned int armIdx = (decRPId / 100) % 10;
199  const unsigned int stIdx = (decRPId / 10) % 10;
200  const unsigned int rpIdx = decRPId % 10;
201  geoID = TotemRPDetId(armIdx, stIdx, rpIdx);
202  }
203  }
204 
205  else if (std::regex_match(name, std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL))) {
206  // check size of copy numbers array
207  if (copyNos.size() < 4)
208  throw cms::Exception("DDDTotemRPContruction")
209  << "size of copyNumbers for TOTEM timing sensor is " << copyNos.size() << ". It must be >= 4.";
210 
211  const unsigned int decRPId = copyNos[copyNos.size() - 4];
212  const unsigned int arm = decRPId / 100, station = (decRPId % 100) / 10, rp = decRPId % 10;
213  const unsigned int plane = copyNos[copyNos.size() - 2], channel = copyNos[copyNos.size() - 1];
214  geoID = TotemTimingDetId(arm, station, rp, plane, channel);
215  }
216 
217  else if (name == DDD_TOTEM_TIMING_RP_NAME) {
218  const unsigned int arm = copyNum / 100, station = (copyNum % 100) / 10, rp = copyNum % 10;
219  geoID = TotemTimingDetId(arm, station, rp);
220  }
221 
222  // pixel sensors
224  // check size of copy numbers array
225  if (copyNos.size() < 4)
226  throw cms::Exception("DDDTotemRPContruction")
227  << "size of copyNumbers for pixel sensor is " << copyNos.size() << ". It must be >= 4.";
228 
229  // extract information
230  const unsigned int decRPId = copyNos[copyNos.size() - 4] % 10000;
231  const unsigned int arm = decRPId / 100;
232  const unsigned int station = (decRPId % 100) / 10;
233  const unsigned int rp = decRPId % 10;
234  const unsigned int detector = copyNos[copyNos.size() - 2] - 1;
235  geoID = CTPPSPixelDetId(arm, station, rp, detector);
236  }
237 
238  // diamond/UFSD sensors
240  const unsigned int id = copyNos[copyNos.size() - 1];
241  const unsigned int arm = copyNos[1] - 1;
242  const unsigned int station = 1;
243  const unsigned int rp = 6;
244  const unsigned int plane = (id / 100);
245  const unsigned int channel = id % 100;
246 
247  geoID = CTPPSDiamondDetId(arm, station, rp, plane, channel);
248  }
249 
250  // diamond/UFSD RPs
251  else if (name == DDD_CTPPS_DIAMONDS_RP_NAME) {
252  // check size of copy numbers array
253  if (copyNos.size() < 2)
254  throw cms::Exception("DDDTotemRPContruction")
255  << "size of copyNumbers for diamond RP is " << copyNos.size() << ". It must be >= 2.";
256 
257  const unsigned int arm = copyNos[1] - 1;
258  const unsigned int station = 1;
259  const unsigned int rp = 6;
260 
261  geoID = CTPPSDiamondDetId(arm, station, rp);
262  }
263 
264  return geoID;
265 }
266 
267 /*
268  * DD4hep DetId computation.
269  */
271  const std::vector<int>& copyNos,
272  unsigned int copyNum) const {
273  std::vector<int> copyNosOldDD = {copyNos.rbegin() + 1, copyNos.rend()};
274 
275  return computeDetID(name, copyNosOldDD, copyNum);
276 }
277 
278 /*
279  * Sensor type computation.
280  * Find out from the namespace (from DB) or the volume name (from XMLs), whether a sensor type is 2x2.
281  */
284 
285  // Case A: Construction from DB.
286  // Namespace is present, and allow identification of 2x2 sensor type: just look for "2x2:RPixWafer" in name.
287  const auto& foundFromDB = name.find(DDD_CTPPS_PIXELS_SENSOR_TYPE_2x2 + ":" + DDD_CTPPS_PIXELS_SENSOR_NAME);
288  if (foundFromDB != std::string::npos) {
290  }
291 
292  // Case B: Construction from XMLs.
293  // Volume name allows identification of 2x2 sensor type: just look whether name is "RPixWafer2x2".
294  const auto& foundFromXML = name.find(DDD_CTPPS_PIXELS_SENSOR_NAME_2x2);
295  if (foundFromXML != std::string::npos) {
297  }
298 
299  return sensorType;
300 }
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:29
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:127
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
DetGeomDesc::computeDetID
DetId computeDetID(const std::string &name, const std::vector< int > &copyNos, unsigned int copyNum) const
Definition: DetGeomDesc.cc:166
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:122
DetGeomDesc::m_sensorType
std::string m_sensorType
Definition: DetGeomDesc.h:129
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:132
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:121
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:91
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:126
DetGeomDesc::clearComponents
void clearComponents()
Definition: DetGeomDesc.h:110
DetGeomDesc::m_z
float m_z
Definition: DetGeomDesc.h:133
DetGeomDesc::CopyMode
CopyMode
Definition: DetGeomDesc.h:62
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:861
DetId
Definition: DetId.h:17
TotemTimingDetId.h
DetGeomDesc::getDiamondDimensions
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:82
DetGeomDesc::computeDetIDFromDD4hep
DetId computeDetIDFromDD4hep(const std::string &name, const std::vector< int > &copyNos, unsigned int copyNum) const
Definition: DetGeomDesc.cc:269
DDSolidShapes.h
DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
Definition: CTPPSDDDNames.h:15
DDSolid.h
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:70
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:128
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
geant_units::operators::convertCmToMm
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
DetGeomDesc.h
DDD_CTPPS_DIAMONDS_RP_NAME
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:25
GeantUnits.h
DetGeomDesc::isABox
bool isABox() const
Definition: DetGeomDesc.h:81
DetGeomDesc::name
const std::string & name() const
Definition: DetGeomDesc.h:66
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:123
DetGeomDesc::deleteComponents
void deleteComponents()
Definition: DetGeomDesc.cc:114
DDSolidShape::ddbox
DetGeomDesc::DetGeomDesc
DetGeomDesc(const DDFilteredView &fv)
Definition: DetGeomDesc.cc:28
DetGeomDesc::computeSensorType
std::string computeSensorType(std::string_view name)
Definition: DetGeomDesc.cc:281
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
TotemRPDetId.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DetGeomDesc::params
const std::vector< double > & params() const
Definition: DetGeomDesc.h:80
DetGeomDesc::computeParameters
std::vector< double > computeParameters(const cms::DDFilteredView &fv) const
Definition: DetGeomDesc.cc:132
DetGeomDesc::cmWithChildren
Definition: DetGeomDesc.h:62
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
DDFilteredView
Definition: DDFilteredView.h:20
DetGeomDesc::m_geographicalID
DetId m_geographicalID
Definition: DetGeomDesc.h:130
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
geant_units
Definition: GeantUnits.h:11
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::m_trans
Translation m_trans
Definition: DetGeomDesc.h:124
DetGeomDesc::m_rot
RotationMatrix m_rot
Definition: DetGeomDesc.h:125