13 #include "canvas/Persistency/Common/FindManyP.h" 47 Name(
"inputPFParticleLabel"),
48 Comment(
"Label of recob::PFParticle Collection to be fit")};
50 Name(
"inputTracksLabel"),
51 Comment(
"Label of recob::Track Collection to be fit")};
53 Name(
"inputShowersLabel"),
54 Comment(
"Label of recob::Shower Collection (associated to PFParticles) to be fit")};
56 Name(
"inputCaloLabel"),
57 Comment(
"Label of anab::Calorimetry Collection, matching inputTracksLabel, to be used for " 58 "initial momentum estimate. Used only if momFromCalo is set to true.")};
61 Comment(
"Label of sim::MCTrack Collection to be used for initial momentum estimate. Used " 62 "only if momFromMC is set to true.")};
64 Name(
"inputPidLabel"),
65 Comment(
"Label of anab::ParticleID Collection, matching inputTracksLabel, to be used for " 73 Comment(
"If true extract tracks from inputPFParticleLabel " 74 "collection, if false from inputTracksLabel.")};
77 Comment(
"If true extract showers from inputPFParticleLabel collection.")};
79 Name(
"momFromMSChi2"),
80 Comment(
"Flag used to get initial momentum estimate from " 81 "trkf::TrackMomentumCalculator::GetMomentumMultiScatterChi2().")};
83 Comment(
"Flag used to get initial momentum estimate from " 84 "trkf::TrackMomentumCalculator::GetTrackMomentum().")};
87 Comment(
"Flag used to get initial momentum estimate from inputCaloLabel collection.")};
90 Comment(
"Flag used to get initial momentum estimate from inputMCLabel collection.")};
92 Name(
"momentumInGeV"),
93 Comment(
"Fixed momentum estimate value, to be used when momFromCalo, momFromMSChi2, " 94 "momFromLength and momFromMC are all false, or if the estimate is not available.")};
96 Comment(
"Flag used to get particle ID estimate from corresponding " 97 "PFParticle. Needs trackFromPF=true.")};
99 Name(
"idFromCollection"),
100 Comment(
"Flag used to get particle ID estimate from inputPidLabel collection.")};
103 Comment(
"Default particle id hypothesis in case no valid id is provided either via " 104 "PFParticle or in the ParticleId collection.")};
106 Name(
"dirFromVtxPF"),
107 Comment(
"Assume track direction from Vertex in PFParticle. Needs trackFromPF=true.")};
110 Comment(
"Assume track direction from as the one giving positive " 111 "dot product with vector specified by dirVec.")};
113 Comment(
"Fhicl sequence defining the vector used when " 114 "dirFromVec=true. It must have 3 elements.")};
116 Name(
"alwaysInvertDir"),
117 Comment(
"If true, fit all tracks from end to vertex assuming inverted direction.")};
119 Name(
"produceTrackFitHitInfo"),
120 Comment(
"Option to produce (or not) the detailed TrackFitHitInfo.")};
122 Name(
"produceSpacePoints"),
123 Comment(
"Option to produce (or not) the associated SpacePoints.")};
125 Name(
"keepInputTrajectoryPoints"),
126 Comment(
"Option to keep positions and directions from input trajectory/track. The fit will " 127 "provide only covariance matrices, chi2, ndof, particle Id and absolute momentum. " 128 "It may also modify the trajectory point flags. In order to avoid inconsistencies, " 129 "it has to be used with the following fitter options all set to false: " 130 "sortHitsByPlane, sortOutputHitsMinLength, skipNegProp.")};
168 std::unique_ptr<art::FindManyP<anab::Calorimetry>>
trackCalo;
169 std::unique_ptr<art::FindManyP<anab::ParticleID>>
trackId;
175 const std::unique_ptr<art::FindManyP<anab::Calorimetry>>& trackCalo,
177 const int pId)
const;
178 int setPId(
const unsigned int iTrack,
179 const std::unique_ptr<art::FindManyP<anab::ParticleID>>& trackId,
180 const int pfPid = 0)
const;
198 ,
inputFromPF{
p_().options().trackFromPF() ||
p_().options().showerFromPF()}
215 produces<std::vector<recob::Track>>();
216 produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
217 produces<art::Assns<recob::Track, recob::Hit>>();
218 if (
inputFromPF) { produces<art::Assns<recob::PFParticle, recob::Track>>(); }
219 if (
p_().options().produceTrackFitHitInfo()) {
220 produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
222 if (
p_().options().produceSpacePoints()) {
223 produces<std::vector<recob::SpacePoint>>();
224 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
228 if (
p_().options().trackFromPF() == 0 &&
p_().options().idFromPF())
230 <<
"Incompatible configuration parameters: cannot use idFromPF=true with trackFromPF=false." 232 if (
p_().options().trackFromPF() == 0 &&
p_().options().dirFromVtxPF())
234 <<
"Incompatible configuration parameters: cannot use dirFromVtxPF=true with " 238 unsigned int nIds = 0;
239 if (
p_().options().idFromPF()) nIds++;
240 if (
p_().options().idFromCollection()) nIds++;
243 <<
"Incompatible configuration parameters: only at most one can be set to true among " 244 "idFromPF and idFromCollection." 248 unsigned int nDirs = 0;
249 if (
p_().
options().dirFromVtxPF()) nDirs++;
251 if (
p_().
options().dirFromVec()) nDirs++;
252 if (
p_().
options().alwaysInvertDir()) nDirs++;
255 <<
"Incompatible configuration parameters: only at most one can be set to true among " 256 "dirFromVtxPF, dirFromMC, dirFromVec, and alwaysInvertDir." 260 unsigned int nPFroms = 0;
261 if (
p_().
options().pFromCalo()) nPFroms++;
262 if (
p_().
options().pFromMSChi2()) nPFroms++;
263 if (
p_().
options().pFromLength()) nPFroms++;
267 <<
"Incompatible configuration parameters: only at most one can be set to true among " 268 "pFromCalo, pFromMSChi2, pFromLength, and pFromMC." 272 if (
p_().
options().keepInputTrajectoryPoints()) {
273 if (
p_().fitter().sortHitsByPlane() ||
p_().fitter().sortOutputHitsMinLength() ||
274 p_().fitter().skipNegProp()) {
276 <<
"Incompatible configuration parameters: keepInputTrajectoryPoints needs the following " 277 "fitter options all set to false: sortHitsByPlane, sortOutputHitsMinLength, skipNegProp." 283 if (nPFroms > 0 || nIds > 0 || nDirs > 0) {
285 <<
"Incompatible configuration parameters: showerFromPF currently does not support " 286 "optional momentum values, particle hypotheses and directions." 295 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
296 auto outputHitsMeta =
297 std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
298 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
299 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
301 auto const tid = e.
getProductID<std::vector<recob::Track>>();
304 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
305 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
306 auto const spid = e.
getProductID<std::vector<recob::SpacePoint>>();
315 for (
unsigned int iMC = 0; iMC < simTracks->size(); ++iMC) {
318 if (mctrack.
PdgCode() != 13)
continue;
319 if (mctrack.
Process() !=
"primary")
continue;
321 mcdir = TVector3(mctrack.
Start().
Momentum().X() * 0.001 / pMC,
332 auto outputPFAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Track>>();
335 if (
p_().options().trackFromPF())
337 std::make_unique<art::FindManyP<recob::Track>>(inputPFParticle, e,
pfParticleInputTag);
338 if (
p_().options().showerFromPF())
340 std::make_unique<art::FindManyP<recob::Shower>>(inputPFParticle, e,
showerInputTag);
344 for (
unsigned int iPF = 0; iPF < inputPFParticle->size(); ++iPF) {
346 if (
p_().options().trackFromPF()) {
348 auto const& tkHitsAssn =
350 const std::vector<art::Ptr<recob::Vertex>>& vertices =
assocVertices->at(iPF);
356 for (
unsigned int iTrack = 0; iTrack < tracks.size(); ++iTrack) {
360 const int pId =
setPId(iTrack,
trackId, inputPFParticle->at(iPF).PdgCode());
362 const bool flipDir =
setDirFlip(track, mcdir, &vertices);
365 std::vector<art::Ptr<recob::Hit>> inHits;
366 for (
auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
367 if (it->first == ptrack)
368 inHits.push_back(it->second);
369 else if (inHits.size() > 0)
374 std::vector<art::Ptr<recob::Hit>> outHits;
389 if (!fitok)
continue;
391 if (
p_().options().keepInputTrajectoryPoints()) {
395 outputTracks->emplace_back(
std::move(outTrack));
398 for (
auto const& trhit : outHits) {
401 outputHitsMeta->addSingle(aptr, trhit, metadata);
402 outputHits->addSingle(aptr, trhit);
410 if (
p_().options().showerFromPF()) {
413 if (showers.size() == 0)
continue;
414 auto const& pfClustersAssn =
416 auto const& clHitsAssn =
418 std::vector<art::Ptr<recob::Hit>> inHits;
419 for (
auto itpf = pfClustersAssn.begin(); itpf != pfClustersAssn.end(); ++itpf) {
420 if (itpf->first == pPF) {
422 for (
auto it = clHitsAssn.
begin(); it != clHitsAssn.
end(); ++it) {
423 if (it->first == clust) inHits.push_back(it->second);
426 else if (inHits.
size() > 0)
429 for (
unsigned int iShower = 0; iShower < showers.size(); ++iShower) {
432 std::vector<art::Ptr<recob::Hit>> outHits;
438 auto pid =
p_().options().pdgId();
439 auto mom =
p_().options().pval();
445 std::vector<recob::TrajectoryPointFlags>(),
452 if (!fitok)
continue;
454 outputTracks->emplace_back(
std::move(outTrack));
457 for (
auto const& trhit : outHits) {
460 outputHitsMeta->addSingle(aptr, trhit, metadata);
461 outputHits->addSingle(aptr, trhit);
462 if (
p_().
options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
463 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
464 double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
465 double fErrXYZ[6] = {0};
467 outputSpacePoints->emplace_back(
std::move(sp));
469 outputHitSpacePointAssn->addSingle(trhit, apsp);
483 if (
p_().
options().produceSpacePoints()) {
485 e.put(
std::move(outputHitSpacePointAssn));
494 if (
p_().options().pFromCalo()) {
498 if (
p_().options().idFromCollection()) {
502 for (
unsigned int iTrack = 0; iTrack < inputTracks->size(); ++iTrack) {
508 const bool flipDir =
setDirFlip(track, mcdir);
511 std::vector<art::Ptr<recob::Hit>> inHits;
512 for (
auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
513 if (it->first == ptrack)
514 inHits.push_back(it->second);
515 else if (inHits.size() > 0)
520 std::vector<art::Ptr<recob::Hit>> outHits;
535 if (!fitok)
continue;
537 if (
p_().options().keepInputTrajectoryPoints()) {
541 outputTracks->emplace_back(
std::move(outTrack));
544 for (
auto const& trhit : outHits) {
547 outputHitsMeta->addSingle(aptr, trhit, metadata);
548 outputHits->addSingle(aptr, trhit);
549 if (
p_().
options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
550 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
551 double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
552 double fErrXYZ[6] = {0};
554 outputSpacePoints->emplace_back(
std::move(sp));
556 outputHitSpacePointAssn->addSingle(trhit, apsp);
566 if (
p_().
options().produceSpacePoints()) {
581 std::vector<Point_t> positions(np);
582 std::vector<Vector_t> momenta(np);
583 std::vector<recob::TrajectoryPointFlags> outFlags(np);
585 for (
unsigned int p = 0;
p < np; ++
p) {
588 auto op = flag.fromHit();
591 auto mask = flag.mask();
607 for (
auto h : inHits)
608 outHits.push_back(
h);
614 const std::unique_ptr<art::FindManyP<anab::Calorimetry>>&
trackCalo,
618 double result =
p_().options().pval();
623 else if (
p_().options().pFromCalo()) {
625 const std::vector<art::Ptr<anab::Calorimetry>>&
calo =
trackCalo->at(ptrack.
key());
626 double sumenergy = 0.;
628 for (
auto caloit : calo) {
629 if (caloit->KineticEnergy() > 0.) {
630 sumenergy += caloit->KineticEnergy();
634 if (nviews != 0 && sumenergy != 0.) {
636 result = sumenergy / (nviews * 1000.);
639 else if (
p_().options().pFromMC() && pMC > 0.) {
647 const unsigned int iTrack,
648 const std::unique_ptr<art::FindManyP<anab::ParticleID>>&
trackId,
649 const int pfPid)
const 675 if (
p_().
options().alwaysInvertDir()) {
return true; }
678 if ((mcdir.X() *
tdir.X() + mcdir.Y() *
tdir.Y() + mcdir.Z() *
tdir.Z()) < 0.) result =
true;
680 else if (
p_().options().dirFromVec()) {
681 std::array<float, 3>
dir =
p_().options().dirVec();
683 if ((dir[0] *
tdir.X() + dir[1] *
tdir.Y() + dir[2] *
tdir.Z()) < 0.) result =
true;
685 else if (
p_().options().trackFromPF() &&
p_().options().dirFromVtxPF() && vertices->size() > 0) {
688 (*vertices)[0]->XYZ(xyz);
691 if (((xyz[0] - te.X()) * (xyz[0] - te.X()) + (xyz[1] - te.Y()) * (xyz[1] - te.Y()) +
692 (xyz[2] - te.Z()) * (xyz[2] - te.Z())) >
693 ((xyz[0] - tv.X()) * (xyz[0] - tv.X()) + (xyz[1] - tv.Y()) * (xyz[1] - tv.Y()) +
694 (xyz[2] - tv.Z()) * (xyz[2] - tv.Z())))
const TVector3 & ShowerStart() const
double VertexMomentum() const
Trajectory_t const & Trajectory() const
Returns the plain trajectory of this object.
Fit tracks using Kalman Filter fit+smooth.
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
ProductID getProductID(std::string const &instance_name="") const
double GetMomentumMultiScatterChi2(art::Ptr< recob::Track > const &trk)
static constexpr Flag_t NoPoint
The trajectory point is not defined.
recob::tracking::Point_t Point_t
recob::tracking::Vector_t Vector_t
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
art::InputTag pidInputTag
EDProducer(fhicl::ParameterSet const &pset)
recob::tracking::SMatrixSym55 SMatrixSym55
ChannelGroupService::Name Name
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
TrackStatePropagator prop
Vector_t VertexDirection() const
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.
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
art::InputTag simTrackInputTag
art::InputTag pfParticleInputTag
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
art::InputTag caloInputTag
trkf::TrackKalmanFitter kalmanFitter
std::unique_ptr< art::FindManyP< recob::Vertex > > assocVertices
const_iterator begin() const
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
double setMomValue(art::Ptr< recob::Track > ptrack, const std::unique_ptr< art::FindManyP< anab::Calorimetry >> &trackCalo, const double pMC, const int pId) const
double Length(size_t p=0) const
Access to various track properties.
#define DEFINE_ART_MODULE(klass)
trkf::TrackMomentumCalculator tmc
A trajectory in space reconstructed from hits.
EDProductGetter const * productGetter(ProductID const pid) const
key_type key() const noexcept
int setPId(const unsigned int iTrack, const std::unique_ptr< art::FindManyP< anab::ParticleID >> &trackId, const int pfPid=0) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
art::InputTag trackInputTag
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
art::InputTag showerInputTag
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::unique_ptr< art::FindManyP< anab::ParticleID > > trackId
const TVector3 & Direction() const
KalmanFilterFinalTrackFitter(Parameters const &p)
Class def header for mctrack data container.
void produce(art::Event &e) override
Point_t const & Vertex() const
Returns the position of the first valid point of the trajectory [cm].
const TLorentzVector & Momentum() const
const_iterator end() const
A trajectory in space reconstructed from hits.
KalmanFilterFinalTrackFitter & operator=(KalmanFilterFinalTrackFitter const &)=delete
Declaration of signal hit object.
const SMatrixSym55 & EndCovarianceLocal5D() const
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
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
const std::string & Process() const
Provides recob::Track data product.
PointFlags_t const & FlagsAtPoint(size_t i) const
const MCStep & Start() const
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
const SMatrixSym55 & VertexCovarianceLocal5D() const
bool setDirFlip(const recob::Track &track, TVector3 &mcdir, const std::vector< art::Ptr< recob::Vertex >> *vertices=0) const
Struct holding optional TrackMaker outputs.
Set of flags pertaining a point of the track.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
double GetTrackMomentum(double trkrange, int pdg) const
cet::coded_exception< error, detail::translate > exception
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