Skip to content

Commit aab9bb3

Browse files
mhemmer-cerndavidrohr
authored andcommitted
Detector/TPC: Added option to add MC information to track and cluster filter
- Fixed bug where unfiltered tracks were propagated instead of filtered tracks
1 parent ead2d61 commit aab9bb3

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

Detectors/TPC/calibration/include/TPCCalibration/TrackDump.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <vector>
2121

2222
#include "DataFormatsTPC/TrackTPC.h"
23+
#include "SimulationDataFormat/MCCompLabel.h"
2324
#include "CommonUtils/TreeStreamRedirector.h"
2425

2526
/// \file TrackDump.h
@@ -76,12 +77,13 @@ class TrackDump
7677
ClassDefNV(TrackInfo, 1);
7778
};
7879

79-
void filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAccess const& clusterIndex, const gsl::span<const o2::tpc::TPCClRefElem> clRefs);
80+
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);
8081
void finalize();
8182

8283
std::string outputFileName{"filtered-tracks-and-clusters.root"}; ///< Name of the output file with the tree
8384
bool writeTracks{true}; ///< write global cluster information for quick drawing
8485
bool writeGlobal{false}; ///< write global cluster information for quick drawing
86+
bool writeMC{false}; ///< write MC track information for quick drawing
8587
private:
8688
std::unique_ptr<o2::utils::TreeStreamRedirector> mTreeDump; ///< Tree writer
8789
};

Detectors/TPC/calibration/src/TrackDump.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
using namespace o2::tpc;
2424
using namespace o2::tpc::constants;
2525

26-
void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAccess const& clusterIndex, const gsl::span<const o2::tpc::TPCClRefElem> clRefs)
26+
void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAccess const& clusterIndex, const gsl::span<const o2::tpc::TPCClRefElem> clRefs, const gsl::span<const o2::MCCompLabel> mcLabels)
2727
{
2828
if (!mTreeDump && outputFileName.size()) {
2929
mTreeDump = std::make_unique<utils::TreeStreamRedirector>(outputFileName.data(), "recreate");
@@ -32,6 +32,7 @@ void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAcce
3232
std::vector<TrackInfo> tpcTracks;
3333
std::vector<std::vector<ClusterGlobal>> clustersGlobalEvent;
3434
std::vector<ClusterGlobal>* clustersGlobal{};
35+
std::vector<o2::MCCompLabel> tpcTracksMCTruth;
3536

3637
GPUCA_NAMESPACE::gpu::GPUTPCGeometry gpuGeom;
3738

@@ -57,6 +58,11 @@ void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAcce
5758
}
5859
}
5960
}
61+
if (writeMC) {
62+
for (const auto& mcLabel : mcLabels) {
63+
tpcTracksMCTruth.emplace_back(mcLabel);
64+
}
65+
}
6066

6167
if (mTreeDump) {
6268
auto& tree = (*mTreeDump) << "tpcrec";
@@ -67,6 +73,9 @@ void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAcce
6773
if (writeGlobal) {
6874
tree << "cls" << clustersGlobalEvent;
6975
}
76+
if (writeMC) {
77+
tree << "TPCTracksMCTruth=" << tpcTracksMCTruth;
78+
}
7079
tree << "\n";
7180
// << "clusters=" << clInfoVec
7281
}

Detectors/TPC/workflow/include/TPCWorkflow/TrackAndClusterFilterSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace o2::tpc
2525

2626
/// create a processor spec
2727
/// read simulated TPC clusters from file and publish
28-
o2::framework::DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr = "TRACKS");
28+
o2::framework::DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr = "TRACKS", const bool writeMC = false);
2929

3030
} // namespace o2::tpc
3131

