CMS 3D CMS Logo

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, GEM = 11, ME0 = 12};
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 
48  VersionInfo() : productionTag(nullptr), cmsswVersion(nullptr), extraDetectors(nullptr) {}
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 
110  bool contains( unsigned int id ) const {
111  return FWGeometry::find( id ) != m_idToInfo.end();
112  }
113 
114  IdToInfoItr mapEnd() const {return m_idToInfo.end();}
115 
116  void clear( void ) { m_idToInfo.clear(); m_idToMatrix.clear(); }
117  IdToInfoItr find( unsigned int ) const;
118  void localToGlobal( const GeomDetInfo& info, const float* local, float* global, bool translatep=true ) const;
119 
120  const VersionInfo& versionInfo() const { return m_versionInfo; }
121 
122  int getProducerVersion() const {return m_producerVersion;}
123 
124  TGeoShape* getShape( const GeomDetInfo& info ) const;
125 
126 
127 private:
128  mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
129 
130  IdToInfo m_idToInfo;
131 
133 
135 
137 
138 };
139 
140 #endif
141 
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:132
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:149
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:364
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:302
FWGeometry(void)
Definition: FWGeometry.cc:19
void clear(void)
Definition: FWGeometry.h:116
~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:218
#define nullptr
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:175
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:120
std::map< unsigned int, TGeoMatrix * > m_idToMatrix
Definition: FWGeometry.h:128
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:318
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
IdToInfoItr mapEnd() const
Definition: FWGeometry.h:114
VersionInfo m_versionInfo
Definition: FWGeometry.h:134
Definition: Muon.py:1
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:259
void loadMap(const char *fileName)
Definition: FWGeometry.cc:52
int m_producerVersion
Definition: FWGeometry.h:136
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:334
bool contains(unsigned int id) const
Definition: FWGeometry.h:110
std::vector< FWRecoGeom::Info > InfoMap
Definition: FWRecoGeom.h:27
static const int kSubdetOffset
Definition: FWGeometry.h:28
int getProducerVersion() const
Definition: FWGeometry.h:122
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:286
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:203
std::vector< FWGeometry::GeomDetInfo > IdToInfo
Definition: FWGeometry.h:106
static const int kDetOffset
Definition: FWGeometry.h:27
IdToInfo m_idToInfo
Definition: FWGeometry.h:130
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:107