Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:02

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