CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWGeometry.h
Go to the documentation of this file.
1 #ifndef Fireworks_Core_FWGeometry_h
2 #define Fireworks_Core_FWGeometry_h
3 //
4 // Description: service class that implements access to geometry of a given DetId
5 //
6 // Primary usage: raw detector id to full transformation matrix mapping
7 //
8 // Original Author: D.Kovalskyi
9 //
10 class TEveGeoShape;
11 class TGeoVolume;
12 class TGeoShape;
13 class TFile;
14 
15 #include "TEveVSDStructs.h"
16 #include "TGeoMatrix.h"
17 
19 
20 #include <map>
21 #include <vector>
22 
24 {
25 public:
26  static const int kDetOffset = 28;
27  static const int kSubdetOffset = 25;
28 
29  enum Detector { Tracker = 1, Muon = 2, Ecal = 3, Hcal = 4, Calo = 5 };
30  enum SubDetector { PixelBarrel = 1, PixelEndcap = 2, TIB = 3, TID = 4, TOB = 5, TEC = 6, CSC = 7, DT = 8, RPCBarrel = 9, RPCEndcap = 10 };
31 
32  struct Range {
33  double min1;
34  double max1;
35  double min2;
36  double max2;
37  Range( void ) : min1( 9999 ), max1( -9999 ), min2( 9999 ), max2( -9999 ) {
38  }
39  };
40 
41  FWGeometry( void );
42 
43  ~FWGeometry( void );
44 
45  // load DetId to RecoGeomInfo map
46  void loadMap( const char* fileName );
47 
48  void initMap( const FWRecoGeom::InfoMap& map );
49 
50  // get matrix for full local to global transformation
51  const TGeoMatrix* getMatrix( unsigned int id ) const;
52 
53  static TFile* findFile( const char* fileName );
54 
55  // extract locally positioned shape for stand alone use
56  TGeoShape* getShape( unsigned int id ) const;
57 
58  // extract globally positioned shape for stand alone use
59  TEveGeoShape* getEveShape( unsigned int id ) const;
60 
61  // get shape description parameters
62  const float* getShapePars( unsigned int id ) const;
63 
64  // get all known detector ids with id matching mask
65  std::vector<unsigned int> getMatchedIds( Detector det, SubDetector subdet ) const;
66 
67  // get reco geometry
68  const float* getCorners( unsigned int id ) const;
69 
70  // get reco topology/parameters
71  const float* getParameters( unsigned int id ) const;
72 
73  void localToGlobal( unsigned int id, const float* local, float* global ) const;
74  void localToGlobal( unsigned int id, const float* local1, float* global1, const float* local2, float* global2 ) const;
75 
76  struct GeomDetInfo
77  {
78  unsigned int id; // DetId
79  float points[24]; // 3*8 x,y,z points defining its shape (can be undefined, e.g. 0s)
80  float parameters[9]; // specific DetId dependent parameters, e.g. topology (can be undefined, e.g. 0s)
81  float shape[5]; // shape description: 0 - shape type, For Trap: 1 - dx1, 2 - dx2, 3 - dz, 4 - dy1; for Box: dx, dy, dz (can be undefined, e.g. 0s)
82  float translation[3]; // translation x, y, z (can be undefined, e.g. 0s)
83  float matrix[9]; // transformation matrix xx, yx, zx, xy, yy, zy, xz, yz, zz (can be undefined, e.g. 0s)
84 
85  bool operator< ( unsigned int id ) const {
86  return ( this->id < id );
87  }
88  };
89 
90  bool match_id( const GeomDetInfo& o, unsigned int mask ) const {
91  unsigned int id = o.id;
92  return ((((( id >> kDetOffset ) & 0xF ) << 4) | (( id >> kSubdetOffset ) & 0x7 )) == mask );
93  }
94 
95  typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
96  typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;
97 
98  bool contains( unsigned int id ) const {
99  return FWGeometry::find( id ) != m_idToInfo.end();
100  }
101 
102  void clear( void ) { m_idToInfo.clear(); m_idToMatrix.clear(); }
103  IdToInfoItr find( unsigned int ) const;
104  void localToGlobal( const GeomDetInfo& info, const float* local, float* global ) const;
105 
106 private:
107  mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
108 
110 
111  TGeoShape* getShape( const GeomDetInfo& info ) const;
112 };
113 
114 #endif
115 
static TFile * findFile(const char *fileName)
Definition: FWGeometry.cc:25
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:140
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:354
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:293
FWGeometry(void)
Definition: FWGeometry.cc:18
void clear(void)
Definition: FWGeometry.h:102
~FWGeometry(void)
Definition: FWGeometry.cc:21
bool match_id(const GeomDetInfo &o, unsigned int mask) const
Definition: FWGeometry.h:90
TGeoShape * getShape(unsigned int id) const
Definition: FWGeometry.cc:209
void localToGlobal(unsigned int id, const float *local, float *global) const
Definition: FWGeometry.cc:325
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:166
dictionary map
Definition: Association.py:205
std::map< unsigned int, TGeoMatrix * > m_idToMatrix
Definition: FWGeometry.h:107
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:309
bool operator<(unsigned int id) const
Definition: FWGeometry.h:85
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:250
void loadMap(const char *fileName)
Definition: FWGeometry.cc:64
bool contains(unsigned int id) const
Definition: FWGeometry.h:98
std::vector< FWRecoGeom::Info > InfoMap
Definition: FWRecoGeom.h:27
static const int kSubdetOffset
Definition: FWGeometry.h:27
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:277
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:194
std::vector< FWGeometry::GeomDetInfo > IdToInfo
Definition: FWGeometry.h:95
static const int kDetOffset
Definition: FWGeometry.h:26
IdToInfo m_idToInfo
Definition: FWGeometry.h:109
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:96