From 36ca52b5bd02a88209b6f6fad54ed90118cbaa10 Mon Sep 17 00:00:00 2001 From: Maximilian Sackel <maximilian.sackel@tu-dortmund.de> Date: Fri, 2 Oct 2020 10:49:51 +0000 Subject: [PATCH] resolve the namespace pollution in the proposal process --- Processes/Proposal/ContinuousProcess.cc | 24 +++++++++++------- Processes/Proposal/ContinuousProcess.h | 4 +-- Processes/Proposal/Interaction.cc | 6 +++-- Processes/Proposal/Interaction.h | 2 -- Processes/Proposal/ProposalProcessBase.h | 31 ++++++++++++------------ 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Processes/Proposal/ContinuousProcess.cc b/Processes/Proposal/ContinuousProcess.cc index 0337bc8b0..2c5cfc3b9 100644 --- a/Processes/Proposal/ContinuousProcess.cc +++ b/Processes/Proposal/ContinuousProcess.cc @@ -20,8 +20,6 @@ namespace corsika::process::proposal { - using namespace corsika::units::si; - void ContinuousProcess::BuildCalculator(particles::Code code, environment::NuclearComposition const& comp) { // search crosssection builder for given particle @@ -45,13 +43,15 @@ namespace corsika::process::proposal { template <> ContinuousProcess::ContinuousProcess(setup::SetupEnvironment const& _env, - corsika::units::si::HEPEnergyType _emCut) + corsika::units::si::HEPEnergyType _emCut) : ProposalProcessBase(_env, _emCut) {} template <> void ContinuousProcess::Scatter(setup::Stack::ParticleType& vP, - HEPEnergyType const& loss, - GrammageType const& grammage) { + corsika::units::si::HEPEnergyType const& loss, + corsika::units::si::GrammageType const& grammage) { + using namespace corsika::units::si; // required for operator::_MeV + // Get or build corresponding calculators auto c = GetCalculator(vP, calc); @@ -87,6 +87,8 @@ namespace corsika::process::proposal { template <> EProcessReturn ContinuousProcess::DoContinuous(setup::Stack::ParticleType& vP, setup::Trajectory const& vT) { + using namespace corsika::units::si; // required for operator::_MeV + if (!CanInteract(vP.GetPID())) return process::EProcessReturn::eOk; // calculate passed grammage @@ -100,15 +102,14 @@ namespace corsika::process::proposal { 1_MeV; auto dE = vP.GetEnergy() - final_energy; energy_lost_ += dE; - + // if the particle has a charge take multiple scattering into account if (vP.GetChargeNumber() != 0) Scatter(vP, dE, dX); // Update the energy and absorbe the particle if it's below the energy // threshold, because it will no longer propagated. vP.SetEnergy(final_energy); - if (vP.GetEnergy() <= emCut_) - return process::EProcessReturn::eParticleAbsorbed; + if (vP.GetEnergy() <= emCut_) return process::EProcessReturn::eParticleAbsorbed; vP.SetMomentum(vP.GetMomentum() * vP.GetEnergy() / vP.GetMomentum().GetNorm()); return process::EProcessReturn::eOk; } @@ -116,13 +117,16 @@ namespace corsika::process::proposal { template <> units::si::LengthType ContinuousProcess::MaxStepLength( setup::Stack::ParticleType const& vP, setup::Trajectory const& vT) { + using namespace corsika::units::si; // required for operator::_MeV + if (!CanInteract(vP.GetPID())) return units::si::meter * std::numeric_limits<double>::infinity(); // Limit the step size of a conitnous loss. The maximal continuous loss seems to be a // hyper parameter which must be adjusted. // in any case: never go below emCut_ - auto energy_lim = std::max(0.9 * vP.GetEnergy(), emCut_);; + auto energy_lim = std::max(0.9 * vP.GetEnergy(), emCut_); + ; // solving the track integral for giving energy lim auto c = GetCalculator(vP, calc); @@ -135,12 +139,14 @@ namespace corsika::process::proposal { } void ContinuousProcess::ShowResults() const { + using namespace corsika::units::si; // required for operator::_MeV std::cout << " ******************************" << std::endl << " PROCESS::ContinuousProcess: " << std::endl; std::cout << " energy lost dE (GeV) : " << energy_lost_ / 1_GeV << std::endl; } void ContinuousProcess::Reset() { + using namespace corsika::units::si; // required for operator::_MeV energy_lost_ = 0_GeV; } diff --git a/Processes/Proposal/ContinuousProcess.h b/Processes/Proposal/ContinuousProcess.h index e2624ed48..aefa4ffc6 100644 --- a/Processes/Proposal/ContinuousProcess.h +++ b/Processes/Proposal/ContinuousProcess.h @@ -35,14 +35,13 @@ namespace corsika::process::proposal { calc; //!< Stores the displacement and scattering calculators. units::si::HEPEnergyType energy_lost_ = 0 * units::si::electronvolt; - + //! //! Build the displacement and scattering calculators and add it to calc. //! void BuildCalculator(particles::Code, environment::NuclearComposition const&) final; public: - //! //! Produces the continuous loss calculator for leptons based on nuclear //! compositions and stochastic description limited by the particle cut. @@ -50,7 +49,6 @@ namespace corsika::process::proposal { template <typename TEnvironment> ContinuousProcess(TEnvironment const&, corsika::units::si::HEPEnergyType _emCut); - //! //! Multiple Scattering of the lepton. Stochastic deflection is not yet taken into //! account. Displacment of the track due to multiple scattering is not possible diff --git a/Processes/Proposal/Interaction.cc b/Processes/Proposal/Interaction.cc index aeeaae484..511f580a7 100644 --- a/Processes/Proposal/Interaction.cc +++ b/Processes/Proposal/Interaction.cc @@ -20,8 +20,6 @@ #include <tuple> namespace corsika::process::proposal { - using namespace corsika::environment; - using namespace corsika::units::si; template <> Interaction::Interaction(setup::SetupEnvironment const& _env, @@ -53,6 +51,8 @@ namespace corsika::process::proposal { template <> corsika::process::EProcessReturn Interaction::DoInteraction( setup::StackView::StackIterator& vP) { + using namespace corsika::units::si; // required for operator::_MeV + if (CanInteract(vP.GetPID())) { // Get or build corresponding calculators auto c = GetCalculator(vP, calc); @@ -100,6 +100,8 @@ namespace corsika::process::proposal { template <> corsika::units::si::GrammageType Interaction::GetInteractionLength( setup::Stack::StackIterator const& vP) { + using namespace corsika::units::si; // required for operator::_MeV + if (CanInteract(vP.GetPID())) { auto c = GetCalculator(vP, calc); return get<INTERACTION>(c->second)->MeanFreePath(vP.GetEnergy() / 1_MeV) * 1_g / diff --git a/Processes/Proposal/Interaction.h b/Processes/Proposal/Interaction.h index 0a4aed0a4..007cff4a8 100644 --- a/Processes/Proposal/Interaction.h +++ b/Processes/Proposal/Interaction.h @@ -20,8 +20,6 @@ namespace corsika::process::proposal { - using namespace corsika::units::si; - //! //! Electro-magnetic and gamma stochastic losses produced by proposal. It makes //! use of interpolation tables which are runtime intensive calculation, but can be diff --git a/Processes/Proposal/ProposalProcessBase.h b/Processes/Proposal/ProposalProcessBase.h index 018fd1b4f..b1696526a 100644 --- a/Processes/Proposal/ProposalProcessBase.h +++ b/Processes/Proposal/ProposalProcessBase.h @@ -9,9 +9,6 @@ namespace corsika::process::proposal { - using namespace corsika::units::si; - using namespace std::placeholders; - //! //! Particles which can be handled by proposal. That means they can be //! propagated and decayed if they decays. @@ -40,20 +37,23 @@ namespace corsika::process::proposal { //! Crosssection factories for different particle types. //! template <typename T> - static auto cross_builder = [](PROPOSAL::Medium& m, corsika::units::si::HEPEnergyType emCut) { - auto p_cut = std::make_shared<const PROPOSAL::EnergyCutSettings>( - emCut / 1_MeV, 1, true); - return PROPOSAL::DefaultCrossSections<T>::template Get<std::false_type>(T(), m, p_cut, - true); - }; + static auto cross_builder = + [](PROPOSAL::Medium& m, corsika::units::si::HEPEnergyType emCut) { + using namespace corsika::units::si; + auto p_cut = + std::make_shared<const PROPOSAL::EnergyCutSettings>(emCut / 1_MeV, 1, true); + return PROPOSAL::DefaultCrossSections<T>::template Get<std::false_type>( + T(), m, p_cut, true); + }; //! //! PROPOSAL default crosssections are maped to corresponding corsika particle //! code. //! - static std::map<particles::Code, std::function<PROPOSAL::crosssection_list_t< - PROPOSAL::ParticleDef, PROPOSAL::Medium>( - PROPOSAL::Medium&, corsika::units::si::HEPEnergyType)>> + static std::map<particles::Code, + std::function<PROPOSAL::crosssection_list_t<PROPOSAL::ParticleDef, + PROPOSAL::Medium>( + PROPOSAL::Medium&, corsika::units::si::HEPEnergyType)>> cross = {{particles::Code::Gamma, cross_builder<PROPOSAL::GammaDef>}, {particles::Code::Electron, cross_builder<PROPOSAL::EMinusDef>}, {particles::Code::Positron, cross_builder<PROPOSAL::EPlusDef>}, @@ -68,9 +68,10 @@ namespace corsika::process::proposal { //! class ProposalProcessBase { protected: - corsika::units::si::HEPEnergyType emCut_; //!< Stochastic losses smaller than the given cut - //!< will be handeled continuously. - corsika::random::RNG& fRNG; //!< random number generator used by proposal + corsika::units::si::HEPEnergyType + emCut_; //!< Stochastic losses smaller than the given cut + //!< will be handeled continuously. + corsika::random::RNG& fRNG; //!< random number generator used by proposal std::unordered_map<const environment::NuclearComposition*, PROPOSAL::Medium> media; //!< maps nuclear composition from univers to media to produce -- GitLab