diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f178908fc48b6bae2130ae005037c0c38b234cb..e38f3484d4a9826869e0fcc6f878318d38e91c6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,16 @@ find_package(Microsoft.GSL CONFIG) find_package(EICD REQUIRED) find_package(EDM4HEP 0.4.1 REQUIRED) +find_package(algorithms) +if(${algorithms_FOUND}) + message(STATUS "algorithms library found") + add_definitions("-DUSE_ALGORITHMS") + set(algorithms "algorithms::JugDigiPlugins") +else() + message(STATUS "algorithms library not found.") + set(algorithms "") +endif() + find_package(podio 0.14.1 REQUIRED) add_definitions("-Dpodio_VERSION_MAJOR=${podio_VERSION_MAJOR}") add_definitions("-Dpodio_VERSION_MINOR=${podio_VERSION_MINOR}") diff --git a/JugDigi/CMakeLists.txt b/JugDigi/CMakeLists.txt index 64a0749a4273b2e5691fb77010a9a4ee6c5c65c2..c44457ce5a46ce41deb23fb2ba8b15fb48dcde77 100644 --- a/JugDigi/CMakeLists.txt +++ b/JugDigi/CMakeLists.txt @@ -15,6 +15,7 @@ gaudi_add_module(JugDigiPlugins ROOT::Core ROOT::RIO ROOT::Tree EDM4HEP::edm4hep EICD::eicd + ${algorithms} ) target_include_directories(JugDigiPlugins PUBLIC diff --git a/JugDigi/src/components/CalorimeterBirksCorr.cpp b/JugDigi/src/components/CalorimeterBirksCorr.cpp index b42c1dd72a783c99149f088a4e70c11e44ebc4e2..6811f5d439c778c596d1cec99d518cc716f7c7e7 100644 --- a/JugDigi/src/components/CalorimeterBirksCorr.cpp +++ b/JugDigi/src/components/CalorimeterBirksCorr.cpp @@ -24,6 +24,10 @@ #include "eicd/RawCalorimeterHitCollection.h" #include "eicd/RawCalorimeterHitData.h" +// Algorithms library +#ifdef USE_ALGORITHMS +#include "JugDigi/CalorimeterBirksCorr.h" +#endif using namespace Gaudi::Units; @@ -45,6 +49,10 @@ namespace Jug::Digi { DataHandle m_outputHitCollection{"outputHitCollection", Gaudi::DataHandle::Writer, this}; +#ifdef USE_ALGORITHMS + algorithms::digi::CalorimeterBirksCorr m_algorithm; +#endif + SmartIF m_pidSvc; // unitless conterpart of arguments double birksConstant{0}; @@ -55,6 +63,10 @@ namespace Jug::Digi { { declareProperty("inputHitCollection", m_inputHitCollection, ""); declareProperty("outputHitCollection", m_outputHitCollection, ""); + +#ifdef USE_ALGORITHMS + m_algorithms->registerProperty{"birksConstant", m_birksConstant}; +#endif } StatusCode initialize() override @@ -71,6 +83,10 @@ namespace Jug::Digi { return StatusCode::FAILURE; } +#ifdef USE_ALGORITHMS + //m_algorithm.setService("particleService", [&m_pidSvc](int pdg){ return m_pidSvc->particle(pdg); }); +#endif + // using juggler internal units (GeV, mm, radian, ns) birksConstant = m_birksConstant.value() / mm * GeV; @@ -79,6 +95,12 @@ namespace Jug::Digi { StatusCode execute() override { +#ifdef USE_ALGORITHMS + const auto* const input = m_inputHitCollection.get(); + auto* output = m_outputHitCollection.createAndPut(); + *output = m_algorithm(*input); + return StatusCode::SUCCESS; +#else auto& ohits = *m_outputHitCollection.createAndPut(); for (const auto& hit : *m_inputHitCollection.get()) { auto ohit = ohits->create(hit.getCellID(), hit.getEnergy(), hit.getPosition()); @@ -98,6 +120,7 @@ namespace Jug::Digi { ohit.setEnergy(energy); } return StatusCode::SUCCESS; +#endif } }; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) diff --git a/JugDigi/src/components/CalorimeterHitDigi.cpp b/JugDigi/src/components/CalorimeterHitDigi.cpp index 622418954cac55d77da55a3ce981fdc3b4bc54f4..2c0fcb79e1134294ef9a3141664bea3d034f2f70 100644 --- a/JugDigi/src/components/CalorimeterHitDigi.cpp +++ b/JugDigi/src/components/CalorimeterHitDigi.cpp @@ -34,6 +34,10 @@ #include "eicd/RawCalorimeterHitCollection.h" #include "eicd/RawCalorimeterHitData.h" +// Algorithms library +#ifdef USE_ALGORITHMS +#include "JugDigi/CalorimeterHitDigi.h" +#endif using namespace Gaudi::Units; @@ -83,11 +87,23 @@ namespace Jug::Digi { DataHandle m_outputHitCollection{ "outputHitCollection", Gaudi::DataHandle::Writer, this}; +#ifdef USE_ALGORITHMS + algorithms::digi::CalorimeterHitDigi m_algorithm; +#endif + // ill-formed: using GaudiAlgorithm::GaudiAlgorithm; CalorimeterHitDigi(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { declareProperty("inputHitCollection", m_inputHitCollection, ""); declareProperty("outputHitCollection", m_outputHitCollection, ""); + +#ifdef USE_ALGORITHMS + // Connecting Gaudi properties to algorithm + m_algorithm.setProperty("pedestalMean", m_pedMeanADC); + + // Connecting Gaudi services to algorithm + m_algorithm.setService("geoSvc", m_normDist); +#endif } StatusCode initialize() override @@ -95,6 +111,10 @@ namespace Jug::Digi { if (GaudiAlgorithm::initialize().isFailure()) { return StatusCode::FAILURE; } +#ifdef USE_ALGORITHMS + m_algorithm.initialize(); +#endif + // random number generator from service auto randSvc = svc("RndmGenSvc", true); auto sc = m_normDist.initialize(randSvc, Rndm::Gauss(0.0, 1.0)); @@ -154,12 +174,25 @@ namespace Jug::Digi { StatusCode execute() override { +#ifdef USE_ALGORITHMS + // input collections + const auto* const simhits = m_inputHitCollection.get(); + // output collections + auto* rawhits = m_outputHitCollection.createAndPut(); + + // apply algorithms + *rawhits = m_algorithm(*simhits); + + return StatusCode::SUCCESS; +#else + if (!u_fields.value().empty()) { signal_sum_digi(); } else { single_hits_digi(); } return StatusCode::SUCCESS; +#endif } private: