48 std::map<Int_t, tuple<Double_t, Double_t>> localPixelCoord;
58 Int_t currentPixelAddress = 1;
59 Int_t currentPmtId = 1;
62 Double_t pmtHeight = 5.2;
63 Double_t pmtWidth = 5.2;
64 TGeoVolume* pmtVolume = gGeoManager->FindVolumeFast(
"pmt");
65 if (pmtVolume ==
nullptr) pmtVolume = gGeoManager->FindVolumeFast(
"pmt_vol_0");
66 if (pmtVolume !=
nullptr) {
67 const TGeoBBox*
shape = (
const TGeoBBox*) (pmtVolume->GetShape());
68 if (
shape !=
nullptr) {
69 pmtHeight = 2. *
shape->GetDY();
70 pmtWidth = 2. *
shape->GetDX();
74 TGeoIterator geoIterator(gGeoManager->GetTopNode()->GetVolume());
75 geoIterator.SetTopName(
"/cave_1");
78 TString pixelNameStr(
"pmt_pixel");
80 while ((curNode = geoIterator())) {
81 TString nodeName(curNode->GetName());
83 if (TString(curNode->GetVolume()->GetName()).Contains(pixelNameStr)) {
84 geoIterator.GetPath(nodePath);
91 const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
92 const Double_t* curNodeTr = curMatrix->GetTranslation();
93 const TGeoMatrix* localMatrix = curNode->GetMatrix();
94 string path = string(nodePath.Data());
96 size_t pmtInd = path.find_last_of(
"/");
97 if (string::npos == pmtInd)
continue;
98 string pmtPath = path.substr(0, pmtInd + 1);
102 pixelData->
fX = curNodeTr[0];
103 pixelData->
fY = curNodeTr[1];
104 pixelData->
fZ = curNodeTr[2];
105 pixelData->
fAddress = currentPixelAddress;
106 localPixelCoord[currentPixelAddress] =
107 make_tuple(localMatrix->GetTranslation()[0], localMatrix->GetTranslation()[1]);
110 currentPixelAddress++;
116 pmtData->
fId = currentPmtId;
119 pmtData->
fWidth = pmtWidth;
131 if (pmtData ==
nullptr || pmtId != pmtData->
fId) {
132 LOG(error) <<
"(pmtData == nullptr || pmtId != pmtData->fId) ";
137 LOG(info) <<
"size:" << pmtData->
fPixelAddresses.size() <<
" pmtData->fId:" << pmtData->
fId
138 <<
" pmtPath:" << pmtPath << endl
146 const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
147 const Double_t* curNodeTr = curMatrix->GetTranslation();
148 const TGeoMatrix* localMatrix = curNode->GetMatrix();
149 string path = string(nodePath.Data());
151 size_t pmtInd = path.find_last_of(
"/");
152 if (string::npos == pmtInd)
continue;
153 string pmtPath = path.substr(0, pmtInd + 1);
155 Int_t channel = std::stoul(path.substr(pmtInd + 11));
156 Int_t posAtPmt = channel / 100;
157 channel = channel % 100;
159 size_t pmtVolInd = path.rfind(
"/", pmtInd - 1);
160 if (string::npos == pmtVolInd)
continue;
161 Int_t pmtPosBP = std::stoul(path.substr(pmtVolInd + 11,
162 pmtInd - pmtVolInd - 11));
164 size_t bpInd = path.rfind(
"/", pmtVolInd - 1);
165 if (string::npos == bpInd)
continue;
166 Int_t posBP = std::stoul(path.substr(bpInd + 14,
167 pmtVolInd - bpInd - 14));
169 Int_t
x = (posBP / 10) + ((((pmtPosBP - 1) / 3) + 1) % 2);
170 Int_t
y = (posBP % 10) + (2 - ((pmtPosBP - 1) % 3));
172 Int_t DiRICH_Add = ((7 & 0xF) << 12) + ((
x & 0xF) << 8) + ((
y & 0xF) << 4) + (posAtPmt & 0xF);
173 Int_t pixelUID = ((DiRICH_Add << 16) | (channel & 0x00FF));
174 Int_t pmtUID = ((
x & 0xF) << 4) + (
y & 0xF);
179 pixelData->
fX = curNodeTr[0];
180 pixelData->
fY = curNodeTr[1];
181 pixelData->
fZ = curNodeTr[2];
183 localPixelCoord[pixelUID] = make_tuple(localMatrix->GetTranslation()[0], localMatrix->GetTranslation()[1]);
192 pmtData->
fId = pmtUID;
195 pmtData->
fWidth = pmtWidth;
205 if (pmtData ==
nullptr || pmtId != pmtData->
fId) {
206 LOG(error) <<
"(pmtData == nullptr || pmtId != pmtData->fId) ";
211 LOG(info) <<
"size:" << pmtData->
fPixelAddresses.size() <<
" pmtData->fId:" << pmtData->
fId
212 <<
" pmtPath:" << pmtPath << endl
219 default: LOG(error) <<
"ERROR: Could not identify Detector setup!";
break;
233 if (pixelData ==
nullptr)
continue;
234 pmtData->
fX += pixelData->
fX;
235 pmtData->
fY += pixelData->
fY;
236 pmtData->
fZ += pixelData->
fZ;
246 std::vector<tuple<CbmRichPixelData*, Double_t, Double_t>> pixelsInPmt;
249 if (pixelData ==
nullptr)
continue;
250 pixelsInPmt.push_back(
251 make_tuple(pixelData, get<0>(localPixelCoord[pixelAddress]), get<1>(localPixelCoord[pixelAddress])));
255 pixelsInPmt.begin(), pixelsInPmt.end(),
256 [](tuple<CbmRichPixelData*, Double_t, Double_t> a, tuple<CbmRichPixelData*, Double_t, Double_t> b) {
257 return (get<2>(a) > get<2>(b)) || ((abs(get<2>(a) - get<2>(b)) <= 0.3) && (get<1>(a) < get<1>(b)));
263 if (pixelsInPmt.size() != 64) {
264 LOG(error) <<
"ERROR: Calculating local pixel indices failed, number of pixels in PMT is not 64. "
267 for (
unsigned int i = 0; i < pixelsInPmt.size(); i++) {
268 get<0>(pixelsInPmt[i])->fPixelId = i;
272 localPixelCoord.clear();
274 LOG(info) <<
"CbmRichDigiMapManager is initialized";
328 vector<Int_t> neighbourPixels;
329 if (n == 0)
return neighbourPixels;
331 Int_t indX = addressPixelData->
fPixelId % 8;
332 Int_t indY = addressPixelData->
fPixelId / 8;
334 for (
auto const& iAddr : pmtPixelAddresses) {
335 if (iAddr == address)
continue;
337 Int_t iIndX = iPixelData->
fPixelId % 8;
338 Int_t iIndY = iPixelData->
fPixelId / 8;
339 if (horizontal && !vertical && !diagonal && n == 1) {
340 if (abs(iIndX - indX) == 1 && abs(iIndY - indY) == 0) neighbourPixels.push_back(iAddr);
342 else if (vertical && !horizontal && !diagonal && n == 1) {
343 if (abs(iIndX - indX) == 0 && abs(iIndY - indY) == 1) neighbourPixels.push_back(iAddr);
345 else if (!horizontal && !vertical && diagonal && n == 1) {
346 if ((abs(iIndX - indX) == 1) && (abs(iIndY - indY) == 1)) neighbourPixels.push_back(iAddr);
348 else if (horizontal && vertical && !diagonal && n == 1) {
349 if ((abs(iIndX - indX) + abs(iIndY - indY)) == 1) neighbourPixels.push_back(iAddr);
351 else if (horizontal && vertical && diagonal) {
352 if ((abs(iIndX - indX) <= n) && (abs(iIndY - indY) <= n)) neighbourPixels.push_back(iAddr);
355 LOG(error) <<
"ERROR: Unrecogniced option in CbmRichDigiMapManager::GetNeighbourPixels " << endl
356 <<
" n = " << n <<
" horizontal = " << horizontal <<
" vertical = " << vertical
357 <<
" diagonal = " << diagonal;
360 return neighbourPixels;