Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Processes to classes and add an inheritance relationship betwe… #40

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions projects/injection/private/ColumnDepthLeptonInjector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LI::dataclasses::Particle::ParticleType> target_types = cross_sections->TargetTypes();
position_distribution = std::make_shared<LI::distributions::ColumnDepthPositionDistribution>(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<LI::distributions::ColumnDepthPositionDistribution>(disk_radius, endcap_length, depth_func, target_types));
target_types = sec_process->GetCrossSections()->TargetTypes();
sec_process->GetInjectionDistributions().push_back(std::make_shared<LI::distributions::ColumnDepthPositionDistribution>(disk_radius, endcap_length, depth_func, target_types));
*/
}
}
Expand Down
6 changes: 3 additions & 3 deletions projects/injection/private/CylinderVolumeLeptonInjector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ CylinderVolumeLeptonInjector::CylinderVolumeLeptonInjector(
LI::geometry::Cylinder cylinder) :
InjectorBase(events_to_inject, earth_model, random),
position_distribution(std::make_shared<LI::distributions::CylinderVolumePositionDistribution>(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);
*/
}
}
Expand Down
8 changes: 4 additions & 4 deletions projects/injection/private/DecayRangeLeptonInjector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LI::distributions::DecayRangePositionDistribution>(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<LI::distributions::DecayRangePositionDistribution>(disk_radius, endcap_length, range_func, target_types));
target_types = sec_process->GetCrossSections()->TargetTypes();
sec_process->GetInjectionDistributions().push_back(std::make_shared<LI::distributions::DecayRangePositionDistribution>(disk_radius, endcap_length, range_func, target_types));
*/
}
}
Expand Down
44 changes: 22 additions & 22 deletions projects/injection/private/InjectorBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ InjectorBase::InjectorBase(
}

