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 class TObjArray;
15 
16 #include "TEveVSDStructs.h"
17 #include "TGeoMatrix.h"
18 
20 
21 #include <map>
22 #include <vector>
23 
25 {
26 public:
27  static const int kDetOffset = 28;
28  static const int kSubdetOffset = 25;
29 
30  enum Detector { Tracker = 1, Muon = 2, Ecal = 3, Hcal = 4, Calo = 5 };
31  enum SubDetector { PixelBarrel = 1, PixelEndcap = 2, TIB = 3, TID = 4, TOB = 5, TEC = 6, CSC = 7, DT = 8, RPCBarrel = 9, RPCEndcap = 10 };
32 
33  struct Range {
34  double min1;
35  double max1;
36  double min2;
37  double max2;
38  Range( void ) : min1( 9999 ), max1( -9999 ), min2( 9999 ), max2( -9999 ) {
39  }
40  };
41 
42  class VersionInfo {
43  public:
44  TNamed* productionTag;
45  TNamed* cmsswVersion;
46  TObjArray* extraDetectors;
47 
49  bool haveExtraDet(const char*)const;
50  };
51 
52  FWGeometry( void );
53 
54  ~FWGeometry( void );
55 
56  // load DetId to RecoGeomInfo map
57  void loadMap( const char* fileName );
58 
59  void initMap( const FWRecoGeom::InfoMap& map );
60 
61  // get matrix for full local to global transformation
62  const TGeoMatrix* getMatrix( unsigned int id ) const;
63 
64  static TFile* findFile( const char* fileName );
65 
66  // extract locally positioned shape for stand alone use
67  TGeoShape* getShape( unsigned int id ) const;
68 
69  // extract globally positioned shape for stand alone use
70  TEveGeoShape* getEveShape( unsigned int id ) const;
71 
72  // get shape description parameters
73  const float* getShapePars( unsigned int id ) const;
74 
75  // get all known detector ids with id matching mask
76  std::vector<unsigned int> getMatchedIds( Detector det, SubDetector subdet ) const;
77 
78  // get reco geometry
79  const float* getCorners( unsigned int id ) const;
80 
81  // get reco topology/parameters
82  const float* getParameters( unsigned int id ) const;
83 
84  void localToGlobal( unsigned int id, const float* local, float* global, bool translatep=true ) const;
85  void localToGlobal( unsigned int id, const float* local1, float* global1, const float* local2, float* global2, bool translatep=true ) const;
86 
87  struct GeomDetInfo
88  {
89  unsigned int id; // DetId
90  float points[24]; // 3*8 x,y,z points defining its shape (can be undefined, e.g. 0s)
91  float parameters[9]; // specific DetId dependent parameters, e.g. topology (can be undefined, e.g. 0s)
92  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)
93  float translation[3]; // translation x, y, z (can be undefined, e.g. 0s)
94  float matrix[9]; // transformation matrix xx, yx, zx, xy, yy, zy, xz, yz, zz (can be undefined, e.g. 0s)
95 
96  bool operator< ( unsigned int id ) const {
97  return ( this->id < id );
98  }
99  };
100 
101  bool match_id( const GeomDetInfo& o, unsigned int mask ) const {
102  unsigned int id = o.id;
103  return ((((( id >> kDetOffset ) & 0xF ) << 4) | (( id >> kSubdetOffset ) & 0x7 )) == mask );
104  }
105 
106  typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
107  typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;
108 
109  bool contains( unsigned int id ) const {
110  return FWGeometry::find( id ) != m_idToInfo.end();
111  }
112 
113  void clear( void ) { m_idToInfo.clear(); m_idToMatrix.clear(); }
114  IdToInfoItr find( unsigned int ) const;
115  void localToGlobal( const GeomDetInfo& info, const float* local, float* global, bool translatep=true ) const;
116 
117  const VersionInfo& versionInfo() const { return m_versionInfo; }
118 
119  TGeoShape* getShape( const GeomDetInfo& info ) const;
120 
121 private:
122  mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
123 
125 
127 
129 
130 };
131 
132 #endif
133 
static TFile * findFile(const char *fileName)
Definition: FWGeometry.cc:26
static const TGPicture * info(bool iBackgroundIsBlack)
TObjArray * extraDetectors
Definition: FWGeometry.h:46
std::string m_prodTag
Definition: FWGeometry.h:126
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:143
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:358
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:296
FWGeometry(void)
Definition: FWGeometry.cc:19
void clear(void)
Definition: FWGeometry.h:113
~FWGeometry(void)
Definition: FWGeometry.cc:22
bool match_id(const GeomDetInfo &o, unsigned int mask) const
Definition: FWGeometry.h:101
TGeoShape * getShape(unsigned int id) const
Definition: FWGeometry.cc:212
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:169
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:117
std::map< unsigned int, TGeoMatrix * > m_idToMatrix
Definition: FWGeometry.h:122
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:312
bool operator<(unsigned int id) const
Definition: FWGeometry.h:96
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:379
VersionInfo m_versionInfo
Definition: FWGeometry.h:128
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:253
void loadMap(const char *fileName)
Definition: FWGeometry.cc:52
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:328
bool contains(unsigned int id) const
Definition: FWGeometry.h:109
std::vector< FWRecoGeom::Info > InfoMap
Definition: FWRecoGeom.h:27
static const int kSubdetOffset
Definition: FWGeometry.h:28
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:280
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:197
std::vector< FWGeometry::GeomDetInfo > IdToInfo
Definition: FWGeometry.h:106
static const int kDetOffset
Definition: FWGeometry.h:27
IdToInfo m_idToInfo
Definition: FWGeometry.h:124
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:107