Skip to content

Commit

Permalink
feat: particle::get utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Dec 1, 2024
1 parent f1c7259 commit f58272f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
33 changes: 33 additions & 0 deletions src/iguana/algorithms/TypeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <string>
#include <optional>
#include <unordered_map>

namespace iguana {
Expand Down Expand Up @@ -92,6 +93,38 @@ namespace iguana {
{ kaon_minus, 0.493677 }
};

/// @brief get a particle property given a PDG code
///
/// Example:
/// ```cpp
/// auto mass = particle::get(particle::mass, particle::PDG::photon); // mass => 0.0
/// ```
/// @param property the particle property, such as `particle::name`, `particle::title`, or `particle::mass`
/// @param pdg_code the `particle::PDG` value
/// @returns the value of the property, if defined for this `pdg_code`
template <typename VALUE_TYPE>
std::optional<VALUE_TYPE> const get(std::unordered_map<PDG,VALUE_TYPE> const& property, PDG const& pdg_code)
{
if(auto const& it = property.find(pdg_code); it != property.end())
return it->second;
return std::nullopt;
}

/// @brief get a particle property given a PDG code
///
/// Example:
/// ```cpp
/// auto mass = particle::get(particle::mass, 22); // mass => 0.0
/// ```
/// @param property the particle property, such as `particle::name`, `particle::title`, or `particle::mass`
/// @param pdg_code the `particle::PDG` value
/// @returns the value of the property, if defined for this `pdg_code`
template <typename VALUE_TYPE>
std::optional<VALUE_TYPE> const get(std::unordered_map<PDG,VALUE_TYPE> const& property, int const& pdg_code)
{
return get(property, static_cast<particle::PDG>(pdg_code));
}

// clang-format on
}

Expand Down
15 changes: 3 additions & 12 deletions src/iguana/algorithms/clas12/PhotonGBTFilter/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ namespace iguana::clas12 {
auto calo_PART = calo_map.at(inner_row);

auto pid = particleBank.getInt("pid",inner_row);
auto mass = GetMass(pid);
auto mass = particle::get(particle::mass, pid);

// Skip over particle if its mass was undefined
if (mass == -1.0) continue;
if (!mass.value()) continue;
auto px = particleBank.getFloat("px",inner_row);
auto py = particleBank.getFloat("py",inner_row);
auto pz = particleBank.getFloat("pz",inner_row);
auto p = sqrt(px*px+py*py+pz*pz);
auto E = sqrt(p*p+mass*mass);
auto E = sqrt(p*p+mass.value()*mass.value());
auto th = acos(pz/p);
// Skip over particle if it is not in the forward detector (necessary for model compatibility)
if (ForwardDetectorFilter(th)==false) continue;
Expand Down Expand Up @@ -367,15 +367,6 @@ namespace iguana::clas12 {
return v;
}

double PhotonGBTFilter::GetMass(int pid) const {
auto it = particle::mass.find(static_cast<particle::PDG>(pid));
if (it != particle::mass.end()) {
return it->second;
} else {
return -1.0; // Default mass if pid not found
}
}

std::function<double(std::vector<float> const &)> PhotonGBTFilter::getModelFunction(int runnum) const {

for (const auto &entry : modelMap) {
Expand Down
7 changes: 0 additions & 7 deletions src/iguana/algorithms/clas12/PhotonGBTFilter/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ namespace iguana::clas12 {
/// @returns a ROOT::Math::XYZVector with the coordinates of the particle in the calorimeter
ROOT::Math::XYZVector GetParticleCaloVector(PhotonGBTFilter::calo_row_data calo_row) const;


/// Gets the mass of a particle given its PID
/// @param pid the particle ID to get the mass for
/// @returns the mass of the particle in GeV; returns -1.0 if the PID is not recognized
double GetMass(int pid) const;


/// Gets the model function for the run number
/// @param runnum the run of the associated event
/// @returns GBT function for the run period
Expand Down

0 comments on commit f58272f

Please sign in to comment.