Detector

FWGeometry

GeomDetInfo

Range

SubDetector

VersionInfo

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
#ifndef Fireworks_Core_FWGeometry_h
#define Fireworks_Core_FWGeometry_h
//
//  Description: service class that implements access to geometry of a given DetId
//
//  Primary usage: raw detector id to full transformation matrix mapping
//
//  Original Author: D.Kovalskyi
//
class TEveGeoShape;
class TGeoVolume;
class TGeoShape;
class TFile;
class TObjArray;

#include <map>
#include <vector>
#include <memory>

#include "TEveVSDStructs.h"
#include "TGeoMatrix.h"
#include "TGeoXtru.h"

#include "Fireworks/Core/interface/FWRecoGeom.h"

#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
class FWGeometry {
public:
  static const int kDetOffset = 28;
  static const int kSubdetOffset = 25;

  enum Detector {
    Tracker = 1,
    Muon = 2,
    Ecal = 3,
    Hcal = 4,
    Calo = 5,
    Forward = 6,
    HGCalEE = 8,
    HGCalHSi = 9,
    HGCalHSc = 10,
    HGCalTrigger = 11
  };
  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
  };

  struct Range {
    double min1;
    double max1;
    double min2;
    double max2;
    Range(void) : min1(9999), max1(-9999), min2(9999), max2(-9999) {}
  };

  class VersionInfo {
  public:
    TNamed* productionTag;
    TNamed* cmsswVersion;
    TObjArray* extraDetectors;

    VersionInfo() : productionTag(nullptr), cmsswVersion(nullptr), extraDetectors(nullptr) {}
    bool haveExtraDet(const char*) const;
  };

  FWGeometry(void);

  ~FWGeometry(void);

  // load DetId to RecoGeomInfo map
  void loadMap(const char* fileName);

  void initMap(const FWRecoGeom::InfoMap& map);

  // get matrix for full local to global transformation
  const TGeoMatrix* getMatrix(unsigned int id) const;

  static TFile* findFile(const char* fileName);

  // extract locally positioned shape for stand alone use
  TGeoShape* getShape(unsigned int id) const;

  // extract globally positioned shape for stand alone use
  TEveGeoShape* getEveShape(unsigned int id) const;
  TEveGeoShape* getHGCSiliconEveShape(unsigned int id) const;
  TEveGeoShape* getHGCScintillatorEveShape(unsigned int id) const;

  // get shape description parameters
  const float* getShapePars(unsigned int id) const;

  // get all known detector ids with id matching mask
  std::vector<unsigned int> getMatchedIds(Detector det, SubDetector subdet) const;
  std::vector<unsigned int> getMatchedIds(Detector det) const;

  // get reco geometry
  const float* getCorners(unsigned int id) const;

  // get reco topology/parameters
  const float* getParameters(unsigned int id) const;

  void localToGlobal(unsigned int id, const float* local, float* global, bool translatep = true) const;
  void localToGlobal(unsigned int id,
                     const float* local1,
                     float* global1,
                     const float* local2,
                     float* global2,
                     bool translatep = true) const;

  struct GeomDetInfo {
    unsigned int id;      // DetId
    float points[24];     // 3*8 x,y,z points defining its shape (can be undefined, e.g. 0s)
    float parameters[9];  // specific DetId dependent parameters, e.g. topology (can be undefined, e.g. 0s)
    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)
    float translation[3];  // translation x, y, z (can be undefined, e.g. 0s)
    float matrix[9];       // transformation matrix xx, yx, zx, xy, yy, zy, xz, yz, zz (can be undefined, e.g. 0s)

    bool operator<(unsigned int id) const { return (this->id < id); }
  };

  bool match_id(const GeomDetInfo& o, unsigned int mask) const {
    unsigned int id = o.id;
    return (((((id >> kDetOffset) & 0xF) << 4) | ((id >> kSubdetOffset) & 0x7)) == mask);
  }

  typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
  typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;

  bool contains(unsigned int id) const { return FWGeometry::find(id) != m_idToInfo.end(); }

  IdToInfoItr mapEnd() const { return m_idToInfo.end(); }

  void clear(void) {
    m_idToInfo.clear();
    m_idToMatrix.clear();
  }
  IdToInfoItr find(unsigned int) const;
  void localToGlobal(const GeomDetInfo& info, const float* local, float* global, bool translatep = true) const;

  const VersionInfo& versionInfo() const { return m_versionInfo; }

  int getProducerVersion() const { return m_producerVersion; }

  TGeoShape* getShape(const GeomDetInfo& info) const;

  const TrackerTopology* getTrackerTopology() const { return m_trackerTopology.get(); }

  void applyGlobalTag(const std::string& gt);

  bool isEmpty() const;

private:
  mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;

  IdToInfo m_idToInfo;

  std::string m_prodTag;

  VersionInfo m_versionInfo;

  int m_producerVersion;

  std::string m_fileName;

  std::unique_ptr<TrackerTopology> m_trackerTopology;
};

#endif