CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ||
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 }
Log< level::Info, true > LogVerbatim
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:24
uint16_t *__restrict__ id
void build(const DetGeomDesc *, unsigned int verbosity)
build up from DetGeomDesc structure
DetId geographicalID() const
Definition: DetGeomDesc.h:102
const Translation & translation() const
Definition: DetGeomDesc.h:80
mapSetType stations_in_arm_
map: parent ID -&gt; set of subelements E.g. stations_in_arm_ is map of arm ID -&gt; set of stations (in th...
const DetGeomDesc * rp(unsigned int id) const
returns geometry of a RP box
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::set< unsigned int > & rpsInStation(unsigned int) const
after checks returns set of RP ids corresponding to the given station id
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
DetGeomDesc::Translation Vector
Definition: CTPPSGeometry.h:36
Vector localToGlobal(const DetGeomDesc *, const Vector &) const
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:78
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:18
tuple d
Definition: ztail.py:151
CTPPSDetId stationId() const
Definition: CTPPSDetId.h:76
Vector globalToLocal(const DetGeomDesc *, const Vector &) const
const DetGeomDesc * sensorNoThrow(unsigned int id) const noexcept
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:20
const Container & components() const
Definition: DetGeomDesc.h:105
CTPPSDetId armId() const
Definition: CTPPSDetId.h:74
Vector globalToLocalDirection(unsigned int id, const Vector &) const
const std::string & name() const
Definition: DetGeomDesc.h:73
const std::set< unsigned int > & sensorsInRP(unsigned int) const
after checks returns set of sensor ids corresponding to the given RP id
const DetGeomDesc * sensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:23
mapSetType rps_in_station_
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:26
RPDeviceMapType rps_map_
map: rp id –&gt; DetGeomDesc
Vector localToGlobalDirection(unsigned int id, const Vector &) const
Vector sensorTranslation(unsigned int id) const
const DetGeomDesc * rpNoThrow(unsigned int id) const noexcept
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
const std::set< unsigned int > & stationsInArm(unsigned int) const
after checks returns set of station ids corresponding to the given arm id
Vector rpTranslation(unsigned int id) const
void print() const
Definition: DetGeomDesc.cc:119
bool addSensor(unsigned int, const DetGeomDesc *&)
adds an item to the map (detector ID –&gt; DetGeomDesc) performs necessary checks
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:81
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:14
mapSetType dets_in_rp_
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:15
mapType sensors_map_
map: sensor id –&gt; DetGeomDesc
bool addRP(unsigned int id, const DetGeomDesc *&)
adds a RP box to a map
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:19