Skip to content

Commit

Permalink
feat: calculate inclusive kinematics (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Mar 12, 2024
1 parent f0e6538 commit 6f83232
Show file tree
Hide file tree
Showing 16 changed files with 615 additions and 19 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ on:
"include": [
{ "mode": "coverage", "build_id": "cpp-gcc-release", "CC": "gcc", "CXX": "g++", "buildtype": "release" },
{ "mode": "noROOT", "build_id": "cpp-gcc-release-noROOT", "CC": "gcc", "CXX": "g++", "buildtype": "release" },
{ "mode": "address sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "thread sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "undefined behavior sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "leak sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" }
{ "mode": "address-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "thread-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "undefined-behavior-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
{ "mode": "leak-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" }
]
}
Expand Down Expand Up @@ -372,7 +372,7 @@ jobs:
build-iguana
;;
*sanitizer)
san=$(echo ${{ matrix.mode }} | sed 's; .*;;g')
san=$(echo ${{ matrix.mode }} | sed 's;-.*;;g')
meson configure \
-Db_sanitize=$san \
-Db_lundef=false \
Expand All @@ -388,7 +388,9 @@ jobs:
- name: meson test
run: |
meson test --print-errorlogs -C build-iguana # terse
# stdbuf -o0 meson test --print-errorlogs --verbose --no-stdsplit -C build-iguana # verbose
### verbose (do not use by default):
# [ ${{ inputs.runner }} = "macos-latest" ] && stdbuf_cmd=gstdbuf || stdbuf_cmd=stdbuf
# $stdbuf_cmd -o0 meson test --print-errorlogs --verbose --no-stdsplit -C build-iguana
- name: coverage
if: ${{ matrix.mode == 'coverage' }}
run: |
Expand All @@ -403,10 +405,10 @@ jobs:
echo '- to compare to the report from the `main` branch, see <https://jeffersonlab.github.io/iguana/coverage-report>' >> $GITHUB_STEP_SUMMARY
### upload artifacts
- uses: actions/upload-artifact@v4
if: ${{ matrix.mode != 'coverage' }}
if: always()
with:
name: logs_build_iguana_${{ matrix.mode }}
retention-days: 1
retention-days: 3
path: build-iguana/meson-logs
- uses: actions/upload-artifact@v4
if: ${{ matrix.mode == 'coverage' }}
Expand Down
8 changes: 7 additions & 1 deletion doc/namespaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
/// General `iguana` namespace
namespace iguana {}

/// Namespace for CLAS12 `iguana` algorithms
/// Namespace for example algorithms
namespace iguana::example {}

/// Namespace for CLAS12 algorithms
namespace iguana::clas12 {}

/// Namespace for physics algorithms
namespace iguana::physics {}
4 changes: 4 additions & 0 deletions meson/ubsan.supp
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# https://github.com/gavalian/hipo/issues/49
alignment:hipo::structure::getFloatAt
alignment:hipo::structure::getShortAt
alignment:hipo::structure::getDoubleAt
alignment:hipo::structure::putDoubleAt
28 changes: 28 additions & 0 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Algorithm.h"

#include <numeric>

namespace iguana {

void Algorithm::Start()
Expand Down Expand Up @@ -212,6 +214,32 @@ namespace iguana {

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

hipo::schema Algorithm::CreateBank(
hipo::banklist& banks,
hipo::banklist::size_type& bank_idx,
std::string bank_name,
std::vector<std::string> schema_def,
int group_id,
int item_id) const
{
if(schema_def.empty()) {
m_log->Error("empty schema_def in CreateBank");
throw std::runtime_error("CreateBank failed");
}
hipo::schema bank_schema(bank_name.c_str(), group_id, item_id);
bank_schema.parse(std::accumulate(
std::next(schema_def.begin()),
schema_def.end(),
schema_def[0],
[](std::string a, std::string b)
{ return a + "," + b; }));
banks.push_back({bank_schema});
bank_idx = GetBankIndex(banks, bank_name);
return bank_schema;
}

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

void Algorithm::ShowBanks(hipo::banklist& banks, const std::string message, const Logger::Level level) const
{
if(m_log->GetLevel() <= level) {
Expand Down
20 changes: 18 additions & 2 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ namespace iguana {
/// @param row the row to mask
void MaskRow(hipo::bank& bank, const int row) const;

/// Create a new bank and push it to the bank list
/// @param [out] banks the `hipo::banklist` onto which the new bank will be pushed
/// @param [out] bank_idx will be set to the `hipo::banklist` index of the new bank
/// @param [in] bank_name the new bank name
/// @param [in] schema_def a list of variables for the schema
/// @param [in] group_id the group ID for the schema
/// @param [in] item_id the item ID for the schema
/// @returns the bank's schema
hipo::schema CreateBank(
hipo::banklist& banks,
hipo::banklist::size_type& bank_idx,
std::string bank_name,
std::vector<std::string> schema_def,
int group_id, // FIXME: generalize group_id and item_id setting
int item_id) const noexcept(false);

/// Dump all banks in a `hipo::banklist`
/// @param banks the banks to show
/// @param message if specified, print a header message
Expand Down Expand Up @@ -238,9 +254,9 @@ namespace iguana {
/// @param creator the creator function
static bool Register(const std::string& name, algo_creator_t creator) noexcept;

/// Create an algorithm.
/// Create an algorithm. Throws an exception if the algorithm cannot be created
/// @param name the name of the algorithm, which was used as an argument in the `AlgorithmFactory::Register` call
static algo_t Create(const std::string& name) noexcept;
static algo_t Create(const std::string& name) noexcept(false);

private:

Expand Down
4 changes: 2 additions & 2 deletions src/iguana/algorithms/AlgorithmFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace iguana {
return false;
}

algo_t AlgorithmFactory::Create(const std::string& name) noexcept
algo_t AlgorithmFactory::Create(const std::string& name)
{
if(auto it = s_creators.find(name); it != s_creators.end())
return it->second();
return nullptr;
throw std::runtime_error(fmt::format("AlgorithmFactory: algorithm with name {:?} does not exist", name));
}

}
8 changes: 8 additions & 0 deletions src/iguana/algorithms/TypeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ namespace iguana {
{ proton, "p" }
};

/// Particle mass in GeV
const std::unordered_map<PDG, double> mass{
{ electron, 0.00051099895000 },
{ pi_plus, 0.13957039 },
{ pi_minus, 0.13957039 },
{ proton, 0.93827208816 }
};

// clang-format on
}

Expand Down
6 changes: 5 additions & 1 deletion src/iguana/algorithms/clas12/LorentzTransformer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "LorentzTransformer.h"

// ROOT
#include <Math/Boost.h>
#include <Math/Vector4D.h>

namespace iguana::clas12 {

REGISTER_IGUANA_ALGORITHM(LorentzTransformer);
Expand Down Expand Up @@ -82,7 +86,7 @@ namespace iguana::clas12 {
}

// boost
ROOT::Math::PxPyPzE4D p_in(p_x, p_y, p_z, E);
ROOT::Math::PxPyPzEVector p_in(p_x, p_y, p_z, E);
ROOT::Math::Boost beta(beta_x, beta_y, beta_z);
auto p_out = beta(p_in);

Expand Down
4 changes: 0 additions & 4 deletions src/iguana/algorithms/clas12/LorentzTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include "iguana/algorithms/Algorithm.h"
#include "iguana/algorithms/TypeDefs.h"

// ROOT
#include <Math/Boost.h>
#include <Math/Vector4D.h>

namespace iguana::clas12 {

/// @brief Lorentz transform momenta in `REC::Particle` (or similar banks)
Expand Down
14 changes: 14 additions & 0 deletions src/iguana/algorithms/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ algo_dict = {
},
'test_args': { 'banks': ['RUN::config', 'REC::Particle', 'REC::Calorimeter', 'REC::Track', 'REC::Scintillator'] },
},
'physics::InclusiveKinematics': {
'algorithm': {
'sources': [ 'physics/InclusiveKinematics.cc' ],
'headers': [ 'physics/InclusiveKinematics.h' ],
'needs_ROOT': true,
},
'validator': {
'sources': [ 'physics/InclusiveKinematicsValidator.cc' ],
'headers': [ 'physics/InclusiveKinematicsValidator.h' ],
'needs_ROOT': true,
},
'configs': [ 'physics/InclusiveKinematics.yaml' ],
'test_args': { 'banks': ['REC::Particle'] },
},
}

# make lists of objects to build; inclusion depends on whether ROOT is needed or not, and if we have ROOT
Expand Down
Loading

0 comments on commit 6f83232

Please sign in to comment.