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
CsvSimHitWriter.cpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file CsvSimHitWriter.cpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2020 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/Csv/CsvSimHitWriter.hpp
"
10
11
#include "
Acts/Definitions/Algebra.hpp
"
12
#include "
Acts/Definitions/Common.hpp
"
13
#include "
Acts/Definitions/Units.hpp
"
14
#include "
Acts/Geometry/GeometryIdentifier.hpp
"
15
#include "
ActsExamples/EventData/SimHit.hpp
"
16
#include "
ActsExamples/Framework/AlgorithmContext.hpp
"
17
#include "
ActsExamples/Utilities/Paths.hpp
"
18
#include "
ActsFatras/EventData/Barcode.hpp
"
19
#include "
ActsFatras/EventData/Hit.hpp
"
20
21
#include <stdexcept>
22
#include <vector>
23
24
#include <dfe/dfe_io_dsv.hpp>
25
26
#include "
CsvOutputData.hpp
"
27
28
ActsExamples::CsvSimHitWriter::CsvSimHitWriter
(
29
const
ActsExamples::CsvSimHitWriter::Config
&
config
,
30
Acts::Logging::Level
level
)
31
:
WriterT
(config.inputSimHits,
"CsvSimHitWriter"
, level),
m_cfg
(config) {
32
// inputSimHits is already checked by base constructor
33
if
(
m_cfg
.
outputStem
.empty()) {
34
throw
std::invalid_argument(
"Missing output filename stem"
);
35
}
36
}
37
38
ActsExamples::ProcessCode
ActsExamples::CsvSimHitWriter::writeT
(
39
const
AlgorithmContext
& ctx,
const
ActsExamples::SimHitContainer
& simHits) {
40
// open per-event file for all simhit components
41
std::string
pathSimHit =
perEventFilepath
(
42
m_cfg
.outputDir,
m_cfg
.outputStem +
".csv"
, ctx.
eventNumber
);
43
44
dfe::NamedTupleCsvWriter<SimHitData> writerSimHit(pathSimHit,
45
m_cfg
.outputPrecision);
46
47
// CsvOutputData struct
48
SimHitData
simhit;
49
// Write data from internal impl. to output-side struct
50
for
(
const
auto
& simHit : simHits) {
51
// local simhit information in global coord.
52
const
Acts::Vector4
& globalPos4 = simHit.fourPosition();
53
const
Acts::Vector4
& momentum4Before = simHit.momentum4Before();
54
55
simhit.
geometry_id
= simHit.geometryId().value();
56
simhit.
particle_id
= simHit.particleId().value();
57
// hit position
58
simhit.
tx
= globalPos4[
Acts::ePos0
] /
Acts::UnitConstants::mm
;
59
simhit.
ty
= globalPos4[
Acts::ePos1
] /
Acts::UnitConstants::mm
;
60
simhit.
tz
= globalPos4[
Acts::ePos2
] /
Acts::UnitConstants::mm
;
61
simhit.
tt
= globalPos4[
Acts::eTime
] /
Acts::UnitConstants::ns
;
62
// particle four-momentum before interaction
63
simhit.
tpx
= momentum4Before[
Acts::eMom0
] /
Acts::UnitConstants::GeV
;
64
simhit.
tpy
= momentum4Before[
Acts::eMom1
] /
Acts::UnitConstants::GeV
;
65
simhit.
tpz
= momentum4Before[
Acts::eMom2
] /
Acts::UnitConstants::GeV
;
66
simhit.
te
= momentum4Before[
Acts::eEnergy
] /
Acts::UnitConstants::GeV
;
67
// particle four-momentum change due to interaction
68
const
auto
delta4 = simHit.momentum4After() - momentum4Before;
69
simhit.
deltapx
= delta4[
Acts::eMom0
] /
Acts::UnitConstants::GeV
;
70
simhit.
deltapy
= delta4[
Acts::eMom1
] /
Acts::UnitConstants::GeV
;
71
simhit.
deltapz
= delta4[
Acts::eMom2
] /
Acts::UnitConstants::GeV
;
72
simhit.
deltae
= delta4[
Acts::eEnergy
] /
Acts::UnitConstants::GeV
;
73
// TODO write hit index along the particle trajectory
74
simhit.
index
= simHit.index();
75
writerSimHit.append(simhit);
76
}
// end simHit loop
77
78
return
ActsExamples::ProcessCode::SUCCESS
;
79
}
acts
blob
sPHENIX
Examples
Io
Csv
src
CsvSimHitWriter.cpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:38
using
1.8.2 with
sPHENIX GitHub integration