Skip to content

Commit 8e4ac86

Browse files
committed
Workflows for primary vertex finding, writing and reading
1 parent d692d17 commit 8e4ac86

9 files changed

Lines changed: 528 additions & 5 deletions

Detectors/GlobalTrackingWorkflow/CMakeLists.txt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@
1010

1111
# FIXME: do we actually need a library here, or is the executable enough ?
1212
o2_add_library(GlobalTrackingWorkflow
13-
SOURCES src/TrackWriterTPCITSSpec.cxx src/TPCITSMatchingSpec.cxx
14-
src/MatchTPCITSWorkflow.cxx src/TrackTPCITSReaderSpec.cxx
15-
PUBLIC_LINK_LIBRARIES O2::GlobalTracking O2::ITStracking O2::ITSWorkflow
16-
O2::TPCWorkflow O2::FT0Workflow
17-
O2::ITSMFTWorkflow)
13+
SOURCES src/TrackWriterTPCITSSpec.cxx
14+
src/TPCITSMatchingSpec.cxx
15+
src/MatchTPCITSWorkflow.cxx
16+
src/TrackTPCITSReaderSpec.cxx
17+
src/PrimaryVertexingSpec.cxx
18+
src/PrimaryVertexWriterSpec.cxx
19+
src/PrimaryVertexReaderSpec.cxx
20+
PUBLIC_LINK_LIBRARIES O2::GlobalTracking
21+
O2::ITStracking
22+
O2::ITSWorkflow
23+
O2::TPCWorkflow
24+
O2::FT0Workflow
25+
O2::ITSMFTWorkflow
26+
O2::DetectorsVertexing)
1827

1928
o2_add_executable(match-workflow
2029
COMPONENT_NAME tpcits
2130
SOURCES src/tpcits-match-workflow.cxx
2231
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow )
2332

