7 const art::ValidHandle<std::vector<recob::PFParticle>>& inputPFParticle,
8 const std::unique_ptr<art::FindManyP<recob::Track>>& assocTracks)
const
11 art::Ptr<recob::PFParticle> pfp(inputPFParticle, iPF);
13 std::cout <<
"pfp#" << iPF <<
" PdgCode=" << pfp->PdgCode() <<
" IsPrimary=" << pfp->IsPrimary()
14 <<
" NumDaughters=" << pfp->NumDaughters() << std::endl;
15 if (pfp->IsPrimary() ==
false || pfp->NumDaughters() < 2)
return VertexWrapper();
19 auto& pfd = pfp->Daughters();
20 for (
auto ipfd : pfd) {
21 vector<art::Ptr<recob::Track>> pftracks = assocTracks->at(ipfd);
22 for (
auto t : pftracks) {
34 const std::vector<art::Ptr<recob::Track>>& arttracks)
const
37 for (
auto t : arttracks) {
47 if (
debugLevel > 0)
std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
54 [](std::reference_wrapper<const recob::Track>
a, std::reference_wrapper<const recob::Track> b) {
55 return a.get().CountValidPoints() > b.get().CountValidPoints();
59 unsigned int tk0 = tracks.size();
60 unsigned int tk1 = tracks.size();
62 for (
unsigned int i = 0; i < tracks.size() - 1; i++) {
63 for (
unsigned int j = i + 1; j < tracks.size(); j++) {
65 (tracks[i].get().Trajectory().Start() - tracks[j].get().Trajectory().Start()).Mag2();
67 std::cout <<
"test i=" << i <<
" start=" << tracks[i].get().Trajectory().Start()
68 <<
" j=" << j <<
" start=" << tracks[j].get().Trajectory().Start() <<
" d=" << d
69 <<
" mind=" << mind <<
" tk0=" << tk0 <<
" tk1=" << tk1 << std::endl;
77 if (tk0 > 1 || tk1 > 1) {
78 if (tk0 > 1 && tk1 > 1) {
79 std::swap(tracks[0], tracks[tk0]);
80 std::swap(tracks[1], tracks[tk1]);
82 if (tk0 == 0) std::swap(tracks[1], tracks[tk1]);
83 if (tk0 == 1) std::swap(tracks[0], tracks[tk1]);
84 if (tk1 == 0) std::swap(tracks[1], tracks[tk0]);
85 if (tk1 == 1) std::swap(tracks[0], tracks[tk0]);
93 for (
auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
94 auto sipv =
sip(detProp, vtx, *tk);
96 if (sipv >
sipCut)
continue;
105 const std::vector<art::Ptr<recob::Track>>& arttracks,
109 for (
auto t : arttracks) {
110 tracks.push_back(*t);
120 if (
debugLevel > 0)
std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
127 if (vtx.isValid() ==
false || vtx.tracks().size() < 2)
return vtx;
130 for (
auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
131 auto sipv =
sip(detProp, vtx, *tk);
133 if (sipv >
sipCut)
continue;
139 std::pair<trkf::TrackState, double>
150 std::cout <<
"par1=" << par1 << std::endl;
151 std::cout <<
"par2=" << par2 << std::endl;
152 std::cout <<
"deltapar=" << deltapar << std::endl;
154 std::cout <<
"cov1=\n" << cov1 << std::endl;
155 std::cout <<
"cov2=\n" << cov2 << std::endl;
156 std::cout <<
"covsum=\n" << covsum << std::endl;
161 bool d1ok = cov1.Det2(det1);
162 std::cout <<
"cov1 det=" << det1 <<
" ok=" << d1ok << std::endl;
164 bool d2ok = cov2.Det2(det2);
165 std::cout <<
"cov2 det=" << det2 <<
" ok=" << d2ok << std::endl;
167 bool dsok = covsum.Det2(detsum);
168 std::cout <<
"covsum det=" << detsum <<
" ok=" << dsok << std::endl;
171 bool invertok = covsum.Invert();
175 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
178 auto k = cov1 * covsum;
181 std::cout <<
"inverted covsum=\n" << covsum << std::endl;
186 SMatrixSym22 vtxcov22 = cov1 - ROOT::Math::SimilarityT(cov1, covsum);
189 std::cout <<
"vtxpar2=" << vtxpar2 << std::endl;
190 std::cout <<
"vtxcov22=\n" << vtxcov22 << std::endl;
193 auto chi2 = ROOT::Math::Similarity(deltapar, covsum);
195 SVector5 vtxpar5(vtxpar2[0], vtxpar2[1], 0, 0, 0);
197 vtxcov55.Place_at(vtxcov22, 0, 0);
198 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
200 return std::make_pair(vtxstate,
chi2);
217 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1 <<
" length=" << track.
Length()
220 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2 <<
" length=" << other.
Length()
225 const auto dpos = start1 - start2;
226 const auto dotd1d2 = dir1.Dot(dir2);
227 const auto dotdpd1 = dpos.Dot(dir1);
228 const auto dotdpd2 = dpos.Dot(dir2);
229 const auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
230 const auto dist1 = (dotd1d2 * dist2 - dotdpd1);
233 std::cout <<
"track1 pca=" << start1 + dist1 * dir1 <<
" dist=" << dist1 << std::endl;
234 std::cout <<
"track2 pca=" << start2 + dist2 * dir2 <<
" dist=" << dist2 << std::endl;
247 state1 =
prop->propagateToPlane(
250 std::cout <<
"failed propagation, return track1 start pos=" << track.
Start() << std::endl;
259 state1.position(), state1.covariance6D().Sub<
SMatrixSym33>(0, 0), 0, 0, track);
277 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1 <<
" length=" << tk1.
Length()
280 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2 <<
" length=" << tk2.
Length()
285 auto dpos = start1 - start2;
286 auto dotd1d2 = dir1.Dot(dir2);
288 auto dotdpd1 = dpos.Dot(dir1);
289 auto dotdpd2 = dpos.Dot(dir2);
291 auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
292 auto dist1 = (dotd1d2 * dist2 - dotdpd1);
301 state1 =
prop->propagateToPlane(
304 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
315 state2 =
prop->propagateToPlane(
318 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
326 std::cout <<
"track1 pca=" << start1 + dist1 * dir1 <<
" dist=" << dist1 << std::endl;
327 std::cout <<
"track2 pca=" << start2 + dist2 * dir2 <<
" dist=" << dist2 << std::endl;
337 auto dcp = state1.position() - state2.position();
341 std::cout <<
"cov1=" << cov1 << std::endl;
342 std::cout <<
"cov2=" << cov2 << std::endl;
345 SVector2 par1(state1.parameters()[0], state1.parameters()[1]);
346 SVector2 par2(state2.parameters()[0], state2.parameters()[1]);
350 std::cout <<
"failed inversion, return track1 start pos=" << tk1.
Start() << std::endl;
359 was.first.position(), was.first.covariance6D().Sub<
SMatrixSym33>(0, 0), was.second, ndof);
366 std::cout <<
"chi2=" << was.second << std::endl;
383 auto dist =
dir.Dot(vtxpos - start);
396 std::cout <<
"input vtx=" << vtxpos << std::endl;
397 std::cout <<
"input cov=\n" << vtxcov << std::endl;
398 std::cout <<
"track pca=" << start +
dist * dir <<
" dist=" <<
dist << std::endl;
403 SVector6 vtxpar6(vtxpos.X(), vtxpos.Y(), vtxpos.Z(), 0, 0, 0);
405 vtxcov66.Place_at(vtxcov, 0, 0);
408 SVector2 par1(vtxpar5[0], vtxpar5[1]);
417 std::cout <<
"vtxpar5=" << vtxpar5 << std::endl;
418 std::cout <<
"state.parameters()=" <<
state.parameters() << std::endl;
419 std::cout <<
"vtx covariance=\n" << vtxcov66 << std::endl;
420 std::cout <<
"trk covariance=\n" <<
state.covariance6D() << std::endl;
421 std::cout <<
"cov1=\n" << cov1 << std::endl;
422 std::cout <<
"cov2=\n" << cov2 << std::endl;
446 was.first.position(), was.first.covariance6D().Sub<
SMatrixSym33>(0, 0), was.second, ndof, tk);
451 std::cout <<
"add chi2=" << was.second << std::endl;
461 bool invertok = covsum.Invert();
462 if (!invertok)
return -1.;
464 return ROOT::Math::Similarity(deltapar, covsum);
479 return std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
495 deltapar /= std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
497 return std::sqrt(ROOT::Math::Similarity(deltapar, covsum));
534 if (ittoerase == vtx.
tracksSize()) {
return vtx; }
547 if (ittoerase == vtx.
tracksSize()) {
return chi2(detProp, vtx, tk); }
560 if (ittoerase == vtx.
tracksSize()) {
return ip(detProp, vtx, tk); }
586 if (ittoerase == vtx.
tracksSize()) {
return sip(detProp, vtx, tk); }
606 std::vector<recob::VertexAssnMeta>
613 std::vector<recob::VertexAssnMeta>
616 const std::vector<art::Ptr<recob::Track>>& arttracks)
619 for (
auto t : arttracks)
620 tracks.push_back(*t);
624 std::vector<recob::VertexAssnMeta>
629 std::vector<recob::VertexAssnMeta> result;
630 for (
auto tk : trks) {
640 std::cout <<
"got unbiased vertex with ntracks=" << ubvtx.tracksSize()
641 <<
" isValid=" << ubvtx.isValid() << std::endl;
642 if (ubvtx.isValid()) {
643 d =
pDist(ubvtx, tk.get());
649 std::cout <<
"unbiasedVertex d=" << d <<
" i=" << i <<
" e=" << e <<
" c=" << c
655 d =
pDist(fakevtx, tk.get());
662 std::cout <<
"closestPointAlongTrack d=" << d <<
" i=" << i <<
" e=" << e <<
" c=" << c
void addTrackToVertex(detinfo::DetectorPropertiesData const &detProp, VertexWrapper &vtx, const recob::Track &tk) const
const recob::tracking::Point_t & position() const
Class for track parameters (and errors) defined on a recob::tracking::Plane.
Vector_t const & direction() const
Reference direction orthogonal to the plane.
std::pair< TrackState, double > weightedAverageState(ParsCovsOnPlane &pcop) const
TrackRefVec tracksWithoutElement(size_t element) const
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
double sip(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
ClusterModuleLabel join with tracks
const recob::tracking::SMatrixSym33 & covariance() const
VertexWrapper closestPointAlongTrack(detinfo::DetectorPropertiesData const &detProp, const recob::Track &track, const recob::Track &other) const
VertexWrapper fitTracksWithVtx(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &tracks, const recob::tracking::Point_t &vtxPos) const
recob::tracking::Vector_t Vector_t
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Wrapper class to facilitate vertex production.
recob::tracking::SVector2 SVector2
recob::tracking::SMatrixSym55 SMatrixSym55
void addTrack(const recob::Track &tk)
void addTrackAndUpdateVertex(const recob::tracking::Point_t &pos, const recob::tracking::SMatrixSym33 &cov, double chi2, int ndof, const recob::Track &tk)
recob::tracking::SMatrixSym22 SMatrixSym22
SVector5 Global6DToLocal5DParameters(const SVector6 &par6d) const
Function to convert parameters from global to local coordinates. Local coordinates are on the plane w...
std::size_t size(FixedBins< T, C > const &) noexcept
process_name use argoneut_mc_hitfinder track
std::vector< recob::VertexAssnMeta > computeMeta(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx)
double ip(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
double ipErr(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
VertexWrapper unbiasedVertex(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
SMatrixSym66 VertexCovarianceGlobal6D() const
double sipUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
unsigned int CountValidPoints() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
size_t tracksSize() const
VertexWrapper fitTwoTracks(detinfo::DetectorPropertiesData const &detProp, const recob::Track &tk1, const recob::Track &tk2) const
Vector_t StartDirection() const
Access to track direction at different points.
const TrackRefVec & tracks() const
double Length(size_t p=0) const
Access to various track properties.
recob::tracking::SVector5 SVector5
Point_t const & Start() const
Access to track position at different points.
Point_t const & position() const
Reference position on the plane.
std::unique_ptr< TrackStatePropagator > prop
double pDistUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
VertexWrapper fitTracks(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &arttracks) const
ParsCovsOnPlane getParsCovsOnPlane(detinfo::DetectorPropertiesData const &detProp, const trkf::VertexWrapper &vtx, const recob::Track &tk) const
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
VertexWrapper fitPFP(detinfo::DetectorPropertiesData const &detProp, size_t iPF, const art::ValidHandle< std::vector< recob::PFParticle >> &inputPFParticle, const std::unique_ptr< art::FindManyP< recob::Track >> &assocTracks) const
constexpr float kBogusF
obviously bogus float value
double pDist(const VertexWrapper &vtx, const recob::Track &tk) const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
SVector5 VertexParametersLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
double chi2(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
recob::tracking::SMatrixSym66 SMatrixSym66
double ipErrUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
recob::tracking::SMatrixSym33 SMatrixSym33
recob::tracking::SVector6 SVector6
constexpr double kBogusD
obviously bogus double value
SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t &trackMomOrDir) const
Translate track covariance from global to local coordinates. The track momentum (or direction) is nee...
double ipUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
size_t findTrack(const recob::Track &tk) const
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
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...
const SMatrixSym55 & VertexCovarianceLocal5D() const
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
double chi2Unbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
std::vector< std::reference_wrapper< const recob::Track > > TrackRefVec