13 #include "art/Framework/Core/EDProducer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
50 void produce(art::Event&
e)
override;
60 const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta)
const;
63 const std::vector<art::Ptr<recob::PFParticle>>& cosmicPFPs,
64 const art::FindManyP<recob::SpacePoint>& fmPFPSP)
const;
69 , fPandoraLabel(
p.get<art::InputTag>(
"PandoraLabel"))
70 , fShowerLabel(
p.get<art::InputTag>(
"ShowerLabel"))
71 , fMinShowerEnergy(
p.get<
float>(
"MinShowerEnergy"))
73 produces<std::vector<float>>();
74 produces<art::Assns<recob::Shower, float>>();
80 auto const showerHandle = e.getValidHandle<std::vector<recob::Shower>>(
fShowerLabel);
81 auto const pfpHandle = e.getValidHandle<std::vector<recob::PFParticle>>(
fPandoraLabel);
83 std::vector<art::Ptr<recob::Shower>> showers;
84 art::fill_ptr_vector(showers, showerHandle);
86 std::vector<art::Ptr<recob::PFParticle>> pfps;
87 art::fill_ptr_vector(pfps, pfpHandle);
89 const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta(pfpHandle, e,
fPandoraLabel);
90 if (!fmPFPMeta.isValid()) {
91 throw cet::exception(
"ShowerCosmicDistance") <<
"PFP-Meta association is somehow not valid. Stopping";
94 const art::FindManyP<recob::SpacePoint> fmPFPSP(pfpHandle, e,
fPandoraLabel);
95 if (!fmPFPSP.isValid()) {
96 throw cet::exception(
"ShowerCosmicDistance") <<
"PFP-SP association is somehow not valid. Stopping";
100 const std::vector<art::Ptr<recob::PFParticle>> cosmicPFPs(
GetCosmicPFPs(pfps, fmPFPMeta));
102 std::unique_ptr<std::vector<float>> residualCol(std::make_unique<std::vector<float>>());
103 std::unique_ptr<art::Assns<recob::Shower, float>> residualAssns(std::make_unique<art::Assns<recob::Shower, float>>());
105 for (
auto const&
shower : showers) {
113 residualCol->push_back(res);
117 e.put(std::move(residualCol));
118 e.put(std::move(residualAssns));
122 const std::vector<art::Ptr<recob::PFParticle>>& pfps,
123 const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta)
const
125 std::vector<art::Ptr<recob::PFParticle>> cosmicPFPs;
126 for (
auto const& pfp : pfps) {
128 if (!pfp->IsPrimary())
131 auto const& pfpMetaVec(fmPFPMeta.at(pfp.key()));
132 if (pfpMetaVec.size() != 1)
133 throw cet::exception(
"ShowerCosmicDistance") <<
"Wrong metadata entries for PFP: " << pfpMetaVec.size() <<
". Stopping";
136 if (!pfpMetaVec.front()->GetPropertiesMap().count(
"IsClearCosmic"))
141 cosmicPFPs.push_back(pfp);
147 const std::vector<art::Ptr<recob::PFParticle>>& cosmicPFPs,
148 const art::FindManyP<recob::SpacePoint>& fmPFPSP)
const
150 float res(std::numeric_limits<float>::max());
152 const geo::Point_t showerStart(showerStart3.X(), showerStart3.Y(), showerStart3.Z());
155 for (
auto const& cosmicPFP : cosmicPFPs) {
156 auto const& pfpSPs(fmPFPSP.at(cosmicPFP.key()));
158 for (
auto const& sp : pfpSPs) {
159 const float dist((showerStart - sp->position()).
r());
160 res = std::min(res,
dist);
const std::vector< art::Ptr< recob::PFParticle > > GetCosmicPFPs(const std::vector< art::Ptr< recob::PFParticle >> &pfps, const art::FindManyP< larpandoraobj::PFParticleMetadata > fmPFPMeta) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
const float FindShowerResidual(const recob::Shower &shower, const std::vector< art::Ptr< recob::PFParticle >> &cosmicPFPs, const art::FindManyP< recob::SpacePoint > &fmPFPSP) const
Provides recob::Track data product.
ShowerCosmicDistance(fhicl::ParameterSet const &p)
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
void produce(art::Event &e) override
const float fMinShowerEnergy
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const TVector3 & ShowerStart() const
const art::InputTag fPandoraLabel
const art::InputTag fShowerLabel
ShowerCosmicDistance & operator=(ShowerCosmicDistance const &)=delete
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.