ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
JsonMaterialDecorator.hpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file JsonMaterialDecorator.hpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2017-2019 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
#pragma once
10
11
#include <fstream>
12
#include <map>
13
#include <mutex>
14
15
#include "
Acts/Geometry/TrackingVolume.hpp
"
16
#include "
Acts/Material/IMaterialDecorator.hpp
"
17
#include "
Acts/Material/ISurfaceMaterial.hpp
"
18
#include "
Acts/Material/IVolumeMaterial.hpp
"
19
#include "
Acts/Plugins/Json/JsonGeometryConverter.hpp
"
20
#include "
Acts/Surfaces/Surface.hpp
"
21
22
// Convenience shorthand
23
24
namespace
Acts {
25
30
class
JsonMaterialDecorator
:
public
IMaterialDecorator
{
31
public
:
32
using
SurfaceMaterialMap
=
33
std::map<GeometryID, std::shared_ptr<const ISurfaceMaterial>>;
34
35
using
VolumeMaterialMap
=
36
std::map<GeometryID, std::shared_ptr<const IVolumeMaterial>>;
37
38
JsonMaterialDecorator
(
const
JsonGeometryConverter::Config
& rConfig,
39
const
std::string& jFileName,
40
bool
clearSurfaceMaterial =
true
,
41
bool
clearVolumeMaterial =
true
)
42
:
m_readerConfig
(rConfig),
43
m_clearSurfaceMaterial
(clearSurfaceMaterial),
44
m_clearVolumeMaterial
(clearVolumeMaterial) {
45
// the material reader
46
Acts::JsonGeometryConverter::Config
jmConverterCfg(
"JsonGeometryConverter"
,
47
Logging::VERBOSE
);
48
Acts::JsonGeometryConverter
jmConverter(jmConverterCfg);
49
50
std::ifstream ifj(jFileName.c_str());
51
nlohmann::json
jin;
52
ifj >> jin;
53
54
auto
maps = jmConverter.
jsonToMaterialMaps
(jin);
55
m_surfaceMaterialMap
= maps.first;
56
m_volumeMaterialMap
= maps.second;
57
}
58
62
void
decorate
(
Surface
&
surface
)
const
final
{
63
// Clear the material if registered to do so
64
if
(
m_clearSurfaceMaterial
) {
65
surface
.assignSurfaceMaterial(
nullptr
);
66
}
67
// Try to find the surface in the map
68
auto
sMaterial =
m_surfaceMaterialMap
.find(
surface
.geoID());
69
if
(sMaterial !=
m_surfaceMaterialMap
.end()) {
70
surface
.assignSurfaceMaterial(sMaterial->second);
71
}
72
}
73
77
void
decorate
(
TrackingVolume
&
volume
)
const
final
{
78
// Clear the material if registered to do so
79
if
(
m_clearVolumeMaterial
) {
80
volume
.assignVolumeMaterial(
nullptr
);
81
}
82
// Try to find the volume in the map
83
auto
vMaterial =
m_volumeMaterialMap
.find(
volume
.geoID());
84
if
(vMaterial !=
m_volumeMaterialMap
.end()) {
85
volume
.assignVolumeMaterial(vMaterial->second);
86
}
87
}
88
89
private
:
90
JsonGeometryConverter::Config
m_readerConfig
;
91
SurfaceMaterialMap
m_surfaceMaterialMap
;
92
VolumeMaterialMap
m_volumeMaterialMap
;
93
94
bool
m_clearSurfaceMaterial
{
true
};
95
bool
m_clearVolumeMaterial
{
true
};
96
};
97
}
// namespace Acts
acts
blob
master
Plugins
Json
include
Acts
Plugins
Json
JsonMaterialDecorator.hpp
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:25
using
1.8.2 with
ECCE GitHub integration