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