CbmRoot
CbmRichMCbmDigiMapManager.cxx
Go to the documentation of this file.
1 /*
2  * CbmRichMCbmDigiMapManager.cxx
3  *
4  * Created on: Jul 11, 2019
5  * Author: aweber
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 #include <TString.h> // for TString
20 
21 #include <iostream> // for string, operator<<, basic_ostream
22 #include <stddef.h> // for size_t
23 #include <string> // for operator<, stoul
24 #include <utility> // for pair
25 
26 using namespace std;
27 
29  : fPixelPathToAddressMap()
30  , fPixelAddressToDataMap()
31  , fPixelAddresses()
32  , fPmtPathToIdMap()
33  , fPmtIdToDataMap()
34  , fPmtIds() {
35  Init();
36 }
37 
39 
41 
42  fPixelPathToAddressMap.clear();
43  fPixelAddressToDataMap.clear();
44  fPixelAddresses.clear();
45 
46  fPmtPathToIdMap.clear();
47  fPmtIdToDataMap.clear();
48  fPmtIds.clear();
49 
50 
51  // Get MAPMT dimensions
52  Double_t pmtHeight = 5.2;
53  Double_t pmtWidth = 5.2;
54  TGeoVolume* pmtVolume = gGeoManager->FindVolumeFast("pmt"); // check for RICH
55  if (pmtVolume == nullptr)
56  pmtVolume = gGeoManager->FindVolumeFast(
57  "pmt_vol_0"); // check for mRICH // or pmt_vol_1
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  const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
78  const Double_t* curNodeTr = curMatrix->GetTranslation();
79  string path = string(nodePath.Data());
80 
81  size_t pmtInd = path.find_last_of("/");
82  if (string::npos == pmtInd) continue;
83  string pmtPath = path.substr(0, pmtInd + 1);
84 
85  Int_t channel =
86  std::stoul(path.substr(pmtInd + 11)); // cut away "pmt_pixel_"
87  Int_t posAtPmt = channel / 100;
88  channel = channel % 100;
89 
90  size_t pmtVolInd = path.rfind("/", pmtInd - 1);
91  if (string::npos == pmtVolInd) continue;
92  Int_t pmtPosBP = std::stoul(path.substr(
93  pmtVolInd + 11,
94  pmtInd - pmtVolInd - 11)); // cut away "/pmt_vol_*_" ; position on BP
95 
96  size_t bpInd = path.rfind("/", pmtVolInd - 1);
97  if (string::npos == bpInd) continue;
98  Int_t posBP = std::stoul(path.substr(
99  bpInd + 14,
100  pmtVolInd - bpInd - 14)); // cut away "/pmt_vol_*_" ; position on BP
101 
102  Int_t x = (posBP / 10) + ((((pmtPosBP - 1) / 3) + 1) % 2);
103  Int_t y = (posBP % 10) + (2 - ((pmtPosBP - 1) % 3));
104 
105  Int_t DiRICH_Add = ((7 & 0xF) << 12) + ((x & 0xF) << 8) + ((y & 0xF) << 4)
106  + (posAtPmt & 0xF);
107  Int_t pixelUID = ((DiRICH_Add << 16) | (channel & 0x00FF));
108  Int_t pmtUID = ((x & 0xF) << 4) + (y & 0xF);
109  //std::cout<<"Addr: 0x"<< std::hex << DiRICH_Add << std::dec << "\t" << channel <<"\t"<< std::hex << pixelUID << std::dec << std::endl;
110 
111  fPixelPathToAddressMap.insert(pair<string, Int_t>(path, pixelUID));
112  CbmRichPixelData* pixelData = new CbmRichPixelData();
113  pixelData->fX = curNodeTr[0];
114  pixelData->fY = curNodeTr[1];
115  pixelData->fZ = curNodeTr[2];
116  pixelData->fAddress = pixelUID;
117  fPixelAddressToDataMap.insert(
118  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(
131  pair<Int_t, CbmRichPmtData*>(pmtData->fId, pmtData));
132  pixelData->fPmtId = pmtData->fId;
133 
134  fPmtIds.push_back(pmtData->fId);
135 
136  } else {
137  //cout << "pmtPath old:" << pmtPath << endl;
138  Int_t pmtId = fPmtPathToIdMap[pmtPath];
139  CbmRichPmtData* pmtData = fPmtIdToDataMap[pmtId];
140  if (pmtData == nullptr || pmtId != pmtData->fId) {
141  LOG(error) << "(pmtData == nullptr || pmtId != pmtData->fId) ";
142  }
143  pmtData->fPixelAddresses.push_back(pixelData->fAddress);
144  pixelData->fPmtId = pmtData->fId;
145  if (pmtData->fPixelAddresses.size() > 64) {
146  LOG(info) << "size:" << pmtData->fPixelAddresses.size()
147  << " pmtData->fId:" << pmtData->fId
148  << " pmtPath:" << pmtPath << endl
149  << " path:" << path;
150  }
151  }
152  }
153  }
154 
155  // calculate Pmt center as center of gravity of 64 pixels
156  for (auto const& pmt : fPmtIdToDataMap) {
157  // Int_t pmtId = pmt.first;
158  CbmRichPmtData* pmtData = pmt.second;
159  pmtData->fX = 0.;
160  pmtData->fY = 0.;
161  pmtData->fZ = 0.;
162  for (int pixelId : pmtData->fPixelAddresses) {
163  CbmRichPixelData* pixelData = fPixelAddressToDataMap[pixelId];
164  if (pixelData == nullptr) continue;
165  pmtData->fX += pixelData->fX;
166  pmtData->fY += pixelData->fY;
167  pmtData->fZ += pixelData->fZ;
168  }
169  pmtData->fX /= pmtData->fPixelAddresses.size();
170  pmtData->fY /= pmtData->fPixelAddresses.size();
171  pmtData->fZ /= pmtData->fPixelAddresses.size();
172  }
173 
174  LOG(info) << "CbmRichMCbmDigiMapManager is initialized";
175  LOG(info) << "fPixelPathToAddressMap.size() = "
176  << fPixelPathToAddressMap.size();
177  LOG(info) << "fPixelAddressToDataMap.size() = "
178  << fPixelAddressToDataMap.size();
179 
180  LOG(info) << "fPmtPathToIdMap.size() = " << fPmtPathToIdMap.size();
181  LOG(info) << "fPmtIdToDataMap.size() = " << fPmtIdToDataMap.size();
182 
183  // for (auto const& pmt : fPmtIdToDataMap) {
184  // // cout << pmt.first << endl;
185  // cout << pmt.second->ToString() << endl;
186  // }
187 }
188 
190  std::map<string, Int_t>::iterator it;
191  it = fPixelPathToAddressMap.find(path);
192  if (it == fPixelPathToAddressMap.end()) return -1;
193  return it->second;
194 }
195 
196 
199  std::map<Int_t, CbmRichPixelData*>::iterator it;
200  it = fPixelAddressToDataMap.find(address);
201  if (it == fPixelAddressToDataMap.end()) return nullptr;
202  return it->second;
203 }
204 
206  Int_t nofPixels = fPixelAddresses.size();
207  Int_t index = gRandom->Integer(nofPixels);
208  return fPixelAddresses[index];
209 }
210 
212  return fPixelAddresses;
213 }
214 
215 
217 
218 
220  std::map<Int_t, CbmRichPmtData*>::iterator it;
221  it = fPmtIdToDataMap.find(id);
222  if (it == fPmtIdToDataMap.end()) return nullptr;
223  return it->second;
224 }
225 
226 vector<Int_t>
228  std::vector<Int_t> v;
229 
230  return v;
231 }
232 
233 vector<Int_t>
235  std::vector<Int_t> v;
236 
237  return v;
238 }
CbmRichPixelData
Definition: CbmRichDetectorData.h:17
CbmRichPmtData::fY
Double_t fY
Definition: CbmRichDetectorData.h:42
CbmRichMCbmDigiMapManager::GetRandomPixelAddress
Int_t GetRandomPixelAddress()
Definition: CbmRichMCbmDigiMapManager.cxx:205
CbmRichMCbmDigiMapManager::CbmRichMCbmDigiMapManager
CbmRichMCbmDigiMapManager()
Definition: CbmRichMCbmDigiMapManager.cxx:28
CbmRichMCbmDigiMapManager::GetPixelAddresses
std::vector< Int_t > GetPixelAddresses()
Definition: CbmRichMCbmDigiMapManager.cxx:211
CbmRichMCbmDigiMapManager::fPixelAddresses
std::vector< Int_t > fPixelAddresses
Definition: CbmRichMCbmDigiMapManager.h:82
CbmRichMCbmDigiMapManager::~CbmRichMCbmDigiMapManager
virtual ~CbmRichMCbmDigiMapManager()
Definition: CbmRichMCbmDigiMapManager.cxx:38
CbmRichPmtData::fZ
Double_t fZ
Definition: CbmRichDetectorData.h:43
CbmRichMCbmDigiMapManager::GetPixelDataByAddress
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
Definition: CbmRichMCbmDigiMapManager.cxx:198
CbmRichPmtData
Definition: CbmRichDetectorData.h:26
CbmRichMCbmDigiMapManager::Init
void Init()
Definition: CbmRichMCbmDigiMapManager.cxx:40
CbmRichMCbmDigiMapManager::fPmtIds
std::vector< Int_t > fPmtIds
Definition: CbmRichMCbmDigiMapManager.h:86
CbmRichPixelData::fPmtId
Int_t fPmtId
Definition: CbmRichDetectorData.h:23
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
CbmRichMCbmDigiMapManager::GetPmtDataById
CbmRichPmtData * GetPmtDataById(Int_t id)
Definition: CbmRichMCbmDigiMapManager.cxx:219
CbmRichPmtData::fX
Double_t fX
Definition: CbmRichDetectorData.h:41
CbmRichPmtData::fId
Int_t fId
Definition: CbmRichDetectorData.h:39
CbmRichMCbmDigiMapManager.h
shape
UInt_t shape
Definition: CbmMvdSensorDigiToHitTask.cxx:73
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
CbmRichMCbmDigiMapManager::fPmtPathToIdMap
std::map< std::string, Int_t > fPmtPathToIdMap
Definition: CbmRichMCbmDigiMapManager.h:84
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
CbmRichMCbmDigiMapManager::fPmtIdToDataMap
std::map< Int_t, CbmRichPmtData * > fPmtIdToDataMap
Definition: CbmRichMCbmDigiMapManager.h:85
CbmRichPmtData::fHeight
Double_t fHeight
Definition: CbmRichDetectorData.h:45
CbmRichMCbmDigiMapManager::GetPmtIds
std::vector< Int_t > GetPmtIds()
Definition: CbmRichMCbmDigiMapManager.cxx:216
CbmRichMCbmDigiMapManager::fPixelPathToAddressMap
std::map< std::string, Int_t > fPixelPathToAddressMap
Definition: CbmRichMCbmDigiMapManager.h:80
CbmRichMCbmDigiMapManager::fPixelAddressToDataMap
std::map< Int_t, CbmRichPixelData * > fPixelAddressToDataMap
Definition: CbmRichMCbmDigiMapManager.h:81
CbmRichPmtData::fPixelAddresses
std::vector< Int_t > fPixelAddresses
Definition: CbmRichDetectorData.h:40
CbmRichMCbmDigiMapManager::GetDirectNeighbourPixels
std::vector< Int_t > GetDirectNeighbourPixels(Int_t address)
Definition: CbmRichMCbmDigiMapManager.cxx:227
CbmRichMCbmDigiMapManager::GetDiagonalNeighbourPixels
std::vector< Int_t > GetDiagonalNeighbourPixels(Int_t address)
Definition: CbmRichMCbmDigiMapManager.cxx:234
CbmRichMCbmDigiMapManager::GetPixelAddressByPath
Int_t GetPixelAddressByPath(const std::string &path)
Definition: CbmRichMCbmDigiMapManager.cxx:189
CbmRichPixelData::fZ
Double_t fZ
Definition: CbmRichDetectorData.h:22