CbmRoot
Loading...
Searching...
No Matches
CbmClusteringGeometry.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2016 FIAS/JINR-LIT, Frankfurt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Grigory Kozlov [committer] */
4
5/*
6 * CbmClusteringGeometry.cxx
7 *
8 * Created on: Feb 22, 2012
9 * Author: kozlov
10 */
11
13
14#include "CbmMCTrack.h"
15#include "CbmMuchAddress.h"
16#include "CbmMuchDigi.h"
17#include "CbmMuchGeoScheme.h"
18#include "CbmMuchLayer.h"
19#include "CbmMuchLayerSide.h"
20#include "CbmMuchModuleGem.h"
22#include "CbmMuchPad.h"
23#include "CbmMuchPadRadial.h"
25#include "CbmMuchPixelHit.h"
26#include "CbmMuchPoint.h"
27#include "CbmMuchSectorRadial.h"
29#include "CbmMuchStation.h"
30#include "CbmStsHit.h"
31#include "CbmStsPoint.h"
32#include "FairRootManager.h"
33#include "TClonesArray.h"
34
35#include <cassert>
36#include <iostream>
37
38using std::cout;
39using std::endl;
40using std::vector;
41
43{
44 fNofPads = 0;
46}
47
48CbmClusteringGeometry::CbmClusteringGeometry(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule,
49 CbmMuchGeoScheme* scheme)
50{
51 SetMuchModuleGeometryRadialFast(nStation, nLayer, nSide, nModule, scheme);
52 // switch(geoVersion){
53 // case 1:
54 // {
55 // SetMuchModuleGeometryRectangular(nStation, nLayer, nSide, nModule, scheme); //For old rectangular geometry
56 // break;
57 // }
58 // case 2:
59 // {
60 // SetMuchModuleGeometryRadial(nStation, nLayer, nSide, nModule, scheme); //For new radial geometry
61 // break;
62 // }
63 // default:
64 // {
65 // std::cout<<"CbmClusteringGeometry: Error! Wrong detector geometry.\n";
66 // break;
67 // }
68 // }
69}
70
71//Addition of a single pad
72void CbmClusteringGeometry::CbmClusteringSetPad(Int_t nPad, Float_t x, Float_t y, Float_t dx, Float_t dy, Double_t phi1,
73 Double_t phi2, Float_t r1, Float_t r2, Int_t digiNum, UInt_t charge,
74 Long64_t chID)
75{
76 fPadList[nPad].fDigiNum = digiNum;
77 fPadList[nPad].fCharge = charge;
78 fPadList[nPad].fX = x;
79 fPadList[nPad].fY = y;
80 fPadList[nPad].fDx = dx;
81 fPadList[nPad].fDy = dy;
82 fPadList[nPad].fPhi1 = phi1;
83 fPadList[nPad].fPhi2 = phi2;
84 fPadList[nPad].fR1 = r1;
85 fPadList[nPad].fR2 = r2;
86 fPadList[nPad].channelID = chID;
87 fPadList[nPad].fNeighbors.clear();
88 fPadList[nPad].fNofNeighbors = 0;
90}
91
93
94/*void CbmClusteringGeometry::SetMuchModuleGeometryRectangular(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule, CbmMuchGeoScheme* scheme)
95{
96 CbmMuchModuleGem* module = (CbmMuchModuleGem*) scheme->GetModule(nStation, nLayer, nSide, nModule);
97 fNofPads = module->GetNPads();
98 fDetId = CbmMuchAddress::GetAddress(nStation, nLayer, nSide, nModule);
99 fPadList = new PadInformation[fNofPads];
100 fNofActivePads = 0;
101 Int_t nofSectors = module->GetNSectors();
102 Int_t padIterator = 0;
103 for(Int_t iSector = 0; iSector < nofSectors; iSector++)
104 {
105 CbmMuchSectorRectangular* sector = (CbmMuchSectorRectangular*) module->GetSector(iSector); //???
106 Int_t nofPadsInSector = sector->GetNChannels();//(sector->GetNCols())*(sector->GetNRows());
107 Int_t padNx = sector->GetPadNx();
108 Int_t padNy = sector->GetPadNy();
109 for(Int_t iPad = 0; iPad < nofPadsInSector; iPad++)
110 {
111 CbmMuchPadRectangular* pad = (CbmMuchPadRectangular*) sector->GetPadByChannelIndex(iPad); //!!!
112 fPadList[padIterator].fDigiNum = 0;
113 fPadList[padIterator].fCharge = 0;
114 fPadList[padIterator].fX = pad->GetX();
115 fPadList[padIterator].fY = pad->GetY();
116 fPadList[padIterator].fDx = sector->GetPadDx();
117 fPadList[padIterator].fDy = sector->GetPadDy();
118 fPadList[padIterator].fNeighbors.clear();
119 fPadList[padIterator].channelID = CbmMuchAddress::GetElementAddress(pad->GetAddress() ,kMuchChannel);
120 fPadByChannelId[CbmMuchAddress::GetElementAddress(pad->GetAddress() ,kMuchChannel)] = padIterator;
121 padIterator++;
122 }
123 }
124 padIterator = 0;
125 for(Int_t iPadMain = 0; iPadMain < fNofPads; iPadMain++)
126 {
127 //padIterator = 0;
128 //Int_t padIterator2 = 0;
129 fPadList[iPadMain].fNofNeighbors = 0;
130 fPadList[iPadMain].fNofGoodNeighbors = 0;
131 Float_t xLeft_1 = fPadList[iPadMain].fX - (fPadList[iPadMain].fDx / 2);
132 Float_t xRight_1 = fPadList[iPadMain].fX + (fPadList[iPadMain].fDx / 2);
133 Float_t yDown_1 = fPadList[iPadMain].fY - (fPadList[iPadMain].fDy / 2);
134 Float_t yUp_1 = fPadList[iPadMain].fY + (fPadList[iPadMain].fDy / 2);
135 for(Int_t iPadNeighbor = 0; iPadNeighbor < fNofPads; iPadNeighbor++)
136 {
137 if((fabs(fPadList[iPadMain].fX - fPadList[iPadNeighbor].fX) < (fPadList[iPadMain].fDx * 3)) &&
138 (fabs(fPadList[iPadMain].fY - fPadList[iPadNeighbor].fY) < (fPadList[iPadNeighbor].fDy * 3))){
139 Float_t xLeft_2 = fPadList[iPadNeighbor].fX - (fPadList[iPadNeighbor].fDx / 2);
140 Float_t xRight_2 = fPadList[iPadNeighbor].fX + (fPadList[iPadNeighbor].fDx / 2);
141 Float_t yDown_2 = fPadList[iPadNeighbor].fY - (fPadList[iPadNeighbor].fDy / 2);
142 Float_t yUp_2 = fPadList[iPadNeighbor].fY + (fPadList[iPadNeighbor].fDy / 2);
143 Float_t dX = fabs(xLeft_1 - xRight_1) * 0.1;
144 Float_t dY = fabs(yDown_1 - yUp_1) * 0.1;
145 if((((SubEqual(xLeft_1, xRight_2, dX) ||
146 SubEqual(xRight_1, xLeft_2, dX)) &&
147 (((GetMax(yDown_2, yUp_2) - dY) >
148 (GetMin(yDown_1, yUp_1) + dY)) &&
149 ((GetMin(yDown_2, yUp_2) + dY) <
150 (GetMax(yDown_1, yUp_1) - dY)))) ||
151 ((SubEqual(yDown_1, yUp_2, dY) ||
152 SubEqual(yUp_1, yDown_2, dY)) &&
153 (((GetMax(xLeft_2, xRight_2) - dX) >
154 (GetMin(xLeft_1, xRight_1) + dX)) &&
155 ((GetMin(xLeft_2, xRight_2) + dX) <
156 (GetMax(xLeft_1, xRight_1) - dX))))) &&
157 (iPadMain != iPadNeighbor))
158 {
159 fPadList[iPadMain].fNeighbors.push_back(iPadNeighbor);
160 fPadList[iPadMain].fNofGoodNeighbors++;
161 }
162 }}
163 }
164}*/
165
166void CbmClusteringGeometry::SetMuchModuleGeometryRadial(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule,
167 CbmMuchGeoScheme* scheme)
168{
169 CbmMuchModuleGemRadial* module = (CbmMuchModuleGemRadial*) scheme->GetModule(nStation, nLayer, nSide, nModule);
170 fNofPads = module->GetNPads();
171 fDetId = module->GetDetectorId();
173 fNofActivePads = 0;
174 Int_t nofSectors = module->GetNSectors();
175 Int_t padIterator = 0;
176 for (Int_t iSector = 0; iSector < nofSectors; iSector++) {
177 CbmMuchSectorRadial* sector = (CbmMuchSectorRadial*) module->GetSectorByIndex(iSector);
178 Int_t nofPadsInSector = sector->GetNChannels();
179 for (Int_t iPad = 0; iPad < nofPadsInSector; iPad++) {
181 fPadList[padIterator].fDigiNum = 0;
182 fPadList[padIterator].fCharge = 0;
183 fPadList[padIterator].fPhi1 = pad->GetPhi1();
184 fPadList[padIterator].fPhi2 = pad->GetPhi2();
185 fPadList[padIterator].fR1 = pad->GetR1();
186 fPadList[padIterator].fR2 = pad->GetR2();
187 Float_t r = (fPadList[padIterator].fR1 + fPadList[padIterator].fR2) / 2;
188 Double_t phi = (fPadList[padIterator].fPhi1 + fPadList[padIterator].fPhi2) / 2;
189 fPadList[padIterator].fX = r * cos(phi);
190 fPadList[padIterator].fY = r * sin(phi);
191 fPadList[padIterator].fNeighbors.clear();
193 fPadByChannelId[pad->GetAddress()] = padIterator;
194 fPadList[padIterator].nSector = iSector;
195 padIterator++;
196 }
197 }
198 padIterator = 0;
199 vector<UInt_t> diagonalNeighbors;
200 diagonalNeighbors.clear();
201 for (Int_t iPadMain = 0; iPadMain < fNofPads; iPadMain++) {
202 fPadList[iPadMain].fNofNeighbors = 0;
203 fPadList[iPadMain].fNofGoodNeighbors = 0;
204 Double_t Left_1 = GetMin(fPadList[iPadMain].fPhi1, fPadList[iPadMain].fPhi2);
205 Double_t Right_1 = GetMax(fPadList[iPadMain].fPhi1, fPadList[iPadMain].fPhi2);
206 Float_t Down_1 = GetMin(fPadList[iPadMain].fR1, fPadList[iPadMain].fR2);
207 Float_t Up_1 = GetMax(fPadList[iPadMain].fR1, fPadList[iPadMain].fR2);
208 Double_t dPhi = fabs(fPadList[iPadMain].fPhi1 - fPadList[iPadMain].fPhi2) * 0.1;
209 Float_t dR = fabs(fPadList[iPadMain].fR1 - fPadList[iPadMain].fR2) * 0.1;
210 Double_t lPhi = (Left_1 - Right_1) * 0.01;
211 Float_t lR = (Down_1 - Up_1) * 0.01;
212 for (Int_t iPadNeighbor = 0; iPadNeighbor < fNofPads; iPadNeighbor++) {
213 if (iPadMain == iPadNeighbor) continue;
214 Double_t Left_2 = GetMin(fPadList[iPadNeighbor].fPhi1, fPadList[iPadNeighbor].fPhi2);
215 Double_t Right_2 = GetMax(fPadList[iPadNeighbor].fPhi1, fPadList[iPadNeighbor].fPhi2);
216 Float_t Down_2 = GetMin(fPadList[iPadNeighbor].fR1, fPadList[iPadNeighbor].fR2);
217 Float_t Up_2 = GetMax(fPadList[iPadNeighbor].fR1, fPadList[iPadNeighbor].fR2);
218 if ((Left_1 == Right_2) || (Right_1 == Left_2)) {
219 if (((Down_1 - lR) < Up_2) && ((Up_1 + lR) > Down_2)) {
220 fPadList[iPadMain].fNeighbors.push_back(iPadNeighbor);
221 fPadList[iPadMain].fNofGoodNeighbors++;
222 }
223 }
224 if ((Up_1 == Down_2) || (Down_1 == Up_2)) {
225 if (((Left_1 - lPhi) < Right_2) && ((Right_1 + lPhi) > Left_2)) {
226 fPadList[iPadMain].fNeighbors.push_back(iPadNeighbor);
227 fPadList[iPadMain].fNofGoodNeighbors++;
228 }
229 }
230 fPadList[iPadMain].fNofNeighbors = fPadList[iPadMain].fNofGoodNeighbors;
231 if (((Left_1 == Right_2) && (Up_1 == Down_2)) || ((Left_1 == Right_2) && (Up_2 == Down_1))
232 || ((Left_2 == Right_1) && (Up_1 == Down_2)) || ((Left_2 == Right_1) && (Up_2 == Down_1))) {
233 diagonalNeighbors.push_back(iPadNeighbor);
234 }
235 }
236 for (Int_t iNeighbor = 0; iNeighbor < diagonalNeighbors.size(); iNeighbor++) {
237 fPadList[iPadMain].fNeighbors.push_back(diagonalNeighbors[iNeighbor]);
238 fPadList[iPadMain].fNofNeighbors++;
239 }
240 diagonalNeighbors.clear();
241 }
242}
243
244void CbmClusteringGeometry::SetMuchModuleGeometryRadialFast(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule,
245 CbmMuchGeoScheme* scheme)
246{
247 CbmMuchModuleGemRadial* module = (CbmMuchModuleGemRadial*) scheme->GetModule(nStation, nLayer, nSide, nModule);
248 fNofPads = module->GetNPads();
249 fDetId = module->GetDetectorId();
251 fNofActivePads = 0;
252 Int_t nofSectors = module->GetNSectors();
253 Int_t padIterator = 0;
254 for (Int_t iSector = 0; iSector < nofSectors; iSector++) {
255 CbmMuchSectorRadial* sector = (CbmMuchSectorRadial*) module->GetSectorByIndex(iSector);
256 Int_t nofPadsInSector = sector->GetNChannels();
257 for (Int_t iPad = 0; iPad < nofPadsInSector; iPad++) {
259 fPadList[padIterator].fDigiNum = 0;
260 fPadList[padIterator].fCharge = 0;
261 fPadList[padIterator].fPhi1 = pad->GetPhi1();
262 fPadList[padIterator].fPhi2 = pad->GetPhi2();
263 fPadList[padIterator].fR1 = pad->GetR1();
264 fPadList[padIterator].fR2 = pad->GetR2();
265 Float_t r = (fPadList[padIterator].fR1 + fPadList[padIterator].fR2) / 2;
266 Double_t phi = (fPadList[padIterator].fPhi1 + fPadList[padIterator].fPhi2) / 2;
267 fPadList[padIterator].fX = r * cos(phi);
268 fPadList[padIterator].fY = r * sin(phi);
269 fPadList[padIterator].fNeighbors.clear();
270 fPadList[padIterator].fNofNeighbors = 0;
271 fPadList[padIterator].fNofGoodNeighbors = 0;
273 fPadByChannelId[pad->GetAddress()] = padIterator;
274 fPadList[padIterator].nSector = iSector;
275 padIterator++;
276 }
277 }
278 padIterator = 0;
279 vector<UInt_t> diagonalNeighbors;
280 diagonalNeighbors.clear();
281 for (Int_t iSector = 0; iSector < nofSectors; iSector++) {
282 CbmMuchSectorRadial* sector = (CbmMuchSectorRadial*) module->GetSectorByIndex(iSector);
283 Int_t nofPadsInSector = sector->GetNChannels();
284 for (Int_t iPad = 0; iPad < nofPadsInSector; iPad++) {
285 Double_t dPhi = fabs(fPadList[iPad].fPhi1 - fPadList[iPad].fPhi2) * 0.1;
286 Float_t dR = fabs(fPadList[iPad].fR1 - fPadList[iPad].fR2) * 0.1;
288 vector<CbmMuchPad*> neighborsVector = pad->GetNeighbours();
289 for (Int_t iNeighbor = 0; iNeighbor < neighborsVector.size(); iNeighbor++) {
290 Int_t padNeighbor = fPadByChannelId[neighborsVector.at(iNeighbor)->GetAddress()];
291 if ((SubEqual(fPadList[padIterator].fPhi1, fPadList[padNeighbor].fPhi2, dPhi)
292 && SubEqual(fPadList[padIterator].fR1, fPadList[padNeighbor].fR2, dR))
293 || (SubEqual(fPadList[padIterator].fPhi1, fPadList[padNeighbor].fPhi2, dPhi)
294 && SubEqual(fPadList[padIterator].fR2, fPadList[padNeighbor].fR1, dR))
295 || (SubEqual(fPadList[padIterator].fPhi2, fPadList[padNeighbor].fPhi1, dPhi)
296 && SubEqual(fPadList[padIterator].fR1, fPadList[padNeighbor].fR2, dR))
297 || (SubEqual(fPadList[padIterator].fPhi2, fPadList[padNeighbor].fPhi1, dPhi)
298 && SubEqual(fPadList[padIterator].fR2, fPadList[padNeighbor].fR1, dR))) {
299 diagonalNeighbors.push_back(padNeighbor);
300 }
301 else {
302 fPadList[padIterator].fNeighbors.push_back(padNeighbor);
303 fPadList[padIterator].fNofGoodNeighbors++;
304 fPadList[padIterator].fNofNeighbors++;
305 }
306 }
307 for (Int_t iNeighbor = 0; iNeighbor < diagonalNeighbors.size(); iNeighbor++) {
308 fPadList[padIterator].fNeighbors.push_back(diagonalNeighbors.at(iNeighbor));
309 fPadList[padIterator].fNofNeighbors++;
310 }
311 diagonalNeighbors.clear();
312 padIterator++;
313 }
314 }
315}
316
317Float_t CbmClusteringGeometry::GetX0(Int_t iPad) { return fPadList[iPad].fX; }
318
319Float_t CbmClusteringGeometry::GetDx(Int_t iPad) { return fPadList[iPad].fDx; }
320
321Float_t CbmClusteringGeometry::GetDy(Int_t iPad) { return fPadList[iPad].fDy; }
322
323Float_t CbmClusteringGeometry::GetY0(Int_t iPad) { return fPadList[iPad].fY; }
324
325Int_t CbmClusteringGeometry::GetDigiNum(Int_t iPad) { return fPadList[iPad].fDigiNum; }
326
327void CbmClusteringGeometry::SetDigiNum(Int_t iPad, Int_t iDigi) { fPadList[iPad].fDigiNum = iDigi; }
328
330
332
333Int_t CbmClusteringGeometry::GetNeighbor(Int_t iPad, Int_t iNeighbor) { return fPadList[iPad].fNeighbors[iNeighbor]; }
334
335Long64_t CbmClusteringGeometry::GetPadID(Int_t iPad) { return fPadList[iPad].channelID; }
336
337UInt_t CbmClusteringGeometry::GetPadCharge(Int_t iPad) { return fPadList[iPad].fCharge; }
338
339void CbmClusteringGeometry::SetPadCharge(Int_t iPad, UInt_t iCharge) { fPadList[iPad].fCharge = iCharge; }
340
342
344
345template<typename T1>
347{
348 if (a > b) {
349 return b;
350 }
351 else {
352 return a;
353 }
354}
355
356template<typename T2>
358{
359 if (a < b) {
360 return b;
361 }
362 else {
363 return a;
364 }
365}
366
367Bool_t CbmClusteringGeometry::SubEqual(Double_t x1, Double_t x2, Double_t l)
368{
369 //l = l * 0.1;
370 if ((x1 < (x2 + l)) && (x1 > (x2 - l))) {
371 return 1;
372 }
373 else {
374 return 0;
375 }
376}
377
378Int_t CbmClusteringGeometry::GetPadByChannelId(Long64_t chId) { return fPadByChannelId[chId]; }
379
380Double_t CbmClusteringGeometry::GetPhi1(Int_t iPad) { return fPadList[iPad].fPhi1; }
381
382Double_t CbmClusteringGeometry::GetPhi2(Int_t iPad) { return fPadList[iPad].fPhi2; }
383
384Float_t CbmClusteringGeometry::GetR1(Int_t iPad) { return fPadList[iPad].fR1; }
385
386Float_t CbmClusteringGeometry::GetR2(Int_t iPad) { return fPadList[iPad].fR2; }
387
388vector<Int_t> CbmClusteringGeometry::GetNeighbors(Int_t iPad) { return fPadList[iPad].fNeighbors; }
389
390Long64_t CbmClusteringGeometry::GetChannelID(Int_t iPad) { return fPadList[iPad].channelID; }
@ kMuchChannel
Channel.
Class for pixel hits in MUCH detector.
Data class for a reconstructed hit in the STS.
friend fvec cos(const fvec &a)
friend fvec sin(const fvec &a)
void CbmClusteringSetPad(Int_t nPad, Float_t x, Float_t y, Float_t dx, Float_t dy, Double_t phi1, Double_t phi2, Float_t r1, Float_t r2, Int_t digiNum, UInt_t charge, Long64_t chID)
Long64_t GetChannelID(Int_t iPad)
Int_t GetPadByChannelId(Long64_t chId)
void SetDigiNum(Int_t iPad, Int_t iDigi)
std::map< Long64_t, Int_t > fPadByChannelId
void SetPadCharge(Int_t iPad, UInt_t iCharge)
Int_t GetGoodNeighborsNum(Int_t iPad)
Bool_t SubEqual(Double_t x1, Double_t x2, Double_t l)
void SetMuchModuleGeometryRadial(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule, CbmMuchGeoScheme *scheme)
void SetMuchModuleGeometryRadialFast(Int_t nStation, Int_t nLayer, Bool_t nSide, Int_t nModule, CbmMuchGeoScheme *scheme)
std::vector< Int_t > GetNeighbors(Int_t iPad)
Int_t GetNeighbor(Int_t iPad, Int_t iNeighbor)
Long64_t GetPadID(Int_t iPad)
static int32_t GetElementAddress(int32_t address, int32_t level)
CbmMuchModule * GetModule(Int_t iStation, Int_t iLayer, Bool_t iSide, Int_t iModule) const
CbmMuchSector * GetSectorByIndex(Int_t iSector)
Double_t GetPhi2() const
Double_t GetPhi1() const
std::vector< CbmMuchPad * > GetNeighbours() const
Definition CbmMuchPad.h:42
Int_t GetAddress() const
Definition CbmMuchPad.h:31
Int_t GetNChannels() const
CbmMuchPad * GetPadByChannelIndex(Int_t iChannel) const