IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 548da7dd authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch '97-cascade-example-debugging-2' into 'master'

Resolve "cascade example debugging"

See merge request !39
parents d0feeb54 c56ebc4a
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 138 deletions
...@@ -16,7 +16,7 @@ build: ...@@ -16,7 +16,7 @@ build:
- cd build - cd build
- cmake .. - cmake ..
- cmake --build . - cmake --build .
- ctest -V - ctest
# code_quality: # code_quality:
# image: docker:stable # image: docker:stable
......
...@@ -45,24 +45,24 @@ using namespace corsika::environment; ...@@ -45,24 +45,24 @@ using namespace corsika::environment;
using namespace std; using namespace std;
using namespace corsika::units::hep; using namespace corsika::units::hep;
static EnergyType fEnergy = 0. * 1_GeV; class ProcessCut : public corsika::process::ContinuousProcess<ProcessCut> {
// FOR NOW: global static variables for ParticleCut process EnergyType fECut;
// this is just wrong...
static EnergyType fEmEnergy;
static int fEmCount;
static EnergyType fInvEnergy; mutable EnergyType fEnergy = 0_GeV;
static int fInvCount; mutable EnergyType fEmEnergy = 0_GeV;
mutable int fEmCount = 0;
mutable EnergyType fInvEnergy = 0_GeV;
mutable int fInvCount = 0;
class ProcessEMCut : public corsika::process::ContinuousProcess<ProcessEMCut> {
public: public:
ProcessEMCut() {} ProcessCut(const EnergyType v)
: fECut(v) {}
template <typename Particle> template <typename Particle>
bool isBelowEnergyCut(Particle& p) const { bool isBelowEnergyCut(Particle& p) const {
// FOR NOW: center-of-mass energy hard coded // FOR NOW: center-of-mass energy hard coded
const EnergyType Ecm = sqrt(2. * p.GetEnergy() * 0.93827_GeV); const EnergyType Ecm = sqrt(2. * p.GetEnergy() * 0.93827_GeV);
if (p.GetEnergy() < 50_GeV || Ecm < 10_GeV) if (p.GetEnergy() < fECut || Ecm < 10_GeV)
return true; return true;
else else
return false; return false;
...@@ -134,25 +134,27 @@ public: ...@@ -134,25 +134,27 @@ public:
template <typename Particle, typename Stack> template <typename Particle, typename Stack>
EProcessReturn DoContinuous(Particle& p, setup::Trajectory&, Stack&) const { EProcessReturn DoContinuous(Particle& p, setup::Trajectory&, Stack&) const {
cout << "ProcessCut: DoContinuous: " << p.GetPID() << endl;
const Code pid = p.GetPID(); const Code pid = p.GetPID();
EnergyType energy = p.GetEnergy();
cout << "ProcessCut: DoContinuous: " << pid << " E= " << energy
<< ", EcutTot=" << (fEmEnergy + fInvEnergy + fEnergy) / 1_GeV << " GeV" << endl;
EProcessReturn ret = EProcessReturn::eOk; EProcessReturn ret = EProcessReturn::eOk;
if (isEmParticle(pid)) { if (isEmParticle(pid)) {
cout << "removing em. particle..." << endl; cout << "removing em. particle..." << endl;
fEmEnergy += p.GetEnergy(); fEmEnergy += energy;
fEmCount += 1; fEmCount += 1;
p.Delete(); // p.Delete();
ret = EProcessReturn::eParticleAbsorbed; ret = EProcessReturn::eParticleAbsorbed;
} else if (isInvisible(pid)) { } else if (isInvisible(pid)) {
cout << "removing inv. particle..." << endl; cout << "removing inv. particle..." << endl;
fInvEnergy += p.GetEnergy(); fInvEnergy += energy;
fInvCount += 1; fInvCount += 1;
p.Delete(); // p.Delete();
ret = EProcessReturn::eParticleAbsorbed; ret = EProcessReturn::eParticleAbsorbed;
} else if (isBelowEnergyCut(p)) { } else if (isBelowEnergyCut(p)) {
cout << "removing low en. particle..." << endl; cout << "removing low en. particle..." << endl;
fEnergy += p.GetEnergy(); fEnergy += energy;
p.Delete(); // p.Delete();
ret = EProcessReturn::eParticleAbsorbed; ret = EProcessReturn::eParticleAbsorbed;
} }
return ret; return ret;
...@@ -178,20 +180,21 @@ public: ...@@ -178,20 +180,21 @@ public:
<< " ******************************" << endl; << " ******************************" << endl;
} }
EnergyType GetInvEnergy() { return fInvEnergy; } EnergyType GetInvEnergy() const { return fInvEnergy; }
EnergyType GetCutEnergy() const { return fEnergy; }
EnergyType GetCutEnergy() { return fEnergy; } EnergyType GetEmEnergy() const { return fEmEnergy; }
EnergyType GetEmEnergy() { return fEmEnergy; }
private:
}; };
//
// The example main program for a particle cascade
//
int main() { int main() {
// initialize random number sequence(s)
corsika::random::RNGManager::GetInstance().RegisterRandomStream("cascade"); corsika::random::RNGManager::GetInstance().RegisterRandomStream("cascade");
corsika::environment::Environment env; // dummy environment // setup environment, geometry
corsika::environment::Environment env;
auto& universe = *(env.GetUniverse()); auto& universe = *(env.GetUniverse());
auto theMedium = corsika::environment::Environment::CreateNode<Sphere>( auto theMedium = corsika::environment::Environment::CreateNode<Sphere>(
...@@ -201,47 +204,47 @@ int main() { ...@@ -201,47 +204,47 @@ int main() {
using MyHomogeneousModel = using MyHomogeneousModel =
corsika::environment::HomogeneousMedium<corsika::environment::IMediumModel>; corsika::environment::HomogeneousMedium<corsika::environment::IMediumModel>;
theMedium->SetModelProperties<MyHomogeneousModel>( theMedium->SetModelProperties<MyHomogeneousModel>(
1_g / (1_m * 1_m * 1_m), 1_kg / (1_m * 1_m * 1_m),
corsika::environment::NuclearComposition( corsika::environment::NuclearComposition(
std::vector<corsika::particles::Code>{corsika::particles::Code::Proton}, std::vector<corsika::particles::Code>{corsika::particles::Code::Oxygen},
std::vector<float>{1.})); std::vector<float>{1.}));
universe.AddChild(std::move(theMedium)); universe.AddChild(std::move(theMedium));
CoordinateSystem& rootCS = const CoordinateSystem& rootCS = env.GetCoordinateSystem();
RootCoordinateSystem::GetInstance().GetRootCoordinateSystem();
// setup processes, decays and interactions
tracking_line::TrackingLine<setup::Stack> tracking(env); tracking_line::TrackingLine<setup::Stack> tracking(env);
stack_inspector::StackInspector<setup::Stack> p0(true); stack_inspector::StackInspector<setup::Stack> p0(true);
corsika::process::sibyll::Interaction sibyll; corsika::process::sibyll::Interaction sibyll;
corsika::process::sibyll::Decay decay; corsika::process::sibyll::Decay decay;
ProcessEMCut cut; ProcessCut cut(8_GeV);
// assemble all processes into an ordered process list
const auto sequence = /*p0 <<*/ sibyll << decay << cut; const auto sequence = /*p0 <<*/ sibyll << decay << cut;
// setup particle stack, and add primary particle
setup::Stack stack; setup::Stack stack;
stack.Clear();
const hep::EnergyType E0 = 1_TeV;
{
auto particle = stack.NewParticle();
particle.SetPID(Code::Proton);
hep::MomentumType P0 = sqrt(E0 * E0 - 0.93827_GeV * 0.93827_GeV);
auto plab = stack::super_stupid::MomentumVector(rootCS, 0_GeV, 0_GeV, -P0);
particle.SetEnergy(E0);
particle.SetMomentum(plab);
particle.SetTime(0_ns);
Point p(rootCS, 0_m, 0_m, 10_km);
particle.SetPosition(p);
}
// define air shower object, run simulation
corsika::cascade::Cascade EAS(env, tracking, sequence, stack); corsika::cascade::Cascade EAS(env, tracking, sequence, stack);
stack.Clear();
auto particle = stack.NewParticle();
EnergyType E0 = 100_GeV;
hep::MomentumType P0 = sqrt(E0 * E0 - 0.93827_GeV * 0.93827_GeV);
auto plab = stack::super_stupid::MomentumVector(rootCS, 0. * 1_GeV, 0. * 1_GeV, P0);
particle.SetEnergy(E0);
particle.SetMomentum(plab);
particle.SetPID(Code::Proton);
particle.SetTime(0_ns);
Point p(rootCS, 0_m, 0_m, 0_m);
particle.SetPosition(p);
EAS.Init(); EAS.Init();
EAS.Run(); EAS.Run();
cout << "Result: E0="
<< E0 / 1_GeV cout << "Result: E0=" << E0 / 1_GeV << endl;
//<< "GeV, particles below energy threshold =" << p1.GetCount()
<< endl;
cout << "total energy below threshold (GeV): " //<< p1.GetEnergy() / 1_GeV
<< std::endl;
cut.ShowResults(); cut.ShowResults();
cout << "total energy (GeV): " cout << "total energy (GeV): "
<< (cut.GetCutEnergy() + cut.GetInvEnergy() + cut.GetEmEnergy()) / 1_GeV << endl; << (cut.GetCutEnergy() + cut.GetInvEnergy() + cut.GetEmEnergy()) / 1_GeV << endl;
......
...@@ -71,9 +71,8 @@ namespace corsika::cascade { ...@@ -71,9 +71,8 @@ namespace corsika::cascade {
fProcessSequence.GetTotalInverseInteractionLength(particle, step); fProcessSequence.GetTotalInverseInteractionLength(particle, step);
// sample random exponential step length in grammage // sample random exponential step length in grammage
auto constexpr grammageConversion = 1_g / (1_m * 1_m); std::exponential_distribution expDist(total_inv_lambda * (1_g / (1_m * 1_m)));
std::exponential_distribution expDist(1 / (grammageConversion * total_inv_lambda)); GrammageType const next_interact = (1_g / (1_m * 1_m)) * expDist(fRNG);
GrammageType const next_interact = grammageConversion * expDist(fRNG);
std::cout << "total_inv_lambda=" << total_inv_lambda std::cout << "total_inv_lambda=" << total_inv_lambda
<< ", next_interact=" << next_interact << std::endl; << ", next_interact=" << next_interact << std::endl;
...@@ -100,7 +99,6 @@ namespace corsika::cascade { ...@@ -100,7 +99,6 @@ namespace corsika::cascade {
<< ", next_decay=" << next_decay << std::endl; << ", next_decay=" << next_decay << std::endl;
// convert next_decay from time to length [m] // convert next_decay from time to length [m]
// Environment::GetDistance(step, next_decay);
LengthType const distance_decay = next_decay * particle.GetMomentum().norm() / LengthType const distance_decay = next_decay * particle.GetMomentum().norm() /
particle.GetEnergy() * particle.GetEnergy() *
corsika::units::constants::c; corsika::units::constants::c;
...@@ -109,10 +107,11 @@ namespace corsika::cascade { ...@@ -109,10 +107,11 @@ namespace corsika::cascade {
auto const min_distance = auto const min_distance =
std::min({distance_interact, distance_decay, distance_max}); std::min({distance_interact, distance_decay, distance_max});
std::cout << " move particle by : " << min_distance << std::endl;
// here the particle is actually moved along the trajectory to new position: // here the particle is actually moved along the trajectory to new position:
// std::visit(corsika::setup::ParticleUpdate<Particle>{particle}, step); // std::visit(corsika::setup::ParticleUpdate<Particle>{particle}, step);
particle.SetPosition(step.PositionFromArclength(min_distance)); particle.SetPosition(step.PositionFromArclength(min_distance));
// .... also update time, momentum, direction, ... // .... also update time, momentum, direction, ...
// apply all continuous processes on particle + track // apply all continuous processes on particle + track
...@@ -120,39 +119,40 @@ namespace corsika::cascade { ...@@ -120,39 +119,40 @@ namespace corsika::cascade {
fProcessSequence.DoContinuous(particle, step, fStack); fProcessSequence.DoContinuous(particle, step, fStack);
if (status == corsika::process::EProcessReturn::eParticleAbsorbed) { if (status == corsika::process::EProcessReturn::eParticleAbsorbed) {
// fStack.Delete(particle); // TODO: check if this is really needed std::cout << "Cascade: delete absorbed particle " << particle.GetPID() << " "
} else { << particle.GetEnergy() / 1_GeV << "GeV" << std::endl;
particle.Delete();
std::cout << "sth. happening before geometric limit ?" return;
<< ((min_distance < distance_max) ? "yes" : "no") << std::endl; }
if (min_distance < distance_max) { // interaction to happen within geometric limit std::cout << "sth. happening before geometric limit ?"
// check weather decay or interaction limits this step << ((min_distance < distance_max) ? "yes" : "no") << std::endl;
if (min_distance == distance_interact) { if (min_distance < distance_max) { // interaction to happen within geometric limit
std::cout << "collide" << std::endl; // check weather decay or interaction limits this step
InverseGrammageType const actual_inv_length = if (min_distance == distance_interact) {
fProcessSequence.GetTotalInverseInteractionLength(particle, step); std::cout << "collide" << std::endl;
corsika::random::UniformRealDistribution<InverseGrammageType> uniDist( InverseGrammageType const actual_inv_length =
actual_inv_length); fProcessSequence.GetTotalInverseInteractionLength(particle, step);
const auto sample_process = uniDist(fRNG);
InverseGrammageType inv_lambda_count = 0. * meter * meter / gram; corsika::random::UniformRealDistribution<InverseGrammageType> uniDist(
fProcessSequence.SelectInteraction(particle, fStack, sample_process, actual_inv_length);
inv_lambda_count); const auto sample_process = uniDist(fRNG);
} else { InverseGrammageType inv_lambda_count = 0. * meter * meter / gram;
std::cout << "decay" << std::endl; fProcessSequence.SelectInteraction(particle, fStack, sample_process,
InverseTimeType const actual_decay_time = inv_lambda_count);
fProcessSequence.GetTotalInverseLifetime(particle); } else {
std::cout << "decay" << std::endl;
corsika::random::UniformRealDistribution<InverseTimeType> uniDist( InverseTimeType const actual_decay_time =
actual_decay_time); fProcessSequence.GetTotalInverseLifetime(particle);
const auto sample_process = uniDist(fRNG);
InverseTimeType inv_decay_count = 0 / second; corsika::random::UniformRealDistribution<InverseTimeType> uniDist(
fProcessSequence.SelectDecay(particle, fStack, sample_process, actual_decay_time);
inv_decay_count); const auto sample_process = uniDist(fRNG);
} InverseTimeType inv_decay_count = 0 / second;
fProcessSequence.SelectDecay(particle, fStack, sample_process, inv_decay_count);
} }
} }
} }
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
} }
template <typename Particle, typename T, typename Stack> template <typename Particle, typename T, typename Stack>
void DoContinuous(Particle& p, T&, Stack& s) const { EProcessReturn DoContinuous(Particle& p, T&, Stack& s) const {
EnergyType E = p.GetEnergy(); EnergyType E = p.GetEnergy();
if (E < 85_MeV) { if (E < 85_MeV) {
p.Delete(); p.Delete();
...@@ -95,6 +95,7 @@ public: ...@@ -95,6 +95,7 @@ public:
pnew.SetPosition(p.GetPosition()); pnew.SetPosition(p.GetPosition());
pnew.SetMomentum(p.GetMomentum()); pnew.SetMomentum(p.GetMomentum());
} }
return EProcessReturn::eOk;
} }
void Init() { fCount = 0; } void Init() { fCount = 0; }
......
...@@ -35,7 +35,7 @@ namespace corsika::process { ...@@ -35,7 +35,7 @@ namespace corsika::process {
// -> enforce derived to implement DoContinuous... // -> enforce derived to implement DoContinuous...
template <typename Particle, typename Track, typename Stack> template <typename Particle, typename Track, typename Stack>
EProcessReturn DoContinuous(Particle&, Track&, Stack&) const; EProcessReturn DoContinuous(Particle&, Track&, Stack&) const;
// -> enforce derived to implement MaxStepLength... // -> enforce derived to implement MaxStepLength...
template <typename Particle, typename Track> template <typename Particle, typename Track>
corsika::units::si::LengthType MaxStepLength(Particle& p, Track& track) const; corsika::units::si::LengthType MaxStepLength(Particle& p, Track& track) const;
......
...@@ -20,13 +20,25 @@ namespace corsika::process { ...@@ -20,13 +20,25 @@ namespace corsika::process {
that can be accumulated easily with "|=" that can be accumulated easily with "|="
*/ */
enum class EProcessReturn { enum class EProcessReturn : int {
eOk = 1, eOk = (1 << 0),
eParticleAbsorbed = 2, eParticleAbsorbed = (1 << 2),
eInteracted = 3, eInteracted = (1 << 3),
eDecayed = 4, eDecayed = (1 << 4),
}; };
inline EProcessReturn operator|(EProcessReturn a, EProcessReturn b) {
return static_cast<EProcessReturn>(static_cast<int>(a) | static_cast<int>(b));
}
inline EProcessReturn& operator|=(EProcessReturn& a, EProcessReturn b) {
return a = a | b;
}
inline bool operator==(EProcessReturn a, EProcessReturn b) {
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
}
} // namespace corsika::process } // namespace corsika::process
#endif #endif
...@@ -60,20 +60,21 @@ namespace corsika::process { ...@@ -60,20 +60,21 @@ namespace corsika::process {
EProcessReturn ret = EProcessReturn::eOk; EProcessReturn ret = EProcessReturn::eOk;
if constexpr (std::is_base_of<ContinuousProcess<T1>, T1>::value || if constexpr (std::is_base_of<ContinuousProcess<T1>, T1>::value ||
is_process_sequence<T1>::value) { is_process_sequence<T1>::value) {
A.DoContinuous(p, t, s); ret |= A.DoContinuous(p, t, s);
} }
if constexpr (std::is_base_of<ContinuousProcess<T2>, T2>::value || if constexpr (std::is_base_of<ContinuousProcess<T2>, T2>::value ||
is_process_sequence<T2>::value) { is_process_sequence<T2>::value) {
B.DoContinuous(p, t, s); ret |= B.DoContinuous(p, t, s);
} }
return ret; return ret;
} }
template <typename Particle, typename Track> template <typename Particle, typename Track>
corsika::units::si::LengthType MaxStepLength(Particle& p, Track& track) const { corsika::units::si::LengthType MaxStepLength(Particle& p, Track& track) const {
corsika::units::si::LengthType max_length = // if no other process in the sequence implements it corsika::units::si::LengthType
max_length = // if no other process in the sequence implements it
std::numeric_limits<double>::infinity() * corsika::units::si::meter; std::numeric_limits<double>::infinity() * corsika::units::si::meter;
if constexpr (std::is_base_of<ContinuousProcess<T1>, T1>::value || if constexpr (std::is_base_of<ContinuousProcess<T1>, T1>::value ||
is_process_sequence<T1>::value) { is_process_sequence<T1>::value) {
corsika::units::si::LengthType const len = A.MaxStepLength(p, track); corsika::units::si::LengthType const len = A.MaxStepLength(p, track);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
on. This breaks ADL (argument-dependent lookup). Here we "fix" this: on. This breaks ADL (argument-dependent lookup). Here we "fix" this:
*/ */
namespace phys::units { namespace phys::units {
// using namespace phys::units::io;
using phys::units::io::operator<<; using phys::units::io::operator<<;
} // namespace phys::units } // namespace phys::units
......
...@@ -15,8 +15,11 @@ namespace corsika::process { ...@@ -15,8 +15,11 @@ namespace corsika::process {
namespace sibyll { namespace sibyll {
class Decay : public corsika::process::DecayProcess<Decay> { class Decay : public corsika::process::DecayProcess<Decay> {
mutable int fCount = 0;
public: public:
Decay() {} Decay() {}
~Decay() { std::cout << "Sibyll::Decay n=" << fCount << std::endl; }
void Init() { void Init() {
setHadronsUnstable(); setHadronsUnstable();
setTrackedParticlesStable(); setTrackedParticlesStable();
...@@ -142,6 +145,7 @@ namespace corsika::process { ...@@ -142,6 +145,7 @@ namespace corsika::process {
void DoDecay(Particle& p, Stack& s) const { void DoDecay(Particle& p, Stack& s) const {
using corsika::geometry::Point; using corsika::geometry::Point;
using namespace corsika::units::si; using namespace corsika::units::si;
fCount++;
SibStack ss; SibStack ss;
ss.Clear(); ss.Clear();
// copy particle to sibyll stack // copy particle to sibyll stack
......
...@@ -15,9 +15,11 @@ namespace corsika::process::sibyll { ...@@ -15,9 +15,11 @@ namespace corsika::process::sibyll {
class Interaction : public corsika::process::InteractionProcess<Interaction> { class Interaction : public corsika::process::InteractionProcess<Interaction> {
mutable int fCount = 0;
public: public:
Interaction() {} Interaction() {}
~Interaction() {} ~Interaction() { std::cout << "Sibyll::Interaction n=" << fCount << std::endl; }
void Init() { void Init() {
...@@ -73,8 +75,8 @@ namespace corsika::process::sibyll { ...@@ -73,8 +75,8 @@ namespace corsika::process::sibyll {
const hep::EnergyType sqs = sqrt(Etot * Etot - Ptot.squaredNorm()); const hep::EnergyType sqs = sqrt(Etot * Etot - Ptot.squaredNorm());
const double Ecm = sqs / 1_GeV; const double Ecm = sqs / 1_GeV;
std::cout << "Interaction: " std::cout << "Interaction: LambdaInt: \n"
<< "MinStep: input en: " << p.GetEnergy() / 1_GeV << endl << " input energy: " << p.GetEnergy() / 1_GeV << endl
<< " beam can interact:" << kBeam << endl << " beam can interact:" << kBeam << endl
<< " beam XS code:" << kBeam << endl << " beam XS code:" << kBeam << endl
<< " beam pid:" << p.GetPID() << endl << " beam pid:" << p.GetPID() << endl
...@@ -102,7 +104,6 @@ namespace corsika::process::sibyll { ...@@ -102,7 +104,6 @@ namespace corsika::process::sibyll {
<< "nucleon mass " << nucleon_mass << std::endl; << "nucleon mass " << nucleon_mass << std::endl;
// calculate interaction length in medium // calculate interaction length in medium
GrammageType int_length = kTarget * nucleon_mass / sig; GrammageType int_length = kTarget * nucleon_mass / sig;
// pick random step lenth
std::cout << "Interaction: " std::cout << "Interaction: "
<< "interaction length (g/cm2): " << int_length << std::endl; << "interaction length (g/cm2): " << int_length << std::endl;
...@@ -110,17 +111,6 @@ namespace corsika::process::sibyll { ...@@ -110,17 +111,6 @@ namespace corsika::process::sibyll {
} }
return std::numeric_limits<double>::infinity() * 1_g / (1_cm * 1_cm); return std::numeric_limits<double>::infinity() * 1_g / (1_cm * 1_cm);
/*
what are the units of the output? slant depth or 3space length?
*/
//
// int a = 0;
// const double next_step = -int_length * log(s_rndm_(a));
// std::cout << "Interaction: "
// << "next step (g/cm2): " << next_step << std::endl;
// return next_step;
} }
template <typename Particle, typename Stack> template <typename Particle, typename Stack>
...@@ -137,9 +127,7 @@ namespace corsika::process::sibyll { ...@@ -137,9 +127,7 @@ namespace corsika::process::sibyll {
<< "DoInteraction: " << p.GetPID() << " interaction? " << "DoInteraction: " << p.GetPID() << " interaction? "
<< process::sibyll::CanInteract(p.GetPID()) << endl; << process::sibyll::CanInteract(p.GetPID()) << endl;
if (process::sibyll::CanInteract(p.GetPID())) { if (process::sibyll::CanInteract(p.GetPID())) {
cout << "defining coordinates" << endl; const CoordinateSystem& rootCS =
// coordinate system, get global frame of reference
CoordinateSystem& rootCS =
RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); RootCoordinateSystem::GetInstance().GetRootCoordinateSystem();
Point pOrig = p.GetPosition(); Point pOrig = p.GetPosition();
...@@ -157,14 +145,12 @@ namespace corsika::process::sibyll { ...@@ -157,14 +145,12 @@ namespace corsika::process::sibyll {
const int kTarget = corsika::particles::Oxygen:: const int kTarget = corsika::particles::Oxygen::
GetNucleusA(); // env.GetTargetParticle().GetPID(); GetNucleusA(); // env.GetTargetParticle().GetPID();
cout << "defining target momentum.." << endl;
// FOR NOW: target is always at rest // FOR NOW: target is always at rest
const EnergyType Etarget = 0. * 1_GeV + corsika::particles::Proton::GetMass(); const EnergyType Etarget = 0_GeV + corsika::particles::Proton::GetMass();
const auto pTarget = MomentumVector(rootCS, 0_GeV, 0_GeV, 0_GeV); const auto pTarget = MomentumVector(rootCS, 0_GeV, 0_GeV, 0_GeV);
cout << "target momentum (GeV/c): " cout << "target momentum (GeV/c): " << pTarget.GetComponents() / 1_GeV << endl;
<< pTarget.GetComponents() / 1_GeV * constants::c << endl; cout << "beam momentum (GeV/c): " << p.GetMomentum().GetComponents() / 1_GeV
cout << "beam momentum (GeV/c): " << endl;
<< p.GetMomentum().GetComponents() / 1_GeV * constants::c << endl;
cout << "position of interaction: " << pOrig.GetCoordinates() << endl; cout << "position of interaction: " << pOrig.GetCoordinates() << endl;
cout << "time: " << tOrig << endl; cout << "time: " << tOrig << endl;
...@@ -182,8 +168,7 @@ namespace corsika::process::sibyll { ...@@ -182,8 +168,7 @@ namespace corsika::process::sibyll {
// total momentum // total momentum
MomentumVector Ptot = p.GetMomentum(); MomentumVector Ptot = p.GetMomentum();
// invariant mass, i.e. cm. energy // invariant mass, i.e. cm. energy
EnergyType Ecm = EnergyType Ecm = sqrt(Etot * Etot - Ptot.squaredNorm());
sqrt(Etot * Etot - Ptot.squaredNorm()); // sqrt( 2. * E * 0.93827_GeV );
/* /*
get transformation between Stack-frame and SibStack-frame get transformation between Stack-frame and SibStack-frame
for EAS Stack-frame is lab. frame, could be different for CRMC-mode for EAS Stack-frame is lab. frame, could be different for CRMC-mode
...@@ -207,8 +192,9 @@ namespace corsika::process::sibyll { ...@@ -207,8 +192,9 @@ namespace corsika::process::sibyll {
<< " DoInteraction: should have dropped particle.." << std::endl; << " DoInteraction: should have dropped particle.." << std::endl;
// p.Delete(); delete later... different process // p.Delete(); delete later... different process
} else { } else {
fCount++;
// Sibyll does not know about units.. // Sibyll does not know about units..
double sqs = Ecm / 1_GeV; const double sqs = Ecm / 1_GeV;
// running sibyll, filling stack // running sibyll, filling stack
sibyll_(kBeam, kTarget, sqs); sibyll_(kBeam, kTarget, sqs);
// running decays // running decays
...@@ -228,7 +214,8 @@ namespace corsika::process::sibyll { ...@@ -228,7 +214,8 @@ namespace corsika::process::sibyll {
// SibStack does not know about momentum yet so we need counter to access // SibStack does not know about momentum yet so we need counter to access
// momentum array in Sibyll // momentum array in Sibyll
int i = -1; int i = -1;
MomentumVector Ptot_final(rootCS, {0.0_GeV, 0.0_GeV, 0.0_GeV}); MomentumVector Plab_final(rootCS, {0.0_GeV, 0.0_GeV, 0.0_GeV});
EnergyType E_final = 0_GeV, Ecm_final = 0_GeV;
for (auto& psib : ss) { for (auto& psib : ss) {
++i; ++i;
// skip particles that have decayed in Sibyll // skip particles that have decayed in Sibyll
...@@ -263,10 +250,14 @@ namespace corsika::process::sibyll { ...@@ -263,10 +250,14 @@ namespace corsika::process::sibyll {
pnew.SetMomentum(MomentumVector(rootCS, p_lab_c)); pnew.SetMomentum(MomentumVector(rootCS, p_lab_c));
pnew.SetPosition(pOrig); pnew.SetPosition(pOrig);
pnew.SetTime(tOrig); pnew.SetTime(tOrig);
Ptot_final += pnew.GetMomentum(); Plab_final += pnew.GetMomentum();
E_final += en_lab;
Ecm_final += psib.GetEnergy();
} }
// cout << "tot. momentum final (GeV/c): " << Ptot_final.GetComponents() / 1_GeV std::cout << "conservation (all GeV): E_final=" << E_final / 1_GeV
// * constants::c << endl; << ", Ecm_final=" << Ecm_final / 1_GeV
<< ", Plab_final=" << (Plab_final / 1_GeV).GetComponents()
<< std::endl;
} }
} }
return process::EProcessReturn::eOk; return process::EProcessReturn::eOk;
......
...@@ -35,7 +35,7 @@ namespace corsika::process::sibyll { ...@@ -35,7 +35,7 @@ namespace corsika::process::sibyll {
SibyllCode constexpr ConvertToSibyll(corsika::particles::Code pCode) { SibyllCode constexpr ConvertToSibyll(corsika::particles::Code pCode) {
return static_cast<SibyllCode>( return static_cast<SibyllCode>(
corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]); corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]);
} }
corsika::particles::Code constexpr ConvertFromSibyll(SibyllCode pCode) { corsika::particles::Code constexpr ConvertFromSibyll(SibyllCode pCode) {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
double s_rndm_(int&) { double s_rndm_(int&) {
static corsika::random::RNG& rng = static corsika::random::RNG& rng =
corsika::random::RNGManager::GetInstance().GetRandomStream("s_rndm"); corsika::random::RNGManager::GetInstance().GetRandomStream("s_rndm");
std::uniform_real_distribution<double> dist; std::uniform_real_distribution<double> dist;
return dist(rng); return dist(rng);
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#define _include_corsika_processes_TrackingLine_h_ #define _include_corsika_processes_TrackingLine_h_
#include <corsika/geometry/Point.h> #include <corsika/geometry/Point.h>
#include <corsika/geometry/QuantityVector.h>
#include <corsika/geometry/Sphere.h> #include <corsika/geometry/Sphere.h>
#include <corsika/geometry/Vector.h> #include <corsika/geometry/Vector.h>
...@@ -75,12 +76,19 @@ namespace corsika::process { ...@@ -75,12 +76,19 @@ namespace corsika::process {
void Init() {} void Init() {}
auto GetTrack(Particle const& p) { auto GetTrack(Particle const& p) {
using std::cout;
using std::endl;
using namespace corsika::units::si; using namespace corsika::units::si;
using namespace corsika::geometry;
geometry::Vector<SpeedType::dimension_type> const velocity = geometry::Vector<SpeedType::dimension_type> const velocity =
p.GetMomentum() / p.GetEnergy() * corsika::units::constants::c; p.GetMomentum() / p.GetEnergy() * corsika::units::constants::c;
auto const currentPosition = p.GetPosition(); auto const currentPosition = p.GetPosition();
std::cout << "TrackingLine pos: " << currentPosition.GetCoordinates()
<< std::endl;
std::cout << "TrackingLine v: " << velocity.GetComponents() << std::endl;
// to do: include effect of magnetic field // to do: include effect of magnetic field
geometry::Line line(currentPosition, velocity); geometry::Line line(currentPosition, velocity);
...@@ -125,6 +133,8 @@ namespace corsika::process { ...@@ -125,6 +133,8 @@ namespace corsika::process {
min = *minIter; min = *minIter;
} }
std::cout << " t-intersect: " << min << std::endl;
return geometry::Trajectory<corsika::geometry::Line>(line, min); return geometry::Trajectory<corsika::geometry::Line>(line, min);
} }
}; };
......
...@@ -120,7 +120,7 @@ namespace corsika::stack { ...@@ -120,7 +120,7 @@ namespace corsika::stack {
void SetPosition(const int i, const corsika::geometry::Point& v) { void SetPosition(const int i, const corsika::geometry::Point& v) {
fPosition[i] = v; fPosition[i] = v;
} }
void SetTime(const int i, const corsika::units::si::TimeType& v) { fTime[i] = v; } void SetTime(const int i, const corsika::units::si::TimeType& v) { fTime[i] = v; }
corsika::particles::Code GetPID(const int i) const { return fDataPID[i]; } corsika::particles::Code GetPID(const int i) const { return fDataPID[i]; }
......
...@@ -45,10 +45,9 @@ TEST_CASE("SuperStupidStack", "[stack]") { ...@@ -45,10 +45,9 @@ TEST_CASE("SuperStupidStack", "[stack]") {
auto pout = s.GetNextParticle(); auto pout = s.GetNextParticle();
REQUIRE(pout.GetPID() == particles::Code::Electron); REQUIRE(pout.GetPID() == particles::Code::Electron);
REQUIRE(pout.GetEnergy() == 1.5_GeV); REQUIRE(pout.GetEnergy() == 1.5_GeV);
#warning Fix the next two lines: // REQUIRE(pout.GetMomentum() == stack::super_stupid::MomentumVector(dummyCS, {1_GeV,
// REQUIRE(pout.GetMomentum() == MomentumVector(dummyCS, {1 * joule, 1 * joule, 1 * // 1_GeV, 1_GeV})); REQUIRE(pout.GetPosition() == Point(dummyCS, {1 * meter, 1 *
// joule})); REQUIRE(pout.GetPosition() == Point(dummyCS, {1 * meter, 1 * meter, 1 * // meter, 1 * meter}));
// meter}));
REQUIRE(pout.GetTime() == 100_s); REQUIRE(pout.GetTime() == 100_s);
} }
......
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