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 #include "TEveVSDStructs.h"
21 #include "TGeoMatrix.h"
22 #include "TGeoXtru.h"
23 
25 
27 class FWGeometry {
28 public:
29  static const int kDetOffset = 28;
30  static const int kSubdetOffset = 25;
31 
32  enum Detector {
33  Tracker = 1,
34  Muon = 2,
35  Ecal = 3,
36  Hcal = 4,
37  Calo = 5,
38  Forward = 6,
39  HGCalEE = 8,
40  HGCalHSi = 9,
41  HGCalHSc = 10,
43  };
44  enum SubDetector {
47  TIB = 3,
48  TID = 4,
49  TOB = 5,
50  TEC = 6,
51  CSC = 7,
52  DT = 8,
53  RPCBarrel = 9,
54  RPCEndcap = 10,
55  GEM = 11,
56  ME0 = 12
57  };
58 
59  struct Range {
60  double min1;
61  double max1;
62  double min2;
63  double max2;
64  Range(void) : min1(9999), max1(-9999), min2(9999), max2(-9999) {}
65  };
66 
67  class VersionInfo {
68  public:
69  TNamed* productionTag;
70  TNamed* cmsswVersion;
71  TObjArray* extraDetectors;
72 
73  VersionInfo() : productionTag(nullptr), cmsswVersion(nullptr), extraDetectors(nullptr) {}
74  bool haveExtraDet(const char*) const;
75  };
76 
77  FWGeometry(void);
78 
79  ~FWGeometry(void);
80 
81  // load DetId to RecoGeomInfo map
82  void loadMap(const char* fileName);
83 
84  void initMap(const FWRecoGeom::InfoMap& map);
85 
86  // get matrix for full local to global transformation
87  const TGeoMatrix* getMatrix(unsigned int id) const;
88 
89  static TFile* findFile(const char* fileName);
90 
91  // extract locally positioned shape for stand alone use
92  TGeoShape* getShape(unsigned int id) const;
93 
94  // extract globally positioned shape for stand alone use
95  TEveGeoShape* getEveShape(unsigned int id) const;
96  TEveGeoShape* getHGCSiliconEveShape(unsigned int id) const;
97  TEveGeoShape* getHGCScintillatorEveShape(unsigned int id) const;
98 
99  // get shape description parameters
100  const float* getShapePars(unsigned int id) const;
101 
102  // get all known detector ids with id matching mask
103  std::vector<unsigned int> getMatchedIds(Detector det, SubDetector subdet) const;
104  std::vector<unsigned int> getMatchedIds(Detector det) const;
105 
106  // get reco geometry
107  const float* getCorners(unsigned int id) const;
108 
109  // get reco topology/parameters
110  const float* getParameters(unsigned int id) const;
111 
112  void localToGlobal(unsigned int id, const float* local, float* global, bool translatep = true) const;
113  void localToGlobal(unsigned int id,
114  const float* local1,
115  float* global1,
116  const float* local2,
117  float* global2,
118  bool translatep = true) const;
119 
120  struct GeomDetInfo {
121  unsigned int id; // DetId
122  float points[24]; // 3*8 x,y,z points defining its shape (can be undefined, e.g. 0s)
123  float parameters[9]; // specific DetId dependent parameters, e.g. topology (can be undefined, e.g. 0s)
124  float shape
125  [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)
126  float translation[3]; // translation x, y, z (can be undefined, e.g. 0s)
127  float matrix[9]; // transformation matrix xx, yx, zx, xy, yy, zy, xz, yz, zz (can be undefined, e.g. 0s)
128 
129  bool operator<(unsigned int id) const { return (this->id < id); }
130  };
131 
132  bool match_id(const GeomDetInfo& o, unsigned int mask) const {
133  unsigned int id = o.id;
134  return (((((id >> kDetOffset) & 0xF) << 4) | ((id >> kSubdetOffset) & 0x7)) == mask);
135  }
136 
137  typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
138  typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;
139 
140  bool contains(unsigned int id) const { return FWGeometry::find(id) != m_idToInfo.end(); }
141 
142  IdToInfoItr mapEnd() const { return m_idToInfo.end(); }
143 
144  void clear(void) {
145  m_idToInfo.clear();
146  m_idToMatrix.clear();
147  }
148  IdToInfoItr find(unsigned int) const;
149  void localToGlobal(const GeomDetInfo& info, const float* local, float* global, bool translatep = true) const;
150 
151  const VersionInfo& versionInfo() const { return m_versionInfo; }
152 
153  int getProducerVersion() const { return m_producerVersion; }
154 
155  TGeoShape* getShape(const GeomDetInfo& info) const;
156 
157  const TrackerTopology* getTrackerTopology() const { return m_trackerTopology.get(); }
158 
159  void applyGlobalTag(const std::string& gt);
160 
161  bool isEmpty() const;
162 
163 private:
164  mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
165 
167 
169 
171 
173 
175 
176  std::unique_ptr<TrackerTopology> m_trackerTopology;
177 };
178 
179 #endif
std::unique_ptr< TrackerTopology > m_trackerTopology
Definition: FWGeometry.h:176
static TFile * findFile(const char *fileName)
Definition: FWGeometry.cc:38
bool contains(unsigned int id) const
Definition: FWGeometry.h:140
static const TGPicture * info(bool iBackgroundIsBlack)
TObjArray * extraDetectors
Definition: FWGeometry.h:71
std::string m_prodTag
Definition: FWGeometry.h:168
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:203
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:254
FWGeometry(void)
Definition: FWGeometry.cc:27
void clear(void)
Definition: FWGeometry.h:144
~FWGeometry(void)
Definition: FWGeometry.cc:29
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:507
constexpr uint32_t mask
Definition: gpuClustering.h:26
int getProducerVersion() const
Definition: FWGeometry.h:153
std::map< unsigned int, TGeoMatrix * > m_idToMatrix
Definition: FWGeometry.h:164
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:492
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:151
TEveGeoShape * getHGCScintillatorEveShape(unsigned int id) const
Definition: FWGeometry.cc:395
const TrackerTopology * getTrackerTopology() const
Definition: FWGeometry.h:157
VersionInfo m_versionInfo
Definition: FWGeometry.h:170
Definition: Muon.py:1
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:439
TEveGeoShape * getHGCSiliconEveShape(unsigned int id) const
Definition: FWGeometry.cc:350
void loadMap(const char *fileName)
Definition: FWGeometry.cc:103
int m_producerVersion
Definition: FWGeometry.h:172
std::vector< FWRecoGeom::Info > InfoMap
Definition: FWRecoGeom.h:23
bool operator<(unsigned int id) const
Definition: FWGeometry.h:129
static const int kSubdetOffset
Definition: FWGeometry.h:30
std::string m_fileName
Definition: FWGeometry.h:174
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:317
TGeoShape * getShape(unsigned int id) const
Definition: FWGeometry.cc:286
bool isEmpty() const
Definition: FWGeometry.cc:31
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:472
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:461
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:450
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:225
IdToInfoItr mapEnd() const
Definition: FWGeometry.h:142
std::vector< FWGeometry::GeomDetInfo > IdToInfo
Definition: FWGeometry.h:137
void applyGlobalTag(const std::string &gt)
Definition: FWGeometry.cc:59
static const int kDetOffset
Definition: FWGeometry.h:29
IdToInfo m_idToInfo
Definition: FWGeometry.h:166
bool match_id(const GeomDetInfo &o, unsigned int mask) const
Definition: FWGeometry.h:132
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:138