Skip to content

Commit c85463a

Browse files
pillotaphecetche
authored andcommitted
new option to write digits associated to tracks
1 parent 8c14295 commit c85463a

7 files changed

Lines changed: 73 additions & 21 deletions

File tree

Detectors/MUON/MCH/Workflow/include/MCHWorkflow/TrackWriterSpec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
namespace o2::mch
1818
{
19-
o2::framework::DataProcessorSpec getTrackWriterSpec(bool useMC, const char* specName = "mch-track-writer", const char* fileName = "mchtracks.root");
19+
o2::framework::DataProcessorSpec getTrackWriterSpec(bool useMC, const char* specName = "mch-track-writer",
20+
const char* fileName = "mchtracks.root", bool digits = false);
2021
}
2122

2223
#endif

Detectors/MUON/MCH/Workflow/src/TrackFinderSpec.cxx

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "DataFormatsMCH/ROFRecord.h"
4242
#include "DataFormatsMCH/TrackMCH.h"
4343
#include "DataFormatsMCH/Cluster.h"
44+
#include "DataFormatsMCH/Digit.h"
4445
#include "MCHTracking/TrackParam.h"
4546
#include "MCHTracking/Track.h"
4647
#include "MCHTracking/TrackFinder.h"
@@ -57,6 +58,9 @@ using namespace o2::framework;
5758
class TrackFinderTask
5859
{
5960
public:
61+
//_________________________________________________________________________________________________
62+
TrackFinderTask(bool digits = false) : mDigits(digits) {}
63+
6064
//_________________________________________________________________________________________________
6165
void init(framework::InitContext& ic)
6266
{
@@ -105,18 +109,22 @@ class TrackFinderTask
105109
auto clusterROFs = pc.inputs().get<gsl::span<ROFRecord>>("clusterrofs");
106110
auto clustersIn = pc.inputs().get<gsl::span<Cluster>>("clusters");
107111

108-
// LOG(info) << "received time frame with " << clusterROFs.size() << " interactions";
109-
110112
// create the output messages for tracks and attached clusters
111113
auto& trackROFs = pc.outputs().make<std::vector<ROFRecord>>(OutputRef{"trackrofs"});
112114
auto& mchTracks = pc.outputs().make<std::vector<TrackMCH>>(OutputRef{"tracks"});
113115
auto& usedClusters = pc.outputs().make<std::vector<Cluster>>(OutputRef{"trackclusters"});
114116

117+
// prepare to send the associated digits if requested
118+
gsl::span<const Digit> digitsIn{};
119+
std::vector<Digit, o2::pmr::polymorphic_allocator<Digit>>* usedDigits(nullptr);
120+
if (mDigits) {
121+
digitsIn = pc.inputs().get<gsl::span<Digit>>("clusterdigits");
122+
usedDigits = &pc.outputs().make<std::vector<Digit>>(OutputRef{"trackdigits"});
123+
}
124+
115125
trackROFs.reserve(clusterROFs.size());
116126
for (const auto& clusterROF : clusterROFs) {
117127

118-
// LOG(info) << "processing interaction: " << clusterROF.getBCData() << "...";
119-
120128
// sort the input clusters of the current event per DE
121129
std::unordered_map<int, std::list<const Cluster*>> clusters{};
122130
for (const auto& cluster : clustersIn.subspan(clusterROF.getFirstIdx(), clusterROF.getNEntries())) {
@@ -131,7 +139,7 @@ class TrackFinderTask
131139

132140
// fill the ouput messages
133141
int trackOffset(mchTracks.size());
134-
writeTracks(tracks, mchTracks, usedClusters);
142+
writeTracks(tracks, mchTracks, usedClusters, digitsIn, usedDigits);
135143
trackROFs.emplace_back(clusterROF.getBCData(), trackOffset, mchTracks.size() - trackOffset,
136144
clusterROF.getBCWidth());
137145
}
@@ -144,9 +152,14 @@ class TrackFinderTask
144152
//_________________________________________________________________________________________________
145153
void writeTracks(const std::list<Track>& tracks,
146154
std::vector<TrackMCH, o2::pmr::polymorphic_allocator<TrackMCH>>& mchTracks,
147-
std::vector<Cluster, o2::pmr::polymorphic_allocator<Cluster>>& usedClusters) const
155+
std::vector<Cluster, o2::pmr::polymorphic_allocator<Cluster>>& usedClusters,
156+
const gsl::span<const Digit>& digitsIn,
157+
std::vector<Digit, o2::pmr::polymorphic_allocator<Digit>>* usedDigits) const
148158
{
149-
/// fill the output messages with tracks and attached clusters
159+
/// fill the output messages with tracks and attached clusters and digits if requested
160+
161+
// map the location of the attached digits between the digitsIn and the usedDigits lists
162+
std::unordered_map<uint32_t, uint32_t> digitLocMap{};
150163

151164
for (const auto& track : tracks) {
152165

@@ -162,26 +175,55 @@ class TrackFinderTask
162175
paramAtMID.getZ(), paramAtMID.getParameters(), paramAtMID.getCovariances());
163176

164177
for (const auto& param : track) {
178+
165179
usedClusters.emplace_back(*param.getClusterPtr());
180+
181+
if (mDigits) {
182+
183+
// map the location of the digits associated to this cluster in the usedDigits list, if not already done
184+
auto& cluster = usedClusters.back();
185+
auto digitLoc = digitLocMap.emplace(cluster.firstDigit, usedDigits->size());
186+
187+
// add the digits associated to this cluster if not already there
188+
if (digitLoc.second) {
189+
auto itFirstDigit = digitsIn.begin() + cluster.firstDigit;
190+
usedDigits->insert(usedDigits->end(), itFirstDigit, itFirstDigit + cluster.nDigits);
191+
}
192+
193+
// make the cluster point to the associated digits in the usedDigits list
194+
cluster.firstDigit = digitLoc.first->second;
195+
}
166196
}
167197
}
168198
}
169199

200+
bool mDigits = false; ///< send to associated digits
170201
TrackFinder mTrackFinder{}; ///< track finder
171202
std::chrono::duration<double> mElapsedTime{}; ///< timer
172203
};
173204

