Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:31

0001 #ifndef Fireworks_Core_FWGeometry_h
0002 #define Fireworks_Core_FWGeometry_h
0003 //
0004 //  Description: service class that implements access to geometry of a given DetId
0005 //
0006 //  Primary usage: raw detector id to full transformation matrix mapping
0007 //
0008 //  Original Author: D.Kovalskyi
0009 //
0010 class TEveGeoShape;
0011 class TGeoVolume;
0012 class TGeoShape;
0013 class TFile;
0014 class TObjArray;
0015 
0016 #include <map>
0017 #include <vector>
0018 #include <memory>
0019 
0020 #include "TEveVSDStructs.h"
0021 #include "TGeoMatrix.h"
0022 #include "TGeoXtru.h"
0023 
0024 #include "Fireworks/Core/interface/FWRecoGeom.h"
0025 
0026 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0027 class FWGeometry {
0028 public:
0029   static const int kDetOffset = 28;
0030   static const int kSubdetOffset = 25;
0031 
0032   enum Detector {
0033     Tracker = 1,
0034     Muon = 2,
0035     Ecal = 3,
0036     Hcal = 4,
0037     Calo = 5,
0038     Forward = 6,
0039     HGCalEE = 8,
0040     HGCalHSi = 9,
0041     HGCalHSc = 10,
0042     HGCalTrigger = 11
0043   };
0044   enum SubDetector {
0045     PixelBarrel = 1,
0046     PixelEndcap = 2,
0047     TIB = 3,
0048     TID = 4,
0049     TOB = 5,
0050     TEC = 6,
0051     CSC = 7,
0052     DT = 8,
0053     RPCBarrel = 9,
0054     RPCEndcap = 10,
0055     GEM = 11,
0056     ME0 = 12
0057   };
0058 
0059   struct Range {
0060     double min1;
0061     double max1;
0062     double min2;
0063     double max2;
0064     Range(void) : min1(9999), max1(-9999), min2(9999), max2(-9999) {}
0065   };
0066 
0067   class VersionInfo {
0068   public:
0069     TNamed* productionTag;
0070     TNamed* cmsswVersion;
0071     TObjArray* extraDetectors;
0072 
0073     VersionInfo() : productionTag(nullptr), cmsswVersion(nullptr), extraDetectors(nullptr) {}
0074     bool haveExtraDet(const char*) const;
0075   };
0076 
0077   FWGeometry(void);
0078 
0079   ~FWGeometry(void);
0080 
0081   // load DetId to RecoGeomInfo map
0082   void loadMap(const char* fileName);
0083 
0084   void initMap(const FWRecoGeom::InfoMap& map);
0085 
0086   // get matrix for full local to global transformation
0087   const TGeoMatrix* getMatrix(unsigned int id) const;
0088 
0089   static TFile* findFile(const char* fileName);
0090 
0091   // extract locally positioned shape for stand alone use
0092   TGeoShape* getShape(unsigned int id) const;
0093 
0094   // extract globally positioned shape for stand alone use
0095   TEveGeoShape* getEveShape(unsigned int id) const;
0096   TEveGeoShape* getHGCSiliconEveShape(unsigned int id) const;
0097   TEveGeoShape* getHGCScintillatorEveShape(unsigned int id) const;
0098 
0099   // get shape description parameters
0100   const float* getShapePars(unsigned int id) const;
0101 
0102   // get all known detector ids with id matching mask
0103   std::vector<unsigned int> getMatchedIds(Detector det, SubDetector subdet) const;
0104   std::vector<unsigned int> getMatchedIds(Detector det) const;
0105 
0106   // get reco geometry
0107   const float* getCorners(unsigned int id) const;
0108 
0109   // get reco topology/parameters
0110   const float* getParameters(unsigned int id) const;
0111 
0112   void localToGlobal(unsigned int id, const float* local, float* global, bool translatep = true) const;
0113   void localToGlobal(unsigned int id,
0114                      const float* local1,
0115                      float* global1,
0116                      const float* local2,
0117                      float* global2,
0118                      bool translatep = true) const;
0119 
0120   struct GeomDetInfo {
0121     unsigned int id;      // DetId
0122     float points[24];     // 3*8 x,y,z points defining its shape (can be undefined, e.g. 0s)
0123     float parameters[9];  // specific DetId dependent parameters, e.g. topology (can be undefined, e.g. 0s)
0124     float shape
0125         [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)
0126     float translation[3];  // translation x, y, z (can be undefined, e.g. 0s)
0127     float matrix[9];       // transformation matrix xx, yx, zx, xy, yy, zy, xz, yz, zz (can be undefined, e.g. 0s)
0128 
0129     bool operator<(unsigned int id) const { return (this->id < id); }
0130   };
0131 
0132   bool match_id(const GeomDetInfo& o, unsigned int mask) const {
0133     unsigned int id = o.id;
0134     return (((((id >> kDetOffset) & 0xF) << 4) | ((id >> kSubdetOffset) & 0x7)) == mask);
0135   }
0136 
0137   typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
0138   typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;
0139 
0140   bool contains(unsigned int id) const { return FWGeometry::find(id) != m_idToInfo.end(); }
0141 
0142   IdToInfoItr mapEnd() const { return m_idToInfo.end(); }
0143 
0144   void clear(void) {
0145     m_idToInfo.clear();
0146     m_idToMatrix.clear();
0147   }
0148   IdToInfoItr find(unsigned int) const;
0149   void localToGlobal(const GeomDetInfo& info, const float* local, float* global, bool translatep = true) const;
0150 
0151   const VersionInfo& versionInfo() const { return m_versionInfo; }
0152 
0153   int getProducerVersion() const { return m_producerVersion; }
0154 
0155   TGeoShape* getShape(const GeomDetInfo& info) const;
0156 
0157   const TrackerTopology* getTrackerTopology() const { return m_trackerTopology.get(); }
0158 
0159   void applyGlobalTag(const std::string& gt);
0160 
0161   bool isEmpty() const;
0162 
0163 private:
0164   mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
0165 
0166   IdToInfo m_idToInfo;
0167 
0168   std::string m_prodTag;
0169 
0170   VersionInfo m_versionInfo;
0171 
0172   int m_producerVersion;
0173 
0174   std::string m_fileName;
0175 
0176   std::unique_ptr<TrackerTopology> m_trackerTopology;
0177 };
0178 
0179 #endif