CbmRoot
CbmRichDigiMapManager.cxx
Go to the documentation of this file.
1 /*
2  * CbmRichDigiMapManager.cxx
3  *
4  * Created on: Dec 17, 2015
5  * Author: slebedev
6  */
8 
9 #include "CbmRichDetectorData.h" // for CbmRichPmtData, CbmRichPixelData
10 
11 #include <FairLogger.h> // for LOG, Logger
12 
13 #include <TGeoBBox.h> // for TGeoBBox
14 #include <TGeoManager.h> // for TGeoManager, gGeoManager
15 #include <TGeoMatrix.h> // for TGeoMatrix
16 #include <TGeoNode.h> // for TGeoIterator, TGeoNode
17 #include <TGeoVolume.h> // for TGeoVolume
18 #include <TRandom.h> // for TRandom, gRandom
19 
20 
21 #include <stddef.h> // for size_t
22 #include <string> // for operator<, stoul
23 #include <utility> // for pair
24 
25 using namespace std;
26 
28  : fPixelPathToAddressMap()
29  , fPixelAddressToDataMap()
30  , fPixelAddresses()
31  , fPmtPathToIdMap()
32  , fPmtIdToDataMap()
33  , fPmtIds() {
34  Init();
35 }
36 
38 
40 
41  fPixelPathToAddressMap.clear();
42  fPixelAddressToDataMap.clear();
43  fPixelAddresses.clear();
44 
45  fPmtPathToIdMap.clear();
46  fPmtIdToDataMap.clear();
47  fPmtIds.clear();
48 
49  Int_t currentPixelAddress = 1;
50  Int_t currentPmtId = 1;
51 
52  // Get MAPMT dimensions
53  Double_t pmtHeight = 5.2;
54  Double_t pmtWidth = 5.2;
55  TGeoVolume* pmtVolume = gGeoManager->FindVolumeFast("pmt");
56  if (pmtVolume == nullptr)
57  pmtVolume = gGeoManager->FindVolumeFast("pmt_vol_0");
58  if (pmtVolume != nullptr) {
59  const TGeoBBox* shape = (const TGeoBBox*) (pmtVolume->GetShape());
60  if (shape != nullptr) {
61  pmtHeight = 2. * shape->GetDY();
62  pmtWidth = 2. * shape->GetDX();
63  }
64  }
65 
66  TGeoIterator geoIterator(gGeoManager->GetTopNode()->GetVolume());
67  geoIterator.SetTopName("/cave_1");
68  TGeoNode* curNode;
69  // PMT plane position\rotation
70  TString pixelNameStr("pmt_pixel");
71  geoIterator.Reset();
72  while ((curNode = geoIterator())) {
73  TString nodeName(curNode->GetName());
74  TString nodePath;
75  if (TString(curNode->GetVolume()->GetName()).Contains(pixelNameStr)) {
76  geoIterator.GetPath(nodePath);
77 
78  int detSetup = getDetectorSetup(nodePath);
79  switch (detSetup) {
80  case 0: {
81  // RICH detector
82  //std::cout<<"RICH"<<std::endl;
83  const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
84  const Double_t* curNodeTr = curMatrix->GetTranslation();
85  string path = string(nodePath.Data());
86 
87  size_t pmtInd = path.find_last_of("/");
88  if (string::npos == pmtInd) continue;
89  string pmtPath = path.substr(0, pmtInd + 1);
90 
92  pair<string, Int_t>(path, currentPixelAddress));
93  CbmRichPixelData* pixelData = new CbmRichPixelData();
94  pixelData->fX = curNodeTr[0];
95  pixelData->fY = curNodeTr[1];
96  pixelData->fZ = curNodeTr[2];
97  pixelData->fAddress = currentPixelAddress;
99  pair<Int_t, CbmRichPixelData*>(pixelData->fAddress, pixelData));
100  fPixelAddresses.push_back(currentPixelAddress);
101  currentPixelAddress++;
102 
103  if (fPmtPathToIdMap.count(pmtPath) == 0) {
104  fPmtPathToIdMap.insert(pair<string, Int_t>(pmtPath, currentPmtId));
105 
106  CbmRichPmtData* pmtData = new CbmRichPmtData();
107  pmtData->fId = currentPmtId;
108  pmtData->fPixelAddresses.push_back(pixelData->fAddress);
109  pmtData->fHeight = pmtHeight;
110  pmtData->fWidth = pmtWidth;
111  fPmtIdToDataMap.insert(
112  pair<Int_t, CbmRichPmtData*>(pmtData->fId, pmtData));
113  pixelData->fPmtId = pmtData->fId;
114 
115  fPmtIds.push_back(pmtData->fId);
116 
117  currentPmtId++;
118  } else {
119  //cout << "pmtPath old:" << pmtPath << endl;
120  Int_t pmtId = fPmtPathToIdMap[pmtPath];
121  CbmRichPmtData* pmtData = fPmtIdToDataMap[pmtId];
122  if (pmtData == nullptr || pmtId != pmtData->fId) {
123  LOG(error) << "(pmtData == nullptr || pmtId != pmtData->fId) ";
124  }
125  pmtData->fPixelAddresses.push_back(pixelData->fAddress);
126  pixelData->fPmtId = pmtData->fId;
127  if (pmtData->fPixelAddresses.size() > 64) {
128  LOG(info) << "size:" << pmtData->fPixelAddresses.size()
129  << " pmtData->fId:" << pmtData->fId
130  << " pmtPath:" << pmtPath << endl
131  << " path:" << path;
132  }
133  }
134  } break;
135 
136  case 1: {
137  //std::cout<<"mRICH"<<std::endl;
138  const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
139  const Double_t* curNodeTr = curMatrix->GetTranslation();
140  string path = string(nodePath.Data());
141 
142  size_t pmtInd = path.find_last_of("/");
143  if (string::npos == pmtInd) continue;
144  string pmtPath = path.substr(0, pmtInd + 1);
145 
146  Int_t channel =
147  std::stoul(path.substr(pmtInd + 11)); // cut away "pmt_pixel_"
148  Int_t posAtPmt = channel / 100;
149  channel = channel % 100;
150 
151  size_t pmtVolInd = path.rfind("/", pmtInd - 1);
152  if (string::npos == pmtVolInd) continue;
153  Int_t pmtPosBP = std::stoul(
154  path.substr(pmtVolInd + 11,
155  pmtInd - pmtVolInd
156  - 11)); // cut away "/pmt_vol_*_" ; position on BP
157 
158  size_t bpInd = path.rfind("/", pmtVolInd - 1);
159  if (string::npos == bpInd) continue;
160  Int_t posBP = std::stoul(
161  path.substr(bpInd + 14,
162  pmtVolInd - bpInd
163  - 14)); // cut away "/pmt_vol_*_" ; position on BP
164 
165  Int_t x = (posBP / 10) + ((((pmtPosBP - 1) / 3) + 1) % 2);
166  Int_t y = (posBP % 10) + (2 - ((pmtPosBP - 1) % 3));
167 
168  Int_t DiRICH_Add = ((7 & 0xF) << 12) + ((x & 0xF) << 8)
169  + ((y & 0xF) << 4) + (posAtPmt & 0xF);
170  Int_t pixelUID = ((DiRICH_Add << 16) | (channel & 0x00FF));
171  Int_t pmtUID = ((x & 0xF) << 4) + (y & 0xF);
172  //std::cout<<"Addr: 0x"<< std::hex << DiRICH_Add << std::dec << "\t" << channel <<"\t"<< std::hex << pixelUID << std::dec << std::endl;
173 
174  fPixelPathToAddressMap.insert(pair<string, Int_t>(path, pixelUID));
175  CbmRichPixelData* pixelData = new CbmRichPixelData();
176  pixelData->fX = curNodeTr[0];
177  pixelData->fY = curNodeTr[1];
178  pixelData->fZ = curNodeTr[2];
179  pixelData->fAddress = pixelUID;
180  fPixelAddressToDataMap.insert(
181  pair<Int_t, CbmRichPixelData*>(pixelData->fAddress, pixelData));
182  fPixelAddresses.push_back(pixelUID);
183  //currentPixelAddress++;
184 
185  if (fPmtPathToIdMap.count(pmtPath) == 0) {
186  fPmtPathToIdMap.insert(pair<string, Int_t>(pmtPath, pmtUID));
187 
188  CbmRichPmtData* pmtData = new CbmRichPmtData();
189  pmtData->fId = pmtUID;
190  pmtData->fPixelAddresses.push_back(pixelData->fAddress);
191  pmtData->fHeight = pmtHeight;
192  pmtData->fWidth = pmtWidth;
193  fPmtIdToDataMap.insert(
194  pair<Int_t, CbmRichPmtData*>(pmtData->fId, pmtData));
195  pixelData->fPmtId = pmtData->fId;
196 
197  fPmtIds.push_back(pmtData->fId);
198 
199  } else {
200  //cout << "pmtPath old:" << pmtPath << endl;
201  Int_t pmtId = fPmtPathToIdMap[pmtPath];
202  CbmRichPmtData* pmtData = fPmtIdToDataMap[pmtId];
203  if (pmtData == nullptr || pmtId != pmtData->fId) {
204  LOG(error) << "(pmtData == nullptr || pmtId != pmtData->fId) ";
205  }
206  pmtData->fPixelAddresses.push_back(pixelData->fAddress);
207  pixelData->fPmtId = pmtData->fId;
208  if (pmtData->fPixelAddresses.size() > 64) {
209  LOG(info) << "size:" << pmtData->fPixelAddresses.size()
210  << " pmtData->fId:" << pmtData->fId
211  << " pmtPath:" << pmtPath << endl
212  << " path:" << path;
213  }
214  }
215 
216  } break;
217 
218  default:
219  LOG(error) << "ERROR: Could not identify Detector setup!";
220  break;
221  }
222  }
223  }
224 
225  // calculate Pmt center as center of gravity of 64 pixels
226  for (auto const& pmt : fPmtIdToDataMap) {
227  // Int_t pmtId = pmt.first;
228  CbmRichPmtData* pmtData = pmt.second;
229  pmtData->fX = 0.;
230  pmtData->fY = 0.;
231  pmtData->fZ = 0.;
232  for (int pixelId : pmtData->fPixelAddresses) {
233  CbmRichPixelData* pixelData = fPixelAddressToDataMap[pixelId];
234  if (pixelData == nullptr) continue;
235  pmtData->fX += pixelData->fX;
236  pmtData->fY += pixelData->fY;
237  pmtData->fZ += pixelData->fZ;
238  }
239  pmtData->fX /= pmtData->fPixelAddresses.size();
240  pmtData->fY /= pmtData->fPixelAddresses.size();
241  pmtData->fZ /= pmtData->fPixelAddresses.size();
242  }
243 
244  LOG(info) << "CbmRichDigiMapManager is initialized";
245  LOG(info) << "fPixelPathToAddressMap.size() = "
246  << fPixelPathToAddressMap.size();
247  LOG(info) << "fPixelAddressToDataMap.size() = "
248  << fPixelAddressToDataMap.size();
249 
250  LOG(info) << "fPmtPathToIdMap.size() = " << fPmtPathToIdMap.size();
251  LOG(info) << "fPmtIdToDataMap.size() = " << fPmtIdToDataMap.size();
252 
253  // for (auto const& pmt : fPmtIdToDataMap) {
254  // // cout << pmt.first << endl;
255  // cout << pmt.second->ToString() << endl;
256  // }
257 }
258 
260  std::map<string, Int_t>::iterator it;
261  it = fPixelPathToAddressMap.find(path);
262  if (it == fPixelPathToAddressMap.end()) return -1;
263  return it->second;
264 }
265 
266 
268  std::map<Int_t, CbmRichPixelData*>::iterator it;
269  it = fPixelAddressToDataMap.find(address);
270  if (it == fPixelAddressToDataMap.end()) return nullptr;
271  return it->second;
272 }
273 
275  Int_t nofPixels = fPixelAddresses.size();
276  Int_t index = gRandom->Integer(nofPixels);
277  return fPixelAddresses[index];
278 }
279 
281  return fPixelAddresses;
282 }
283 
284 
285 vector<Int_t> CbmRichDigiMapManager::GetPmtIds() { return fPmtIds; }
286 
287 
289  std::map<Int_t, CbmRichPmtData*>::iterator it;
290  it = fPmtIdToDataMap.find(id);
291  if (it == fPmtIdToDataMap.end()) return nullptr;
292  return it->second;
293 }
294 
295 vector<Int_t>
297  std::vector<Int_t> v;
298 
299  return v;
300 }
301 
302 vector<Int_t>
304  std::vector<Int_t> v;
305 
306  return v;
307 }
308 
309 int CbmRichDigiMapManager::getDetectorSetup(TString const nodePath) {
310  //identify Detector by nodePath:
311  // 0: RICH
312  // 1: mRICH
313  bool check = nodePath.Contains("mcbm");
314  if (check) {
315  //mRICH
316  return 1;
317  } else {
318  //RICH
319  return 0;
320  }
321 
322  return 0;
323 }
CbmRichPixelData
Definition: CbmRichDetectorData.h:17
CbmRichPmtData::fY
Double_t fY
Definition: CbmRichDetectorData.h:42
CbmRichDigiMapManager::GetPmtIds
std::vector< Int_t > GetPmtIds()
Definition: CbmRichDigiMapManager.cxx:285
CbmRichDigiMapManager::GetPixelAddresses
std::vector< Int_t > GetPixelAddresses()
Definition: CbmRichDigiMapManager.cxx:280
CbmRichDigiMapManager::~CbmRichDigiMapManager
virtual ~CbmRichDigiMapManager()
Definition: CbmRichDigiMapManager.cxx:37
CbmRichDigiMapManager::getDetectorSetup
int getDetectorSetup(TString const nodePath)
Definition: CbmRichDigiMapManager.cxx:309
CbmRichDigiMapManager::fPixelPathToAddressMap
std::map< std::string, Int_t > fPixelPathToAddressMap
Definition: CbmRichDigiMapManager.h:81
CbmRichDigiMapManager::GetPmtDataById
CbmRichPmtData * GetPmtDataById(Int_t id)
Definition: CbmRichDigiMapManager.cxx:288
CbmRichDigiMapManager.h
CbmRichDigiMapManager::fPmtPathToIdMap
std::map< std::string, Int_t > fPmtPathToIdMap
Definition: CbmRichDigiMapManager.h:85
CbmRichPmtData::fZ
Double_t fZ
Definition: CbmRichDetectorData.h:43
CbmRichDigiMapManager::fPmtIds
std::vector< Int_t > fPmtIds
Definition: CbmRichDigiMapManager.h:87
CbmRichDigiMapManager::fPixelAddresses
std::vector< Int_t > fPixelAddresses
Definition: CbmRichDigiMapManager.h:83
CbmRichDigiMapManager::fPixelAddressToDataMap
std::map< Int_t, CbmRichPixelData * > fPixelAddressToDataMap
Definition: CbmRichDigiMapManager.h:82
CbmRichPmtData
Definition: CbmRichDetectorData.h:26
CbmRichDigiMapManager::GetDirectNeighbourPixels
std::vector< Int_t > GetDirectNeighbourPixels(Int_t address)
Definition: CbmRichDigiMapManager.cxx:296
CbmRichPixelData::fPmtId
Int_t fPmtId
Definition: CbmRichDetectorData.h:23
CbmRichDigiMapManager::Init
void Init()
Definition: CbmRichDigiMapManager.cxx:39
CbmRichDetectorData.h
CbmRichPixelData::fY
Double_t fY
Definition: CbmRichDetectorData.h:21
CbmRichPixelData::fAddress
Int_t fAddress
Definition: CbmRichDetectorData.h:19
CbmRichPixelData::fX
Double_t fX
Definition: CbmRichDetectorData.h:20
CbmRichPmtData::fX
Double_t fX
Definition: CbmRichDetectorData.h:41
CbmRichPmtData::fId
Int_t fId
Definition: CbmRichDetectorData.h:39
CbmRichDigiMapManager::GetDiagonalNeighbourPixels
std::vector< Int_t > GetDiagonalNeighbourPixels(Int_t address)
Definition: CbmRichDigiMapManager.cxx:303
CbmRichDigiMapManager::GetPixelAddressByPath
Int_t GetPixelAddressByPath(const std::string &path)
Definition: CbmRichDigiMapManager.cxx:259
shape
UInt_t shape
Definition: CbmMvdSensorDigiToHitTask.cxx:73
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
CbmRichDigiMapManager::GetRandomPixelAddress
Int_t GetRandomPixelAddress()
Definition: CbmRichDigiMapManager.cxx:274
CbmRichPmtData::fWidth
Double_t fWidth
Definition: CbmRichDetectorData.h:44
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmRichPmtData::fHeight
Double_t fHeight
Definition: CbmRichDetectorData.h:45
CbmRichDigiMapManager::CbmRichDigiMapManager
CbmRichDigiMapManager()
Definition: CbmRichDigiMapManager.cxx:27
CbmRichPmtData::fPixelAddresses
std::vector< Int_t > fPixelAddresses
Definition: CbmRichDetectorData.h:40
CbmRichDigiMapManager::fPmtIdToDataMap
std::map< Int_t, CbmRichPmtData * > fPmtIdToDataMap
Definition: CbmRichDigiMapManager.h:86
CbmRichDigiMapManager::GetPixelDataByAddress
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
Definition: CbmRichDigiMapManager.cxx:267
CbmRichPixelData::fZ
Double_t fZ
Definition: CbmRichDetectorData.h:22