Skip to content

Commit

Permalink
Merge branch 'main' into test-on-jug-xl-nightly-and-23.12-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
veprbl authored Apr 24, 2024
2 parents a662519 + e9b8248 commit bcd3e5e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 5 deletions.
82 changes: 82 additions & 0 deletions src/algorithms/meta/FilterMatching.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Simon Gardner

#pragma once

#include <spdlog/spdlog.h>
#include <algorithms/algorithm.h>
#include <string>
#include <string_view>

#include "services/log/Log_service.h"
#include "algorithms/interfaces/WithPodConfig.h"

namespace eicrecon {

template<class ToFilterObjectT, class FilterByObjectT>
using FilterMatchingAlgorithm = algorithms::Algorithm<
typename algorithms::Input<
typename ToFilterObjectT::collection_type,
typename FilterByObjectT::collection_type
>,
typename algorithms::Output<
typename ToFilterObjectT::collection_type,
typename ToFilterObjectT::collection_type
>
>;

/// Filters a collection by the members of another collection
/// The first collection is divided up into two collections where its elements either passed the filter or not
/// The second collection provides a filter
/// Functions need to be provided along with the collections to form the link between the data types
/// These functions are envisioned to link the objectIDs of the collection/associations but could be anything
template<typename ToFilterObjectT,auto ToFilterFunction, typename FilterByObjectT,auto FilterByFunction>
class FilterMatching : public FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT> {

public:
FilterMatching(std::string_view name)
: FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>{name,
{"inputCollection","inputMatchedCollection"},
{"outputMatchedAssociations","outputUnmatchedAssociations"},
"Filter by matching to a collection"
} {
};

void init() final { };

void process(const typename FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>::Input& input,
const typename FilterMatchingAlgorithm<ToFilterObjectT,ToFilterObjectT>::Output& output) const final{

const auto [toFilterEntries,filterByEntries] = input;
auto [is_matched,is_not_matched] = output;

is_matched->setSubsetCollection();
is_not_matched->setSubsetCollection();

for (const auto& matchedEntry : *toFilterEntries){

auto ref_value = ToFilterFunction(&matchedEntry);

bool found_match = false;

// Tries to find the association in the entries
for(const auto& entry : *filterByEntries){
auto other_value = FilterByFunction(&entry);
if(other_value == ref_value){
is_matched->push_back(matchedEntry);
found_match = true;
break;
}
}

if(!found_match){
is_not_matched->push_back(matchedEntry);
}

}

};

};

} // eicrecon
40 changes: 40 additions & 0 deletions src/factories/meta/FilterMatching_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Simon Gardner

#pragma once

#include "algorithms/meta/FilterMatching.h"
#include "extensions/jana/JOmniFactory.h"

namespace eicrecon {

template <typename ToFilterObjectT,auto ToFilterMemberFunctionPtr,typename FilterByObjectT,auto FilterByMemberFunctionPtr>
class FilterMatching_factory : public JOmniFactory<FilterMatching_factory<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>> {

public:
using AlgoT = eicrecon::FilterMatching<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>;
using FactoryT = JOmniFactory<FilterMatching_factory<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>>;

private:

std::unique_ptr<AlgoT> m_algo;

typename FactoryT::template PodioInput<ToFilterObjectT> m_collection_input {this};
typename FactoryT::template PodioInput<FilterByObjectT> m_matched_input {this};
typename FactoryT::template PodioOutput<ToFilterObjectT> m_is_matched_output {this};
typename FactoryT::template PodioOutput<ToFilterObjectT> m_is_not_matched_output {this};

public:
void Configure() {
m_algo = std::make_unique<AlgoT>(this->GetPrefix());
m_algo->init();
}

void ChangeRun(int64_t run_number) {
}

void Process(int64_t run_number, uint64_t event_number) {
m_algo->process({m_collection_input(),m_matched_input()},{m_is_matched_output().get(),m_is_not_matched_output().get()});
};
}; // FilterByAssociations_factory
} // eicrecon
4 changes: 2 additions & 2 deletions src/global/beam/beam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern "C" {
using namespace eicrecon;

// Divide MCParticle collection based on generator status and PDG
std::vector<std::string> outCollections{"BeamElectrons","BeamProtons"};
std::vector<std::vector<int>> values{{4,11},{4,2212}};
std::vector<std::string> outCollections{"MCBeamElectrons","MCBeamProtons","MCScatteredElectrons","MCScatteredProtons"};
std::vector<std::vector<int>> values{{4,11},{4,2212},{1,11},{1,2212}};

app->Add(new JOmniFactoryGeneratorT<SubDivideCollection_factory<edm4hep::MCParticle>>(
"BeamParticles",
Expand Down
15 changes: 14 additions & 1 deletion src/global/reco/reco.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <JANA/JApplication.h>
#include <edm4eic/Cluster.h>
#include <edm4eic/MCRecoClusterParticleAssociation.h>
#include <edm4eic/MCRecoParticleAssociation.h>
#include <edm4eic/ReconstructedParticle.h>
#include <edm4hep/MCParticle.h>
#include <algorithm>
#include <map>
#include <memory>
Expand All @@ -19,6 +21,7 @@
#include "algorithms/reco/InclusiveKinematicseSigma.h"
#include "extensions/jana/JOmniFactoryGeneratorT.h"
#include "factories/meta/CollectionCollector_factory.h"
#include "factories/meta/FilterMatching_factory.h"
#include "factories/reco/InclusiveKinematicsML_factory.h"
#include "factories/reco/InclusiveKinematicsReconstructed_factory.h"
#include "factories/reco/InclusiveKinematicsTruth_factory.h"
Expand All @@ -31,13 +34,23 @@
#include "global/reco/ScatteredElectronsEMinusPz_factory.h"
#include "global/reco/ScatteredElectronsTruth_factory.h"

//
extern "C" {
void InitPlugin(JApplication *app) {
InitJANAPlugin(app);

using namespace eicrecon;

// Finds associations matched to initial scattered electrons
app->Add(new JOmniFactoryGeneratorT<FilterMatching_factory< edm4eic::MCRecoParticleAssociation,
[](auto* obj) { return obj->getSim().getObjectID();},
edm4hep::MCParticle,
[](auto* obj) { return obj->getObjectID(); }>>(
"MCScatteredElectronAssociations",
{"ReconstructedChargedParticleAssociations","MCScatteredElectrons"},
{"MCScatteredElectronAssociations","MCNonScatteredElectronAssociations"},
app
));

app->Add(new JOmniFactoryGeneratorT<MC2SmearedParticle_factory>(
"GeneratedParticles",
{"MCParticles"},
Expand Down
8 changes: 6 additions & 2 deletions src/services/io/podio/JEventProcessorPODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ JEventProcessorPODIO::JEventProcessorPODIO() {

// Truth record
"MCParticles",
"BeamElectrons",
"BeamProtons",
"MCBeamElectrons",
"MCBeamProtons",
"MCScatteredElectrons",
"MCScatteredProtons",

// All tracking hits combined
"CentralTrackingRecHits",
Expand Down Expand Up @@ -125,6 +127,8 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
"ReconstructedChargedParticleAssociations",
"ReconstructedSeededChargedParticles",
"ReconstructedSeededChargedParticleAssociations",
"MCScatteredElectronAssociations", // Remove if/when used internally
"MCNonScatteredElectronAssociations", // Remove if/when used internally
"ReconstructedChargedParticleIDs",
"ReconstructedBreitFrameParticles",
"CentralTrackSegments",
Expand Down

0 comments on commit bcd3e5e

Please sign in to comment.