CMS 3D CMS Logo

CTPPSGeometry.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kaspar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
11 #include <regex>
12 
13 //----------------------------------------------------------------------------------------------------
14 
15 void CTPPSGeometry::build(const DetGeomDesc* gD, unsigned int verbosity) {
16  // reset
17  sensors_map_.clear();
18  rps_map_.clear();
19  stations_in_arm_.clear();
20  rps_in_station_.clear();
21  dets_in_rp_.clear();
22 
23  // propagate through the GeometricalDet structure and add all detectors to 'sensors_map_'
24  std::deque<const DetGeomDesc*> buffer;
25  buffer.emplace_back(gD);
26  while (!buffer.empty()) {
27  const DetGeomDesc* d = buffer.front();
28  buffer.pop_front();
29 
30  // verbosity printout
31  if (verbosity == 2) {
32  d->print();
33  }
34 
35  // check if it is a sensor
36  if (d->name() == DDD_TOTEM_RP_SENSOR_NAME ||
37  std::regex_match(d->name(), std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL)) ||
40  addSensor(d->geographicalID(), d);
41 
42  // check if it is a RP
43  if (d->name() == DDD_TOTEM_RP_RP_NAME || d->name() == DDD_TOTEM_TIMING_RP_NAME ||
44  d->name() == DDD_CTPPS_DIAMONDS_RP_NAME || d->name() == DDD_CTPPS_PIXELS_RP_NAME)
45  addRP(d->geographicalID(), d);
46 
47  for (const auto& comp : d->components())
48  buffer.emplace_back(comp);
49  }
50 
51  // verbosity printout
52  if (verbosity) {
53  edm::LogVerbatim("CTPPSGeometry::build")
54  << "sensors_map_.size() = " << sensors_map_.size() << ", rps_map_.size() = " << rps_map_.size() << std::endl;
55  }
56 
57  // build sets
58  for (const auto& it : sensors_map_) {
59  const CTPPSDetId detId(it.first);
60  const CTPPSDetId rpId = detId.rpId();
61  const CTPPSDetId stId = detId.stationId();
62  const CTPPSDetId armId = detId.armId();
63 
64  stations_in_arm_[armId].insert(armId);
65  rps_in_station_[stId].insert(rpId);
66  dets_in_rp_[rpId].insert(detId);
67  }
68 }
69 
70 //----------------------------------------------------------------------------------------------------
71 
72 bool CTPPSGeometry::addSensor(unsigned int id, const DetGeomDesc*& gD) {
73  if (sensors_map_.find(id) != sensors_map_.end())
74  return false;
75 
76  sensors_map_[id] = gD;
77  return true;
78 }
79 
80 //----------------------------------------------------------------------------------------------------
81 
82 bool CTPPSGeometry::addRP(unsigned int id, const DetGeomDesc*& gD) {
83  if (rps_map_.find(id) != rps_map_.end())
84  return false;
85 
86  rps_map_[id] = gD;
87  return true;
88 }
89 
90 //----------------------------------------------------------------------------------------------------
91 
92 const DetGeomDesc* CTPPSGeometry::sensor(unsigned int id) const {
93  auto g = sensorNoThrow(id);
94  if (nullptr == g) {
95  throw cms::Exception("CTPPSGeometry") << "Not found detector with ID " << id << ", i.e. " << CTPPSDetId(id);
96  }
97  return g;
98 }
99 
100 //----------------------------------------------------------------------------------------------------
101 
102 const DetGeomDesc* CTPPSGeometry::sensorNoThrow(unsigned int id) const noexcept {
103  auto it = sensors_map_.find(id);
104  if (it == sensors_map_.end()) {
105  return nullptr;
106  }
107  return it->second;
108 }
109 
110 //----------------------------------------------------------------------------------------------------
111 
112 const DetGeomDesc* CTPPSGeometry::rp(unsigned int id) const {
113  auto rp = rpNoThrow(id);
114  if (nullptr == rp) {
115  throw cms::Exception("CTPPSGeometry") << "Not found RP device with ID " << id << ", i.e. " << CTPPSDetId(id);
116  }
117  return rp;
118 }
119 
120 //----------------------------------------------------------------------------------------------------
121 
122 const DetGeomDesc* CTPPSGeometry::rpNoThrow(unsigned int id) const noexcept {
123  auto it = rps_map_.find(id);
124  if (it == rps_map_.end()) {
125  return nullptr;
126  }
127 
128  return it->second;
129 }
130 
131 //----------------------------------------------------------------------------------------------------
132 const std::set<unsigned int>& CTPPSGeometry::stationsInArm(unsigned int id) const {
133  auto it = stations_in_arm_.find(id);
134  if (it == stations_in_arm_.end())
135  throw cms::Exception("CTPPSGeometry") << "Arm with ID " << id << " not found.";
136  return it->second;
137 }
138 
139 //----------------------------------------------------------------------------------------------------
140 
141 const std::set<unsigned int>& CTPPSGeometry::rpsInStation(unsigned int id) const {
142  auto it = rps_in_station_.find(id);
143  if (it == rps_in_station_.end())
144  throw cms::Exception("CTPPSGeometry") << "Station with ID " << id << " not found.";
145  return it->second;
146 }
147 
148 //----------------------------------------------------------------------------------------------------
149 
150 const std::set<unsigned int>& CTPPSGeometry::sensorsInRP(unsigned int id) const {
151  auto it = dets_in_rp_.find(id);
152  if (it == dets_in_rp_.end())
153  throw cms::Exception("CTPPSGeometry") << "RP with ID " << id << " not found.";
154  return it->second;
155 }
156 
157 //----------------------------------------------------------------------------------------------------
158 
160  return gd->rotation() * r + gd->translation();
161 }
162 
163 //----------------------------------------------------------------------------------------------------
164 
166  return localToGlobal(sensor(id), r);
167 }
168 
169 //----------------------------------------------------------------------------------------------------
170 
172  return gd->rotation().Inverse() * (r - gd->translation());
173 }
174 
175 //----------------------------------------------------------------------------------------------------
176 
178  return globalToLocal(sensor(id), r);
179 }
180 
181 //----------------------------------------------------------------------------------------------------
182 
184  return sensor(id)->rotation() * dir;
185 }
186 
187 //----------------------------------------------------------------------------------------------------
188 
190  return sensor(id)->rotation().Inverse() * dir;
191 }
192 
193 //----------------------------------------------------------------------------------------------------
194 
196  auto gd = sensor(id);
197  return gd->translation();
198 }
199 
200 //----------------------------------------------------------------------------------------------------
201 
203  auto gd = rp(id);
204  return gd->translation();
205 }
HIPAlignmentAlgorithm_cfi.verbosity
verbosity
Definition: HIPAlignmentAlgorithm_cfi.py:7
CTPPSGeometry::globalToLocal
Vector globalToLocal(const DetGeomDesc *, const Vector &) const
Definition: CTPPSGeometry.cc:170
CTPPSGeometry::rpTranslation
Vector rpTranslation(unsigned int id) const
Definition: CTPPSGeometry.cc:201
CTPPSGeometry::globalToLocalDirection
Vector globalToLocalDirection(unsigned int id, const Vector &) const
Definition: CTPPSGeometry.cc:188
DDD_CTPPS_UFSD_SEGMENT_NAME
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:18
MessageLogger.h
DDD_CTPPS_PIXELS_SENSOR_NAME
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:14
DetGeomDesc::translation
const Translation & translation() const
Definition: DetGeomDesc.h:75
CTPPSGeometry::stationsInArm
const std::set< unsigned int > & stationsInArm(unsigned int) const
after checks returns set of station ids corresponding to the given arm id
Definition: CTPPSGeometry.cc:131
DDD_CTPPS_PIXELS_RP_NAME
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:23
DDD_TOTEM_TIMING_RP_NAME
const std::string DDD_TOTEM_TIMING_RP_NAME
Definition: CTPPSDDDNames.h:26
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
DDD_CTPPS_DIAMONDS_SEGMENT_NAME
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:17
CTPPSDetId::armId
CTPPSDetId armId() const
Definition: CTPPSDetId.h:78
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
CTPPSGeometry.h
CTPPSGeometry::stations_in_arm_
mapSetType stations_in_arm_
map: parent ID -> set of subelements E.g. stations_in_arm_ is map of arm ID -> set of stations (in th...
Definition: CTPPSGeometry.h:122
CTPPSGeometry::sensors_map_
mapType sensors_map_
map: sensor id --> DetGeomDesc
Definition: CTPPSGeometry.h:115
DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
Definition: CTPPSDDDNames.h:15
CTPPSGeometry::localToGlobalDirection
Vector localToGlobalDirection(unsigned int id, const Vector &) const
Definition: CTPPSGeometry.cc:182
CTPPSGeometry::sensorTranslation
Vector sensorTranslation(unsigned int id) const
Definition: CTPPSGeometry.cc:194
CTPPSGeometry::sensorNoThrow
const DetGeomDesc * sensorNoThrow(unsigned int id) const noexcept
Definition: CTPPSGeometry.cc:101
CTPPSGeometry::dets_in_rp_
mapSetType dets_in_rp_
Definition: CTPPSGeometry.h:122
DDD_CTPPS_DIAMONDS_RP_NAME
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:25
CTPPSGeometry::rps_map_
RPDeviceMapType rps_map_
map: rp id --> DetGeomDesc
Definition: CTPPSGeometry.h:118
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
DDD_TOTEM_TIMING_SENSOR_TMPL
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:19
DetGeomDesc
Definition: DetGeomDesc.h:49
CTPPSGeometry::rpNoThrow
const DetGeomDesc * rpNoThrow(unsigned int id) const noexcept
Definition: CTPPSGeometry.cc:121
DDD_TOTEM_RP_RP_NAME
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:22
CTPPSGeometry::rpsInStation
const std::set< unsigned int > & rpsInStation(unsigned int) const
after checks returns set of RP ids corresponding to the given station id
Definition: CTPPSGeometry.cc:140
alignCSCRings.r
r
Definition: alignCSCRings.py:93
CTPPSGeometry::addRP
bool addRP(unsigned int id, const DetGeomDesc *&)
adds a RP box to a map
Definition: CTPPSGeometry.cc:81
CTPPSGeometry::addSensor
bool addSensor(unsigned int, const DetGeomDesc *&)
adds an item to the map (detector ID --> DetGeomDesc) performs necessary checks
Definition: CTPPSGeometry.cc:71
CTPPSDetId::stationId
CTPPSDetId stationId() const
Definition: CTPPSDetId.h:80
profile_2016_postTS2_cff.rpId
rpId
Definition: profile_2016_postTS2_cff.py:21
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
CTPPSGeometry::sensorsInRP
const std::set< unsigned int > & sensorsInRP(unsigned int) const
after checks returns set of sensor ids corresponding to the given RP id
Definition: CTPPSGeometry.cc:149
DDD_TOTEM_RP_SENSOR_NAME
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:13
CTPPSGeometry::rp
const DetGeomDesc * rp(unsigned int id) const
returns geometry of a RP box
Definition: CTPPSGeometry.cc:111
ztail.d
d
Definition: ztail.py:151
CTPPSGeometry::build
void build(const DetGeomDesc *, unsigned int verbosity)
build up from DetGeomDesc structure
Definition: CTPPSGeometry.cc:14
cms::Exception
Definition: Exception.h:70
CTPPSDetId::rpId
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:82
DetGeomDesc::rotation
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:76
CTPPSGeometry::localToGlobal
Vector localToGlobal(const DetGeomDesc *, const Vector &) const
Definition: CTPPSGeometry.cc:158
CTPPSGeometry::rps_in_station_
mapSetType rps_in_station_
Definition: CTPPSGeometry.h:122
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
CTPPSGeometry::sensor
const DetGeomDesc * sensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
Definition: CTPPSGeometry.cc:91
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
CTPPSGeometry::Vector
DetGeomDesc::Translation Vector
Definition: CTPPSGeometry.h:39