IAP GITLAB

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AirShowerPhysics/corsika
  • rulrich/corsika
  • AAAlvesJr/corsika
  • Andre/corsika
  • arrabito/corsika
  • Nikos/corsika
  • olheiser73/corsika
  • AirShowerPhysics/papers/corsika
  • pranav/corsika
9 results
Show changes
Showing
with 231 additions and 1170 deletions
#ifndef _include_stackone_h_
#define _include_stackone_h_
#include <vector>
#include <string>
#include <StackInterface/Stack.h>
namespace stack {
/**
Example of a particle object on the stack.
*/
template<typename _Stack>
class ParticleReadOne : public StackIteratorInfo<_Stack, ParticleReadOne<_Stack> >
{
using StackIteratorInfo<_Stack, ParticleReadOne>::GetIndex;
using StackIteratorInfo<_Stack, ParticleReadOne>::GetStack;
public:
void SetId(const int id) { GetStack().SetId(GetIndex(), id); }
void SetEnergy(const double e) { GetStack().SetEnergy(GetIndex(), e); }
int GetId() const { GetStack().GetId(GetIndex()); }
double GetEnergy() const { GetStack().GetEnergy(GetIndex()); }
double GetPDG() const { return 0; } // ConvertToPDG(GetId()); }
void SetPDG(double v) { GetStack().SetId(0, 0); } //fIndex, ConvertFromPDG(v)); }
};
/**
Memory implementation of the most simple particle stack object.
*/
class StackOneImpl
{
private:
/// the actual memory to store particle data
std::vector<int> fId;
std::vector<double> fData;
public:
void Clear() { fData.clear(); }
int GetSize() const { return fData.size(); }
int GetCapacity() const { return fData.size(); }
void SetId(const int i, const int id) { fId[i] = id; }
void SetEnergy(const int i, const double e) { fData[i] = e; }
const int GetId(const int i) const { return fId[i]; }
const double GetEnergy(const int i) const { return fData[i]; }
/**
Function to copy particle at location i2 in stack to i1
*/
void Copy(const int i1, const int i2) {
fData[i2] = fData[i1];
fId[i2] = fId[i1];
}
protected:
void IncrementSize() { fData.push_back(0.); fId.push_back(0.); }
void DecrementSize() { if (fData.size()>0) { fData.pop_back(); fId.pop_back(); } }
};
typedef StackIterator<StackOneImpl, ParticleReadOne<StackOneImpl> > ParticleOne;
typedef Stack<StackOneImpl, ParticleOne> StackOne;
} // end namespace
#endif
add_library (CORSIKAprocesssequence INTERFACE)
target_include_directories (CORSIKAprocesssequence INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES ProcessSequence.h
DESTINATION include/ProcessSequence)
#ifndef _include_ProcessSequence_h_
#define _include_ProcessSequence_h_
#include <iostream>
#include <typeinfo>
using namespace std;
namespace processes {
/**
/class Base
The structural base type of a process object in a
ProcessSequence. Both, the ProcessSequence and all its elements
are of type Base<T>
*/
template <typename derived>
struct Base
{
const derived& GetRef() const
{
return static_cast<const derived&>(*this);
}
};
/**
\class ProcessSequence
A compile time static list of processes. The compiler will
generate a new type based on template logic containing all the
elements.
\comment Using CRTP pattern, https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
*/
template <typename T1, typename T2>
class ProcessSequence : public Base <ProcessSequence<T1,T2> >
{
public:
const T1& A;
const T2& B;
ProcessSequence(const T1& in_A, const T2& in_B)
: A(in_A)
, B(in_B)
{ }
template<typename D>
inline void DoContinuous(D& d) const { A.DoContinuous(d); B.DoContinuous(d); } // add trajectory
template<typename D>
inline double MinStepLength(D& d) const { return min(A.MinStepLength(d), B.MinStepLength(d)); }
//template<typename D>
//inline Trajectory Transport(D& d, double& length) const { A.Transport(d, length); B.Transport(d, length); }
template<typename D>
inline void DoDiscrete(D& d) const { A.DoDiscrete(d); B.DoDiscrete(d); }
};
template <typename T1, typename T2>
inline
const ProcessSequence<T1,T2>
operator+ (const Base<T1>& A, const Base<T2>& B)
{
return ProcessSequence<T1,T2>( A.GetRef(), B.GetRef() );
}
/*
template <typename T1>
struct depth_lhs
{
static const int num = 0;
};
// terminating condition
template <typename T1, typename T2>
struct depth_lhs< Sequence<T1,T2> >
{
// try to expand the left node (T1) which might be a Sequence type
static const int num = 1 + depth_lhs<T1>::num;
};
*/
/*
template <typename T1>
struct mat_ptrs
{
static const int num = 0;
inline static void
get_ptrs(const Process** ptrs, const T1& X)
{
ptrs[0] = reinterpret_cast<const Process*>(&X);
}
};
template <typename T1, typename T2>
struct mat_ptrs< Sequence<T1,T2> >
{
static const int num = 1 + mat_ptrs<T1>::num;
inline static void
get_ptrs(const Process** in_ptrs, const Sequence<T1,T2>& X)
{
// traverse the left node
mat_ptrs<T1>::get_ptrs(in_ptrs, X.A);
// get address of the matrix on the right node
in_ptrs[num] = reinterpret_cast<const Process*>(&X.B);
}
};
*/
/*
template<typename T1, typename T2>
const Process&
Process::operator=(const Sequence<T1,T2>& X)
{
int N = 1 + depth_lhs< Sequence<T1,T2> >::num;
const Process* ptrs[N];
mat_ptrs< Sequence<T1,T2> >::get_ptrs(ptrs, X);
int r = ptrs[0]->rows;
int c = ptrs[0]->cols;
// ... check that all matrices have the same size ...
set_size(r, c);
for(int j=0; j<r*c; ++j)
{
double sum = ptrs[0]->data[j];
for(int i=1; i<N; ++i)
{
sum += ptrs[i]->data[j];
}
data[j] = sum;
}
return *this;
}
*/
} // end namespace
#endif
add_library (CORSIKAstack INTERFACE)
target_include_directories (CORSIKAstack INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES Stack.h StackIterator.h
DESTINATION include/Stack)
add_library (CORSIKAstackinterface INTERFACE)
target_include_directories (CORSIKAstackinterface INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES Stack.h StackIterator.h
DESTINATION include/StackInterface)
#ifndef _include_Stack_h__
#define _include_Stack_h__
#include <StackInterface/StackIterator.h> // to help application programmres
namespace stack {
/**
Interface definition of a Stack object.
*/
template<typename DataImpl, typename Particle>
class Stack : public DataImpl {
public:
using DataImpl::GetCapacity;
using DataImpl::GetSize;
using DataImpl::Clear;
using DataImpl::Copy;
using DataImpl::IncrementSize;
using DataImpl::DecrementSize;
public:
typedef Particle iterator;
typedef const Particle const_iterator;
/// these are functions required by std containers and std loops
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, GetSize()); }
iterator last() { return iterator(*this, GetSize()-1); }
/// these are functions required by std containers and std loops
const_iterator cbegin() const { return const_iterator(*this, 0); }
const_iterator cend() const { return const_iterator(*this, GetSize()); }
const_iterator clast() const { return const_iterator(*this, GetSize()-1); }
iterator NewParticle() { IncrementSize(); return iterator(*this, GetSize()-1); }
void DeleteLast() { DecrementSize(); }
};
} // end namespace
#endif
#ifndef _include_StackIterator_h__
#define _include_StackIterator_h__
#include <iostream>
#include <iomanip>
namespace stack {
// forward decl.
template<class Stack, class Particle> class StackIteratorInfo;
/**
\class StackIterator
The StackIterator is the main interface to iterator over
particles on a stack. At the same time StackIterator is a
Particle object by itself, thus there is no difference between
type and ref_type for convenience of the physicist.
This allows to write code like
\verbatim
for (auto& p : theStack) { p.SetEnergy(newEnergy); }
\endverbatim
*/
template<typename Stack, typename Particle>
class StackIterator : public Particle
{
friend Stack;
friend Particle;
friend StackIteratorInfo<Stack,Particle>;
private:
int fIndex;
//#warning stacks should not be copied because of this:
Stack* fData;
public:
StackIterator() : fData(0), fIndex(0) { }
StackIterator(Stack& data, const int index) : fData(&data), fIndex(index) { }
StackIterator(const StackIterator& mit) : fData(mit.fData), fIndex(mit.fIndex) { }
StackIterator& operator++() { ++fIndex; return *this; }
StackIterator operator++(int) { StackIterator tmp(*this); ++fIndex; return tmp; }
bool operator==(const StackIterator& rhs) { return fIndex == rhs.fIndex; }
bool operator!=(const StackIterator& rhs) { return fIndex != rhs.fIndex; }
StackIterator& operator*() { return *this; }
const StackIterator& operator*() const { return *this; }
protected:
int GetIndex() const { return fIndex; }
Stack& GetStack() { return *fData; }
const Stack& GetStack() const { return *fData; }
// this is probably not needed rigth now:
//inline StackIterator<Stack,Particle>& BaseRef() { return static_cast<StackIterator<Stack, Particle>&>(*this); }
//inline const StackIterator<Stack,Particle>& BaseRef() const { return static_cast<const StackIterator<Stack, Particle>&>(*this); }
};
/**
\class StackIteratorInfo
Internal helper class for StackIterator. Document better...
*/
template<typename _Stack, typename Particle>
class StackIteratorInfo {
friend Particle;
private:
StackIteratorInfo() {}
protected:
inline _Stack& GetStack() { return static_cast<StackIterator<_Stack, Particle>*>(this)->GetStack(); }
inline int GetIndex() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetIndex(); }
inline const _Stack& GetStack() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetStack(); }
};
} // end namespace stack
#endif
add_library (CORSIKAunits INTERFACE)
target_include_directories (CORSIKAunits
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ThirdParty>
$<INSTALL_INTERFACE:include>
)
install (FILES PhysicalUnits.h DESTINATION include/Units)
# code testing
add_executable (testUnits testUnits.cc)
target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2
add_test(NAME testUnits COMMAND testUnits)
#ifndef _include_PhysicalUnits_h_
#define _include_PhysicalUnits_h_
#include <phys/units/quantity.hpp>
#include <phys/units/io.hpp>
#include <phys/units/physical_constants.hpp>
/**
@file PhysicalUnits
Define _XeV literals, alowing 10_GeV in the code.
*/
/*using namespace phys::units::io;
using namespace phys::units::literals;*/
namespace phys {
namespace units {
namespace literals {
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(eV) )
}
}
}
using Length = phys::units::quantity<phys::units::length_d, double>;
using Time = phys::units::quantity<phys::units::time_interval_d, double>;
using Speed = phys::units::quantity<phys::units::speed_d, double>;
using Frequency = phys::units::quantity<phys::units::frequency_d, double>;
using ElectricCharge = phys::units::quantity<phys::units::electric_charge_d, double>;
#endif
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch.hpp>
#include <Units/PhysicalUnits.h>
using namespace phys::units;
using namespace phys::units::literals;
TEST_CASE( "PhysicalUnits", "[Units]" ) {
REQUIRE( 1_m/1_m == 1 );
}
This diff is collapsed.
#include <utl/Stack.h>
int
main(int argc, char** argv)
{
return 0;
}
add_subdirectory (NullModel)
#include <Processes/NullModel/NullModel.h>
#ifndef _Physics_NullModel_NullModel_h_
#define _Physics_NullModel_NullModel_h_
namespace processes {
class NullModel {
public:
NullModel();
~NullModel();
void init();
void run();
double GetStepLength();
};
}
#endif
# CORSIKA 8 Framework for Particle Cascades in Astroparticle Physics
The purpose of CORSIKA 8 is to simulate any particle cascades in
astroparticle physics or astrophysical context. A lot of emphasis has been
put on modularity, flexibility, completeness, validation and
correctness. To boost computational efficiency, different techniques
are provided, like thinning or cascade equations. The aim is that
CORSIKA 8 remains the most comprehensive framework for simulating
particle cascades with stochastic and continuous processes.
The software makes extensive use of static design patterns and
compiler optimization. Thus, the most fundamental configuration
decisions of the user must be performed at compile time. At run time,
model parameters can still be changed.
CORSIKA 8 is by default released under the BSD 3-Clause License. See [license
file](https://gitlab.iap.kit.edu/AirShowerPhysics/corsika/blob/master/LICENSE)
which is part of every release and the source code.
If you use, or want to refer to, CORSIKA 8 please cite ["Towards a Next
Generation of CORSIKA: A Framework for the Simulation of Particle
Cascades in Astroparticle Physics", Comput. Softw. Big Sci. 3 (2019)
2](https://doi.org/10.1007/s41781-018-0013-0) as well as
["Simulating radio emission from particle cascades with CORSIKA 8", Astropart. Phys. 166 (2025)
103072](https://doi.org/10.1016/j.astropartphys.2024.103072).
We kindly ask (and require) any relevant improvement or addition to be offered or
contributed to the main CORSIKA 8 repository for the benefit of the
whole community.
CORSIKA 8 makes use of various third-party code, in particular interaction
models. Please check the [using and collaborating
agreement](https://gitlab.iap.kit.edu/AirShowerPhysics/corsika/blob/master/USING_COLLABORATING.md)
for further information on this topic.
If you plan to contribute to CORSIKA 8, please check the guidelines outlined here:
[coding
guidelines](https://gitlab.iap.kit.edu/AirShowerPhysics/corsika/blob/master/CONTRIBUTING.md). Code
that fails the review by the CORSIKA 8 author group must be improved
before it can be merged in the official code base. After your code has
been accepted and merged, you become a contributor of the CORSIKA 8
project (code author).
IMPORTANT: Before you contribute, you need to read and agree to the conditions set out in the
[using and collaborating
agreement](https://gitlab.iap.kit.edu/AirShowerPhysics/corsika/blob/master/USING_COLLABORATING.md).
The agreement can be discussed, and eventually improved if necessary.
## Get in contact
* Join our chat threads using Mattermost via this [invite link](https://mattermost.hzdr.de/signup_user_complete/?id=xtdd8jyt6trbiezt71gaz3z4ge&md=link&sbr=su). Click the `GitLab` button, then `Sign in with Helmholtz ID`. You will be able to make an account by either finding your institution, or using your e.g. ORCID, GitHub, or Google account.
* Connect to https://gitlab.iap.kit.edu, register yourself and join the "Air Shower Physics" group. Write to us on Mattermost (in the User Questions channel), or directly contact one of the [steering comittee members](https://gitlab.iap.kit.edu/AirShowerPhysics/corsika/-/wikis/Steering-Committee) in case there are problems with that.
* Connect to corsika-devel@lists.kit.edu (self-register at
https://www.lists.kit.edu/sympa/subscribe/corsika-devel) to get in
touch with the project.
## Installation
CORSIKA 8 is tested regularly at least on `gcc11.0.0` and `clang-14.0.0`.
### Prerequisites
You will also need:
- Python 3 (supported versions are Python >= 3.6), with pip
- cmake > 3.4
- git
- g++, gfortran, binutils, make
- optional: FLUKA (see below)
On a bare Ubuntu machine, just add:
``` shell
sudo apt-get install python3 python3-pip cmake g++ gfortran git doxygen graphviz
```
### Creating a virtual environment and Conan
It is recommended that you install CORSIKA 8 and its dependencies within a python3 virtual environment.
To do so, you can run the following.
``` shell
# Create the environment using your native python3 binary
python3 -m venv /path/to/new/virtual/environment/corsika-8
# Load the environment (should be run each time you open a new terminal)
source /path/to/new/virtual/environment/corsika-8/bin/activate
```
You will need to load the environment each time that you open a new terminal.
CORSIKA 8 uses the [conan](https://conan.io/) package manager to
manage our dependencies. Currently, version 2.50.0 or higher is required.
**Note**: if you are NOT using a virtual environment, you may want to use the `pip install --user` flag.
``` shell
pip install conan particle==0.25.1 numpy
```
### Enabling FLUKA support
For legal reasons we do not distribute/bundle FLUKA together with CORSIKA 8.
As FLUKA is the standard low-energy hadronic interaction model for CORSIKA 8, you have to download
it separately from (http://www.fluka.org/), which requires registering there as FLUKA user.
The following should be done *before* compiling CORSIKA 8:
1. Note your system's version of gfortran (`gfortran --version`) and glibc (`ldd --version`)
2. Download the FLUKA __binary__, ensuring that it matches the versions you found above
3. Download the FLUKA __data file__ (will be named something similar to __fluka20xy.z-data.tar.gz__).
4. Un-tar the files that you downloaded using `tar -xf <filename>`
5. Set environmental variables `export FLUFOR=gfortran` and `export FLUPRO=<path to where you unzipped the files>`. Note that the `FLUPRO` directory should contain __libflukahp.a__. Both of these variables will have to be set every time you open a new terminal.
6. Go to the `FLUPRO` directory and run `make`. This will compile an exe, __flukahp__, in your current directory.
7. Follow the normal steps to compile CORSIKA 8 (see below).
When you later install CORSIKA 8, you should see a message during the __cmake__ step indicating the FLUKA was correctly found.
``` shell
libflukahp.a found in directory <some location here> via FLUPRO environment variable
FLUKA support is enabled.
```
### Compiling CORSIKA 8
Once Conan is installed and FLUKA provided, follow these steps to download and install CORSIKA 8:
``` shell
cd ./top/directory/for/corsika/installation
git clone --recursive git@gitlab.iap.kit.edu:AirShowerPhysics/corsika.git
# Or for https: git clone --recursive https://gitlab.iap.kit.edu/AirShowerPhysics/corsika.git
mkdir corsika-build
cd corsika-build
../corsika/conan-install.sh --source-directory ../corsika --release-with-debug
# conan-install.sh takes required options from command line to install dependencies for 'Debug', 'Release' and 'RelWithDebInfo' builds.
../corsika/corsika-cmake.sh -c "-DCMAKE_BUILD_TYPE="RelWithDebInfo" -DWITH_FLUKA=ON -DCMAKE_INSTALL_PREFIX=../corsika-install"
make -j4 #The number should match the number of available cores on your machine
make install
```
## Alternate installation using docker containers
There are docker containers prepared that bring all the environment and packages you need to run CORSIKA. See [docker hub](https://hub.docker.com/repository/docker/corsika/devel) for a complete overview.
### Prerequisites
You only need docker, e.g. on Ubuntu: `sudo apt-get install docker` and of course root access.
### Compiling
Follow these steps to download and install CORSIKA 8, master development version
```shell
cd ./top/directory/for/corsika/installation
git clone --recursive git@gitlab.iap.kit.edu:AirShowerPhysics/corsika.git
sudo docker run -v $PWD:/corsika -it corsika/devel:clang-8 /bin/bash
mkdir corsika-build
cd corsika-build
../corsika/conan-install.sh --source-directory ../corsika --release-with-debug
# conan-install.sh takes required options from command line to install dependencies for 'Debug', 'Release' and 'RelWithDebInfo' builds.
../corsika/corsika-cmake.sh -c "-DCMAKE_BUILD_TYPE="RelWithDebInfo" -DWITH_FLUKA=ON -DCMAKE_INSTALL_PREFIX=../corsika-install"
make -j4 #The number should match the number of available cores on your machine
make install
```
## Running Unit Tests
To run the unit tests, do the following.
```shell
cd ./corsika-build
ctest -j4 #The number should match the number of available cores on your machine
```
## Running applications and examples
### Standard applications
Applications for standard use-cases are located in the `applications` directory.
These are example scripts that can be used directly or slightly modified for your use case.
See [applications/README.md] for more.
The applications are compiled automatically after running `make` and will appear your `corsika-build/bin` directory.
After running `make install` the binaries will also be copied into your `corsika-install/bin` directory as well.
For example, from inside your `corsika-install/bin` directory, run
```shell
c8_air_shower --pdg 2212 -E 1e5 -f my_shower
```
This will run a vertical 100 TeV proton shower and will create and put the output into `./my_shower`.
### Building the examples
Unlike the applications, the examples must be compiled as a second step.
From your top corsika directory, (the one that includes `corsika-build` and `corsika-install`) run
```shell
export CONAN_DEPENDENCIES=$PWD/corsika-install/lib/cmake/dependencies
cmake -DCMAKE_TOOLCHAIN_FILE=${CONAN_DEPENDENCIES}/conan_toolchain.cmake -DCMAKE_PREFIX_PATH=${CONAN_DEPENDENCIES} -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dcorsika_DIR=$PWD/corsika-build -DWITH_FLUKA=ON -S $PWD/corsika/examples -B $PWD/corsika-build-examples
cd corsika-build-examples
make -j4 #The number should match the number of available cores on your machine
```
You can run the examples by using the binaries in `corsika-build-examples/bin/`.
For example:
```shell
corsika-build-examples/bin/known_particles
```
This will print out all of the particles that are known by CORSIKA.
### Generating doxygen documentation
To generate the documentation, you need doxygen and graphviz. If you work with
the docker corsika/devel containers this is already included.
Otherwise, e.g. on Ubuntu machines, do:
```shell
sudo apt-get install doxygen graphviz
```
Switch to the `corsika-build` directory and do
```shell
make docs
make install
```
open with firefox:
```shell
firefox ../corsika-install/share/corsika/doc/html/index.html
```
add_library (CORSIKAthirdparty INTERFACE)
target_include_directories (CORSIKAthirdparty SYSTEM
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ThirdParty>
$<INSTALL_INTERFACE:include/ThirdParty>
)
install (DIRECTORY phys DESTINATION include/ThirdParty/)
install (DIRECTORY catch2 DESTINATION include/ThirdParty/)