Skip to content

Commit

Permalink
Merge pull request #326 from eic/dmitry-matching
Browse files Browse the repository at this point in the history
Catch tracking exceptions, report warning, skip event
  • Loading branch information
DraTeots authored Nov 10, 2022
2 parents e392e39 + 24895b0 commit 541acf0
Show file tree
Hide file tree
Showing 29 changed files with 1,088 additions and 2,538 deletions.
4 changes: 2 additions & 2 deletions docs/table_flags/flags.in.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="tabs">
<div class="tab">
<input type="radio" id="tab1" name="tab-group" checked>
<label for="tab1" class="tab-title">Dump flags</label>
<label for="tab1" class="tab-title">EICrecon flags</label>
<section class="tab-content">
<table id="myTable" class="table_flags">
<thead>
Expand All @@ -27,7 +27,7 @@
</div>
<div class="tab">
<input type="radio" id="tab2" name="tab-group">
<label for="tab2" class="tab-title">User flags</label>
<label for="tab2" class="tab-title">reco_flags.py</label>
<section class="tab-content">
<table id="myTable2" class="table_flags">
<thead>
Expand Down
12 changes: 6 additions & 6 deletions docs/table_flags/flags.md

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions src/algorithms/tracking/TrackerSourceLinker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ eicrecon::TrackerSourceLinkerResult *eicrecon::TrackerSourceLinker::produce(std:
const auto* vol_ctx = m_cellid_converter->findContext(hit->getCellID());
auto vol_id = vol_ctx->identifier;


auto surfaceMap = m_acts_context->surfaceMap();

m_log->trace("Hit preparation information: {}", hit_index);
Expand All @@ -75,16 +76,25 @@ eicrecon::TrackerSourceLinkerResult *eicrecon::TrackerSourceLinker::produce(std:

auto& hit_pos = hit->getPosition();

// transform global position into local coordinates
// geometry context contains nothing here
Acts::Vector2 pos = surface->globalToLocal(
Acts::GeometryContext(),
{hit_pos.x, hit_pos.y, hit_pos.z},
{0, 0, 0}).value();
Acts::Vector2 loc = Acts::Vector2::Zero();
Acts::Vector2 pos;
try {
// transform global position into local coordinates
// geometry context contains nothing here
pos = surface->globalToLocal(
Acts::GeometryContext(),
{hit_pos.x, hit_pos.y, hit_pos.z},
{0, 0, 0}).value();

loc[Acts::eBoundLoc0] = pos[0];
loc[Acts::eBoundLoc1] = pos[1];
}
catch(std::exception &ex) {

Acts::Vector2 loc = Acts::Vector2::Zero();
loc[Acts::eBoundLoc0] = pos[0];
loc[Acts::eBoundLoc1] = pos[1];
m_log->warn("Can't convert globalToLocal for hit: vol_id={} det_id={} CellID={} x={} y={} z={}",
vol_id, hit->getCellID()&0xFF, hit->getCellID(), hit_pos.x, hit_pos.y, hit_pos.z);
continue;
}

if (m_log->level() <= spdlog::level::trace) {
auto volman = m_acts_context->dd4hepDetector()->volumeManager();
Expand Down
9 changes: 9 additions & 0 deletions src/extensions/jana/JChainFactoryT.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <vector>

#include <JANA/JFactoryT.h>
#include "extensions/string/StringHelpers.h"


/// This struct might be used for factories that has no underlying config class
Expand Down Expand Up @@ -64,6 +65,14 @@ class JChainFactoryT : public JFactoryT<OutT> {
/// Gets config
ConfigT& GetDefaultConfig() { return m_default_cfg; }

/// Get default prefix name
std::string GetDefaultParameterPrefix() {
std::string plugin_name = eicrecon::str::ReplaceAll(this->GetPluginName(), ".so", "");
std::string param_prefix = plugin_name+ ":" + this->GetTag();
return std::move(param_prefix);
}


protected:

/// Underlying algorithm config
Expand Down
13 changes: 8 additions & 5 deletions src/global/reco/MatchClusters_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ namespace eicrecon {
// }
}

auto result = m_match_algo.execute(mc_particles,
charged_prt_with_assoc->particles(),
charged_prt_with_assoc->associations(),
input_cluster_vectors,
input_cluster_assoc);



// auto result = m_match_algo.execute(mc_particles,
// charged_prt_with_assoc->particles(),
// charged_prt_with_assoc->associations(),
// input_cluster_vectors,
// input_cluster_assoc);

//std::vector<edm4eic::ReconstructedParticle*> result;
// for(size_t i=0; i < tracking_data->particles()->size(); i++) {
Expand Down
25 changes: 18 additions & 7 deletions src/global/tracking/CKFTracking_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void eicrecon::CKFTracking_factory::Process(const std::shared_ptr<const JEvent>

// Collect all hits
auto source_linker_result = event->GetSingle<eicrecon::TrackerSourceLinkerResult>(input_tag);

if(!source_linker_result) {
m_log->warn("TrackerSourceLinkerResult is null (hasn't been produced?). Skipping tracking for the whole event!");
return;
}

auto track_parameters = event->Get<Jug::TrackParameters>("InitTrackParams");
Jug::TrackParametersContainer acts_track_params;
for(auto track_params_item: track_parameters) {
Expand Down Expand Up @@ -83,14 +89,19 @@ void eicrecon::CKFTracking_factory::Process(const std::shared_ptr<const JEvent>
m_log->debug("Measurements count: {}", source_linker_result->measurements->size());
m_log->debug("Diving into tracking...");

// RUN TRACKING ALGORITHM
auto trajectories = m_tracking_algo.process(
source_links,
*source_linker_result->measurements,
acts_track_params);
try {
// RUN TRACKING ALGORITHM
auto trajectories = m_tracking_algo.process(
source_links,
*source_linker_result->measurements,
acts_track_params);

// Save the result
Set(trajectories);
// Save the result
Set(trajectories);
}
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}

// Enable ticker back
GetApplication()->SetTicker(tickerEnabled);
Expand Down
45 changes: 25 additions & 20 deletions src/global/tracking/ParticlesWithTruthPID_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,32 @@ namespace eicrecon {
auto mc_particles = event->Get<edm4hep::MCParticle>(GetInputTags()[0]);
auto track_params = event->Get<edm4eic::TrackParameters>(GetInputTags()[1]);

// Set indexes for MCParticles. Evil, Evil, Evil is here. TODO remove ASAP
for(size_t i=0; i< mc_particles.size(); i++) {
// Dirty hacks begun! Mutate army of mutant particles because of PODIO mudagen
auto * mc_particle = const_cast<edm4hep::MCParticle*>(mc_particles[i]);

// Nothing is private in this world anymore!
auto obj = ACCESS(*mc_particle, m_obj);
obj->id.index = (int)i; // Change!
try {
// Set indexes for MCParticles. Evil, Evil, Evil is here. TODO remove ASAP
for (size_t i = 0; i < mc_particles.size(); i++) {
// Dirty hacks begun! Mutate army of mutant particles because of PODIO mudagen
auto *mc_particle = const_cast<edm4hep::MCParticle *>(mc_particles[i]);

// Nothing is private in this world anymore!
auto obj = ACCESS(*mc_particle, m_obj);
obj->id.index = (int) i; // Change!
}

// Set indexes for TrackParameters. Evil, Evil, Evil is here. TODO remove ASAP
for (size_t i = 0; i < track_params.size(); i++) {
// Dirty hacks begun! Mutate army of mutant tracks because of PODIO mudagen
auto *track_param = const_cast<edm4eic::TrackParameters *>(track_params[i]);

// Nothing is private in this world anymore!
auto obj = ACCESS(*track_param, m_obj);
obj->id.index = (int) i; // Change!
}

auto result = m_matching_algo.process(mc_particles, track_params);
Insert(result);
}

// Set indexes for TrackParameters. Evil, Evil, Evil is here. TODO remove ASAP
for(size_t i=0; i< track_params.size(); i++) {
// Dirty hacks begun! Mutate army of mutant tracks because of PODIO mudagen
auto * track_param = const_cast<edm4eic::TrackParameters*>(track_params[i]);

// Nothing is private in this world anymore!
auto obj = ACCESS(*track_param, m_obj);
obj->id.index = (int)i; // Change!
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}

auto result = m_matching_algo.process(mc_particles, track_params);
Insert(result);
}
} // eicrecon
78 changes: 29 additions & 49 deletions src/global/tracking/TrackParamTruthInit_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,12 @@

void eicrecon::TrackParamTruthInit_factory::Init() {
// This prefix will be used for parameters
std::string plugin_name = eicrecon::str::ReplaceAll(GetPluginName(), ".so", "");
std::string param_prefix = plugin_name+ ":" + GetTag();
std::string param_prefix = GetDefaultParameterPrefix();

// Create plugin level sub-log
m_log = spdlog::stdout_color_mt("TrackParamTruthInit_factory");

// Ask service locator for parameter manager. We want to get this plugin parameters.
auto pm = this->GetApplication()->GetJParameterManager();

pm->SetDefaultParameter(param_prefix + ":verbose", m_verbose, "verbosity: 0 - none, 1 - default, 2 - debug, 3 - trace");
pm->SetDefaultParameter(param_prefix + ":input_tags", m_input_tags, "Input data tag name");



// This level will work for this plugin only
switch (m_verbose) {
case 0:
m_log->set_level(spdlog::level::warn); break;
case 2:
m_log->set_level(spdlog::level::debug); break;
case 3:
m_log->set_level(spdlog::level::trace); break;
default:
m_log->set_level(spdlog::level::info); break;
}
InitLogger(param_prefix);
InitDataTags(param_prefix);

// Initialize underlying algorithm
m_truth_track_seeding_algo.init(m_log);
}

Expand All @@ -50,39 +30,39 @@ void eicrecon::TrackParamTruthInit_factory::ChangeRun(const std::shared_ptr<cons
}

void eicrecon::TrackParamTruthInit_factory::Process(const std::shared_ptr<const JEvent> &event) {
// Now we check that user provided an input names
std::vector<std::string> &input_tags = m_input_tags;
if(input_tags.empty()) {
input_tags = GetDefaultInputTags();
}

// Get MCParticles
auto mc_particles = event->Get<edm4hep::MCParticle>(input_tags[0]);
auto mc_particles = event->Get<edm4hep::MCParticle>(GetInputTags()[0]);

// Produce track parameters out of MCParticles
std::vector<Jug::TrackParameters*> results;
for(auto mc_particle: mc_particles) {
try {
// Produce track parameters out of MCParticles
std::vector<Jug::TrackParameters *> results;
for (auto mc_particle: mc_particles) {

// Only stable particles from MC
if(mc_particle->getGeneratorStatus() != 1 ) continue;
// Only stable particles from MC
if (mc_particle->getGeneratorStatus() != 1) continue;

// Do conversion
auto result = m_truth_track_seeding_algo.produce(mc_particle);
// Do conversion
auto result = m_truth_track_seeding_algo.produce(mc_particle);

if(!result) continue; // result might be null
if (!result) continue; // result might be null

results.push_back(result);
results.push_back(result);

// >oO debug output
if(m_log->level() <= spdlog::level::debug) {
const auto p = std::hypot(mc_particle->getMomentum().x, mc_particle->getMomentum().y, mc_particle->getMomentum().z);
const auto charge = result->charge();
m_log->debug("Invoke track finding seeded by truth particle with:");
m_log->debug(" p = {} GeV\"", p);
m_log->debug(" charge = {}", charge);
m_log->debug(" q/p = {}", charge / p);
// >oO debug output
if (m_log->level() <= spdlog::level::debug) {
const auto p = std::hypot(mc_particle->getMomentum().x, mc_particle->getMomentum().y,
mc_particle->getMomentum().z);
const auto charge = result->charge();
m_log->debug("Invoke track finding seeded by truth particle with:");
m_log->debug(" p = {} GeV\"", p);
m_log->debug(" charge = {}", charge);
m_log->debug(" q/p = {}", charge / p);
}
}
Set(results);
}
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}

Set(results);
}
12 changes: 4 additions & 8 deletions src/global/tracking/TrackParamTruthInit_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
#define EICRECON_TrackParamTruthInit_factory_H

#include <spdlog/spdlog.h>
#include "extensions/jana/JChainFactoryT.h"
#include <extensions/jana/JChainFactoryT.h>
#include <extensions/spdlog/SpdlogMixin.h>

#include <algorithms/tracking/TrackParamTruthInit.h>



namespace eicrecon {

class TrackParamTruthInit_factory : public JChainFactoryT<Jug::TrackParameters> {
class TrackParamTruthInit_factory : public JChainFactoryT<Jug::TrackParameters>,
public SpdlogMixin<TrackParamTruthInit_factory> {

public:
TrackParamTruthInit_factory( std::vector<std::string> default_input_tags):
Expand All @@ -32,13 +34,7 @@ class TrackParamTruthInit_factory : public JChainFactoryT<Jug::TrackParameters>

private:

std::shared_ptr<spdlog::logger> m_log; /// Logger for this factory

int m_verbose; /// verbosity 0-none, 1-default, 2-debug, 3-trace
std::vector<std::string> m_input_tags; /// Tag for the input data

eicrecon::TrackParamTruthInit m_truth_track_seeding_algo; /// Truth track seeding algorithm

};

} // eicrecon
Expand Down
16 changes: 11 additions & 5 deletions src/global/tracking/TrackParameters_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ namespace eicrecon {

void TrackParameters_factory::Process(const std::shared_ptr<const JEvent> &event) {
auto tracking_data = event->GetSingle<ParticlesFromTrackFitResult>("CentralTrackingParticles");
std::vector<edm4eic::TrackParameters*> result;
for(size_t i=0; i < tracking_data->trackParameters()->size(); i++) {
auto track_params = (*tracking_data->trackParameters())[i];
result.push_back(new edm4eic::TrackParameters(track_params));

try {
std::vector<edm4eic::TrackParameters *> result;
for (size_t i = 0; i < tracking_data->trackParameters()->size(); i++) {
auto track_params = (*tracking_data->trackParameters())[i];
result.push_back(new edm4eic::TrackParameters(track_params));
}
Set(result);
}
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}
Set(result);
}
} // eicrecon
17 changes: 10 additions & 7 deletions src/global/tracking/TrackProjector_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
namespace eicrecon {
void TrackProjector_factory::Init() {
// This prefix will be used for parameters
std::string plugin_name = eicrecon::str::ReplaceAll(GetPluginName(), ".so", "");
std::string param_prefix = plugin_name+ ":" + GetTag();
std::string param_prefix = GetDefaultParameterPrefix();

// Set input data tags properly
InitDataTags(param_prefix);

// SpdlogMixin logger initialization, sets m_log
InitLogger(param_prefix, "info");
InitLogger(param_prefix);

auto acts_service = GetApplication()->GetService<ACTSGeo_service>();

Expand All @@ -33,11 +32,15 @@ namespace eicrecon {
void TrackProjector_factory::Process(const std::shared_ptr<const JEvent> &event) {
// Now we check that user provided an input names
std::string input_tag = GetInputTags()[0];

// Collect all hits
auto trajectories = event->Get<Jug::Trajectories>(input_tag);
auto result = m_track_projector_algo.execute(trajectories);
Set(result);

try {
auto result = m_track_projector_algo.execute(trajectories);
Set(result);
}
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}
}

} // eicrecon
Loading

0 comments on commit 541acf0

Please sign in to comment.