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 //----------------------------------------------------------------------------------------------------
16 
18 {
19  using namespace std;
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  const DetGeomDesc *d = buffer.front();
27  buffer.pop_front();
28 
29  // check if it is RP detector
30  if (! d->name().name().compare(DDD_TOTEM_RP_DETECTOR_NAME)) {
31  //std::cout<<d->geographicalID().rawId()<<std::endl;
33  }
34 
35  // check if it is RP device (primary vacuum)
36  if (! d->name().name().compare(DDD_TOTEM_RP_PRIMARY_VACUUM_NAME)) {
37  AddRPDevice(d->copyno(), d);
38  }
39 
40  for (unsigned int i = 0; i < d->components().size(); i++) {
41  buffer.push_back( d->components()[i] );
42  }
43  }
44 
45  // build sets from theMap
46  BuildSets();
47 
48  return 0;
49 }
50 
51 //----------------------------------------------------------------------------------------------------
52 
53 char TotemRPGeometry::AddDetector(unsigned int id, const DetGeomDesc* &gD)
54 {
55  // check if id is RP id?
56 
57  // check if the ID is already in map
58  //std::cout<<"TotemRPGeometry::AddDetector, Detector added: "<<id<<std::endl;
59  if (theMap.find(id) != theMap.end()) return 1;
60 
61  // add gD
62  theMap[id] = (DetGeomDesc*) gD;
63  return 0;
64 }
65 
66 //----------------------------------------------------------------------------------------------------
67 
69 {
70  // check if id is RP id?
71 
72  // check if there is a corresponding key
73 // std::cout<<"TotemRPGeometry::GetDetector entered, id="<<id<<std::endl;
74  mapType::const_iterator it = theMap.find(id);
75  if (it == theMap.end())
76  throw cms::Exception("TotemRPGeometry") << "Detector with ID " << id << " not found.";
77 
78  // the [] operator cannot be used as this method is const
79  // and it must be const and one gets TotemRPGeometry const
80  // from EventSetup
81  //std::cout<<"det. retrieved:"<<id<<std::endl;
82  return (*it).second;
83 }
84 
85 //----------------------------------------------------------------------------------------------------
86 
87 CLHEP::Hep3Vector TotemRPGeometry::GetDetEdgePosition(unsigned int id) const
88 {
89  // hardcoded for now, values taken from RP_Hybrid.xml
90  // +-------+
91  // | |
92  // | + (0,0)
93  // *(x,y) |
94  // \-----+
95  // x=-RP_Det_Size_a/2+RP_Det_Edge_Length/(2*sqrt(2))
96  // y=x
97  // ideally we would get this from the geometry in the event setup
98  double x=-36.07/2+22.276/(2*sqrt(2));
99  return LocalToGlobal(id, CLHEP::Hep3Vector(x, x, 0.));
100 }
101 
102 // Left edge: -18.0325, -2.2209 ; Right edge: -2.2209, -18.0325
103 
104 //----------------------------------------------------------------------------------------------------
105 
106 CLHEP::Hep3Vector TotemRPGeometry::GetDetEdgeNormalVector(unsigned int id) const
107 {
108  return GetDetector(id)->rotation() * CLHEP::Hep3Vector(-sqrt(2)/2, -sqrt(2)/2, 0.);
109 }
110 
111 //----------------------------------------------------------------------------------------------------
112 
113 char TotemRPGeometry::AddRPDevice(int copy_no, const DetGeomDesc* &gD)
114 {
115  // check if the copy_no is already in map
116  if (theRomanPotMap.find(copy_no) != theRomanPotMap.end())
117  return 1;
118 
119  // add gD
120  theRomanPotMap[copy_no] = (DetGeomDesc*) gD;
121  return 0;
122 }
123 
124 //----------------------------------------------------------------------------------------------------
125 
127 {
128  // check if there is a corresponding key
129  RPDeviceMapType::const_iterator it = theRomanPotMap.find(copy_no);
130  if (it == theRomanPotMap.end())
131  throw cms::Exception("TotemRPGeometry") << "RP device with ID " << copy_no << " not found.";
132 
133  return (*it).second;
134 }
135 
136 //----------------------------------------------------------------------------------------------------
137 
138 CLHEP::Hep3Vector TotemRPGeometry::GetRPThinFoilPosition(int copy_no) const
139 {
140  // hardcoded for now, taken from RP_Box.xml:RP_Box_primary_vacuum_y
141  // ideally we would get this from the geometry in the event setup
142  return LocalToGlobal(GetRPDevice(copy_no), CLHEP::Hep3Vector(0., -135.65/2.0, 0.));
143 }
144 
145 //----------------------------------------------------------------------------------------------------
146 
147 CLHEP::Hep3Vector TotemRPGeometry::GetRPThinFoilNormalVector(int copy_no) const
148 {
149  return GetRPDevice(copy_no)->rotation() * CLHEP::Hep3Vector(0., -1., 0.);
150 }
151 
152 //----------------------------------------------------------------------------------------------------
153 
155 {
156  // reset
157  stationsInArm.clear();
158  rpsInStation.clear();
159  detsInRP.clear();
160 
161  // build
162  for (mapType::const_iterator it = theMap.begin(); it != theMap.end(); ++it) {
163  unsigned int id = TotemRPDetId::rawToDecId((*it).first);
166  detsInRP[TotemRPDetId::rpOfDet(id)].insert(id);
167  }
168 }
169 
170 //----------------------------------------------------------------------------------------------------
171 std::set<unsigned int> TotemRPGeometry::StationsInArm(unsigned int id) const
172 {
173  mapSetType::const_iterator it = stationsInArm.find(id);
174  if (it == stationsInArm.end())
175  throw cms::Exception("TotemRPGeometry") << "Arm with ID " << id << " not found.";
176  return (*it).second;
177 }
178 
179 //----------------------------------------------------------------------------------------------------
180 
181 std::set<unsigned int> TotemRPGeometry::RPsInStation(unsigned int id) const
182 {
183  mapSetType::const_iterator it = rpsInStation.find(id);
184  if (it == rpsInStation.end())
185  throw cms::Exception("TotemRPGeometry") << "Station with ID " << id << " not found.";
186  return (*it).second;
187 }
188 
189 //----------------------------------------------------------------------------------------------------
190 
191 double TotemRPGeometry::GetStationCentreZPosition(unsigned int id) const
192 {
193  unsigned int st_id = id%10;
194  unsigned int arm_id = id/10;
195 
196  TotemRPDetId near = TotemRPDetId(arm_id, st_id, 0, 0);
197  TotemRPDetId far = TotemRPDetId(arm_id, st_id, 5, 9);
198 
199  return (GetDetTranslation(near).z() + GetDetTranslation(far).z()) / 2.0;
200 }
201 
202 //----------------------------------------------------------------------------------------------------
203 
204 std::set<unsigned int> TotemRPGeometry::DetsInRP(unsigned int id) const
205 {
206  mapSetType::const_iterator it = detsInRP.find(id);
207  if (it == detsInRP.end())
208  throw cms::Exception("TotemRPGeometry") << "RP with ID " << id << " not found.";
209  return (*it).second;
210 }
211 
212 //----------------------------------------------------------------------------------------------------
213 
214 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
215 {
216  CLHEP::Hep3Vector tmp = gd->rotation() * r;
217  tmp.setX(tmp.x() + (gd->translation()).x());
218  tmp.setY(tmp.y() + (gd->translation()).y());
219  tmp.setZ(tmp.z() + (gd->translation()).z());
220  return tmp;
221 }
222 
223 //----------------------------------------------------------------------------------------------------
224 
225 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobal(unsigned int id, const CLHEP::Hep3Vector r) const
226 {
227  DetGeomDesc *gd = GetDetector(id);
228  CLHEP::Hep3Vector tmp = gd->rotation() * 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 tmp;
233 }
234 
235 //----------------------------------------------------------------------------------------------------
236 
237 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
238 {
239  CLHEP::Hep3Vector tmp = r;
240  tmp.setX(tmp.x() - (gd->translation()).x());
241  tmp.setY(tmp.y() - (gd->translation()).y());
242  tmp.setZ(tmp.z() - (gd->translation()).z());
243  return (gd->rotation()).Inverse() * tmp;
244 }
245 
246 //----------------------------------------------------------------------------------------------------
247 
248 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocal(unsigned int id, const CLHEP::Hep3Vector r) const
249 {
250  DetGeomDesc *gd = GetDetector(id);
251  CLHEP::Hep3Vector tmp = r;
252  tmp.setX(tmp.x() - (gd->translation()).x());
253  tmp.setY(tmp.y() - (gd->translation()).y());
254  tmp.setZ(tmp.z() - (gd->translation()).z());
255  return (gd->rotation()).Inverse() * tmp;
256 }
257 
258 //----------------------------------------------------------------------------------------------------
259 
260 CLHEP::Hep3Vector TotemRPGeometry::LocalToGlobalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
261 {
262  return GetDetector(id)->rotation() * dir;
263 }
264 
265 //----------------------------------------------------------------------------------------------------
266 
267 CLHEP::Hep3Vector TotemRPGeometry::GlobalToLocalDirection(unsigned int id, const CLHEP::Hep3Vector dir) const
268 {
269  return (GetDetector(id)->rotation()).Inverse() * dir;
270 }
271 
272 //----------------------------------------------------------------------------------------------------
273 
274 CLHEP::Hep3Vector TotemRPGeometry::GetDetTranslation(unsigned int id) const
275 {
276  DetGeomDesc *gd = GetDetector(id);
277  CLHEP::Hep3Vector tmp;
278  tmp.setX((gd->translation()).x());
279  tmp.setY((gd->translation()).y());
280  tmp.setZ((gd->translation()).z());
281  return tmp;
282 }
283 
284 //----------------------------------------------------------------------------------------------------
285 
286 void TotemRPGeometry::GetReadoutDirection(unsigned int id, double &dx, double &dy) const
287 {
288  CLHEP::Hep3Vector d = LocalToGlobalDirection(id, CLHEP::Hep3Vector(0., 1., 0.));
289  dx = d.x();
290  dy = d.y();
291 }
292 
293 //----------------------------------------------------------------------------------------------------
294 
295 CLHEP::Hep3Vector TotemRPGeometry::GetRPGlobalTranslation(int copy_no) const
296 {
297  CLHEP::Hep3Vector tmp;
298  DetGeomDesc * gd = GetRPDevice(copy_no);
299  tmp.setX((gd->translation()).x());
300  tmp.setY((gd->translation()).y());
301  tmp.setZ((gd->translation()).z());
302  return tmp;
303 }
304 
305 //----------------------------------------------------------------------------------------------------
306 
307 CLHEP::HepRotation TotemRPGeometry::GetRPGlobalRotation(int copy_no) const
308 {
309  double xx, xy, xz, yx, yy, yz, zx, zy, zz;
310  GetRPDevice(copy_no)->rotation().GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz);
311  CLHEP::HepRep3x3 rot_mat( xx, xy, xz, yx, yy, yz, zx, zy, zz);
312  CLHEP::HepRotation rot(rot_mat);
313  return rot;
314 }
315 
Roman Pot detector ID.
Definition: TotemRPDetId.h:51
int i
Definition: DBlmapReader.cc:9
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
static unsigned int rpOfDet(unsigned int i)
returns ID of RP for given detector ID &#39;&#39;i&#39;&#39;
Definition: TotemRPDetId.h:141
CLHEP::Hep3Vector GetRPGlobalTranslation(int copy_no) const
position of a RP package (translation z corresponds to the first plane - TODO check it) ...
double GetStationCentreZPosition(unsigned int) const
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
static unsigned int rawToDecId(unsigned int raw)
fast conversion Raw to Decimal ID
Definition: TotemRPDetId.h:120
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 ...
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::set< unsigned int > DetsInRP(unsigned int) const
tuple d
Definition: ztail.py:151
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
static unsigned int stOfDet(unsigned int i)
returns ID of station for given detector ID &#39;&#39;i&#39;&#39;
Definition: TotemRPDetId.h:144
mapSetType stationsInArm
map: parent ID -&gt; set of subelements E.g. stationsInArm is map of arm ID -&gt; set of stations (in that ...
Geometrical description of a detector.
Definition: DetGeomDesc.h:40
mapType theMap
map: detectorID –&gt; DetGeomDesc
DDTranslation translation() const
Definition: DetGeomDesc.h:87
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
DetGeomDesc * GetRPDevice(int copy_no) const
returns geometry of a RP box
char AddRPDevice(int copy_no, const DetGeomDesc *&det_geom_desc)
adds a RP package (primary vacuum) to a map copy_no means RPId (i.e. 3 digit decimal number) ...
virtual int copyno() const
Definition: DetGeomDesc.h:93
CLHEP::HepRotation GetRPGlobalRotation(int copy_no) const
returns number of detectors in the geometry (size of theMap)
static unsigned int armOfDet(unsigned int i)
returns ID of arm for given detector ID &#39;&#39;i&#39;&#39;
Definition: TotemRPDetId.h:147
virtual DetId geographicalID() const
Definition: DetGeomDesc.h:64
CLHEP::Hep3Vector LocalToGlobal(DetGeomDesc *gd, const CLHEP::Hep3Vector r) const
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
mapSetType rpsInStation
RPDeviceMapType theRomanPotMap
map: RPID –&gt; DetGeomDesc
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:87
CLHEP::Hep3Vector GetRPThinFoilNormalVector(int copy_no) const
returns a normal vector for the thin foil of a RP box
mapSetType detsInRP