All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexStubTracker_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: VertexStubTracker
3 // Plugin Type: producer (art v3_02_06)
4 // File: VertexStubTracker_module.cc
5 // Author: grayputnam@uchicago.edu
6 //
7 // Art module for building "Stub" reconstruction objects. Stubs are
8 // correspond to low energy hadrons produced in neutrino interactions that
9 // produce short, highly-ionizing charge depositions near the vertex.
10 //
11 // Module operates on sbn::VertexHit objects and connects the end-point Hit
12 // to the start-point Vertex to build a stub. Merging is then done between
13 // and across planes to consoldiate and refine output. Produces the sbn::Stub
14 // object.
15 ////////////////////////////////////////////////////////////////////////
16 
17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Principal/Event.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Principal/Run.h"
22 #include "art/Framework/Principal/SubRun.h"
23 #include "art/Utilities/make_tool.h"
24 #include "canvas/Utilities/InputTag.h"
25 #include "fhiclcpp/ParameterSet.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
31 
52 
53 #include <memory>
54 #include <optional>
55 
56 namespace sbn {
57  class VertexStubTracker;
58 }
59 
60 
61 class sbn::VertexStubTracker : public art::EDProducer {
62 public:
63  explicit VertexStubTracker(fhicl::ParameterSet const& p);
64  // The compiler-generated destructor is fine for non-base
65  // classes without bare pointers or other resource use.
66 
67  // Plugins should not be copied or assigned.
68  VertexStubTracker(VertexStubTracker const&) = delete;
72 
73  // Required functions.
74  void produce(art::Event& e) override;
75 
76 private:
77 
78  // input labels
79  art::InputTag fPFPLabel;
80  art::InputTag fTrackLabel;
81  art::InputTag fVertexChargeLabel;
82  float fdQdxCut;
87  std::vector<std::unique_ptr<sbn::IStubMerge>> fStubMergeTools;
88 };
89 
90 sbn::VertexStubTracker::VertexStubTracker(fhicl::ParameterSet const& p)
91  : EDProducer{p},
92  fPFPLabel(p.get<art::InputTag>("PFPLabel", "pandora")),
93  fTrackLabel(p.get<art::InputTag>("TrackLabel", "pandoraTrack")),
94  fVertexChargeLabel(p.get<art::InputTag>("VertexChargeLabel", "vhit")),
95  fdQdxCut(p.get<float>("dQdxCut")),
96  fOneWiredQdxCut(p.get<float>("OneWiredQdxCut")),
97  fCorrectSCE(p.get<bool>("CorrectSCE")),
98  fPositionsAreSCECorrected(p.get<bool>("PositionsAreSCECorrected")),
99  fStubBuilder(p.get<fhicl::ParameterSet >("CaloAlg"), fPositionsAreSCECorrected)
100 {
101  // load the tools
102  std::vector<fhicl::ParameterSet> merge_tool_configs(p.get<std::vector<fhicl::ParameterSet>>("MergeTools"));
103  for (unsigned i = 0; i < merge_tool_configs.size(); i++) {
104  fStubMergeTools.push_back(art::make_tool<IStubMerge>(merge_tool_configs[i]));
105  }
106 
107  produces<std::vector<sbn::Stub>>();
108  produces<art::Assns<sbn::VertexHit, sbn::Stub>>();
109  produces<art::Assns<sbn::Stub, recob::Hit>>();
110  produces<art::Assns<sbn::Stub, recob::Slice>>();
111  produces<art::Assns<sbn::Stub, recob::PFParticle>>();
112 
113 }
114 
116 {
117  // collect services
118  const geo::GeometryCore *geo = lar::providerFrom<geo::Geometry>();
119  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
120  auto const dprop =
121  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clock_data);
122  const spacecharge::SpaceCharge *sce = lar::providerFrom<spacecharge::SpaceChargeService>();
123  // If we are not correcting for SCE, then blank out the service
124  if (!fCorrectSCE) sce = nullptr;
125 
126  // output data products
127  std::unique_ptr<std::vector<sbn::Stub>> outStubs(new std::vector<sbn::Stub>);
128  std::unique_ptr<art::Assns<sbn::VertexHit, sbn::Stub>> assn(new art::Assns<sbn::VertexHit, sbn::Stub>);
129  std::unique_ptr<art::Assns<sbn::Stub, recob::Hit>> hitAssn(new art::Assns<sbn::Stub, recob::Hit>);
130  std::unique_ptr<art::Assns<sbn::Stub, recob::Slice>> slcAssn(new art::Assns<sbn::Stub, recob::Slice>);
131  std::unique_ptr<art::Assns<sbn::Stub, recob::PFParticle>> pfpAssn(new art::Assns<sbn::Stub, recob::PFParticle>);
132 
133  art::PtrMaker<sbn::Stub> StubPtrMaker {e};
134 
135  // input data
136  art::Handle<std::vector<recob::Slice>> slice_handle;
137  e.getByLabel(fPFPLabel, slice_handle);
138 
139  std::vector<art::Ptr<recob::Slice>> slices;
140  art::fill_ptr_vector(slices, slice_handle);
141 
142  art::FindManyP<sbn::VertexHit> slcVHits(slices, e, fVertexChargeLabel);
143 
144  // Setup the stub builder
145  fStubBuilder.Setup(e, fPFPLabel, fTrackLabel);
146 
147  for (unsigned i_slc = 0; i_slc < slices.size(); i_slc++) {
148  const std::vector<art::Ptr<sbn::VertexHit>> &vhits = slcVHits.at(i_slc);
149 
150  // look up info per vertex hit
151  art::FindManyP<recob::Vertex> vhitVtxs(vhits, e, fVertexChargeLabel);
152  art::FindManyP<recob::Hit> vhitHits(vhits, e, fVertexChargeLabel);
153 
154  // stuff common to each vertex hit in a slice
155  art::Ptr<recob::Slice> thisSlice = slices[i_slc];
156 
157  std::vector<sbn::StubInfo> stubs;
158  for (unsigned i_vhit = 0; i_vhit < vhits.size(); i_vhit++) {
159  // Collect data on this Vertex-Hit
160  const sbn::VertexHit &thisVHit = *vhits[i_vhit];
161  const recob::Hit &thisVHitHit = *vhitHits.at(i_vhit).at(0);
162 
163  bool passcut = (thisVHit.dqdx >= fdQdxCut) || ((abs(thisVHit.wire.Wire - thisVHit.vtxw) < 1.) && (thisVHit.dqdx >= fOneWiredQdxCut));
164 
165  if (!passcut) continue;
166 
167  sbn::StubInfo sinfo;
168  sinfo.stub = fStubBuilder.FromVertexHit(thisSlice, thisVHit, thisVHitHit, geo, sce, clock_data, dprop, e, sinfo.hits, sinfo.pfp);
169  sinfo.vhit = vhits[i_vhit];
170  sinfo.vhit_hit = vhitHits.at(i_vhit).at(0);
171 
172  stubs.push_back(sinfo);
173 
174  } // end iterate over vertex hits
175 
176  // Run all of the merging tools
177  for (unsigned i_mrg = 0; i_mrg < fStubMergeTools.size(); i_mrg++) {
178  stubs = fStubMergeTools[i_mrg]->Merge(stubs, geo, sce, clock_data, dprop);
179  }
180 
181  // Save!
182  for (unsigned i_stub = 0; i_stub < stubs.size(); i_stub++) {
183  const sbn::StubInfo &sinfo = stubs[i_stub];
184 
185  outStubs->push_back(sinfo.stub);
186  art::Ptr<sbn::Stub> outStub = StubPtrMaker(outStubs->size() - 1);
187  assn->addSingle(sinfo.vhit, outStub);
188  for (unsigned i_hit = 0; i_hit < sinfo.hits.size(); i_hit++) {
189  hitAssn->addSingle(outStub, sinfo.hits[i_hit]);
190  }
191  slcAssn->addSingle(outStub, thisSlice);
192  if (sinfo.pfp) {
193  pfpAssn->addSingle(outStub, sinfo.pfp);
194  }
195  } // end loop over stubs
196 
197  } // end loop over slices
198  // Save into event
199  e.put(std::move(outStubs));
200  e.put(std::move(assn));
201  e.put(std::move(hitAssn));
202  e.put(std::move(slcAssn));
203  e.put(std::move(pfpAssn));
204 }
205 
206 DEFINE_ART_MODULE(sbn::VertexStubTracker)
Data product for reconstructed trajectory in space.
float dqdx
charge/pitch [#elec/cm]
Definition: VertexHit.h:20
Utilities related to art service access.
geo::WireID wire
Wire that the hit is on.
Definition: VertexHit.h:11
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
void produce(art::Event &e) override
Class to keep data related to recob::Hit associated with recob::Track.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
std::vector< std::unique_ptr< sbn::IStubMerge > > fStubMergeTools
Internal struct: contains information on stub and other associated data products. ...
std::vector< art::Ptr< recob::Hit > > hits
Access the description of detector geometry.
T abs(T value)
VertexStubTracker(fhicl::ParameterSet const &p)
Collection of exceptions for Geometry system.
Data product for reconstructed trajectory in space.
art::Ptr< recob::Hit > vhit_hit
Description of geometry of one entire detector.
Declaration of cluster object.
Provides recob::Track data product.
std::vector< TCSlice > slices
Definition: DataStructs.cxx:13
art::Ptr< sbn::VertexHit > vhit
do i e
Declaration of basic channel signal object.
VertexStubTracker & operator=(VertexStubTracker const &)=delete
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
Class defining a sparse vector (holes are zeroes)
art framework interface to geometry description
float vtxw
Wire of the vertex associated with this hit. Not space charge corrected. [cm].
Definition: VertexHit.h:14
art::Ptr< recob::PFParticle > pfp