File indexing completed on 2025-08-05 08:20:37
0001
0002
0003 #ifndef MVTX_TB_SETUP_STAVE_GEOM_H
0004 #define MVTX_TB_SETUP_STAVE_GEOM_H
0005
0006 #define NMAXRU 2
0007 #define NMAXRUCHN 28
0008 #define NLAYER 4
0009 #define NCHIP 9
0010 #define NROW 512
0011 #define NCOL 1024
0012 #define NREGION 32
0013 #define NCOL_PER_REGION 32
0014
0015 #include <trackbase/TrkrDefs.h>
0016 #include <mvtx/MvtxDefs.h>
0017 #include <mvtx/SegmentationAlpide.h>
0018
0019 #include <TGeoMatrix.h>
0020
0021 typedef SegmentationAlpide Segmentation;
0022
0023 template <typename T = TGeoHMatrix>
0024 class MatrixCache
0025 {
0026 public:
0027 MatrixCache() = default;
0028 ~MatrixCache() = default;
0029 MatrixCache(const MatrixCache& src) = delete;
0030 MatrixCache& operator=(const MatrixCache src) = delete;
0031
0032
0033 void setSize(int s)
0034 {
0035 if (!m_cache.size())
0036 m_cache.resize(s);
0037 }
0038
0039
0040 int getSize() const { return m_cache.size(); }
0041
0042 void setMatrix(const T& mat, int sensID)
0043 {
0044
0045
0046
0047
0048 m_cache[sensID] = mat;
0049 }
0050
0051 const T& getMatrix(int sensID) const { return m_cache[sensID]; }
0052 bool isFilled() const { return !m_cache.empty(); }
0053
0054 private:
0055 std::vector<T> m_cache;
0056 };
0057
0058
0059
0060
0061 class MvtxPrototype2Geom
0062 {
0063 public:
0064 MvtxPrototype2Geom():m_verbose(0)
0065 {
0066 if (s_instance) {
0067 exit(1);
0068 }
0069 Build();
0070 }
0071
0072 ~MvtxPrototype2Geom() = default;
0073 MvtxPrototype2Geom(const MvtxPrototype2Geom& src) = delete;
0074 MvtxPrototype2Geom& operator=(const MvtxPrototype2Geom& geo) = delete;
0075
0076 const MatrixCache<TGeoHMatrix>& getCacheL2G() const { return m_l2G; }
0077 const TGeoHMatrix& getMatrixL2G(int sensID) const { return m_l2G.getMatrix(sensID); }
0078 bool isBuilt() const { return m_size != 0; }
0079 int getSize() const { return m_size; }
0080
0081 void setSize(int s)
0082 {
0083
0084
0085
0086
0087 m_size = s;
0088 }
0089 int getLastChipIndex(int lay) const { return m_lastChipIndex[lay]; }
0090 int getFirstChipIndex(int lay) const { return (lay == 0) ? 0 : m_lastChipIndex[lay - 1] + 1; }
0091 int getChipIndex(int lay, int chipInStave)
0092 {
0093 return getFirstChipIndex(lay) + chipInStave;
0094 }
0095 int getChipIndex(TrkrDefs::hitsetkey _key) {
0096 return getChipIndex(TrkrDefs::getLayer(_key), MvtxDefs::getChipId(_key));
0097 }
0098 int getLayer(int index) const { return index / m_numOfChips; }
0099 int getChipInLay(int index) const { return index % m_numOfChips; }
0100
0101 static MvtxPrototype2Geom* Instance()
0102 {
0103
0104 if (!s_instance)
0105 s_instance = std::unique_ptr<MvtxPrototype2Geom>(new MvtxPrototype2Geom());
0106 return s_instance.get();
0107 }
0108
0109 void Build();
0110
0111 void setVerbose(int v) { m_verbose = v; }
0112 int Verbose() { return m_verbose; }
0113
0114 public:
0115 static constexpr float s_pitchChip_IB = 100.e-4;
0116 static constexpr float s_gapLayers_TB = 4.;
0117
0118
0119
0120 bool detectorToGlobal(int index, int iCol, int iRow, double* glo);
0121 bool detectorToGlobal(TrkrDefs::hitsetkey, TrkrDefs::hitkey, double*);
0122
0123 private:
0124 static int getNumberOfChipsInLay()
0125 {
0126 return m_numOfStaves * m_numOfChips;
0127 }
0128 TGeoHMatrix* extractMatrixSensor(int index);
0129 void fillMatrixCache();
0130
0131 private:
0132 int m_verbose;
0133 static std::unique_ptr<MvtxPrototype2Geom> s_instance;
0134 int m_size = 0;
0135 MatrixCache<TGeoHMatrix> m_l2G;
0136
0137 static constexpr int m_numOfLayers = 4;
0138 static constexpr int m_numOfStaves = 1;
0139 static constexpr int m_numOfChips = 9;
0140
0141 std::vector<int> m_lastChipIndex;
0142
0143 };
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 inline bool MvtxPrototype2Geom::detectorToGlobal(int index, int iCol, int iRow, double* glo)
0170 {
0171 if (iRow<0 || iRow>=Segmentation::NRows || iCol<0 || iCol>=Segmentation::NCols)
0172 return false;
0173 TVector3 locPoint;
0174 Segmentation::detectorToLocal(iRow, iCol, locPoint);
0175 const TGeoHMatrix& matL2G = Instance()->getMatrixL2G(index);
0176
0177 double loc[3];
0178 locPoint.GetXYZ(loc);
0179 matL2G.LocalToMaster(loc, glo);
0180 return true;
0181 }
0182
0183 inline bool MvtxPrototype2Geom::detectorToGlobal(TrkrDefs::hitsetkey _hitsetkey, TrkrDefs::hitkey _hitkey, double* glo)
0184 {
0185 return detectorToGlobal(getChipIndex(_hitsetkey), MvtxDefs::getCol(_hitkey), MvtxDefs::getRow(_hitkey), glo);
0186 }
0187
0188 #endif