test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TotemRPGeometry.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 
12 #include <iostream>
14 
15 using namespace std;
16 
17 //----------------------------------------------------------------------------------------------------
18 
20 {
21  // propagate through the GeometricalDet structure and add
22  // all detectors to 'theMap'
23  deque<const DetGeomDesc *> buffer;
24  buffer.push_back(gD);
25  while (buffer.size() > 0)
26  {
27  const DetGeomDesc *d = buffer.front();
28  buffer.pop_front();
29 
30  // check if it is RP detector
31  if (! d->name().name().compare(DDD_TOTEM_RP_DETECTOR_NAME))
32  AddDetector(d->geographicalID(), d);
33 
34  // check if it is RP device (primary vacuum)
35  if (! d->name().name().compare(DDD_TOTEM_RP_PRIMARY_VACUUM_NAME))
36  AddRPDevice(d->geographicalID(), d);
37 
38  for (unsigned int i = 0; i < d->components().size(); i++)
39  buffer.push_back(d->components()[i]);
40  }
41 
42  // build sets from theMap
43  BuildSets();
44 
45  return 0;
46 }
47 
48 //----------------------------------------------------------------------------------------------------
49 
50 char TotemRPGeometry::AddDetector(unsigned int id, const DetGeomDesc* &gD)
51 {
52  // check if the ID is already in map
53  if (theMap.find(id) != theMap.end())
54  return 1;
55 
56  // add gD
57  theMap[id] = (DetGeomDesc*) gD;
58  return 0;
59 }
60 
61 //----------------------------------------------------------------------------------------------------
62 
64 {
65  // check if id is RP id?
66 
67  // check if there is a corresponding key
68 // std::cout<<"TotemRPGeometry::GetDetector entered, id="<<id<<std::endl;
69  mapType::const_iterator it = theMap.find(id);
70  if (it == theMap.end())
71  throw cms::Exception("TotemRPGeometry") << "Not found detector with ID " << id << ", i.e. "
72  << TotemRPDetId(id);
73 
74  // the [] operator cannot be used as this method is const
75  // and it must be const and one gets TotemRPGeometry const
76  // from EventSetup
77  //std::cout<<"det. retrieved:"<<id<<std::endl;
78  return (*it).second;
79 }
80 
81 //----------------------------------------------------------------------------------------------------
82 
83 CLHEP::Hep3Vector TotemRPGeometry::GetDetEdgePosition(unsigned int id) const
84 {
85  // hardcoded for now, values taken from RP_Hybrid.xml
86  // +-------+
87  // | |
88  // | + (0,0)
89  // *(x,y) |
90  // \-----+
91  // x=-RP_Det_Size_a/2+RP_Det_Edge_Length/(2*sqrt(2))
92  // y=x
93  // ideally we would get this from the geometry in the event setup
94  double x=-36.07/2+22.276/(2*sqrt(2));
95  return LocalToGlobal(id, CLHEP::Hep3Vector(x, x, 0.));
96 }
97 
98 // Left edge: -18.0325, -2.2209 ; Right edge: -2.2209, -18.0325
99 
100 //----------------------------------------------------------------------------------------------------
101 
102 CLHEP::Hep3Vector TotemRPGeometry::GetDetEdgeNormalVector(unsigned int id) const
103 {
104  return GetDetector(id)->rotation() * CLHEP::Hep3Vector(-sqrt(2)/2, -sqrt(2)/2, 0.);
105 }
106 
107 //----------------------------------------------------------------------------------------------------
108 
109 char TotemRPGeometry::AddRPDevice(unsigned int id, const DetGeomDesc* &gD)
110 {
111  // check if the copy_no is already in map
112  if (theRomanPotMap.find(id) != theRomanPotMap.end())
113  return 1;
114 
115  // add gD
116  theRomanPotMap[id] = (DetGeomDesc*) gD;
117  return 0;
118 }
119 
120 //----------------------------------------------------------------------------------------------------
121 
123 {
124  // check if there is a corresponding key
125  RPDeviceMapType::const_iterator it = theRomanPotMap.find(id);
126  if (it == theRomanPotMap.end())
127  throw cms::Exception("TotemRPGeometry") << "Not found RP device with ID " << id << ", i.e. "
128  << TotemRPDetId(id);
129 
130  return (*it).second;
131 }
132 
133 //----------------------------------------------------------------------------------------------------
134 
135 CLHEP::Hep3Vector TotemRPGeometry::GetRPThinFoilPosition(int copy_no) const
136 {
137  // hardcoded for now, taken from RP_Box.xml:RP_Box_primary_vacuum_y
138  // ideally we would get this from the geometry in the event setup
139  return LocalToGlobal(GetRPDevice(copy_no), CLHEP::Hep3Vector(0., -135.65/2.0, 0.));
140 }
141 
142 //----------------------------------------------------------------------------------------------------
143 
144 CLHEP::Hep3Vector TotemRPGeometry::GetRPThinFoilNormalVector(int copy_no) const
145 {
146  return GetRPDevice(copy_no)->rotation() * CLHEP::Hep3Vector(0., -1., 0.);
147 }
148 
149 //----------------------------------------------------------------------------------------------------
150 
152 {
153  // reset
154  stationsInArm.clear();
155  rpsInStation.clear();
156  detsInRP.clear();
157 
158  // build
159  for (mapType::const_iterator it = theMap.begin(); it != theMap.end(); ++it)
160  {
161  const TotemRPDetId detId(it->first);
162  const CTPPSDetId rpId = detId.getRPId();
163  const CTPPSDetId stId = detId.getStationId();
164  const CTPPSDetId armId = detId.getArmId();
165 
166  stationsInArm[armId].insert(armId);
167  rpsInStation[stId].insert(rpId);
168  detsInRP[rpId].insert(detId);
169  }
170 }
171 
172 //----------------------------------------------------------------------------------------------------
173 std::set<unsigned int> TotemRPGeometry::StationsInArm(unsigned int id) const
174 {
175  mapSetType::const_iterator it = stationsInArm.find(id);
176  if (it == stationsInArm.end())
177  throw cms::Exception("TotemRPGeometry") << "Arm with ID " << id << " not found.";
178  return (*it).second;
179 }
180 
181 //----------------------------------------------------------------------------------------------------
182 
183 std::set<unsigned int> TotemRPGeometry::RPsInStation(unsigned int id) const
184 {
185  mapSetType::const_iterator it = rpsInStation.find(id);
186  if (it == rpsInStation.end())
187  throw cms::Exception("TotemRPGeometry") << "Station with ID " << id << " not found.";
188  return (*it).second;
189 }
190 
191 //----------------------------------------------------------------------------------------------------
192 
193 std::set<unsigned int> TotemRPGeometry::DetsInRP(unsigned int id) const
194 {
195  mapSetType::const_iterator it = detsInRP.find(id);
196  if (it == detsInRP.end())
197  throw cms::Exception("TotemRPGeometry") << "RP with ID " << id << " not found.";
198  return (*it).second;
199 }
200 
201 //----------------------------------------------------------------------------------------------------
202 
203 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
204 {
205  CLHEP::Hep3Vector tmp = gd->rotation() * r;
206  tmp.setX(tmp.x() + (gd->translation()).x());
207  tmp.setY(tmp.y() + (gd->translation()).y());
208  tmp.setZ(tmp.z() + (gd->translation()).z());
209  return tmp;
210 }
211 
212 //----------------------------------------------------------------------------------------------------
213 
214 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobal(unsigned int id, const CLHEP::Hep3Vector r) const
215 {
216  DetGeomDesc *gd = GetDetector(id);
217  CLHEP::Hep3Vector tmp = gd->rotation() * r;
218  tmp.setX(tmp.x() + (gd->translation()).x());
219  tmp.setY(tmp.y() + (gd->translation()).y());
220  tmp.setZ(tmp.z() + (gd->translation()).z());
221  return tmp;
222 }
223 
224 //----------------------------------------------------------------------------------------------------
225 
226 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
227 {
228  CLHEP::Hep3Vector tmp = r;
229  tmp.setX(tmp.x() - (gd->translation()).x());
230  tmp.setY(tmp.y() - (gd->translation()).y());
231  tmp.setZ(tmp.z() - (gd->translation()).z());
232  return (gd->rotation()).Inverse() * tmp;
233 }
234 
235 //----------------------------------------------------------------------------------------------------
236 
237 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocal(unsigned int id, const CLHEP::Hep3Vector r) const
238 {
239  DetGeomDesc *gd = GetDetector(id);
240  CLHEP::Hep3Vector tmp = r;
241  tmp.setX(tmp.x() - (gd->translation()).x());
242  tmp.setY(tmp.y() - (gd->translation()).y());
243  tmp.setZ(tmp.z() - (gd->translation()).z());
244  return (gd->rotation()).Inverse() * tmp;
245 }
246 
247 //----------------------------------------------------------------------------------------------------
248 
249 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
250 {
251  return GetDetector(id)->rotation() * dir;
252 }
253 
254 //----------------------------------------------------------------------------------------------------
255 
256 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
257 {
258  return (GetDetector(id)->rotation()).Inverse() * dir;
259 }
260 
261 //----------------------------------------------------------------------------------------------------
262 
263 CLHEP::Hep3Vector TotemRPGeometry::GetDetTranslation(unsigned int id) const
264 {
265  DetGeomDesc *gd = GetDetector(id);
266  CLHEP::Hep3Vector tmp;
267  tmp.setX((gd->translation()).x());
268  tmp.setY((gd->translation()).y());
269  tmp.setZ((gd->translation()).z());
270  return tmp;
271 }
272 
273 //----------------------------------------------------------------------------------------------------
274 
275 void TotemRPGeometry::GetReadoutDirection(unsigned int id, double &dx, double &dy) const
276 {
277  CLHEP::Hep3Vector d = LocalToGlobalDirection(id, CLHEP::Hep3Vector(0., 1., 0.));
278  dx = d.x();
279  dy = d.y();
280 }
281 
282 //----------------------------------------------------------------------------------------------------
283 
284 CLHEP::Hep3Vector TotemRPGeometry::GetRPGlobalTranslation(int copy_no) const
285 {
286  CLHEP::Hep3Vector tmp;
287  DetGeomDesc * gd = GetRPDevice(copy_no);
288  tmp.setX((gd->translation()).x());
289  tmp.setY((gd->translation()).y());
290  tmp.setZ((gd->translation()).z());
291  return tmp;
292 }
293 
294 //----------------------------------------------------------------------------------------------------
295 
296 CLHEP::HepRotation TotemRPGeometry::GetRPGlobalRotation(int copy_no) const
297 {
298  double xx, xy, xz, yx, yy, yz, zx, zy, zz;
299  GetRPDevice(copy_no)->rotation().GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz);
300  CLHEP::HepRep3x3 rot_mat( xx, xy, xz, yx, yy, yz, zx, zy, zz);
301  CLHEP::HepRotation rot(rot_mat);
302  return rot;
303 }
304 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
int i
Definition: DBlmapReader.cc:9
DetGeomDesc * GetRPDevice(unsigned int id) const
returns geometry of a RP box
DDRotationMatrix rotation() const
geometry information
Definition: DetGeomDesc.h:86
CLHEP::Hep3Vector GetDetEdgePosition(unsigned int id) const
returns the position of the edge of a detector
CLHEP::Hep3Vector GetRPGlobalTranslation(int copy_no) const
position of a RP package (translation z corresponds to the first plane - TODO check it) ...
CLHEP::Hep3Vector GetRPThinFoilPosition(int copy_no) const
returns the (outer) position of the thin foil of a RP box
char Build(const DetGeomDesc *)
build up from DetGeomDesc structure, return 0 = success
void BuildSets()
builds maps element ID –&gt; set of subelements (re)builds stationsInArm, rpsInStation, detsInRP out of theMap
const char DDD_TOTEM_RP_PRIMARY_VACUUM_NAME[]
DDD name of RP.
DetGeomDesc * GetDetector(unsigned int) const
returns geometry of a detector performs necessary checks, returns NULL if fails input is raw ID ...
CTPPSDetId getStationId() const
Definition: CTPPSDetId.h:92
char AddRPDevice(unsigned int id, const DetGeomDesc *&det_geom_desc)
adds a RP package (primary vacuum) to a map
void GetReadoutDirection(unsigned int id, double &dx, double &dy) const
std::set< unsigned int > RPsInStation(unsigned int) const
after checks returns set of RP corresponding to the given station ID
std::set< unsigned int > DetsInRP(unsigned int) const
tuple d
Definition: ztail.py:151
T x() const
Cartesian x coordinate.
CLHEP::Hep3Vector GlobalToLocalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
CLHEP::Hep3Vector GetDetTranslation(unsigned int id) const
virtual ConstContainer components() const
access to the tree structure
Definition: DetGeomDesc.cc:121
T sqrt(T t)
Definition: SSEVec.h:18
Geometrical description of a detector.
Definition: DetGeomDesc.h:40
DDTranslation translation() const
Definition: DetGeomDesc.h:87
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
DDName name() const
Definition: DetGeomDesc.h:90
CLHEP::Hep3Vector GetDetEdgeNormalVector(unsigned int id) const
returns a normal vector for the edge of a detector
CLHEP::Hep3Vector GlobalToLocal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
CLHEP::Hep3Vector LocalToGlobalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
CLHEP::HepRotation GetRPGlobalRotation(int copy_no) const
returns number of detectors in the geometry (size of theMap)
CTPPSDetId getArmId() const
Definition: CTPPSDetId.h:87
virtual DetId geographicalID() const
Definition: DetGeomDesc.h:64
CLHEP::Hep3Vector LocalToGlobal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
std::set< unsigned int > StationsInArm(unsigned int) const
after checks returns set of stations corresponding to the given arm ID
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
dbl *** dir
Definition: mlp_gen.cc:35
const char DDD_TOTEM_RP_DETECTOR_NAME[]
DDD name of RP detector.
char AddDetector(unsigned int, const DetGeomDesc *&)
adds an item to the map (detector ID –&gt; DetGeomDesc) performs necessary checks, returns 0 if succesfu...
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
CLHEP::Hep3Vector GetRPThinFoilNormalVector(int copy_no) const
returns a normal vector for the thin foil of a RP box