Project
Loading...
Searching...
No Matches
TrackAndClusterFilterSpec.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 <vector>
13#include <string>
14#include "fmt/format.h"
15
16#include "Framework/Task.h"
19#include "Framework/Logger.h"
22
26#include "Headers/DataHeader.h"
30
31using namespace o2::framework;
33
34namespace o2::tpc
35{
36
38{
39 public:
41 TrackAndClusterFilterDevice(bool writeMC) { mTrackDump.writeMC = writeMC; };
42
44 {
45 mTrackDump.outputFileName = ic.options().get<std::string>("output-file");
46 mTrackDump.writeTracks = !ic.options().get<bool>("dont-write-tracks");
47 mTrackDump.writeGlobal = ic.options().get<bool>("write-global-cluster-info");
48
49 // cluster write types
51 const auto clWriteType = ic.options().get<int>("clusters-write-type");
52 if (clWriteType >= 0 && clWriteType <= 3) {
53 mTrackDump.clusterStorageType = (TrackDump::ClStorageType)clWriteType;
54 } else {
55 LOGP(error, "clWriteType {} unknown, using default", clWriteType);
56 }
57
59 const auto clNoTrackWriteType = ic.options().get<int>("notrack-clusters-write-type");
60 if (clNoTrackWriteType >= 0 && clNoTrackWriteType <= 2) {
61 mTrackDump.noTrackClusterType = (TrackDump::ClUnStorageType)clNoTrackWriteType;
62 } else {
63 LOGP(error, "clNoTrackWriteType {} unknown, using default", clNoTrackWriteType);
64 }
65
66 // track cuts
67 const double mindEdx = ic.options().get<double>("min-dedx");
68 const double maxdEdx = ic.options().get<double>("max-dedx");
69 const double minP = ic.options().get<double>("min-momentum");
70 const double maxP = ic.options().get<double>("max-momentum");
71 const int minClusters = std::max(10, ic.options().get<int>("min-clusters"));
72
73 mCuts.setPMin(minP);
74 mCuts.setPMax(maxP);
75 mCuts.setNClusMin(minClusters);
76 mCuts.setdEdxMin(mindEdx);
77 mCuts.setdEdxMax(maxdEdx);
78 }
79
81 {
82 // for (auto const& ref : pc.inputs()) {
83 // const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
84 // LOGP(info, "Specifier: {}/{}/{} Part {} of {}", dh->dataOrigin, dh->dataDescription, dh->subSpecification, dh->splitPayloadIndex, dh->splitPayloadParts);
85 // }
86 const auto tracks = pc.inputs().get<gsl::span<o2::tpc::TrackTPC>>("trackTPC");
87 const auto clRefs = pc.inputs().get<gsl::span<o2::tpc::TPCClRefElem>>("trackTPCClRefs");
88 const auto mcLabel = (mTrackDump.writeMC) ? pc.inputs().get<gsl::span<o2::MCCompLabel>>("trackTPCMCTruth") : gsl::span<o2::MCCompLabel>();
89 const auto& clustersInputs = getWorkflowTPCInput(pc);
90
91 std::vector<TrackTPC> filteredTracks;
92 std::vector<o2::MCCompLabel> filteredMCLabels;
93 for (size_t iTrack = 0; iTrack < tracks.size(); iTrack++) {
94 if (mCuts.goodTrack(tracks[iTrack])) {
95 filteredTracks.emplace_back(tracks[iTrack]);
96 if (mTrackDump.writeMC) {
97 filteredMCLabels.emplace_back(mcLabel[iTrack]);
98 }
99 }
100 }
101
102 LOGP(info, "Filtered {} good tracks with {} MC labels out of {} total tpc tracks", filteredTracks.size(), filteredMCLabels.size(), tracks.size());
103
104 mTrackDump.filter(filteredTracks, clustersInputs->clusterIndex, clRefs, filteredMCLabels);
105 }
106
108 {
109 stop();
110 }
111
112 void stop() final
113 {
114 mTrackDump.finalize();
115 }
116
117 private:
118 TrackDump mTrackDump;
119 TrackCuts mCuts{};
120};
121
122DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr, const bool writeMC)
123{
124 std::vector<InputSpec> inputs;
125 std::vector<OutputSpec> outputs;
126 o2::header::DataDescription dataDescription;
127 if (dataDescriptionStr.size() > dataDescription.size + 1) {
128 LOGP(fatal, "Size of {} is larger than {}", dataDescriptionStr, dataDescription.size);
129 }
130 for (size_t i = 0; i < dataDescriptionStr.size(); ++i) {
131 dataDescription.str[i] = dataDescriptionStr[i];
132 }
133 inputs.emplace_back("trackTPC", "TPC", dataDescription, 0, Lifetime::Timeframe);
134 inputs.emplace_back("trackTPCClRefs", "TPC", "CLUSREFS", 0, Lifetime::Timeframe);
135 inputs.emplace_back("clusTPC", ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}, Lifetime::Timeframe);
136 if (writeMC) {
137 inputs.emplace_back("trackTPCMCTruth", "TPC", "TRACKSMCLBL", 0, Lifetime::Timeframe);
138 }
139
140 return DataProcessorSpec{
141 "tpc-track-and-cluster-filter",
142 inputs,
143 outputs,
144 AlgorithmSpec{adaptFromTask<TrackAndClusterFilterDevice>(writeMC)},
145 Options{
146 {"output-file", VariantType::String, "filtered-tracks-and-clusters.root", {"output file name"}},
147 {"dont-write-tracks", VariantType::Bool, false, {"don't dump filtered tracks and clusters"}},
148 {"write-global-cluster-info", VariantType::Bool, false, {"write simple clusters tree"}},
149 {"clusters-write-type", VariantType::Int, 0, {"how to store clusters associated to tracks: 0 - vector in track, 1 - separate branch, 2 - separate tree, 3 - spearate file"}},
150 {"notrack-clusters-write-type", VariantType::Int, 0, {"clusters not associated to tracks: 0 - don't write, 1 - separate tree, 2 - spearate file"}},
151 {"min-dedx", VariantType::Double, 20., {"minimum dEdx cut"}},
152 {"max-dedx", VariantType::Double, 1e10, {"maximum dEdx cut"}},
153 {"min-momentum", VariantType::Double, 0.2, {"minimum momentum cut"}},
154 {"max-momentum", VariantType::Double, 1e10, {"maximum momentum cut"}},
155 {"min-clusters", VariantType::Int, 60, {"minimum number of clusters in a track"}},
156 } // end Options
157 }; // end DataProcessorSpec
158}
159} // namespace o2::tpc
Utils and constants for calibration and related workflows.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
int32_t i
Helper class to obtain TPC clusters / digits / labels from DPL.
o2::header::DataHeader::SubSpecificationType SubSpecificationType
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &) final
This is invoked whenever we have an EndOfStream event.
void stop() final
This is invoked on stop.
void init(o2::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 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
The class can be used to dump track and associated clusters to a tree to easily iterate over them and...
Definition TrackDump.h:41
ClStorageType clusterStorageType
instead of storing the clusters with the tracks, store them in a separate tree
Definition TrackDump.h:121
ClUnStorageType
how to store clusters NOT associated to tracks
Definition TrackDump.h:105
bool writeTracks
write global cluster information for quick drawing
Definition TrackDump.h:118
bool writeMC
write MC track information for quick drawing
Definition TrackDump.h:120
void filter(const gsl::span< const TrackTPC > tracks, ClusterNativeAccess const &clusterIndex, const gsl::span< const o2::tpc::TPCClRefElem > clRefs, const gsl::span< const MCCompLabel > mcLabels)
Definition TrackDump.cxx:29
ClUnStorageType noTrackClusterType
store unassociated clusters in separate tree
Definition TrackDump.h:122
bool writeGlobal
write global cluster information for quick drawing
Definition TrackDump.h:119
std::string outputFileName
Name of the output file with the tree.
Definition TrackDump.h:117
ClStorageType
how to store clusters associated to tracks
Definition TrackDump.h:97
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
Global TPC definitions and constants.
Definition SimTraits.h:167
o2::framework::DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr="TRACKS", const bool writeMC=false)
static int constexpr size
Definition DataHeader.h:211