VertexFitter_module.cc
Go to the documentation of this file.
6 
8 #include "canvas/Persistency/Common/FindManyP.h"
9 #include "fhiclcpp/types/Atom.h"
10 #include "fhiclcpp/types/Table.h"
11 
15 
16 #include <memory>
17 
18 namespace trkf {
19 
20  /**
21  * @file larreco/VertexFinder/VertexFitter_module.cc
22  * @class trkf::VertexFitter
23  *
24  * @brief Module for fitting a vertex using the Geometric3DVertexFitter.
25  *
26  * It selects primary PFParticles, and then collects all tracks associated to its daughters;
27  * if at least 2 tracks are found, they are passed to the vertex fitter.
28  *
29  * Inputs are: a PFParticle collection, and the associated tracks.
30  *
31  * Outputs are: vector of recob::Vertex, Assns of (neutrino) recob::PFParticle to recob::Vertex,
32  * Assns of recob::Vertex and recob::Track with recob::VertexAssnMeta.
33  *
34  * For configuration options see Geometric3DVertexFitter#Parameters
35  *
36  * @author G. Cerati (FNAL, MicroBooNE)
37  * @date 2017
38  * @version 1.0
39  */
40 
41  class VertexFitter : public art::EDProducer {
42  public:
43  struct Inputs {
44  using Name = fhicl::Name;
47  Name("inputPFParticleLabel"),
48  Comment("Label of recob::PFParticle Collection to be fit")};
50  Name("inputTracksLabel"),
51  Comment("Label of recob::Track Collection associated to PFParticles")};
52  };
53 
54  struct Config {
55  using Name = fhicl::Name;
57  Name("inputs"),
58  };
59  fhicl::Table<Geometric3DVertexFitter::Config> geom3dvtxfit{Name("geom3dvtxfit")};
61  };
63 
64  explicit VertexFitter(Parameters const& p);
65 
66  // Plugins should not be copied or assigned.
67  VertexFitter(VertexFitter const&) = delete;
68  VertexFitter(VertexFitter&&) = delete;
69  VertexFitter& operator=(VertexFitter const&) = delete;
70  VertexFitter& operator=(VertexFitter&&) = delete;
71 
72  private:
73  void produce(art::Event& e) override;
74 
78  };
79 }
80 
82  : EDProducer{p}
83  , pfParticleInputTag(p().inputs().inputPFParticleLabel())
84  , trackInputTag(p().inputs().inputTracksLabel())
85  , fitter(p().geom3dvtxfit, p().propagator)
86 {
87  produces<std::vector<recob::Vertex>>();
88  produces<art::Assns<recob::PFParticle, recob::Vertex>>();
89  produces<art::Assns<recob::Vertex, recob::Track, recob::VertexAssnMeta>>();
90 }
91 
92 void
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:114
VertexFitter & operator=(VertexFitter const &)=delete
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
VertexFitter(Parameters const &p)
bool isValid() const
Definition: VertexWrapper.h:37
Wrapper class to facilitate vertex production.
Definition: VertexWrapper.h:28
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
ChannelGroupService::Name Name
art::InputTag pfParticleInputTag
STL namespace.
std::vector< recob::VertexAssnMeta > computeMeta(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx)
3D vertex fitter based on the geometric properties (start position, direction, covariance) of the tra...
const double e
Module for fitting a vertex using the Geometric3DVertexFitter.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
art::InputTag trackInputTag
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
VertexWrapper fitTracks(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &arttracks) const
fhicl::Atom< art::InputTag > inputTracksLabel
#define Comment
void setVertexId(int newID)
Definition: VertexWrapper.h:41
Geometric3DVertexFitter fitter
void produce(art::Event &e) override
fhicl::Atom< art::InputTag > inputPFParticleLabel
const recob::Vertex & vertex() const
Definition: VertexWrapper.h:36