Project
Loading...
Searching...
No Matches
OccupancyFilterSpec.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
12#include <fmt/core.h>
13#include <iterator>
14#include <memory>
15#include <unordered_map>
16#include <vector>
17#include <gsl/span>
18
20#include "Framework/Task.h"
22#include "Framework/Logger.h"
24#include "Headers/DataHeader.h"
25
29
30using namespace o2::framework;
31using namespace o2::header;
33
34namespace o2::tpc
35{
36
38{
39 public:
41
43 {
44 mOccupancyThreshold = ic.options().get<float>("occupancy-threshold");
45 mAdcValueThreshold = ic.options().get<float>("adc-threshold");
46 mMinimumTimeStamp = ic.options().get<long>("min-timestamp");
47 mFilterAdcValue = ic.options().get<bool>("filter-adc");
48 mFilterTimeStamp = ic.options().get<bool>("filter-timestamp");
49 LOGP(debug, "got minimum timestamp {}", mMinimumTimeStamp);
50 }
51
53 {
54 for (auto const& inputRef : InputRecordWalker(pc.inputs())) {
55 auto const* sectorHeader = DataRefUtils::getHeader<TPCSectorHeader*>(inputRef);
56 if (sectorHeader == nullptr) {
57 LOGP(error, "sector header missing on header stack for input on ", inputRef.spec->binding);
58 continue;
59 }
60
61 const int sector = sectorHeader->sector();
62 auto inDigitsO = pc.inputs().get<std::vector<o2::tpc::Digit>>(inputRef);
63 LOGP(debug, "processing sector {} with {} input digits", sector, inDigitsO.size());
64
65 std::vector<size_t> digitsPerTimeBin(int(128 * 445.5));
66
67 for (const auto& digit : inDigitsO) {
68 if ((digit.getChargeFloat() > mAdcValueThreshold) && (digit.getTimeStamp() > mMinimumTimeStamp)) {
69 ++digitsPerTimeBin[digit.getTimeStamp()];
70 }
71 }
72
73 bool isAboveThreshold{false};
74 for (const auto& timeBinOccupancy : digitsPerTimeBin) {
75 if (timeBinOccupancy > mOccupancyThreshold) {
76 LOGP(info, "Sector {}, timeBinOccupancy {} > occupancy-threshold {}", sector, timeBinOccupancy, mOccupancyThreshold);
77 isAboveThreshold = true;
78 break;
79 }
80 }
81
82 std::vector<o2::tpc::Digit> cpDigits;
83 if (isAboveThreshold) {
84 std::copy_if(inDigitsO.begin(), inDigitsO.end(), std::back_inserter(cpDigits),
85 [this](const auto& digit) {
86 return (!mFilterTimeStamp || (digit.getTimeStamp() > mMinimumTimeStamp)) && (!mFilterAdcValue || (digit.getChargeFloat() > mAdcValueThreshold));
87 });
88 }
89 snapshot(pc.outputs(), cpDigits, sector);
90
91 ++mProcessedTFs;
92 LOGP(info, "Number of processed time frames: {}", mProcessedTFs);
93 }
94 }
95
96 private:
97 float mOccupancyThreshold{50.f};
98 float mAdcValueThreshold{0.f};
99 long mMinimumTimeStamp{0LL};
100 bool mFilterAdcValue{false};
101 bool mFilterTimeStamp{false};
102 uint32_t mProcessedTFs{0};
103
104 //____________________________________________________________________________
105 void snapshot(DataAllocator& output, std::vector<Digit>& digits, int sector)
106 {
107 o2::tpc::TPCSectorHeader header{sector};
108 header.activeSectors = (0x1 << sector);
109 output.snapshot(Output{gDataOriginTPC, "FILTERDIG", static_cast<SubSpecificationType>(sector), header}, digits);
110 }
111};
112
114{
115 using device = o2::tpc::OccupancyFilterDevice;
116
117 std::vector<InputSpec> inputs{
118 InputSpec{"digits", gDataOriginTPC, "DIGITS", 0, Lifetime::Timeframe},
119 };
120
121 std::vector<OutputSpec> outputs;
122 outputs.emplace_back(gDataOriginTPC, "FILTERDIG", 0, Lifetime::Sporadic);
123
124 return DataProcessorSpec{
125 "tpc-occupancy-filter",
126 inputs,
127 outputs,
128 AlgorithmSpec{adaptFromTask<device>()},
129 Options{
130 {"occupancy-threshold", VariantType::Float, 50.f, {"threshold for occupancy in one time bin"}},
131 {"adc-threshold", VariantType::Float, 0.f, {"threshold for adc value"}},
132 {"min-timestamp", VariantType::Int64, 0LL, {"minimum time bin"}},
133 {"filter-adc", VariantType::Bool, false, {"filter the data by the given adc threshold"}},
134 {"filter-timestamp", VariantType::Bool, false, {"filter the data by the given minimum timestamp"}},
135 } // end Options
136 }; // end DataProcessorSpec
137}
138} // namespace o2::tpc
Definition of the TPC Digit.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
A helper class to iteratate over all parts of all input routes.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Processor spec for filtering krypton raw data.
std::ostringstream debug
o2::header::DataHeader::SubSpecificationType SubSpecificationType
A helper class to iteratate over all parts of all input routes.
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
O2 data header classes and API, v0.1.
Definition DetID.h:49
Global TPC definitions and constants.
Definition SimTraits.h:167
o2::framework::DataProcessorSpec getOccupancyFilterSpec()
std::vector< Digit > digits