LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackProducerFromTrackTrajectory_module.cc
Go to the documentation of this file.
8 #include "cetlib_except/exception.h"
10 
11 #include <memory>
12 
16 
38 //
39 //
41 public:
43  // The compiler-generated destructor is fine for non-base
44  // classes without bare pointers or other resource use.
45 
46  // Plugins should not be copied or assigned.
51 
52 private:
53  // Required functions.
54  void produce(art::Event& e) override;
55  std::unique_ptr<trkmkr::TrackMaker> trackMaker_;
60 };
61 
63  : EDProducer{p}
64  , trackMaker_{art::make_tool<trkmkr::TrackMaker>(p.get<fhicl::ParameterSet>("trackMaker"))}
65  , trajInputTag{p.get<art::InputTag>("inputCollection")}
66  , doTrackFitHitInfo_{p.get<bool>("doTrackFitHitInfo")}
67  , doSpacePoints_{p.get<bool>("doSpacePoints")}
68  , spacePointsFromTrajP_{p.get<bool>("spacePointsFromTrajP")}
69 {
70  produces<std::vector<recob::Track>>();
71  produces<art::Assns<recob::Track, recob::Hit>>();
72  produces<art::Assns<recob::TrackTrajectory, recob::Track>>();
73  if (doTrackFitHitInfo_) produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
74  if (doSpacePoints_) {
75  produces<std::vector<recob::SpacePoint>>();
76  produces<art::Assns<recob::Hit, recob::SpacePoint>>();
77  }
78 }
79 
81 {
82  // Output collections
83  auto outputTracks = std::make_unique<std::vector<recob::Track>>();
84  auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
85  auto outputTTjTAssn = std::make_unique<art::Assns<recob::TrackTrajectory, recob::Track>>();
86  auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
87  auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
88  auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
89 
90  // PtrMakers for Assns
91  art::PtrMaker<recob::Track> trackPtrMaker(e);
92  art::PtrMaker<recob::SpacePoint> spacePointPtrMaker(e);
93 
94  // Input from event
96  e.getValidHandle<std::vector<recob::TrackTrajectory>>(trajInputTag);
97  auto const& tjHitsAssn =
99  const auto& trajectoriesWithHits = util::associated_groups(tjHitsAssn);
100 
101  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
102 
103  // Initialize tool for this event
104  trackMaker_->initEvent(e);
105 
106  // Loop over trajectories to fit
107  unsigned int iTraj = 0;
108  for (auto hitsRange : trajectoriesWithHits) {
109 
110  // Get track and its hits
111  art::Ptr<recob::TrackTrajectory> traj(inputTrajs, iTraj++);
112  std::vector<art::Ptr<recob::Hit>> inHits;
113  for (art::Ptr<recob::Hit> const& hit : hitsRange)
114  inHits.push_back(hit);
115 
116  // Declare output objects
117  recob::Track outTrack;
118  std::vector<art::Ptr<recob::Hit>> outHits;
119  trkmkr::OptionalOutputs optionals;
120  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
122 
123  // Invoke tool to fit track and fill output objects
124  bool fitok = trackMaker_->makeTrack(detProp, traj, inHits, outTrack, outHits, optionals);
125  if (!fitok) continue;
126 
127  // Check that the requirement Nhits == Npoints is satisfied
128  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
129  if (outTrack.NumberTrajectoryPoints() != outHits.size()) {
130  throw cet::exception("TrackProducerFromTrackTrajectory")
131  << "Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
132  }
133 
134  // Fill output collections, including Assns
135  outputTracks->emplace_back(std::move(outTrack));
136  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
137  outputTTjTAssn->addSingle(traj, aptr);
138  unsigned int ip = 0;
139  for (auto const& trhit : outHits) {
140  outputHits->addSingle(aptr, trhit);
141 
142  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
143  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
144  const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
145  const double fErrXYZ[6] = {0};
146  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
147  outputSpacePoints->emplace_back(std::move(sp));
148  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
149  outputHitSpacePointAssn->addSingle(trhit, apsp);
150  }
151  ip++;
152  }
154  auto osp = optionals.spacePointHitPairs();
155  for (auto it = osp.begin(); it != osp.end(); ++it) {
156  outputSpacePoints->emplace_back(std::move(it->first));
157  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
158  outputHitSpacePointAssn->addSingle(it->second, apsp);
159  }
160  }
161  if (doTrackFitHitInfo_) { outputHitInfo->emplace_back(optionals.trackFitHitInfos()); }
162  }
163 
164  // Put collections in the event
165  e.put(std::move(outputTracks));
166  e.put(std::move(outputHits));
167  e.put(std::move(outputTTjTAssn));
168  if (doTrackFitHitInfo_) { e.put(std::move(outputHitInfo)); }
169  if (doSpacePoints_) {
170  e.put(std::move(outputSpacePoints));
171  e.put(std::move(outputHitSpacePointAssn));
172  }
173 }
174 
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:140
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:132
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
Produce a reco::Track collection, as a result of the fit of an existing recob::TrackTrajectory collec...
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:136
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
auto associated_groups(A const &assns)
Helper functions to access associations in order.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
TrackProducerFromTrackTrajectory(fhicl::ParameterSet const &p)
TrackProducerFromTrackTrajectory & operator=(TrackProducerFromTrackTrajectory const &)=delete
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
Detector simulation of raw signals on wires.
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
Definition: TrackMaker.h:160
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:151
Helper functions to access associations in order.
Float_t e
Definition: plot.C:35
Definition: fwd.h:26
void initSpacePoints()
initialize the output vector of SpHitPair
Definition: TrackMaker.h:145
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:108
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33