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