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 
10 
11 //----------------------------------------------------------------------------------------------------
12 
13 void
15 {
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  // check if it is a sensor
31  if ( d->name().name() == DDD_TOTEM_RP_SENSOR_NAME
34  || d->name().name() == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
35  addSensor(d->geographicalID(), d);
36  }
37 
38  // check if it is a RP
39  if ( d->name().name() == DDD_TOTEM_RP_RP_NAME
41  || d->name().name() == DDD_CTPPS_PIXELS_RP_NAME ) {
42  addRP( d->geographicalID(), d );
43  }
44 
45  for ( unsigned int i = 0; i < d->components().size(); i++ )
46  buffer.emplace_back( d->components()[i] );
47  }
48 
49  // build sets
50  for ( const auto& it : sensors_map_ ) {
51  const CTPPSDetId detId( it.first );
52  const CTPPSDetId rpId = detId.getRPId();
53  const CTPPSDetId stId = detId.getStationId();
54  const CTPPSDetId armId = detId.getArmId();
55 
56  stations_in_arm_[armId].insert( armId );
57  rps_in_station_[stId].insert( rpId );
58  dets_in_rp_[rpId].insert( detId );
59  }
60 }
61 
62 //----------------------------------------------------------------------------------------------------
63 
64 bool
65 CTPPSGeometry::addSensor( unsigned int id, const DetGeomDesc*& gD )
66 {
67  if ( sensors_map_.find( id ) != sensors_map_.end() ) return false;
68 
69  sensors_map_[id] = gD;
70  return true;
71 }
72 
73 //----------------------------------------------------------------------------------------------------
74 
75 bool
76 CTPPSGeometry::addRP( unsigned int id, const DetGeomDesc*& gD )
77 {
78  if ( rps_map_.find( id ) != rps_map_.end() ) return false;
79 
80  rps_map_[id] = const_cast<DetGeomDesc*>( gD );
81  return true;
82 }
83 
84 //----------------------------------------------------------------------------------------------------
85 
86 const DetGeomDesc*
87 CTPPSGeometry::getSensor( unsigned int id ) const
88 {
89  auto it = sensors_map_.find( id );
90  if ( it == sensors_map_.end() )
91  throw cms::Exception("CTPPSGeometry") << "Not found detector with ID " << id << ", i.e. "
92  << CTPPSDetId( id );
93 
94  return it->second;
95 }
96 
97 //----------------------------------------------------------------------------------------------------
98 
99 const DetGeomDesc*
100 CTPPSGeometry::getRP( unsigned int id ) const
101 {
102  auto it = rps_map_.find( id );
103  if ( it == rps_map_.end() )
104  throw cms::Exception("CTPPSGeometry") << "Not found RP device with ID " << id << ", i.e. "
105  << CTPPSDetId( id );
106 
107  return it->second;
108 }
109 
110 //----------------------------------------------------------------------------------------------------
111 const std::set<unsigned int>&
112 CTPPSGeometry::getStationsInArm( unsigned int id ) const
113 {
114  auto it = stations_in_arm_.find( id );
115  if ( it == stations_in_arm_.end() )
116  throw cms::Exception("CTPPSGeometry") << "Arm with ID " << id << " not found.";
117  return it->second;
118 }
119 
120 //----------------------------------------------------------------------------------------------------
121 
122 const std::set<unsigned int>&
123 CTPPSGeometry::getRPsInStation( unsigned int id ) const
124 {
125  auto it = rps_in_station_.find( id );
126  if ( it == rps_in_station_.end() )
127  throw cms::Exception("CTPPSGeometry") << "Station with ID " << id << " not found.";
128  return it->second;
129 }
130 
131 //----------------------------------------------------------------------------------------------------
132 
133 const std::set<unsigned int>&
134 CTPPSGeometry::getSensorsInRP( unsigned int id ) const
135 {
136  auto it = dets_in_rp_.find( id );
137  if ( it == dets_in_rp_.end() )
138  throw cms::Exception("CTPPSGeometry") << "RP with ID " << id << " not found.";
139  return it->second;
140 }
141 
142 //----------------------------------------------------------------------------------------------------
143 
144 CLHEP::Hep3Vector
145 CTPPSGeometry::localToGlobal( const DetGeomDesc* gd, const CLHEP::Hep3Vector& r ) const
146 {
147  return gd->rotation() * r + CLHEP::Hep3Vector( gd->translation().x(), gd->translation().y(), gd->translation().z() );
148 }
149 
150 //----------------------------------------------------------------------------------------------------
151 
152 CLHEP::Hep3Vector
153 CTPPSGeometry::localToGlobal( unsigned int id, const CLHEP::Hep3Vector& r ) const
154 {
155  return localToGlobal( getSensor( id ), r );
156 }
157 
158 //----------------------------------------------------------------------------------------------------
159 
160 CLHEP::Hep3Vector
161 CTPPSGeometry::globalToLocal( const DetGeomDesc* gd, const CLHEP::Hep3Vector& r ) const
162 {
163  return gd->rotation().Inverse() * ( r - CLHEP::Hep3Vector( gd->translation().x(), gd->translation().y(), gd->translation().z() ) );
164 }
165 
166 //----------------------------------------------------------------------------------------------------
167 
168 CLHEP::Hep3Vector
169 CTPPSGeometry::globalToLocal( unsigned int id, const CLHEP::Hep3Vector& r ) const
170 {
171  return globalToLocal( getSensor( id ), r );
172 }
173 
174 //----------------------------------------------------------------------------------------------------
175 
176 CLHEP::Hep3Vector
177 CTPPSGeometry::localToGlobalDirection( unsigned int id, const CLHEP::Hep3Vector& dir ) const
178 {
179  return getSensor( id )->rotation() * dir;
180 }
181 
182 //----------------------------------------------------------------------------------------------------
183 
184 CLHEP::Hep3Vector
185 CTPPSGeometry::globalToLocalDirection( unsigned int id, const CLHEP::Hep3Vector& dir ) const
186 {
187  return getSensor( id )->rotation().Inverse() * dir;
188 }
189 
190 //----------------------------------------------------------------------------------------------------
191 
192 CLHEP::Hep3Vector
193 CTPPSGeometry::getSensorTranslation( unsigned int id ) const
194 {
195  auto gd = getSensor( id );
196  return CLHEP::Hep3Vector( gd->translation().x(), gd->translation().y(), gd->translation().z() );
197 }
198 
199 //----------------------------------------------------------------------------------------------------
200 
201 CLHEP::Hep3Vector
202 CTPPSGeometry::getRPTranslation( unsigned int id ) const
203 {
204  auto gd = getRP( id );
205  return CLHEP::Hep3Vector( gd->translation().x(), gd->translation().y(), gd->translation().z() );
206 }
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:22
DDRotationMatrix rotation() const
geometry information
Definition: DetGeomDesc.h:83
const std::set< unsigned int > & getStationsInArm(unsigned int) const
after checks returns set of station ids corresponding to the given arm id
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...
CTPPSDetId getStationId() const
Definition: CTPPSDetId.h:92
const std::set< unsigned int > & getRPsInStation(unsigned int) const
after checks returns set of RP ids corresponding to the given station id
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:16
const DetGeomDesc * getSensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
void build(const DetGeomDesc *)
build up from DetGeomDesc structure
virtual ConstContainer components() const
access to the tree structure
Definition: DetGeomDesc.cc:123
Geometrical description of a sensor.
Definition: DetGeomDesc.h:37
DDTranslation translation() const
Definition: DetGeomDesc.h:84
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
DDName name() const
Definition: DetGeomDesc.h:87
CLHEP::Hep3Vector localToGlobal(const DetGeomDesc *, const CLHEP::Hep3Vector &) const
CLHEP::Hep3Vector getRPTranslation(unsigned int id) const
CTPPSDetId getArmId() const
Definition: CTPPSDetId.h:87
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:21
mapSetType rps_in_station_
virtual DetId geographicalID() const
Definition: DetGeomDesc.h:61
CLHEP::Hep3Vector localToGlobalDirection(unsigned int id, const CLHEP::Hep3Vector &) const
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:23
RPDeviceMapType rps_map_
map: rp id –> DetGeomDesc
CLHEP::Hep3Vector globalToLocalDirection(unsigned int id, const CLHEP::Hep3Vector &) const
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
bool addSensor(unsigned int, const DetGeomDesc *&)
adds an item to the map (detector ID –> DetGeomDesc) performs necessary checks
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:14
CLHEP::Hep3Vector getSensorTranslation(unsigned int id) const
dbl *** dir
Definition: mlp_gen.cc:35
mapSetType dets_in_rp_
const std::set< unsigned int > & getSensorsInRP(unsigned int) const
after checks returns set of sensor ids corresponding to the given RP id
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:15
mapType sensors_map_
map: sensor id –> DetGeomDesc
CLHEP::Hep3Vector globalToLocal(const DetGeomDesc *, const CLHEP::Hep3Vector &) const
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
const DetGeomDesc * getRP(unsigned int id) const
returns geometry of a RP box
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:17