15#include <fmt/format.h>
28 gsl::span<const o2::mch::Digit>
digits,
29 uint32_t timeClusterSize, uint32_t nBins,
bool improvePeakSearch,
bool debug)
30 : mTimeClusterSize(timeClusterSize),
31 mNbinsInOneWindow(nBins),
32 mBinWidth(timeClusterSize / nBins),
35 mImprovePeakSearch(improvePeakSearch),
37 mLastSavedTimeBin(-1),
47void ROFTimeClusterFinder::initTimeBins()
49 static constexpr uint32_t maxNTimeBins = 1e7;
54 if (mInputROFs.empty()) {
60 auto tfSize = mInputROFs.back().getBCData().differenceInBC(mFirstIR);
61 mNbinsInOneTF = tfSize / mBinWidth + 1;
62 if (mNbinsInOneTF > maxNTimeBins) {
63 LOGP(alarm,
"Number of time bins exceeding the limit");
64 mNbinsInOneTF = maxNTimeBins;
66 mTimeBins.resize(mNbinsInOneTF);
69 int64_t previousROFbc = -1;
70 for (
size_t iRof = 0; iRof < mInputROFs.size(); iRof++) {
71 const auto& rof = mInputROFs[iRof];
72 const auto&
ir = rof.getBCData();
74 auto binIdx = rofBc / mBinWidth;
77 if (rofBc <= previousROFbc || rofBc > tfSize) {
78 LOGP(alarm,
"Wrong ROF ordering");
81 previousROFbc = rofBc;
82 if (rof.getNEntries() < 1) {
83 LOGP(alarm,
"Empty ROF");
88 if (binIdx >= mNbinsInOneTF) {
92 auto& timeBin = mTimeBins[binIdx];
94 if (timeBin.mFirstIdx < 0) {
95 timeBin.mFirstIdx = iRof;
97 timeBin.mLastIdx = iRof;
100 if (mImprovePeakSearch) {
101 auto rofDigits = mDigits.subspan(rof.getFirstIdx(), rof.getNEntries());
102 for (
auto& digit : rofDigits) {
103 if (mIsGoodDigit(digit)) {
108 nDigitsPS = rof.getNEntries();
110 timeBin.mNDigitsPS += nDigitsPS;
114 std::cout <<
"Peak search histogram:" << std::endl;
115 for (int32_t
i = 0;
i < mNbinsInOneTF;
i++) {
116 if (mTimeBins[
i].mFirstIdx >= 0) {
117 auto nDigits = mInputROFs[mTimeBins[
i].mLastIdx].getLastIdx() - mInputROFs[mTimeBins[
i].mFirstIdx].getFirstIdx() + 1;
118 std::cout << fmt::format(
"bin {}: {}/{}",
i, mTimeBins[
i].mNDigitsPS, nDigits) << std::endl;
126int32_t ROFTimeClusterFinder::getNextPeak()
128 int32_t sPadding = mNbinsInOneWindow / 2;
131 std::cout <<
"Searching peak from " << mLastSavedTimeBin + 1 << std::endl;
136 for (int32_t
i = mLastSavedTimeBin + sPadding + 1;
i < mNbinsInOneTF;
i++) {
137 auto& peak = mTimeBins[
i];
144 for (
int j =
i - sPadding;
j <
i;
j++) {
145 if (
j >= 0 && peak <= mTimeBins[
j]) {
151 for (
int j =
i + 1;
j <=
i + sPadding;
j++) {
152 if (
j < mNbinsInOneTF && peak < mTimeBins[
j]) {
163 auto nDigits = mInputROFs[peak.mLastIdx].getLastIdx() - mInputROFs[peak.mFirstIdx].getFirstIdx() + 1;
164 std::cout << fmt::format(
"new peak found at bin {}, entries = {}/{}",
i, peak.mNDigitsPS, nDigits) << std::endl;
174void ROFTimeClusterFinder::storeROF(int32_t firstBin, int32_t lastBin)
177 std::cout << fmt::format(
"Storing ROF from bin range [{},{}]", firstBin, lastBin) << std::endl;
183 if (lastBin >= mNbinsInOneTF) {
184 lastBin = mNbinsInOneTF - 1;
187 int32_t rofFirstIdx{-1};
188 int32_t rofLastIdx{-1};
189 for (int32_t
j = firstBin;
j <= lastBin;
j++) {
190 auto& timeBin = mTimeBins[
j];
191 if (timeBin.mFirstIdx < 0) {
195 if (rofFirstIdx < 0) {
196 rofFirstIdx = timeBin.mFirstIdx;
198 rofLastIdx = timeBin.mLastIdx;
201 auto size = timeBin.mLastIdx - timeBin.mFirstIdx + 1;
202 auto nDigits = mInputROFs[timeBin.mLastIdx].getLastIdx() - mInputROFs[timeBin.mFirstIdx].getFirstIdx() + 1;
203 std::cout << fmt::format(
" bin {}: firstIdx={} size={} ndigits={}/{}",
j, timeBin.mFirstIdx,
size, timeBin.mNDigitsPS, nDigits) << std::endl;
208 if (rofFirstIdx >= 0) {
210 auto& firstRofInCluster = mInputROFs[rofFirstIdx];
211 auto&
irFirst = firstRofInCluster.getBCData();
212 auto& lastRofInCluster = mInputROFs[rofLastIdx];
213 auto&
irLast = lastRofInCluster.getBCData();
216 auto firstDigitIdx = firstRofInCluster.getFirstIdx();
217 auto nDigits = lastRofInCluster.getLastIdx() - firstDigitIdx + 1;
221 auto bcWidth = bcDiff + lastRofInCluster.getBCWidth();
224 mOutputROFs.emplace_back(
irFirst, firstDigitIdx, nDigits, bcWidth);
227 std::cout << fmt::format(
"new ROF stored: firstDigitIdx={} size={} bcWidth={}", firstDigitIdx, nDigits, bcWidth) << std::endl;
231 mLastSavedTimeBin = lastBin;
239 std::cout <<
"\n\n==================\n[ROFTimeClusterFinder] processing new TF\n"
246 mLastSavedTimeBin = -1;
248 while ((peak = getNextPeak()) >= 0) {
249 int32_t peakStart = peak - mNbinsInOneWindow / 2;
250 int32_t peakEnd = peakStart + mNbinsInOneWindow - 1;
255 std::cout << fmt::format(
"peakStart={} mLastSavedTimeBin={}", peakStart, mLastSavedTimeBin) << std::endl;
257 while ((peakStart - mLastSavedTimeBin) > 1) {
258 int32_t firstBin = mLastSavedTimeBin + 1;
259 int32_t lastBin = firstBin + mNbinsInOneWindow - 1;
260 if (lastBin >= peakStart) {
261 lastBin = peakStart - 1;
264 storeROF(firstBin, lastBin);
266 storeROF(peakStart, peakEnd);
280 bufSize = mOutputROFs.size() * sizeOfROFRecord;
288 for (
size_t i = 0;
i < mOutputROFs.size();
i++) {
289 auto& rof = mOutputROFs[
i];
290 memcpy(p, &(rof), sizeOfROFRecord);
294 return reinterpret_cast<char*
>(
buf);
301 for (
size_t i = 0;
i < mInputROFs.size();
i++) {
302 auto& rof = mInputROFs[
i];
303 const auto ir = rof.getBCData();
304 std::cout << fmt::format(
" ROF {} RANGE {}-{} SIZE {} IR {}-{},{}\n",
i, rof.getFirstIdx(), rof.getLastIdx(),
313 for (
size_t i = 0;
i < mOutputROFs.size();
i++) {
314 auto& rof = mOutputROFs[
i];
315 std::cout << fmt::format(
" ROF {} RANGE {}-{} SIZE {} IR {}-{},{}\n",
i, rof.getFirstIdx(), rof.getLastIdx(),
316 rof.getNEntries(), rof.getBCData().orbit, rof.getBCData().bc, rof.getBCData().toLong());
Class to group the fired pads according to their time stamp.
char * saveROFRsToBuffer(size_t &bufSize)
stores the output ROFs into a flat memory buffer
ROFTimeClusterFinder(gsl::span< const o2::mch::ROFRecord > rofs, gsl::span< const o2::mch::Digit > digits, uint32_t timeClusterSize, uint32_t nBins, bool improvePeakSearch, bool debug)
void process()
process the digit ROFs and create the time clusters
void dumpInputROFs()
debugging output
GLenum GLuint GLenum GLsizei const GLchar * buf
DigitFilter createDigitFilter(uint32_t minADC, bool rejectBackground, bool selectSignal, const StatusMap &statusMap={}, uint32_t statusMask=0)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
uint16_t bc
bunch crossing ID of interaction
int64_t differenceInBC(const InteractionRecord &other) const
o2::InteractionRecord ir(0, 0)
std::vector< Digit > digits