Skip to content

Commit

Permalink
feat: add beam energy as a reload function parameter, for users who d…
Browse files Browse the repository at this point in the history
…o not have RCDB
  • Loading branch information
c-dilks committed Oct 3, 2024
1 parent 67ab326 commit 3b3d6c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/iguana/algorithms/physics/InclusiveKinematics/Action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ actions:
inputs:
- name: runnum
type: int
- name: beam_energy
type: double
outputs:
- type: concurrent_key_t
cast: int
Expand Down
16 changes: 6 additions & 10 deletions src/iguana/algorithms/physics/InclusiveKinematics/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,32 @@ namespace iguana::physics {

///////////////////////////////////////////////////////////////////////////////

concurrent_key_t InclusiveKinematics::PrepareEvent(int const runnum) const
concurrent_key_t InclusiveKinematics::PrepareEvent(int const runnum, double const beam_energy) const
{
m_log->Trace("calling PrepareEvent({})", runnum);
if(o_runnum->NeedsHashing()) {
std::hash<int> hash_ftn;
auto hash_key = hash_ftn(runnum);
if(!o_runnum->HasKey(hash_key))
Reload(runnum, hash_key);
Reload(runnum, beam_energy, hash_key);
return hash_key;
} else {
if(o_runnum->IsEmpty() || o_runnum->Load(0) != runnum)
Reload(runnum, 0);
Reload(runnum, beam_energy, 0);
return 0;
}
}

///////////////////////////////////////////////////////////////////////////////

void InclusiveKinematics::Reload(int const runnum, concurrent_key_t key) const
void InclusiveKinematics::Reload(int const runnum, double const user_beam_energy, concurrent_key_t key) const
{
std::lock_guard<std::mutex> const lock(m_mutex);
m_log->Trace("-> calling Reload({}, {})", runnum, key);
m_log->Trace("-> calling Reload({}, {}, {})", runnum, user_beam_energy, key);
o_runnum->Save(runnum, key);

// get the beam energy //////////////////////////////////////////////////////////
auto beam_energy = m_rcdb->GetBeamEnergy(runnum);
m_log->Warn("Run = {}, Beam energy = {}", runnum, beam_energy);
/////////////////////////////////////////////////////////////////////////////////

// parse config params
auto beam_energy = user_beam_energy < 0 ? m_rcdb->GetBeamEnergy(runnum) : user_beam_energy;
auto beam_direction = GetOptionVector<double>("beam_direction", {"initial_state", GetConfig()->InRange("runs", runnum), "beam_direction"});
auto target_particle = GetOptionScalar<std::string>("target_particle", {"initial_state", GetConfig()->InRange("runs", runnum), "target_particle"});

Expand Down
5 changes: 3 additions & 2 deletions src/iguana/algorithms/physics/InclusiveKinematics/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ namespace iguana::physics {
/// @action_function{reload} prepare the event
/// @when_to_call{for each event}
/// @param runnum the run number
/// @param beam_energy the beam energy; if negative (the default), RCDB will be used to get the beam energy from `runnum`
/// @returns the key to be used in `::ComputeFromLepton`
concurrent_key_t PrepareEvent(int const runnum) const;
concurrent_key_t PrepareEvent(int const runnum, double const beam_energy = -1) const;

/// @action_function{scalar creator} compute kinematics from the scattered lepton.
/// @param lepton_px scattered lepton momentum component @f$p_x@f$ (GeV)
Expand All @@ -85,7 +86,7 @@ namespace iguana::physics {
/// @returns the bank row of the scattered lepton, or `-1` if not found
int FindScatteredLepton(hipo::bank const& particle_bank, concurrent_key_t const key) const;

void Reload(int const runnum, concurrent_key_t key) const;
void Reload(int const runnum, double const user_beam_energy, concurrent_key_t key) const;

// banklist indices
hipo::banklist::size_type b_particle;
Expand Down

0 comments on commit 3b3d6c8

Please sign in to comment.