IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
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
Model registry
Operate
Environments
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
Air Shower Physics
corsika
Commits
8fdd0ebc
Commit
8fdd0ebc
authored
5 years ago
by
Maximilian Reininghaus
Browse files
Options
Downloads
Patches
Plain Diff
added NuclearComposition::WeightedSum for cross-sections etc.
parent
b98289ee
No related branches found
No related tags found
1 merge request
!100
Resolve "Low energy hadronic interactions: UrQMD interface"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Environment/NuclearComposition.h
+24
-0
24 additions, 0 deletions
Environment/NuclearComposition.h
with
24 additions
and
0 deletions
Environment/NuclearComposition.h
+
24
−
0
View file @
8fdd0ebc
...
...
@@ -13,6 +13,8 @@
#define _include_NuclearComposition_h
#include
<corsika/particles/ParticleProperties.h>
#include
<corsika/units/PhysicalUnits.h>
#include
<cassert>
#include
<numeric>
#include
<random>
...
...
@@ -76,6 +78,28 @@ namespace corsika::environment {
}
}
template
<
typename
TFunction
>
auto
WeightedSum
(
TFunction
func
)
const
{
using
ResultQuantity
=
decltype
(
func
(
*
fComponents
.
cbegin
()));
auto
const
sum
=
[](
auto
x
,
auto
y
)
{
return
x
+
y
;
};
auto
const
prod
=
[
&
](
auto
const
compID
,
auto
const
fraction
)
{
return
func
(
compID
)
*
fraction
;
};
if
constexpr
(
phys
::
units
::
is_quantity_v
<
ResultQuantity
>
)
{
return
std
::
inner_product
(
fComponents
.
cbegin
(),
fComponents
.
cend
(),
fNumberFractions
.
cbegin
(),
ResultQuantity
::
zero
(),
// .zero() is defined for quantity types only
sum
,
prod
);
}
else
{
return
std
::
inner_product
(
fComponents
.
cbegin
(),
fComponents
.
cend
(),
fNumberFractions
.
cbegin
(),
ResultQuantity
(
0
),
// in other cases we have to use a bare 0
sum
,
prod
);
}
}
auto
size
()
const
{
return
fNumberFractions
.
size
();
}
auto
const
&
GetFractions
()
const
{
return
fNumberFractions
;
}
...
...
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