CbmRoot
Loading...
Searching...
No Matches
Clusterizer2D.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Dominik Smith [committer], Alexandru Bercuci */
4
5#include "Clusterizer2D.h"
6
8
9#include <algorithm>
10
11namespace cbm::algo::trd
12{
13
14 //_______________________________________________________________________________
15 std::vector<Cluster2D> Clusterizer2D::operator()(const std::vector<std::pair<CbmTrdDigi, int32_t>>& inVec,
16 const uint64_t t0) const
17 {
18 const size_t numRows = fParams.rowPar.size();
19 const size_t numCols = fParams.rowPar[0].padPar.size();
20
21 std::vector<std::vector<Cluster2D*>> buffer(numRows); //row-wise organized clusters
22 std::vector<size_t> bufferPos(numRows); //storage of starting positon in buffers
23 std::vector<Cluster2D> clustersOut; //clusters to be returned
24 std::vector<inputType> inputData; //formatted input
25
26 // Apply input formatting
27 for (auto& input : inVec) {
28 const CbmTrdDigi* d = &input.first;
29 const size_t index = input.second;
30 int pad = d->GetAddressChannel();
31 uint16_t chT = pad << 1;
32 uint16_t chR = chT + 1;
33 int dtime;
34 double t;
35 double r = d->GetCharge(t, dtime); //subtract timeslice start time. maybe not needed anymore?
36 int tm = d->GetTimeDAQ() - t0;
37 const int row = pad / numCols;
38 const int col = pad % numCols;
39 if (dtime < 0) tm += dtime; // correct for the difference between tilt and rect
40 if (r < 1 && !fParams.rowPar[row].padPar[col].chRMasked) chR = 0;
41 if (t < 1 && !fParams.rowPar[row].padPar[col].chTMasked) chT = 0;
42 inputData.emplace_back(chT, chR, tm, row, index, d);
43 }
44
45 // Sort input by time. TO DO: Use insert-sort like in TOF hitfinder
46 std::sort(inputData.begin(), inputData.end(),
47 [](const auto& a, const auto& b) -> bool { return std::get<2>(a) < std::get<2>(b); });
48
49 // Fill row buffers
50 for (auto& in : inputData) {
51 auto& [chT, chR, tm, row, id, digi] = in;
52
53 // check for saved
54 if (buffer[row].empty()) {
55 buffer[row].push_back(new Cluster2D(fParams.address, id, digi, chT, chR, row, tm));
56 bufferPos[row] = 0;
57 continue;
58 }
60
61 // Get stored starting position
62 auto itc = (buffer[row].begin() + bufferPos[row]);
63
64 //Update cluster
65 for (; itc != buffer[row].end(); itc++) {
66 if ((int64_t)(*itc)->GetStartTime() < tm - 5) {
67 bufferPos[row]++;
68 continue;
69 }
70 if ((*itc)->IsChannelInRange(chT, chR) == 0) {
71 const uint tc = (*itc)->GetStartTime();
72 (*itc)->AddDigi(id, digi, chT, chR, tc - tm);
73 break;
74 }
75 }
76 if (itc == buffer[row].end()) {
77 buffer[row].push_back(new Cluster2D(fParams.address, id, digi, chT, chR, row, tm));
78 }
79 }
80
81 // Build clusters
82 for (auto& clRow : buffer) {
83
84 // TO DO: Process the following remark from original code:
85 // TODO look left and right for masked channels. If they exists add them to cluster.
86 // if (AddClusterEdges(*itc0) && CWRITE(0)) L_(debug) << " edge cl[0] : " << (*itc0)->ToString();
87
88 // Phase 0 : try merge clusters if more than one on a row
89 for (auto itc0 = clRow.begin(); itc0 != clRow.end(); itc0++) {
90 if (*itc0 == nullptr) {
91 continue;
92 }
93 for (auto itc1 = std::next(itc0); itc1 != clRow.end(); itc1++) {
94 if (*itc1 == nullptr) {
95 continue;
96 }
97 if ((*itc1)->GetStartTime() - (*itc0)->GetStartTime() > 50) {
98 break;
99 }
100 if ((*itc0)->Merge((*itc1))) {
101 delete (*itc1);
102 *itc1 = nullptr;
103 itc1 = itc0;
104 }
105 }
106 }
107
108 // Phase 1 : copy older clusters from the buffer to the module wise storage
109 for (auto& pcluster : clRow) {
110 if (pcluster == nullptr) {
111 continue;
112 }
113 clustersOut.emplace_back(*pcluster);
114 clustersOut.back().Finalize(fParams.rowPar[0].padPar.size());
115 delete pcluster;
116 pcluster = nullptr;
117 }
118 }
119
120 return clustersOut;
121 }
122
123} // namespace cbm::algo::trd
uint64_t GetTimeDAQ() const
Getter for global DAQ time [clk]. Differs for each ASIC. In FASP case DAQ time is already stored in f...
Definition CbmTrdDigi.h:158
int32_t GetAddressChannel() const
Getter read-out id.
double GetCharge() const
Common purpose charge getter.
Data Container for TRD clusters.
Definition Cluster2D.h:22
HitFinder2DModPar fParams
Parameter container.
std::vector< Cluster2D > operator()(const std::vector< std::pair< CbmTrdDigi, int32_t > > &inVec, uint64_t t0) const
Execution.
std::vector< HitFinder2DRowPar > rowPar