diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualWriterSpec.h b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualWriterSpec.h index 3a4492d666ad2..3ac666399d048 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualWriterSpec.h +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualWriterSpec.h @@ -22,7 +22,7 @@ namespace tpc { /// create a processor spec -framework::DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput); +framework::DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput, bool writeTrackDataMC); } // namespace tpc } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h index 724151c90576f..d94578176a05b 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h @@ -30,7 +30,7 @@ namespace tpc class TPCUnbinnedResidualReader : public o2::framework::Task { public: - TPCUnbinnedResidualReader(bool trkInput) : mTrackInput(trkInput){}; + TPCUnbinnedResidualReader(bool trkInput, bool mcInput) : mTrackInput(trkInput), mMCInput(mcInput) {}; ~TPCUnbinnedResidualReader() override = default; void init(o2::framework::InitContext& ic) final; void run(o2::framework::ProcessingContext& pc) final; @@ -38,6 +38,7 @@ class TPCUnbinnedResidualReader : public o2::framework::Task private: void connectTree(); bool mTrackInput = false; + bool mMCInput = false; std::unique_ptr mFileIn; std::unique_ptr mTreeIn; std::string mInFileName; @@ -45,11 +46,12 @@ class TPCUnbinnedResidualReader : public o2::framework::Task std::vector mUnbinnedResid, *mUnbinnedResidPtr = &mUnbinnedResid; std::vector mDetInfoUnbRes, *mDetInfoUnbResPtr = &mDetInfoUnbRes; std::vector mTrackData, *mTrackDataPtr = &mTrackData; + std::vector mTrackDataMC, *mTrackDataMCPtr = &mTrackDataMC; std::vector mTrackDataCompact, *mTrackDataCompactPtr = &mTrackDataCompact; }; -/// read unbinned TPC residuals and reference tracks from a root file -framework::DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput); +/// read unbinned TPC residuals and reference tracks (with mcInput also their MC truth) from a root file +framework::DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput, bool mcInput); } // namespace tpc } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx index 68c9b3abfe4ef..cb324ff3e8dc7 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx @@ -29,7 +29,7 @@ namespace tpc template using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition; -DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput) +DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput, bool writeTrackDataMC) { bool writeUnfiltered = SpacePointsCalibConfParam::Instance().writeUnfiltered; return MakeRootTreeWriterSpec("tpc-residuals-writer", @@ -39,6 +39,7 @@ DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData, bool debugOutput BranchDefinition>{InputSpec{"detInfo", "GLO", "DETINFORES"}, "detInfo"}, BranchDefinition>{InputSpec{"trackRefs", "GLO", "TRKREFS"}, "trackRefs"}, BranchDefinition>{InputSpec{"tracks", "GLO", "TRKDATA"}, "tracks", (writeTrackData ? 1 : 0)}, + BranchDefinition>{InputSpec{"tracksMC", "GLO", "TRKDATAMC"}, "tracksMC", (writeTrackDataMC ? 1 : 0)}, BranchDefinition>{InputSpec{"trackExt", "GLO", "TRKDATAEXT"}, "trackExt", (debugOutput ? 1 : 0)})(); } diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx index c2dae375731a4..a3c99fd2c9438 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx @@ -52,6 +52,12 @@ void TPCUnbinnedResidualReader::connectTree() if (mTrackInput) { mTreeIn->SetBranchAddress("tracks", &mTrackDataPtr); } + if (mMCInput) { + if (!mTreeIn->GetBranch("tracksMC")) { + LOG(fatal) << "No tracksMC branch found in the unbinned residuals tree, the interpolation workflow must run with --enable-mc"; + } + mTreeIn->SetBranchAddress("tracksMC", &mTrackDataMCPtr); + } LOG(info) << "Loaded tree from " << mInFileName << " with " << mTreeIn->GetEntries() << " entries"; } @@ -68,6 +74,9 @@ void TPCUnbinnedResidualReader::run(ProcessingContext& pc) LOG(info) << "Pushing " << mTrackData.size() << " reference tracks for these residuals"; pc.outputs().snapshot(Output{"GLO", "TRKDATA", 0}, mTrackData); } + if (mMCInput) { + pc.outputs().snapshot(Output{"GLO", "TRKDATAMC", 0}, mTrackDataMC); + } if (mTreeIn->GetReadEntry() + 1 >= mTreeIn->GetEntries()) { pc.services().get().endOfStream(); @@ -75,7 +84,7 @@ void TPCUnbinnedResidualReader::run(ProcessingContext& pc) } } -DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput) +DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput, bool mcInput) { std::vector outputs; outputs.emplace_back("GLO", "UNBINNEDRES", 0, Lifetime::Timeframe); @@ -84,12 +93,15 @@ DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput) if (trkInput) { outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe); } + if (mcInput) { + outputs.emplace_back("GLO", "TRKDATAMC", 0, Lifetime::Timeframe); + } return DataProcessorSpec{ "TPCUnbinnedResidualReader", Inputs{}, outputs, - AlgorithmSpec{adaptFromTask(trkInput)}, + AlgorithmSpec{adaptFromTask(trkInput, mcInput)}, Options{ {"input-filename", VariantType::String, "o2residuals_tpc.root", {"Name of the input file"}}, {"input-dir", VariantType::String, "none", {"Input directory"}}, diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-interpolation-workflow.cxx b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-interpolation-workflow.cxx index d43c10ce9c74b..ea9c432acb4ce 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-interpolation-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-interpolation-workflow.cxx @@ -113,7 +113,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) specs.emplace_back(o2::tpc::getTPCInterpolationSpec(srcClusters, srcVtx, srcTracks, srcTracksMap, useMC, processITSTPConly, sendTrackData, debugOutput, extDetResid, doStag)); if (!configcontext.options().get("disable-root-output")) { - specs.emplace_back(o2::tpc::getTPCResidualWriterSpec(sendTrackData, debugOutput)); + specs.emplace_back(o2::tpc::getTPCResidualWriterSpec(sendTrackData, debugOutput, useMC && sendTrackData)); } // MC labels only for the ITS-TPC tracks and their ITS and TPC parts (see getTPCInterpolationSpec) diff --git a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-residual-aggregator.cxx b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-residual-aggregator.cxx index d3593c1c50744..156a11cc46920 100644 --- a/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-residual-aggregator.cxx +++ b/Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/tpc-residual-aggregator.cxx @@ -53,9 +53,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) LOG(error) << "MC truth input requires the track input (enable-track-input), will be ignored"; mcInput = false; } - if (mcInput && !configcontext.options().get("disable-root-input")) { - LOG(fatal) << "MC truth input is only supported directly from the interpolation workflow (disable-root-input)"; - } bool writeUnbinnedResiduals = false; bool writeBinnedResiduals = false; @@ -85,7 +82,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) WorkflowSpec specs; if (!configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getUnbinnedTPCResidualsReaderSpec(trkInput)); + specs.emplace_back(o2::tpc::getUnbinnedTPCResidualsReaderSpec(trkInput, mcInput)); } specs.emplace_back(getTPCResidualAggregatorSpec(trkInput, ctpInput, writeUnbinnedResiduals, writeBinnedResiduals, writeTrackData, mcInput));