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