118 #include "Pandora/PdgTable.h" 132 produces< std::vector<recob::PFParticle> >();
133 produces< std::vector<recob::SpacePoint> >();
134 produces< std::vector<recob::Cluster> >();
135 produces< std::vector<recob::Vertex> >();
136 produces< std::vector<recob::Track> >();
137 produces< std::vector<recob::Shower> >();
138 produces< std::vector<recob::PCAxis> >();
139 produces< std::vector<larpandoraobj::PFParticleMetadata> >();
141 produces< art::Assns<recob::PFParticle, recob::SpacePoint> >();
142 produces< art::Assns<recob::PFParticle, recob::Cluster> >();
143 produces< art::Assns<recob::PFParticle, recob::Vertex> >();
144 produces< art::Assns<recob::PFParticle, recob::Track> >();
145 produces< art::Assns<recob::PFParticle, recob::Shower> >();
146 produces< art::Assns<recob::PFParticle, recob::PCAxis> >();
147 produces< art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata> >();
148 produces< art::Assns<recob::Track, recob::Hit> >();
149 produces< art::Assns<recob::Shower, recob::Hit> >();
150 produces< art::Assns<recob::Shower, recob::PCAxis> >();
151 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
152 produces< art::Assns<recob::Cluster, recob::Hit> >();
156 produces< std::vector<anab::T0> >();
157 produces< art::Assns<recob::PFParticle, anab::T0> >();
176 this->
CollectSlices(particles, particlesToMetadata, particleMap, slices);
198 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i)
201 const auto &metadata(pfParticleMetadataAssoc.at(part.
key()));
203 particles.push_back(part);
205 if (metadata.size() != 1)
206 throw cet::exception(
"LArPandora") <<
" LArPandoraExternalEventBuilding::CollectPFParticles -- Found a PFParticle without exactly 1 metadata associated." << std::endl;
208 if (!particlesToMetadata.insert(PFParticleToMetadata::value_type(part, metadata.front())).second)
209 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"Repeated PFParticles" << std::endl;
217 for (
const auto &entry : particlesToMetadata)
219 if (!particleMap.insert(PFParticleMap::value_type(entry.first->Self(), entry.first)).second)
220 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"Repeated PFParticles" << std::endl;
228 for (
const auto &
part : allParticles)
232 if (parentIt == particlesToMetadata.end())
233 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"Found PFParticle without metadata" << std::endl;
238 if (static_cast<bool>(std::round(this->
GetMetadataValue(parentIt->second,
"IsClearCosmic"))))
239 clearCosmics.push_back(
part);
251 std::map<unsigned int, float> nuScores;
252 std::map<unsigned int, PFParticleVector> crHypotheses;
253 std::map<unsigned int, PFParticleVector> nuHypotheses;
256 for (
const auto &
part : allParticles)
260 if (parentIt == particlesToMetadata.end())
261 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"Found PFParticle without metadata" << std::endl;
266 if (static_cast<bool>(std::round(this->
GetMetadataValue(parentIt->second,
"IsClearCosmic"))))
273 const unsigned int sliceId(static_cast<unsigned int>(std::round(this->
GetMetadataValue(parentIt->second,
"SliceIndex"))));
276 nuScores[sliceId] = nuScore;
280 nuHypotheses[sliceId].push_back(
part);
284 crHypotheses[sliceId].push_back(
part);
294 for (
unsigned int sliceId = 1; sliceId <= nuScores.size(); ++sliceId)
297 const auto nuScoresIter(nuScores.find(sliceId));
298 if (nuScoresIter == nuScores.end())
299 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"Scrambled slice information - can't find nuScore with id = " << sliceId << std::endl;
303 const auto nuHypothesisIter(nuHypotheses.find(sliceId));
304 nuPFParticleVector = ((nuHypothesisIter == nuHypotheses.end()) ? emptyPFParticleVector : nuHypothesisIter->second);
307 const auto crHypothesisIter(crHypotheses.find(sliceId));
308 crPFParticleVector = ((crHypothesisIter == crHypotheses.end()) ? emptyPFParticleVector : crHypothesisIter->second);
310 slices.emplace_back(nuScoresIter->second, nuPFParticleVector, crPFParticleVector);
319 const auto &it(propertiesMap.find(key));
321 if (it == propertiesMap.end())
322 throw cet::exception(
"LArPandoraExternalEventBuilding") <<
"No key \"" << key <<
"\" found in metadata properties map" << std::endl;
332 collectedParticles.insert(collectedParticles.end(), clearCosmics.begin(), clearCosmics.end());
334 for (
const auto &slice : slices)
336 const PFParticleVector &particles(slice.IsTaggedAsNeutrino() ? slice.GetNeutrinoHypothesis() : slice.GetCosmicRayHypothesis());
337 collectedParticles.insert(collectedParticles.end(), particles.begin(), particles.end());
342 for (
const auto &
part : allParticles)
344 if (std::find(collectedParticles.begin(), collectedParticles.end(),
part) != collectedParticles.end())
345 consolidatedParticles.push_back(
part);
void CollectSlices(const PFParticleVector &allParticles, const PFParticleToMetadata &particlesToMetadata, const PFParticleMap &particleMap, SliceVector &slices) const
Collect slices.
void CollectPFParticles(const art::Event &evt, PFParticleToMetadata &particlesToMetadata, PFParticleVector &particles) const
Collect PFParticles from the ART event and their mapping to metadata objects.
std::map< art::Ptr< recob::PFParticle >, art::Ptr< larpandoraobj::PFParticleMetadata > > PFParticleToMetadata
std::enable_if_t< std::is_class< T >::value, tool_return_type< T > > make_tool(fhicl::ParameterSet const &pset)
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
LArPandoraExternalEventBuilding & operator=(LArPandoraExternalEventBuilding const &)=delete
header for the lar pandora slice class
static art::Ptr< recob::PFParticle > GetParentPFParticle(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the top-level parent particle by navigating up the chain of parent/daughter associations...
std::unique_ptr< NeutrinoIdBaseTool > m_neutrinoIdTool
The neutrino id tool.
void CollectClearCosmicRays(const PFParticleVector &allParticles, const PFParticleToMetadata &particlesToMetadata, const PFParticleMap &particleMap, PFParticleVector &clearCosmics) const
Collect PFParticles that have been identified as clear cosmic ray muons by pandora.
std::map< int, art::Ptr< recob::PFParticle > > PFParticleMap
std::string m_trackProducerLabel
Label for the track producer using the Pandora instance that produced the collections we want to cons...
std::string m_showerProducerLabel
Label for the shower producer using the Pandora instance that produced the collections we want to con...
std::string m_hitProducerLabel
Label for the hit producer that was used as input to the Pandora instance specified.
#define DEFINE_ART_MODULE(klass)
A description of all outputs from an instance of pandora with functionality to filter and merge multi...
const PropertiesMap & GetPropertiesMap() const
std::vector< TCSlice > slices
void produce(art::Event &evt) override
float GetMetadataValue(const art::Ptr< larpandoraobj::PFParticleMetadata > &metadata, const std::string &key) const
Query a metadata object for a given key and return the corresponding value.
std::vector< Slice > SliceVector
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
bool m_shouldProduceT0s
If we should produce T0s (relevant when stitching over multiple drift volumes)
art::InputTag m_pandoraTag
The input tag for the pandora producer.
Class to handle the required producer labels.
std::string m_inputProducerLabel
Label for the Pandora instance that produced the collections we want to consolidated.
void BuildPFParticleMap(const PFParticleToMetadata &particlesToMetadata, PFParticleMap &particleMap) const
Build mapping from ID to PFParticle for fast navigation through the hierarchy.
void CollectConsolidatedParticles(const PFParticleVector &allParticles, const PFParticleVector &clearCosmics, const SliceVector &slices, PFParticleVector &consolidatedParticles) const
Get the consolidated collection of particles based on the slice ids.
helper function for LArPandoraInterface producer module
cet::coded_exception< error, detail::translate > exception
LArPandoraExternalEventBuilding(fhicl::ParameterSet const &pset)
void WriteToEvent() const
Write (put) the collections in this LArPandoraEvent to the art::Event.