12 std::cout <<
"pfp#" << iPF <<
" PdgCode=" << pfp->
PdgCode() <<
" IsPrimary=" << pfp->
IsPrimary()
19 for (
auto ipfd : pfd) {
20 vector<art::Ptr<recob::Track>> pftracks = assocTracks->at(ipfd);
21 for (
auto t : pftracks) {
36 for (
auto t : arttracks) {
46 if (
debugLevel > 0) std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
53 [](std::reference_wrapper<const recob::Track> a, std::reference_wrapper<const recob::Track> b) {
54 return a.get().CountValidPoints() > b.get().CountValidPoints();
58 unsigned int tk0 = tracks.size();
59 unsigned int tk1 = tracks.size();
61 for (
unsigned int i = 0; i < tracks.size() - 1; i++) {
62 for (
unsigned int j = i + 1; j < tracks.size(); j++) {
64 (tracks[i].get().Trajectory().Start() - tracks[j].get().Trajectory().Start()).Mag2();
66 std::cout <<
"test i=" << i <<
" start=" << tracks[i].get().Trajectory().Start()
67 <<
" j=" << j <<
" start=" << tracks[j].get().Trajectory().Start() <<
" d=" << d
68 <<
" mind=" << mind <<
" tk0=" << tk0 <<
" tk1=" << tk1 << std::endl;
76 if (tk0 > 1 || tk1 > 1) {
77 if (tk0 > 1 && tk1 > 1) {
81 if (tk0 == 0)
std::swap(tracks[1], tracks[tk1]);
82 if (tk0 == 1)
std::swap(tracks[0], tracks[tk1]);
83 if (tk1 == 0)
std::swap(tracks[1], tracks[tk0]);
84 if (tk1 == 1)
std::swap(tracks[0], tracks[tk0]);
92 for (
auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
93 auto sipv =
sip(detProp, vtx, *tk);
94 if (
debugLevel > 1) std::cout <<
"sip=" << sipv << std::endl;
95 if (sipv >
sipCut)
continue;
107 for (
auto t : arttracks) {
108 tracks.push_back(*t);
118 if (
debugLevel > 0) std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
125 if (vtx.isValid() ==
false || vtx.tracks().size() < 2)
return vtx;
128 for (
auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
129 auto sipv =
sip(detProp, vtx, *tk);
130 if (
debugLevel > 1) std::cout <<
"sip=" << sipv << std::endl;
131 if (sipv >
sipCut)
continue;
148 std::cout <<
"par1=" << par1 << std::endl;
149 std::cout <<
"par2=" << par2 << std::endl;
150 std::cout <<
"deltapar=" << deltapar << std::endl;
152 std::cout <<
"cov1=\n" << cov1 << std::endl;
153 std::cout <<
"cov2=\n" << cov2 << std::endl;
154 std::cout <<
"covsum=\n" << covsum << std::endl;
159 bool d1ok = cov1.Det2(det1);
160 std::cout <<
"cov1 det=" << det1 <<
" ok=" << d1ok << std::endl;
162 bool d2ok = cov2.Det2(det2);
163 std::cout <<
"cov2 det=" << det2 <<
" ok=" << d2ok << std::endl;
165 bool dsok = covsum.Det2(detsum);
166 std::cout <<
"covsum det=" << detsum <<
" ok=" << dsok << std::endl;
169 bool invertok = covsum.Invert();
173 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
176 auto k = cov1 * covsum;
179 std::cout <<
"inverted covsum=\n" << covsum << std::endl;
180 std::cout <<
"k=\n" << k << std::endl;
183 SVector2 vtxpar2 = par1 + k * deltapar;
184 SMatrixSym22 vtxcov22 = cov1 - ROOT::Math::SimilarityT(cov1, covsum);
187 std::cout <<
"vtxpar2=" << vtxpar2 << std::endl;
188 std::cout <<
"vtxcov22=\n" << vtxcov22 << std::endl;
191 auto chi2 = ROOT::Math::Similarity(deltapar, covsum);
193 SVector5 vtxpar5(vtxpar2[0], vtxpar2[1], 0, 0, 0);
195 vtxcov55.Place_at(vtxcov22, 0, 0);
196 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
198 return std::make_pair(vtxstate,
chi2);
214 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1 <<
" length=" << track.
Length()
217 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2 <<
" length=" << other.
Length()
222 const auto dpos = start1 - start2;
223 const auto dotd1d2 = dir1.Dot(dir2);
224 const auto dotdpd1 = dpos.Dot(dir1);
225 const auto dotdpd2 = dpos.Dot(dir2);
226 const auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
227 const auto dist1 = (dotd1d2 * dist2 - dotdpd1);
230 std::cout <<
"track1 pca=" << start1 + dist1 * dir1 <<
" dist=" << dist1 << std::endl;
231 std::cout <<
"track2 pca=" << start2 + dist2 * dir2 <<
" dist=" << dist2 << std::endl;
244 state1 =
prop->propagateToPlane(
247 std::cout <<
"failed propagation, return track1 start pos=" << track.
Start() << std::endl;
256 state1.position(), state1.covariance6D().Sub<
SMatrixSym33>(0, 0), 0, 0, track);
274 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1 <<
" length=" << tk1.
Length()
277 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2 <<
" length=" << tk2.
Length()
282 auto dpos = start1 - start2;
283 auto dotd1d2 = dir1.Dot(dir2);
285 auto dotdpd1 = dpos.Dot(dir1);
286 auto dotdpd2 = dpos.Dot(dir2);
288 auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
289 auto dist1 = (dotd1d2 * dist2 - dotdpd1);
298 state1 =
prop->propagateToPlane(
301 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
312 state2 =
prop->propagateToPlane(
315 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
323 std::cout <<
"track1 pca=" << start1 + dist1 * dir1 <<
" dist=" << dist1 << std::endl;
324 std::cout <<
"track2 pca=" << start2 + dist2 * dir2 <<
" dist=" << dist2 << std::endl;
332 std::cout <<
"target pos=" << target.
position() <<
" dir=" << target.
direction() << std::endl;
334 auto dcp = state1.position() - state2.position();
338 std::cout <<
"cov1=" << cov1 << std::endl;
339 std::cout <<
"cov2=" << cov2 << std::endl;
342 SVector2 par1(state1.parameters()[0], state1.parameters()[1]);
343 SVector2 par2(state2.parameters()[0], state2.parameters()[1]);
347 std::cout <<
"failed inversion, return track1 start pos=" << tk1.
Start() << std::endl;
356 was.first.position(), was.first.covariance6D().Sub<
SMatrixSym33>(0, 0), was.second, ndof);
361 std::cout <<
"vtxpos=" << vtx.
position() << std::endl;
362 std::cout <<
"vtxcov=\n" << vtx.
covariance() << std::endl;
363 std::cout <<
"chi2=" << was.second << std::endl;
380 auto dist =
dir.Dot(vtxpos - start);
389 state =
prop->propagateToPlane(
393 std::cout <<
"input vtx=" << vtxpos << std::endl;
394 std::cout <<
"input cov=\n" << vtxcov << std::endl;
395 std::cout <<
"track pca=" << start +
dist * dir <<
" dist=" <<
dist << std::endl;
396 std::cout <<
"target pos=" << target.
position() <<
" dir=" << target.
direction() << std::endl;
400 SVector6 vtxpar6(vtxpos.X(), vtxpos.Y(), vtxpos.Z(), 0, 0, 0);
402 vtxcov66.Place_at(vtxcov, 0, 0);
405 SVector2 par1(vtxpar5[0], vtxpar5[1]);
406 SVector2 par2(state.parameters()[0], state.parameters()[1]);
414 std::cout <<
"vtxpar5=" << vtxpar5 << std::endl;
415 std::cout <<
"state.parameters()=" << state.parameters() << std::endl;
416 std::cout <<
"vtx covariance=\n" << vtxcov66 << std::endl;
417 std::cout <<
"trk covariance=\n" << state.covariance6D() << std::endl;
418 std::cout <<
"cov1=\n" << cov1 << std::endl;
419 std::cout <<
"cov2=\n" << cov2 << std::endl;
442 was.first.position(), was.first.covariance6D().Sub<
SMatrixSym33>(0, 0), was.second, ndof, tk);
445 std::cout <<
"updvtxpos=" << vtx.
position() << std::endl;
446 std::cout <<
"updvtxcov=\n" << vtx.
covariance() << std::endl;
447 std::cout <<
"add chi2=" << was.second << std::endl;
457 bool invertok = covsum.Invert();
458 if (!invertok)
return -1.;
460 return ROOT::Math::Similarity(deltapar, covsum);
474 return std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
488 deltapar /= std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
490 return std::sqrt(ROOT::Math::Similarity(deltapar, covsum));
524 if (ittoerase == vtx.
tracksSize()) {
return vtx; }
536 if (ittoerase == vtx.
tracksSize()) {
return chi2(detProp, vtx, tk); }
548 if (ittoerase == vtx.
tracksSize()) {
return ip(detProp, vtx, tk); }
572 if (ittoerase == vtx.
tracksSize()) {
return sip(detProp, vtx, tk); }
604 for (
auto t : arttracks)
605 tracks.push_back(*t);
614 std::vector<recob::VertexAssnMeta> result;
615 for (
auto tk : trks) {
622 std::cout <<
"computeMeta for vertex with ntracks=" << vtx.
tracksSize() << std::endl;
625 std::cout <<
"got unbiased vertex with ntracks=" << ubvtx.
tracksSize()
626 <<
" isValid=" << ubvtx.isValid() << std::endl;
627 if (ubvtx.isValid()) {
628 d =
pDist(ubvtx, tk.get());
634 std::cout <<
"unbiasedVertex d=" << d <<
" i=" << i <<
" e=" << e <<
" c=" << c
640 d =
pDist(fakevtx, tk.get());
647 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
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
double sip(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
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
int ParticleId() const
Access to various track properties.
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...
int PdgCode() const
Return the type of particle as a PDG ID.
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
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
double sipUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
unsigned int CountValidPoints() const
Various functions related to the presence and the number of (valid) points.
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
bool IsPrimary() const
Returns whether the particle is the root of the flow.
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
cout<< "-> Edep in the target
recob::tracking::SMatrixSym66 SMatrixSym66
double ipErrUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
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
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
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