EIC Software
Reference for
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 "
Acts/Geometry/TrackingVolume.hpp
"
12
#include "
Acts/Material/IMaterialDecorator.hpp
"
13
#include "
Acts/Material/ISurfaceMaterial.hpp
"
14
#include "
Acts/Material/IVolumeMaterial.hpp
"
15
#include "
Acts/Plugins/Json/JsonGeometryConverter.hpp
"
16
#include "
Acts/Surfaces/Surface.hpp
"
17
18
#include <fstream>
19
#include <map>
20
#include <mutex>
21
22
// Convenience shorthand
23
24
namespace
Acts {
25
30
class
JsonMaterialDecorator
:
public
IMaterialDecorator
{
31
public
:
32
using
SurfaceMaterialMap
=
33
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
34
35
using
VolumeMaterialMap
=
36
std::map<GeometryIdentifier, 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
jmConverter(rConfig);
47
48
std::ifstream ifj(jFileName.c_str());
49
nlohmann::json
jin;
50
ifj >> jin;
51
52
auto
maps = jmConverter.
jsonToMaterialMaps
(jin);
53
m_surfaceMaterialMap
= maps.first;
54
m_volumeMaterialMap
= maps.second;
55
}
56
60
void
decorate
(
Surface
&
surface
)
const
final
{
61
// Clear the material if registered to do so
62
if
(
m_clearSurfaceMaterial
) {
63
surface
.assignSurfaceMaterial(
nullptr
);
64
}
65
// Try to find the surface in the map
66
auto
sMaterial =
m_surfaceMaterialMap
.find(
surface
.geometryId());
67
if
(sMaterial !=
m_surfaceMaterialMap
.end()) {
68
surface
.assignSurfaceMaterial(sMaterial->second);
69
}
70
}
71
75
void
decorate
(
TrackingVolume
&
volume
)
const
final
{
76
// Clear the material if registered to do so
77
if
(
m_clearVolumeMaterial
) {
78
volume
.assignVolumeMaterial(
nullptr
);
79
}
80
// Try to find the volume in the map
81
auto
vMaterial =
m_volumeMaterialMap
.find(
volume
.geometryId());
82
if
(vMaterial !=
m_volumeMaterialMap
.end()) {
83
volume
.assignVolumeMaterial(vMaterial->second);
84
}
85
}
86
87
private
:
88
JsonGeometryConverter::Config
m_readerConfig
;
89
SurfaceMaterialMap
m_surfaceMaterialMap
;
90
VolumeMaterialMap
m_volumeMaterialMap
;
91
92
bool
m_clearSurfaceMaterial
{
true
};
93
bool
m_clearVolumeMaterial
{
true
};
94
};
95
}
// namespace Acts
acts
blob
sPHENIX
Plugins
Json
include
Acts
Plugins
Json
JsonMaterialDecorator.hpp
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:26
using
1.8.2 with
EIC GitHub integration