CbmRoot
CbmStsAlgoFindClusters.cxx
Go to the documentation of this file.
1 
7 
8 #include <cassert>
9 #include <iostream>
10 
11 #include "CbmStsCluster.h"
12 #include "CbmStsDigi.h"
13 #include "CbmStsParAsic.h"
14 #include "CbmStsParModule.h"
15 
16 using std::pair;
17 using std::vector;
18 
20 
21 
22 // ----- Search for a matching cluster for a given channel ---------------
23 Bool_t CbmStsAlgoFindClusters::CheckChannel(Short_t channel, Double_t time) {
24 
25  // Neighbours of first or last channel without cross-connection
26  if (channel == -1 || channel == fNofChannels) return kFALSE;
27 
28  // Check channel number
29  assert(channel < fNofChannels);
30 
31  // No match if no active digi in the channel
32  if (!IsActive(channel)) return kFALSE;
33 
34  // Check time ordering of input digis
35  assert(time >= fStatus[channel].second);
36 
37  // Time difference
38  Double_t tResol = fModPar->GetParAsic(channel).GetTimeResol();
39  Double_t deltaT =
40  (fTimeCutAbs > 0. ? fTimeCutAbs : fTimeCutSig * 1.4142 * tResol);
41 
42  // Channel is active, but time is not matching: close cluster
43  if (time - fStatus[channel].second > deltaT) {
44  CreateCluster(channel);
45  return kFALSE;
46  }
47 
48  // Matching digi found
49  return kTRUE;
50 }
51 // -------------------------------------------------------------------------
52 
53 
54 // ----- Algorithm execution -------------------------------------------
55 Long64_t CbmStsAlgoFindClusters::Exec(const vector<InputData>& input,
56  vector<CbmStsCluster>& output,
57  UInt_t address,
58  UShort_t nChannels,
59  UShort_t channelOffset,
60  Double_t timeCutSigma,
61  Double_t timeCutAbs,
62  Bool_t connectEdge,
63  const CbmStsParModule* modPar) {
64 
65  // --- Set parameters and output
66  fAddress = address;
67  fNofChannels = nChannels;
68  fChannelOffset = channelOffset;
69  fTimeCutSig = timeCutSigma;
70  fTimeCutAbs = timeCutAbs;
71  fConnectEdge = connectEdge;
72  fOutput = &output;
73  fModPar = modPar;
74 
75  // --- Reset buffer and output
76  fStatus.assign(fNofChannels, {-1, 0.});
77  fOutput->clear();
78 
79  // --- Process digis one by one
80  Long64_t nDigis = 0;
81  Bool_t result = kTRUE;
82  for (auto data : input) {
83  UShort_t channel = data.first->GetChannel();
84  assert(channel >= channelOffset);
85  channel -= channelOffset; // Transform into [0, nofChannels-1]
86  result = ProcessDigi(channel, data.first->GetTime(), data.second);
87  if (result) nDigis++;
88  }
89 
90  // --- Create clusters from the remaining digis in the buffer
91  for (UShort_t channel = 0; channel < nChannels; channel++) {
92  CreateCluster(channel);
93  }
94 
95  return nDigis;
96 }
97 // -------------------------------------------------------------------------
98 
99 
100 // ----- Close a cluster -----------------------------------------------
102 
103  assert(channel < fNofChannels);
104  if (!IsActive(channel)) return;
105 
106  // --- Find start and stop channel of cluster
107  Short_t start = channel;
108  Short_t stop = channel;
109  while (IsActive(ChanLeft(start)))
110  start = ChanLeft(start);
111  while (IsActive(ChanRight(stop)))
112  stop = ChanRight(stop);
113 
114  // --- Just a check
115  assert(start >= 0 && start < fNofChannels);
116  assert(stop >= 0 && stop < fNofChannels);
117  if (!fConnectEdge) assert(stop >= start);
118 
119  // --- Create a cluster object
120  CbmStsCluster cluster {};
121  cluster.SetAddress(fAddress);
122 
123  // --- Add digis to cluster and reset the respective buffer channels
124  Short_t iChannel = start;
125  while (kTRUE) {
126  assert(IsActive(iChannel));
127  cluster.AddDigi(fStatus[iChannel].first);
128  fStatus[iChannel].first = -1;
129  fStatus[iChannel].second = 0.;
130  if (iChannel == stop) break;
131  iChannel = ChanRight(iChannel);
132  }
133 
134  // --- Add cluster to output array
135  fOutput->push_back(std::move(cluster));
136 }
137 // -------------------------------------------------------------------------
138 
139 
140 // ----- Process one digi ----------------------------------------------
141 Bool_t CbmStsAlgoFindClusters::ProcessDigi(UShort_t channel,
142  Double_t time,
143  Int_t index) {
144 
145  // Assert channel number
146  assert(channel < fNofChannels);
147 
148  // Check for matching digi in the same channel (can only happen if
149  // time resolution is not much smaller than the dead time.)
150  // In this case, the digi is ignored.
151  if (CheckChannel(channel, time)) return kFALSE;
152 
153  assert(ChanLeft(channel) >= -1);
154  assert(ChanLeft(channel) < fNofChannels + 1);
155  assert(ChanRight(channel) < fNofChannels + 1);
156 
157  // Check for not-matching digis in the neighbour channels
158  CheckChannel(ChanLeft(channel), time);
159  CheckChannel(ChanRight(channel), time);
160 
161  // Set channel status with this digi
162  fStatus[channel].first = index;
163  fStatus[channel].second = time;
164 
165  return kTRUE;
166 }
167 // -------------------------------------------------------------------------
CbmStsAlgoFindClusters.h
CbmStsCluster
Data class for STS clusters.
Definition: CbmStsCluster.h:31
CbmStsAlgoFindClusters::fModPar
const CbmStsParModule * fModPar
Definition: CbmStsAlgoFindClusters.h:187
CbmStsAlgoFindClusters::CreateCluster
void CreateCluster(UShort_t channel)
Create a cluster from an active channel.
Definition: CbmStsAlgoFindClusters.cxx:101
CbmStsAlgoFindClusters::fOutput
std::vector< CbmStsCluster > * fOutput
Pointer to output vector.
Definition: CbmStsAlgoFindClusters.h:178
CbmStsAlgoFindClusters::Exec
Long64_t Exec(const std::vector< InputData > &input, std::vector< CbmStsCluster > &output, UInt_t address, UShort_t nChannels, UShort_t channelOffset, Double_t timeCutSigma, Double_t timeCutAbs, Bool_t connectEdge, const CbmStsParModule *modPar)
Algorithm execution.
Definition: CbmStsAlgoFindClusters.cxx:55
CbmStsAlgoFindClusters::fTimeCutSig
Double_t fTimeCutSig
Time cut in multiples of error.
Definition: CbmStsAlgoFindClusters.h:184
CbmStsAlgoFindClusters::IsActive
Bool_t IsActive(Short_t channel)
Check for a channel being active.
Definition: CbmStsAlgoFindClusters.h:151
InputData
CbmStsAlgoFindClusters::InputData InputData
Definition: CbmStsAlgoFindClusters.cxx:19
CbmStsAlgoFindClusters::InputData
std::pair< const CbmStsDigi *, Long64_t > InputData
Typedef for input data.
Definition: CbmStsAlgoFindClusters.h:58
CbmStsDigi.h
CbmStsParModule::GetParAsic
const CbmStsParAsic & GetParAsic(UInt_t channel) const
ASIC parameters for a given channel.
Definition: CbmStsParModule.cxx:29
CbmStsParModule
Parameters for one STS module.
Definition: CbmStsParModule.h:28
CbmStsParModule.h
CbmStsAlgoFindClusters::ChanRight
Short_t ChanRight(UShort_t channel)
Number of right neighbour channel.
Definition: CbmStsAlgoFindClusters.h:117
first
bool first
Definition: LKFMinuit.cxx:143
CbmStsAlgoFindClusters::fAddress
UInt_t fAddress
Unique module address for clusters.
Definition: CbmStsAlgoFindClusters.h:181
CbmStsAlgoFindClusters::ChanLeft
Short_t ChanLeft(UShort_t channel)
Number of left neighbour channel.
Definition: CbmStsAlgoFindClusters.h:104
CbmCluster::SetAddress
void SetAddress(Int_t address)
Definition: CbmCluster.h:94
CbmStsAlgoFindClusters::fNofChannels
UShort_t fNofChannels
Number of channels.
Definition: CbmStsAlgoFindClusters.h:182
CbmStsAlgoFindClusters::fTimeCutAbs
Double_t fTimeCutAbs
Absolute time cut [ns].
Definition: CbmStsAlgoFindClusters.h:185
CbmStsAlgoFindClusters::fStatus
std::vector< std::pair< Long64_t, Double_t > > fStatus
Status buffer.
Definition: CbmStsAlgoFindClusters.h:175
CbmStsCluster.h
Data class for STS clusters.
CbmStsAlgoFindClusters::CheckChannel
Bool_t CheckChannel(Short_t channel, Double_t time)
Check for a matching digi in a given channel.
Definition: CbmStsAlgoFindClusters.cxx:23
CbmStsAlgoFindClusters::fChannelOffset
UShort_t fChannelOffset
Number of first channel.
Definition: CbmStsAlgoFindClusters.h:183
CbmStsAlgoFindClusters::fConnectEdge
Bool_t fConnectEdge
Connect last and first channel.
Definition: CbmStsAlgoFindClusters.h:186
CbmStsAlgoFindClusters::ProcessDigi
Bool_t ProcessDigi(UShort_t channel, Double_t time, Int_t index)
Process one input digi.
Definition: CbmStsAlgoFindClusters.cxx:141
CbmStsParAsic.h
CbmStsParAsic::GetTimeResol
Double_t GetTimeResol() const
Time resolution.
Definition: CbmStsParAsic.h:137