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