Skip to content

Commit

Permalink
Add a Link collection to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Feb 4, 2025
1 parent 28beeb7 commit 4150f13
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
OutputCollectionTrackerHits=["TrackerHits0"],
OutputCollectionTracks=["Tracks0"],
OutputCollectionRecoParticles=["Recos0"],
OutputCollectionLinks=["Links0"],
ExampleInt=5,
)
producer1 = ExampleFunctionalProducerMultiple(
Expand All @@ -49,6 +50,7 @@
OutputCollectionTrackerHits=["TrackerHits1"],
OutputCollectionTracks=["Tracks1"],
OutputCollectionRecoParticles=["Recos1"],
OutputCollectionLinks=["Links1"],
ExampleInt=5,
)
producer2 = ExampleFunctionalProducerMultiple(
Expand All @@ -60,6 +62,7 @@
OutputCollectionTrackerHits=["TrackerHits2"],
OutputCollectionTracks=["Tracks2"],
OutputCollectionRecoParticles=["Recos2"],
OutputCollectionLinks=["Links2"],
ExampleInt=5,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
InputCollectionSimTrackerHits=["SimTrackerHits"],
InputCollectionTrackerHits=["TrackerHits"],
InputCollectionTracks=["Tracks"],
InputCollectionLinks=["NewLinks"],
Offset=10,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"drop Tracks",
"drop Counter",
"drop NewMCParticles",
"drop NewLinks",
]

transformer = ExampleFunctionalTransformerMultiple(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
OutputCollectionTrackerHits=["TrackerHits0"],
OutputCollectionTracks=["Tracks0"],
OutputCollectionRecoParticles=["Recos0"],
OutputCollectionLinks=["Links0"],
ExampleInt=5,
)
producer1 = ExampleFunctionalProducerMultiple(
Expand All @@ -50,6 +51,7 @@
OutputCollectionTrackerHits=["TrackerHits1"],
OutputCollectionTracks=["Tracks1"],
OutputCollectionRecoParticles=["Recos1"],
OutputCollectionLinks=["Links1"],
ExampleInt=5,
)
producer2 = ExampleFunctionalProducerMultiple(
Expand All @@ -61,6 +63,7 @@
OutputCollectionTrackerHits=["TrackerHits2"],
OutputCollectionTracks=["Tracks2"],
OutputCollectionRecoParticles=["Recos2"],
OutputCollectionLinks=["Links2"],
ExampleInt=5,
)

Expand All @@ -75,6 +78,8 @@
],
InputCollectionTrackerHits=["TrackerHits0", "TrackerHits1", "TrackerHits2"],
InputCollectionTracks=["Tracks0", "Tracks1", "Tracks2"],
InputCollectionRecoParticles=["Recos0", "Recos1", "Recos2"],
InputCollectionLinks=["Links0", "Links1", "Links2"],
OutputCollectionFloat=["NewVectorFloat0", "NewVectorFloat1", "NewVectorFloat2"],
OutputCollectionParticles1=[
"NewMCParticles0",
Expand All @@ -95,6 +100,8 @@
"NewTrackerHits2",
],
OutputCollectionTracks=["NewTracks0", "NewTracks1", "NewTracks2"],
OutputCollectionRecos=["NewRecos0", "NewRecos1", "NewRecos2"],
OutputCollectionLinks=["NewLinks0", "NewLinks1", "NewLinks2"],
Offset=0,
)

Expand All @@ -105,6 +112,9 @@
InputCollectionSimTrackerHits=["NewSimTrackerHits0"],
InputCollectionTrackerHits=["NewTrackerHits0"],
InputCollectionTracks=["NewTracks0"],
InputCollectionRecoParticles=["NewRecos0"],
InputCollectionLinks=["NewLinks0"],
Offset=0,
)

consumer1 = ExampleFunctionalConsumerMultiple(
Expand All @@ -114,6 +124,9 @@
InputCollectionSimTrackerHits=["NewSimTrackerHits1"],
InputCollectionTrackerHits=["NewTrackerHits1"],
InputCollectionTracks=["NewTracks1"],
InputCollectionRecoParticles=["NewRecos1"],
InputCollectionLinks=["NewLinks1"],
Offset=0,
)

consumer2 = ExampleFunctionalConsumerMultiple(
Expand All @@ -123,6 +136,9 @@
InputCollectionSimTrackerHits=["NewSimTrackerHits2"],
InputCollectionTrackerHits=["NewTrackerHits2"],
InputCollectionTracks=["NewTracks2"],
InputCollectionRecoParticles=["NewRecos2"],
InputCollectionLinks=["NewLinks2"],
Offset=0,
)


Expand Down
2 changes: 2 additions & 0 deletions test/k4FWCoreTest/options/TwoProducers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
producer2.simtrackhits.Path = "simtrackhits2"
producer2.tracks.Path = "tracks2"
producer2.vectorfloat.Path = "vectorfloat2"
producer2.recoparticles.Path = "recoparticles2"
producer2.links.Path = "links"
ApplicationMgr().TopAlg += [producer2]


