CbmRoot
Loading...
Searching...
No Matches
Cluster2D.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 "Cluster2D.h"
6
8#include "CbmTrdDigi.h"
9
10#include <cmath>
11
12using std::vector;
13
14namespace cbm::algo::trd
15{
16 //____________________________________________________________________
18 : fRecDigis(ref.fRecDigis)
19 , fDigis(ref.fDigis)
20 , fDigiIndices(ref.fDigiIndices)
21 , fAddress(ref.fAddress)
22 , fNCols(ref.fNCols)
23 , fNRows(ref.fNRows)
24 , fStartCh(ref.fStartCh)
25 , fStartTime(ref.fStartTime)
26 {
27 }
28
29 //____________________________________________________________________
30 Cluster2D::Cluster2D(int32_t address, int32_t idx, const CbmTrdDigi* digi, uint16_t chT, uint16_t chR, int32_t row,
31 int32_t time)
32 : fAddress(address)
33 , fNCols(0)
34 , fStartCh(0xffff)
35 , fStartTime(time)
36 {
37 SetNRows(row);
38 SetStart(false);
39 SetStop(false);
40 AddDigi(idx, digi, chT, chR);
41 }
42
43 //____________________________________________________________________
44 bool Cluster2D::AddDigi(int32_t idx, const CbmTrdDigi* digi, uint16_t chT, uint16_t chR, int32_t dt)
45 {
61 if (chT == 0xffff) { // basic functionality for rectangular pads
62 AddDigiIdxPair(idx, digi);
63 return true;
64 }
65
66 uint16_t chMin = (chT != 0 ? chT : chR), chMax = (chR != 0 ? chR : chT);
67
68 // assume triangular pads only
69 if (!fNCols) { // first digi
70 fStartCh = chMin;
71 AddDigiIdxPair(idx, digi);
72 }
73 else if (chMin > GetEndCh()) { // digi @ end
74 //if (HasStop()) return false;
75 AddDigiIdxPair(idx, digi);
76 }
77 else if (chMax < fStartCh) { // digi @ beginning
78 //if (HasStart()) return false;
79 fStartCh = chMin;
80 vector<int32_t> idx_vec = GetDigiIndices();
81 vector<const CbmTrdDigi*> digi_vec = GetDigis();
82 ClearDigis();
83 AddDigiIdxPair(idx, digi);
84 AddDigiIdxPairs(idx_vec, digi_vec);
85 }
86 int nch(0);
87 if (chT == 0)
88 SetStart();
89 else
90 nch++;
91 if (chR == 0)
92 SetStop();
93 else
94 nch++;
95
96 fNCols += nch;
97 if (dt > 0) fStartTime -= dt;
98
99 return true;
100 }
101
102 //____________________________________________________________________
103 int32_t Cluster2D::IsChannelInRange(uint16_t chT, uint16_t chR) const
104 {
105 if (!fNCols) return -2;
106 // if(IsTerminatedLeft() && fAddressCh[0]>ch) return -1;
107 // if(IsTerminatedRight() && fAddressCh[clSize-1]<ch) return 1;
108
109 uint16_t chMin = (chT != 0 ? chT : chR), chMax = (chR != 0 ? chR : chT);
110 if (fStartCh > chMax + 1) return -1;
111 if (fStartCh + fNCols < chMin) return 1;
112 return 0;
113 }
114
115 //____________________________________________________________________
117 {
118 if (GetRow() != second->GetRow()) return false;
119 // time difference condition
120 if (fNCols == 1 || second->fNCols == 1) {
121 if (abs(int32_t(second->fStartTime - fStartTime)) > 50) return false;
122 }
123 else if (abs(int32_t(second->fStartTime - fStartTime)) > 20)
124 return false;
125 // look before current
126 if (second->fStartCh + second->fNCols == fStartCh) {
127 fStartCh = second->fStartCh;
128 fNCols += second->fNCols;
129 fStartTime = std::min(fStartTime, second->fStartTime);
130
131 vector<int32_t> idx_vec = GetDigiIndices();
132 vector<const CbmTrdDigi*> digi_vec = GetDigis();
133 ClearDigis();
134 AddDigiIdxPairs(second->GetDigiIndices(), second->GetDigis());
135 AddDigiIdxPairs(idx_vec, digi_vec);
136 if (second->HasStart()) SetStart();
137 return true;
138 }
139
140 // look after current
141 if (fStartCh + fNCols == second->fStartCh) {
142 fNCols += second->fNCols;
143 fStartTime = std::min(fStartTime, second->fStartTime);
144 AddDigiIdxPairs(second->GetDigiIndices(), second->GetDigis());
145 if (second->HasStop()) SetStop();
146 return true;
147 }
148 return false;
149 }
150
151 bool Cluster2D::Finalize(size_t numCols)
152 {
156 int last_col(-1);
157 for (auto i = fDigis.begin(); i != fDigis.end(); i++) {
158 if ((*i) == nullptr) continue;
159 int colR(-1);
160 const CbmTrdDigi* dgT = (*i);
161 int colT = dgT->GetAddressChannel() % numCols;
162
163 // check column order for cluster /// TO DO: we can probably drop this check
164 if (last_col >= 0 && colT != last_col + 1) {
165 L_(error) << "TrdModuleRec2D::LoadDigis : digis in cluster not in increasing order !";
166 return false;
167 }
168 last_col = colT;
169 const CbmTrdDigi* dgR = nullptr;
170
171 auto j = std::next(i);
172 if (j != fDigis.end()) {
173 dgR = (*j);
174 colR = dgR->GetAddressChannel() % numCols;
175 }
176 if (colR == colT && dgR != nullptr) {
177 fRecDigis.emplace_back(*dgT, *dgR);
178 i++;
179 }
180 else {
181 fRecDigis.emplace_back(*dgT);
182 }
183 }
184 return true;
185 }
186} // namespace cbm::algo::trd
#define L_(level)
int32_t GetAddressChannel() const
Getter read-out id.
Data Container for TRD clusters.
Definition Cluster2D.h:22
bool Finalize(const size_t numCols)
Fill array of calibrated digis.
bool Merge(Cluster2D *second)
Merge current cluster with info from second.
void ClearDigis()
Remove all digis.
Definition Cluster2D.h:111
uint16_t GetRow() const
Definition Cluster2D.h:136
const std::vector< int32_t > & GetDigiIndices() const
Get array of digi indices.
Definition Cluster2D.h:94
std::vector< const CbmTrdDigi * > fDigis
Array of digi pointers.
Definition Cluster2D.h:176
void AddDigiIdxPair(int32_t index, const CbmTrdDigi *digi)
Add digi to cluster.
Definition Cluster2D.h:61
std::vector< const CbmTrdDigi * > & GetDigis()
Get array of digi pointers.
Definition Cluster2D.h:100
void SetStart(bool set=true)
Definition Cluster2D.h:171
uint16_t GetEndCh() const
Definition Cluster2D.h:135
void SetStop(bool set=true)
Definition Cluster2D.h:172
Cluster2D()=delete
Default constructor.
bool AddDigi(int32_t idx, const CbmTrdDigi *digi, uint16_t chT=0xffff, uint16_t chR=0, int32_t dt=0)
Append digi to cluster.
Definition Cluster2D.cxx:44
void SetNRows(uint16_t nrows)
Definition Cluster2D.h:166
int32_t IsChannelInRange(uint16_t chT, uint16_t chR) const
Query on RO channels list.
void AddDigiIdxPairs(const std::vector< int32_t > &indices, const std::vector< const CbmTrdDigi * > digis)
Add array of digi to cluster.
Definition Cluster2D.h:71
std::vector< DigiRec > fRecDigis
Array of calibrated digis.
Definition Cluster2D.h:175