CbmRoot
Loading...
Searching...
No Matches
CbmStsAlgoFindClusters.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
11
12#include "CbmStsCluster.h"
13#include "CbmStsDigi.h"
14#include "CbmStsParAsic.h"
15#include "CbmStsParModule.h"
16
17#include <cassert>
18#include <iostream>
19
20using std::pair;
21using std::vector;
22
24
25
26// ----- Search for a matching cluster for a given channel ---------------
27Bool_t CbmStsAlgoFindClusters::CheckChannel(Short_t channel, Double_t time)
28{
29
30 // Neighbours of first or last channel without cross-connection
31 if (channel == -1 || channel == fNofChannels) return kFALSE;
32
33 // Check channel number
34 assert(channel < fNofChannels);
35
36 // No match if no active digi in the channel
37 if (!IsActive(channel)) return kFALSE;
38
39 // Check time ordering of input digis
40 assert(time >= fStatus[channel].second);
41
42 // Time difference
43 Double_t tResol = fModPar->GetParAsic(channel).GetTimeResol();
44 Double_t deltaT = (fTimeCutAbs > 0. ? fTimeCutAbs : fTimeCutSig * 1.4142 * tResol);
45
46 // Channel is active, but time is not matching: close cluster
47 if (time - fStatus[channel].second > deltaT) {
48 CreateCluster(channel);
49 return kFALSE;
50 }
51
52 // Matching digi found
53 return kTRUE;
54}
55// -------------------------------------------------------------------------
56
57
58// ----- Algorithm execution -------------------------------------------
59Long64_t CbmStsAlgoFindClusters::Exec(const vector<InputData>& input, vector<CbmStsCluster>& output, UInt_t address,
60 UShort_t nChannels, UShort_t channelOffset, Double_t timeCutSigma,
61 Double_t timeCutAbs, Bool_t connectEdge, const CbmStsParModule* modPar)
62{
63
64 // --- Set parameters and output
65 fAddress = address;
66 fNofChannels = nChannels;
67 fChannelOffset = channelOffset;
68 fTimeCutSig = timeCutSigma;
69 fTimeCutAbs = timeCutAbs;
70 fConnectEdge = connectEdge;
71 fOutput = &output;
72 fModPar = modPar;
73
74 // --- Reset buffer and output
75 fStatus.assign(fNofChannels, {-1, 0.});
76 fOutput->clear();
77
78 // --- Process digis one by one
79 Long64_t nDigis = 0;
80 Bool_t result = kTRUE;
81 for (auto data : input) {
82 UShort_t channel = data.first->GetChannel();
83 assert(channel >= channelOffset);
84 channel -= channelOffset; // Transform into [0, nofChannels-1]
85 result = ProcessDigi(channel, data.first->GetTime(), data.second);
86 if (result) nDigis++;
87 }
88
89 // --- Create clusters from the remaining digis in the buffer
90 for (UShort_t channel = 0; channel < nChannels; channel++) {
91 CreateCluster(channel);
92 }
93
94 return nDigis;
95}
96// -------------------------------------------------------------------------
97
98
99// ----- Close a cluster -----------------------------------------------
101{
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 ----------------------------------------------
141Bool_t CbmStsAlgoFindClusters::ProcessDigi(UShort_t channel, Double_t time, Int_t index)
142{
143
144 // Assert channel number
145 assert(channel < fNofChannels);
146
147 // Check for matching digi in the same channel (can only happen if
148 // time resolution is not much smaller than the dead time.)
149 // In this case, the digi is ignored.
150 if (CheckChannel(channel, time)) return kFALSE;
151
152 assert(ChanLeft(channel) >= -1);
153 assert(ChanLeft(channel) < fNofChannels + 1);
154 assert(ChanRight(channel) < fNofChannels + 1);
155
156 // Check for not-matching digis in the neighbour channels
157 CheckChannel(ChanLeft(channel), time);
158 CheckChannel(ChanRight(channel), time);
159
160 // Set channel status with this digi
161 fStatus[channel].first = index;
162 fStatus[channel].second = time;
163
164 return kTRUE;
165}
166// -------------------------------------------------------------------------
CbmStsAlgoFindClusters::InputData InputData
Data class for STS clusters.
bool first
void SetAddress(int32_t address)
Definition CbmCluster.h:94
UShort_t fChannelOffset
Number of first channel.
Double_t fTimeCutSig
Time cut in multiples of error.
Short_t ChanRight(UShort_t channel)
Number of right neighbour channel.
Double_t fTimeCutAbs
Absolute time cut [ns].
UShort_t fNofChannels
Number of channels.
std::vector< std::pair< Long64_t, Double_t > > fStatus
Status buffer.
Bool_t IsActive(Short_t channel)
Check for a channel being active.
UInt_t fAddress
Unique module address for clusters.
std::vector< CbmStsCluster > * fOutput
Pointer to output vector.
Bool_t ProcessDigi(UShort_t channel, Double_t time, Int_t index)
Process one input digi.
Short_t ChanLeft(UShort_t channel)
Number of left neighbour channel.
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.
std::pair< const CbmStsDigi *, Long64_t > InputData
Typedef for input data.
Bool_t fConnectEdge
Connect last and first channel.
const CbmStsParModule * fModPar
void CreateCluster(UShort_t channel)
Create a cluster from an active channel.
Bool_t CheckChannel(Short_t channel, Double_t time)
Check for a matching digi in a given channel.
Data class for STS clusters.
double GetTimeResol() const
Time resolution.
Parameters for one STS module.
const CbmStsParAsic & GetParAsic(uint32_t channel) const
ASIC parameters for a given channel.