294 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
295 auto outputHitsMeta =
296 std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
297 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
298 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
300 auto const tid = e.
getProductID<std::vector<recob::Track>>();
303 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
304 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
305 auto const spid = e.
getProductID<std::vector<recob::SpacePoint>>();
311 if (
p_().options().pFromMC() ||
p_().options().dirFromMC()) {
314 for (
unsigned int iMC = 0; iMC < simTracks->size(); ++iMC) {
317 if (mctrack.
PdgCode() != 13)
continue;
318 if (mctrack.
Process() !=
"primary")
continue;
320 mcdir = TVector3(mctrack.
Start().
Momentum().X() * 0.001 / pMC,
331 auto outputPFAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Track>>();
334 if (
p_().options().trackFromPF())
337 if (
p_().options().showerFromPF())
343 for (
unsigned int iPF = 0; iPF < inputPFParticle->size(); ++iPF) {
345 if (
p_().options().trackFromPF()) {
346 const std::vector<art::Ptr<recob::Track>>& tracks =
assocTracks->at(iPF);
347 auto const& tkHitsAssn =
349 const std::vector<art::Ptr<recob::Vertex>>& vertices =
assocVertices->at(iPF);
351 if (
p_().options().pFromCalo()) {
355 for (
unsigned int iTrack = 0; iTrack < tracks.size(); ++iTrack) {
359 const int pId =
setPId(iTrack,
trackId, inputPFParticle->at(iPF).PdgCode());
361 const bool flipDir =
setDirFlip(track, mcdir, &vertices);
364 std::vector<art::Ptr<recob::Hit>> inHits;
365 for (
auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
366 if (it->first == ptrack)
367 inHits.push_back(it->second);
368 else if (inHits.size() > 0)
373 std::vector<art::Ptr<recob::Hit>> outHits;
388 if (!fitok)
continue;
390 if (
p_().options().keepInputTrajectoryPoints()) {
394 outputTracks->emplace_back(std::move(outTrack));
397 for (
auto const& trhit : outHits) {
400 outputHitsMeta->addSingle(aptr, trhit, metadata);
401 outputHits->addSingle(aptr, trhit);
409 if (
p_().options().showerFromPF()) {
411 const std::vector<art::Ptr<recob::Shower>>& showers =
assocShowers->at(iPF);
412 if (showers.size() == 0)
continue;
413 auto const& pfClustersAssn =
415 auto const& clHitsAssn =
417 std::vector<art::Ptr<recob::Hit>> inHits;
418 for (
auto itpf = pfClustersAssn.begin(); itpf != pfClustersAssn.end(); ++itpf) {
419 if (itpf->first == pPF) {
421 for (
auto it = clHitsAssn.
begin(); it != clHitsAssn.
end(); ++it) {
422 if (it->first == clust) inHits.push_back(it->second);
425 else if (inHits.
size() > 0)
428 for (
unsigned int iShower = 0; iShower < showers.size(); ++iShower) {
431 std::vector<art::Ptr<recob::Hit>> outHits;
437 auto pid =
p_().options().pdgId();
438 auto mom =
p_().options().pval();
444 std::vector<recob::TrajectoryPointFlags>(),
451 if (!fitok)
continue;
453 outputTracks->emplace_back(std::move(outTrack));
456 for (
auto const& trhit : outHits) {
459 outputHitsMeta->addSingle(aptr, trhit, metadata);
460 outputHits->addSingle(aptr, trhit);
461 if (
p_().options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
462 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
463 double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
464 double fErrXYZ[6] = {0};
466 outputSpacePoints->emplace_back(std::move(sp));
468 outputHitSpacePointAssn->addSingle(trhit, apsp);
477 e.put(std::move(outputTracks));
478 e.put(std::move(outputHitsMeta));
479 e.put(std::move(outputHits));
480 e.put(std::move(outputPFAssn));
481 if (
p_().options().produceTrackFitHitInfo()) { e.put(std::move(outputHitInfo)); }
482 if (
p_().options().produceSpacePoints()) {
483 e.put(std::move(outputSpacePoints));
484 e.put(std::move(outputHitSpacePointAssn));
493 if (
p_().options().pFromCalo()) {
497 if (
p_().options().idFromCollection()) {
501 for (
unsigned int iTrack = 0; iTrack < inputTracks->size(); ++iTrack) {
507 const bool flipDir =
setDirFlip(track, mcdir);
510 std::vector<art::Ptr<recob::Hit>> inHits;
511 for (
auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
512 if (it->first == ptrack)
513 inHits.push_back(it->second);
514 else if (inHits.size() > 0)
519 std::vector<art::Ptr<recob::Hit>> outHits;
534 if (!fitok)
continue;
536 if (
p_().options().keepInputTrajectoryPoints()) {
540 outputTracks->emplace_back(std::move(outTrack));
543 for (
auto const& trhit : outHits) {
546 outputHitsMeta->addSingle(aptr, trhit, metadata);
547 outputHits->addSingle(aptr, trhit);
548 if (
p_().options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
549 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
550 double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
551 double fErrXYZ[6] = {0};
553 outputSpacePoints->emplace_back(std::move(sp));
555 outputHitSpacePointAssn->addSingle(trhit, apsp);
561 e.put(std::move(outputTracks));
562 e.put(std::move(outputHitsMeta));
563 e.put(std::move(outputHits));
564 if (
p_().options().produceTrackFitHitInfo()) { e.put(std::move(outputHitInfo)); }
565 if (
p_().options().produceSpacePoints()) {
566 e.put(std::move(outputSpacePoints));
567 e.put(std::move(outputHitSpacePointAssn));
const TVector3 & ShowerStart() const
Trajectory_t const & Trajectory() const
Returns the plain trajectory of this object.
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
ProductID getProductID(std::string const &instance_name="") const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
art::InputTag pidInputTag
recob::tracking::SMatrixSym55 SMatrixSym55
bool fitTrack(detinfo::DetectorPropertiesData const &detProp, const recob::TrackTrajectory &traj, int tkID, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, const std::vector< art::Ptr< recob::Hit >> &hits, const double pval, const int pdgid, const bool flipDirection, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, trkmkr::OptionalOutputs &optionals) const
Fit track starting from TrackTrajectory.
art::InputTag simTrackInputTag
art::InputTag pfParticleInputTag
art::InputTag caloInputTag
trkf::TrackKalmanFitter kalmanFitter
std::unique_ptr< art::FindManyP< recob::Vertex > > assocVertices
recob::tracking::Point_t Point_t
const_iterator begin() const
double setMomValue(art::Ptr< recob::Track > ptrack, const std::unique_ptr< art::FindManyP< anab::Calorimetry >> &trackCalo, const double pMC, const int pId) const
EDProductGetter const * productGetter(ProductID const pid) const
int setPId(const unsigned int iTrack, const std::unique_ptr< art::FindManyP< anab::ParticleID >> &trackId, const int pfPid=0) const
art::InputTag trackInputTag
art::InputTag showerInputTag
std::unique_ptr< art::FindManyP< anab::ParticleID > > trackId
const TVector3 & Direction() const
const TLorentzVector & Momentum() const
const_iterator end() const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
const SMatrixSym55 & EndCovarianceLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
std::unique_ptr< art::FindManyP< anab::Calorimetry > > trackCalo
std::unique_ptr< art::FindManyP< recob::Shower > > assocShowers
const std::string & Process() const
const MCStep & Start() const
recob::tracking::Vector_t Vector_t
const SMatrixSym55 & VertexCovarianceLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
bool setDirFlip(const recob::Track &track, TVector3 &mcdir, const std::vector< art::Ptr< recob::Vertex >> *vertices=0) const
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:
std::unique_ptr< art::FindManyP< recob::Track > > assocTracks
void restoreInputPoints(const recob::Trajectory &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits) const