ATLAS Offline Software
Loading...
Searching...
No Matches
Material.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Material.h, (c) ATLAS Detector software
8
9#ifndef TRKGEOMETRY_MATERIAL_H
10#define TRKGEOMETRY_MATERIAL_H
11
13#include <climits>
14#include <iomanip>
15#include <iostream>
16#include <sstream>
17#include <string>
18#include <utility>
19#include <vector>
20#include <memory>
21
22namespace Trk {
23
24static const double s_oneOverUcharMax = 1. / double(UCHAR_MAX);
25
27class ElementFraction : public std::pair<unsigned char, unsigned char> {
28 public:
30 ElementFraction() : std::pair<unsigned char, unsigned char>(0, 0) {}
31
33 ElementFraction(const std::pair<unsigned char, unsigned char>& ef)
34 : std::pair<unsigned char, unsigned char>(ef) {}
35
37 ElementFraction(unsigned char iz, unsigned char ifrac)
38 : std::pair<unsigned char, unsigned char>(iz, ifrac) {}
39
42 const std::pair<unsigned char, unsigned char>& ef) {
43 if (this != &ef) {
44 std::pair<unsigned char, unsigned char>::operator=(ef);
45 }
46 return (*this);
47 }
48
50 unsigned int element() const {
51 return static_cast<unsigned int>((*this).first);
52 }
53
55 double fraction() const {
56 return (static_cast<unsigned int>((*this).second)) * s_oneOverUcharMax;
57 }
58};
59
61class MaterialComposition : public std::vector<ElementFraction> {
62 public:
70
72 MaterialComposition(const std::vector<unsigned char>& iel,
73 const std::vector<unsigned char>& ifrac) {
74 reserve(iel.size());
75 for (std::size_t elvc = 0; elvc < iel.size() && !ifrac.empty(); ++elvc)
76 push_back(ElementFraction(iel[elvc], ifrac[elvc]));
77 }
78
81 const std::vector<std::pair<unsigned char, unsigned char> >& efracs) {
82 reserve(efracs.size());
83 for (auto& efracIt : efracs) push_back(efracIt);
84 }
85
87 MaterialComposition(const std::vector<ElementFraction>& mc)
89
91 MaterialComposition& operator=(const std::vector<ElementFraction>& mc) {
92 if (this != &mc) {
93 std::vector<ElementFraction>::operator=(mc);
94 }
95 return (*this);
96 }
97
100 const std::vector<std::pair<unsigned char, unsigned char> >& efracs) {
101 clear();
102 reserve(efracs.size());
103 for (auto& efracIt : efracs) push_back(efracIt);
104 return (*this);
105 }
106};
107
117class Material {
118 public:
119 // standard x0, l0, A, Z, rho description
120 float X0;
121 float L0;
122 float A;
123 float Z;
124 float rho;
125 float dEdX;
126 float zOaTr;
128
131 : X0(10.e10),
132 L0(10.e10),
133 A(0.),
134 Z(0.),
135 rho(0.),
136 dEdX(0.),
137 zOaTr(0.),
138 composition(nullptr) {}
139
141 Material(float iX0, float iL0, float iA, float iZ, float iRho,
142 float idEdX = 0., MaterialComposition* mc = nullptr)
143 : X0(iX0),
144 L0(iL0),
145 A(iA),
146 Z(iZ),
147 rho(iRho),
148 dEdX(idEdX),
150 {
151 // Tell clang to optimize assuming that FP exceptions can trap.
152 // Otherwise, it can vectorize the division, which can lead to
153 // spurious division-by-zero traps from unused vector lanes.
155 zOaTr = iA > 0 ? iZ / iA * iRho : 0.;
156 }
157
159 Material(const Material& amc)
160 : X0(amc.X0),
161 L0(amc.L0),
162 A(amc.A),
163 Z(amc.Z),
164 rho(amc.rho),
165 dEdX(amc.dEdX),
166 zOaTr(amc.zOaTr),
168 : nullptr) {}
169
172 : X0(amc.X0),
173 L0(amc.L0),
174 A(amc.A),
175 Z(amc.Z),
176 rho(amc.rho),
177 dEdX(amc.dEdX),
178 zOaTr(amc.zOaTr),
180 amc.composition = nullptr;
181 }
182
184 virtual ~Material() {
185 if (composition) delete composition;
186 }
187
190 if (this != &amc) {
191 X0 = amc.X0;
192 L0 = amc.L0;
193 A = amc.A;
194 Z = amc.Z;
195 rho = amc.rho;
196 dEdX = amc.dEdX;
197 zOaTr = amc.zOaTr;
198 delete composition;
200 amc.composition ? new MaterialComposition(*amc.composition) : nullptr;
201 }
202 return (*this);
203 }
204
207 X0 = amc.X0;
208 L0 = amc.L0;
209 A = amc.A;
210 Z = amc.Z;
211 rho = amc.rho;
212 dEdX = amc.dEdX;
213 zOaTr = amc.zOaTr;
214 if (composition && composition != amc.composition) {
215 delete composition;
216 }
217 composition = amc.composition;
218 amc.composition = nullptr;
219 return *this;
220 }
221
223 std::unique_ptr<Material> scale(float sf) const;
224
226 float zOverAtimesRho() const { return (*this).zOaTr; }
227 float x0() const { return (*this).X0; }
228 float averageZ() const { return (*this).Z; }
229
231 std::string toString() const {
232 std::ostringstream sout;
233 sout << std::setiosflags(std::ios::fixed) << std::setprecision(4);
234 sout << "(" << X0 << " | " << L0 << " | " << A << " | " << Z << " | " << rho
235 << ")";
236 return sout.str();
237 }
238};
239
240inline std::unique_ptr<Material> Material::scale(float sf) const {
241 // Tell clang to optimize assuming that FP exceptions can trap.
242 // Otherwise, it can vectorize the division, which can lead to
243 // spurious division-by-zero traps from unused vector lanes.
245 return std::make_unique<Material>(X0 / sf, L0 / sf, sf * A, sf * Z, sf * rho);
246}
247
248} // namespace Trk
249
250#endif
unsigned int element() const
Return in a nice format.
Definition Material.h:50
ElementFraction & operator=(const std::pair< unsigned char, unsigned char > &ef)
assignment operator from base class
Definition Material.h:41
double fraction() const
Return in a nice format.
Definition Material.h:55
ElementFraction(const std::pair< unsigned char, unsigned char > &ef)
Copy Constructor from base class.
Definition Material.h:33
ElementFraction()
Default Constructor.
Definition Material.h:30
ElementFraction(unsigned char iz, unsigned char ifrac)
Constructor from arguments.
Definition Material.h:37
MaterialComposition(const MaterialComposition &)=default
MaterialComposition(const std::vector< ElementFraction > &mc)
Copy constructor from base class.
Definition Material.h:87
MaterialComposition & operator=(const std::vector< std::pair< unsigned char, unsigned char > > &efracs)
assignment operator for persistency (2)
Definition Material.h:99
MaterialComposition & operator=(const MaterialComposition &)=default
MaterialComposition & operator=(const std::vector< ElementFraction > &mc)
assignment operator from base class
Definition Material.h:91
MaterialComposition(const std::vector< unsigned char > &iel, const std::vector< unsigned char > &ifrac)
constructor for persistency (1), size optimized
Definition Material.h:72
MaterialComposition()
default constructors
Definition Material.h:64
MaterialComposition(MaterialComposition &&)=default
MaterialComposition & operator=(MaterialComposition &&)=default
MaterialComposition(const std::vector< std::pair< unsigned char, unsigned char > > &efracs)
constructor for persistency (2), size optimized
Definition Material.h:80
Material(float iX0, float iL0, float iA, float iZ, float iRho, float idEdX=0., MaterialComposition *mc=nullptr)
Constructor with arguments.
Definition Material.h:141
float x0() const
Definition Material.h:227
std::unique_ptr< Material > scale(float sf) const
scaling method
Definition Material.h:240
std::string toString() const
spit out as a string
Definition Material.h:231
Material(const Material &amc)
Copy Constructor.
Definition Material.h:159
Material()
Default Constructor needed for POOL.
Definition Material.h:130
MaterialComposition * composition
Definition Material.h:127
float averageZ() const
Definition Material.h:228
Material & operator=(const Material &amc)
Assignment operator.
Definition Material.h:189
Material(Material &&amc)
Move Constructor.
Definition Material.h:171
virtual ~Material()
Destructor - delete the composition if there.
Definition Material.h:184
Material & operator=(Material &&amc)
Move Assignment operator.
Definition Material.h:206
float zOverAtimesRho() const
access to members
Definition Material.h:226
STL class.
Ensure that the ATLAS eigen extensions are properly loaded.
static const double s_oneOverUcharMax
Definition Material.h:24
STL namespace.
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24