From f129beff61cc0cb48fce621e361b0676419e79f2 Mon Sep 17 00:00:00 2001
From: Alan Coleman <alanc@udel.edu>
Date: Wed, 6 Mar 2024 15:49:32 +0100
Subject: [PATCH] Fix overwriting of primary writer by startOfLibrary command

---
 examples/cascade_examples/em_shower.cpp       |  3 ++-
 examples/cascade_examples/mc_conex.cpp        |  3 ++-
 examples/cascade_examples/radio_em_shower.cpp |  3 ++-
 examples/cascade_examples/water.cpp           | 14 +++++++-------
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/examples/cascade_examples/em_shower.cpp b/examples/cascade_examples/em_shower.cpp
index 301248655..bbce60b4f 100644
--- a/examples/cascade_examples/em_shower.cpp
+++ b/examples/cascade_examples/em_shower.cpp
@@ -181,6 +181,8 @@ int main(int argc, char** argv) {
   auto sequence = make_sequence(emCascade, emContinuous, longprof, observationLevel, cut);
   // define air shower object, run simulation
   TrackingType tracking;
+  
+  output.startOfLibrary();
 
   auto const primaryProperties = std::make_tuple(
       beamCode, calculate_kinetic_energy(plab.getNorm(), get_mass(beamCode)),
@@ -192,7 +194,6 @@ int main(int argc, char** argv) {
   stack.addParticle(primaryProperties);
   primaryWriter.recordPrimary(primaryProperties);
 
-  output.startOfLibrary();
   Cascade EAS(env, tracking, sequence, output, stack);
 
   // to fix the point of first interaction, uncomment the following two lines:
diff --git a/examples/cascade_examples/mc_conex.cpp b/examples/cascade_examples/mc_conex.cpp
index c11699261..f63aef200 100644
--- a/examples/cascade_examples/mc_conex.cpp
+++ b/examples/cascade_examples/mc_conex.cpp
@@ -272,6 +272,8 @@ int main(int argc, char** argv) {
   auto sequence = make_sequence(hadronSequence, decayPythia, eLoss, cut, conex_model,
                                 longprof, observationLevel, trackCheck);
 
+  output.startOfLibrary();
+  
   StackType stack;
   stack.clear();
 
@@ -279,7 +281,6 @@ int main(int argc, char** argv) {
   TrackingType tracking;
   Cascade EAS(env, tracking, sequence, output, stack);
 
-  output.startOfLibrary();
 
   auto const primaryProperties = std::make_tuple(
       Code::Proton, calculate_kinetic_energy(plab.getNorm(), get_mass(beamCode)),
diff --git a/examples/cascade_examples/radio_em_shower.cpp b/examples/cascade_examples/radio_em_shower.cpp
index b25d2ff9f..4a3bb5d23 100644
--- a/examples/cascade_examples/radio_em_shower.cpp
+++ b/examples/cascade_examples/radio_em_shower.cpp
@@ -290,13 +290,14 @@ int main(int argc, char** argv) {
       beamCode, calculate_kinetic_energy(plab.getNorm(), get_mass(beamCode)),
       plab.normalized(), injectionPos, 0_ns);
 
+  output.startOfLibrary();
+
   // setup particle stack, and add primary particle
   StackType stack;
   stack.clear();
   stack.addParticle(primaryProperties);
   primaryWriter.recordPrimary(primaryProperties);
 
-  output.startOfLibrary();
   Cascade EAS(env, tracking, sequence, output, stack);
 
   // to fix the point of first interaction, uncomment the following two lines:
diff --git a/examples/cascade_examples/water.cpp b/examples/cascade_examples/water.cpp
index 300b188a2..8dceb7c62 100644
--- a/examples/cascade_examples/water.cpp
+++ b/examples/cascade_examples/water.cpp
@@ -213,13 +213,13 @@ int main(int argc, char** argv) {
   ParticleCut<SubWriter<decltype(dEdX)>> cut(emCut, emCut, hadCut, hadCut, true, dEdX);
 
   // tell proposal that we are interested in all energy losses above the particle cut
-  set_energy_production_threshold(Code::Electron, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::Positron, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::Photon, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::MuMinus, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::MuPlus, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::TauMinus, std::min({emcut, hadcut}));
-  set_energy_production_threshold(Code::TauPlus, std::min({emcut, hadcut}));
+  set_energy_production_threshold(Code::Electron, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::Positron, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::Photon, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::MuMinus, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::MuPlus, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::TauMinus, std::min({emCut, hadCut}));
+  set_energy_production_threshold(Code::TauPlus, std::min({emCut, hadCut}));
 
   // hadronic interactions
   HEPEnergyType heHadronModelThreshold = std::pow(10, 1.9) * 1_GeV;
-- 
GitLab