Detectors/TPC/workflow/src/TrackAndClusterFilterSpec.cxx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TrackAndClusterFilterDevice : public o2::framework::Task
3838
{
3939
public:
4040
TrackAndClusterFilterDevice() = default;
41+
TrackAndClusterFilterDevice(bool writeMC) { mTrackDump.writeMC = writeMC; };
4142

4243
void init(o2::framework::InitContext& ic) final
4344
{
@@ -65,15 +66,23 @@ class TrackAndClusterFilterDevice : public o2::framework::Task
6566
// }
6667
const auto tracks = pc.inputs().get<gsl::span<o2::tpc::TrackTPC>>("trackTPC");
6768
const auto clRefs = pc.inputs().get<gsl::span<o2::tpc::TPCClRefElem>>("trackTPCClRefs");
69+
const auto mcLabel = (mTrackDump.writeMC) ? pc.inputs().get<gsl::span<o2::MCCompLabel>>("trackTPCMCTruth") : gsl::span<o2::MCCompLabel>();
6870
const auto& clustersInputs = getWorkflowTPCInput(pc);
6971

7072
std::vector<TrackTPC> filteredTracks;
71-
std::copy_if(tracks.begin(), tracks.end(), std::back_inserter(filteredTracks),
72-
[this](const auto& track) { return mCuts.goodTrack(track); });
73-
74-
LOGP(info, "Filtered {} good tracks out of {} total tpc tracks", filteredTracks.size(), tracks.size());
75-
76-
mTrackDump.filter(tracks, clustersInputs->clusterIndex, clRefs);
73+
std::vector<o2::MCCompLabel> filteredMCLabels;
74+
for (size_t iTrack = 0; iTrack < tracks.size(); iTrack++) {
75+
if (mCuts.goodTrack(tracks[iTrack])) {
76+
filteredTracks.emplace_back(tracks[iTrack]);
77+
if (mTrackDump.writeMC) {
78+
filteredMCLabels.emplace_back(mcLabel[iTrack]);
79+
}
80+
}
81+
}
82+
83+
LOGP(info, "Filtered {} good tracks with {} MC labels out of {} total tpc tracks", filteredTracks.size(), filteredMCLabels.size(), tracks.size());
84+
85+
mTrackDump.filter(filteredTracks, clustersInputs->clusterIndex, clRefs, filteredMCLabels);
7786
}
7887

7988
void endOfStream(o2::framework::EndOfStreamContext& /*ec*/) final
@@ -91,7 +100,7 @@ class TrackAndClusterFilterDevice : public o2::framework::Task
91100
TrackCuts mCuts{};
92101
};
93102

94-
DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr)
103+
DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescriptionStr, const bool writeMC)
95104
{
96105
std::vector<InputSpec> inputs;
97106
std::vector<OutputSpec> outputs;
@@ -105,12 +114,15 @@ DataProcessorSpec getTrackAndClusterFilterSpec(const std::string dataDescription
105114
inputs.emplace_back("trackTPC", "TPC", dataDescription, 0, Lifetime::Timeframe);
106115
inputs.emplace_back("trackTPCClRefs", "TPC", "CLUSREFS", 0, Lifetime::Timeframe);
107116
inputs.emplace_back("clusTPC", ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}, Lifetime::Timeframe);
117+
if (writeMC) {
118+
inputs.emplace_back("trackTPCMCTruth", "TPC", "TRACKSMCLBL", 0, Lifetime::Timeframe);
119+
}
108120

109121
return DataProcessorSpec{
110122
"tpc-track-and-cluster-filter",
111123
inputs,
112124
outputs,
113-
AlgorithmSpec{adaptFromTask<TrackAndClusterFilterDevice>()},
125+
AlgorithmSpec{adaptFromTask<TrackAndClusterFilterDevice>(writeMC)},
114126
Options{
115127
{"output-file", VariantType::String, "filtered-track-and-clusters.root", {"output file name"}},
116128
{"write-tracks", VariantType::Bool, true, {"dump filtered tracks and clusters"}},

Detectors/TPC/workflow/src/track-and-cluster-filter.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
4141
std::vector<ConfigParamSpec> options{
4242
// {"use-digit-input", VariantType::Bool, false, {"use TPC digits as input, instead of raw data"}},
4343
{"data-description", VariantType::String, "TRACKS", {"Can be used to select filterd tracks, e.g. 'LASERTRACKS', 'MIPS'"}},
44+
{"write-mc", VariantType::Bool, false, {"Can be used to write mc labels, e.g. 'TPCTracksMCTruth'"}},
4445
};
4546

4647
std::swap(workflowOptions, options);
@@ -52,10 +53,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfg)
5253
{
5354
// const bool useDigitsAsInput = cfg.options().get<bool>("use-digit-input");
5455
const auto dataDescription = cfg.options().get<std::string>("data-description");
56+
const auto writeMC = cfg.options().get<bool>("write-mc");
5557

5658
WorkflowSpec specs;
5759

58-
specs.emplace_back(o2::tpc::getTrackAndClusterFilterSpec(dataDescription));
60+
specs.emplace_back(o2::tpc::getTrackAndClusterFilterSpec(dataDescription, writeMC));
5961

6062
return specs;
6163
}

0 commit comments

Comments
 (0)