174 {
178
180
181 std::vector<int> grid(gridCells, -1);
182
183 auto gridIdx = [&](
int p,
int l,
int c) ->
int& {
return grid[
p * (
nLayers *
nCells) + l * nCells + c];};
184
185 int nHits {static_cast<int>(hits->GetEntries())};
186 if (nHits == 0) return {};
187 std::vector<bool> visited(nHits, false);
188 std::vector<std::vector<int>> allClusters;
189
190
191 for (
int i = 0;
i != nHits; ++
i) {
193 int p = hit->GetPlane();
194 int l = hit->GetLayer();
195 int c = hit->GetCell();
196
197 if (p >= 0 && p < nPlanes && l >= 0 && l < nLayers && c >= 0 && c < nCells) {
198 gridIdx(p, l, c) =
i;
199 }
200 }
201
202
206 int startIdx {gridIdx(p, l, c)};
207
208 if (startIdx == -1 || visited[startIdx]) continue;
209
210 std::vector<int> blob;
211 std::vector<int>
stack = {startIdx};
212 visited[startIdx] = true;
213
214 while (!
stack.empty()) {
215 int currIdx {
stack.back()};
217 blob.push_back(currIdx);
218
219 auto hit =
dynamic_cast<DriftTubeHit*
>(hits->At(currIdx));
220 auto neighbours =
GetNeighbours(hit->GetLayer(), hit->GetCell());
221
222 for (const auto& nb : neighbours) {
223 if (
nb.C >= 0 &&
nb.C < nCells) {
224 int nbIdx {gridIdx(p,
nb.L,
nb.C)};
225
226 if (nbIdx != -1 && !visited[nbIdx]) {
227 visited[nbIdx] = true;
228 stack.push_back(nbIdx);
229 }
230 }
231 }
232 }
233
234
235 if (blob.size() >= 3) {
236 std::vector<std::vector<int>> layerHits(nLayers);
237
238
239
240
241 for (int idx : blob) {
243 layerHits[hit->GetLayer()].push_back(idx);
244 }
245
246 for (auto& layerVec : layerHits) {
247 if (layerVec.empty()) layerVec.push_back(-1);
248 }
249
250 for (int i0 : layerHits[0]) {
251 for (int i1 : layerHits[1]) {
252 for (int i2 : layerHits[2]) {
253 for (int i3 : layerHits[3]) {
254 std::vector<int> candidate;
255
256 candidate.reserve(nLayers);
257 if (i0 != -1) candidate.push_back(i0);
258 if (i1 != -1) candidate.push_back(i1);
259 if (i2 != -1) candidate.push_back(i2);
260 if (i3 != -1) candidate.push_back(i3);
261
262 if (candidate.size() < 3) continue;
263
264 bool validChain {true};
265 for (
size_t k = 0;
k < candidate.size() - 1; ++
k) {
266 auto hA =
dynamic_cast<DriftTubeHit*
>(hits->At(candidate[k]));
267 auto hB =
dynamic_cast<DriftTubeHit*
>(hits->At(candidate[k + 1]));
268
269 int dL {hB->
GetLayer() - hA->GetLayer()};
270 int dC {hB->GetCell() - hA->GetCell()};
271
272 if (dL == 1) {
273 if (hA->GetLayer() % 2 == 0) {
274 if (dC != 0 && dC != 1) {
275 validChain = false;
276 break;
277 }
278 } else {
279 if (dC != 0 && dC != -1) {
280 validChain = false;
281 break;
282 }
283 }
284 } else if (dL == 2) {
285 if (std::abs(dC) > 1) {
286 validChain = false;
287 break;
288 }
289 }
290 }
291
292 if (validChain) {
293 allClusters.push_back(candidate);
294 }
295 }
296 }
297 }
298 }
299
300 }
301 }
302 }
303 }
304 return allClusters;
305}
std::vector< HitPoint > GetNeighbours(const int &L, const int &C)
Int_t GetConfParI(TString name)