Project
Loading...
Searching...
No Matches
MIPTrackFilterSpec.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
15
17
18#include <algorithm>
19#include <iterator>
20#include <vector>
21#include <memory>
22#include <random>
23
24// o2 includes
28#include "Framework/Logger.h"
30#include "Framework/Task.h"
35#include "Headers/DataHeader.h"
36
37using namespace o2::framework;
38
39namespace o2::tpc
40{
41
43{
44 public:
45 MIPTrackFilterDevice(std::shared_ptr<o2::base::GRPGeomRequest> gr) : mGRPGeomRequest(gr) {}
46
47 void init(framework::InitContext& ic) final;
48 void run(ProcessingContext& pc) final;
49 void endOfStream(EndOfStreamContext& eos) final;
50 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
51
52 private:
53 void sendOutput(DataAllocator& output);
54
55 std::shared_ptr<o2::base::GRPGeomRequest> mGRPGeomRequest;
56 TrackCuts mCuts{};
57 std::vector<TrackTPC> mMIPTracks;
58 unsigned int mProcessEveryNthTF{1};
59 int mMaxTracksPerTF{-1};
60 uint32_t mTFCounter{0};
61 int mProcessNFirstTFs{0};
62 float mDCACut{-1};
63 bool mSendDummy{false};
64
65 bool acceptDCA(const TrackTPC& track);
66};
67
69{
70 const double minP = ic.options().get<double>("min-momentum");
71 const double maxP = ic.options().get<double>("max-momentum");
72 const double mindEdx = ic.options().get<double>("min-dedx");
73 const double maxdEdx = ic.options().get<double>("max-dedx");
74 const int minClusters = std::max(10, ic.options().get<int>("min-clusters"));
75 const auto cutLoopers = !ic.options().get<bool>("dont-cut-loopers");
76 mSendDummy = ic.options().get<bool>("send-dummy-data");
77 mMaxTracksPerTF = ic.options().get<int>("maxTracksPerTF");
78 if (mMaxTracksPerTF > 0) {
79 mMIPTracks.reserve(mMaxTracksPerTF);
80 }
81
82 mProcessEveryNthTF = ic.options().get<int>("processEveryNthTF");
83 if (mProcessEveryNthTF <= 0) {
84 mProcessEveryNthTF = 1;
85 }
86 mProcessNFirstTFs = ic.options().get<int>("process-first-n-TFs");
87
88 if (mProcessEveryNthTF > 1) {
89 std::mt19937 rng(std::time(nullptr));
90 std::uniform_int_distribution<std::mt19937::result_type> dist(1, mProcessEveryNthTF);
91 mTFCounter = dist(rng);
92 LOGP(info, "Skipping first {} TFs", mProcessEveryNthTF - mTFCounter);
93 }
94
95 mCuts.setPMin(minP);
96 mCuts.setPMax(maxP);
97 mCuts.setNClusMin(minClusters);
98 mCuts.setdEdxMin(mindEdx);
99 mCuts.setdEdxMax(maxdEdx);
100 mCuts.setCutLooper(cutLoopers);
101
102 mDCACut = ic.options().get<float>("dca-cut");
103
105}
106
108{
110 const auto currentTF = processing_helpers::getCurrentTF(pc);
111 if ((mTFCounter++ % mProcessEveryNthTF) && (currentTF >= mProcessNFirstTFs)) {
112 LOGP(info, "Skipping TF {}", currentTF);
113 mMIPTracks.clear();
114 if (mSendDummy) {
115 sendOutput(pc.outputs());
116 }
117 return;
118 }
119
120 const auto tracks = pc.inputs().get<gsl::span<TrackTPC>>("tracks");
121 const auto nTracks = tracks.size();
122
123 if ((mMaxTracksPerTF != -1) && (nTracks > mMaxTracksPerTF)) {
124 // indices to good tracks
125 std::vector<size_t> indices;
126 indices.reserve(nTracks);
127 for (size_t i = 0; i < nTracks; ++i) {
128 if (mCuts.goodTrack(tracks[i]) && acceptDCA(tracks[i])) {
129 indices.emplace_back(i);
130 }
131 }
132
133 // in case no good tracks have been found
134 if (indices.empty()) {
135 mMIPTracks.clear();
136 if (mSendDummy) {
137 sendOutput(pc.outputs());
138 }
139 return;
140 }
141
142 // shuffle indices to good tracks
143 std::minstd_rand rng(std::time(nullptr));
144 std::shuffle(indices.begin(), indices.end(), rng);
145
146 // copy good tracks
147 const int loopEnd = (mMaxTracksPerTF > indices.size()) ? indices.size() : mMaxTracksPerTF;
148 for (int i = 0; i < loopEnd; ++i) {
149 mMIPTracks.emplace_back(tracks[indices[i]]);
150 }
151 } else {
152 std::copy_if(tracks.begin(), tracks.end(), std::back_inserter(mMIPTracks), [this](const auto& track) { return mCuts.goodTrack(track) && acceptDCA(track); });
153 }
154
155 LOGP(info, "Filtered {} MIP tracks out of {} total tpc tracks", mMIPTracks.size(), tracks.size());
156 sendOutput(pc.outputs());
157 mMIPTracks.clear();
158}
159
161{
163 return;
164 }
165}
166
167void MIPTrackFilterDevice::sendOutput(DataAllocator& output) { output.snapshot(Output{header::gDataOriginTPC, "MIPS", 0}, mMIPTracks); }
168
170{
171 LOG(info) << "Finalizig MIP Tracks filter";
172}
173
174bool MIPTrackFilterDevice::acceptDCA(const TrackTPC& track)
175{
176 if (mDCACut < 0) {
177 return true;
178 }
179
180 auto propagator = o2::base::Propagator::Instance();
182 const o2::math_utils::Point3D<float> refPoint{0, 0, 0};
183 o2::track::TrackPar propTrack(track);
184 const auto ok = propagator->propagateToDCABxByBz(refPoint, propTrack, 2., o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca);
185 const auto dcar = std::abs(dca[0]);
186
187 return ok && (dcar < mDCACut);
188}
189
191{
192 std::vector<OutputSpec> outputs;
193 outputs.emplace_back(header::gDataOriginTPC, "MIPS", 0, Lifetime::Sporadic);
194
195 std::vector<InputSpec> inputs;
196 inputs.emplace_back("tracks", "TPC", "TRACKS");
197
198 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
199 true, // GRPECS=true
200 false, // GRPLHCIF
201 true, // GRPMagField
202 true, // askMatLUT
204 inputs,
205 true);
206
207 return DataProcessorSpec{
208 "tpc-miptrack-filter",
209 inputs,
210 outputs,
211 adaptFromTask<MIPTrackFilterDevice>(ggRequest),
212 Options{
213 {"min-momentum", VariantType::Double, 0.35, {"minimum momentum cut"}},
214 {"max-momentum", VariantType::Double, 0.55, {"maximum momentum cut"}},
215 {"min-dedx", VariantType::Double, 10., {"minimum dEdx cut"}},
216 {"max-dedx", VariantType::Double, 200., {"maximum dEdx cut"}},
217 {"min-clusters", VariantType::Int, 60, {"minimum number of clusters in a track"}},
218 {"processEveryNthTF", VariantType::Int, 1, {"Using only a fraction of the data: 1: Use every TF, 10: Process only every tenth TF."}},
219 {"maxTracksPerTF", VariantType::Int, -1, {"Maximum number of processed tracks per TF (-1 for processing all tracks)"}},
220 {"process-first-n-TFs", VariantType::Int, 1, {"Number of first TFs which are not sampled"}},
221 {"send-dummy-data", VariantType::Bool, false, {"Send empty data in case TF is skipped"}},
222 {"dont-cut-loopers", VariantType::Bool, false, {"Do not cut loopers by comparing zout-zin"}},
223 {"dca-cut", VariantType::Float, 3.f, {"DCA cut in cm, < 0 to disable"}},
224 }};
225}
226
227} // namespace o2::tpc
Utils and constants for calibration and related workflows.
int32_t i
Helper for geometry and GRP related CCDB requests.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Workflow to filter MIP tracks and streams them to other devices.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:143
ConfigParamRegistry const & options()
Definition InitContext.h:33
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.
void endOfStream(EndOfStreamContext &eos) final
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void run(ProcessingContext &pc) final
MIPTrackFilterDevice(std::shared_ptr< o2::base::GRPGeomRequest > gr)
void init(framework::InitContext &ic) final
track cut class
Definition TrackCuts.h:37
void setPMax(float PMax)
Definition TrackCuts.h:45
void setPMin(float PMin)
Definition TrackCuts.h:44
void setCutLooper(bool cut)
try to remove looper cutting on (abs(z_out) - abs(z_in)) < -10), not very precise
Definition TrackCuts.h:50
void setdEdxMax(float dEdxMax)
Definition TrackCuts.h:48
void setNClusMin(float NClusMin)
Definition TrackCuts.h:46
void setdEdxMin(float dEdxMin)
Definition TrackCuts.h:47
bool goodTrack(o2::tpc::TrackTPC const &track)
Definition TrackCuts.cxx:31
GLsizei GLenum const void * indices
Definition glcorearb.h:400
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::array< T, N > array
uint32_t getCurrentTF(o2::framework::ProcessingContext &pc)
Global TPC definitions and constants.
Definition SimTraits.h:167
o2::framework::DataProcessorSpec getMIPTrackFilterSpec()
create a processor spec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"