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/Principal/Run.h"
6 #include "art/Framework/Principal/SubRun.h"
7 #include "art/Persistency/Common/PtrMaker.h"
8 #include "canvas/Utilities/InputTag.h"
9 #include "cetlib_except/exception.h"
10 #include "fhiclcpp/ParameterSet.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
15 #include "art/Utilities/make_tool.h"
53 void produce(art::Event&
e)
override;
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")}
69 produces<std::vector<recob::Track>>();
70 produces<art::Assns<recob::Track, recob::Hit>>();
71 if (doTrackFitHitInfo_) produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
73 produces<std::vector<recob::SpacePoint>>();
74 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
82 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
83 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
84 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
85 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
86 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
89 art::PtrMaker<recob::Track> trackPtrMaker(e);
90 art::PtrMaker<recob::SpacePoint> spacePointPtrMaker(e);
93 auto const inputTracks = e.getValidHandle<std::vector<recob::Track>>(
trackInputTag);
94 auto const& tkHitsAssn = *e.getValidHandle<art::Assns<recob::Track, recob::Hit>>(
trackInputTag);
100 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
103 unsigned int iTrack = 0;
104 for (
auto hitsRange : tracksWithHits) {
107 art::Ptr<recob::Track>
track(inputTracks, iTrack++);
108 std::vector<art::Ptr<recob::Hit>> inHits;
109 for (art::Ptr<recob::Hit>
const&
hit : hitsRange)
110 inHits.push_back(
hit);
114 std::vector<art::Ptr<recob::Hit>> outHits;
120 bool fitok =
trackMaker_->makeTrack(
detProp, track, inHits, outTrack, outHits, optionals);
121 if (!fitok)
continue;
126 throw cet::exception(
"TrackProducerFromTrack")
127 <<
"Produced recob::Track required to have 1-1 correspondance between hits and "
128 "points.\noutTrack.NumberTrajectoryPoints()="
133 outputTracks->emplace_back(std::move(outTrack));
134 const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
136 for (
auto const& trhit : outHits) {
137 outputHits->addSingle(aptr, trhit);
140 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
141 const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
142 const double fErrXYZ[6] = {0};
144 outputSpacePoints->emplace_back(std::move(sp));
145 const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
146 outputHitSpacePointAssn->addSingle(trhit, apsp);
152 for (
auto it = osp.begin(); it != osp.end(); ++it) {
153 outputSpacePoints->emplace_back(std::move(it->first));
154 const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
155 outputHitSpacePointAssn->addSingle(it->second, apsp);
162 e.put(std::move(outputTracks));
163 e.put(std::move(outputHits));
166 e.put(std::move(outputSpacePoints));
167 e.put(std::move(outputHitSpacePointAssn));
TrackProducerFromTrack & operator=(TrackProducerFromTrack const &)=delete
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
process_name use argoneut_mc_hitfinder track
Produce a reco::Track collection, as a result of the fit of an existing recob::Track collection...
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
auto associated_groups(A const &assns)
Helper functions to access associations in order.
void produce(art::Event &e) override
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
art::InputTag trackInputTag
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Helper functions to access associations in order.
bool spacePointsFromTrajP_
TrackProducerFromTrack(fhicl::ParameterSet const &p)
void initSpacePoints()
initialize the output vector of SpHitPair
Struct holding optional TrackMaker outputs.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track: