30#include <fmt/format.h>
44 DigitFilteringTask(
bool useMC,
bool useStatusMap) : mUseMC{useMC}, mUseStatusMap{useStatusMap} {}
57 auto stop = [
this]() {
58 LOG(info) <<
"digit filtering duration = "
59 << std::chrono::duration<double, std::milli>(mElapsedTime).count() <<
" ms";
66 for (
auto i = 0;
i < rofs.size();
i++) {
71 for (
auto i = 0;
i <
digits.size();
i++) {
82 auto iRofs = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs");
83 auto iDigits = pc.
inputs().
get<gsl::span<Digit>>(
"digits");
89 auto tStart = std::chrono::high_resolution_clock::now();
92 if (tinfo.runNumber != 0) {
93 mRunNumber = tinfo.runNumber;
97 LOGP(info,
"performing sanity checks");
101 if (error.nofOutOfBounds > 0) {
103 LOGP(error,
"in a TF with {} rofs and {} digits", iRofs.size(), iDigits.size());
120 bool selectSignal =
false;
124 statusMap ? *statusMap : defaultStatusMap,
134 for (
const auto& irof : iRofs) {
135 const auto digits = iDigits.subspan(irof.getFirstIdx(), irof.getNEntries());
138 for (
auto i = 0;
i <
digits.size();
i++) {
142 if (mDigitModifier) {
143 mDigitModifier(digit);
147 if (mIsGoodDigit(digit)) {
148 oDigits.emplace_back(digit);
150 oLabels->addElements(oLabels->getIndexedSize(), iLabels->getLabels(
i + irof.getFirstIdx()));
155 int nofGoodDigits = oDigits.size() - cursor;
156 if (nofGoodDigits > 0) {
159 oRofs.emplace_back(
ROFRecord(irof.getBCData(),
163 cursor += nofGoodDigits;
168 auto labelMsg = mUseMC ? fmt::format(
"| {} labels (out of {})", oLabels->getNElements(), iLabels->getNElements()) :
"";
170 LOGP(info,
"Kept after filtering : {} rofs (out of {}) | {} digits (out of {}) {}",
171 oRofs.size(), iRofs.size(),
172 oDigits.size(), iDigits.size(),
175 if (mTimeCalib != 0) {
180 LOGP(error,
"Sanity check failed");
182 auto tEnd = std::chrono::high_resolution_clock::now();
183 mElapsedTime += tEnd - tStart;
188 bool mRejectBackground{
false};
189 bool mSanityCheck{
false};
191 bool mUseStatusMap{
false};
193 int32_t mTimeCalib{0};
194 uint32_t mStatusMask{0};
195 bool mUpdateDigitsST1{
false};
196 bool mUpdateDigitsST2{
false};
199 std::chrono::duration<double> mElapsedTime{};
205 std::string_view inputDigitDataDescription,
206 std::string_view outputDigitDataDescription,
207 std::string_view inputDigitRofDataDescription,
208 std::string_view outputDigitRofDataDescription,
209 std::string_view inputDigitLabelDataDescription,
210 std::string_view outputDigitLabelDataDescription)
214 fmt::format(
"digits:MCH/{}/0;rofs:MCH/{}/0",
215 inputDigitDataDescription,
216 inputDigitRofDataDescription);
218 input += fmt::format(
";labels:MCH/{}/0", inputDigitLabelDataDescription);
224 input +=
";statusmap:MCH/STATUSMAP/0";
228 fmt::format(
"digits:MCH/{}/0;rofs:MCH/{}/0",
229 outputDigitDataDescription,
230 outputDigitRofDataDescription);
232 output += fmt::format(
";labels:MCH/{}/0", outputDigitLabelDataDescription);
235 std::vector<OutputSpec> outputs;
237 for (
auto& matcher : matchers) {
245 AlgorithmSpec{adaptFromTask<DigitFilteringTask>(useMC, useStatusMap)},
Definition of a container to keep Monte Carlo truth external to simulation objects.
static const DigitFilterParam & Instance()
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
void run(ProcessingContext &pc)
DigitFilteringTask(bool useMC, bool useStatusMap)
void init(InitContext &ic)
void shiftDigitsTime(gsl::span< ROFRecord > rofs, gsl::span< Digit > digits)
MCH digit implementation.
const BCData & getBCData() const
get the interaction record
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getDigitFilteringSpec(bool useMC, std::string_view specName="mch-digit-filtering", std::string_view inputDigitDataDescription="DIGITS", std::string_view outputDigitDataDescription="F-DIGITS", std::string_view inputDigitRofDataDescription="DIGITROFS", std::string_view outputDigitRofDataDescription="F-DIGITROFS", std::string_view inputDigitLabelDataDescription="DIGITLABELS", std::string_view outputDigitLabelDataDescription="F-DIGITLABELS")
std::string asString(const o2::mch::TrackMCH &t)
std::function< void(Digit &)> DigitModifier
std::function< bool(const Digit &)> DigitFilter
DigitFilter createDigitFilter(uint32_t minADC, bool rejectBackground, bool selectSignal, const StatusMap &statusMap={}, uint32_t statusMask=0)
bool isOK(const SanityError &error)
SanityError sanityCheck(gsl::span< const ROFRecord > rofs, gsl::span< const T > items)
DigitModifier createDigitModifier(int runNumber, bool updateST1, bool updateST2)
static OutputSpec asOutputSpec(InputSpec const &spec)
uint32_t statusMask
mask to reject digits based on the statusmap (0 = no rejection)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits