diff --git a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc index d92b382714..296720c490 100644 --- a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc +++ b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc @@ -32,10 +32,10 @@ namespace eicrecon { // Locate and load the weight file // TODO - Add functionality to select passed by configuration - bool methodFound = false; if(!m_cfg.modelPath.empty()){ try{ m_method = dynamic_cast(m_reader->BookMVA( m_cfg.methodName, m_cfg.modelPath )); + m_initialized = true; } catch(std::exception &e){ error(fmt::format("Failed to load method {} from file {}: {}", m_cfg.methodName, m_cfg.modelPath, e.what())); @@ -55,6 +55,12 @@ namespace eicrecon { const auto [inputTracks,beamElectrons] = input; auto [outputFarDetectorMLTrajectories, outputFarDetectorMLTrackParameters, outputFarDetectorMLTracks] = output; + // Check if the algorithm has been initialized properly + if(!m_initialized){ + debug("Initialization did not complete"); + return; + } + //Set beam energy from first MCBeamElectron, using std::call_once std::call_once(m_initBeamE,[&](){ // Check if beam electrons are present diff --git a/src/algorithms/fardetectors/FarDetectorMLReconstruction.h b/src/algorithms/fardetectors/FarDetectorMLReconstruction.h index a0f72141a7..b95f6be000 100644 --- a/src/algorithms/fardetectors/FarDetectorMLReconstruction.h +++ b/src/algorithms/fardetectors/FarDetectorMLReconstruction.h @@ -61,6 +61,7 @@ namespace eicrecon { float m_beamE{10.0}; std::once_flag m_initBeamE; float nnInput[4] = {0.0,0.0,0.0,0.0}; + bool m_initialized{false}; }; diff --git a/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc b/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc index b12a61b738..d49214eace 100644 --- a/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc +++ b/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc @@ -30,7 +30,7 @@ void FarDetectorTrackerCluster::init() { m_cellid_converter = algorithms::GeoSvc::instance().cellIDPositionConverter(); if (m_cfg.readout.empty()) { - throw JException("Readout is empty"); + error("Config readout field is empty"); } try { m_seg = m_detector->readout(m_cfg.readout).segmentation(); @@ -43,9 +43,9 @@ void FarDetectorTrackerCluster::init() { m_y_idx = m_id_dec->index(m_cfg.y_field); debug("Find layer field {}, index = {}", m_cfg.y_field, m_y_idx); } + m_initialized = true; } catch (...) { error("Failed to load ID decoder for {}", m_cfg.readout); - throw JException("Failed to load ID decoder"); } } @@ -55,6 +55,12 @@ void FarDetectorTrackerCluster::process(const FarDetectorTrackerCluster::Input& const auto [inputHitsCollections] = input; auto [outputClustersCollection] = output; + // Return if configurations are not set properly + if (!m_initialized) { + debug("Initialization did not complete"); + return; + } + // Loop over input and output collections - Any collection should only contain hits from a single // surface for (size_t i = 0; i < inputHitsCollections.size(); i++) { diff --git a/src/algorithms/fardetectors/FarDetectorTrackerCluster.h b/src/algorithms/fardetectors/FarDetectorTrackerCluster.h index 6ac60e5067..1849c1d107 100644 --- a/src/algorithms/fardetectors/FarDetectorTrackerCluster.h +++ b/src/algorithms/fardetectors/FarDetectorTrackerCluster.h @@ -62,6 +62,7 @@ class FarDetectorTrackerCluster : public FarDetectorTrackerClusterAlgorithm, const dd4hep::BitFieldCoder* m_id_dec{nullptr}; const dd4hep::rec::CellIDPositionConverter* m_cellid_converter{nullptr}; dd4hep::Segmentation m_seg; + bool m_initialized{false}; int m_x_idx{0}; int m_y_idx{0};