Project
Loading...
Searching...
No Matches
EventFinder.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18
19#include <algorithm>
20#include <iterator>
21#include <utility>
22
25
26namespace o2
27{
28namespace mch
29{
30
31//_________________________________________________________________________________________________
33void EventFinder::run(const gsl::span<const mch::ROFRecord>& mchROFs,
34 const gsl::span<const mch::Digit>& digits,
36 const gsl::span<const mid::ROFRecord>& midROFs)
37{
38 mEvents.clear();
39 mROFs.clear();
40 mDigits.clear();
41 mLabels.clear();
42
43 if (mchROFs.empty() || midROFs.empty()) {
44 return;
45 }
46
47 // create empty events ordered in increasing trigger time
48 const auto& param = EventFinderParam::Instance();
49 for (const auto& midROF : midROFs) {
50 if (midROF.nEntries == 0) {
51 continue;
52 }
53 auto midBC = midROF.interactionRecord.toLong();
54 mEvents.emplace(std::make_pair(midBC, Event(midBC + param.triggerRange[0], midBC + param.triggerRange[1])));
55 }
56
57 // associate each MCH ROF to the first compatible trigger, if any
58 for (int i = 0; i < mchROFs.size(); ++i) {
59 auto mchBC = mchROFs[i].getBCData().toLong();
60 auto itEvent = mEvents.lower_bound(mchBC - param.triggerRange[1] + 1);
61 if (itEvent != mEvents.end() && itEvent->second.trgRange[0] < mchBC + mchROFs[i].getBCWidth()) {
62 itEvent->second.iMCHROFs.push_back(i);
63 itEvent->second.maxRORange = std::max(itEvent->second.maxRORange, mchBC + mchROFs[i].getBCWidth());
64 }
65 }
66
67#pragma GCC diagnostic push // TODO: Remove once this is fixed in GCC
68#pragma GCC diagnostic ignored "-Wstringop-overflow" // TODO: Remove once this is fixed in GCC
69 // merge overlapping events (when a MCH ROF is compatible with multiple trigger) and cleanup
70 for (auto itEvent = mEvents.begin(); itEvent != mEvents.end();) {
71 if (itEvent->second.iMCHROFs.empty()) {
72 itEvent = mEvents.erase(itEvent);
73 } else {
74 auto itNextEvent = std::next(itEvent);
75 if (itNextEvent != mEvents.end() && itNextEvent->second.trgRange[0] < itEvent->second.maxRORange) {
76 itEvent->second.trgRange[1] = itNextEvent->second.trgRange[1];
77 itEvent->second.maxRORange = std::max(itEvent->second.maxRORange, itNextEvent->second.maxRORange);
78 itEvent->second.iMCHROFs.insert(itEvent->second.iMCHROFs.end(),
79 itNextEvent->second.iMCHROFs.begin(), itNextEvent->second.iMCHROFs.end());
80 mEvents.erase(itNextEvent);
81 } else {
82 itEvent = itNextEvent;
83 }
84 }
85 }
86#pragma GCC diagnostic pop // TODO: Remove once this is fixed in GCC
87
88 // merge digits associated to each event and produce the output ROFs pointing to them
89 // the BC range of each ROF is set to contain only the MID IR(s) associated to the event
91 for (const auto& event : mEvents) {
92 mDigitLoc.clear();
93 int digitOffset = mDigits.size();
94 for (auto iMCHROF : event.second.iMCHROFs) {
95 for (int iDigit = mchROFs[iMCHROF].getFirstIdx(); iDigit <= mchROFs[iMCHROF].getLastIdx(); ++iDigit) {
96 const auto& digit = digits[iDigit];
97 auto digitLoc = mDigitLoc.emplace(((digit.getDetID() << 16) | digit.getPadID()), mDigits.size());
98 if (digitLoc.second) {
99 mDigits.emplace_back(digit);
100 if (labels != nullptr) {
101 mLabels.addElements(digitLoc.first->second, labels->getLabels(iDigit));
102 }
103 } else {
104 auto& digit0 = mDigits[digitLoc.first->second];
105 digit0.setADC(digit0.getADC() + digit.getADC());
106 auto nofSamples = digit0.getNofSamples() + digit.getNofSamples();
107 digit0.setNofSamples((nofSamples > 0x3FF) ? 0x3FF : nofSamples);
108 digit0.setSaturated(digit0.isSaturated() || digit.isSaturated());
109 if (labels != nullptr) {
110 for (const auto& label : labels->getLabels(iDigit)) {
111 mLabels.addElementRandomAccess(digitLoc.first->second, label);
112 }
113 }
114 }
115 }
116 }
117 ir.setFromLong(event.first);
118 mROFs.emplace_back(ir, digitOffset, mDigits.size() - digitOffset,
119 event.second.trgRange[1] - param.triggerRange[1] - event.first + 1);
120 }
121}
122
123} // namespace mch
124} // namespace o2
Configurable parameters to group MCH digits based on MID information.
Definition of a class to group MCH digits based on MID information.
int32_t i
gsl::span< TruthElement > getLabels(uint32_t dataindex)
void addElements(uint32_t dataindex, gsl::span< CompatibleLabel > elements)
void addElementRandomAccess(uint32_t dataindex, TruthElement const &element)
void run(const gsl::span< const mch::ROFRecord > &mchROFs, const gsl::span< const mch::Digit > &digits, const dataformats::MCLabelContainer *labels, const gsl::span< const mid::ROFRecord > &midROFs)
run the event finder algorithm
struct _cl_event * event
Definition glcorearb.h:2982
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLenum GLfloat param
Definition glcorearb.h:271
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void setFromLong(int64_t l)
std::vector< o2::mid::ROFRecord > midROFs
std::vector< o2::mch::ROFRecord > mchROFs
o2::InteractionRecord ir(0, 0)
std::vector< Digit > digits