Expand Down
12 changes: 10 additions & 2 deletions test/k4FWCoreTest/options/runFunctionalMix.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"SimTrackerHits",
"TrackerHits",
"Tracks",
"RecoParticles",
"Links",
]

out = PodioOutput()
Expand Down Expand Up @@ -91,16 +93,18 @@
OutputCollectionTrackerHits=["FunctionalTrackerHits"],
OutputCollectionTracks=["FunctionalTracks"],
OutputCollectionRecoParticles=["FunctionalRecos"],
OutputCollectionLinks=["FunctionalLinks"],
ExampleInt=5,
)

# Check the functional-produced collections with functional and old algorithms

# Here we check the new FunctionalMCParticles and the others that are
# read from the file
# Here we check a few new classes and others that are read from the file
consumer_producerfun_functional = ExampleFunctionalConsumerMultiple(
"FunctionalConsumerFromFunctional",
InputCollectionParticles=["FunctionalMCParticles"],
InputCollectionRecoParticles=["FunctionalRecos"],
InputCollectionLinks=["FunctionalLinks"],
Offset=0,
)
consumer_producerfun_algorithm = k4FWCoreTest_CheckExampleEventData(
Expand All @@ -118,12 +122,16 @@
producer_algorithm.trackhits = "OldAlgorithmTrackerHits"
producer_algorithm.tracks = "OldAlgorithmTracks"
producer_algorithm.vectorfloat = "OldAlgorithmVectorFloat"
producer_algorithm.recoparticles = "OldAlgorithmRecoParticles"
producer_algorithm.links = "OldAlgorithmLinks"

# Check the functional-produced collections with functional and old algorithms

consumer_produceralg_functional = ExampleFunctionalConsumerMultiple(
"FunctionalConsumerFromAlgorithm",
InputCollectionParticles=["OldAlgorithmMCParticles"],
InputCollectionRecoParticles=["OldAlgorithmRecoParticles"],
InputCollectionLinks=["OldAlgorithmLinks"],
Offset=0,
)
consumer_produceralg_algorithm = k4FWCoreTest_CheckExampleEventData("CheckAlgorithm")
Expand Down
9 changes: 9 additions & 0 deletions test/k4FWCoreTest/scripts/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def check_metadata(filename, expected_metadata):
"Counter",
"NewMCParticles",
"RecoParticles",
"Links",
"NewLinks",
],
)
check_collections(
Expand All @@ -95,6 +97,7 @@ def check_metadata(filename, expected_metadata):
"SimTrackerHits",
"TrackerHits",
"RecoParticles",
"Links",
],
)
check_collections("/tmp/a/b/c/functional_producer.root", ["MCParticles"])
Expand All @@ -113,6 +116,7 @@ def check_metadata(filename, expected_metadata):
"Tracks",
"NewMCParticles",
"RecoParticles",
"Links",
],
)

Expand All @@ -126,6 +130,7 @@ def check_metadata(filename, expected_metadata):
"TrackerHits",
"Tracks",
"RecoParticles",
"Links",
# Produced by functional
"FunctionalVectorFloat",
"FunctionalMCParticles",
Expand All @@ -134,15 +139,19 @@ def check_metadata(filename, expected_metadata):
"FunctionalTrackerHits",
"FunctionalTracks",
"FunctionalRecos",
"FunctionalLinks",
# Produced by an old algorithm
"OldAlgorithmMCParticles",
"OldAlgorithmSimTrackerHits",
"OldAlgorithmTrackerHits",
"OldAlgorithmTracks",
"OldAlgorithmVectorFloat",
"OldAlgorithmRecoParticles",
"OldAlgorithmLinks",
# Produced by the last transformer
"Counter",
"TransformedFunctionalMCParticles1",
"NewLinks",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "Gaudi/Property.h"

#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/RecoMCParticleLinkCollection.h"
#include "edm4hep/ReconstructedParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/TrackCollection.h"
#include "edm4hep/TrackerHit3DCollection.h"
Expand All @@ -37,10 +39,12 @@ using ParticleColl = edm4hep::MCParticleCollection;
using SimTrackerHitColl = edm4hep::SimTrackerHitCollection;
using TrackerHitColl = edm4hep::TrackerHit3DCollection;
using TrackColl = edm4hep::TrackCollection;
using RecoColl = edm4hep::ReconstructedParticleCollection;
using LinkColl = edm4hep::RecoMCParticleLinkCollection;

