CbmRoot
Loading...
Searching...
No Matches
CbmRichMCbmDigiMapManager.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Adrian Amatus Weber [committer], Florian Uhlig */
4
5/*
6 * CbmRichMCbmDigiMapManager.cxx
7 *
8 * Created on: Jul 11, 2019
9 * Author: aweber
10 */
12
13#include "CbmRichDetectorData.h" // for CbmRichPmtData, CbmRichPixelData
14
15#include <Logger.h> // for LOG, Logger
16
17#include <TGeoBBox.h> // for TGeoBBox
18#include <TGeoManager.h> // for TGeoManager, gGeoManager
19#include <TGeoMatrix.h> // for TGeoMatrix
20#include <TGeoNode.h> // for TGeoIterator, TGeoNode
21#include <TGeoVolume.h> // for TGeoVolume
22#include <TRandom.h> // for TRandom, gRandom
23#include <TString.h> // for TString
24
25#include <iostream> // for string, operator<<, basic_ostream
26#include <string> // for operator<, stoul
27#include <utility> // for pair
28
29#include <stddef.h> // for size_t
30
31using namespace std;
32
34 : fPixelPathToAddressMap()
35 , fPixelAddressToDataMap()
36 , fPixelAddresses()
37 , fPmtPathToIdMap()
38 , fPmtIdToDataMap()
39 , fPmtIds()
40{
41 Init();
42}
43
45
47{
48
51 fPixelAddresses.clear();
52
53 fPmtPathToIdMap.clear();
54 fPmtIdToDataMap.clear();
55 fPmtIds.clear();
56
57
58 // Get MAPMT dimensions
59 Double_t pmtHeight = 5.2;
60 Double_t pmtWidth = 5.2;
61 TGeoVolume* pmtVolume = gGeoManager->FindVolumeFast("pmt"); // check for RICH
62 if (pmtVolume == nullptr) pmtVolume = gGeoManager->FindVolumeFast("pmt_vol_0"); // check for mRICH // or pmt_vol_1
63 if (pmtVolume != nullptr) {
64 const TGeoBBox* shape = (const TGeoBBox*) (pmtVolume->GetShape());
65 if (shape != nullptr) {
66 pmtHeight = 2. * shape->GetDY();
67 pmtWidth = 2. * shape->GetDX();
68 }
69 }
70
71 TGeoIterator geoIterator(gGeoManager->GetTopNode()->GetVolume());
72 geoIterator.SetTopName("/cave_1");
73 TGeoNode* curNode;
74 // PMT plane position\rotation
75 TString pixelNameStr("pmt_pixel");
76 geoIterator.Reset();
77 while ((curNode = geoIterator())) {
78 TString nodeName(curNode->GetName());
79 TString nodePath;
80 if (TString(curNode->GetVolume()->GetName()).Contains(pixelNameStr)) {
81 geoIterator.GetPath(nodePath);
82 const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
83 const Double_t* curNodeTr = curMatrix->GetTranslation();
84 string path = string(nodePath.Data());
85
86 size_t pmtInd = path.find_last_of("/");
87 if (string::npos == pmtInd) continue;
88 string pmtPath = path.substr(0, pmtInd + 1);
89
90 Int_t channel = std::stoul(path.substr(pmtInd + 11)); // cut away "pmt_pixel_"
91 Int_t posAtPmt = channel / 100;
92 channel = channel % 100;
93
94 size_t pmtVolInd = path.rfind("/", pmtInd - 1);
95 if (string::npos == pmtVolInd) continue;
96 Int_t pmtPosBP = std::stoul(path.substr(pmtVolInd + 11,
97 pmtInd - pmtVolInd - 11)); // cut away "/pmt_vol_*_" ; position on BP
98
99 size_t bpInd = path.rfind("/", pmtVolInd - 1);
100 if (string::npos == bpInd) continue;
101 Int_t posBP = std::stoul(path.substr(bpInd + 14,
102 pmtVolInd - bpInd - 14)); // cut away "/pmt_vol_*_" ; position on BP
103
104 Int_t x = (posBP / 10) + ((((pmtPosBP - 1) / 3) + 1) % 2);
105 Int_t y = (posBP % 10) + (2 - ((pmtPosBP - 1) % 3));
106
107 Int_t DiRICH_Add = ((7 & 0xF) << 12) + ((x & 0xF) << 8) + ((y & 0xF) << 4) + (posAtPmt & 0xF);
108 Int_t pixelUID = ((DiRICH_Add << 16) | (channel & 0x00FF));
109 Int_t pmtUID = ((x & 0xF) << 4) + (y & 0xF);
110 //std::cout<<"Addr: 0x"<< std::hex << DiRICH_Add << std::dec << "\t" << channel <<"\t"<< std::hex << pixelUID << std::dec << std::endl;
111
112 fPixelPathToAddressMap.insert(pair<string, Int_t>(path, pixelUID));
113 CbmRichPixelData* pixelData = new CbmRichPixelData();
114 pixelData->fX = curNodeTr[0];
115 pixelData->fY = curNodeTr[1];
116 pixelData->fZ = curNodeTr[2];
117 pixelData->fAddress = pixelUID;
118 fPixelAddressToDataMap.insert(pair<Int_t, CbmRichPixelData*>(pixelData->fAddress, pixelData));
119 fPixelAddresses.push_back(pixelUID);
120 //currentPixelAddress++;
121
122 if (fPmtPathToIdMap.count(pmtPath) == 0) {
123 fPmtPathToIdMap.insert(pair<string, Int_t>(pmtPath, pmtUID));
124
125 CbmRichPmtData* pmtData = new CbmRichPmtData();
126 pmtData->fId = pmtUID;
127 pmtData->fPixelAddresses.push_back(pixelData->fAddress);
128 pmtData->fHeight = pmtHeight;
129 pmtData->fWidth = pmtWidth;
130 fPmtIdToDataMap.insert(pair<Int_t, CbmRichPmtData*>(pmtData->fId, pmtData));
131 pixelData->fPmtId = pmtData->fId;
132
133 fPmtIds.push_back(pmtData->fId);
134 }
135 else {
136 //cout << "pmtPath old:" << pmtPath << endl;
137 Int_t pmtId = fPmtPathToIdMap[pmtPath];
138 CbmRichPmtData* pmtData = fPmtIdToDataMap[pmtId];
139 if (pmtData == nullptr || pmtId != pmtData->fId) {
140 LOG(error) << "(pmtData == nullptr || pmtId != pmtData->fId) ";
141 }
142 pmtData->fPixelAddresses.push_back(pixelData->fAddress);
143 pixelData->fPmtId = pmtData->fId;
144 if (pmtData->fPixelAddresses.size() > 64) {
145 LOG(info) << "size:" << pmtData->fPixelAddresses.size() << " pmtData->fId:" << pmtData->fId
146 << " pmtPath:" << pmtPath << endl
147 << " path:" << path;
148 }
149 }
150 }
151 }
152
153 // calculate Pmt center as center of gravity of 64 pixels
154 for (auto const& pmt : fPmtIdToDataMap) {
155 // Int_t pmtId = pmt.first;
156 CbmRichPmtData* pmtData = pmt.second;
157 pmtData->fX = 0.;
158 pmtData->fY = 0.;
159 pmtData->fZ = 0.;
160 for (int pixelId : pmtData->fPixelAddresses) {
161 CbmRichPixelData* pixelData = fPixelAddressToDataMap[pixelId];
162 if (pixelData == nullptr) continue;
163 pmtData->fX += pixelData->fX;
164 pmtData->fY += pixelData->fY;
165 pmtData->fZ += pixelData->fZ;
166 }
167 pmtData->fX /= pmtData->fPixelAddresses.size();
168 pmtData->fY /= pmtData->fPixelAddresses.size();
169 pmtData->fZ /= pmtData->fPixelAddresses.size();
170 }
171
172 LOG(info) << "CbmRichMCbmDigiMapManager is initialized";
173 LOG(info) << "fPixelPathToAddressMap.size() = " << fPixelPathToAddressMap.size();
174 LOG(info) << "fPixelAddressToDataMap.size() = " << fPixelAddressToDataMap.size();
175
176 LOG(info) << "fPmtPathToIdMap.size() = " << fPmtPathToIdMap.size();
177 LOG(info) << "fPmtIdToDataMap.size() = " << fPmtIdToDataMap.size();
178
179 // for (auto const& pmt : fPmtIdToDataMap) {
180 // // cout << pmt.first << endl;
181 // cout << pmt.second->ToString() << endl;
182 // }
183}
184
186{
187 std::map<string, Int_t>::iterator it;
188 it = fPixelPathToAddressMap.find(path);
189 if (it == fPixelPathToAddressMap.end()) return -1;
190 return it->second;
191}
192
193
195{
196 std::map<Int_t, CbmRichPixelData*>::iterator it;
197 it = fPixelAddressToDataMap.find(address);
198 if (it == fPixelAddressToDataMap.end()) return nullptr;
199 return it->second;
200}
201
203{
204 Int_t nofPixels = fPixelAddresses.size();
205 Int_t index = gRandom->Integer(nofPixels);
206 return fPixelAddresses[index];
207}
208
210
211
213
214
216{
217 std::map<Int_t, CbmRichPmtData*>::iterator it;
218 it = fPmtIdToDataMap.find(id);
219 if (it == fPmtIdToDataMap.end()) return nullptr;
220 return it->second;
221}
222
224{
225 std::vector<Int_t> v;
226
227 return v;
228}
229
231{
232 std::vector<Int_t> v;
233
234 return v;
235}
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Int_t GetPixelAddressByPath(const std::string &path)
std::map< Int_t, CbmRichPixelData * > fPixelAddressToDataMap
std::map< Int_t, CbmRichPmtData * > fPmtIdToDataMap
std::map< std::string, Int_t > fPmtPathToIdMap
std::map< std::string, Int_t > fPixelPathToAddressMap
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
std::vector< Int_t > GetDiagonalNeighbourPixels(Int_t address)
CbmRichPmtData * GetPmtDataById(Int_t id)
std::vector< Int_t > GetDirectNeighbourPixels(Int_t address)
std::vector< Int_t > fPixelAddresses
Hash for CbmL1LinkKey.