7#ifndef LAR_PANDORA_EVENT_H
8#define LAR_PANDORA_EVENT_H 1
12#include "lardataobj/AnalysisBase/T0.h"
14#include "lardataobj/RecoBase/Cluster.h"
15#include "lardataobj/RecoBase/Hit.h"
16#include "lardataobj/RecoBase/PCAxis.h"
17#include "lardataobj/RecoBase/PFParticle.h"
18#include "lardataobj/RecoBase/PFParticleMetadata.h"
19#include "lardataobj/RecoBase/Shower.h"
20#include "lardataobj/RecoBase/Slice.h"
21#include "lardataobj/RecoBase/SpacePoint.h"
22#include "lardataobj/RecoBase/Track.h"
23#include "lardataobj/RecoBase/TrackHitMeta.h"
24#include "lardataobj/RecoBase/Vertex.h"
29#include "art/Framework/Principal/Event.h"
30#include "art/Persistency/Common/PtrMaker.h"
31#include "canvas/Persistency/Common/Assns.h"
32#include "canvas/Persistency/Common/Ptr.h"
53 template <
typename R,
typename D>
54 using PairVector = std::vector<std::pair<art::Ptr<R>, D>>;
59 template <
typename L,
typename R,
typename D>
135 Labels(
const std::string& pfParticleProducerLabel,
const std::string& hitProducerLabel);
142 Labels(
const std::string& pfParticleProducerLabel,
143 const std::string& trackProducerLabel,
144 const std::string& showerProducerLabel,
145 const std::string& hitProducerLabel);
178 const Labels& inputLabels,
179 const bool shouldProduceT0s =
false);
207 template <
typename T>
217 template <
typename L,
typename R,
typename D>
229 template <
typename L,
typename R>
241 template <
typename L,
typename R,
typename D>
256 template <
typename L,
typename R,
typename D>
267 template <
typename T>
278 template <
typename L,
typename R,
typename D>
282 const bool thisProducesR =
true)
const;
292 template <
typename L,
typename R>
296 const bool thisProducesR =
true)
const;
306 template <
typename T>
355 template <
typename T>
361 for (
unsigned int i = 0; i != handle->size(); i++)
362 outputCollection.emplace_back(handle, i);
367 template <
typename L,
typename R,
typename D>
372 const auto& assocHandle(
376 for (
const auto& entry : *assocHandle) {
377 auto it(std::find(collectionL.begin(), collectionL.end(), entry.first));
378 if (it == collectionL.end())
379 throw cet::exception(
"LArPandora") <<
" LArPandoraEvent::GetAssociationMap -- Found object "
380 "in association that isn't in the supplied collection"
385 for (
const auto& objectL : collectionL)
386 outputAssociationMap[objectL];
389 for (
const auto& entry : *assocHandle)
390 outputAssociationMap.at(entry.first).emplace_back(entry.second, *entry.data);
395 template <
typename L,
typename R>
401 const auto& assocHandle(
405 for (
const auto& entry : *assocHandle) {
406 auto it(std::find(collectionL.begin(), collectionL.end(), entry.first));
407 if (it == collectionL.end())
408 throw cet::exception(
"LArPandora") <<
" LArPandoraEvent::GetAssociationMap -- Found object "
409 "in association that isn't in the supplied collection"
414 for (
const auto& objectL : collectionL)
415 outputAssociationMap[objectL];
418 for (
const auto& entry : *assocHandle)
419 outputAssociationMap.at(entry.first).emplace_back(entry.second,
nullptr);
424 template <
typename L,
typename R,
typename D>
429 if (associationLtoR.find(anObject) == associationLtoR.end())
430 throw cet::exception(
"LArPandora")
431 <<
" LArPandoraEvent::CollectAssociated -- Can not find association for object supplied."
434 for (
const auto& entry : associationLtoR.at(anObject)) {
436 if (std::find(associatedR.begin(), associatedR.end(), entry.first) == associatedR.end())
437 associatedR.push_back(entry.first);
443 template <
typename L,
typename R,
typename D>
450 for (
const auto& objectL : collectionL) {
451 if (inputAssociationLtoR.find(objectL) == inputAssociationLtoR.end())
452 throw cet::exception(
"LArPandora")
453 <<
" LArPandoraEvent::GetFilteredAssociationMap -- Can not find association for object "
454 "in supplied collection."
457 if (outputAssociationLtoR.find(objectL) != outputAssociationLtoR.end())
458 throw cet::exception(
"LArPandora")
459 <<
" LArPandoraEvent::GetFilteredAssociationMap -- Repeated objects in input collectionL"
462 for (
const auto& entry : inputAssociationLtoR.at(objectL)) {
463 if (std::find(collectionR.begin(), collectionR.end(), entry.first) == collectionR.end())
466 outputAssociationLtoR[objectL].push_back(entry);
473 template <
typename T>
476 std::unique_ptr<std::vector<T>> output(
new std::vector<T>);
478 for (
const auto&
object : collection)
479 output->push_back(*
object);
486 template <
typename L,
typename R,
typename D>
490 const bool thisProducesR)
const
493 std::unique_ptr<art::Assns<L, R, D>> outputAssn(
new art::Assns<L, R, D>);
498 const art::PtrMaker<L> makePtrL(*
m_pEvent);
500 for (
auto it = associationMap.begin(); it != associationMap.end(); ++it) {
501 const auto indexL(this->
GetIndex(it->first, collectionL));
502 const auto outputPtrL(makePtrL(indexL));
504 for (
const auto& entry : it->second) {
505 const auto& objectR(entry.first);
506 const auto& objectD(entry.second);
509 const art::PtrMaker<R> makePtrR(*
m_pEvent);
510 const auto indexR(this->
GetIndex(objectR, collectionR));
511 outputAssn->addSingle(outputPtrL, makePtrR(indexR), objectD);
514 outputAssn->addSingle(outputPtrL, objectR, objectD);
519 m_pEvent->put(std::move(outputAssn));
524 template <
typename L,
typename R>
528 const bool thisProducesR)
const
531 std::unique_ptr<art::Assns<L, R>> outputAssn(
new art::Assns<L, R>);
536 const art::PtrMaker<L> makePtrL(*
m_pEvent);
538 for (
auto it = associationMap.begin(); it != associationMap.end(); ++it) {
539 const auto indexL(this->
GetIndex(it->first, collectionL));
540 const auto outputPtrL(makePtrL(indexL));
542 for (
const auto& entry : it->second) {
543 const auto& objectR(entry.first);
546 const art::PtrMaker<R> makePtrR(*
m_pEvent);
547 const auto indexR(this->
GetIndex(objectR, collectionR));
548 outputAssn->addSingle(outputPtrL, makePtrR(indexR));
551 outputAssn->addSingle(outputPtrL, objectR);
556 m_pEvent->put(std::move(outputAssn));
561 template <
typename T>
565 const auto it(std::find(collection.begin(), collection.end(),
object));
566 if (it == collection.end())
567 throw cet::exception(
"LArPandora")
568 <<
" LArPandoraEvent::GetIndex -- Can't find input object in the supplied collection."
571 return static_cast<size_t>(std::distance(collection.begin(), it));
helper function for LArPandoraInterface producer module
Class to handle the required producer labels.
LabelType
Label type enumeration.
@ PFParticleToSpacePointLabel
@ PFParticleToClusterLabel
@ PFParticleToShowerLabel
@ PFParticleToVertexLabel
@ PFParticleToMetadataLabel
@ PFParticleMetadataLabel
@ PFParticleToPCAxisLabel
const std::string & GetLabel(const LabelType type) const
Get the label of a given type.
std::map< LabelType, std::string > m_labels
Map holding the labels.
void SetLabel(const LabelType type, const std::string &label)
Set the label of a given type.
SliceToHitAssoc m_sliceHitMap
The input associations: Slice -> Hit.
Association< recob::Track, recob::Hit, recob::TrackHitMeta > TrackToHitAssoc
PFParticleToVertexAssoc m_pfParticleVertexMap
The input associations: PFParticle -> Vertex.
PFParticleToPFParticleMetadataAssoc m_pfParticleMetadataMap
The input associations: PFParticle -> Metadata.
art::Event * m_pEvent
The event to consider.
PFParticleToSliceAssoc m_pfParticleSliceMap
The input associations: PFParticle -> Slice.
PFParticleToPCAxisAssoc m_pfParticlePCAxisMap
The input associations: PFParticle -> PCAxis.
void WriteToEvent() const
Write (put) the collections in this LArPandoraEvent to the art::Event.
TrackToHitAssoc m_trackHitMap
The input associations: Track -> Hit.
void GetFilteredAssociationMap(const Collection< L > &collectionL, const Collection< R > &collectionR, const Association< L, R, D > &inputAssociationLtoR, Association< L, R, D > &outputAssociationLtoR) const
Gets the filtered mapping from objects in collectionL to objects that also exist in collectionR using...
VertexCollection m_vertices
The input collection of Vertices.
PFParticleToT0Assoc m_pfParticleT0Map
The input associations: PFParticle -> T0.
void CollectAssociated(const art::Ptr< L > &anObject, const Association< L, R, D > &associationLtoR, Collection< R > &associatedR) const
Collects all objects of type R with metadata D associated to a given object of type L.
Association< recob::Slice, recob::Hit, void * > SliceToHitAssoc
Collection< recob::Track > TrackCollection
void WriteCollection(const Collection< T > &collection) const
Write a given collection to the event.
Association< recob::PFParticle, recob::Shower, void * > PFParticleToShowerAssoc
PFParticleToTrackAssoc m_pfParticleTrackMap
The input associations: PFParticle -> Track.
Association< recob::Cluster, recob::Hit, void * > ClusterToHitAssoc
Association< recob::PFParticle, recob::Vertex, void * > PFParticleToVertexAssoc
Association< recob::PFParticle, recob::Cluster, void * > PFParticleToClusterAssoc
Association< recob::PFParticle, recob::Track, void * > PFParticleToTrackAssoc
std::vector< std::pair< art::Ptr< R >, D > > PairVector
SpacePointCollection m_spacePoints
The input collection of SpacePoints.
ShowerToPCAxisAssoc m_showerPCAxisMap
The input associations: PCAxis -> Shower.
Collection< recob::Hit > HitCollection
Collection< recob::Shower > ShowerCollection
Association< recob::Shower, recob::PCAxis, void * > ShowerToPCAxisAssoc
PFParticleToShowerAssoc m_pfParticleShowerMap
The input associations: PFParticle -> Shower.
T0Collection m_t0s
The input collection of T0s.
Collection< anab::T0 > T0Collection
Association< recob::PFParticle, anab::T0, void * > PFParticleToT0Assoc
Association< recob::PFParticle, recob::Slice, void * > PFParticleToSliceAssoc
PFParticleMetadataCollection m_metadata
The input collection of PFParticle metadata.
Collection< recob::Slice > SliceCollection
PFParticleCollection m_pfParticles
The input collection of PFParticles.
Association< recob::PFParticle, larpandoraobj::PFParticleMetadata, void * > PFParticleToPFParticleMetadataAssoc
Association< recob::PFParticle, recob::SpacePoint, void * > PFParticleToSpacePointAssoc
Association< recob::Shower, recob::Hit, void * > ShowerToHitAssoc
void WriteAssociation(const Association< L, R, D > &associationMap, const Collection< L > &collectionL, const Collection< R > &collectionR, const bool thisProducesR=true) const
Write a given association to the event.
ClusterToHitAssoc m_clusterHitMap
The input associations: Cluster -> Hit.
TrackCollection m_tracks
The input collection of Tracks.
ShowerToHitAssoc m_showerHitMap
The input associations: Shower -> Hit.
void GetAssociationMap(const Collection< L > &collectionL, const Labels::LabelType &inputLabel, Association< L, R, D > &outputAssociationMap) const
Get the mapping between two collections with metadata using the specified label.
Collection< recob::SpacePoint > SpacePointCollection
ShowerCollection m_showers
The input collection of Showers.
Collection< larpandoraobj::PFParticleMetadata > PFParticleMetadataCollection
PCAxisCollection m_pcAxes
The input collection of PCAxes.
art::EDProducer * m_pProducer
The producer which should write the output collections and associations.
PFParticleToClusterAssoc m_pfParticleClusterMap
The input associations: PFParticle -> Cluster.
Labels m_labels
A set of labels describing the producers for each input collection.
Collection< recob::PFParticle > PFParticleCollection
PFParticleToSpacePointAssoc m_pfParticleSpacePointMap
The input associations: PFParticle -> SpacePoint.
size_t GetIndex(const art::Ptr< T > object, const Collection< T > &collection) const
Get the index of an objet in a given collection.
Association< recob::SpacePoint, recob::Hit, void * > SpacePointToHitAssoc
HitCollection m_hits
The input collection of Hits.
Association< recob::PFParticle, recob::PCAxis, void * > PFParticleToPCAxisAssoc
void GetCollection(const Labels::LabelType &inputLabel, Collection< T > &outputCollection) const
Gets a given collection from m_pEvent with the label supplied.
Collection< recob::Cluster > ClusterCollection
std::vector< art::Ptr< T > > Collection
Shorthand for a collection of objects of type T.
Collection< recob::Vertex > VertexCollection
Collection< recob::PCAxis > PCAxisCollection
bool m_shouldProduceT0s
If T0s should be produced (usually only true for use cases with multiple drift volumes)
ClusterCollection m_clusters
The input collection of Clusters.
void GetCollections()
Get the collections and associations from m_pEvent with the required labels.
SliceCollection m_slices
The input collection of Slices.
SpacePointToHitAssoc m_spacePointHitMap
The input associations: SpacePoint -> Hit.
std::map< art::Ptr< L >, PairVector< R, D > > Association
General purpose short-hand with optional D parameter.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector