5 #include <trackbase/TrkrDefUtil.h>
12 #include <TDecompSVD.h>
23 , ghostrejection_(
false)
37 if ( lyrs.size() < 3 || lyrs.size() > 4 )
39 std::cout <<
PHWHERE <<
"ERROR: Inappropriate number of input layers - " << lyrs.size() << std::endl;
48 clusters_ = findNode::getClass<TrkrClusterContainer>(topNode,
"TrkrClusterContainer");
51 std::cout <<
PHWHERE <<
"ERROR: Can't find node TrkrClusterContainer" << std::endl;
62 std::cout <<
PHWHERE <<
" Finished associating clusters. N candidates:" << trklst.size() << std::endl;
66 for (
unsigned int itrk = 0; itrk < trklst.size(); itrk++)
96 clusters_->GetClusters(TrkrDefs::TRKRID::mvtx_id, lyrs.at(0));
98 iter0 != clusrange0.second;
104 clusters_->GetClusters(TrkrDefs::TRKRID::mvtx_id, lyrs.at(1));
106 iter1 != clusrange1.second;
115 double mxy =
CalcSlope(clus0->GetY(), clus0->GetX(), clus1->GetY(), clus1->GetX());
116 double bxy =
CalcIntecept(clus0->GetY(), clus0->GetX(), mxy);
119 double mzy =
CalcSlope(clus0->GetY(), clus0->GetZ(), clus1->GetY(), clus1->GetZ());
120 double bzy =
CalcIntecept(clus0->GetY(), clus0->GetZ(), mxy);
124 clusters_->GetClusters(TrkrDefs::TRKRID::mvtx_id, lyrs.at(2));
126 iter2 != clusrange2.second;
142 if ( lyrs.size() > 3 )
145 clusters_->GetClusters(TrkrDefs::TRKRID::mvtx_id, lyrs.at(3));
147 iter3 != clusrange3.second;
157 trklst.push_back(trk);
164 trklst.push_back(trk);
179 std::cout <<
PHWHERE <<
" Running Ghost Rejection on "
180 << trklst.size() <<
" tracks" << std::endl;
183 std::multimap<TrkrDefs::cluskey, unsigned int> key_trk_map;
185 for (
unsigned int itrk = 0; itrk < trklst.size(); itrk++)
187 for (
unsigned int iclus = 0; iclus < trklst.at(itrk).ClusterList.size(); iclus++)
190 key_trk_map.insert(std::make_pair(ckey, itrk));
195 std::set<unsigned int> remove_set;
196 for (
auto iter = key_trk_map.begin(); iter != key_trk_map.end(); ++iter)
199 auto upiter = key_trk_map.upper_bound(iter->first);
202 double chi2_best = 9999.;
203 unsigned int idx_best = 0;
205 for (
auto jter = iter; jter != upiter; ++jter)
208 double chi2 = trklst.at(jter->second).chi2_xy + trklst.at(jter->second).chi2_zy;
209 if ( chi2 < chi2_best && chi2 > 0 )
212 idx_best = jter->second;
219 std::cout <<
PHWHERE <<
" Tracks sharing cluster:" << ntrk << std::endl;
220 for (
auto jter = iter; jter != upiter; ++jter)
222 double chi2 = trklst.at(jter->second).chi2_xy + trklst.at(jter->second).chi2_zy;
224 <<
" trk idx: " << jter->second
226 <<
" m_xy:" << trklst.at(jter->second).m_xy;
228 if ( jter->second == idx_best)
230 std::cout <<
" <--- BEST" << std::endl;
234 std::cout << std::endl;
240 for (
auto jter = iter; jter != upiter; ++jter)
242 if ( jter->second != idx_best )
244 remove_set.insert(jter->second);
254 std::cout <<
PHWHERE <<
" List of idx to remove:";
255 for (
auto it = remove_set.begin();
it != remove_set.end(); ++
it)
257 std::cout <<
" " << *
it;
259 std::cout << std::endl;
263 for (
auto rit = remove_set.rbegin(); rit != remove_set.rend(); ++rit)
264 trklst.erase(trklst.begin() + *rit);
270 std::cout <<
PHWHERE <<
" Remaining tracks:" << std::endl;
271 for (
unsigned int i = 0;
i < trklst.size();
i++)
273 double chi2 = trklst.at(
i).chi2_xy + trklst.at(
i).chi2_zy;
274 std::cout <<
" chi2:" << chi2 <<
" m_xy:" << trklst.at(
i).m_xy << std::endl;
290 TMatrixD XT(X); XT.T();
291 TMatrixD
A = XT * L *
X;
292 TVectorD
b = XT * L *
y;
296 TMatrixD UT = svd.GetU(); UT.T();
299 TVectorD
s = svd.GetSig();
300 TMatrixD Sd(s.GetNrows(), s.GetNrows());
301 for (
int i = 0;
i < s.GetNrows();
i++)
302 Sd(
i,
i) =
s(
i) > 0 ? 1. /
s(
i) : 0.;
304 TVectorD beta = svd.GetV() * Sd * UT *
b;
324 for (
int iclus = 0; iclus <
m; iclus++)
328 x(iclus) = clus->GetX();
329 y(iclus) = clus->GetY();
332 X(iclus, 1) =
y(iclus);
334 Cinv(iclus, iclus) = 2.0 * sqrt(clus->GetSize(0, 0));
337 TVectorD beta =
SolveGLS(X, x, Cinv);
338 double x0 = beta(0),
c = beta(1);
344 for (
int iclus = 0; iclus <
m; iclus++)
348 double cx = clus->GetX();
349 double cy = clus->GetY();
351 double px = cy *
c +
x0;
354 trk.
dx.push_back(dx);
356 chi2 += pow(dx, 2) / clus->GetError(0, 0);
379 for (
int iclus = 0; iclus <
m; iclus++)
383 z(iclus) = clus->GetZ();
384 y(iclus) = clus->GetY();
387 X(iclus, 1) =
y(iclus);
389 Cinv(iclus, iclus) = 2.0 * sqrt(clus->GetSize(2, 2));
392 TVectorD beta =
SolveGLS(X, z, Cinv);
393 double z0 = beta(0),
c = beta(1);
399 for (
int iclus = 0; iclus <
m; iclus++)
403 double cz = clus->GetZ();
404 double cy = clus->GetY();
406 double pz = cy *
c + z0;
409 trk.
dz.push_back(dz);
411 chi2 += pow(dz, 2) / clus->GetError(2, 2);
422 std::cout <<
"===================================================" << std::endl;
423 std::cout <<
"== " <<
PHWHERE <<
" Found " << trklst.size() <<
" Track Candidates" << std::endl;
424 std::cout <<
"===================================================" << std::endl;
425 for (
unsigned int i = 0;
i < trklst.size();
i++)
427 std::cout <<
"== " <<
i << std::endl;
428 for (
unsigned int j = 0;
j < trklst.at(
i).ClusterList.size();
j++)
430 std::cout <<
" clus " <<
j
431 <<
" key:0x" << std::hex << trklst.at(
i).ClusterList.at(
j)->GetClusKey() << std::dec
432 <<
" (" << trklst.at(
i).ClusterList.at(
j)->GetX()
433 <<
", " << trklst.at(
i).ClusterList.at(
j)->GetY()
434 <<
", " << trklst.at(
i).ClusterList.at(
j)->GetZ()
436 <<
" dx:" << trklst.at(
i).dx.at(
j)
437 <<
" dz:" << trklst.at(
i).dz.at(
j)
441 <<
" m:" << trklst.at(
i).m_xy
442 <<
" b:" << trklst.at(
i).b_xy
443 <<
" chi2:" << trklst.at(
i).chi2_xy
446 <<
" m:" << trklst.at(
i).m_zy
447 <<
" b:" << trklst.at(
i).b_zy
448 <<
" chi2:" << trklst.at(
i).chi2_zy
451 std::cout <<
"===================================================" << std::endl;
457 return (y1 - y0) / (x1 -
x0);