Skip to content

Commit d813052

Browse files
Writing Track MC labels to output file, adjusting default branch names
Renamed process to tpc-tracks-writer, options are now: Data processor options: tpc-track-writer: --outfile arg (=tpctracks.root) Name of the input file --treename arg (=o2sim) Name of output tree --track-branch-name arg (=TPCTracks) Branch name for TPC tracks --trackmc-branch-name arg (=TPCTracksMCTruth) Branch name for TPC track mc labels Also catching possible error code at TPCCATracking initialization, from AliTPCCommon v.1.4.3, error code is return on unknown option.
1 parent 434d782 commit d813052

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

Detectors/TPC/workflow/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Important options for the `digit-reader` as initial publisher
3939
--tpc-sectors arg (=0-35) TPC sector range, e.g. 5-7,8,9
4040
```
4141

42+
Options for the `tpc-track-writer` process
43+
```
44+
--outfile arg (=tpctracks.root) Name of the input file
45+
--treename arg (=o2sim) Name of output tree
46+
--track-branch-name arg (=TPCTracks) Branch name for TPC tracks
47+
--trackmc-branch-name arg (=TPCTracksMCTruth) Branch name for TPC track mc labels
48+
```
49+
4250
Examples:
4351
```
4452
tpc-reco-workflow --infile tpcdigits.root --tpc-sectors 0-15
@@ -65,9 +73,16 @@ lanes, each with clusterer, converter and decoder. The tracker will fan in from
6573
### Processor options
6674

6775
#### TPC CA tracker
68-
The [tracker spec](src/CATrackerSpec.cxx) interfaces the [o2::TPC::TPCCATracking](reconstruction/include/TPCReconstruction/TPCCATracking.h) worker class which can be initialized using an option string. The processor spec defines the option `--tracker-option`, e.g.
76+
The [tracker spec](src/CATrackerSpec.cxx) interfaces the [o2::TPC::TPCCATracking](reconstruction/include/TPCReconstruction/TPCCATracking.h) worker class which can be initialized using an option string. The processor spec defines the option `--tracker-option`. Currently, the tracker should be run with options
77+
```
78+
--tracker-option "refX=83 cont"
79+
```
80+
81+
The most important tracker options are:
6982
```
70-
--tracker-option ""refX=83""
83+
cont activation of continuous mode
84+
refX= reference x coordinate, tracker tries to propagate all track to the reference
85+
bz= magnetic field
7186
```
7287

7388
### Current limitations

Detectors/TPC/workflow/src/CATrackerSpec.cxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <memory> // for make_shared
2929
#include <vector>
3030
#include <iomanip>
31+
#include <stdexcept>
3132

3233
using namespace o2::framework;
3334
using namespace o2::header;
@@ -67,7 +68,9 @@ DataProcessorSpec getCATrackerSpec(bool processMC, size_t fanIn)
6768
auto& tracker = processAttributes->tracker;
6869
parser = std::make_unique<ClusterGroupParser>();
6970
tracker = std::make_unique<o2::TPC::TPCCATracking>();
70-
tracker->initialize(options.c_str());
71+
if (tracker->initialize(options.c_str()) != 0) {
72+
throw std::invalid_argument("TPCCATracking initialization failed");
73+
}
7174
processAttributes->validInputs.reset();
7275
processAttributes->validMcInputs.reset();
7376
}
@@ -214,10 +217,8 @@ DataProcessorSpec getCATrackerSpec(bool processMC, size_t fanIn)
214217
LOG(INFO) << "found " << tracks.size() << " track(s)";
215218
pc.outputs().snapshot(OutputRef{ "output" }, tracks);
216219
if (processMC) {
217-
LOG(INFO) << "have " << tracksMCTruth.getIndexedSize() << " track label(s)";
218-
// have to change the writer process as well but want to convert to the RootTreeWriter tool
219-
// at this occasion so we skip sending the labels for the moment
220-
//pc.outputs().snapshot(OutputRef{ "mclblout" }, tracksMCTruth);
220+
LOG(INFO) << "sending " << tracksMCTruth.getIndexedSize() << " track label(s)";
221+
pc.outputs().snapshot(OutputRef{ "mclblout" }, tracksMCTruth);
221222
}
222223

223224
validInputs.reset();
@@ -261,7 +262,7 @@ DataProcessorSpec getCATrackerSpec(bool processMC, size_t fanIn)
261262

