All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexFitter_module.cc
Go to the documentation of this file.
1 #include "art/Framework/Core/EDProducer.h"
2 #include "art/Framework/Core/ModuleMacros.h"
3 #include "art/Framework/Principal/Event.h"
4 #include "art/Framework/Principal/Handle.h"
5 #include "art/Framework/Services/Registry/ServiceHandle.h"
6 #include "canvas/Utilities/InputTag.h"
7 
8 #include "art/Persistency/Common/PtrMaker.h"
9 #include "canvas/Persistency/Common/FindManyP.h"
10 #include "fhiclcpp/types/Atom.h"
11 #include "fhiclcpp/types/Table.h"
12 
16 
17 #include <memory>
18 
19 namespace trkf {
20 
21  /**
22  * @file larreco/VertexFinder/VertexFitter_module.cc
23  * @class trkf::VertexFitter
24  *
25  * @brief Module for fitting a vertex using the Geometric3DVertexFitter.
26  *
27  * It selects primary PFParticles, and then collects all tracks associated to its daughters;
28  * if at least 2 tracks are found, they are passed to the vertex fitter.
29  *
30  * Inputs are: a PFParticle collection, and the associated tracks.
31  *
32  * Outputs are: vector of recob::Vertex, Assns of (neutrino) recob::PFParticle to recob::Vertex,
33  * Assns of recob::Vertex and recob::Track with recob::VertexAssnMeta.
34  *
35  * For configuration options see Geometric3DVertexFitter#Parameters
36  *
37  * @author G. Cerati (FNAL, MicroBooNE)
38  * @date 2017
39  * @version 1.0
40  */
41 
42  class VertexFitter : public art::EDProducer {
43  public:
44  struct Inputs {
45  using Name = fhicl::Name;
46  using Comment = fhicl::Comment;
47  fhicl::Atom<art::InputTag> inputPFParticleLabel{
48  Name("inputPFParticleLabel"),
49  Comment("Label of recob::PFParticle Collection to be fit")};
50  fhicl::Atom<art::InputTag> inputTracksLabel{
51  Name("inputTracksLabel"),
52  Comment("Label of recob::Track Collection associated to PFParticles")};
53  };
54 
55  struct Config {
56  using Name = fhicl::Name;
57  fhicl::Table<VertexFitter::Inputs> inputs{
58  Name("inputs"),
59  };
60  fhicl::Table<Geometric3DVertexFitter::Config> geom3dvtxfit{Name("geom3dvtxfit")};
61  fhicl::Table<TrackStatePropagator::Config> propagator{Name("propagator")};
62  };
63  using Parameters = art::EDProducer::Table<Config>;
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 
76  art::InputTag pfParticleInputTag;
77  art::InputTag trackInputTag;
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 
93 void
95 {
96  using namespace std;
97 
98  auto outputVertices = make_unique<vector<recob::Vertex>>();
99  auto outputPFVxAssn = make_unique<art::Assns<recob::PFParticle, recob::Vertex>>();
100  auto outputVxTkMtAssn =
101  make_unique<art::Assns<recob::Vertex, recob::Track, recob::VertexAssnMeta>>();
102 
103  const auto& inputPFParticle = e.getValidHandle<vector<recob::PFParticle>>(pfParticleInputTag);
104  art::FindManyP<recob::Track> const assocTracks{inputPFParticle, e, trackInputTag};
105 
106  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
107 
108  // PtrMakers for Assns
109  art::PtrMaker<recob::Vertex> vtxPtrMaker(e);
110 
111  for (size_t iPF = 0; iPF < inputPFParticle->size(); ++iPF) {
112 
113  art::Ptr<recob::PFParticle> pfp(inputPFParticle, iPF);
114  if (pfp->IsPrimary() == false || pfp->NumDaughters() < 2) continue;
115  vector<art::Ptr<recob::Track>> tracks;
116  auto& pfd = pfp->Daughters();
117  for (auto ipfd : pfd) {
118  // Daugthers returns the id as in pfp->Self() not the key
119  // so need to find the key for the pfp with Self==ipfd
120  for (size_t jPF = 0; jPF < inputPFParticle->size(); ++jPF) {
121  art::Ptr<recob::PFParticle> pfpd(inputPFParticle, jPF);
122  if (pfpd->Self() != ipfd) continue;
123  vector<art::Ptr<recob::Track>> pftracks = assocTracks.at(jPF);
124  for (auto t : pftracks) {
125  tracks.push_back(t);
126  }
127  break;
128  }
129  }
130  if (tracks.size() < 2) continue;
131 
132  VertexWrapper vtx = fitter.fitTracks(detProp, tracks);
133  if (vtx.isValid() == false) continue;
134  vtx.setVertexId(outputVertices->size());
135 
136  auto meta = fitter.computeMeta(detProp, 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 DEFINE_ART_MODULE(trkf::VertexFitter)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
VertexFitter & operator=(VertexFitter const &)=delete
fhicl::Table< Geometric3DVertexFitter::Config > geom3dvtxfit
ClusterModuleLabel join with tracks
VertexFitter(Parameters const &p)
bool isValid() const
Definition: VertexWrapper.h:37
Wrapper class to facilitate vertex production.
Definition: VertexWrapper.h:28
pdgs p
Definition: selectors.fcl:22
art::InputTag pfParticleInputTag
fhicl::Table< VertexFitter::Inputs > inputs
art::EDProducer::Table< Config > Parameters
3D vertex fitter based on the geometric properties (start position, direction, covariance) of the tra...
Module for fitting a vertex using the Geometric3DVertexFitter.
fhicl::Table< TrackStatePropagator::Config > propagator
art::InputTag trackInputTag
BEGIN_PROLOG vertical distance to the surface Name
fhicl::Atom< art::InputTag > inputTracksLabel
void setVertexId(int newID)
Definition: VertexWrapper.h:41
Geometric3DVertexFitter fitter
do i e
void produce(art::Event &e) override
fhicl::Atom< art::InputTag > inputPFParticleLabel
auto const detProp
const recob::Vertex & vertex() const
Definition: VertexWrapper.h:36