Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
EDM4hepParticleReader.cpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file EDM4hepParticleReader.cpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2022 CERN for the benefit of the Acts project
4
//
5
// This Source Code Form is subject to the terms of the Mozilla Public
6
// License, v. 2.0. If a copy of the MPL was not distributed with this
7
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9
#include "
ActsExamples/Io/EDM4hep/EDM4hepParticleReader.hpp
"
10
11
#include "
Acts/Definitions/Units.hpp
"
12
#include "
ActsExamples/EventData/SimParticle.hpp
"
13
#include "
ActsExamples/Framework/WhiteBoard.hpp
"
14
#include "
ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp
"
15
#include "
ActsExamples/Utilities/Paths.hpp
"
16
17
#include <stdexcept>
18
19
#include <podio/Frame.h>
20
21
namespace
ActsExamples {
22
23
EDM4hepParticleReader::EDM4hepParticleReader
(
24
const
EDM4hepParticleReader::Config
&
config
,
Acts::Logging::Level
level
)
25
:
m_cfg
(config),
26
m_logger
(Acts::
getDefaultLogger
(
"EDM4hepParticleReader"
, level)) {
27
if
(
m_cfg
.
outputParticles
.empty()) {
28
throw
std::invalid_argument(
"Missing output collection"
);
29
}
30
31
m_reader
.openFile(
m_cfg
.
inputPath
);
32
33
m_eventsRange
= std::make_pair(0,
m_reader
.getEntries(
"events"
));
34
35
m_outputParticles
.
initialize
(
m_cfg
.
outputParticles
);
36
}
37
38
std::string
EDM4hepParticleReader::name
()
const
{
39
return
"EDM4hepParticleReader"
;
40
}
41
42
std::pair<size_t, size_t>
EDM4hepParticleReader::availableEvents
()
const
{
43
return
m_eventsRange
;
44
}
45
46
ProcessCode
EDM4hepParticleReader::read
(
const
AlgorithmContext
& ctx) {
47
podio::Frame frame =
m_reader
.readEntry(
"events"
, ctx.
eventNumber
);
48
const
auto
& mcParticleCollection =
49
frame.get<edm4hep::MCParticleCollection>(
m_cfg
.
inputParticles
);
50
51
SimParticleContainer::sequence_type unordered;
52
53
for
(
const
auto
& mcParticle : mcParticleCollection) {
54
auto
particle
=
55
EDM4hepUtil::readParticle
(mcParticle, [](
const
edm4hep::MCParticle&
p
) {
56
ActsFatras::Barcode
result;
57
// TODO dont use podio internal id
58
result.
setParticle
(p.id());
59
return
result;
60
});
61
unordered.push_back(
particle
);
62
}
63
64
// Write ordered particles container to the EventStore
65
SimParticleContainer
particles
;
66
particles.insert(unordered.begin(), unordered.end());
67
m_outputParticles
(ctx,
std::move
(particles));
68
69
return
ProcessCode::SUCCESS
;
70
}
71
72
}
// namespace ActsExamples
acts
blob
sPHENIX
Examples
Io
EDM4hep
src
EDM4hepParticleReader.cpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:38
using
1.8.2 with
sPHENIX GitHub integration