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 6 additions and 1291 deletions
#ifndef PARTICLEPROPERTIES_HPP
#define PARTICLEPROPERTIES_HPP
#include <array>
#include <cstdint>
#include <iostream>
namespace ParticleProperties {
typedef int16_t PDGCode;
#include "generated_particle_properties.inc"
auto constexpr getMass(InternalParticleCode const p)
{
return masses[static_cast<uint8_t const>(p)];
}
auto constexpr getPDG(InternalParticleCode const p)
{
return pdg_codes[static_cast<uint8_t const>(p)];
}
auto constexpr getElectricChargeQN(InternalParticleCode const p)
{
return electric_charge[static_cast<uint8_t const>(p)];
}
auto constexpr getElectricCharge(InternalParticleCode const p)
{
return getElectricChargeQN(p) * (phys::units::e / 3.);
}
auto const getName(InternalParticleCode const p)
{
return names[static_cast<uint8_t const>(p)];
}
std::ostream& operator<< (std::ostream& stream, InternalParticleCode const p)
{
stream << getName(p);
return stream;
}
}
#endif
set (STACK_HEADERS StackOne.h)
add_library (CORSIKAstack INTERFACE)
#set_target_properties (CORSIKAstack PROPERTIES VERSION ${PROJECT_VERSION})
#set_target_properties (CORSIKAstack PROPERTIES SOVERSION 1)
#set_target_properties (CORSIKAstack PROPERTIES PUBLIC_HEADER "${STACK_HEADERS}")
#target_link_libraries (CORSIKAstackinterface CORSIKAunits)
#target_include_directories (CORSIKAstack PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories (CORSIKAstack INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES StackOne.h DESTINATION include/Stack)
#ifndef _include_StackIterator_h__
#define _include_StackIterator_h__
#include <iostream>
#include <iomanip>
namespace stack {
template<class Stack, class Particle> class StackIteratorInfo;
/**
The main interface to iterator over objects on a stack.
*/
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; }
inline StackIterator<Stack,Particle>& base_ref() { return static_cast<StackIterator<Stack, Particle>&>(*this); }
inline const StackIterator<Stack,Particle>& base_ref() const { return static_cast<const StackIterator<Stack, Particle>&>(*this); }
};
/**
Internal helper class for StackIterator
*/
template<class _Stack, class Particle>
class StackIteratorInfo {
friend Particle;
private:
StackIteratorInfo() {}
protected:
inline _Stack& Stack() { return static_cast<StackIterator<_Stack, Particle>*>(this)->GetStack(); }
inline int Index() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetIndex(); }
inline const _Stack& Stack() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetStack(); }
};
} // end namespace stack
#endif
#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
/**
All classes around management of particles on a stack.
*/
namespace stack {
/**
Interface definition of a Stack object. The Stack implements the
std-type begin/end function to allow integration in normal for
loops etc.
*/
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); }
/// increase stack size, create new particle at end of stack
iterator NewParticle() { IncrementSize(); return iterator(*this, GetSize()-1); }
/// delete last particle on stack by decrementing stack size
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
The template argument Stack determines the type of Stack object
the data is stored in. A pointer to the Stack object is part of
the StackIterator. In addition to Stack the iterator only knows
the index fIndex in the Stack data.
The template argument Particles acts as a policy to provide
readout function of Particle data from the stack. The Particle
class must know how to retrieve information from the Stack data
for a particle entry at any index fIndex.
*/
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
This is the class where custom ...
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>