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;
175 inHits.push_back(
hit);
178 recob::
Track outTrack;
179 std::
vector<art::Ptr<recob::Hit>> outHits;
180 trkmkr::OptionalOutputs optionals;
190 if (outTrack.NumberTrajectoryPoints() != outHits.
size()) {
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);
220 auto osp = optionals.spacePointHitPairs();
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);
228 if (
doTrackFitHitInfo_) { outputHitInfo->emplace_back(optionals.trackFitHitInfos()); }
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) {
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);
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));
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
bool spacePointsFromTrajP_
then if[["$THISISATEST"==1]]
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.
std::size_t size(FixedBins< T, C > const &) noexcept
process_name use argoneut_mc_hitfinder track
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
auto associated_groups(A const &assns)
Helper functions to access associations in order.
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.
for($it=0;$it< $RaceTrack_number;$it++)
std::vector< PointFlags_t > Flags_t
Type of point flag list.
art::InputTag clsInputTag
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
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: