ATLAS Offline Software
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 
12 #include "CxxUtils/trapping_fp.h"
13 #include <climits>
14 #include <iomanip>
15 #include <iostream>
16 #include <sstream>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace Trk {
22 
23 static const double s_oneOverUcharMax = 1. / double(UCHAR_MAX);
24 
26 class ElementFraction : public std::pair<unsigned char, unsigned char> {
27  public:
29  ElementFraction() : std::pair<unsigned char, unsigned char>(0, 0) {}
30 
32  ElementFraction(const std::pair<unsigned char, unsigned char>& ef)
33  : std::pair<unsigned char, unsigned char>(ef) {}
34 
36  ElementFraction(unsigned char iz, unsigned char ifrac)
37  : std::pair<unsigned char, unsigned char>(iz, ifrac) {}
38 
41  const std::pair<unsigned char, unsigned char>& ef) {
42  if (this != &ef) {
43  std::pair<unsigned char, unsigned char>::operator=(ef);
44  }
45  return (*this);
46  }
47 
49  unsigned int element() const {
50  return static_cast<unsigned int>((*this).first);
51  }
52 
54  double fraction() const {
55  return (static_cast<unsigned int>((*this).second)) * s_oneOverUcharMax;
56  }
57 };
58 
60 class MaterialComposition : public std::vector<ElementFraction> {
61  public:
69 
71  MaterialComposition(const std::vector<unsigned char>& iel,
72  const std::vector<unsigned char>& ifrac) {
73  reserve(iel.size());
74  for (std::size_t elvc = 0; elvc < iel.size() && !ifrac.empty(); ++elvc)
75  push_back(ElementFraction(iel[elvc], ifrac[elvc]));
76  }
77 
80  const std::vector<std::pair<unsigned char, unsigned char> >& efracs) {
81  reserve(efracs.size());
82  for (auto& efracIt : efracs) push_back(efracIt);
83  }
84 
86  MaterialComposition(const std::vector<ElementFraction>& mc)
87  : std::vector<ElementFraction>(mc) {}
88 
90  MaterialComposition& operator=(const std::vector<ElementFraction>& mc) {
91  if (this != &mc) {
92  std::vector<ElementFraction>::operator=(mc);
93  }
94  return (*this);
95  }
96 
99  const std::vector<std::pair<unsigned char, unsigned char> >& efracs) {
100  clear();
101  reserve(efracs.size());
102  for (auto& efracIt : efracs) push_back(efracIt);
103  return (*this);
104  }
105 };
106 
116 class Material {
117  public:
118  // standard x0, l0, A, Z, rho description
119  float X0;
120  float L0;
121  float A;
122  float Z;
123  float rho;
124  float dEdX;
125  float zOaTr;
127 
130  : X0(10.e10),
131  L0(10.e10),
132  A(0.),
133  Z(0.),
134  rho(0.),
135  dEdX(0.),
136  zOaTr(0.),
137  composition(nullptr) {}
138 
140  Material(float iX0, float iL0, float iA, float iZ, float iRho,
141  float idEdX = 0., MaterialComposition* mc = nullptr)
142  : X0(iX0),
143  L0(iL0),
144  A(iA),
145  Z(iZ),
146  rho(iRho),
147  dEdX(idEdX),
148  composition(mc)
149  {
150  // Tell clang to optimize assuming that FP exceptions can trap.
151  // Otherwise, it can vectorize the division, which can lead to
152  // spurious division-by-zero traps from unused vector lanes.
154  zOaTr = iA > 0 ? iZ / iA * iRho : 0.;
155  }
156 
158  Material(const Material& amc)
159  : X0(amc.X0),
160  L0(amc.L0),
161  A(amc.A),
162  Z(amc.Z),
163  rho(amc.rho),
164  dEdX(amc.dEdX),
165  zOaTr(amc.zOaTr),
167  : nullptr) {}
168 
171  : X0(amc.X0),
172  L0(amc.L0),
173  A(amc.A),
174  Z(amc.Z),
175  rho(amc.rho),
176  dEdX(amc.dEdX),
177  zOaTr(amc.zOaTr),
178  composition(amc.composition) {
179  amc.composition = nullptr;
180  }
181 
183  virtual ~Material() {
184  if (composition) delete composition;
185  }
186 
188  Material& operator=(const Material& amc) {
189  if (this != &amc) {
190  X0 = amc.X0;
191  L0 = amc.L0;
192  A = amc.A;
193  Z = amc.Z;
194  rho = amc.rho;
195  dEdX = amc.dEdX;
196  zOaTr = amc.zOaTr;
197  delete composition;
198  composition =
199  amc.composition ? new MaterialComposition(*amc.composition) : nullptr;
200  }
201  return (*this);
202  }
203 
206  X0 = amc.X0;
207  L0 = amc.L0;
208  A = amc.A;
209  Z = amc.Z;
210  rho = amc.rho;
211  dEdX = amc.dEdX;
212  zOaTr = amc.zOaTr;
213  if (composition && composition != amc.composition) {
214  delete composition;
215  }
216  composition = amc.composition;
217  amc.composition = nullptr;
218  return *this;
219  }
220 
222  Material* scale(float sf) const;
223 
225  float zOverAtimesRho() const { return (*this).zOaTr; }
226  float x0() const { return (*this).X0; }
227  float averageZ() const { return (*this).Z; }
228 
230  std::string toString() const {
231  std::ostringstream sout;
232  sout << std::setiosflags(std::ios::fixed) << std::setprecision(4);
233  sout << "(" << X0 << " | " << L0 << " | " << A << " | " << Z << " | " << rho
234  << ")";
235  return sout.str();
236  }
237 };
238 
239 inline Material* Material::scale(float sf) const {
240  // Tell clang to optimize assuming that FP exceptions can trap.
241  // Otherwise, it can vectorize the division, which can lead to
242  // spurious division-by-zero traps from unused vector lanes.
244  return new Material(X0 / sf, L0 / sf, sf * A, sf * Z, sf * rho);
245 }
246 
247 } // namespace Trk
248 
249 #endif
Trk::Material::averageZ
float averageZ() const
Definition: Material.h:227
Trk::Material::Material
Material()
Default Constructor needed for POOL.
Definition: Material.h:129
CXXUTILS_TRAPPING_FP
#define CXXUTILS_TRAPPING_FP
Definition: trapping_fp.h:24
Trk::MaterialComposition::operator=
MaterialComposition & operator=(const std::vector< std::pair< unsigned char, unsigned char > > &efracs)
assignment operator for persistency (2)
Definition: Material.h:98
Trk::ElementFraction::ElementFraction
ElementFraction()
Default Constructor.
Definition: Material.h:29
Trk::Material::L0
float L0
Definition: Material.h:120
Trk::Material::Z
float Z
Definition: Material.h:122
Trk::Material::~Material
virtual ~Material()
Destructor - delete the composition if there.
Definition: Material.h:183
Trk::Material::Material
Material(float iX0, float iL0, float iA, float iZ, float iRho, float idEdX=0., MaterialComposition *mc=nullptr)
Constructor with arguments.
Definition: Material.h:140
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
Trk::Material::zOverAtimesRho
float zOverAtimesRho() const
access to members
Definition: Material.h:225
Trk::MaterialComposition
Definition: Material.h:60
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
Trk::ElementFraction::operator=
ElementFraction & operator=(const std::pair< unsigned char, unsigned char > &ef)
assignment operator from base class
Definition: Material.h:40
Trk::MaterialComposition::operator=
MaterialComposition & operator=(MaterialComposition &&)=default
Trk::MaterialComposition::MaterialComposition
MaterialComposition(MaterialComposition &&)=default
Trk::Material::Material
Material(const Material &amc)
Copy Constructor.
Definition: Material.h:158
A
Trk::ElementFraction::element
unsigned int element() const
Return in a nice format.
Definition: Material.h:49
mc
Definition: mc.PG_single_nu_valid.py:1
Trk::Material::x0
float x0() const
Definition: Material.h:226
Trk::Material::A
float A
Definition: Material.h:121
Trk::Material::Material
Material(Material &&amc)
Move Constructor.
Definition: Material.h:170
vector
Definition: MultiHisto.h:13
Trk::ElementFraction::ElementFraction
ElementFraction(const std::pair< unsigned char, unsigned char > &ef)
Copy Constructor from base class.
Definition: Material.h:32
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
Trk::MaterialComposition::MaterialComposition
MaterialComposition(const std::vector< ElementFraction > &mc)
Copy constructor from base class.
Definition: Material.h:86
Trk::ElementFraction
Definition: Material.h:26
Trk::Material::X0
float X0
Definition: Material.h:119
Trk::MaterialComposition::MaterialComposition
MaterialComposition()
default constructors
Definition: Material.h:63
trapping_fp.h
Tell the compiler to optimize assuming that FP may trap.
Trk::Material::operator=
Material & operator=(const Material &amc)
Assignment operator.
Definition: Material.h:188
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::ElementFraction::ElementFraction
ElementFraction(unsigned char iz, unsigned char ifrac)
Constructor from arguments.
Definition: Material.h:36
Trk::Material::toString
std::string toString() const
spit out as a string
Definition: Material.h:230
Trk::Material::rho
float rho
Definition: Material.h:123
Trk::MaterialComposition::operator=
MaterialComposition & operator=(const MaterialComposition &)=default
Trk::Material::operator=
Material & operator=(Material &&amc)
Move Assignment operator.
Definition: Material.h:205
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::Material::composition
MaterialComposition * composition
Definition: Material.h:126
Trk::MaterialComposition::MaterialComposition
MaterialComposition(const std::vector< unsigned char > &iel, const std::vector< unsigned char > &ifrac)
constructor for persistency (1), size optimized
Definition: Material.h:71
Trk::MaterialComposition::MaterialComposition
MaterialComposition(const MaterialComposition &)=default
Trk::Material::scale
Material * scale(float sf) const
scaling method
Definition: Material.h:239
Trk::Material::dEdX
float dEdX
Definition: Material.h:124
Trk::Material::zOaTr
float zOaTr
Definition: Material.h:125
Trk::MaterialComposition::~MaterialComposition
~MaterialComposition()
Definition: Material.h:68
Trk::Material
Definition: Material.h:116
Trk::ElementFraction::fraction
double fraction() const
Return in a nice format.
Definition: Material.h:54
Trk::MaterialComposition::operator=
MaterialComposition & operator=(const std::vector< ElementFraction > &mc)
assignment operator from base class
Definition: Material.h:90
LheEventFiller_Common.ef
ef
Definition: SFGen_i/share/common/LheEventFiller_Common.py:7
Trk::MaterialComposition::MaterialComposition
MaterialComposition(const std::vector< std::pair< unsigned char, unsigned char > > &efracs)
constructor for persistency (2), size optimized
Definition: Material.h:79