262263
return DataProcessorSpec{ "tpc-tracker", // process id
263264
{ createInputSpecs(processMC) },
264-
{ createOutputSpecs(false /*create onece writer process has been changed*/) },
265+
{ createOutputSpecs(processMC) },
265266
AlgorithmSpec(initFunction),
266267
Options{
267268
{ "tracker-options", VariantType::String, "", { "Option string passed to tracker" } },

Detectors/TPC/workflow/src/RecoWorkflow.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ framework::WorkflowSpec getWorkflow(bool propagateMC, int nLanes, std::string cf
144144

145145
if (outputType == OutputType::Tracks) {
146146
specs.emplace_back(o2::TPC::getCATrackerSpec(propagateMC, nLanes));
147-
specs.emplace_back(o2::TPC::getRootFileWriterSpec());
147+
specs.emplace_back(o2::TPC::getRootFileWriterSpec(propagateMC));
148148
} else if (outputType == OutputType::DecodedClusters) {
149149
specs.emplace_back(DataProcessorSpec{ "writer",
150150
{ createInputSpec() },

Detectors/TPC/workflow/src/RootFileWriterSpec.cxx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,41 @@
1717
#include "Framework/ControlService.h"
1818
#include "Framework/CallbackService.h"
1919
#include "DataFormatsTPC/TrackTPC.h"
20+
#include "SimulationDataFormat/MCTruthContainer.h"
21+
#include "SimulationDataFormat/MCCompLabel.h"
2022
#include <TFile.h>
2123
#include <TTree.h>
2224
#include <memory> // for make_shared, make_unique, unique_ptr
2325
#include <stdexcept>
2426

2527
using namespace o2::framework;
2628

29+
using MCLabelContainer = o2::dataformats::MCTruthContainer<o2::MCCompLabel>;
30+
2731
namespace o2
2832
{
2933
namespace TPC
3034
{
3135
/// create a processor spec
3236
/// read simulated TPC digits from file and publish
33-
DataProcessorSpec getRootFileWriterSpec()
37+
DataProcessorSpec getRootFileWriterSpec(bool writeMC)
3438
{
35-
auto initFunction = [](InitContext& ic) {
39+
auto initFunction = [writeMC](InitContext& ic) {
3640
// get the option from the init context
3741
auto filename = ic.options().get<std::string>("outfile");
3842
auto treename = ic.options().get<std::string>("treename");
43+
auto trackBranchName = ic.options().get<std::string>("track-branch-name");
44+
auto trackMcBranchName = ic.options().get<std::string>("trackmc-branch-name");
3945
auto nevents = ic.options().get<int>("nevents");
4046

4147
auto outputfile = std::make_shared<TFile>(filename.c_str(), "RECREATE");
4248
auto outputtree = std::make_shared<TTree>(treename.c_str(), treename.c_str());
4349
auto tracks = std::make_shared<std::vector<o2::TPC::TrackTPC>>();
44-
auto trackbranch = outputtree->Branch("Tracks", tracks.get());
50+
auto mclabels = std::make_shared<MCLabelContainer>();
51+
outputtree->Branch(trackBranchName.c_str(), tracks.get());
52+
if (writeMC) {
53+
outputtree->Branch(trackMcBranchName.c_str(), mclabels.get());
54+
}
4555

4656
// the callback to be set as hook at stop of processing for the framework
4757
auto finishWriting = [outputfile, outputtree]() {
@@ -54,11 +64,15 @@ DataProcessorSpec getRootFileWriterSpec()
5464
// using by-copy capture of the worker instance shared pointer
5565
// the shared pointer makes sure to clean up the instance when the processing
5666
// function gets out of scope
57-
auto processingFct = [outputfile, outputtree, tracks, nevents](ProcessingContext& pc) {
67+
auto processingFct = [outputfile, outputtree, tracks, mclabels, nevents, writeMC](ProcessingContext& pc) {
5868
static int eventCount = 0;
5969
auto indata = pc.inputs().get<std::vector<o2::TPC::TrackTPC>>("input");
6070
LOG(INFO) << "RootFileWriter: get " << indata.size() << " track(s)";
6171
*tracks.get() = std::move(indata);
72+
if (writeMC) {
73+
auto mcdata = pc.inputs().get<MCLabelContainer*>("mcinput");
74+
*mclabels.get() = *mcdata;
75+
}
6276
LOG(INFO) << "RootFileWriter: write " << tracks->size() << " track(s)";
6377
outputtree->Fill();
6478

@@ -72,13 +86,26 @@ DataProcessorSpec getRootFileWriterSpec()
7286
return processingFct;
7387
};
7488

75-
return DataProcessorSpec{ "writer",
76-
{ InputSpec{ "input", "TPC", "TRACKS", 0, Lifetime::Timeframe } }, // track input
77-
{}, // no output
89+
auto createInputSpecs = [](bool makeMcInput) {
90+
std::vector<InputSpec> inputSpecs{
91+
InputSpec{ { "input" }, "TPC", "TRACKS", 0, Lifetime::Timeframe },
92+
};
93+
if (makeMcInput) {
94+
constexpr o2::header::DataDescription datadesc("TRACKMCLBL");
95+
inputSpecs.emplace_back(InputSpec{ "mcinput", "TPC", datadesc, 0, Lifetime::Timeframe });
96+
}
97+
return std::move(inputSpecs);
98+
};
99+
100+
return DataProcessorSpec{ "tpc-track-writer",
101+
{ createInputSpecs(writeMC) },
102+
{},
78103
AlgorithmSpec(initFunction),
79104
Options{
80105
{ "outfile", VariantType::String, "tpctracks.root", { "Name of the input file" } },
81-
{ "treename", VariantType::String, "Tracks", { "Name of tree for tracks" } },
106+
{ "treename", VariantType::String, "o2sim", { "Name of output tree" } },
107+
{ "track-branch-name", VariantType::String, "TPCTracks", { "Branch name for TPC tracks" } },
108+
{ "trackmc-branch-name", VariantType::String, "TPCTracksMCTruth", { "Branch name for TPC track mc labels" } },
82109
{ "nevents", VariantType::Int, 1, { "terminate after n events" } },
83110
} };
84111
}

Detectors/TPC/workflow/src/RootFileWriterSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace o2
2020
namespace TPC
2121
{
2222

23-
framework::DataProcessorSpec getRootFileWriterSpec();
23+
framework::DataProcessorSpec getRootFileWriterSpec(bool writeMC = false);
2424

2525
} // end namespace TPC
2626
} // end namespace o2

0 commit comments

Comments
 (0)