std::shared_ptr<distributions::VertexPositionDistribution> InjectorBase::FindPositionDistribution(std::shared_ptr<LI::injection::InjectionProcess> process) {
for(auto distribution : process->injection_distributions) {
for(auto distribution : process->GetInjectionDistributions()) {
if(distribution->IsPositionDistribution()) return std::dynamic_pointer_cast<distributions::VertexPositionDistribution>(distribution);
}
throw(LI::utilities::AddProcessFailure("No vertex distribution specified!"));
Expand Down Expand Up @@ -103,13 +103,13 @@ void InjectorBase::AddSecondaryProcess(std::shared_ptr<LI::injection::InjectionP
}
secondary_processes.push_back(secondary);
secondary_position_distributions.push_back(vtx_dist);
secondary_process_map.insert({secondary->primary_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;
}

Expand All @@ -118,7 +118,7 @@ void InjectorBase::SetRandom(std::shared_ptr<LI::utilities::LI_random> 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<LI::crosssections::CrossSectionCollection> cross_sections) const {
Expand Down Expand Up @@ -398,14 +398,14 @@ bool InjectorBase::SampleSecondaryProcess(unsigned int idx,
LI::dataclasses::Particle::ParticleType const primary = parent->record.signature.secondary_types[idx];
std::vector<std::shared_ptr<LI::injection::InjectionProcess>>::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<LI::crosssections::CrossSectionCollection> sec_cross_sections = (*it)->cross_sections;
std::vector<std::shared_ptr<LI::distributions::InjectionDistribution>> sec_distributions = (*it)->injection_distributions;
std::shared_ptr<LI::crosssections::CrossSectionCollection> sec_cross_sections = (*it)->GetCrossSections();
std::vector<std::shared_ptr<LI::distributions::InjectionDistribution>> 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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -493,11 +493,11 @@ double InjectorBase::GenerationProbability(std::shared_ptr<LI::dataclasses::Inte
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, *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;
}
Expand All @@ -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;
}
Expand All @@ -522,12 +522,12 @@ double InjectorBase::GenerationProbability(LI::dataclasses::InteractionRecord co
std::set<std::vector<std::string>> InjectorBase::DensityVariables() const {
std::set<std::vector<std::string>> variable_sets;
std::vector<std::string> variables;
for(auto const & dist : primary_process->injection_distributions) {
for(auto const & dist : primary_process->GetInjectionDistributions()) {
std::vector<std::string> new_variables = dist->DensityVariables();
variables.reserve(variables.size() + new_variables.size());
variables.insert(variables.end(), new_variables.begin(), new_variables.end());
}
std::vector<std::shared_ptr<LI::crosssections::CrossSection>> xs_vec = primary_process->cross_sections->GetCrossSections();
std::vector<std::shared_ptr<LI::crosssections::CrossSection>> xs_vec = primary_process->GetCrossSections()->GetCrossSections();
for(auto const & xs : xs_vec) {
std::vector<std::string> new_variables = xs->DensityVariables();
std::vector<std::string> variable_list;
Expand All @@ -547,24 +547,24 @@ std::pair<LI::math::Vector3D, LI::math::Vector3D> InjectorBase::InjectionBounds(
if(!primary_position_distribution) {
return std::pair<LI::math::Vector3D, LI::math::Vector3D>(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<LI::math::Vector3D, LI::math::Vector3D> 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<std::shared_ptr<LI::distributions::InjectionDistribution>> InjectorBase::GetInjectionDistributions() const {
return primary_process->injection_distributions;
return primary_process->GetInjectionDistributions();
}

std::shared_ptr<LI::detector::EarthModel> InjectorBase::GetEarthModel() const {
return earth_model;
}

std::shared_ptr<LI::crosssections::CrossSectionCollection> InjectorBase::GetCrossSections() const {
return primary_process->cross_sections;
return primary_process->GetCrossSections();
}

unsigned int InjectorBase::InjectedEvents() const {
Expand Down
96 changes: 96 additions & 0 deletions projects/injection/private/Process.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@
namespace LI {
namespace injection {

Process::Process(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr<crosssections::CrossSectionCollection> _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<crosssections::CrossSectionCollection> _cross_sections) {
cross_sections = _cross_sections;
}

std::shared_ptr<crosssections::CrossSectionCollection> 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,
Expand All @@ -25,5 +59,67 @@ bool Process::MatchesHead(std::shared_ptr<Process> const & other) const {
other->cross_sections);
}

PhysicalProcess::PhysicalProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr<crosssections::CrossSectionCollection> _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<distributions::WeightableDistribution> dist) {
for(auto _dist: physical_distributions) {
if((*_dist) == (*dist)) return;
}
physical_distributions.push_back(dist);
}

std::vector<std::shared_ptr<distributions::WeightableDistribution>> const & PhysicalProcess::GetPhysicalDistributions() const {
return physical_distributions;
}

InjectionProcess::InjectionProcess(LI::dataclasses::Particle::ParticleType _primary_type, std::shared_ptr<crosssections::CrossSectionCollection> _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<distributions::WeightableDistribution> dist) {
throw std::runtime_error("Cannot add a physical distribution to an InjectionProcess");
}
void InjectionProcess::AddInjectionDistribution(std::shared_ptr<distributions::InjectionDistribution> dist) {
for(auto _dist: injection_distributions) {
if((*_dist) == (*dist)) return;
}
injection_distributions.push_back(dist);
physical_distributions.push_back(std::static_pointer_cast<distributions::WeightableDistribution>(dist));
}

std::vector<std::shared_ptr<distributions::InjectionDistribution>> const & InjectionProcess::GetInjectionDistributions() const {
return injection_distributions;
}

} // namespace injection
} // namespace LI
8 changes: 4 additions & 4 deletions projects/injection/private/RangedLeptonInjector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LI::dataclasses::Particle::ParticleType> target_types = cross_sections->TargetTypes();
position_distribution = std::make_shared<LI::distributions::RangePositionDistribution>(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<LI::distributions::DecayRangePositionDistribution>(disk_radius, endcap_length, range_func, target_types));
target_types = sec_process->GetCrossSections()->TargetTypes();
sec_process->GetInjectionDistributions().push_back(std::make_shared<LI::distributions::DecayRangePositionDistribution>(disk_radius, endcap_length, range_func, target_types));
*/
}
}
Expand Down
Loading
Loading