struct ExampleFunctionalConsumerMultiple final
: k4FWCore::Consumer<void(const FloatColl&, const ParticleColl&, const SimTrackerHitColl&, const TrackerHitColl&,
const TrackColl&)> {
const TrackColl&, const RecoColl&, const LinkColl&)> {
// The pairs in KeyValue can be changed from python and they correspond
// to the names of the input collections
ExampleFunctionalConsumerMultiple(const std::string& name, ISvcLocator* svcLoc)
Expand All @@ -51,13 +55,16 @@ struct ExampleFunctionalConsumerMultiple final
KeyValues("InputCollectionSimTrackerHits", {"SimTrackerHits"}),
KeyValues("InputCollectionTrackerHits", {"TrackerHits"}),
KeyValues("InputCollectionTracks", {"Tracks"}),
KeyValues("InputCollectionRecoParticles", {"RecoParticles"}),
KeyValues("InputCollectionLinks", {"Links"}),
}) {}

// This is the function that will be called to transform the data
// Note that the function has to be const, as well as the collections
// we get from the input
void operator()(const FloatColl& floatVector, const ParticleColl& particles, const SimTrackerHitColl& simTrackerHits,
const TrackerHitColl& trackerHits, const TrackColl& tracks) const override {
const TrackerHitColl& trackerHits, const TrackColl& tracks, const RecoColl& recos,
const LinkColl& links) const override {
if (floatVector.size() != 3) {
throw std::runtime_error("Wrong size of floatVector collection, expected 3, got " +
std::to_string(floatVector.size()) + "");
Expand Down Expand Up @@ -107,6 +114,15 @@ struct ExampleFunctionalConsumerMultiple final
<< tracks[0].getChi2() << ", " << tracks[0].getNdf();
throw std::runtime_error(error.str());
}

for (size_t j = 0; j < links.size(); j++) {
if (links[j].getFrom() != recos[j] || links[j].getTo() != particles[j]) {
std::stringstream error;
error << "Wrong data in links collection, link" << j << " expected " << recos[0] << ", " << particles[j]
<< " got " << links[j].getFrom() << ", " << links[j].getTo();
throw std::runtime_error(error.str());
}
}
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "k4FWCore/Producer.h"

#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/RecoMCParticleLinkCollection.h"
#include "edm4hep/ReconstructedParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/TrackCollection.h"
Expand All @@ -35,7 +36,7 @@
using retType =
std::tuple<podio::UserDataCollection<float>, edm4hep::MCParticleCollection, edm4hep::MCParticleCollection,
edm4hep::SimTrackerHitCollection, edm4hep::TrackerHit3DCollection, edm4hep::TrackCollection,
edm4hep::ReconstructedParticleCollection>;
edm4hep::ReconstructedParticleCollection, edm4hep::RecoMCParticleLinkCollection>;

struct ExampleFunctionalProducerMultiple final : k4FWCore::Producer<retType()> {
// The pairs in KeyValue can be changed from python and they correspond
Expand All @@ -48,7 +49,8 @@ struct ExampleFunctionalProducerMultiple final : k4FWCore::Producer<retType()> {
KeyValues("OutputCollectionParticles2", {"MCParticles2"}),
KeyValues("OutputCollectionSimTrackerHits", {"SimTrackerHits"}),
KeyValues("OutputCollectionTrackerHits", {"TrackerHits"}), KeyValues("OutputCollectionTracks", {"Tracks"}),
KeyValues("OutputCollectionRecoParticles", {"RecoParticles"})}) {}
KeyValues("OutputCollectionRecoParticles", {"RecoParticles"}),
KeyValues("OutputCollectionLinks", {"Links"})}) {}

// This is the function that will be called to produce the data
retType operator()() const override {
Expand All @@ -62,8 +64,8 @@ struct ExampleFunctionalProducerMultiple final : k4FWCore::Producer<retType()> {

auto particles = edm4hep::MCParticleCollection();
edm4hep::Vector3d v{0, 0, 0};
particles.create(1, 2, 3, 4.f, 5.f, 6.f, v, v, v);
particles.create(2, 3, 4, 5.f, 6.f, 7.f);
auto part1 = particles.create(1, 2, 3, 4.f, 5.f, 6.f, v, v, v);
auto part2 = particles.create(2, 3, 4, 5.f, 6.f, 7.f);

auto simTrackerHits = edm4hep::SimTrackerHitCollection();
auto hit = simTrackerHits.create();
Expand All @@ -88,13 +90,21 @@ struct ExampleFunctionalProducerMultiple final : k4FWCore::Producer<retType()> {
track.addToTracks(track2);

auto recos = edm4hep::ReconstructedParticleCollection();
for (int i = 1; i < 5; ++i) {
for (int i = 0; i < 5; ++i) {
auto reco = recos.create();
reco.setPDG(i);
}

auto links = edm4hep::RecoMCParticleLinkCollection();
for (size_t i = 0; i < 2; ++i) {
auto link = links.create();
link.setFrom(recos[i]);
link.setTo(particles[i]);
}

return std::make_tuple(std::move(floatVector), std::move(particles), edm4hep::MCParticleCollection(),
std::move(simTrackerHits), std::move(trackerHits), std::move(tracks), std::move(recos));
std::move(simTrackerHits), std::move(trackerHits), std::move(tracks), std::move(recos),
std::move(links));
}

private:
Expand Down
Loading

0 comments on commit 4150f13

Please sign in to comment.