LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrackProducerFromTrackTrajectory_module.cc
Go to the documentation of this file.
12 #include "cetlib_except/exception.h"
13 //
14 #include <memory>
15 //
18 //
40 //
41 //
43 public:
45  // The compiler-generated destructor is fine for non-base
46  // classes without bare pointers or other resource use.
47  //
48  // Plugins should not be copied or assigned.
53  // Required functions.
54  void produce(art::Event & e) override;
55 private:
56  std::unique_ptr<trkmkr::TrackMaker> trackMaker_;
61 };
62 //
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, *this);
92  art::PtrMaker<recob::SpacePoint> spacePointPtrMaker(e, *this);
93  //
94  // Input from event
95  art::ValidHandle<std::vector<recob::TrackTrajectory> > inputTrajs = e.getValidHandle<std::vector<recob::TrackTrajectory> >(trajInputTag);
97  const auto& trajectoriesWithHits = util::associated_groups(tjHitsAssn);
98  //
99  // Initialize tool for this event
100  trackMaker_->initEvent(e);
101  //
102  // Loop over trajectories to fit
103  unsigned int iTraj = 0;
104  for (auto hitsRange: trajectoriesWithHits) {
105  //
106  // Get track and its hits
107  art::Ptr<recob::TrackTrajectory> traj(inputTrajs, iTraj++);
108  std::vector<art::Ptr<recob::Hit> > inHits;
109  for (art::Ptr<recob::Hit> const& hit: hitsRange) inHits.push_back(hit);
110  //
111  // Declare output objects
112  recob::Track outTrack;
113  std::vector<art::Ptr<recob::Hit> > outHits;
114  trkmkr::OptionalOutputs optionals;
115  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
117  //
118  // Invoke tool to fit track and fill output objects
119  bool fitok = trackMaker_->makeTrack(traj, inHits, outTrack, outHits, optionals);
120  if (!fitok) continue;
121  //
122  // Check that the requirement Nhits == Npoints is satisfied
123  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
124  if (outTrack.NumberTrajectoryPoints()!=outHits.size()) {
125  throw cet::exception("TrackProducerFromTrackTrajectory") << "Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
126  }
127  //
128  // Fill output collections, including Assns
129  outputTracks->emplace_back(std::move(outTrack));
130  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size()-1);
131  outputTTjTAssn->addSingle(traj, aptr);
132  unsigned int ip = 0;
133  for (auto const& trhit: outHits) {
134  outputHits->addSingle(aptr, trhit);
135  //
136  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
137  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
138  const double fXYZ[3] = {tp.X(),tp.Y(),tp.Z()};
139  const double fErrXYZ[6] = {0};
140  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
141  outputSpacePoints->emplace_back(std::move(sp));
142  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size()-1);
143  outputHitSpacePointAssn->addSingle(trhit, apsp);
144  }
145  ip++;
146  }
148  auto osp = optionals.spacePointHitPairs();
149  for (auto it = osp.begin(); it!=osp.end(); ++it ) {
150  outputSpacePoints->emplace_back(std::move(it->first));
151  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size()-1);
152  outputHitSpacePointAssn->addSingle(it->second,apsp);
153  }
154  }
155  if (doTrackFitHitInfo_) {
156  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
157  }
158  }
159  //
160  // Put collections in the event
161  e.put(std::move(outputTracks));
162  e.put(std::move(outputHits));
163  e.put(std::move(outputTTjTAssn));
164  if (doTrackFitHitInfo_) {
165  e.put(std::move(outputHitInfo));
166  }
167  if (doSpacePoints_) {
168  e.put(std::move(outputSpacePoints));
169  e.put(std::move(outputHitSpacePointAssn));
170  }
171 }
172 //
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:102
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:105
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:109
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
auto associated_groups(A const &assns)
Helper functions to access associations in order.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
TrackProducerFromTrackTrajectory(fhicl::ParameterSet const &p)
TrackProducerFromTrackTrajectory & operator=(TrackProducerFromTrackTrajectory const &)=delete
T get(std::string const &key) const
Definition: ParameterSet.h:231
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:255
Detector simulation of raw signals on wires.
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
Definition: TrackMaker.h:119
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:114
Helper functions to access associations in order.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Float_t e
Definition: plot.C:34
Definition: fwd.h:25
void initSpacePoints()
initialize the output vector of SpHitPair
Definition: TrackMaker.h:106
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:73
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:51
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33