Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxPrototype2Geom.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxPrototype2Geom.h
1 // Tell emacs that this is a C++ source
2 // -*- C++ -*-.
3 #ifndef MVTX_TB_SETUP_STAVE_GEOM_H
4 #define MVTX_TB_SETUP_STAVE_GEOM_H
5 
6 #define NMAXRU 2
7 #define NMAXRUCHN 28
8 #define NLAYER 4
9 #define NCHIP 9
10 #define NROW 512
11 #define NCOL 1024
12 #define NREGION 32
13 #define NCOL_PER_REGION 32
14 
15 #include <trackbase/TrkrDefs.h>
16 #include <mvtx/MvtxDefs.h>
18 
19 #include <TGeoMatrix.h>
20 
22 
23 template <typename T = TGeoHMatrix>
25 {
26  public:
27  MatrixCache() = default;
28  ~MatrixCache() = default;
29  MatrixCache(const MatrixCache& src) = delete;
30  MatrixCache& operator=(const MatrixCache src) = delete;
31 
33  void setSize(int s)
34  {
35  if (!m_cache.size())
36  m_cache.resize(s);
37  }
38 
40  int getSize() const { return m_cache.size(); }
42  void setMatrix(const T& mat, int sensID)
43  {
44  // assign matrix for given sensor. The cache must be booked in advance
45  //if ((unsigned int)sensID >= mCache.size()) {
46  // LOG(FATAL) << "SensID " << sensID << " exceeds cache size of " << mCache.size();
47  //}
48  m_cache[sensID] = mat;
49  }
50 
51  const T& getMatrix(int sensID) const { return m_cache[sensID]; }
52  bool isFilled() const { return !m_cache.empty(); }
53 
54  private:
55  std::vector<T> m_cache;
56 };
57 
62 {
63  public:
65  {
66  if (s_instance) {
67  exit(1);
68  }
69  Build();
70  }
71 
72  ~MvtxPrototype2Geom() = default;
73  MvtxPrototype2Geom(const MvtxPrototype2Geom& src) = delete;
74  MvtxPrototype2Geom& operator=(const MvtxPrototype2Geom& geo) = delete;
75 
76  const MatrixCache<TGeoHMatrix>& getCacheL2G() const { return m_l2G; }
77  const TGeoHMatrix& getMatrixL2G(int sensID) const { return m_l2G.getMatrix(sensID); }
78  bool isBuilt() const { return m_size != 0; }
79  int getSize() const { return m_size; }
80  // before calling fillMatrixCache, detector implementation should set the size of the matrix cache
81  void setSize(int s)
82  {
83  // set the size of the matrix cache, can be done only once
84  //if (mSize != 0) {
85  // LOG(FATAL) << "Cache size (N sensors) was already set to " << mSize;
86  //}
87  m_size = s;
88  }
89  int getLastChipIndex(int lay) const { return m_lastChipIndex[lay]; }
90  int getFirstChipIndex(int lay) const { return (lay == 0) ? 0 : m_lastChipIndex[lay - 1] + 1; }
91  int getChipIndex(int lay, int chipInStave)
92  {
93  return getFirstChipIndex(lay) + chipInStave;
94  }
97  }
98  int getLayer(int index) const { return index / m_numOfChips; }
99  int getChipInLay(int index) const { return index % m_numOfChips; }
100 
102  {
103  // get (create if needed) a unique instance of the object
104  if (!s_instance)
105  s_instance = std::unique_ptr<MvtxPrototype2Geom>(new MvtxPrototype2Geom());
106  return s_instance.get();
107  }
108 
109  void Build();
110 
111  void setVerbose(int v) { m_verbose = v; }
112  int Verbose() { return m_verbose; }
113 
114  public:
115  static constexpr float s_pitchChip_IB = 100.e-4;
116  static constexpr float s_gapLayers_TB = 4.;
117 
118  // static bool detectorToStave(int chip, int iRow, int iCol, int& sRow, int& sCol);
119  // static bool staveToDetector(int sRow, int sCol, int& chip, int& iRow, int& iCol);
120  bool detectorToGlobal(int index, int iCol, int iRow, double* glo);
122 
123  private:
125  {
126  return m_numOfStaves * m_numOfChips;
127  }
128  TGeoHMatrix* extractMatrixSensor(int index);
129  void fillMatrixCache();
130 
131  private:
132  int m_verbose;
133  static std::unique_ptr<MvtxPrototype2Geom> s_instance;
134  int m_size = 0;
136 
137  static constexpr int m_numOfLayers = 4;
138  static constexpr int m_numOfStaves = 1;
139  static constexpr int m_numOfChips = 9;
140 
141  std::vector<int> m_lastChipIndex;
142 
143 };
144 
145 //_________________________________________________________________________________________________
146 /* inline bool MvtxPrototype2Geom::detectorToStave(int chip, int iRow, int iCol, int& sRow, int& sCol)
147 {
148  //convert to concecutive row/col in a stave from row/col in chip
149  if (iRow<0 || iRow>=Segmentation::NRows || iCol<0 || iCol>=Segmentation::NCols)
150  return false;
151  sRow = iRow;
152  sCol = chip * Segmentation::NCols + iCol;
153  return true;
154 }
155 
156 //_________________________________________________________________________________________________
157 inline bool MvtxPrototype2Geom::staveToDetector(int sRow, int sCol, int& chip, int& iRow, int& iCol)
158 {
159  //convert to chip row/col from consecutive stave from row/col in chip
160  if (sRow<0 || sRow>=Segmentation::NRows || sCol<0 || sCol>=(m_numOfChips * Segmentation::NCols))
161  return false;
162  chip = sCol / Segmentation::NCols;
163  iCol = sCol % Segmentation::NCols;
164  iRow = sRow;
165  return true;
166 }
167 */
168 //_________________________________________________________________________________________________
169 inline bool MvtxPrototype2Geom::detectorToGlobal(int index, int iCol, int iRow, double* glo)
170 {
171  if (iRow<0 || iRow>=Segmentation::NRows || iCol<0 || iCol>=Segmentation::NCols)
172  return false;
173  TVector3 locPoint;
174  Segmentation::detectorToLocal(iRow, iCol, locPoint);
175  const TGeoHMatrix& matL2G = Instance()->getMatrixL2G(index);
176  //matL2G.Print();
177  double loc[3];
178  locPoint.GetXYZ(loc);
179  matL2G.LocalToMaster(loc, glo);
180  return true;
181 }
182 
183 inline bool MvtxPrototype2Geom::detectorToGlobal(TrkrDefs::hitsetkey _hitsetkey, TrkrDefs::hitkey _hitkey, double* glo)
184 {
185  return detectorToGlobal(getChipIndex(_hitsetkey), MvtxDefs::getCol(_hitkey), MvtxDefs::getRow(_hitkey), glo);
186 }
187 
188 #endif