CbmRoot
CbmMuchModuleGemRectangular.cxx
Go to the documentation of this file.
1 
10 
11 #include "CbmMuchPadRectangular.h" // for CbmMuchPadRectangular
12 #include "CbmMuchSectorRectangular.h" // for CbmMuchSectorRectangular
13 
14 #include <TMathBase.h> // for Abs
15 
16 #include <algorithm> // for find
17 #include <limits> // for numeric_limits
18 #include <vector> // for vector, vector<>::iterator
19 
20 using std::vector;
21 
22 // ----- Default constructor -------------------------------------------
25  , fUseModuleDesign(kFALSE)
26  , fGridNx(0)
27  , fGridNy(0)
28  , fGridDx(0.)
29  , fGridDy(0.)
30  , fGrid() {
31  fDetectorType = 1;
32 }
33 // -------------------------------------------------------------------------
34 
35 
36 // ----- Standard constructor ------------------------------------------
38  Int_t iLayer,
39  Bool_t iSide,
40  Int_t iModule,
41  TVector3 position,
42  TVector3 size,
43  Double_t cutRadius)
44  : CbmMuchModuleGem(iStation,
45  iLayer,
46  iSide,
47  iModule,
48  position,
49  size,
50  cutRadius)
51  , fUseModuleDesign(kFALSE)
52  , fGridNx(0)
53  , fGridNy(0)
54  , fGridDx(0.)
55  , fGridDy(0.)
56  , fGrid() {
57  fDetectorType = 1;
58 }
59 // -------------------------------------------------------------------------
60 
61 
62 // ----- Public method GetSector ---------------------------------------
64  Int_t iy) {
65  if (ix < 0 || ix >= fGridNx) return nullptr;
66  if (iy < 0 || iy >= fGridNy) return nullptr;
67  Long64_t iSector = fGrid[ix][iy];
68  if (iSector == -1) return nullptr;
69  return (CbmMuchSectorRectangular*) fSectors[iSector];
70 }
71 // -------------------------------------------------------------------------
72 
73 
74 // ----- Public method GetSector ---------------------------------------
76  Double_t y) {
78 }
79 // -------------------------------------------------------------------------
80 
81 // -------------------------------------------------------------------------
83  Double_t mx0 = fPosition[0];
84  Double_t mlx = fSize[0];
85  Double_t msx = mx0 > 0 ? +1 : -1;
86  Double_t mx1 = mx0 - msx * mlx / 2;
87  return Int_t((x - mx1) / msx / fGridDx);
88 }
89 // -------------------------------------------------------------------------
90 
91 // -------------------------------------------------------------------------
93  Double_t my0 = fPosition[1];
94  Double_t mly = fSize[1];
95  Double_t msy = my0 > 0 ? +1 : -1;
96  Double_t my1 = my0 - msy * mly / 2;
97  return Int_t((y - my1) / msy / fGridDy);
98 }
99 // -------------------------------------------------------------------------
100 
101 // -------------------------------------------------------------------------
103  Double_t y) {
105  if (!sector) return nullptr;
106  return sector->GetPad(x, y);
107 }
108 // -------------------------------------------------------------------------
109 
110 
111 // ----- Public method InitGrid -----------------------------------------
112 Bool_t CbmMuchModuleGemRectangular::InitGrid(Bool_t useModuleDesign) {
113  Int_t nSectors = GetNSectors();
114  if (!nSectors) return kFALSE;
115  fUseModuleDesign = useModuleDesign;
116 
117  Double_t mx0 = fPosition[0];
118  Double_t my0 = fPosition[1];
119  Double_t mlx = fSize[0];
120  Double_t mly = fSize[1];
121  Double_t msx = mx0 > 0 ? +1 : -1;
122  Double_t msy = my0 > 0 ? +1 : -1;
123  Double_t mx1 = mx0 - msx * mlx / 2;
124  Double_t my1 = my0 - msy * mly / 2;
125 
126  // Determine grid dimensions
129  for (Int_t iSector = 0; iSector < nSectors; iSector++) {
131  if (s->IsIncomplete()) continue;
132  Double_t dx = s->GetSize()[0];
133  Double_t dy = s->GetSize()[1];
134  if (dx < fGridDx) fGridDx = dx;
135  if (dy < fGridDy) fGridDy = dy;
136  }
137 
138  Int_t nCell =
139  fUseModuleDesign ? 1 : 2; // Number of additional columns/rows in the grid
140  fGridNx = Int_t((mlx + 1e-5) / fGridDx) + nCell;
141  fGridNy = Int_t((mly + 1e-5) / fGridDy) + nCell;
142 
143  // Fill grid
144  fGrid.resize(fGridNx);
145  for (Int_t ix = 0; ix < fGridNx; ix++) {
146  fGrid[ix].resize(fGridNy);
147  for (Int_t iy = 0; iy < fGridNy; iy++) {
148  Double_t x = mx1 + msx * fGridDx * (ix + 1e-3);
149  Double_t y = my1 + msy * fGridDy * (iy + 1e-3);
150  fGrid[ix][iy] = -1;
151  for (int iSector = 0; iSector < nSectors; iSector++) {
154  if (sec->Inside(x, y)) {
155  fGrid[ix][iy] = sec->GetSectorIndex();
156  break;
157  }
158  }
159  }
160  }
161  return kTRUE;
162 }
163 // -------------------------------------------------------------------------
164 
165 // ------ Public method InitNeighbours ------------------------------------
167  vector<CbmMuchSectorRectangular*> neighbours;
168  vector<CbmMuchSectorRectangular*>::iterator it;
169  for (Int_t iSector = 0; iSector < GetNSectors(); iSector++) {
170  CbmMuchSectorRectangular* sector =
172  Double_t x1 = sector->GetX1() - 1e-3;
173  Double_t x2 = sector->GetX2() + 1e-3;
174  Double_t y1 = sector->GetY1() - 1e-3;
175  Double_t y2 = sector->GetY2() + 1e-3;
176  Double_t ix1 = GetGridIndexX(x1);
177  Double_t ix2 = GetGridIndexX(x2);
178  Double_t iy1 = GetGridIndexY(y1);
179  Double_t iy2 = GetGridIndexY(y2);
180  Double_t ixmin = (ix1 < ix2) ? ix1 : ix2;
181  Double_t ixmax = (ix1 < ix2) ? ix2 : ix1;
182  Double_t iymin = (iy1 < iy2) ? iy1 : iy2;
183  Double_t iymax = (iy1 < iy2) ? iy2 : iy1;
184  if (ixmin < 0) ixmin = 0;
185  if (ixmax >= fGridNx) ixmax = fGridNx - 1;
186  if (iymin < 0) iymin = 0;
187  if (iymax >= fGridNy) iymax = fGridNy - 1;
188 
189  for (Int_t ix = ixmin; ix <= ixmax; ix++) {
190  for (Int_t iy = iymin; iy <= iymax; iy++) {
191  Int_t iSec = fGrid[ix][iy];
192  if (iSec < 0) continue;
193  if (iSec == iSector) continue;
196  it = find(neighbours.begin(), neighbours.end(), sec);
197  if (it == neighbours.end()) neighbours.push_back(sec);
198  }
199  }
200  sector->SetNeighbours(neighbours);
201  neighbours.clear();
202  }
203 }
204 // -------------------------------------------------------------------------
205 
206 // ------ Public method InitNeighbourPads ----------------------------------
208  vector<CbmMuchPad*>::iterator it;
209  vector<CbmMuchPad*> neighbours;
210 
211  // Loop over all sectors within the module
212  for (Int_t iSector = 0; iSector < GetNSectors(); iSector++) {
213  CbmMuchSectorRectangular* sector =
215  if (!sector) continue;
216  Double_t mindx = sector->GetPadDx();
217  Double_t mindy = sector->GetPadDy();
218  vector<CbmMuchSectorRectangular*> neighbourSectors =
219  sector->GetNeighbours();
220  for (UInt_t iSec = 0; iSec < neighbourSectors.size(); iSec++) {
221  CbmMuchSectorRectangular* sec = neighbourSectors[iSec];
222  Double_t dx = sec->GetPadDx();
223  Double_t dy = sec->GetPadDy();
224  if (dx < mindx) mindx = dx;
225  if (dy < mindy) mindy = dy;
226  }
227 
228  for (Int_t iChannel = 0; iChannel < sector->GetNChannels(); iChannel++) {
229  CbmMuchPadRectangular* pad =
230  (CbmMuchPadRectangular*) sector->GetPadByChannelIndex(iChannel);
231  Double_t x1 = pad->GetX1();
232  Double_t x2 = pad->GetX2();
233  Double_t y1 = pad->GetY1();
234  Double_t y2 = pad->GetY2();
235  for (Double_t x = x1 - mindx / 2; x < x2 + mindx / 2 + 1e-3; x += mindx) {
236  for (Double_t y = y1 - mindy / 2; y < y2 + mindy / 2 + 1e-3;
237  y += mindy) {
238  CbmMuchPad* p = GetPad(x, y);
239  if (!p) continue;
240  if (p == pad) continue;
241  it = find(neighbours.begin(), neighbours.end(), p);
242  if (it == neighbours.end()) neighbours.push_back(p);
243  }
244  }
245  pad->SetNeighbours(neighbours);
246  neighbours.clear();
247  }
248  }
249 }
250 // -------------------------------------------------------------------------
251 
252 // -------------------------------------------------------------------------
254  Bool_t useModuleDesign =
255  TMath::Abs(fPosition[0]) > 1e-5 || TMath::Abs(fPosition[1]) > 1e-5;
256  if (!InitGrid(useModuleDesign)) return kFALSE;
258  for (Int_t iSector = 0; iSector < GetNSectors(); iSector++) {
259  CbmMuchSectorRectangular* sector =
261  if (!sector) continue;
262  sector->AddPads();
263  }
265  return kTRUE;
266 }
267 // -------------------------------------------------------------------------
268 
CbmMuchSectorRectangular::GetPad
CbmMuchPadRectangular * GetPad(Double_t x, Double_t y)
Definition: CbmMuchSectorRectangular.cxx:45
CbmMuchModule::fPosition
TVector3 fPosition
Definition: CbmMuchModule.h:78
CbmMuchSectorRectangular::GetPadDy
Double_t GetPadDy() const
Definition: CbmMuchSectorRectangular.h:40
CbmMuchSectorRectangular::GetPadDx
Double_t GetPadDx() const
Definition: CbmMuchSectorRectangular.h:39
CbmMuchModuleGemRectangular::fGridNy
Int_t fGridNy
Definition: CbmMuchModuleGemRectangular.h:44
CbmMuchModuleGemRectangular::InitGrid
Bool_t InitGrid(Bool_t useModuleDesign)
Definition: CbmMuchModuleGemRectangular.cxx:112
CbmMuchModuleGemRectangular::InitModule
virtual Bool_t InitModule()
Definition: CbmMuchModuleGemRectangular.cxx:253
CbmMuchModuleGemRectangular::GetGridIndexX
Int_t GetGridIndexX(Double_t x)
Definition: CbmMuchModuleGemRectangular.cxx:82
CbmMuchSectorRectangular::GetSize
TVector3 GetSize() const
Definition: CbmMuchSectorRectangular.h:36
CbmMuchSectorRectangular::SetNeighbours
void SetNeighbours(std::vector< CbmMuchSectorRectangular * > neighbours)
Definition: CbmMuchSectorRectangular.h:47
CbmMuchModuleGemRectangular::fGrid
std::vector< std::vector< Int_t > > fGrid
Definition: CbmMuchModuleGemRectangular.h:48
CbmMuchSector::GetNChannels
Int_t GetNChannels() const
Definition: CbmMuchSector.h:31
CbmMuchModuleGemRectangular::fGridDy
Double_t fGridDy
Definition: CbmMuchModuleGemRectangular.h:46
CbmMuchModuleGemRectangular
Definition: CbmMuchModuleGemRectangular.h:20
CbmMuchModuleGemRectangular::CbmMuchModuleGemRectangular
CbmMuchModuleGemRectangular()
Definition: CbmMuchModuleGemRectangular.cxx:23
CbmMuchSectorRectangular.h
CbmMuchModuleGemRectangular.h
CbmMuchModule::fSize
TVector3 fSize
Definition: CbmMuchModule.h:76
CbmMuchSector::GetSectorIndex
UInt_t GetSectorIndex() const
Definition: CbmMuchSector.h:28
CbmMuchSectorRectangular::Inside
Bool_t Inside(Double_t x, Double_t y)
Definition: CbmMuchSectorRectangular.h:50
CbmMuchModuleGemRectangular::InitNeighbourSectors
void InitNeighbourSectors()
Definition: CbmMuchModuleGemRectangular.cxx:166
CbmMuchModuleGemRectangular::GetPad
CbmMuchPadRectangular * GetPad(Double_t x, Double_t y)
Definition: CbmMuchModuleGemRectangular.cxx:102
CbmMuchModuleGemRectangular::GetGridIndexY
Int_t GetGridIndexY(Double_t y)
Definition: CbmMuchModuleGemRectangular.cxx:92
CbmMuchModuleGem
Definition: CbmMuchModuleGem.h:24
CbmMuchSectorRectangular
Definition: CbmMuchSectorRectangular.h:24
CbmMuchModule::fDetectorType
Int_t fDetectorType
Definition: CbmMuchModule.h:74
CbmMuchSector::GetPadByChannelIndex
CbmMuchPad * GetPadByChannelIndex(Int_t iChannel) const
Definition: CbmMuchSector.cxx:22
CbmMuchSectorRectangular::GetNeighbours
std::vector< CbmMuchSectorRectangular * > GetNeighbours()
Definition: CbmMuchSectorRectangular.h:55
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMuchModuleGemRectangular::GetSector
CbmMuchSectorRectangular * GetSector(Double_t x, Double_t y)
Definition: CbmMuchModuleGemRectangular.cxx:75
CbmMuchModuleGem::fSectors
std::vector< CbmMuchSector * > fSectors
Definition: CbmMuchModuleGem.h:79
CbmMuchPad
Definition: CbmMuchPad.h:21
CbmMuchPadRectangular.h
CbmMuchModuleGemRectangular::InitNeighbourPads
void InitNeighbourPads()
Definition: CbmMuchModuleGemRectangular.cxx:207
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmMuchSectorRectangular::AddPads
void AddPads()
Definition: CbmMuchSectorRectangular.cxx:57
CbmMuchModuleGemRectangular::fGridNx
Int_t fGridNx
Definition: CbmMuchModuleGemRectangular.h:43
CbmMuchPadRectangular
Definition: CbmMuchPadRectangular.h:21
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmMuchModuleGemRectangular::fUseModuleDesign
Bool_t fUseModuleDesign
Definition: CbmMuchModuleGemRectangular.h:42
CbmMuchSectorRectangular::IsIncomplete
Bool_t IsIncomplete()
Definition: CbmMuchSectorRectangular.h:53
CbmMuchPad::SetNeighbours
void SetNeighbours(std::vector< CbmMuchPad * > neighbours)
Definition: CbmMuchPad.h:39
CbmMuchModuleGemRectangular::fGridDx
Double_t fGridDx
Definition: CbmMuchModuleGemRectangular.h:45
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
CbmMuchModuleGem::GetNSectors
Int_t GetNSectors() const
Definition: CbmMuchModuleGem.h:57