174205
//_________________________________________________________________________________________________
175-
o2::framework::DataProcessorSpec getTrackFinderSpec(const char* specName)
206+
o2::framework::DataProcessorSpec getTrackFinderSpec(const char* specName, bool digits)
176207
{
208+
std::vector<InputSpec> inputSpecs{};
209+
inputSpecs.emplace_back(InputSpec{"clusterrofs", "MCH", "CLUSTERROFS", 0, Lifetime::Timeframe});
210+
inputSpecs.emplace_back(InputSpec{"clusters", "MCH", "GLOBALCLUSTERS", 0, Lifetime::Timeframe});
211+
212+
std::vector<OutputSpec> outputSpecs{};
213+
outputSpecs.emplace_back(OutputSpec{{"trackrofs"}, "MCH", "TRACKROFS", 0, Lifetime::Timeframe});
214+
outputSpecs.emplace_back(OutputSpec{{"tracks"}, "MCH", "TRACKS", 0, Lifetime::Timeframe});
215+
outputSpecs.emplace_back(OutputSpec{{"trackclusters"}, "MCH", "TRACKCLUSTERS", 0, Lifetime::Timeframe});
216+
217+
if (digits) {
218+
inputSpecs.emplace_back(InputSpec{"clusterdigits", "MCH", "CLUSTERDIGITS", 0, Lifetime::Timeframe});
219+
outputSpecs.emplace_back(OutputSpec{{"trackdigits"}, "MCH", "TRACKDIGITS", 0, Lifetime::Timeframe});
220+
}
221+
177222
return DataProcessorSpec{
178223
specName,
179-
Inputs{InputSpec{"clusterrofs", "MCH", "CLUSTERROFS", 0, Lifetime::Timeframe},
180-
InputSpec{"clusters", "MCH", "GLOBALCLUSTERS", 0, Lifetime::Timeframe}},
181-
Outputs{OutputSpec{{"trackrofs"}, "MCH", "TRACKROFS", 0, Lifetime::Timeframe},
182-
OutputSpec{{"tracks"}, "MCH", "TRACKS", 0, Lifetime::Timeframe},
183-
OutputSpec{{"trackclusters"}, "MCH", "TRACKCLUSTERS", 0, Lifetime::Timeframe}},
184-
AlgorithmSpec{adaptFromTask<TrackFinderTask>()},
224+
inputSpecs,
225+
outputSpecs,
226+
AlgorithmSpec{adaptFromTask<TrackFinderTask>(digits)},
185227
Options{{"l3Current", VariantType::Float, -30000.0f, {"L3 current"}},
186228
{"dipoleCurrent", VariantType::Float, -6000.0f, {"Dipole current"}},
187229
{"grp-file", VariantType::String, o2::base::NameConf::getGRPFileName(), {"Name of the grp file"}},

Detectors/MUON/MCH/Workflow/src/TrackFinderSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace o2
2424
namespace mch
2525
{
2626

27-
o2::framework::DataProcessorSpec getTrackFinderSpec(const char* specName = "mch-track-finder");
27+
o2::framework::DataProcessorSpec getTrackFinderSpec(const char* specName = "mch-track-finder", bool digits = false);
2828

2929
} // end namespace mch
3030
} // end namespace o2

Detectors/MUON/MCH/Workflow/src/TrackWriterSpec.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "DataFormatsMCH/TrackMCH.h"
1818
#include "Framework/Logger.h"
1919
#include "DataFormatsMCH/Cluster.h"
20+
#include "DataFormatsMCH/Digit.h"
2021
#include <vector>
2122

2223
using namespace o2::framework;
@@ -27,14 +28,15 @@ namespace o2::mch
2728
template <typename T>
2829
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
2930

30-
DataProcessorSpec getTrackWriterSpec(bool useMC, const char* specName, const char* fileName)
31+
DataProcessorSpec getTrackWriterSpec(bool useMC, const char* specName, const char* fileName, bool digits)
3132
{
3233
return MakeRootTreeWriterSpec(specName,
3334
fileName,
3435
MakeRootTreeWriterSpec::TreeAttributes{"o2sim", "Tree MCH Standalone Tracks"},
3536
BranchDefinition<std::vector<TrackMCH>>{InputSpec{"tracks", "MCH", "TRACKS"}, "tracks"},
3637
BranchDefinition<std::vector<ROFRecord>>{InputSpec{"trackrofs", "MCH", "TRACKROFS"}, "trackrofs"},
3738
BranchDefinition<std::vector<Cluster>>{InputSpec{"trackclusters", "MCH", "TRACKCLUSTERS"}, "trackclusters"},
39+
BranchDefinition<std::vector<Digit>>{InputSpec{"trackdigits", "MCH", "TRACKDIGITS"}, "trackdigits", digits ? 1 : 0},
3840
BranchDefinition<std::vector<o2::MCCompLabel>>{InputSpec{"tracklabels", "MCH", "TRACKLABELS"}, "tracklabels", useMC ? 1 : 0})();
3941
}
4042

Detectors/MUON/MCH/Workflow/src/clusters-to-tracks-workflow.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
2424
{
2525
workflowOptions.emplace_back("configKeyValues", VariantType::String, "",
2626
ConfigParamSpec::HelpString{"Semicolon separated key=value strings"});
27+
workflowOptions.emplace_back("digits", VariantType::Bool, false,
28+
ConfigParamSpec::HelpString{"Send associated digits"});
2729
}
2830

2931
#include "Framework/runDataProcessing.h"
3032

3133
WorkflowSpec defineDataProcessing(const ConfigContext& configcontext)
3234
{
3335
o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
34-
return WorkflowSpec{o2::mch::getTrackFinderSpec()};
36+
bool digits = configcontext.options().get<bool>("digits");
37+
return WorkflowSpec{o2::mch::getTrackFinderSpec("mch-track-finder", digits)};
3538
}

Detectors/MUON/MCH/Workflow/src/reco-workflow.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
4343
{"disable-root-input", o2::framework::VariantType::Bool, false, {"disable root-files input reader"}},
4444
{"disable-root-output", o2::framework::VariantType::Bool, false, {"do not write output root files"}},
4545
{"disable-mc", o2::framework::VariantType::Bool, false, {"disable MC propagation even if available"}},
46+
{"digits", VariantType::Bool, false, {"Write digits associated to tracks"}},
4647
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};
4748
o2::raw::HBFUtilsInitializer::addConfigOption(options);
4849
std::swap(workflowOptions, options);
@@ -56,6 +57,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
5657

5758
auto disableRootOutput = configcontext.options().get<bool>("disable-root-output");
5859
auto disableRootInput = configcontext.options().get<bool>("disable-root-input");
60+
auto digits = configcontext.options().get<bool>("digits");
5961
auto useMC = !configcontext.options().get<bool>("disable-mc");
6062

6163
o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
@@ -79,15 +81,15 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
7981
"TC-F-DIGITROFS"));
8082
specs.emplace_back(o2::mch::getClusterFinderOriginalSpec("mch-cluster-finder"));
8183
specs.emplace_back(o2::mch::getClusterTransformerSpec());
82-
specs.emplace_back(o2::mch::getTrackFinderSpec("mch-track-finder"));
84+
specs.emplace_back(o2::mch::getTrackFinderSpec("mch-track-finder", digits));
8385
if (useMC) {
8486
specs.emplace_back(o2::mch::getTrackMCLabelFinderSpec("mch-track-mc-label-finder",
8587
"TC-F-DIGITROFS",
8688
"F-DIGITLABELS"));
8789
}
8890

