Skip to content

Commit 6f83232

Browse files
authored
feat: calculate inclusive kinematics (#128)
1 parent f0e6538 commit 6f83232

16 files changed

+615
-19
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ on:
3333
"include": [
3434
{ "mode": "coverage", "build_id": "cpp-gcc-release", "CC": "gcc", "CXX": "g++", "buildtype": "release" },
3535
{ "mode": "noROOT", "build_id": "cpp-gcc-release-noROOT", "CC": "gcc", "CXX": "g++", "buildtype": "release" },
36-
{ "mode": "address sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
37-
{ "mode": "thread sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
38-
{ "mode": "undefined behavior sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
39-
{ "mode": "leak sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" }
36+
{ "mode": "address-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
37+
{ "mode": "thread-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
38+
{ "mode": "undefined-behavior-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" },
39+
{ "mode": "leak-sanitizer", "build_id": "cpp-clang-debug", "CC": "clang", "CXX": "clang++", "buildtype": "debug" }
4040
]
4141
}
4242
@@ -372,7 +372,7 @@ jobs:
372372
build-iguana
373373
;;
374374
*sanitizer)
375-
san=$(echo ${{ matrix.mode }} | sed 's; .*;;g')
375+
san=$(echo ${{ matrix.mode }} | sed 's;-.*;;g')
376376
meson configure \
377377
-Db_sanitize=$san \
378378
-Db_lundef=false \
@@ -388,7 +388,9 @@ jobs:
388388
- name: meson test
389389
run: |
390390
meson test --print-errorlogs -C build-iguana # terse
391-
# stdbuf -o0 meson test --print-errorlogs --verbose --no-stdsplit -C build-iguana # verbose
391+
### verbose (do not use by default):
392+
# [ ${{ inputs.runner }} = "macos-latest" ] && stdbuf_cmd=gstdbuf || stdbuf_cmd=stdbuf
393+
# $stdbuf_cmd -o0 meson test --print-errorlogs --verbose --no-stdsplit -C build-iguana
392394
- name: coverage
393395
if: ${{ matrix.mode == 'coverage' }}
394396
run: |
@@ -403,10 +405,10 @@ jobs:
403405
echo '- to compare to the report from the `main` branch, see <https://jeffersonlab.github.io/iguana/coverage-report>' >> $GITHUB_STEP_SUMMARY
404406
### upload artifacts
405407
- uses: actions/upload-artifact@v4
406-
if: ${{ matrix.mode != 'coverage' }}
408+
if: always()
407409
with:
408410
name: logs_build_iguana_${{ matrix.mode }}
409-
retention-days: 1
411+
retention-days: 3
410412
path: build-iguana/meson-logs
411413
- uses: actions/upload-artifact@v4
412414
if: ${{ matrix.mode == 'coverage' }}

doc/namespaces.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
/// General `iguana` namespace
44
namespace iguana {}
55

6-
/// Namespace for CLAS12 `iguana` algorithms
6+
/// Namespace for example algorithms
7+
namespace iguana::example {}
8+
9+
/// Namespace for CLAS12 algorithms
710
namespace iguana::clas12 {}
11+
12+
/// Namespace for physics algorithms
13+
namespace iguana::physics {}

meson/ubsan.supp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# https://github.com/gavalian/hipo/issues/49
12
alignment:hipo::structure::getFloatAt
3+
alignment:hipo::structure::getShortAt
4+
alignment:hipo::structure::getDoubleAt
5+
alignment:hipo::structure::putDoubleAt

src/iguana/algorithms/Algorithm.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Algorithm.h"
22

3+
#include <numeric>
4+
35
namespace iguana {
46

57
void Algorithm::Start()
@@ -212,6 +214,32 @@ namespace iguana {
212214

213215
///////////////////////////////////////////////////////////////////////////////
214216

217+
hipo::schema Algorithm::CreateBank(
218+
hipo::banklist& banks,
219+
hipo::banklist::size_type& bank_idx,
220+
std::string bank_name,
221+
std::vector<std::string> schema_def,
222+
int group_id,
223+
int item_id) const
224+
{
225+
if(schema_def.empty()) {
226+
m_log->Error("empty schema_def in CreateBank");
227+
throw std::runtime_error("CreateBank failed");
228+
}
229+
hipo::schema bank_schema(bank_name.c_str(), group_id, item_id);
230+
bank_schema.parse(std::accumulate(
231+
std::next(schema_def.begin()),
232+
schema_def.end(),
233+
schema_def[0],
234+
[](std::string a, std::string b)
235+
{ return a + "," + b; }));
236+
banks.push_back({bank_schema});
237+
bank_idx = GetBankIndex(banks, bank_name);
238+
return bank_schema;
239+
}
240+
241+
///////////////////////////////////////////////////////////////////////////////
242+
215243
void Algorithm::ShowBanks(hipo::banklist& banks, const std::string message, const Logger::Level level) const
216244
{
217245
if(m_log->GetLevel() <= level) {

src/iguana/algorithms/Algorithm.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ namespace iguana {
164164
/// @param row the row to mask
165165
void MaskRow(hipo::bank& bank, const int row) const;
166166

167+
/// Create a new bank and push it to the bank list
168+
/// @param [out] banks the `hipo::banklist` onto which the new bank will be pushed
169+
/// @param [out] bank_idx will be set to the `hipo::banklist` index of the new bank
170+
/// @param [in] bank_name the new bank name
171+
/// @param [in] schema_def a list of variables for the schema
172+
/// @param [in] group_id the group ID for the schema
173+
/// @param [in] item_id the item ID for the schema
174+
/// @returns the bank's schema
175+
hipo::schema CreateBank(
176+
hipo::banklist& banks,
177+
hipo::banklist::size_type& bank_idx,
178+
std::string bank_name,
179+
std::vector<std::string> schema_def,
180+
int group_id, // FIXME: generalize group_id and item_id setting
181+
int item_id) const noexcept(false);
182+
167183
/// Dump all banks in a `hipo::banklist`
168184
/// @param banks the banks to show
169185
/// @param message if specified, print a header message
@@ -238,9 +254,9 @@ namespace iguana {
238254
/// @param creator the creator function
239255
static bool Register(const std::string& name, algo_creator_t creator) noexcept;
240256

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

245261
private:
246262

src/iguana/algorithms/AlgorithmFactory.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace iguana {
1313
return false;
1414
}
1515

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

2323
}

src/iguana/algorithms/TypeDefs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ namespace iguana {
4444
{ proton, "p" }
4545
};
4646

47+
/// Particle mass in GeV
48+
const std::unordered_map<PDG, double> mass{
49+
{ electron, 0.00051099895000 },
50+
{ pi_plus, 0.13957039 },
51+
{ pi_minus, 0.13957039 },
52+
{ proton, 0.93827208816 }
53+
};
54+
4755
// clang-format on
4856
}
4957

src/iguana/algorithms/clas12/LorentzTransformer.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "LorentzTransformer.h"
22

3+
// ROOT
4+
#include <Math/Boost.h>
5+
#include <Math/Vector4D.h>
6+
37
namespace iguana::clas12 {
48

59
REGISTER_IGUANA_ALGORITHM(LorentzTransformer);
@@ -82,7 +86,7 @@ namespace iguana::clas12 {
8286
}
8387

8488
// boost
85-
ROOT::Math::PxPyPzE4D p_in(p_x, p_y, p_z, E);
89+
ROOT::Math::PxPyPzEVector p_in(p_x, p_y, p_z, E);
8690
ROOT::Math::Boost beta(beta_x, beta_y, beta_z);
8791
auto p_out = beta(p_in);
8892

src/iguana/algorithms/clas12/LorentzTransformer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
#include "iguana/algorithms/Algorithm.h"
44
#include "iguana/algorithms/TypeDefs.h"
55

6-
// ROOT
7-
#include <Math/Boost.h>
8-
#include <Math/Vector4D.h>
9-
106
namespace iguana::clas12 {
117

128
/// @brief Lorentz transform momenta in `REC::Particle` (or similar banks)

src/iguana/algorithms/meson.build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ algo_dict = {
8181
},
8282
'test_args': { 'banks': ['RUN::config', 'REC::Particle', 'REC::Calorimeter', 'REC::Track', 'REC::Scintillator'] },
8383
},
84+
'physics::InclusiveKinematics': {
85+
'algorithm': {
86+
'sources': [ 'physics/InclusiveKinematics.cc' ],
87+
'headers': [ 'physics/InclusiveKinematics.h' ],
88+
'needs_ROOT': true,
89+
},
90+
'validator': {
91+
'sources': [ 'physics/InclusiveKinematicsValidator.cc' ],
92+
'headers': [ 'physics/InclusiveKinematicsValidator.h' ],
93+
'needs_ROOT': true,
94+
},
95+
'configs': [ 'physics/InclusiveKinematics.yaml' ],
96+
'test_args': { 'banks': ['REC::Particle'] },
97+
},
8498
}
8599

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

0 commit comments

Comments
 (0)