Skip to content

Commit 419788c

Browse files
TPC SCD: write and read the MC truth of the residual tracks via the ROOT files (#15943)
With --enable-mc the interpolation workflow writes the TrackDataMC vector as branch tracksMC of o2residuals_tpc.root (with --send-track-data), and the residual aggregator reads it back from there, so the MC truth no longer needs the aggregator to run directly behind the interpolation workflow (disable-root-input). This is the setup of the O2DPG MC workflow, where both run as separate tasks. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1409648 commit 419788c

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualWriterSpec.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace tpc
2222
{
2323

2424
/// create a processor spec
25-
framework::DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput);
25+
framework::DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput, bool writeTrackDataMC);
2626

2727
} // namespace tpc
2828
} // namespace o2

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,28 @@ namespace tpc
3030
class TPCUnbinnedResidualReader : public o2::framework::Task
3131
{
3232
public:
33-
TPCUnbinnedResidualReader(bool trkInput) : mTrackInput(trkInput){};
33+
TPCUnbinnedResidualReader(bool trkInput, bool mcInput) : mTrackInput(trkInput), mMCInput(mcInput) {};
3434
~TPCUnbinnedResidualReader() override = default;
3535
void init(o2::framework::InitContext& ic) final;
3636
void run(o2::framework::ProcessingContext& pc) final;
3737

3838
private:
3939
void connectTree();
4040
bool mTrackInput = false;
41+
bool mMCInput = false;
4142
std::unique_ptr<TFile> mFileIn;
4243
std::unique_ptr<TTree> mTreeIn;
4344
std::string mInFileName;
4445
std::string mInTreeName;
4546
std::vector<UnbinnedResid> mUnbinnedResid, *mUnbinnedResidPtr = &mUnbinnedResid;
4647
std::vector<DetInfoResid> mDetInfoUnbRes, *mDetInfoUnbResPtr = &mDetInfoUnbRes;
4748
std::vector<TrackData> mTrackData, *mTrackDataPtr = &mTrackData;
49+
std::vector<TrackDataMC> mTrackDataMC, *mTrackDataMCPtr = &mTrackDataMC;
4850
std::vector<TrackDataCompact> mTrackDataCompact, *mTrackDataCompactPtr = &mTrackDataCompact;
4951
};
5052

51-
/// read unbinned TPC residuals and reference tracks from a root file
52-
framework::DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput);
53+
/// read unbinned TPC residuals and reference tracks (with mcInput also their MC truth) from a root file
54+
framework::DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput, bool mcInput);
5355

5456
} // namespace tpc
5557
} // namespace o2

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace tpc
2929
template <typename T>
3030
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
3131

32-
DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput)
32+
DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput, bool writeTrackDataMC)
3333
{
3434
bool writeUnfiltered = SpacePointsCalibConfParam::Instance().writeUnfiltered;
3535
return MakeRootTreeWriterSpec("tpc-residuals-writer",
@@ -39,6 +39,7 @@ DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput
3939
BranchDefinition<std::vector<DetInfoResid>>{InputSpec{"detInfo", "GLO", "DETINFORES"}, "detInfo"},
4040
BranchDefinition<std::vector<TrackDataCompact>>{InputSpec{"trackRefs", "GLO", "TRKREFS"}, "trackRefs"},
4141
BranchDefinition<std::vector<TrackData>>{InputSpec{"tracks", "GLO", "TRKDATA"}, "tracks", (writeTrackData ? 1 : 0)},
42+
BranchDefinition<std::vector<TrackDataMC>>{InputSpec{"tracksMC", "GLO", "TRKDATAMC"}, "tracksMC", (writeTrackDataMC ? 1 : 0)},
4243
BranchDefinition<std::vector<TrackDataExtended>>{InputSpec{"trackExt", "GLO", "TRKDATAEXT"}, "trackExt", (debugOutput ? 1 : 0)})();
4344
}
4445

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ void TPCUnbinnedResidualReader::connectTree()
5252
if (mTrackInput) {
5353
mTreeIn->SetBranchAddress("tracks", &mTrackDataPtr);
5454
}
55+
if (mMCInput) {
56+
if (!mTreeIn->GetBranch("tracksMC")) {
57+
LOG(fatal) << "No tracksMC branch found in the unbinned residuals tree, the interpolation workflow must run with --enable-mc";
58+
}
59+
mTreeIn->SetBranchAddress("tracksMC", &mTrackDataMCPtr);
60+
}
5561
LOG(info) << "Loaded tree from " << mInFileName << " with " << mTreeIn->GetEntries() << " entries";
5662
}
5763