33+
o2_add_executable(vertexing-workflow
34+
COMPONENT_NAME primary
35+
SOURCES src/primary-vertexing-workflow.cxx
36+
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow )
37+
38+
o2_add_executable(vertex-reader-workflow
39+
COMPONENT_NAME primary
40+
SOURCES src/primary-vertex-reader-workflow.cxx
41+
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow )
42+
2443
add_subdirectory(tofworkflow)
2544
add_subdirectory(tpcinterpolationworkflow)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file PrimaryVertexReaderSpec.h
12+
13+
#ifndef O2_PRIMARY_VERTEXREADER
14+
#define O2_PRIMARY_VERTEXREADER
15+
16+
#include "TFile.h"
17+
#include "TTree.h"
18+
19+
#include "Framework/DataProcessorSpec.h"
20+
#include "Framework/Task.h"
21+
22+
#include "CommonDataFormat/TimeStamp.h"
23+
#include "CommonDataFormat/RangeReference.h"
24+
#include "ReconstructionDataFormats/Vertex.h"
25+
#include "SimulationDataFormat/MCEventLabel.h"
26+
27+
namespace o2
28+
{
29+
namespace vertexing
30+
{
31+
// read primary vertices produces by the o2-primary-vertexing-workflow
32+
33+
class PrimaryVertexReader : public o2::framework::Task
34+
{
35+
using TimeEst = o2::dataformats::TimeStampWithError<float, float>;
36+
using Vertex = o2::dataformats::Vertex<TimeEst>;
37+
using V2TRef = o2::dataformats::RangeReference<int, int>;
38+
using Label = o2::MCEventLabel;
39+
40+
public:
41+
PrimaryVertexReader(bool useMC) : mUseMC(useMC) {}
42+
~PrimaryVertexReader() override = default;
43+
void init(o2::framework::InitContext& ic) final;
44+
void run(o2::framework::ProcessingContext& pc) final;
45+
46+
protected:
47+
void connectTree(const std::string& filename);
48+
49+
bool mUseMC = false;
50+
51+
std::vector<Vertex> mVertices, *mVerticesPtr = &mVertices;
52+
std::vector<int> mPVTrIdx, *mPVTrIdxPtr = &mPVTrIdx;
53+
std::vector<V2TRef> mPV2TrIdx, *mPV2TrIdxPtr = &mPV2TrIdx;
54+
std::vector<Label> mLabels, *mLabelsPtr = &mLabels;
55+
56+
std::unique_ptr<TFile> mFile;
57+
std::unique_ptr<TTree> mTree;
58+
std::string mFileName = "";
59+
std::string mVertexTreeName = "o2sim";
60+
std::string mVertexBranchName = "PrimaryVertex";
61+
std::string mVertexTrackIDsBranchName = "PVTrackIndices";
62+
std::string mVertex2TrackIDRefsBranchName = "PV2TrackRefs";
63+
std::string mVertexLabelsBranchName = "PVMCTruth";
64+
};
65+
66+
/// create a processor spec
67+
/// read primary vertex data from a root file
68+
o2::framework::DataProcessorSpec getPrimaryVertexReaderSpec(bool useMC);
69+
70+
} // namespace vertexing
71+
} // namespace o2
72+
73+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file PrimaryVertexWriterSpec.h
12+
13+
#ifndef O2_PRIMARY_VERTEX_WRITER
14+
#define O2_PRIMARY_VERTEX_WRITER
15+
16+
#include "Framework/DataProcessorSpec.h"
17+
18+
namespace o2
19+
{
20+
namespace vertexing
21+
{
22+
23+
/// create a processor spec
24+
framework::DataProcessorSpec getPrimaryVertexWriterSpec(bool useMC);
25+
26+
} // namespace vertexing
27+
} // namespace o2
28+
29+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_PRIMARY_VERTEXER_SPEC_H
12+
#define O2_PRIMARY_VERTEXER_SPEC_H
13+
14+
/// @file PrimaryVertexingSpec.h
15+
16+
#include "DetectorsVertexing/PVertexer.h"
17+
#include "Framework/DataProcessorSpec.h"
18+
#include "Framework/Task.h"
19+
#include "TStopwatch.h"
20+
21+
namespace o2
22+
{
23+
namespace vertexing
24+
{
25+
26+
using namespace o2::framework;
27+
28+
class PrimaryVertexingSpec : public Task
29+
{
30+
public:
31+
PrimaryVertexingSpec(bool useMC) : mUseMC(useMC) {}
32+
~PrimaryVertexingSpec() override = default;
33+
void init(InitContext& ic) final;
34+
void run(ProcessingContext& pc) final;
35+
void endOfStream(EndOfStreamContext& ec) final;
36+
37+
private:
38+
o2::vertexing::PVertexer mVertexer;
39+
bool mUseMC{false}; ///< MC flag
40+
TStopwatch mTimer;
41+
};
42+
43+
/// create a processor spec
44+
DataProcessorSpec getPrimaryVertexingSpec(bool useMC);
45+
46+
} // namespace vertexing
47+
} // namespace o2
48+
49+
#endif
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file VertexReaderSpec.cxx
12+
13+
#include <vector>
14+
15+
#include "Framework/ControlService.h"
16+
#include "Framework/ConfigParamRegistry.h"
17+
#include "GlobalTrackingWorkflow/PrimaryVertexReaderSpec.h"
18+
19+
using namespace o2::framework;
20+
21+
namespace o2
22+
{
23+
namespace vertexing
24+
{
25+
26+
void PrimaryVertexReader::init(InitContext& ic)
27+
{
28+
mFileName = ic.options().get<std::string>("primary-vertex-infile");
29+
connectTree(mFileName);
30+
}
31+
32+
void PrimaryVertexReader::run(ProcessingContext& pc)
33+
{
34+
auto ent = mTree->GetReadEntry() + 1;
35+
assert(ent < mTree->GetEntries()); // this should not happen
36+
mTree->GetEntry(ent);
37+
LOG(INFO) << "Pushing " << mVerticesPtr->size() << " vertices at entry " << ent;
38+
39+
pc.outputs().snapshot(Output{"GLO", "PVERTEX", 0, Lifetime::Timeframe}, mVertices);
40+
pc.outputs().snapshot(Output{"GLO", "PVERTEX_TRIDREFS", 0, Lifetime::Timeframe}, mPV2TrIdx);
41+
pc.outputs().snapshot(Output{"GLO", "PVERTEX_TRID", 0, Lifetime::Timeframe}, mPVTrIdx);
42+
43+
if (mUseMC) {
44+
pc.outputs().snapshot(Output{"GLO", "PVERTEX_MCTR", 0, Lifetime::Timeframe}, mLabels);
45+
}
46+
47+
if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
48+
pc.services().get<ControlService>().endOfStream();
49+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
50+
}
51+
}
52+
53+
void PrimaryVertexReader::connectTree(const std::string& filename)
54+
{
55+
mTree.reset(nullptr); // in case it was already loaded
56+
mFile.reset(TFile::Open(filename.c_str()));
57+
assert(mFile && !mFile->IsZombie());
58+
mTree.reset((TTree*)mFile->Get(mVertexTreeName.c_str()));
59+
assert(mTree);
60+
assert(mTree->GetBranch(mVertexBranchName.c_str()));
61+
assert(mTree->GetBranch(mVertexTrackIDsBranchName.c_str()));
62+
assert(mTree->GetBranch(mVertex2TrackIDRefsBranchName.c_str()));
63+
64+
mTree->SetBranchAddress(mVertexBranchName.c_str(), &mVerticesPtr);
65+
mTree->SetBranchAddress(mVertexTrackIDsBranchName.c_str(), &mPVTrIdxPtr);
66+
mTree->SetBranchAddress(mVertex2TrackIDRefsBranchName.c_str(), &mPV2TrIdxPtr);
67+
68+
if (mUseMC) {
69+
assert(mTree->GetBranch(mVertexLabelsBranchName.c_str()));
70+
mTree->SetBranchAddress(mVertexLabelsBranchName.c_str(), &mLabelsPtr);
71+
}
72+
73+
LOG(INFO) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
74+
}
75+
76+
DataProcessorSpec getPrimaryVertexReaderSpec(bool useMC)
77+
{
78+
std::vector<OutputSpec> outputs;
79+
outputs.emplace_back("GLO", "PVERTEX", 0, Lifetime::Timeframe);
80+
outputs.emplace_back("GLO", "PVERTEX_TRIDREFS", 0, Lifetime::Timeframe);
81+
outputs.emplace_back("GLO", "PVERTEX_TRID", 0, Lifetime::Timeframe);
82+
if (useMC) {
83+
outputs.emplace_back("GLO", "PVERTEX_MCTR", 0, Lifetime::Timeframe);
84+
}
85+
86+
return DataProcessorSpec{
87+
"primary-vertex-reader",
88+
Inputs{},
89+
outputs,
90+
AlgorithmSpec{adaptFromTask<PrimaryVertexReader>(useMC)},
91+
Options{
92+
{"primary-vertex-infile", VariantType::String, "o2_primary_vertex.root", {"Name of the input primary vertex file"}}}};
93+
}
94+
95+
} // namespace vertexing
96+
} // namespace o2
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file PrimaryVertexWriterSpec.cxx
12+
13+
#include <vector>
14+
15+
#include "GlobalTrackingWorkflow/PrimaryVertexWriterSpec.h"
16+
#include "DPLUtils/MakeRootTreeWriterSpec.h"
17+
#include "CommonDataFormat/TimeStamp.h"
18+
#include "CommonDataFormat/RangeReference.h"
19+
#include "ReconstructionDataFormats/Vertex.h"
20+
#include "SimulationDataFormat/MCEventLabel.h"
21+
22+
using namespace o2::framework;
23+
24+
namespace o2
25+
{
26+
namespace vertexing
27+
{
28+
29+
template <typename T>
30+
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
31+
32+
using TimeEst = o2::dataformats::TimeStampWithError<float, float>;
33+
using Vertex = o2::dataformats::Vertex<TimeEst>;
34+
using V2TRef = o2::dataformats::RangeReference<int, int>;
35+
using Label = o2::MCEventLabel;
36+
37+
using namespace o2::header;
38+
39+
DataProcessorSpec getPrimaryVertexWriterSpec(bool useMC)
40+
{
41+
auto logger = [](std::vector<Vertex> const& v) {
42+
LOG(INFO) << "PrimaryVertexWriter pulled " << v.size() << " vertices";
43+
};
44+
45+
return MakeRootTreeWriterSpec("primary-vertex-writer",
46+
"o2_primary_vertex.root",
47+
MakeRootTreeWriterSpec::TreeAttributes{"o2sim", "Tree with Primary Vertices"},
48+
BranchDefinition<std::vector<Vertex>>{InputSpec{"vertices", "GLO", "PVERTEX", 0}, "PrimaryVertex", logger},
49+
BranchDefinition<std::vector<V2TRef>>{InputSpec{"v2tref", "GLO", "PVERTEX_TRIDREFS", 0}, "PV2TrackRefs"},
50+
BranchDefinition<std::vector<int>>{InputSpec{"vttrackID", "GLO", "PVERTEX_TRID", 0}, "PVTrackIndices"},
51+
BranchDefinition<std::vector<Label>>{InputSpec{"labels", "GLO", "PVERTEX_MCTR", 0}, "PVMCTruth", (useMC ? 1 : 0), ""})();
52+
}
53+
54+
} // namespace vertexing
55+
} // namespace o2

0 commit comments

Comments
 (0)