8991
if (!disableRootOutput) {
90-
specs.emplace_back(o2::mch::getTrackWriterSpec(useMC, "mch-track-writer", "mchtracks.root"));
92+
specs.emplace_back(o2::mch::getTrackWriterSpec(useMC, "mch-track-writer", "mchtracks.root", digits));
9193
}
9294

9395
// configure dpl timer to inject correct firstTFOrbit: start from the 1st orbit of TF containing 1st sampled orbit

Detectors/MUON/MCH/Workflow/src/tracks-writer-workflow.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ using namespace o2::framework;
1919
void customize(std::vector<ConfigParamSpec>& workflowOptions)
2020
{
2121
workflowOptions.emplace_back("enable-mc", VariantType::Bool, false, ConfigParamSpec::HelpString{"Propagate MC info"});
22+
workflowOptions.emplace_back("digits", VariantType::Bool, false, ConfigParamSpec::HelpString{"Write associated digits"});
2223
}
2324

2425
#include "Framework/runDataProcessing.h"
2526

2627
WorkflowSpec defineDataProcessing(const ConfigContext& config)
2728
{
2829
bool useMC = config.options().get<bool>("enable-mc");
29-
return WorkflowSpec{o2::mch::getTrackWriterSpec(useMC)};
30+
bool digits = config.options().get<bool>("digits");
31+
return WorkflowSpec{o2::mch::getTrackWriterSpec(useMC, "mch-track-writer", "mchtracks.root", digits)};
3032
}

0 commit comments

Comments
 (0)