@@ -68,14 +74,17 @@ void TPCUnbinnedResidualReader::run(ProcessingContext& pc)
6874
LOG(info) << "Pushing " << mTrackData.size() << " reference tracks for these residuals";
6975
pc.outputs().snapshot(Output{"GLO", "TRKDATA", 0}, mTrackData);
7076
}
77+
if (mMCInput) {
78+
pc.outputs().snapshot(Output{"GLO", "TRKDATAMC", 0}, mTrackDataMC);
79+
}
7180

7281
if (mTreeIn->GetReadEntry() + 1 >= mTreeIn->GetEntries()) {
7382
pc.services().get<ControlService>().endOfStream();
7483
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
7584
}
7685
}
7786

78-
DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput)
87+
DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput, bool mcInput)
7988
{
8089
std::vector<OutputSpec> outputs;
8190
outputs.emplace_back("GLO", "UNBINNEDRES", 0, Lifetime::Timeframe);
@@ -84,12 +93,15 @@ DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput)
8493
if (trkInput) {
8594
outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe);
8695
}
96+
if (mcInput) {
97+
outputs.emplace_back("GLO", "TRKDATAMC", 0, Lifetime::Timeframe);
98+
}
8799

88100
return DataProcessorSpec{
89101
"TPCUnbinnedResidualReader",
90102
Inputs{},
91103
outputs,
92-
AlgorithmSpec{adaptFromTask<TPCUnbinnedResidualReader>(trkInput)},
104+
AlgorithmSpec{adaptFromTask<TPCUnbinnedResidualReader>(trkInput, mcInput)},
93105
Options{
94106
{"input-filename", VariantType::String, "o2residuals_tpc.root", {"Name of the input file"}},
95107
{"input-dir", VariantType::String, "none", {"Input directory"}},

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-interpolation-workflow.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
113113

114114
specs.emplace_back(o2::tpc::getTPCInterpolationSpec(srcClusters, srcVtx, srcTracks, srcTracksMap, useMC, processITSTPConly, sendTrackData, debugOutput, extDetResid, doStag));
115115
if (!configcontext.options().get<bool>("disable-root-output")) {
116-
specs.emplace_back(o2::tpc::getTPCResidualWriterSpec(sendTrackData, debugOutput));
116+
specs.emplace_back(o2::tpc::getTPCResidualWriterSpec(sendTrackData, debugOutput, useMC && sendTrackData));
117117
}
118118

119119
// MC labels only for the ITS-TPC tracks and their ITS and TPC parts (see getTPCInterpolationSpec)

‎Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-residual-aggregator.cxx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
5353
LOG(error) << "MC truth input requires the track input (enable-track-input), will be ignored";
5454
mcInput = false;
5555
}
56-
if (mcInput && !configcontext.options().get<bool>("disable-root-input")) {
57-
LOG(fatal) << "MC truth input is only supported directly from the interpolation workflow (disable-root-input)";
58-
}
5956

6057
bool writeUnbinnedResiduals = false;
6158
bool writeBinnedResiduals = false;
@@ -85,7 +82,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
8582

8683
WorkflowSpec specs;
8784
if (!configcontext.options().get<bool>("disable-root-input")) {
88-
specs.emplace_back(o2::tpc::getUnbinnedTPCResidualsReaderSpec(trkInput));
85+
specs.emplace_back(o2::tpc::getUnbinnedTPCResidualsReaderSpec(trkInput, mcInput));
8986
}
9087
specs.emplace_back(getTPCResidualAggregatorSpec(trkInput, ctpInput, writeUnbinnedResiduals, writeBinnedResiduals, writeTrackData, mcInput));
9188

0 commit comments

Comments
 (0)