IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 08cdf486 authored by ralfulrich's avatar ralfulrich
Browse files

stack example with fwk::Energy and fwk::particle::InternalParticleCode

parent f478571e
No related branches found
No related tags found
No related merge requests found
#include <stack/super_stupid/SuperStupidStack.h> #include <stack/super_stupid/SuperStupidStack.h>
#include <fwk/Particles.h>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace fwk::literals;
// using namespace fwk; // using namespace fwk::io;
void fill(stack::super_stupid::SuperStupidStack& s) { void fill(stack::super_stupid::SuperStupidStack& s) {
for (int i = 0; i < 11; ++i) { for (int i = 0; i < 11; ++i) {
auto p = s.NewParticle(); auto p = s.NewParticle();
p.SetId(i); p.SetId(fwk::particle::InternalParticleCode::Electron);
p.SetEnergy(1.5 * i); p.SetEnergy(1.5_GeV * i);
} }
} }
void read(stack::super_stupid::SuperStupidStack& s) { void read(stack::super_stupid::SuperStupidStack& s) {
cout << "found Stack with " << s.GetSize() << " particles. " << endl; cout << "found Stack with " << s.GetSize() << " particles. " << endl;
double Etot = 0; fwk::quantity<fwk::energy_d> Etot;
for (auto p : s) { Etot += p.GetEnergy(); } for (auto p : s) {
cout << "Etot=" << Etot << endl; Etot += p.GetEnergy();
cout << "particle: " << p.GetId() << " with " << p.GetEnergy()/1_GeV << " GeV" << endl;
}
cout << "Etot=" << Etot << " = " << Etot / 1_GeV << " GeV" << endl;
} }
int main() { int main() {
......
...@@ -13,57 +13,57 @@ ...@@ -13,57 +13,57 @@
#include <fwk/GeneratedParticleProperties.inc> #include <fwk/GeneratedParticleProperties.inc>
namespace fwk { namespace fwk {
/** /**
* @namespace particle * @namespace particle
* *
* The properties of all elementary particles is stored here. The data * The properties of all elementary particles is stored here. The data
* is taken from the Pythia ParticleData.xml file. * is taken from the Pythia ParticleData.xml file.
* *
*/ */
namespace particle { namespace particle {
/** /**
* @function GetMass * @function GetMass
* *
* return mass of particle * return mass of particle
*/ */
auto constexpr GetMass(InternalParticleCode const p) auto constexpr GetMass(InternalParticleCode const p) {
{
return masses[static_cast<uint8_t const>(p)]; return masses[static_cast<uint8_t const>(p)];
} }
auto constexpr GetPDG(InternalParticleCode const p) auto constexpr GetPDG(InternalParticleCode const p) {
{
return pdg_codes[static_cast<uint8_t const>(p)]; return pdg_codes[static_cast<uint8_t const>(p)];
} }
auto constexpr GetElectricChargeNumber(InternalParticleCode const p) auto constexpr GetElectricChargeNumber(InternalParticleCode const p) {
{
return electric_charge[static_cast<uint8_t const>(p)] / 3; return electric_charge[static_cast<uint8_t const>(p)] / 3;
} }
auto constexpr GetElectricCharge(InternalParticleCode const p) auto constexpr GetElectricCharge(InternalParticleCode const p) {
{
return GetElectricChargeNumber(p) * (phys::units::e); return GetElectricChargeNumber(p) * (phys::units::e);
} }
auto const GetName(InternalParticleCode const p) auto const GetName(InternalParticleCode const p) {
{
return names[static_cast<uint8_t const>(p)]; return names[static_cast<uint8_t const>(p)];
} }
std::ostream& operator<< (std::ostream& stream, InternalParticleCode const p) namespace io {
{
stream << GetName(p); std::ostream& operator<<(std::ostream& stream, InternalParticleCode const p) {
return stream; stream << GetName(p);
return stream;
} }
} // end namespace } // namespace io
} // end namespace } // namespace particle
} // namespace fwk
// to inject the operator<< into the root namespace
using namespace fwk::particle::io;
#endif #endif
...@@ -23,13 +23,6 @@ target_include_directories ( ...@@ -23,13 +23,6 @@ target_include_directories (
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
) )
#add_custom_command (
# TARGET
# CORSIKAstackinterfaceerface
# PRE_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CORSIKAstackinterfaceerface_HEADERS} ${PROJECT_BINARY_DIR}/include/corsika
# )
install ( install (
FILES FILES
${CORSIKAstackinterface_HEADERS} ${CORSIKAstackinterface_HEADERS}
......
#ifndef _include_PhysicalUnits_h_ #ifndef _include_PhysicalUnits_h_
#define _include_PhysicalUnits_h_ #define _include_PhysicalUnits_h_
#include <phys/units/quantity.hpp>
#include <phys/units/io.hpp> #include <phys/units/io.hpp>
#include <phys/units/physical_constants.hpp> #include <phys/units/physical_constants.hpp>
#include <phys/units/quantity.hpp>
/** /**
@file PhysicalUnits * @file PhysicalUnits
*
Define _XeV literals, alowing 10_GeV in the code. * Define _XeV literals, alowing 10_GeV in the code.
*/ */
/*using namespace phys::units::io; /*using namespace phys::units::io;
using namespace phys::units::literals;*/ using namespace phys::units::literals;*/
...@@ -17,16 +17,27 @@ using namespace phys::units::literals;*/ ...@@ -17,16 +17,27 @@ using namespace phys::units::literals;*/
namespace phys { namespace phys {
namespace units { namespace units {
namespace literals { namespace literals {
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(eV) ) QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(eV))
} }
} } // namespace units
} } // namespace phys
using Length = phys::units::quantity<phys::units::length_d, double>; namespace fwk {
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 using namespace phys;
using namespace phys::units;
// using namespace phys::units::literals;
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>;
using Energy = phys::units::quantity<phys::units::energy_d, double>;
} // end namespace fwk
// we want to call the operator<< without namespace... I think
using namespace phys::units::io;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment