LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrackProducerFromTrack_module.cc
Go to the documentation of this file.
12 #include "cetlib_except/exception.h"
13 //
14 #include <memory>
15 //
18 //
39 //
40 //
42 public:
43  explicit TrackProducerFromTrack(fhicl::ParameterSet const & p);
44  // The compiler-generated destructor is fine for non-base
45  // classes without bare pointers or other resource use.
46  //
47  // Plugins should not be copied or assigned.
52  // Required functions.
53  void produce(art::Event & e) override;
54 private:
55  std::unique_ptr<trkmkr::TrackMaker> trackMaker_;
60 };
61 //
63  : trackMaker_{art::make_tool<trkmkr::TrackMaker>(p.get<fhicl::ParameterSet>("trackMaker"))}
64  , trackInputTag{p.get<art::InputTag>("inputCollection")}
65  , doTrackFitHitInfo_{p.get<bool>("doTrackFitHitInfo")}
66  , doSpacePoints_{p.get<bool>("doSpacePoints")}
67  , spacePointsFromTrajP_{p.get<bool>("spacePointsFromTrajP")}
68 {
69  produces<std::vector<recob::Track> >();
70  produces<art::Assns<recob::Track, recob::Hit> >();
71  if (doTrackFitHitInfo_) produces<std::vector<std::vector<recob::TrackFitHitInfo> > >();
72  if (doSpacePoints_) {
73  produces<std::vector<recob::SpacePoint> >();
74  produces<art::Assns<recob::Hit, recob::SpacePoint> >();
75  }
76 }
77 //
79 {
80  // Output collections
81  auto outputTracks = std::make_unique<std::vector<recob::Track> >();
82  auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit> >();
83  auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo> > >();
84  auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint> >();
85  auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint> >();
86  //
87  // PtrMakers for Assns
88  art::PtrMaker<recob::Track> trackPtrMaker(e, *this);
89  art::PtrMaker<recob::SpacePoint> spacePointPtrMaker(e, *this);
90  //
91  // Input from event
92  art::ValidHandle<std::vector<recob::Track> > inputTracks = e.getValidHandle<std::vector<recob::Track> >(trackInputTag);
94  const auto& tracksWithHits = util::associated_groups(tkHitsAssn);
95  //
96  // Initialize tool for this event
97  trackMaker_->initEvent(e);
98  //
99  // Loop over tracks to refit
100  unsigned int iTrack = 0;
101  for (auto hitsRange: tracksWithHits) {
102  //
103  // Get track and its hits
104  art::Ptr<recob::Track> track(inputTracks, iTrack++);
105  std::vector<art::Ptr<recob::Hit> > inHits;
106  for (art::Ptr<recob::Hit> const& hit: hitsRange) inHits.push_back(hit);
107  //
108  // Declare output objects
109  recob::Track outTrack;
110  std::vector<art::Ptr<recob::Hit> > outHits;
111  trkmkr::OptionalOutputs optionals;
112  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
114  //
115  // Invoke tool to fit track and fill output objects
116  bool fitok = trackMaker_->makeTrack(track, inHits, outTrack, outHits, optionals);
117  if (!fitok) continue;
118  //
119  // Check that the requirement Nhits == Npoints is satisfied
120  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
121  if (outTrack.NumberTrajectoryPoints()!=outHits.size()) {
122  throw cet::exception("TrackProducerFromTrack") << "Produced recob::Track required to have 1-1 correspondance between hits and points.\noutTrack.NumberTrajectoryPoints()=" << outTrack.NumberTrajectoryPoints() << " outHits.size()=" << outHits.size() <<"\n";
123  }
124  //
125  // Fill output collections, including Assns
126  outputTracks->emplace_back(std::move(outTrack));
127  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size()-1);
128  unsigned int ip = 0;
129  for (auto const& trhit: outHits) {
130  outputHits->addSingle(aptr, trhit);
131  //
132  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
133  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
134  const double fXYZ[3] = {tp.X(),tp.Y(),tp.Z()};
135  const double fErrXYZ[6] = {0};
136  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
137  outputSpacePoints->emplace_back(std::move(sp));
138  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size()-1);
139  outputHitSpacePointAssn->addSingle(trhit, apsp);
140  }
141  ip++;
142  }
144  auto osp = optionals.spacePointHitPairs();
145  for (auto it = osp.begin(); it!=osp.end(); ++it ) {
146  outputSpacePoints->emplace_back(std::move(it->first));
147  const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size()-1);
148  outputHitSpacePointAssn->addSingle(it->second,apsp);
149  }
150  }
151  if (doTrackFitHitInfo_) {
152  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
153  }
154  }
155  //
156  // Put collections in the event
157  e.put(std::move(outputTracks));
158  e.put(std::move(outputHits));
159  if (doTrackFitHitInfo_) {
160  e.put(std::move(outputHitInfo));
161  }
162  if (doSpacePoints_) {
163  e.put(std::move(outputSpacePoints));
164  e.put(std::move(outputHitSpacePointAssn));
165  }
166 }
167 //
TrackProducerFromTrack & operator=(TrackProducerFromTrack const &)=delete
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
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:109
Produce a reco::Track collection, as a result of the fit of an existing recob::Track collection...
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
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.
void produce(art::Event &e) override
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
TrackProducerFromTrack(fhicl::ParameterSet const &p)
Float_t e
Definition: plot.C:34
Float_t track
Definition: plot.C:34
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