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/Persistency/Common/PtrMaker.h"
6 #include "art/Utilities/make_tool.h"
7 #include "canvas/Utilities/InputTag.h"
8 #include "cetlib_except/exception.h"
9 #include "fhiclcpp/ParameterSet.h"
54 void produce(art::Event&
e)
override;
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")}
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>>>();
75 produces<std::vector<recob::SpacePoint>>();
76 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
84 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
85 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
86 auto outputTTjTAssn = std::make_unique<art::Assns<recob::TrackTrajectory, recob::Track>>();
87 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
88 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
89 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
92 art::PtrMaker<recob::Track> trackPtrMaker(e);
93 art::PtrMaker<recob::SpacePoint> spacePointPtrMaker(e);
96 art::ValidHandle<std::vector<recob::TrackTrajectory>> inputTrajs =
97 e.getValidHandle<std::vector<recob::TrackTrajectory>>(
trajInputTag);
98 auto const& tjHitsAssn =
99 *e.getValidHandle<art::Assns<recob::TrackTrajectory, recob::Hit>>(
trajInputTag);
102 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
108 unsigned int iTraj = 0;
109 for (
auto hitsRange : trajectoriesWithHits) {
112 art::Ptr<recob::TrackTrajectory> traj(inputTrajs, iTraj++);
113 std::vector<art::Ptr<recob::Hit>> inHits;
114 for (art::Ptr<recob::Hit>
const&
hit : hitsRange)
115 inHits.push_back(
hit);
119 std::vector<art::Ptr<recob::Hit>> outHits;
125 bool fitok =
trackMaker_->makeTrack(
detProp, traj, inHits, outTrack, outHits, optionals);
126 if (!fitok)
continue;
131 throw cet::exception(
"TrackProducerFromTrackTrajectory")
132 <<
"Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
136 outputTracks->emplace_back(std::move(outTrack));
137 const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
138 outputTTjTAssn->addSingle(traj, aptr);
140 for (
auto const& trhit : outHits) {
141 outputHits->addSingle(aptr, trhit);
144 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
145 const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
146 const double fErrXYZ[6] = {0};
148 outputSpacePoints->emplace_back(std::move(sp));
149 const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
150 outputHitSpacePointAssn->addSingle(trhit, apsp);
156 for (
auto it = osp.begin(); it != osp.end(); ++it) {
157 outputSpacePoints->emplace_back(std::move(it->first));
158 const art::Ptr<recob::SpacePoint> apsp = spacePointPtrMaker(outputSpacePoints->size() - 1);
159 outputHitSpacePointAssn->addSingle(it->second, apsp);
166 e.put(std::move(outputTracks));
167 e.put(std::move(outputHits));
168 e.put(std::move(outputTTjTAssn));
171 e.put(std::move(outputSpacePoints));
172 e.put(std::move(outputHitSpacePointAssn));
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
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.
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
auto associated_groups(A const &assns)
Helper functions to access associations in order.
TrackProducerFromTrackTrajectory(fhicl::ParameterSet const &p)
TrackProducerFromTrackTrajectory & operator=(TrackProducerFromTrackTrajectory const &)=delete
bool spacePointsFromTrajP_
void produce(art::Event &e) override
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
art::InputTag trajInputTag
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Helper functions to access associations in order.
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: