16 std::vector<inputType> inputData;
17 std::vector<Cluster> clustersOut;
18 std::vector<inputType*> digiPtrVec;
19 std::vector<std::vector<inputType*>> digiMapSelf;
20 std::vector<std::vector<inputType*>> digiMapNeig;
24 const size_t numChan = numCols * numRows;
26 for (
auto& input : inVec) {
27 inputData.push_back(std::make_tuple(input.second, &input.first, input.first.GetTime()));
32 digiMapSelf.resize(numChan);
33 digiMapNeig.resize(numChan);
35 for (
auto& digidata : inputData) {
41 digiMapSelf[channel].push_back(&digidata);
42 digiPtrVec.push_back(&digidata);
45 digiMapNeig[channel].push_back(&digidata);
50 std::vector<std::vector<inputType*>::iterator> lastChanPosSelf, lastChanPosNeig;
51 for (
size_t chan = 0; chan < numChan; chan++) {
52 lastChanPosSelf.push_back(digiMapSelf[chan].begin());
53 lastChanPosNeig.push_back(digiMapNeig[chan].begin());
58 for (
auto mainit = digiPtrVec.begin(); mainit != digiPtrVec.end(); mainit++) {
62 if (digi ==
nullptr)
continue;
65 const double time = std::get<2>(**mainit);
69 const int digiId = std::get<0>(**mainit);
75 int highcol = channel;
78 bool sealtopcol =
false;
79 bool sealbotcol =
false;
82 if (channel % ncols == ncols - 1) {
85 if (channel % ncols == 0) {
90 std::vector<std::pair<int, const CbmTrdDigi*>> cluster;
91 cluster.emplace_back(digiId, digi);
92 std::get<1>(**mainit) =
nullptr;
101 const size_t oldSize = cluster.size();
103 const int col = channel % ncols;
104 if (col == ncols - 1) sealtopcol =
true;
105 if (col == 0) sealbotcol =
true;
107 if (!sealbotcol && 0 <= lowcol - 1) {
108 if (
TryAddDigi(&digiMapSelf, lowcol - 1, &lastChanPosSelf, &cluster, time)) {
112 if (!sealtopcol && highcol + 1 < numChan) {
113 if (
TryAddDigi(&digiMapSelf, highcol + 1, &lastChanPosSelf, &cluster, time)) {
117 if (!sealbotcol && 0 <= lowcol - 1) {
118 if (
TryAddDigi(&digiMapNeig, lowcol - 1, &lastChanPosNeig, &cluster, time)) {
122 if (!sealtopcol && highcol + 1 < numChan) {
123 if (
TryAddDigi(&digiMapNeig, highcol + 1, &lastChanPosNeig, &cluster, time)) {
131 if (cluster.size() - oldSize == 0)
break;
132 if (sealbotcol && sealtopcol)
break;
142 std::vector<std::vector<inputType*>::iterator>* lastPos,
143 std::vector<std::pair<int, const CbmTrdDigi*>>* cluster,
const double digiTime)
const
148 for (
auto FNit = (*lastPos)[chan]; FNit != (*digimap)[chan].end(); FNit++) {
151 const double newtime = std::get<2>(**FNit);
152 if (newtime < digiTime - interval) {
158 if (newtime > digiTime + interval)
break;
162 if (d ==
nullptr)
continue;
165 const int digiid = std::get<0>(**FNit);
166 cluster->emplace_back(digiid, d);
167 std::get<1>(**FNit) =
nullptr;
175 std::vector<Cluster>* clustersOut)
const
178 std::vector<int> digiIndices;
179 digiIndices.reserve(cluster.size());
182 std::transform(cluster.begin(), cluster.end(), std::back_inserter(digiIndices),
183 [](
const auto& pair) { return pair.first; });
186 std::vector<const CbmTrdDigi*> digis;
187 digis.reserve(cluster.size());
190 std::transform(cluster.begin(), cluster.end(), std::back_inserter(digis),
191 [](
const auto& pair) { return pair.second; });
194 std::unordered_map<int, bool> cols, rows;
195 for (
const auto& pair : cluster) {
197 int digiChannel = pair.second->GetAddressChannel();
198 int colId = digiChannel % ncols;
199 int globalRow = digiChannel / ncols;
200 int combiId = globalRow * ncols + colId;
201 cols[combiId] =
true;
202 rows[globalRow] =
true;
206 clustersOut->emplace_back(digiIndices, digis,
fParams.
address, cols.size(), rows.size());
bool TryAddDigi(std::vector< std::vector< inputType * > > *digimap, int chan, std::vector< std::vector< inputType * >::iterator > *lastPos, std::vector< std::pair< int, const CbmTrdDigi * > > *cluster, const double digiTime) const