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