19 for (
auto ipfd : pfd) {
20 vector< art::Ptr<recob::Track> > pftracks = assocTracks->at(ipfd);
21 for (
auto t : pftracks) {
33 for (
auto t : arttracks) {
42 if (
debugLevel>0) std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
45 std::sort(tracks.begin(), tracks.end(), [](std::reference_wrapper<const recob::Track> a, std::reference_wrapper<const recob::Track> b) {
46 return a.get().CountValidPoints() > b.get().CountValidPoints();}
49 unsigned int tk0 = tracks.size();
50 unsigned int tk1 = tracks.size();
52 for (
unsigned int i=0;i<tracks.size()-1;i++) {
53 for (
unsigned int j=i+1;j<tracks.size();j++) {
54 float d = (tracks[i].get().Trajectory().Start()-tracks[j].get().Trajectory().Start()).Mag2();
55 if (
debugLevel>1) std::cout <<
"test i=" << i <<
" start=" << tracks[i].get().Trajectory().Start() <<
" j=" << j <<
" start=" << tracks[j].get().Trajectory().Start() <<
" d=" << d <<
" mind=" << mind <<
" tk0=" << tk0 <<
" tk1=" << tk1 << std::endl;
68 if (tk0==0)
std::swap(tracks[1],tracks[tk1]);
69 if (tk0==1)
std::swap(tracks[0],tracks[tk1]);
70 if (tk1==0)
std::swap(tracks[1],tracks[tk0]);
71 if (tk1==1)
std::swap(tracks[0],tracks[tk0]);
79 for (
auto tk = tracks.begin()+2; tk<tracks.end(); ++tk) {
80 auto sipv =
sip(vtx, *tk);
81 if (
debugLevel>1) std::cout <<
"sip=" << sipv << std::endl;
92 for (
auto t : arttracks) {
102 if (
debugLevel>0) std::cout <<
"fitting vertex with ntracks=" << tracks.size() << std::endl;
109 if (vtx.isValid()==
false || vtx.tracks().size()<2)
return vtx;
112 for (
auto tk = tracks.begin()+2; tk<tracks.end(); ++tk) {
113 auto sipv =
sip(vtx, *tk);
114 if (
debugLevel>1) std::cout <<
"sip=" << sipv << std::endl;
115 if (sipv>
sipCut)
continue;
129 std::cout <<
"par1=" << par1 << std::endl;
130 std::cout <<
"par2=" << par2 << std::endl;
131 std::cout <<
"deltapar=" << deltapar << std::endl;
133 std::cout <<
"cov1=\n" << cov1 << std::endl;
134 std::cout <<
"cov2=\n" << cov2 << std::endl;
135 std::cout <<
"covsum=\n" << covsum << std::endl;
140 bool d1ok = cov1.Det2(det1);
141 std::cout <<
"cov1 det=" << det1 <<
" ok=" << d1ok << std::endl;
143 bool d2ok = cov2.Det2(det2);
144 std::cout <<
"cov2 det=" << det2 <<
" ok=" << d2ok << std::endl;
146 bool dsok = covsum.Det2(detsum);
147 std::cout <<
"covsum det=" << detsum <<
" ok=" << dsok << std::endl;
150 bool invertok = covsum.Invert();
154 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
157 auto k = cov1*covsum;
160 std::cout <<
"inverted covsum=\n" << covsum << std::endl;
161 std::cout <<
"k=\n" << k << std::endl;
164 SVector2 vtxpar2 = par1 + k*deltapar;
165 SMatrixSym22 vtxcov22 = cov1 - ROOT::Math::SimilarityT(cov1,covsum);
168 std::cout <<
"vtxpar2=" << vtxpar2 << std::endl;
169 std::cout <<
"vtxcov22=\n" << vtxcov22 << std::endl;
172 auto chi2 = ROOT::Math::Similarity(deltapar,covsum);
174 SVector5 vtxpar5(vtxpar2[0],vtxpar2[1],0,0,0);
176 TrackState vtxstate(vtxpar5, vtxcov55, target,
true, 0);
178 return std::make_pair(vtxstate,
chi2);
191 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1
195 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2
201 const auto dpos = start1-start2;
202 const auto dotd1d2 = dir1.Dot(dir2);
203 const auto dotdpd1 = dpos.Dot(dir1);
204 const auto dotdpd2 = dpos.Dot(dir2);
205 const auto dist2 = ( dotd1d2*dotdpd1 - dotdpd2 )/( dotd1d2*dotd1d2 - 1 );
206 const auto dist1 = ( dotd1d2*dist2 - dotdpd1 );
209 std::cout <<
"track1 pca=" << start1+dist1*dir1 <<
" dist=" << dist1 << std::endl;
210 std::cout <<
"track2 pca=" << start2+dist2*dir2 <<
" dist=" << dist2 << std::endl;
221 std::cout <<
"failed propagation, return track1 start pos=" << track.
Start() << std::endl;
242 std::cout <<
"track1 with start=" << start1 <<
" dir=" << dir1
246 std::cout <<
"track2 with start=" << start2 <<
" dir=" << dir2
252 auto dpos = start1-start2;
253 auto dotd1d2 = dir1.Dot(dir2);
255 auto dotdpd1 = dpos.Dot(dir1);
256 auto dotdpd2 = dpos.Dot(dir2);
258 auto dist2 = ( dotd1d2*dotdpd1 - dotdpd2 )/( dotd1d2*dotd1d2 - 1 );
259 auto dist1 = ( dotd1d2*dist2 - dotdpd1 );
269 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
280 std::cout <<
"failed propagation, return track1 start pos=" << tk1.
Start() << std::endl;
287 std::cout <<
"track1 pca=" << start1+dist1*dir1 <<
" dist=" << dist1 << std::endl;
288 std::cout <<
"track2 pca=" << start2+dist2*dir2 <<
" dist=" << dist2 << std::endl;
296 std::cout <<
"target pos=" << target.
position() <<
" dir=" << target.
direction() << std::endl;
298 auto dcp = state1.position()-state2.position();
302 std::cout <<
"cov1=" << cov1 << std::endl;
303 std::cout <<
"cov2=" << cov2 << std::endl;
306 SVector2 par1(state1.parameters()[0],state1.parameters()[1]);
307 SVector2 par2(state2.parameters()[0],state2.parameters()[1]);
311 std::cout <<
"failed inversion, return track1 start pos=" << tk1.
Start() << std::endl;
323 std::cout <<
"vtxpos=" << vtx.
position() << std::endl;
324 std::cout <<
"vtxcov=\n" << vtx.
covariance() << std::endl;
325 std::cout <<
"chi2=" << was.second << std::endl;
338 auto dist =
dir.Dot(vtxpos-start);
349 std::cout <<
"input vtx=" << vtxpos << std::endl;
350 std::cout <<
"input cov=\n" << vtxcov << std::endl;
351 std::cout <<
"track pca=" << start+dist*dir <<
" dist=" << dist << std::endl;
352 std::cout <<
"target pos=" << target.
position() <<
" dir=" << target.
direction() << std::endl;
356 SVector6 vtxpar6(vtxpos.X(),vtxpos.Y(),vtxpos.Z(),0,0,0);
360 SVector2 par1(vtxpar5[0],vtxpar5[1]);
361 SVector2 par2(state.parameters()[0],state.parameters()[1]);
368 std::cout <<
"vtxpar5=" << vtxpar5 << std::endl;
369 std::cout <<
"state.parameters()=" << state.parameters() << std::endl;
370 std::cout <<
"vtx covariance=\n" << vtxcov66 << std::endl;
371 std::cout <<
"trk covariance=\n" << state.covariance6D() << std::endl;
372 std::cout <<
"cov1=\n" << cov1 << std::endl;
373 std::cout <<
"cov2=\n" << cov2 << std::endl;
399 std::cout <<
"updvtxpos=" << vtx.
position() << std::endl;
400 std::cout <<
"updvtxcov=\n" << vtx.
covariance() << std::endl;
401 std::cout <<
"add chi2=" << was.second << std::endl;
412 bool invertok = covsum.Invert();
413 if (!invertok)
return -1.;
415 return ROOT::Math::Similarity(deltapar,covsum);
426 return std::sqrt( deltapar[0]*deltapar[0] + deltapar[1]*deltapar[1] );
437 deltapar/=std::sqrt( deltapar[0]*deltapar[0] + deltapar[1]*deltapar[1] );
439 return std::sqrt(ROOT::Math::Similarity(deltapar,covsum));
496 return ipErr(vtx,tk);
516 return pDist(vtx,tk);
531 for (
auto t : arttracks) tracks.push_back(*t);
537 std::vector<recob::VertexAssnMeta> result;
538 for (
auto tk : trks) {
544 if (
debugLevel>1) std::cout <<
"computeMeta for vertex with ntracks=" << vtx.
tracksSize() << std::endl;
546 if (
debugLevel>1) std::cout <<
"got unbiased vertex with ntracks=" << ubvtx.
tracksSize() <<
" isValid=" << ubvtx.isValid() << std::endl;
547 if (ubvtx.isValid()) {
548 d =
pDist(ubvtx, tk.get());
553 if (
debugLevel>1) std::cout <<
"unbiasedVertex d=" << d <<
" i=" << i <<
" e=" << e <<
" c=" << c << std::endl;
557 d =
pDist(fakevtx, tk.get());
563 if (
debugLevel>1) std::cout <<
"closestPointAlongTrack d=" << d <<
" i=" << i <<
" e=" << e <<
" c=" << c << std::endl;
double sipUnbiased(const 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.
VertexWrapper closestPointAlongTrack(const recob::Track &track, const recob::Track &other) const
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
VertexWrapper fitTracksWithVtx(const std::vector< art::Ptr< recob::Track > > &tracks, const recob::tracking::Point_t &vtxPos) const
const recob::tracking::SMatrixSym33 & covariance() const
ParsCovsOnPlane getParsCovsOnPlane(const trkf::VertexWrapper &vtx, const recob::Track &tk) const
int ParticleId() const
Access to various track properties.
cout<< "-> Edep in the target
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
double chi2(const VertexWrapper &vtx, const recob::Track &tk) const
SVector5 Global6DToLocal5DParameters(const SVector6 &par6d) const
Function to convert parameters from global to local coordinates. Local coordinates are on the plane w...
VertexWrapper unbiasedVertex(const VertexWrapper &vtx, const recob::Track &tk) const
int PdgCode() const
Return the type of particle as a PDG ID.
void addTrackToVertex(VertexWrapper &vtx, const recob::Track &tk) const
SMatrixSym66 VertexCovarianceGlobal6D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
std::vector< recob::VertexAssnMeta > computeMeta(const VertexWrapper &vtx)
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 fitTracks(const std::vector< art::Ptr< recob::Track > > &arttracks) 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.
double pDistUnbiased(const VertexWrapper &vtx, const recob::Track &tk) const
std::unique_ptr< TrackStatePropagator > prop
bool IsPrimary() const
Returns whether the particle is the root of the flow.
VertexWrapper fitTwoTracks(const recob::Track &tk1, const recob::Track &tk2) const
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
double ipUnbiased(const VertexWrapper &vtx, const recob::Track &tk) const
constexpr float kBogusF
obviously bogus float value
double pDist(const VertexWrapper &vtx, const recob::Track &tk) const
double sip(const VertexWrapper &vtx, const recob::Track &tk) const
SVector5 VertexParametersLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
recob::tracking::SMatrixSym66 SMatrixSym66
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 ipErr(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...
double chi2Unbiased(const VertexWrapper &vtx, const recob::Track &tk) const
const SMatrixSym55 & VertexCovarianceLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
VertexWrapper fitPFP(size_t iPF, const art::ValidHandle< std::vector< recob::PFParticle > > &inputPFParticle, const std::unique_ptr< art::FindManyP< recob::Track > > &assocTracks) const
double ipErrUnbiased(const VertexWrapper &vtx, const recob::Track &tk) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
double ip(const VertexWrapper &vtx, const recob::Track &tk) const
std::vector< std::reference_wrapper< const recob::Track > > TrackRefVec