Skip to content

Commit

Permalink
feat: Lorentz transformer algorithm (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Dec 7, 2023
1 parent 7b57b0e commit 81b6233
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 18 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sudo apt install -y doxygen
- run: doxygen doc/Doxyfile
- name: doxygen
uses: mattnotmitt/doxygen-action@v1
with:
doxyfile-path: doc/Doxyfile
- uses: actions/upload-pages-artifact@v2
with:
retention-days: 1
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ FORMULA_MACROFILE =
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

USE_MATHJAX = NO
USE_MATHJAX = YES

# With MATHJAX_VERSION it is possible to specify the MathJax version to be used.
# Note that the different versions of MathJax have different requirements with
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "services/Algorithm.h"
#include <set>

namespace iguana::clas12 {

Expand Down
3 changes: 0 additions & 3 deletions src/algorithms/clas12/event_builder_filter/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions src/algorithms/clas12/fiducial_cuts/README.md

This file was deleted.

50 changes: 50 additions & 0 deletions src/algorithms/clas12/lorentz_transformer/LorentzTransformer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "LorentzTransformer.h"

namespace iguana::clas12 {

void LorentzTransformer::Start(hipo::banklist& banks) {

CacheOption("frame", std::string{"mirror"}, o_frame);
CacheBankIndex(banks, "REC::Particle", b_particle);

// define transformation function
// TODO: add more useful frames, e.g., Breit
if(o_frame == "mirror") { // reverses the momentum, just for demonstration
m_transform = [] (float& px, float& py, float& pz, float& e) {
px = -px;
py = -py;
pz = -pz;
};
}
else
Throw(fmt::format("unknown frame '{}'", o_frame));

}


void LorentzTransformer::Run(hipo::banklist& banks) const {
auto& particleBank = GetBank(banks, b_particle, "REC::Particle");
ShowBank(particleBank, Logger::Header("INPUT PARTICLES"));
for(int row = 0; row < particleBank.getRows(); row++) {
auto px = particleBank.getFloat("px", row);
auto py = particleBank.getFloat("py", row);
auto pz = particleBank.getFloat("pz", row);
float e = 0.0; // TODO: get the energy
Transform(px, py, pz, e);
particleBank.putFloat("px", row, px);
particleBank.putFloat("py", row, py);
particleBank.putFloat("pz", row, pz);
}
ShowBank(particleBank, Logger::Header("OUTPUT PARTICLES"));
}


void LorentzTransformer::Transform(float& px, float& py, float& pz, float& e) const {
m_transform(px, py, pz, e);
}


void LorentzTransformer::Stop() {
}

}
43 changes: 43 additions & 0 deletions src/algorithms/clas12/lorentz_transformer/LorentzTransformer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "services/Algorithm.h"

namespace iguana::clas12 {

/// @brief Lorentz transform momenta in `REC::Particle` (or similar banks)
///
/// Available frames are:
/// - `"mirror"`: reverse the momentum (just a demo)
class LorentzTransformer : public Algorithm {

public:

/// @see `Algorithm::Algorithm`
LorentzTransformer(std::string name="lorentz_transformer") : Algorithm(name) {}
~LorentzTransformer() {}

void Start(hipo::banklist& banks) override;
void Run(hipo::banklist& banks) const override;
void Stop() override;

/// **Action function**: transform the 4-momentum @f$p=(p_x,p_y,p_z,E)@f$ to the specified frame
/// @param px @f$p_x@f$
/// @param py @f$p_y@f$
/// @param pz @f$p_z@f$
/// @param e @f$E@f$
void Transform(float& px, float& py, float& pz, float& e) const;

private:

/// `hipo::banklist` index for the particle bank
int b_particle;

/// configuration options
std::string o_frame;

/// Lorentz transformation function
std::function<void(float&,float&,float&,float&)> m_transform;

};

}
3 changes: 0 additions & 3 deletions src/algorithms/clas12/momentum_corrections/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions src/algorithms/clas12/pid_refinement/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/algorithms/meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
algo_headers = [
'clas12/event_builder_filter/EventBuilderFilter.h',
'clas12/lorentz_transformer/LorentzTransformer.h',
]

algo_sources = [
'clas12/event_builder_filter/EventBuilderFilter.cc',
'clas12/lorentz_transformer/LorentzTransformer.cc',
]

algo_lib = shared_library(
Expand Down
1 change: 1 addition & 0 deletions src/iguana/AlgorithmSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace iguana {

AlgorithmSequence::AlgorithmSequence() {
algo_map.insert({clas12_EventBuilderFilter, std::move(std::make_unique<clas12::EventBuilderFilter>())});
algo_map.insert({clas12_LorentzTransformer, std::move(std::make_unique<clas12::LorentzTransformer>())});
}

}
4 changes: 3 additions & 1 deletion src/iguana/AlgorithmSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// TODO: avoid listing the algos
#include "algorithms/clas12/event_builder_filter/EventBuilderFilter.h"
#include "algorithms/clas12/lorentz_transformer/LorentzTransformer.h"

namespace iguana {

Expand All @@ -19,7 +20,8 @@ namespace iguana {
// TODO: avoid listing the algos
// TODO: who should own the algorithm instances: AlgorithmSequence or the user?
enum algo {
clas12_EventBuilderFilter
clas12_EventBuilderFilter,
clas12_LorentzTransformer
};

/// Map of algorithm enumerator to the algorithm
Expand Down
1 change: 1 addition & 0 deletions src/services/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <functional>

#include <hipo4/bank.h>

Expand Down
3 changes: 2 additions & 1 deletion src/tests/run_banks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ int main(int argc, char **argv) {
* use the test algorithm directly
*/
const iguana::AlgorithmSequence I;
auto& algo = I.algo_map.at(iguana::AlgorithmSequence::clas12_EventBuilderFilter);
// auto& algo = I.algo_map.at(iguana::AlgorithmSequence::clas12_EventBuilderFilter);
auto& algo = I.algo_map.at(iguana::AlgorithmSequence::clas12_LorentzTransformer);
algo->Log()->SetLevel("trace");
// algo->Log()->DisableStyle();
algo->SetOption("pids", std::set<int>{11, 211, -211});
Expand Down

0 comments on commit 81b6233

Please sign in to comment.