IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pranav Sampathkumar
corsika
Commits
91fdc3e6
Commit
91fdc3e6
authored
4 years ago
by
Maximilian Reininghaus
Committed by
ralfulrich
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ParticleProperties
parent
0c883651
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
corsika/framework/core/ParticleProperties.hpp
+60
-71
60 additions, 71 deletions
corsika/framework/core/ParticleProperties.hpp
src/framework/core/pdxml_reader.py
+17
-16
17 additions, 16 deletions
src/framework/core/pdxml_reader.py
with
77 additions
and
87 deletions
corsika/framework/core/ParticleProperties.hpp
+
60
−
71
View file @
91fdc3e6
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include
<array>
#include
<array>
#include
<cstdint>
#include
<cstdint>
#include
<cmath>
#include
<iosfwd>
#include
<iosfwd>
#include
<corsika/framework/core/PhysicalUnits.hpp>
#include
<corsika/framework/core/PhysicalUnits.hpp>
...
@@ -28,7 +29,6 @@
...
@@ -28,7 +29,6 @@
*/
*/
namespace
corsika
{
namespace
corsika
{
/**
/**
* @enum Code
* @enum Code
* The Code enum is the actual place to define CORSIKA 8 particle codes.
* The Code enum is the actual place to define CORSIKA 8 particle codes.
...
@@ -39,126 +39,115 @@ namespace corsika {
...
@@ -39,126 +39,115 @@ namespace corsika {
using
PDGCodeType
=
std
::
underlying_type
<
PDGCode
>::
type
;
using
PDGCodeType
=
std
::
underlying_type
<
PDGCode
>::
type
;
// forward declarations to be used in GeneratedParticleProperties
// forward declarations to be used in GeneratedParticleProperties
int16_t
constexpr
GetChargeNumber
(
Code
const
);
int16_t
constexpr
charge_number
(
Code
const
);
//!< electric charge in units of e
ElectricChargeType
constexpr
GetCharge
(
Code
const
);
ElectricChargeType
constexpr
charge
(
Code
const
);
//!< electric charge
HEPMassType
constexpr
GetMass
(
Code
const
);
HEPMassType
constexpr
mass
(
Code
const
);
//!< mass
PDGCode
constexpr
GetPDG
(
Code
const
);
constexpr
std
::
string
const
&
GetName
(
Code
const
);
//! Particle code according to PDG, "Monte Carlo Particle Numbering Scheme"
TimeType
constexpr
GetLifetime
(
Code
const
);
PDGCode
constexpr
PDG
(
Code
const
);
constexpr
std
::
string
const
&
name
(
Code
const
);
//!< name of the particle as string
bool
constexpr
IsNucleus
(
Code
const
);
TimeType
constexpr
lifetime
(
Code
const
);
//!< lifetime
bool
constexpr
IsHadron
(
Code
const
);
bool
constexpr
IsEM
(
Code
const
);
//! true iff the particle is a hard-coded nucleus or Code::Nucleus
bool
constexpr
IsMuon
(
Code
const
);
bool
constexpr
is_nucleus
(
Code
const
);
bool
constexpr
IsNeutrino
(
Code
const
);
bool
constexpr
is_hadron
(
Code
const
);
//!< true iff particle is hadron
int
constexpr
GetNucleusA
(
Code
const
);
bool
constexpr
is_em
(
Code
const
);
//!< true iff particle is electron, positron or gamma
int
constexpr
GetNucleusZ
(
Code
const
);
bool
constexpr
is_muon
(
Code
const
);
//!< true iff particle is mu+ or mu-
bool
constexpr
is_neutrino
(
Code
const
);
//!< true iff particle is (anti-) neutrino
int
constexpr
nucleus_A
(
Code
const
);
//!< returns A for hard-coded nucleus, otherwise 0
int
constexpr
nucleus_Z
(
Code
const
);
//!< returns Z for hard-coded nucleus, otherwise 0
}
// namespace corsika
#include
<corsika/framework/core/GeneratedParticleProperties.inc>
#include
<corsika/framework/core/GeneratedParticleProperties.inc>
namespace
corsika
::
particles
{
namespace
corsika
{
/*!
HEPMassType
constexpr
mass
(
Code
const
p
)
{
* returns mass of particle in natural units
*/
HEPMassType
constexpr
GetMass
(
Code
const
p
)
{
if
(
p
==
Code
::
Nucleus
)
if
(
p
==
Code
::
Nucleus
)
throw
std
::
runtime_error
(
"Cannot GetMass() of particle::Nucleus -> unspecified"
);
throw
std
::
runtime_error
(
"Cannot GetMass() of particle::Nucleus -> unspecified"
);
return
particle
::
detail
::
masses
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
masses
[
static_cast
<
CodeIntType
>
(
p
)];
}
}
/*!
PDGCode
constexpr
PDG
(
Code
const
p
)
{
* returns PDG id
*/
PDGCode
constexpr
GetPDG
(
Code
const
p
)
{
return
particle
::
detail
::
pdg_codes
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
pdg_codes
[
static_cast
<
CodeIntType
>
(
p
)];
}
}
/*!
int16_t
constexpr
charge_number
(
Code
const
code
)
{
* returns electric charge number of particle return 1 for a proton.
if
(
code
==
Code
::
Nucleus
)
*/
throw
std
::
runtime_error
(
"charge of particle::Nucleus undefined"
);
int16_t
constexpr
GetChargeNumber
(
Code
const
p
)
{
return
particle
::
detail
::
electric_charges
[
static_cast
<
CodeIntType
>
(
code
)];
if
(
p
==
Code
::
Nucleus
)
throw
std
::
runtime_error
(
"Cannot GetChargeNumber() of particle::Nucleus -> unspecified"
);
// electric_charges stores charges in units of (e/3), e.g. 3 for a proton
return
particle
::
detail
::
electric_charges
[
static_cast
<
CodeIntType
>
(
p
)]
/
3
;
}
}
/*!
ElectricChargeType
constexpr
charge
(
Code
const
code
)
{
* returns electric charge of particle, e.g. return 1.602e-19_C for a proton.
if
(
code
==
Code
::
Nucleus
)
*/
ElectricChargeType
constexpr
GetCharge
(
Code
const
p
)
{
if
(
p
==
Code
::
Nucleus
)
throw
std
::
runtime_error
(
"Cannot GetCharge() of particle::Nucleus -> unspecified"
);
throw
std
::
runtime_error
(
"Cannot GetCharge() of particle::Nucleus -> unspecified"
);
return
GetC
harge
N
umber
(
p
)
*
constants
::
e
;
return
c
harge
_n
umber
(
code
)
*
constants
::
e
;
}
}
constexpr
std
::
string
const
&
GetN
ame
(
Code
const
p
)
{
constexpr
std
::
string
const
&
n
ame
(
Code
const
code
)
{
return
particle
::
detail
::
names
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
names
[
static_cast
<
CodeIntType
>
(
code
)];
}
}
inline
TimeType
constexpr
GetL
ifetime
(
Code
const
p
)
{
TimeType
constexpr
l
ifetime
(
Code
const
p
)
{
return
particle
::
detail
::
lifetime
[
static_cast
<
CodeIntType
>
(
p
)]
*
second
;
return
particle
::
detail
::
lifetime
[
static_cast
<
CodeIntType
>
(
p
)]
*
second
;
}
}
inline
bool
constexpr
IsH
adron
(
Code
const
p
)
{
bool
constexpr
is_h
adron
(
Code
const
p
)
{
return
particle
::
detail
::
isHadron
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
isHadron
[
static_cast
<
CodeIntType
>
(
p
)];
}
}
inline
bool
constexpr
IsEM
(
Code
c
)
{
bool
constexpr
is_em
(
Code
c
)
{
return
c
==
Code
::
Electron
||
c
==
Code
::
Positron
||
c
==
Code
::
Gamma
;
return
c
==
Code
::
Electron
||
c
==
Code
::
Positron
||
c
==
Code
::
Gamma
;
}
}
inline
bool
constexpr
IsM
uon
(
Code
c
)
{
return
c
==
Code
::
MuPlus
||
c
==
Code
::
MuMinus
;
}
bool
constexpr
is_m
uon
(
Code
c
)
{
return
c
==
Code
::
MuPlus
||
c
==
Code
::
MuMinus
;
}
inline
bool
constexpr
IsN
eutrino
(
Code
c
)
{
bool
constexpr
is_n
eutrino
(
Code
c
)
{
return
c
==
Code
::
NuE
||
c
==
Code
::
NuMu
||
c
==
Code
::
NuTau
||
c
==
Code
::
NuEBar
||
return
c
==
Code
::
NuE
||
c
==
Code
::
NuMu
||
c
==
Code
::
NuTau
||
c
==
Code
::
NuEBar
||
c
==
Code
::
NuMuBar
||
c
==
Code
::
NuTauBar
;
c
==
Code
::
NuMuBar
||
c
==
Code
::
NuTauBar
;
}
}
inline
int
constexpr
GetN
ucleusA
(
Code
const
p
)
{
int
constexpr
n
ucleus
_
A
(
Code
const
code
)
{
if
(
p
==
Code
::
Nucleus
)
{
if
(
code
==
Code
::
Nucleus
)
{
throw
std
::
runtime_error
(
"
GetN
ucleusA(Code::Nucleus) is impossible!"
);
throw
std
::
runtime_error
(
"
n
ucleus
_
A(Code::Nucleus) is impossible!"
);
}
}
return
particle
::
detail
::
nucleusA
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
nucleusA
[
static_cast
<
CodeIntType
>
(
code
)];
}
}
inline
int
constexpr
GetN
ucleusZ
(
Code
const
p
)
{
int
constexpr
n
ucleus
_
Z
(
Code
const
code
)
{
if
(
p
==
Code
::
Nucleus
)
{
if
(
code
==
Code
::
Nucleus
)
{
throw
std
::
runtime_error
(
"
GetN
ucleusZ(Code::Nucleus) is impossible!"
);
throw
std
::
runtime_error
(
"
n
ucleus
_
Z(Code::Nucleus) is impossible!"
);
}
}
return
particle
::
detail
::
nucleusZ
[
static_cast
<
CodeIntType
>
(
p
)];
return
particle
::
detail
::
nucleusZ
[
static_cast
<
CodeIntType
>
(
code
)];
}
}
inline
bool
constexpr
IsN
ucleus
(
Code
const
p
)
{
bool
constexpr
is_n
ucleus
(
Code
const
code
)
{
return
(
p
==
Code
::
Nucleus
)
||
(
GetN
ucleusA
(
p
)
!=
0
);
return
(
code
==
Code
::
Nucleus
)
||
(
n
ucleus
_
A
(
code
)
!=
0
);
}
}
/**
//! the output stream operator for human-readable particle codes
* the output operator for humand-readable particle codes
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
corsika
::
Code
const
code
)
{
**/
return
stream
<<
name
(
code
);
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
corsika
::
Code
const
p
)
{
return
stream
<<
corsika
::
GetName
(
p
);
}
}
inline
Code
ConvertFromPDG
(
PDGCode
p
)
{
//! convert PDG code to CORSIKA 8 internal code
inline
Code
convert_from_PDG
(
PDGCode
p
)
{
static_assert
(
particle
::
detail
::
conversionArray
.
size
()
%
2
==
1
);
static_assert
(
particle
::
detail
::
conversionArray
.
size
()
%
2
==
1
);
// this will fail, for the strange case where the maxPDG is negative...
// this will fail, for the strange case where the maxPDG is negative...
unsigned
int
constexpr
maxPDG
{(
particle
::
detail
::
conversionArray
.
size
()
-
1
)
>>
1
};
int
constexpr
maxPDG
{(
particle
::
detail
::
conversionArray
.
size
()
-
1
)
>>
1
};
auto
k
=
static_cast
<
PDGCodeType
>
(
p
);
auto
const
k
=
static_cast
<
PDGCodeType
>
(
p
);
if
(
(
unsigned
int
)
abs
(
k
)
<=
maxPDG
)
{
if
(
std
::
abs
(
k
)
<=
maxPDG
)
{
return
particle
::
detail
::
conversionArray
[
k
+
maxPDG
];
return
particle
::
detail
::
conversionArray
[
k
+
maxPDG
];
}
else
{
}
else
{
return
particle
::
detail
::
conversionMap
.
at
(
p
);
return
particle
::
detail
::
conversionMap
.
at
(
p
);
}
}
}
}
/**
* Get mass of nucleus
//! returns mass of (A,Z) nucleus, disregarding binding energy
**/
HEPMassType
constexpr
nucleus_mass
(
const
int
A
,
const
int
Z
)
{
inline
HEPMassType
constexpr
GetNucleusMass
(
const
int
vA
,
const
int
vZ
)
{
auto
const
absA
=
std
::
abs
(
A
);
return
Proton
::
GetMass
()
*
vZ
+
(
vA
-
vZ
)
*
Neutron
::
GetMass
();
auto
const
absZ
=
std
::
abs
(
Z
);
return
Proton
::
mass
()
*
absZ
+
(
absA
-
absZ
)
*
Neutron
::
mass
();
}
}
}
// namespace corsika
}
// namespace corsika
This diff is collapsed.
Click to expand it.
src/framework/core/pdxml_reader.py
+
17
−
16
View file @
91fdc3e6
...
@@ -346,7 +346,7 @@ def gen_properties(particle_db):
...
@@ -346,7 +346,7 @@ def gen_properties(particle_db):
# electric charges table
# electric charges table
string
+=
"
static constexpr std::array<int16_t, size> electric_charges = {
\n
"
string
+=
"
static constexpr std::array<int16_t, size> electric_charges = {
\n
"
for
p
in
particle_db
.
values
():
for
p
in
particle_db
.
values
():
string
+=
"
{charge:d},
\n
"
.
format
(
charge
=
p
[
'
electric_charge
'
])
string
+=
"
{charge:d},
\n
"
.
format
(
charge
=
p
[
'
electric_charge
'
]
//
3
)
string
+=
"
};
\n
"
string
+=
"
};
\n
"
# anti-particle table
# anti-particle table
...
@@ -416,7 +416,7 @@ def gen_classes(particle_db):
...
@@ -416,7 +416,7 @@ def gen_classes(particle_db):
string
+=
"
* Particle properties are taken from the PYTHIA8 ParticleData.xml file:<br>
\n
"
string
+=
"
* Particle properties are taken from the PYTHIA8 ParticleData.xml file:<br>
\n
"
string
+=
"
* - pdg=
"
+
str
(
particle_db
[
cname
][
'
pdg
'
])
+
"
\n
"
string
+=
"
* - pdg=
"
+
str
(
particle_db
[
cname
][
'
pdg
'
])
+
"
\n
"
string
+=
"
* - mass=
"
+
str
(
particle_db
[
cname
][
'
mass
'
])
+
"
GeV
\n
"
string
+=
"
* - mass=
"
+
str
(
particle_db
[
cname
][
'
mass
'
])
+
"
GeV
\n
"
string
+=
"
* - charge=
"
+
str
(
particle_db
[
cname
][
'
electric_charge
'
]
/
3
)
+
"
\n
"
string
+=
"
* - charge=
"
+
str
(
particle_db
[
cname
][
'
electric_charge
'
]
//
3
)
+
"
\n
"
string
+=
"
* - name=
"
+
str
(
cname
)
+
"
\n
"
string
+=
"
* - name=
"
+
str
(
cname
)
+
"
\n
"
string
+=
"
* - anti=
"
+
str
(
antiP
)
+
"
\n
"
string
+=
"
* - anti=
"
+
str
(
antiP
)
+
"
\n
"
if
(
particle_db
[
cname
][
'
isNucleus
'
]):
if
(
particle_db
[
cname
][
'
isNucleus
'
]):
...
@@ -425,19 +425,18 @@ def gen_classes(particle_db):
...
@@ -425,19 +425,18 @@ def gen_classes(particle_db):
string
+=
"
*/
\n\n
"
string
+=
"
*/
\n\n
"
string
+=
"
class
"
+
cname
+
"
{
\n
"
string
+=
"
class
"
+
cname
+
"
{
\n
"
string
+=
"
public:
\n
"
string
+=
"
public:
\n
"
string
+=
"
static constexpr Code GetCode() { return Type; }
\n
"
string
+=
"
"
+
cname
+
"
() = delete;
\n
"
string
+=
"
static constexpr corsika::units::si::HEPMassType GetMass() { return corsika::GetMass(Type); }
\n
"
string
+=
"
static constexpr Code code = Code::
"
+
cname
+
"
;
\n
"
string
+=
"
static constexpr corsika::units::si::ElectricChargeType GetCharge() { return corsika::GetCharge(Type); }
\n
"
string
+=
"
static constexpr HEPMassType mass() {return corsika::mass(code);}
\n
"
string
+=
"
static constexpr int16_t GetChargeNumber() { return corsika::GetChargeNumber(Type); }
\n
"
string
+=
"
static constexpr ElectricChargeType charge() { return corsika::charge(code); }
\n
"
string
+=
"
static std::string const& GetName() { return corsika::GetName(Type); }
\n
"
string
+=
"
static constexpr int16_t charge_number() { return corsika::charge_number(code); }
\n
"
string
+=
"
static constexpr Code GetAntiParticle() { return AntiType; }
\n
"
string
+=
"
static std::string const& name() { return corsika::name(code); }
\n
"
string
+=
"
static constexpr bool IsNucleus() { return corsika::IsNucleus(Type); }
\n
"
string
+=
"
static constexpr bool is_nucleus() { return corsika::is_nucleus(code); }
\n
"
string
+=
"
static constexpr int16_t GetNucleusA() { return corsika::GetNucleusA(Type); }
\n
"
string
+=
"
static constexpr int16_t nucleus_A() { return corsika::nucleus_A(code); }
\n
"
string
+=
"
static constexpr int16_t GetNucleusZ() { return corsika::GetNucleusZ(Type); }
\n
"
string
+=
"
static constexpr int16_t nucleus_Z() { return corsika::nucleus_Z(code); }
\n
"
string
+=
"
static constexpr Code Type = Code::
"
+
cname
+
"
;
\n
"
string
+=
"
static constexpr Code anti_code = Code::
"
+
antiP
+
"
;
\n
"
string
+=
"
static constexpr Code AntiType = Code::
"
+
antiP
+
"
;
\n
"
string
+=
"
private:
\n
"
string
+=
"
private:
\n
"
string
+=
"
static constexpr CodeIntType TypeIndex = static_cast<CodeIntType
const>(Typ
e);
\n
"
string
+=
"
static constexpr CodeIntType TypeIndex = static_cast<CodeIntType
>(cod
e);
\n
"
string
+=
"
};
\n
"
string
+=
"
};
\n
"
return
string
return
string
...
@@ -448,7 +447,9 @@ def gen_classes(particle_db):
...
@@ -448,7 +447,9 @@ def gen_classes(particle_db):
#
#
def
inc_start
():
def
inc_start
():
string
=
(
'
// generated by pdxml_reader.py
\n
'
string
=
(
'
// generated by pdxml_reader.py
\n
'
'
// MANUAL EDITS ON OWN RISK. THEY WILL BE OVERWRITTEN.
\n
'
)
'
// MANUAL EDITS ON OWN RISK. THEY WILL BE OVERWRITTEN.
\n
'
'
\n
'
'
namespace corsika {
\n
'
)
return
string
return
string
...
@@ -471,7 +472,7 @@ def detail_end():
...
@@ -471,7 +472,7 @@ def detail_end():
#
#
#
#
def
inc_end
():
def
inc_end
():
string
=
""
string
=
"
} // end namespace corsika
"
return
string
return
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment