Skip to content

Commit f55aff7

Browse files
jmcarcelltmadlener
andauthored
Add a Link collection to the tests (#283)
Co-authored-by: jmcarcell <[email protected]> Co-authored-by: Thomas Madlener <[email protected]>
1 parent 3bc1997 commit f55aff7

13 files changed

+183
-38
lines changed

Diff for: test/k4FWCoreTest/options/ExampleFunctionalConsumerRuntimeCollectionsMultiple.py

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
OutputCollectionTrackerHits=["TrackerHits0"],
3939
OutputCollectionTracks=["Tracks0"],
4040
OutputCollectionRecoParticles=["Recos0"],
41+
OutputCollectionLinks=["Links0"],
4142
ExampleInt=5,
4243
)
4344
producer1 = ExampleFunctionalProducerMultiple(
@@ -49,6 +50,7 @@
4950
OutputCollectionTrackerHits=["TrackerHits1"],
5051
OutputCollectionTracks=["Tracks1"],
5152
OutputCollectionRecoParticles=["Recos1"],
53+
OutputCollectionLinks=["Links1"],
5254
ExampleInt=5,
5355
)
5456
producer2 = ExampleFunctionalProducerMultiple(
@@ -60,6 +62,7 @@
6062
OutputCollectionTrackerHits=["TrackerHits2"],
6163
OutputCollectionTracks=["Tracks2"],
6264
OutputCollectionRecoParticles=["Recos2"],
65+
OutputCollectionLinks=["Links2"],
6366
ExampleInt=5,
6467
)
6568

Diff for: test/k4FWCoreTest/options/ExampleFunctionalMultipleMemory.py

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
InputCollectionSimTrackerHits=["SimTrackerHits"],
5151
InputCollectionTrackerHits=["TrackerHits"],
5252
InputCollectionTracks=["Tracks"],
53+
InputCollectionLinks=["NewLinks"],
5354
Offset=10,
5455
)
5556

Diff for: test/k4FWCoreTest/options/ExampleFunctionalOutputCommands.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"drop Tracks",
3232
"drop Counter",
3333
"drop NewMCParticles",
34+
"drop NewLinks",
3435
]
3536

3637
transformer = ExampleFunctionalTransformerMultiple(

Diff for: test/k4FWCoreTest/options/ExampleFunctionalTransformerRuntimeCollectionsMultiple.py

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
OutputCollectionTrackerHits=["TrackerHits0"],
4040
OutputCollectionTracks=["Tracks0"],
4141
OutputCollectionRecoParticles=["Recos0"],
42+
OutputCollectionLinks=["Links0"],
4243
ExampleInt=5,
4344
)
4445
producer1 = ExampleFunctionalProducerMultiple(
@@ -50,6 +51,7 @@
5051
OutputCollectionTrackerHits=["TrackerHits1"],
5152
OutputCollectionTracks=["Tracks1"],
5253
OutputCollectionRecoParticles=["Recos1"],
54+
OutputCollectionLinks=["Links1"],
5355
ExampleInt=5,
5456
)
5557
producer2 = ExampleFunctionalProducerMultiple(
@@ -61,6 +63,7 @@
6163
OutputCollectionTrackerHits=["TrackerHits2"],
6264
OutputCollectionTracks=["Tracks2"],
6365
OutputCollectionRecoParticles=["Recos2"],
66+
OutputCollectionLinks=["Links2"],
6467
ExampleInt=5,
6568
)
6669

@@ -75,6 +78,8 @@
7578
],
7679
InputCollectionTrackerHits=["TrackerHits0", "TrackerHits1", "TrackerHits2"],
7780
InputCollectionTracks=["Tracks0", "Tracks1", "Tracks2"],
81+
InputCollectionRecoParticles=["Recos0", "Recos1", "Recos2"],
82+
InputCollectionLinks=["Links0", "Links1", "Links2"],
7883
OutputCollectionFloat=["NewVectorFloat0", "NewVectorFloat1", "NewVectorFloat2"],
7984
OutputCollectionParticles1=[
8085
"NewMCParticles0",
@@ -95,6 +100,8 @@
95100
"NewTrackerHits2",
96101
],
97102
OutputCollectionTracks=["NewTracks0", "NewTracks1", "NewTracks2"],
103+
OutputCollectionRecos=["NewRecos0", "NewRecos1", "NewRecos2"],
104+
OutputCollectionLinks=["NewLinks0", "NewLinks1", "NewLinks2"],
98105
Offset=0,
99106
)
100107

@@ -105,6 +112,9 @@
105112
InputCollectionSimTrackerHits=["NewSimTrackerHits0"],
106113
InputCollectionTrackerHits=["NewTrackerHits0"],
107114
InputCollectionTracks=["NewTracks0"],
115+
InputCollectionRecoParticles=["NewRecos0"],
116+
InputCollectionLinks=["NewLinks0"],
117+
Offset=0,
108118
)
109119

110120
consumer1 = ExampleFunctionalConsumerMultiple(
@@ -114,6 +124,9 @@
114124
InputCollectionSimTrackerHits=["NewSimTrackerHits1"],
115125
InputCollectionTrackerHits=["NewTrackerHits1"],
116126
InputCollectionTracks=["NewTracks1"],
127+
InputCollectionRecoParticles=["NewRecos1"],
128+
InputCollectionLinks=["NewLinks1"],
129+
Offset=0,
117130
)
118131

119132
consumer2 = ExampleFunctionalConsumerMultiple(
@@ -123,6 +136,9 @@
123136
InputCollectionSimTrackerHits=["NewSimTrackerHits2"],
124137
InputCollectionTrackerHits=["NewTrackerHits2"],
125138
InputCollectionTracks=["NewTracks2"],
139+
InputCollectionRecoParticles=["NewRecos2"],
140+
InputCollectionLinks=["NewLinks2"],
141+
Offset=0,
126142
)
127143

128144

Diff for: test/k4FWCoreTest/options/TwoProducers.py

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
producer2.simtrackhits.Path = "simtrackhits2"
4646
producer2.tracks.Path = "tracks2"
4747
producer2.vectorfloat.Path = "vectorfloat2"
48+
producer2.recoparticles.Path = "recoparticles2"
49+
producer2.links.Path = "links"
4850
ApplicationMgr().TopAlg += [producer2]
4951

5052

Diff for: test/k4FWCoreTest/options/runFunctionalMix.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"SimTrackerHits",
5858
"TrackerHits",
5959
"Tracks",
60+
"RecoParticles",
61+
"Links",
6062
]
6163

6264
out = PodioOutput()
@@ -91,16 +93,18 @@
9193
OutputCollectionTrackerHits=["FunctionalTrackerHits"],
9294
OutputCollectionTracks=["FunctionalTracks"],
9395
OutputCollectionRecoParticles=["FunctionalRecos"],
96+
OutputCollectionLinks=["FunctionalLinks"],
9497
ExampleInt=5,
9598
)
9699

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

99-
# Here we check the new FunctionalMCParticles and the others that are
100-
# read from the file
102+
# Here we check a few new classes and others that are read from the file
101103
consumer_producerfun_functional = ExampleFunctionalConsumerMultiple(
102104
"FunctionalConsumerFromFunctional",
103105
InputCollectionParticles=["FunctionalMCParticles"],
106+
InputCollectionRecoParticles=["FunctionalRecos"],
107+
InputCollectionLinks=["FunctionalLinks"],
104108
Offset=0,
105109
)
106110
consumer_producerfun_algorithm = k4FWCoreTest_CheckExampleEventData(
@@ -118,12 +122,16 @@
118122
producer_algorithm.trackhits = "OldAlgorithmTrackerHits"
119123
producer_algorithm.tracks = "OldAlgorithmTracks"
120124
producer_algorithm.vectorfloat = "OldAlgorithmVectorFloat"
125+
producer_algorithm.recoparticles = "OldAlgorithmRecoParticles"
126+
producer_algorithm.links = "OldAlgorithmLinks"
121127

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

124130
consumer_produceralg_functional = ExampleFunctionalConsumerMultiple(
125131
"FunctionalConsumerFromAlgorithm",
126132
InputCollectionParticles=["OldAlgorithmMCParticles"],
133+
InputCollectionRecoParticles=["OldAlgorithmRecoParticles"],
134+
InputCollectionLinks=["OldAlgorithmLinks"],
127135
Offset=0,
128136
)
129137
consumer_produceralg_algorithm = k4FWCoreTest_CheckExampleEventData("CheckAlgorithm")

Diff for: test/k4FWCoreTest/scripts/CheckOutputFiles.py

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def check_metadata(filename, expected_metadata):
8484
"Counter",
8585
"NewMCParticles",
8686
"RecoParticles",
87+
"Links",
88+
"NewLinks",
8789
],
8890
)
8991
check_collections(
@@ -95,6 +97,7 @@ def check_metadata(filename, expected_metadata):
9597
"SimTrackerHits",
9698
"TrackerHits",
9799
"RecoParticles",
100+
"Links",
98101
],
99102
)
100103
check_collections("/tmp/a/b/c/functional_producer.root", ["MCParticles"])
@@ -113,6 +116,7 @@ def check_metadata(filename, expected_metadata):
113116
"Tracks",
114117
"NewMCParticles",
115118
"RecoParticles",
119+
"Links",
116120
],
117121
)
118122

@@ -126,6 +130,7 @@ def check_metadata(filename, expected_metadata):
126130
"TrackerHits",
127131
"Tracks",
128132
"RecoParticles",
133+
"Links",
129134
# Produced by functional
130135
"FunctionalVectorFloat",
131136
"FunctionalMCParticles",
@@ -134,15 +139,19 @@ def check_metadata(filename, expected_metadata):
134139
"FunctionalTrackerHits",
135140
"FunctionalTracks",
136141
"FunctionalRecos",
142+
"FunctionalLinks",
137143
# Produced by an old algorithm
138144
"OldAlgorithmMCParticles",
139145
"OldAlgorithmSimTrackerHits",
140146
"OldAlgorithmTrackerHits",
141147
"OldAlgorithmTracks",
142148
"OldAlgorithmVectorFloat",
149+
"OldAlgorithmRecoParticles",
150+
"OldAlgorithmLinks",
143151
# Produced by the last transformer
144152
"Counter",
145153
"TransformedFunctionalMCParticles1",
154+
"NewLinks",
146155
]
147156

148157

Diff for: test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "Gaudi/Property.h"
2121

2222
#include "edm4hep/MCParticleCollection.h"
23+
#include "edm4hep/RecoMCParticleLinkCollection.h"
24+
#include "edm4hep/ReconstructedParticleCollection.h"
2325
#include "edm4hep/SimTrackerHitCollection.h"
2426
#include "edm4hep/TrackCollection.h"
2527
#include "edm4hep/TrackerHit3DCollection.h"
@@ -37,10 +39,12 @@ using ParticleColl = edm4hep::MCParticleCollection;
3739
using SimTrackerHitColl = edm4hep::SimTrackerHitCollection;
3840
using TrackerHitColl = edm4hep::TrackerHit3DCollection;
3941
using TrackColl = edm4hep::TrackCollection;
42+
using RecoColl = edm4hep::ReconstructedParticleCollection;
43+
using LinkColl = edm4hep::RecoMCParticleLinkCollection;
4044

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

5662
// This is the function that will be called to transform the data
5763
// Note that the function has to be const, as well as the collections
5864
// we get from the input
5965
void operator()(const FloatColl& floatVector, const ParticleColl& particles, const SimTrackerHitColl& simTrackerHits,
60-
const TrackerHitColl& trackerHits, const TrackColl& tracks) const override {
66+
const TrackerHitColl& trackerHits, const TrackColl& tracks, const RecoColl& recos,
67+
const LinkColl& links) const override {
6168
if (floatVector.size() != 3) {
6269
throw std::runtime_error("Wrong size of floatVector collection, expected 3, got " +
6370
std::to_string(floatVector.size()) + "");
@@ -107,6 +114,15 @@ struct ExampleFunctionalConsumerMultiple final
107114
<< tracks[0].getChi2() << ", " << tracks[0].getNdf();
108115
throw std::runtime_error(error.str());
109116
}
117+
118+
for (size_t j = 0; j < links.size(); j++) {
119+
if (links[j].getFrom() != recos[j] || links[j].getTo() != particles[j]) {
120+
std::stringstream error;
121+
error << "Wrong data in links collection, link" << j << " expected " << recos[j].id() << ", "
122+
<< particles[j].id() << " got " << links[j].getFrom().id() << ", " << links[j].getTo().id();
123+
throw std::runtime_error(error.str());
124+
}
125+
}
110126
}
111127

112128
private:

Diff for: test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "k4FWCore/Producer.h"
2323

2424
#include "edm4hep/MCParticleCollection.h"
25+
#include "edm4hep/RecoMCParticleLinkCollection.h"
2526
#include "edm4hep/ReconstructedParticleCollection.h"
2627
#include "edm4hep/SimTrackerHitCollection.h"
2728
#include "edm4hep/TrackCollection.h"
@@ -35,7 +36,7 @@
3536
using retType =
3637
std::tuple<podio::UserDataCollection<float>, edm4hep::MCParticleCollection, edm4hep::MCParticleCollection,
3738
edm4hep::SimTrackerHitCollection, edm4hep::TrackerHit3DCollection, edm4hep::TrackCollection,
38-
edm4hep::ReconstructedParticleCollection>;
39+
edm4hep::ReconstructedParticleCollection, edm4hep::RecoMCParticleLinkCollection>;
3940

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

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

6365
auto particles = edm4hep::MCParticleCollection();
6466
edm4hep::Vector3d v{0, 0, 0};
65-
particles.create(1, 2, 3, 4.f, 5.f, 6.f, v, v, v);
66-
particles.create(2, 3, 4, 5.f, 6.f, 7.f);
67+
auto part1 = particles.create(1, 2, 3, 4.f, 5.f, 6.f, v, v, v);
68+
auto part2 = particles.create(2, 3, 4, 5.f, 6.f, 7.f);
6769

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

9092
auto recos = edm4hep::ReconstructedParticleCollection();
91-
for (int i = 1; i < 5; ++i) {
93+
for (int i = 0; i < 5; ++i) {
9294
auto reco = recos.create();
9395
reco.setPDG(i);
9496
}
9597

98+
auto links = edm4hep::RecoMCParticleLinkCollection();
99+
for (size_t i = 0; i < 2; ++i) {
100+
auto link = links.create();
101+
link.setFrom(recos[i]);
102+
link.setTo(particles[i]);
103+
}
104+
96105
return std::make_tuple(std::move(floatVector), std::move(particles), edm4hep::MCParticleCollection(),
97-
std::move(simTrackerHits), std::move(trackerHits), std::move(tracks), std::move(recos));
106+
std::move(simTrackerHits), std::move(trackerHits), std::move(tracks), std::move(recos),
107+
std::move(links));
98108
}
99109

100110
private:

0 commit comments

Comments
 (0)