forked from sPHENIX-Collaboration/acts
/
RootMaterialDecorator.hpp
151 lines (132 loc) · 4.47 KB
/
RootMaterialDecorator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// This file is part of the Acts project.
//
// Copyright (C) 2017-2019 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include "ActsExamples/Framework/ProcessCode.hpp"
#include <Acts/Geometry/GeometryIdentifier.hpp>
#include <Acts/Geometry/TrackingVolume.hpp>
#include <Acts/Material/IMaterialDecorator.hpp>
#include <Acts/Material/ISurfaceMaterial.hpp>
#include <Acts/Material/IVolumeMaterial.hpp>
#include <Acts/Surfaces/Surface.hpp>
#include <Acts/Utilities/Definitions.hpp>
#include <Acts/Utilities/Logger.hpp>
#include <map>
#include <mutex>
class TFile;
namespace Acts {
using SurfaceMaterialMap =
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
using VolumeMaterialMap =
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
} // namespace Acts
namespace ActsExamples {
/// @class RootMaterialDecorator
///
/// @brief Read the collection of SurfaceMaterial & VolumeMaterial
class RootMaterialDecorator : public Acts::IMaterialDecorator {
public:
/// @class Config
/// Configuration of the Reader
class Config {
public:
/// The name of the output tree
std::string folderNameBase = "Material";
/// The volume identification string
std::string voltag = "_vol";
/// The boundary identification string
std::string boutag = "_bou";
/// The layer identification string
std::string laytag = "_lay";
/// The approach identification string
std::string apptag = "_app";
/// The sensitive identification string
std::string sentag = "_sen";
/// The bin number tag
std::string ntag = "n";
/// The value tag -> binning values: binZ, binR, binPhi, etc.
std::string vtag = "v";
/// The option tag -> binning options: open, closed
std::string otag = "o";
/// The range min tag: min value
std::string mintag = "min";
/// The range max tag: max value
std::string maxtag = "max";
/// The thickness tag
std::string ttag = "t";
/// The x0 tag
std::string x0tag = "x0";
/// The l0 tag
std::string l0tag = "l0";
/// The A tag
std::string atag = "A";
/// The Z tag
std::string ztag = "Z";
/// The rho tag
std::string rhotag = "rho";
/// The name of the output file
std::string fileName = "material-maps.root";
/// The default logger
std::shared_ptr<const Acts::Logger> logger;
// The name of the writer
std::string name = "";
/// Constructor
///
/// @param lname Name of the writer tool
/// @param lvl The output logging level
Config(const std::string& lname = "MaterialReader",
Acts::Logging::Level lvl = Acts::Logging::INFO)
: logger(Acts::getDefaultLogger(lname, lvl)), name(lname) {}
};
/// Constructor
///
/// @param cfg configuration struct for the reader
RootMaterialDecorator(const Config& cfg);
/// Destructor
~RootMaterialDecorator();
/// Decorate a surface
///
/// @param surface the non-cost surface that is decorated
void decorate(Acts::Surface& surface) const final {
// Null out the material for this surface
if (m_clearSurfaceMaterial) {
surface.assignSurfaceMaterial(nullptr);
}
// Try to find the surface in the map
auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
if (sMaterial != m_surfaceMaterialMap.end()) {
surface.assignSurfaceMaterial(sMaterial->second);
}
}
/// Decorate a TrackingVolume
///
/// @param volume the non-cost volume that is decorated
void decorate(Acts::TrackingVolume& volume) const final {
// Null out the material for this volume
if (m_clearSurfaceMaterial) {
volume.assignVolumeMaterial(nullptr);
}
// Try to find the surface in the map
auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
if (vMaterial != m_volumeMaterialMap.end()) {
volume.assignVolumeMaterial(vMaterial->second);
}
}
private:
/// The config class
Config m_cfg;
/// The input file
TFile* m_inputFile{nullptr};
/// Surface based material
Acts::SurfaceMaterialMap m_surfaceMaterialMap;
/// Volume based material
Acts::VolumeMaterialMap m_volumeMaterialMap;
bool m_clearSurfaceMaterial{true};
/// Private access to the logging instance
const Acts::Logger& logger() const { return *m_cfg.logger; }
};
} // namespace ActsExamples