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 "art/Utilities/make_tool.h"
9 #include "canvas/Persistency/Common/FindManyP.h"
10 #include "canvas/Utilities/InputTag.h"
11 #include "cetlib_except/exception.h"
12 #include "fhiclcpp/ParameterSet.h"
13 #include "messagefacility/MessageLogger/MessageLogger.h"
67 void produce(art::Event&
e)
override;
83 , trackMaker_{art::make_tool<trkmkr::TrackMaker>(
p.get<fhicl::ParameterSet>(
"trackMaker"))}
84 , pfpInputTag{
p.get<art::InputTag>(
"inputCollection")}
85 , doTrackFitHitInfo_{
p.get<
bool>(
"doTrackFitHitInfo")}
86 , doSpacePoints_{
p.get<
bool>(
"doSpacePoints")}
87 , spacePointsFromTrajP_{
p.get<
bool>(
"spacePointsFromTrajP")}
88 , trackFromPF_{
p.get<
bool>(
"trackFromPF")}
89 , showerFromPF_{
p.get<
bool>(
"showerFromPF")}
90 , seedFromPF_{
p.get<
bool>(
"seedFromPF")}
93 if (
p.has_key(
"trackInputTag"))
94 trkInputTag =
p.get<art::InputTag>(
"trackInputTag");
96 trkInputTag = pfpInputTag;
97 if (
p.has_key(
"showerInputTag"))
98 shwInputTag =
p.get<art::InputTag>(
"showerInputTag");
100 shwInputTag = pfpInputTag;
101 if (
p.has_key(
"clusterInputTag"))
102 clsInputTag =
p.get<art::InputTag>(
"clusterInputTag");
104 clsInputTag = pfpInputTag;
105 produces<std::vector<recob::Track>>();
106 produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
107 produces<art::Assns<recob::PFParticle, recob::Track>>();
108 if (doTrackFitHitInfo_) produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
109 if (doSpacePoints_) {
110 produces<std::vector<recob::SpacePoint>>();
111 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
119 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
120 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
121 auto outputPfpTAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Track>>();
122 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
123 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
124 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
127 art::PtrMaker<recob::Track> trackPtrMaker(e);
128 art::PtrMaker<recob::SpacePoint>* spacePointPtrMaker =
nullptr;
129 if (
doSpacePoints_) spacePointPtrMaker =
new art::PtrMaker<recob::SpacePoint>(
e);
132 art::ValidHandle<std::vector<recob::PFParticle>> inputPfps =
133 e.getValidHandle<std::vector<recob::PFParticle>>(
pfpInputTag);
134 std::unique_ptr<art::FindManyP<recob::Track>> assocTracks;
135 art::Assns<recob::Track, recob::Hit> tkHitsAssn;
136 std::unique_ptr<art::FindManyP<recob::Shower>> assocShowers;
137 std::unique_ptr<art::FindManyP<recob::Seed>> assocSeeds;
139 assocTracks = std::unique_ptr<art::FindManyP<recob::Track>>(
140 new art::FindManyP<recob::Track>(inputPfps,
e,
trkInputTag));
141 tkHitsAssn = *e.getValidHandle<art::Assns<recob::Track, recob::Hit>>(
trkInputTag);
144 assocShowers = std::unique_ptr<art::FindManyP<recob::Shower>>(
145 new art::FindManyP<recob::Shower>(inputPfps,
e,
shwInputTag));
147 assocSeeds = std::unique_ptr<art::FindManyP<recob::Seed>>(
148 new art::FindManyP<recob::Seed>(inputPfps,
e,
pfpInputTag));
151 std::unique_ptr<art::FindManyP<recob::Cluster>> assocClusters =
152 std::unique_ptr<art::FindManyP<recob::Cluster>>(
153 new art::FindManyP<recob::Cluster>(inputPfps,
e,
pfpInputTag));
154 auto const& clHitsAssn = *e.getValidHandle<art::Assns<recob::Cluster, recob::Hit>>(
clsInputTag);
160 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
163 for (
unsigned int iPfp = 0; iPfp < inputPfps->size(); ++iPfp) {
164 const art::Ptr<recob::PFParticle> pfp(inputPfps, iPfp);
167 const std::vector<art::Ptr<recob::Track>>&
tracks = assocTracks->at(iPfp);
169 for (art::Ptr<recob::Track>
const&
track : tracks) {
172 std::vector<art::Ptr<recob::Hit>> inHits;
174 for (art::Ptr<recob::Hit>
const&
hit : hitsRange)
175 inHits.push_back(
hit);
179 std::vector<art::Ptr<recob::Hit>> outHits;
186 if (!fitok)
continue;
191 throw cet::exception(
"TrackProducerFromPFParticle")
192 <<
"Produced recob::Track required to have 1-1 correspondance between hits and "
197 outputTracks->emplace_back(std::move(outTrack));
198 const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
199 outputPfpTAssn->addSingle(pfp, aptr);
201 for (
auto const& trhit : outHits) {
203 outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(),
204 -std::numeric_limits<double>::max());
205 outputHits->addSingle(aptr, trhit, metadata);
208 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
209 const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
210 const double fErrXYZ[6] = {0};
212 outputSpacePoints->emplace_back(std::move(sp));
213 const art::Ptr<recob::SpacePoint> apsp =
214 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
215 outputHitSpacePointAssn->addSingle(trhit, apsp);
221 for (
auto it = osp.begin(); it != osp.end(); ++it) {
222 outputSpacePoints->emplace_back(std::move(it->first));
223 const art::Ptr<recob::SpacePoint> apsp =
224 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
225 outputHitSpacePointAssn->addSingle(it->second, apsp);
235 const std::vector<art::Ptr<recob::Shower>>& showers = assocShowers->at(iPfp);
237 if (showers.size() != 1)
continue;
240 std::vector<art::Ptr<recob::Hit>> inHits;
241 const std::vector<art::Ptr<recob::Cluster>> clustersRange = assocClusters->at(iPfp);
242 for (art::Ptr<recob::Cluster>
const&
cluster : clustersRange) {
245 for (art::Ptr<recob::Hit>
const&
hit : hitsRange)
246 inHits.push_back(
hit);
249 for (
unsigned int iShower = 0; iShower < showers.size(); ++iShower) {
252 art::Ptr<recob::Shower>
shower = showers[iShower];
254 shower->ShowerStart().X(), shower->ShowerStart().Y(), shower->ShowerStart().Z());
256 shower->Direction().X(), shower->Direction().Y(), shower->Direction().Z());
258 if (shower->Energy().size() == 3) mom = shower->Energy()[2] * 0.001;
259 std::vector<recob::tracking::Point_t>
p;
260 std::vector<recob::tracking::Vector_t> d;
261 for (
unsigned int i = 0; i < inHits.size(); ++i) {
263 d.push_back(mom *
dir);
270 std::vector<art::Ptr<recob::Hit>> outHits;
278 if (!fitok)
continue;
283 throw cet::exception(
"TrackProducerFromPFParticle")
284 <<
"Produced recob::Track required to have 1-1 correspondance between hits and "
289 outputTracks->emplace_back(std::move(outTrack));
290 const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
291 outputPfpTAssn->addSingle(pfp, aptr);
293 for (
auto const& trhit : outHits) {
295 outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(),
296 -std::numeric_limits<double>::max());
297 outputHits->addSingle(aptr, trhit, metadata);
300 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
301 const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
302 const double fErrXYZ[6] = {0};
304 outputSpacePoints->emplace_back(std::move(sp));
305 const art::Ptr<recob::SpacePoint> apsp =
306 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
307 outputHitSpacePointAssn->addSingle(trhit, apsp);
313 for (
auto it = osp.begin(); it != osp.end(); ++it) {
314 outputSpacePoints->emplace_back(std::move(it->first));
315 const art::Ptr<recob::SpacePoint> apsp =
316 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
317 outputHitSpacePointAssn->addSingle(it->second, apsp);
328 const std::vector<art::Ptr<recob::Seed>>&
seeds = assocSeeds->at(iPfp);
330 if (seeds.size() != 1)
continue;
333 std::vector<art::Ptr<recob::Hit>> inHits;
334 const std::vector<art::Ptr<recob::Cluster>> clustersRange = assocClusters->at(iPfp);
335 for (art::Ptr<recob::Cluster>
const&
cluster : clustersRange) {
338 for (art::Ptr<recob::Hit>
const&
hit : hitsRange)
339 inHits.push_back(
hit);
341 if (inHits.size() < 4)
continue;
343 for (
unsigned int iS = 0; iS < seeds.size(); ++iS) {
346 art::Ptr<recob::Seed>
seed = seeds[iS];
348 seed->GetPoint(p0, pe);
350 seed->GetDirection(d0, de);
353 std::vector<recob::tracking::Point_t>
p;
354 std::vector<recob::tracking::Vector_t> d;
355 for (
unsigned int i = 0; i < inHits.size(); ++i) {
364 std::vector<art::Ptr<recob::Hit>> outHits;
372 if (!fitok)
continue;
377 throw cet::exception(
"TrackProducerFromPFParticle")
378 <<
"Produced recob::Track required to have 1-1 correspondance between hits and "
383 outputTracks->emplace_back(std::move(outTrack));
384 const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size() - 1);
385 outputPfpTAssn->addSingle(pfp, aptr);
387 for (
auto const& trhit : outHits) {
389 outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(),
390 -std::numeric_limits<double>::max());
391 outputHits->addSingle(aptr, trhit, metadata);
394 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
395 const double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
396 const double fErrXYZ[6] = {0};
398 outputSpacePoints->emplace_back(std::move(sp));
399 const art::Ptr<recob::SpacePoint> apsp =
400 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
401 outputHitSpacePointAssn->addSingle(trhit, apsp);
407 for (
auto it = osp.begin(); it != osp.end(); ++it) {
408 outputSpacePoints->emplace_back(std::move(it->first));
409 const art::Ptr<recob::SpacePoint> apsp =
410 (*spacePointPtrMaker)(outputSpacePoints->size() - 1);
411 outputHitSpacePointAssn->addSingle(it->second, apsp);
421 e.put(std::move(outputTracks));
422 e.put(std::move(outputHits));
423 e.put(std::move(outputPfpTAssn));
426 e.put(std::move(outputSpacePoints));
427 e.put(std::move(outputHitSpacePointAssn));
bool spacePointsFromTrajP_
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
art::InputTag pfpInputTag
ClusterModuleLabel join with tracks
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
process_name use argoneut_mc_hitfinder track
TrackProducerFromPFParticle(fhicl::ParameterSet const &p)
auto associated_groups(A const &assns)
Helper functions to access associations in order.
void produce(art::Event &e) override
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
A trajectory in space reconstructed from hits.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
Declaration of cluster object.
art::InputTag clsInputTag
Produce a reco::Track collection, as a result of the fit of an existing recob::PFParticle collection...
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
std::vector< TrajPoint > seeds
auto groupByIndex(Groups &&groups, std::size_t index) -> decltype(auto)
Returns the group within groups with the specified index.
art::InputTag shwInputTag
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Helper functions to access associations in order.
TrackProducerFromPFParticle & operator=(TrackProducerFromPFParticle const &)=delete
art::InputTag trkInputTag
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
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: