From 92bfb86e628c8e48ad2754f9a0509580854f8a9a Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Wed, 10 Jan 2024 14:17:42 -0700 Subject: [PATCH] Change Processes to classes and add an inheritance relationship between PhysicalProcess and InjectionProcess --- .../private/ColumnDepthLeptonInjector.cxx | 8 +- .../private/CylinderVolumeLeptonInjector.cxx | 6 +- .../private/DecayRangeLeptonInjector.cxx | 8 +- projects/injection/private/InjectorBase.cxx | 44 ++++----- projects/injection/private/Process.cxx | 96 +++++++++++++++++++ .../private/RangedLeptonInjector.cxx | 8 +- projects/injection/private/TreeWeighter.cxx | 30 +++--- .../injection/ColumnDepthLeptonInjector.h | 2 +- .../injection/CylinderVolumeLeptonInjector.h | 2 +- .../injection/DecayRangeLeptonInjector.h | 2 +- .../LeptonInjector/injection/InjectorBase.h | 2 +- .../public/LeptonInjector/injection/Process.h | 73 +++++++++----- .../injection/RangedLeptonInjector.h | 2 +- .../LeptonInjector/injection/TreeWeighter.h | 4 +- 14 files changed, 204 insertions(+), 83 deletions(-) diff --git a/projects/injection/private/ColumnDepthLeptonInjector.cxx b/projects/injection/private/ColumnDepthLeptonInjector.cxx index 236b4e3b..9f1a5fcc 100644 --- a/projects/injection/private/ColumnDepthLeptonInjector.cxx +++ b/projects/injection/private/ColumnDepthLeptonInjector.cxx @@ -38,18 +38,18 @@ ColumnDepthLeptonInjector::ColumnDepthLeptonInjector( disk_radius(disk_radius), endcap_length(endcap_length) { - cross_sections = primary_process->cross_sections; + cross_sections = primary_process->GetCrossSections(); std::set target_types = cross_sections->TargetTypes(); position_distribution = std::make_shared(disk_radius, endcap_length, depth_func, target_types); - primary_process->injection_distributions.push_back(position_distribution); + primary_process->AddInjectionDistribution(position_distribution); SetPrimaryProcess(primary_process); for(auto & sec_process : secondary_processes) { AddSecondaryProcess(sec_process); // Assume each secondary process already has a position distribution // Otherwise uncomment below /* - target_types = sec_process->cross_sections->TargetTypes(); - sec_process->injection_distributions.push_back(std::make_shared(disk_radius, endcap_length, depth_func, target_types)); + target_types = sec_process->GetCrossSections()->TargetTypes(); + sec_process->GetInjectionDistributions().push_back(std::make_shared(disk_radius, endcap_length, depth_func, target_types)); */ } } diff --git a/projects/injection/private/CylinderVolumeLeptonInjector.cxx b/projects/injection/private/CylinderVolumeLeptonInjector.cxx index cc133b9b..32c4da5d 100644 --- a/projects/injection/private/CylinderVolumeLeptonInjector.cxx +++ b/projects/injection/private/CylinderVolumeLeptonInjector.cxx @@ -28,15 +28,15 @@ CylinderVolumeLeptonInjector::CylinderVolumeLeptonInjector( LI::geometry::Cylinder cylinder) : InjectorBase(events_to_inject, earth_model, random), position_distribution(std::make_shared(cylinder)) { - cross_sections = primary_process->cross_sections; - primary_process->injection_distributions.push_back(position_distribution); + cross_sections = primary_process->GetCrossSections(); + primary_process->AddInjectionDistribution(position_distribution); SetPrimaryProcess(primary_process); for(auto & sec_process : secondary_processes) { AddSecondaryProcess(sec_process); // Assume each secondary process already has a position distribution // Otherwise uncomment below /* - sec_process->injection_distributions.push_back(position_distribution); + sec_process->GetInjectionDistributions().push_back(position_distribution); */ } } diff --git a/projects/injection/private/DecayRangeLeptonInjector.cxx b/projects/injection/private/DecayRangeLeptonInjector.cxx index 82879d7f..a300a733 100644 --- a/projects/injection/private/DecayRangeLeptonInjector.cxx +++ b/projects/injection/private/DecayRangeLeptonInjector.cxx @@ -37,17 +37,17 @@ DecayRangeLeptonInjector::DecayRangeLeptonInjector( disk_radius(disk_radius), endcap_length(endcap_length) { - cross_sections = primary_process->cross_sections; + cross_sections = primary_process->GetCrossSections(); position_distribution = std::make_shared(disk_radius, endcap_length, range_func); - primary_process->injection_distributions.push_back(position_distribution); + primary_process->AddInjectionDistribution(position_distribution); SetPrimaryProcess(primary_process); for(auto & sec_process : secondary_processes) { AddSecondaryProcess(sec_process); // Assume each secondary process already has a position distribution // Otherwise uncomment below /* - target_types = sec_process->cross_sections->TargetTypes(); - sec_process->injection_distributions.push_back(std::make_shared(disk_radius, endcap_length, range_func, target_types)); + target_types = sec_process->GetCrossSections()->TargetTypes(); + sec_process->GetInjectionDistributions().push_back(std::make_shared(disk_radius, endcap_length, range_func, target_types)); */ } } diff --git a/projects/injection/private/InjectorBase.cxx b/projects/injection/private/InjectorBase.cxx index f9c2bce2..369ad3c1 100644 --- a/projects/injection/private/InjectorBase.cxx +++ b/projects/injection/private/InjectorBase.cxx @@ -75,7 +75,7 @@ InjectorBase::InjectorBase( } std::shared_ptr InjectorBase::FindPositionDistribution(std::shared_ptr process) { - for(auto distribution : process->injection_distributions) { + for(auto distribution : process->GetInjectionDistributions()) { if(distribution->IsPositionDistribution()) return std::dynamic_pointer_cast(distribution); } throw(LI::utilities::AddProcessFailure("No vertex distribution specified!")); @@ -103,13 +103,13 @@ void InjectorBase::AddSecondaryProcess(std::shared_ptrprimary_type,secondary}); - secondary_position_distribution_map.insert({secondary->primary_type,vtx_dist}); + secondary_process_map.insert({secondary->GetPrimaryType(), secondary}); + secondary_position_distribution_map.insert({secondary->GetPrimaryType(), vtx_dist}); } LI::dataclasses::InteractionRecord InjectorBase::NewRecord() const { LI::dataclasses::InteractionRecord record; - record.signature.primary_type = primary_process->primary_type; + record.signature.primary_type = primary_process->GetPrimaryType(); return record; } @@ -118,7 +118,7 @@ void InjectorBase::SetRandom(std::shared_ptr random) { } void InjectorBase::SampleCrossSection(LI::dataclasses::InteractionRecord & record) const { - SampleCrossSection(record, primary_process->cross_sections); + SampleCrossSection(record, primary_process->GetCrossSections()); } void InjectorBase::SampleCrossSection(LI::dataclasses::InteractionRecord & record, std::shared_ptr cross_sections) const { @@ -398,14 +398,14 @@ bool InjectorBase::SampleSecondaryProcess(unsigned int idx, LI::dataclasses::Particle::ParticleType const primary = parent->record.signature.secondary_types[idx]; std::vector>::iterator it; for(it = secondary_processes.begin(); it != secondary_processes.end(); ++it) { - if ((*it)->primary_type == primary) break; + if ((*it)->GetPrimaryType() == primary) break; } if(it==secondary_processes.end()) { return false; throw(LI::utilities::SecondaryProcessFailure("No process defined for this particle type!")); } - std::shared_ptr sec_cross_sections = (*it)->cross_sections; - std::vector> sec_distributions = (*it)->injection_distributions; + std::shared_ptr sec_cross_sections = (*it)->GetCrossSections(); + std::vector> sec_distributions = (*it)->GetInjectionDistributions(); datum.record.signature.primary_type = parent->record.signature.secondary_types[idx]; datum.record.primary_mass = parent->record.secondary_masses[idx]; datum.record.primary_momentum = parent->record.secondary_momenta[idx]; @@ -436,8 +436,8 @@ LI::dataclasses::InteractionTree InjectorBase::GenerateEvent() { while(true) { try { record = this->NewRecord(); - for(auto & distribution : primary_process->injection_distributions) { - distribution->Sample(random, earth_model, primary_process->cross_sections, record); + for(auto & distribution : primary_process->GetInjectionDistributions()) { + distribution->Sample(random, earth_model, primary_process->GetCrossSections(), record); } SampleCrossSection(record); break; @@ -493,11 +493,11 @@ double InjectorBase::GenerationProbability(std::shared_ptrinjection_distributions) { - double prob = dist->GenerationProbability(earth_model, process->cross_sections, *datum); + for(auto const & dist : process->GetInjectionDistributions()) { + double prob = dist->GenerationProbability(earth_model, process->GetCrossSections(), *datum); probability *= prob; } - double prob = LI::injection::CrossSectionProbability(earth_model, process->cross_sections, datum->record); + double prob = LI::injection::CrossSectionProbability(earth_model, process->GetCrossSections(), datum->record); probability *= prob; return probability; } @@ -509,11 +509,11 @@ double InjectorBase::GenerationProbability(LI::dataclasses::InteractionRecord co process = primary_process; probability *= events_to_inject; // only do this for the primary process } - for(auto const & dist : process->injection_distributions) { - double prob = dist->GenerationProbability(earth_model, process->cross_sections, record); + for(auto const & dist : process->GetInjectionDistributions()) { + double prob = dist->GenerationProbability(earth_model, process->GetCrossSections(), record); probability *= prob; } - double prob = LI::injection::CrossSectionProbability(earth_model, process->cross_sections, record); + double prob = LI::injection::CrossSectionProbability(earth_model, process->GetCrossSections(), record); probability *= prob; return probability; } @@ -522,12 +522,12 @@ double InjectorBase::GenerationProbability(LI::dataclasses::InteractionRecord co std::set> InjectorBase::DensityVariables() const { std::set> variable_sets; std::vector variables; - for(auto const & dist : primary_process->injection_distributions) { + for(auto const & dist : primary_process->GetInjectionDistributions()) { std::vector new_variables = dist->DensityVariables(); variables.reserve(variables.size() + new_variables.size()); variables.insert(variables.end(), new_variables.begin(), new_variables.end()); } - std::vector> xs_vec = primary_process->cross_sections->GetCrossSections(); + std::vector> xs_vec = primary_process->GetCrossSections()->GetCrossSections(); for(auto const & xs : xs_vec) { std::vector new_variables = xs->DensityVariables(); std::vector variable_list; @@ -547,16 +547,16 @@ std::pair InjectorBase::InjectionBounds( if(!primary_position_distribution) { return std::pair(LI::math::Vector3D(0, 0, 0), LI::math::Vector3D(0, 0, 0)); } - return primary_position_distribution->InjectionBounds(earth_model, primary_process->cross_sections, interaction); + return primary_position_distribution->InjectionBounds(earth_model, primary_process->GetCrossSections(), interaction); } // Assumes there is a secondary process and position distribuiton for the provided particle type std::pair InjectorBase::InjectionBounds(LI::dataclasses::InteractionTreeDatum const & datum, LI::dataclasses::Particle::ParticleType const & primary_type) const { - return secondary_position_distribution_map.at(primary_type)->InjectionBounds(earth_model, secondary_process_map.at(primary_type)->cross_sections, datum); + return secondary_position_distribution_map.at(primary_type)->InjectionBounds(earth_model, secondary_process_map.at(primary_type)->GetCrossSections(), datum); } std::vector> InjectorBase::GetInjectionDistributions() const { - return primary_process->injection_distributions; + return primary_process->GetInjectionDistributions(); } std::shared_ptr InjectorBase::GetEarthModel() const { @@ -564,7 +564,7 @@ std::shared_ptr InjectorBase::GetEarthModel() const { } std::shared_ptr InjectorBase::GetCrossSections() const { - return primary_process->cross_sections; + return primary_process->GetCrossSections(); } unsigned int InjectorBase::InjectedEvents() const { diff --git a/projects/injection/private/Process.cxx b/projects/injection/private/Process.cxx index 757f6ba4..9dd0389c 100644 --- a/projects/injection/private/Process.cxx +++ b/projects/injection/private/Process.cxx @@ -5,6 +5,40 @@ namespace LI { namespace injection { +Process::Process(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections) : primary_type(_primary_type), cross_sections(_cross_sections) {} + +Process::Process(Process const & other) : primary_type(other.primary_type), cross_sections(other.cross_sections) {} + +Process::Process(Process && other) : primary_type(other.primary_type), cross_sections(other.cross_sections) {} + +Process & Process::operator=(Process const & other) { + primary_type = other.primary_type; + cross_sections = other.cross_sections; + return *this; +} + +Process & Process::operator=(Process && other) { + primary_type = other.primary_type; + cross_sections = other.cross_sections; + return *this; +} + +void Process::SetCrossSections(std::shared_ptr _cross_sections) { + cross_sections = _cross_sections; +} + +std::shared_ptr Process::GetCrossSections() const { + return cross_sections; +} + +void Process::SetPrimaryType(LI::dataclasses::Particle::ParticleType _primary_type) { + primary_type = _primary_type; +} + +LI::dataclasses::Particle::ParticleType Process::GetPrimaryType() const { + return primary_type; +} + bool Process::operator==(Process const & other) const { return std::tie( primary_type, @@ -25,5 +59,67 @@ bool Process::MatchesHead(std::shared_ptr const & other) const { other->cross_sections); } +PhysicalProcess::PhysicalProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections) : Process(_primary_type, _cross_sections) {}; + +PhysicalProcess::PhysicalProcess(PhysicalProcess const & other) : Process(other), physical_distributions(other.physical_distributions) {}; + +PhysicalProcess::PhysicalProcess(PhysicalProcess && other) : Process(other), physical_distributions(other.physical_distributions) {}; + +PhysicalProcess & PhysicalProcess::operator=(PhysicalProcess const & other) { + Process::operator=(other); + physical_distributions = other.physical_distributions; + return *this; +}; + +PhysicalProcess & PhysicalProcess::operator=(PhysicalProcess && other) { + Process::operator=(other); + physical_distributions = other.physical_distributions; + return *this; +}; + +void PhysicalProcess::AddPhysicalDistribution(std::shared_ptr dist) { + for(auto _dist: physical_distributions) { + if((*_dist) == (*dist)) return; + } + physical_distributions.push_back(dist); +} + +std::vector> const & PhysicalProcess::GetPhysicalDistributions() const { + return physical_distributions; +} + +InjectionProcess::InjectionProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections) : PhysicalProcess(_primary_type, _cross_sections) {}; + +InjectionProcess::InjectionProcess(InjectionProcess const & other) : PhysicalProcess(other), injection_distributions(other.injection_distributions) {}; + +InjectionProcess::InjectionProcess(InjectionProcess && other) : PhysicalProcess(other), injection_distributions(other.injection_distributions) {}; + +InjectionProcess & InjectionProcess::operator=(InjectionProcess const & other) { + PhysicalProcess::operator=(other); + injection_distributions = other.injection_distributions; + return *this; +}; + +InjectionProcess & InjectionProcess::operator=(InjectionProcess && other) { + PhysicalProcess::operator=(other); + injection_distributions = other.injection_distributions; + return *this; +}; + +void InjectionProcess::AddPhysicalDistribution(std::shared_ptr dist) { + throw std::runtime_error("Cannot add a physical distribution to an InjectionProcess"); +} +void InjectionProcess::AddInjectionDistribution(std::shared_ptr dist) { + for(auto _dist: injection_distributions) { + if((*_dist) == (*dist)) return; + } + injection_distributions.push_back(dist); + physical_distributions.push_back(std::static_pointer_cast(dist)); +} + +std::vector> const & InjectionProcess::GetInjectionDistributions() const { + return injection_distributions; +} + } // namespace injection } // namespace LI diff --git a/projects/injection/private/RangedLeptonInjector.cxx b/projects/injection/private/RangedLeptonInjector.cxx index 22b7a0fe..e03e4494 100644 --- a/projects/injection/private/RangedLeptonInjector.cxx +++ b/projects/injection/private/RangedLeptonInjector.cxx @@ -37,18 +37,18 @@ RangedLeptonInjector::RangedLeptonInjector( disk_radius(disk_radius), endcap_length(endcap_length) { - cross_sections = primary_process->cross_sections; + cross_sections = primary_process->GetCrossSections(); std::set target_types = cross_sections->TargetTypes(); position_distribution = std::make_shared(disk_radius, endcap_length, range_func, target_types); - primary_process->injection_distributions.push_back(position_distribution); + primary_process->AddInjectionDistribution(position_distribution); SetPrimaryProcess(primary_process); for(auto & sec_process : secondary_processes) { AddSecondaryProcess(sec_process); // Assume each secondary process already has a position distribution // Otherwise uncomment below /* - target_types = sec_process->cross_sections->TargetTypes(); - sec_process->injection_distributions.push_back(std::make_shared(disk_radius, endcap_length, range_func, target_types)); + target_types = sec_process->GetCrossSections()->TargetTypes(); + sec_process->GetInjectionDistributions().push_back(std::make_shared(disk_radius, endcap_length, range_func, target_types)); */ } } diff --git a/projects/injection/private/TreeWeighter.cxx b/projects/injection/private/TreeWeighter.cxx index 185cd3be..e9c553ff 100644 --- a/projects/injection/private/TreeWeighter.cxx +++ b/projects/injection/private/TreeWeighter.cxx @@ -109,12 +109,12 @@ void LeptonTreeWeighter::Initialize() { > injector_sec_process_map = injector->GetSecondaryProcessMap(); for(auto const & sec_phys_process : secondary_physical_processes) { try{ - std::shared_ptr sec_inj_process = injector_sec_process_map.at(sec_phys_process->primary_type); + std::shared_ptr sec_inj_process = injector_sec_process_map.at(sec_phys_process->GetPrimaryType()); assert(sec_phys_process->MatchesHead(sec_inj_process)); // make sure cross section collection matches - injector_sec_process_weighter_map[sec_phys_process->primary_type] = std::make_shared(LeptonProcessWeighter(sec_phys_process,sec_inj_process,earth_model)); + injector_sec_process_weighter_map[sec_phys_process->GetPrimaryType()] = std::make_shared(LeptonProcessWeighter(sec_phys_process,sec_inj_process,earth_model)); } catch(const std::out_of_range& oor) { std::cout << "Out of Range error: " << oor.what() << '\n'; - std::cout << "Initialization Incomplete: Particle " << sec_phys_process->primary_type << " does not exist in injector\n"; + std::cout << "Initialization Incomplete: Particle " << sec_phys_process->GetPrimaryType() << " does not exist in injector\n"; return; } } @@ -187,7 +187,7 @@ LeptonTreeWeighter::LeptonTreeWeighter(std::vector void LeptonProcessWeighter::Initialize() { normalization = 1.0; - for(auto physical_dist : phys_process->physical_distributions) { + for(auto physical_dist : phys_process->GetPhysicalDistributions()) { const LI::distributions::PhysicallyNormalizedDistribution* p = dynamic_cast(physical_dist.get()); if(p) { if(p->IsNormalizationSet()) { @@ -195,8 +195,8 @@ void LeptonProcessWeighter::Initialize() { } } } - unique_gen_distributions = inj_process->injection_distributions; - unique_phys_distributions = phys_process->physical_distributions; + unique_gen_distributions = inj_process->GetInjectionDistributions(); + unique_phys_distributions = phys_process->GetPhysicalDistributions(); std::vector>::iterator gen_iterator = unique_gen_distributions.begin(); while(gen_iterator != unique_gen_distributions.end()) { std::vector>::iterator phys_iterator = unique_phys_distributions.begin(); @@ -225,11 +225,11 @@ double LeptonProcessWeighter::InteractionProbability(std::pairGetIntersections(earth_model->GetEarthCoordPosFromDetCoordPos(interaction_vertex), earth_model->GetEarthCoordDirFromDetCoordDir(primary_direction)); - std::map>> const & cross_sections_by_target = phys_process->cross_sections->GetCrossSectionsByTarget(); + std::map>> const & cross_sections_by_target = phys_process->GetCrossSections()->GetCrossSectionsByTarget(); std::vector targets; targets.reserve(cross_sections_by_target.size()); std::vector total_cross_sections; - double total_decay_length = phys_process->cross_sections->TotalDecayLength(record); + double total_decay_length = phys_process->GetCrossSections()->TotalDecayLength(record); LI::dataclasses::InteractionRecord fake_record = record; for(auto const & target_xs : cross_sections_by_target) { @@ -273,13 +273,13 @@ double LeptonProcessWeighter::NormalizedPositionProbability(std::pairGetIntersections(earth_model->GetEarthCoordPosFromDetCoordPos(interaction_vertex), primary_direction); - std::map>> const & cross_sections_by_target = phys_process->cross_sections->GetCrossSectionsByTarget(); + std::map>> const & cross_sections_by_target = phys_process->GetCrossSections()->GetCrossSectionsByTarget(); unsigned int n_targets = cross_sections_by_target.size(); std::vector targets; targets.reserve(n_targets); std::vector total_cross_sections; - double total_decay_length = phys_process->cross_sections->TotalDecayLength(record); + double total_decay_length = phys_process->GetCrossSections()->TotalDecayLength(record); LI::dataclasses::InteractionRecord fake_record = record; for(auto const & target_xs : cross_sections_by_target) { targets.push_back(target_xs.first); @@ -326,22 +326,22 @@ double LeptonProcessWeighter::PhysicalProbability(std::paircross_sections, record); + prob = LI::injection::CrossSectionProbability(earth_model, phys_process->GetCrossSections(), record); physical_probability *= prob; for(auto physical_dist : unique_phys_distributions) { - physical_probability *= physical_dist->GenerationProbability(earth_model, phys_process->cross_sections, record); + physical_probability *= physical_dist->GenerationProbability(earth_model, phys_process->GetCrossSections(), record); } return normalization * physical_probability; } double LeptonProcessWeighter::GenerationProbability(LI::dataclasses::InteractionTreeDatum const & datum ) const { - double gen_probability = LI::injection::CrossSectionProbability(earth_model, phys_process->cross_sections, datum.record); + double gen_probability = LI::injection::CrossSectionProbability(earth_model, phys_process->GetCrossSections(), datum.record); for(auto gen_dist : unique_gen_distributions) { - gen_probability *= gen_dist->GenerationProbability(earth_model, phys_process->cross_sections, datum); + gen_probability *= gen_dist->GenerationProbability(earth_model, phys_process->GetCrossSections(), datum); } return gen_probability; } @@ -351,7 +351,7 @@ double LeptonProcessWeighter::EventWeight(std::pair phys_process,std::shared_ptr inj_process, std::shared_ptr earth_model) +LeptonProcessWeighter::LeptonProcessWeighter(std::shared_ptr phys_process, std::shared_ptr inj_process, std::shared_ptr earth_model) : phys_process(phys_process) , inj_process(inj_process) , earth_model(earth_model) diff --git a/projects/injection/public/LeptonInjector/injection/ColumnDepthLeptonInjector.h b/projects/injection/public/LeptonInjector/injection/ColumnDepthLeptonInjector.h index 3acc1f26..fa63e976 100644 --- a/projects/injection/public/LeptonInjector/injection/ColumnDepthLeptonInjector.h +++ b/projects/injection/public/LeptonInjector/injection/ColumnDepthLeptonInjector.h @@ -29,7 +29,7 @@ namespace LI { namespace crosssections { class CrossSectionCollection; } } namespace LI { namespace dataclasses { struct InteractionRecord; } } -namespace LI { namespace injection { struct InjectionProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } namespace LI { namespace math { class Vector3D; } } namespace LI { namespace utilities { class LI_random; } } diff --git a/projects/injection/public/LeptonInjector/injection/CylinderVolumeLeptonInjector.h b/projects/injection/public/LeptonInjector/injection/CylinderVolumeLeptonInjector.h index 5c3c9b23..c8961ef6 100644 --- a/projects/injection/public/LeptonInjector/injection/CylinderVolumeLeptonInjector.h +++ b/projects/injection/public/LeptonInjector/injection/CylinderVolumeLeptonInjector.h @@ -29,7 +29,7 @@ #include "LeptonInjector/injection/InjectorBase.h" // for InjectorBase namespace LI { namespace dataclasses { struct InteractionRecord; } } -namespace LI { namespace injection { struct InjectionProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } namespace LI { namespace math { class Vector3D; } } // lines 40-40 namespace LI { namespace utilities { class LI_random; } } // lines 44-44 diff --git a/projects/injection/public/LeptonInjector/injection/DecayRangeLeptonInjector.h b/projects/injection/public/LeptonInjector/injection/DecayRangeLeptonInjector.h index 3d5cee7e..f13b42d7 100644 --- a/projects/injection/public/LeptonInjector/injection/DecayRangeLeptonInjector.h +++ b/projects/injection/public/LeptonInjector/injection/DecayRangeLeptonInjector.h @@ -29,7 +29,7 @@ #include "LeptonInjector/injection/InjectorBase.h" // for InjectorBase namespace LI { namespace dataclasses { struct InteractionRecord; } } -namespace LI { namespace injection { struct InjectionProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } namespace LI { namespace math { class Vector3D; } } namespace LI { namespace utilities { class LI_random; } } diff --git a/projects/injection/public/LeptonInjector/injection/InjectorBase.h b/projects/injection/public/LeptonInjector/injection/InjectorBase.h index 559013c2..db0fb6e5 100644 --- a/projects/injection/public/LeptonInjector/injection/InjectorBase.h +++ b/projects/injection/public/LeptonInjector/injection/InjectorBase.h @@ -36,7 +36,7 @@ namespace LI { namespace detector { class EarthModel; } } namespace LI { namespace distributions { class InjectionDistribution; } } namespace LI { namespace distributions { class VertexPositionDistribution; } } namespace LI { namespace geometry { class Geometry; } } -namespace LI { namespace injection { struct InjectionProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } namespace LI { namespace math { class Vector3D; } } namespace LI { namespace utilities { class LI_random; } } diff --git a/projects/injection/public/LeptonInjector/injection/Process.h b/projects/injection/public/LeptonInjector/injection/Process.h index bcaedbc1..99de1715 100644 --- a/projects/injection/public/LeptonInjector/injection/Process.h +++ b/projects/injection/public/LeptonInjector/injection/Process.h @@ -24,12 +24,26 @@ namespace LI { namespace crosssections { class CrossSectionCollection; } } namespace LI { namespace injection { -struct Process { +class Process { +private: LI::dataclasses::Particle::ParticleType primary_type; std::shared_ptr cross_sections; - void SetCrossSections(std::shared_ptr _cross_sections) {cross_sections = _cross_sections;} +public: + Process() = default; + Process(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections); + Process(Process const & other); + Process(Process && other); + Process & operator=(Process const & other); + Process & operator=(Process && other); + virtual ~Process() = default; + + void SetCrossSections(std::shared_ptr _cross_sections); + std::shared_ptr GetCrossSections() const; + void SetPrimaryType(LI::dataclasses::Particle::ParticleType _primary_type); + LI::dataclasses::Particle::ParticleType GetPrimaryType() const; + bool operator==(Process const & other) const; - bool MatchesHead(std::shared_ptr const & other) const; // required to compared instances of derived structs + bool MatchesHead(std::shared_ptr const & other) const; // required to compared instances of derived classs template void serialize(Archive & archive, std::uint32_t const version) { if(version == 0) { @@ -41,40 +55,51 @@ struct Process { }; }; -struct InjectionProcess : Process { - std::vector> injection_distributions; - void AddInjectionDistribution(std::shared_ptr dist) { - for(auto _dist: injection_distributions) { - if((*_dist) == (*dist)) return; - } - injection_distributions.push_back(dist); - } +class PhysicalProcess : public Process { +protected: + std::vector> physical_distributions; +public: + PhysicalProcess() = default; + PhysicalProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections); + PhysicalProcess(PhysicalProcess const & other); + PhysicalProcess(PhysicalProcess && other); + PhysicalProcess & operator=(PhysicalProcess const & other); + PhysicalProcess & operator=(PhysicalProcess && other); + virtual ~PhysicalProcess() = default; + virtual void AddPhysicalDistribution(std::shared_ptr dist); + std::vector> const & GetPhysicalDistributions() const; template void serialize(Archive & archive, std::uint32_t const version) { if(version == 0) { - archive(::cereal::make_nvp("InjectionDistributions", injection_distributions)); + archive(::cereal::make_nvp("PhysicalDistributions", physical_distributions)); archive(cereal::virtual_base_class(this)); } else { - throw std::runtime_error("InjectionProcess only supports version <= 0!"); + throw std::runtime_error("PhysicalProcess only supports version <= 0!"); } }; }; -struct PhysicalProcess : Process{ - std::vector> physical_distributions; - void AddPhysicalDistribution(std::shared_ptr dist) { - for(auto _dist: physical_distributions) { - if((*_dist) == (*dist)) return; - } - physical_distributions.push_back(dist); - } +class InjectionProcess : public PhysicalProcess { +protected: + std::vector> injection_distributions; +public: + InjectionProcess() = default; + InjectionProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr _cross_sections); + InjectionProcess(InjectionProcess const & other); + InjectionProcess(InjectionProcess && other); + InjectionProcess & operator=(InjectionProcess const & other); + InjectionProcess & operator=(InjectionProcess && other); + virtual ~InjectionProcess() = default; + virtual void AddPhysicalDistribution(std::shared_ptr dist) override; + virtual void AddInjectionDistribution(std::shared_ptr dist); + std::vector> const & GetInjectionDistributions() const; template void serialize(Archive & archive, std::uint32_t const version) { if(version == 0) { - archive(::cereal::make_nvp("PhysicalDistributions", physical_distributions)); - archive(cereal::virtual_base_class(this)); + archive(::cereal::make_nvp("InjectionDistributions", injection_distributions)); + archive(cereal::virtual_base_class(this)); } else { - throw std::runtime_error("PhysicalProcess only supports version <= 0!"); + throw std::runtime_error("InjectionProcess only supports version <= 0!"); } }; }; diff --git a/projects/injection/public/LeptonInjector/injection/RangedLeptonInjector.h b/projects/injection/public/LeptonInjector/injection/RangedLeptonInjector.h index 956b4ea5..4c550bd3 100644 --- a/projects/injection/public/LeptonInjector/injection/RangedLeptonInjector.h +++ b/projects/injection/public/LeptonInjector/injection/RangedLeptonInjector.h @@ -27,7 +27,7 @@ #include "LeptonInjector/injection/InjectorBase.h" // for InjectorBase namespace LI { namespace dataclasses { struct InteractionRecord; } } -namespace LI { namespace injection { struct InjectionProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } namespace LI { namespace math { class Vector3D; } } namespace LI { namespace utilities { class LI_random; } } diff --git a/projects/injection/public/LeptonInjector/injection/TreeWeighter.h b/projects/injection/public/LeptonInjector/injection/TreeWeighter.h index 359817bc..f0d37fdd 100644 --- a/projects/injection/public/LeptonInjector/injection/TreeWeighter.h +++ b/projects/injection/public/LeptonInjector/injection/TreeWeighter.h @@ -23,8 +23,8 @@ namespace LI { namespace detector { class EarthModel; } } namespace LI { namespace distributions { class InjectionDistribution; } } namespace LI { namespace distributions { class WeightableDistribution; } } namespace LI { namespace injection { class InjectorBase; } } -namespace LI { namespace injection { struct InjectionProcess; } } -namespace LI { namespace injection { struct PhysicalProcess; } } +namespace LI { namespace injection { class InjectionProcess; } } +namespace LI { namespace injection { class PhysicalProcess; } } namespace LI { namespace math { class Vector3D; } } namespace LI {