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
bdac768d
Commit
bdac768d
authored
2 years ago
by
Maximilian Reininghaus
Committed by
Nikos Karastathis
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
implemented testEMThinning
parent
57c54a94
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!466
Resolve "Implement thinning algorithms"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/modules/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/modules/CMakeLists.txt
tests/modules/testEMThinning.cpp
+223
-0
223 additions, 0 deletions
tests/modules/testEMThinning.cpp
with
224 additions
and
0 deletions
tests/modules/CMakeLists.txt
+
1
−
0
View file @
bdac768d
...
...
@@ -13,6 +13,7 @@ set (test_modules_sources
testSibyll.cpp
testEpos.cpp
testRadio.cpp
testEMThinning.cpp
testSophia.cpp
)
...
...
This diff is collapsed.
Click to expand it.
tests/modules/testEMThinning.cpp
0 → 100644
+
223
−
0
View file @
bdac768d
/*
* (c) Copyright 2022 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*/
#include
<corsika/framework/core/PhysicalUnits.hpp>
#include
<corsika/framework/geometry/Point.hpp>
#include
<corsika/framework/geometry/Vector.hpp>
#include
<corsika/framework/utility/CorsikaFenv.hpp>
#include
<corsika/media/Environment.hpp>
#include
<corsika/modules/thinning/EMThinning.hpp>
#include
<SetupStack.hpp>
#include
<SetupTestTrajectory.hpp>
#include
<SetupTestEnvironment.hpp>
#include
<catch2/catch.hpp>
#include
<boost/accumulators/accumulators.hpp>
#include
<boost/accumulators/statistics/stats.hpp>
#include
<boost/accumulators/statistics/mean.hpp>
using
namespace
corsika
;
using
DummyEnvironmentInterface
=
IMediumPropertyModel
<
IMagneticFieldModel
<
IMediumModel
>>
;
using
DummyEnvironment
=
Environment
<
DummyEnvironmentInterface
>
;
TEST_CASE
(
"EMThinning"
,
"process,secondary"
)
{
RNGManager
<>::
getInstance
().
registerRandomStream
(
"thinning"
);
logging
::
set_level
(
logging
::
level
::
info
);
feenableexcept
(
FE_INVALID
);
using
EnvType
=
DummyEnvironment
;
EnvType
env
;
CoordinateSystemPtr
const
&
rootCS
=
env
.
getCoordinateSystem
();
// setup empty particle stack
test
::
Stack
stack
;
stack
.
clear
();
SECTION
(
"non-EM primary"
)
{
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Proton
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
auto
sec1
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
PiPlus
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
auto
sec2
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
KMinus
,
8
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
EMThinning
thinning
{
100
_GeV
,
1e20
};
thinning
.
doSecondaries
(
view
);
REQUIRE
(
view
.
getEntries
()
==
2
);
REQUIRE
(
sec1
.
getWeight
()
==
1.
);
REQUIRE
(
sec2
.
getWeight
()
==
1.
);
}
SECTION
(
"non-EM interaction"
)
{
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Photon
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
// mimic photohadronic interaction, more than 2 secondaries
auto
sec1
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
PiPlus
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
auto
sec2
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
KMinus
,
3
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
auto
sec3
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Proton
,
5
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
EMThinning
thinning
{
100
_GeV
,
1e20
};
thinning
.
doSecondaries
(
view
);
REQUIRE
(
view
.
getEntries
()
==
3
);
REQUIRE
(
sec1
.
getWeight
()
==
1.
);
REQUIRE
(
sec2
.
getWeight
()
==
1.
);
REQUIRE
(
sec3
.
getWeight
()
==
1.
);
}
SECTION
(
"above threshold"
)
{
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Photon
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
auto
sec1
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Electron
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
auto
sec2
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Positron
,
8
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
EMThinning
thinning
{
1
_MeV
,
1e20
};
thinning
.
doSecondaries
(
view
);
REQUIRE
(
view
.
getEntries
()
==
2
);
REQUIRE
(
sec1
.
getWeight
()
==
1.
);
REQUIRE
(
sec2
.
getWeight
()
==
1.
);
}
SECTION
(
"below threshold"
)
{
EMThinning
thinning
{
100
_GeV
,
1e20
};
boost
::
accumulators
::
accumulator_set
<
double
,
boost
::
accumulators
::
stats
<
boost
::
accumulators
::
tag
::
mean
>>
acc
;
boost
::
accumulators
::
accumulator_set
<
HEPEnergyType
,
boost
::
accumulators
::
stats
<
boost
::
accumulators
::
tag
::
mean
>>
accE
;
// statistical test, 10000 iterations
for
(
int
i
=
0
;
i
<
10'000
;
++
i
)
{
stack
.
clear
();
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Photon
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Electron
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Positron
,
8
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
thinning
.
doSecondaries
(
view
);
REQUIRE
(
view
.
getEntries
()
==
1
);
double
sumWeight
{};
HEPEnergyType
sumE
{};
for
(
auto
&
p
:
view
)
{
sumWeight
+=
p
.
getWeight
();
sumE
+=
p
.
getWeight
()
*
p
.
getEnergy
();
}
acc
(
sumWeight
);
accE
(
sumE
);
}
REQUIRE
(
boost
::
accumulators
::
mean
(
acc
)
==
Approx
(
2
).
epsilon
(
2e-2
));
REQUIRE
(
boost
::
accumulators
::
mean
(
accE
)
/
1
_GeV
==
Approx
(
10
).
epsilon
(
2e-2
));
}
SECTION
(
"weight limitation"
)
{
double
constexpr
maxWeight
=
3
;
// min acceptance prob. >= 0.3333
EMThinning
thinning
{
100
_GeV
,
maxWeight
};
boost
::
accumulators
::
accumulator_set
<
double
,
boost
::
accumulators
::
stats
<
boost
::
accumulators
::
tag
::
mean
>>
acc
;
boost
::
accumulators
::
accumulator_set
<
HEPEnergyType
,
boost
::
accumulators
::
stats
<
boost
::
accumulators
::
tag
::
mean
>>
accE
;
// statistical test, 10000 iterations
for
(
int
i
=
0
;
i
<
10'000
;
++
i
)
{
stack
.
clear
();
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Photon
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Electron
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Positron
,
8
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
thinning
.
doSecondaries
(
view
);
double
sumWeight
{};
HEPEnergyType
sumE
{};
for
(
auto
&
p
:
view
)
{
auto
const
w
=
p
.
getWeight
();
REQUIRE
(
w
<=
maxWeight
);
sumWeight
+=
w
;
sumE
+=
p
.
getEnergy
()
*
w
;
}
acc
(
sumWeight
);
accE
(
sumE
);
}
REQUIRE
(
boost
::
accumulators
::
mean
(
acc
)
==
Approx
(
2
).
epsilon
(
2e-2
));
REQUIRE
(
boost
::
accumulators
::
mean
(
accE
)
/
1
_GeV
==
Approx
(
10
).
epsilon
(
2e-2
));
}
SECTION
(
"max. weight reached"
)
{
double
constexpr
maxWeight
=
3
;
// min acceptance prob. >= 0.3333
EMThinning
thinning
{
100
_GeV
,
maxWeight
};
for
(
int
i
=
0
;
i
<
10'000
;
++
i
)
{
stack
.
clear
();
auto
prim
=
stack
.
addParticle
(
std
::
make_tuple
(
Code
::
Photon
,
10
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
}),
Point
(
rootCS
,
0
_m
,
0
_m
,
0
_m
),
0
_ns
));
prim
.
setWeight
(
3.5
);
test
::
StackView
view
{
prim
};
auto
projectile
=
view
.
getProjectile
();
auto
sec1
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Electron
,
2
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
auto
sec2
=
projectile
.
addSecondary
(
std
::
make_tuple
(
Code
::
Positron
,
8
_GeV
,
DirectionVector
(
rootCS
,
{
1
,
0
,
0
})));
// cannot perform thinning anymore, always keep all secondaries, weight unchanged
thinning
.
doSecondaries
(
view
);
REQUIRE
(
view
.
getEntries
()
==
2
);
REQUIRE
(
sec1
.
getWeight
()
==
3.5
);
REQUIRE
(
sec2
.
getWeight
()
==
3.5
);
}
}
}
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