CbmRoot
Loading...
Searching...
No Matches
CbmTrdCluster.cxx
Go to the documentation of this file.
1/* Copyright (C) 2010-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
10#include "CbmTrdCluster.h"
11
12#include <Logger.h> // for LOG, Logger
13
14#include <iostream> // for operator<<, basic_ostream, stringstream
15
16#include <cmath>
17
18using std::endl;
19using std::string;
20using std::stringstream;
21using std::vector;
22//____________________________________________________________________
24
25//____________________________________________________________________
27 : CbmCluster(ref.GetDigis(), ref.GetAddress())
28 , fNCols(ref.fNCols)
29 , fNRows(ref.fNRows)
30 , fStartCh(ref.fStartCh)
31 , fStartTime(ref.fStartTime)
32{
33}
34
35//____________________________________________________________________
36CbmTrdCluster::CbmTrdCluster(const std::vector<int32_t>& indices, int32_t address)
37 : CbmCluster(indices, address)
38{
39}
40
41//____________________________________________________________________
42CbmTrdCluster::CbmTrdCluster(int32_t address, int32_t idx, uint16_t chT, uint16_t chR, int32_t row, int32_t time)
43 : CbmCluster()
44{
45 ReInit(address, row, time);
46 AddDigi(idx, chT, chR);
47}
48
49//____________________________________________________________________
51
53{
54 if (this != &ref) {
56 fNCols = ref.fNCols;
57 fNRows = ref.fNRows;
58 fStartCh = ref.fStartCh;
60 }
61 return *this;
62}
63
64//____________________________________________________________________
66{
67 if (!r) {
68 if (!fStartCh) return false;
69 fStartCh--;
70 }
71 fNCols++;
72 return true;
73}
74
75//____________________________________________________________________
76bool CbmTrdCluster::AddDigi(int32_t idx, uint16_t chT, uint16_t chR, int32_t dt)
77{
93 if (chT == 0xffff) { // basic functionality for rectangular pads
95 return true;
96 }
97
98 uint16_t chMin = (chT != 0 ? chT : chR), chMax = (chR != 0 ? chR : chT);
99
100 // assume triangular pads only
101 if (!fNCols) { // first digi
102 fStartCh = chMin;
104 }
105 else if (chMin > GetEndCh()) { // digi @ end
106 //if (HasStop()) return false;
108 }
109 else if (chMax < fStartCh) { // digi @ beginning
110 //if (HasStart()) return false;
111 fStartCh = chMin;
112 vector<int32_t> vec = GetDigis();
113 ClearDigis();
115 AddDigis(vec);
116 }
117 int nch(0);
118 if (chT == 0) SetStart();
119 else
120 nch++;
121 if (chR == 0) SetStop();
122 else
123 nch++;
124
125 fNCols += nch;
126 if (dt > 0) fStartTime -= dt;
127
128 return true;
129}
130
131//____________________________________________________________________
132void CbmTrdCluster::Clear(Option_t*)
133{
135 fNCols = 0;
136 fNRows = 0x1f;
137 fStartCh = 0xffff;
138 fStartTime = 0xffffffff;
139}
140
141//____________________________________________________________________
142void CbmTrdCluster::ReInit(int32_t address, int32_t row, int32_t time)
143{
144 SetAddress(address);
145 fNCols = 0;
146 fStartCh = 0xffff;
147 // check truncation
148 if (row >= 0x1f) LOG(warn) << GetName() << "::ReInit: pad-row truncated to 5bits.";
149 SetNRows(row);
150 SetStart(false);
151 SetStop(false);
152 if (std::abs(time) >= 0x7fffffff) LOG(warn) << GetName() << "::ReInit: buffer time truncated to 4bytes.";
153 fStartTime = time;
154}
155
156//____________________________________________________________________
157int32_t CbmTrdCluster::IsChannelInRange(uint16_t chT, uint16_t chR) const
158{
159 if (!fNCols) return -2;
160 // if(IsTerminatedLeft() && fAddressCh[0]>ch) return -1;
161 // if(IsTerminatedRight() && fAddressCh[clSize-1]<ch) return 1;
162
163 uint16_t chMin = (chT != 0 ? chT : chR), chMax = (chR != 0 ? chR : chT);
164 if (fStartCh > chMax + 1) return -1;
165 if (fStartCh + fNCols < chMin) return 1;
166 return 0;
167}
168
169//____________________________________________________________________
171{
172 if (GetRow() != second->GetRow()) return false;
173 // time difference condition
174 if (fNCols == 1 || second->fNCols == 1) {
175 if (abs(int32_t(second->fStartTime - fStartTime)) > 50) return false;
176 }
177 else if (abs(int32_t(second->fStartTime - fStartTime)) > 20)
178 return false;
179 // look before current
180 if (second->fStartCh + second->fNCols == fStartCh) {
181 // std::cout<<"Merge before with "<<second->ToString();
182 fStartCh = second->fStartCh;
183 fNCols += second->fNCols;
184 fStartTime = std::min(fStartTime, second->fStartTime);
185
186 vector<int32_t> vec = GetDigis();
187 ClearDigis();
188 AddDigis(second->GetDigis());
189 AddDigis(vec);
190 if (second->HasStart()) SetStart();
191 return true;
192 }
193
194 // look after current
195 if (fStartCh + fNCols == second->fStartCh) {
196 // std::cout<<"Merge after with "<<second->ToString();
197 fNCols += second->fNCols;
198 fStartTime = std::min(fStartTime, second->fStartTime);
199 AddDigis(second->GetDigis());
200 if (second->HasStop()) SetStop();
201 return true;
202 }
203 return false;
204}
205
206//____________________________________________________________________
208{
209 stringstream ss;
210 ss << CbmCluster::ToString();
211 ss << "CbmTrdCluster: mod=" << GetAddress() << " row=" << (int32_t) GetRow() << " "
212 << (HasFaspDigis() ? "Fasp_" : "Spadic_") << "Chs=";
213 ss << (HasStart() ? "|" : "/");
214 for (int32_t i(0); i < fNCols; i++)
215 ss << fStartCh + i << " ";
216 ss << (HasStop() ? "|" : "/");
217 ss << endl;
218 return ss.str();
219}
220
ClassImp(CbmConverterManager)
Data Container for TRD clusters.
Base class for cluster objects.
Definition CbmCluster.h:30
void AddDigi(int32_t index)
Add digi to cluster.
Definition CbmCluster.h:51
const std::vector< int32_t > & GetDigis() const
Get array of digi indices.
Definition CbmCluster.h:82
int32_t GetAddress() const
Definition CbmCluster.h:90
void SetAddress(int32_t address)
Definition CbmCluster.h:94
virtual std::string ToString() const
Return string representation of the object.
CbmCluster & operator=(const CbmCluster &)
void AddDigis(const std::vector< int32_t > &indices)
Add array of digi to cluster.
Definition CbmCluster.h:57
void ClearDigis()
Remove all digis.
Definition CbmCluster.h:87
Data Container for TRD clusters.
bool HasStart() const
CbmTrdCluster()
Default constructor.
uint32_t fStartTime
void ReInit(int32_t address, int32_t row, int32_t time)
Initialize basic parameters of the cluster.
void SetStart(bool set=true)
int32_t IsChannelInRange(uint16_t chT, uint16_t chR) const
Query on RO channels list.
virtual ~CbmTrdCluster()
Destructor.
bool AddDigi(int32_t idx, uint16_t chT=0xffff, uint16_t chR=0, int32_t dt=0)
Append digi to cluster.
uint16_t GetRow() const
CbmTrdCluster & operator=(const CbmTrdCluster &ref)
bool AddChannel(bool r=true)
Append a channel to cluster edge. The usage is to account for the masked channels....
void SetStop(bool set=true)
bool HasFaspDigis() const
void SetNRows(uint16_t nrows)
virtual std::string ToString() const
Extended functionality.
bool HasStop() const
bool Merge(CbmTrdCluster *second)
Merge current cluster with info from second.
uint16_t fStartCh
uint16_t GetEndCh() const
void Clear(Option_t *)
reset cluster data