LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
VertexFitter_module.cc
Go to the documentation of this file.
7 
10 #include "fhiclcpp/types/Atom.h"
11 #include "fhiclcpp/types/Table.h"
12 
16 
17 #include <memory>
18 
19 namespace trkf {
20 
42  class VertexFitter : public art::EDProducer {
43  public:
44  struct Inputs {
45  using Name = fhicl::Name;
48  Name("inputPFParticleLabel"),
49  Comment("Label of recob::PFParticle Collection to be fit")};
51  Name("inputTracksLabel"),
52  Comment("Label of recob::Track Collection associated to PFParticles")};
53  };
54 
55  struct Config {
56  using Name = fhicl::Name;
58  Name("inputs"),
59  };
60  fhicl::Table<Geometric3DVertexFitter::Config> geom3dvtxfit{Name("geom3dvtxfit")};
62  };
64 
65  explicit VertexFitter(Parameters const& p);
66 
67  // Plugins should not be copied or assigned.
68  VertexFitter(VertexFitter const&) = delete;
69  VertexFitter(VertexFitter&&) = delete;
70  VertexFitter& operator=(VertexFitter const&) = delete;
71  VertexFitter& operator=(VertexFitter&&) = delete;
72 
73  private:
74  void produce(art::Event& e) override;
75 
79  };
80 }
81 
83  : EDProducer{p}
84  , pfParticleInputTag(p().inputs().inputPFParticleLabel())
85  , trackInputTag(p().inputs().inputTracksLabel())
86  , fitter(p().geom3dvtxfit, p().propagator)
87 {
88  produces<std::vector<recob::Vertex>>();
89  produces<art::Assns<recob::PFParticle, recob::Vertex>>();
90  produces<art::Assns<recob::Vertex, recob::Track, recob::VertexAssnMeta>>();
91 }
92 
94 {
95  using namespace std;
96 
97  auto outputVertices = make_unique<vector<recob::Vertex>>();
98  auto outputPFVxAssn = make_unique<art::Assns<recob::PFParticle, recob::Vertex>>();
99  auto outputVxTkMtAssn =
100  make_unique<art::Assns<recob::Vertex, recob::Track, recob::VertexAssnMeta>>();
101 
102  const auto& inputPFParticle = e.getValidHandle<vector<recob::PFParticle>>(pfParticleInputTag);
103  art::FindManyP<recob::Track> const assocTracks{inputPFParticle, e, trackInputTag};
104 
105  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
106 
107  // PtrMakers for Assns
108  art::PtrMaker<recob::Vertex> vtxPtrMaker(e);
109 
110  for (size_t iPF = 0; iPF < inputPFParticle->size(); ++iPF) {
111 
112  art::Ptr<recob::PFParticle> pfp(inputPFParticle, iPF);
113  if (pfp->IsPrimary() == false || pfp->NumDaughters() < 2) continue;
114  vector<art::Ptr<recob::Track>> tracks;
115  auto& pfd = pfp->Daughters();
116  for (auto ipfd : pfd) {
117  // Daugthers returns the id as in pfp->Self() not the key
118  // so need to find the key for the pfp with Self==ipfd
119  for (size_t jPF = 0; jPF < inputPFParticle->size(); ++jPF) {
120  art::Ptr<recob::PFParticle> pfpd(inputPFParticle, jPF);
121  if (pfpd->Self() != ipfd) continue;
122  vector<art::Ptr<recob::Track>> pftracks = assocTracks.at(jPF);
123  for (auto t : pftracks) {
124  tracks.push_back(t);
125  }
126  break;
127  }
128  }
129  if (tracks.size() < 2) continue;
130 
131  VertexWrapper vtx = fitter.fitTracks(detProp, tracks);
132  if (vtx.isValid() == false) continue;
133  vtx.setVertexId(outputVertices->size());
134 
135  auto meta = fitter.computeMeta(detProp, vtx, tracks);
136 
137  // Fill the output collections
138 
139  outputVertices->emplace_back(vtx.vertex());
140  const art::Ptr<recob::Vertex> aptr = vtxPtrMaker(outputVertices->size() - 1);
141  outputPFVxAssn->addSingle(art::Ptr<recob::PFParticle>(inputPFParticle, iPF), aptr);
142 
143  size_t itt = 0;
144  for (auto t : tracks) {
145  outputVxTkMtAssn->addSingle(aptr, t, meta[itt]);
146  itt++;
147  }
148  }
149 
150  e.put(std::move(outputVertices));
151  e.put(std::move(outputPFVxAssn));
152  e.put(std::move(outputVxTkMtAssn));
153 }
154 
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:110
VertexFitter & operator=(VertexFitter const &)=delete
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:85
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:88
VertexFitter(Parameters const &p)
bool isValid() const
Definition: VertexWrapper.h:42
Wrapper class to facilitate vertex production.
Definition: VertexWrapper.h:28
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
art::InputTag pfParticleInputTag
STL namespace.
std::vector< recob::VertexAssnMeta > computeMeta(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
3D vertex fitter based on the geometric properties (start position, direction, covariance) of the tra...
Module for fitting a vertex using the Geometric3DVertexFitter.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
art::InputTag trackInputTag
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:82
VertexWrapper fitTracks(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &arttracks) const
fhicl::Atom< art::InputTag > inputTracksLabel
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void setVertexId(int newID)
Definition: VertexWrapper.h:46
Geometric3DVertexFitter fitter
void produce(art::Event &e) override
Float_t e
Definition: plot.C:35
fhicl::Atom< art::InputTag > inputPFParticleLabel
const recob::Vertex & vertex() const
Definition: VertexWrapper.h:41