Project
Loading...
Searching...
No Matches
DigitFilteringSpec.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
13
18#include "Framework/Logger.h"
20#include "Framework/Task.h"
22#include "MCHBase/SanityCheck.h"
23#include "MCHStatus/StatusMap.h"
30#include <fmt/format.h>
31#include <functional>
32#include <iostream>
33#include <string>
34#include <vector>
35
36using namespace o2::dataformats;
37using namespace o2::framework;
38
39namespace o2::mch
40{
42{
43 public:
44 DigitFilteringTask(bool useMC, bool useStatusMap) : mUseMC{useMC}, mUseStatusMap{useStatusMap} {}
45
46 void init(InitContext& ic)
47 {
48 mSanityCheck = DigitFilterParam::Instance().sanityCheck;
49 mMinADC = DigitFilterParam::Instance().minADC;
50 mRejectBackground = DigitFilterParam::Instance().rejectBackground;
51 mStatusMask = DigitFilterParam::Instance().statusMask;
52 mTimeCalib = DigitFilterParam::Instance().timeOffset;
53
54 mUpdateDigitsST1 = DigitModifierParam::Instance().updateST1;
55 mUpdateDigitsST2 = DigitModifierParam::Instance().updateST2;
56
57 auto stop = [this]() {
58 LOG(info) << "digit filtering duration = "
59 << std::chrono::duration<double, std::milli>(mElapsedTime).count() << " ms";
60 };
61 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(stop);
62 }
63
64 void shiftDigitsTime(gsl::span<ROFRecord> rofs, gsl::span<Digit> digits)
65 {
66 for (auto i = 0; i < rofs.size(); i++) {
67 ROFRecord& rof = rofs[i];
68 rof.getBCData() += mTimeCalib;
69 }
70
71 for (auto i = 0; i < digits.size(); i++) {
72 Digit& d = digits[i];
73 d.setTime(d.getTime() + mTimeCalib);
74 }
75 }
76
78 {
79 StatusMap defaultStatusMap;
80
81 // get input
82 auto iRofs = pc.inputs().get<gsl::span<ROFRecord>>("rofs");
83 auto iDigits = pc.inputs().get<gsl::span<Digit>>("digits");
84 auto iLabels = mUseMC ? pc.inputs().get<MCTruthContainer<MCCompLabel>*>("labels") : nullptr;
85 auto statusMap = mUseStatusMap && pc.inputs().isValid("statusmap") ? pc.inputs().get<StatusMap*>("statusmap") : nullptr;
86
87 bool abort{false};
88
89 auto tStart = std::chrono::high_resolution_clock::now();
90
91 const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
92 if (tinfo.runNumber != 0) {
93 mRunNumber = tinfo.runNumber;
94 }
95
96 if (mSanityCheck) {
97 LOGP(info, "performing sanity checks");
98 auto error = sanityCheck(iRofs, iDigits);
99
100 if (!isOK(error)) {
101 if (error.nofOutOfBounds > 0) {
102 LOGP(error, "{}", asString(error));
103 LOGP(error, "in a TF with {} rofs and {} digits", iRofs.size(), iDigits.size());
104 abort = true;
105 }
106 }
107 }
108
109 // create the output messages
110 auto& oRofs = pc.outputs().make<std::vector<ROFRecord>>(OutputRef{"rofs"});
111 auto& oDigits = pc.outputs().make<std::vector<Digit>>(OutputRef{"digits"});
112 auto oLabels = mUseMC ? &pc.outputs().make<MCTruthContainer<MCCompLabel>>(OutputRef{"labels"}) : nullptr;
113
114 if (!abort) {
115
116 mDigitModifier = createDigitModifier(mRunNumber,
117 mUpdateDigitsST1,
118 mUpdateDigitsST2);
119
120 bool selectSignal = false;
121 mIsGoodDigit = createDigitFilter(mMinADC,
122 mRejectBackground,
123 selectSignal,
124 statusMap ? *statusMap : defaultStatusMap,
125 mStatusMask);
126 // at digit filtering stage it is important to keep the 3rd parameter
127 // (selectSignal) to false in the call above : the idea is to not cut
128 // too much on the tails of the charge distributions otherwise
129 // the clustering resolution will suffer.
130 // That's why we only apply the "reject background" filter, which
131 // is a loose background cut that does not penalize the signal
132
133 int cursor{0};
134 for (const auto& irof : iRofs) {
135 const auto digits = iDigits.subspan(irof.getFirstIdx(), irof.getNEntries());
136
137 // filter the digits from the current ROF
138 for (auto i = 0; i < digits.size(); i++) {
139 auto digit = digits[i];
140
141 // modify the digit if needed
142 if (mDigitModifier) {
143 mDigitModifier(digit);
144 }
145
146 // check the digit quality
147 if (mIsGoodDigit(digit)) {
148 oDigits.emplace_back(digit);
149 if (iLabels) {
150 oLabels->addElements(oLabels->getIndexedSize(), iLabels->getLabels(i + irof.getFirstIdx()));
151 }
152 }
153 }
154
155 int nofGoodDigits = oDigits.size() - cursor;
156 if (nofGoodDigits > 0) {
157 // we create an ouput ROF only if at least one digit from
158 // the input ROF passed the filtering
159 oRofs.emplace_back(ROFRecord(irof.getBCData(),
160 cursor,
161 nofGoodDigits,
162 irof.getBCWidth()));
163 cursor += nofGoodDigits;
164 }
165 }
166 }
167
168 auto labelMsg = mUseMC ? fmt::format("| {} labels (out of {})", oLabels->getNElements(), iLabels->getNElements()) : "";
169
170 LOGP(info, "Kept after filtering : {} rofs (out of {}) | {} digits (out of {}) {}",
171 oRofs.size(), iRofs.size(),
172 oDigits.size(), iDigits.size(),
173 labelMsg);
174
175 if (mTimeCalib != 0) {
176 shiftDigitsTime(oRofs, oDigits);
177 }
178
179 if (abort) {
180 LOGP(error, "Sanity check failed");
181 }
182 auto tEnd = std::chrono::high_resolution_clock::now();
183 mElapsedTime += tEnd - tStart;
184 }
185
186 private:
187 int mRunNumber{0};
188 bool mRejectBackground{false};
189 bool mSanityCheck{false};
190 bool mUseMC{false};
191 bool mUseStatusMap{false};
192 int mMinADC{1};
193 int32_t mTimeCalib{0};
194 uint32_t mStatusMask{0};
195 bool mUpdateDigitsST1{false};
196 bool mUpdateDigitsST2{false};
197 DigitFilter mIsGoodDigit;
198 DigitModifier mDigitModifier;
199 std::chrono::duration<double> mElapsedTime{};
200};
201
204 std::string_view specName,
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)
211
212{
213 std::string input =
214 fmt::format("digits:MCH/{}/0;rofs:MCH/{}/0",
215 inputDigitDataDescription,
216 inputDigitRofDataDescription);
217 if (useMC) {
218 input += fmt::format(";labels:MCH/{}/0", inputDigitLabelDataDescription);
219 }
220
221 bool useStatusMap = DigitFilterParam::Instance().statusMask != 0;
222
223 if (useStatusMap) {
224 input += ";statusmap:MCH/STATUSMAP/0";
225 }
226
227 std::string output =
228 fmt::format("digits:MCH/{}/0;rofs:MCH/{}/0",
229 outputDigitDataDescription,
230 outputDigitRofDataDescription);
231 if (useMC) {
232 output += fmt::format(";labels:MCH/{}/0", outputDigitLabelDataDescription);
233 }
234
235 std::vector<OutputSpec> outputs;
236 auto matchers = select(output.c_str());
237 for (auto& matcher : matchers) {
238 outputs.emplace_back(DataSpecUtils::asOutputSpec(matcher));
239 }
240
241 return DataProcessorSpec{
242 specName.data(),
243 Inputs{select(input.c_str())},
244 outputs,
245 AlgorithmSpec{adaptFromTask<DigitFilteringTask>(useMC, useStatusMap)},
246 Options{}};
247}
248} // namespace o2::mch
std::vector< framework::ConcreteDataMatcher > matchers
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
char error[CURL_ERROR_SIZE]
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the MCH ROFrame record.
const char * specName
A container to hold and manage MC truth information/labels.
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
Definition InitContext.h:34
bool isValid(std::string const &s) const
Helper method to be used to check if a given part of the InputRecord is present.
decltype(auto) get(R binding, int part=0) const
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 shiftDigitsTime(gsl::span< ROFRecord > rofs, gsl::span< Digit > digits)
MCH digit implementation.
Definition Digit.h:31
const BCData & getBCData() const
get the interaction record
Definition ROFRecord.h:46
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
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)
Definition TrackMCH.cxx:104
std::function< void(Digit &)> DigitModifier
std::function< bool(const Digit &)> DigitFilter
Definition DigitFilter.h:21
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)
Definition SanityCheck.h:48
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