18 #include <trackbase_historic/SvtxVertexMap.h>
21 #include <trackbase_historic/SvtxVertexMap_v1.h>
23 #include <phgenfit/Fitter.h>
24 #include <phgenfit/PlanarMeasurement.h>
25 #include <phgenfit/Track.h>
39 #include <phfield/PHFieldUtility.h>
40 #include <phgeom/PHGeomUtility.h>
42 #include <GenFit/EventDisplay.h>
43 #include <GenFit/RKTrackRep.h>
45 #include <TClonesArray.h>
46 #include <TMatrixDSymfwd.h>
47 #include <TMatrixTSym.h>
48 #include <TMatrixTUtils.h>
70 #define LogDebug(exp) std::cout << "DEBUG: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
71 #define LogError(exp) std::cout << "ERROR: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
72 #define LogWarning(exp) std::cout << "WARNING: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
74 #define WILD_FLOAT -9999.
76 #define _DEBUG_MODE_ 0
88 , _track_fitting_alg_name(
"KalmanFitter")
92 , _primary_pid_guess(2212)
95 , _clustermap(nullptr)
97 , _assoc_container(nullptr)
100 , _eval_outname(
"TpcPrototypeGenFitTrkFinder_eval.root")
101 , _eval_tree(nullptr)
103 , _tca_trackmap(nullptr)
104 , _do_evt_display(
false)
166 std::cout <<
PHWHERE <<
"Events processed: " <<
_event << std::endl;
174 vector<std::shared_ptr<PHGenFit::Track> > rf_phgf_tracks;
180 rf_phgf_tracks.clear();
184 set<tracklet_t> tracklets;
189 set<tracklet_t> new_tracklets(tracklets);
192 for (
auto iter = cluster_range.first; iter != cluster_range.second; ++iter)
202 TVector3 z_dir(0, 0, 1);
203 TVector3 azimuth_dir(z_dir.Cross(n_dir));
205 bool matched =
false;
206 for (
const auto tracklet : tracklets)
208 assert(tracklet.size() >= 1);
212 TVector3 last_pos(last_cluster->getPosition(0), last_cluster->getPosition(1), last_cluster->getPosition(2));
214 TVector3 pos_diff =
pos - last_pos;
215 const double n_residual = pos_diff.Dot(n_dir);
216 const double z_residual = pos_diff.Dot(z_dir);
217 const double azimuth_residual = pos_diff.Dot(azimuth_dir);
220 const double z_diff = z_residual / n_residual;
221 const double azimuth_diff = azimuth_residual / n_residual;
227 cout << __PRETTY_FUNCTION__ <<
" adding cluster at layer " <<
layer <<
" to tracklet length " << tracklet.size() << endl;
230 auto iter_old_tracklet =
231 new_tracklets.find(tracklet);
232 if (iter_old_tracklet != new_tracklets.end())
233 new_tracklets.erase(iter_old_tracklet);
236 new_tracklet.push_back(cluster);
237 new_tracklets.insert(new_tracklet);
243 cout << __PRETTY_FUNCTION__ <<
" skipping rest tracklet at layer " <<
layer
244 <<
" due to tracklet count " << new_tracklets.size() <<
" > " <<
maxTracklet << endl;
254 cout << __PRETTY_FUNCTION__ <<
" skipping rest clusters at layer " <<
layer
255 <<
" due to tracklet count " << new_tracklets.size() <<
" > " <<
maxTracklet << endl;
264 cout << __PRETTY_FUNCTION__ <<
" init tracket with cluster at layer " <<
layer << endl;
270 tracklets = new_tracklets;
275 cout << __PRETTY_FUNCTION__ <<
"print initial trackets: ";
276 for (
const auto& tracklet : tracklets)
279 <<
"size = " << tracklet.size();
285 multimap<double, tracklet_t> quality_tracklets_map;
286 for (
const auto& tracklet : tracklets)
290 quality_tracklets_map.insert(std::pair<double, tracklet_t>(chi2Ndf, tracklet));
294 cout << __PRETTY_FUNCTION__ <<
"print fitted trackets: ";
295 for (
const auto& tracklet : quality_tracklets_map)
298 <<
"size = " << tracklet.second.size() <<
" chi2/ndf = " << tracklet.first;
304 for (
auto iter_current = quality_tracklets_map.begin(); iter_current != quality_tracklets_map.end(); ++iter_current)
306 const tracklet_t& track_current = iter_current->second;
308 auto iter_check = iter_current;
310 for (; iter_check != quality_tracklets_map.end();)
312 const tracklet_t& track_check = iter_check->second;
314 unsigned int identical_cluster = 0;
316 for (
const auto cluster : track_current)
320 if (find(track_check.begin(), track_check.end(), cluster) != track_check.end())
324 if (identical_cluster >= track_current.size() / 3 or identical_cluster >= track_check.size() / 3)
328 cout << __PRETTY_FUNCTION__ <<
" found " << identical_cluster <<
"-shared ghost track size" << track_check.size() <<
" chi2ndf" << iter_check->first
329 <<
" from base track size" << track_current.size() <<
" chi2ndf" << iter_current->first << endl;
332 auto iter_tmp = iter_check;
335 quality_tracklets_map.erase(iter_tmp);
341 cout << __PRETTY_FUNCTION__ <<
"low " << identical_cluster <<
"-shared track size" << track_check.size() <<
" chi2ndf" << iter_check->first
342 <<
" from base track size" << track_current.size() <<
" chi2ndf" << iter_current->first << endl;
350 cout << __PRETTY_FUNCTION__ <<
"print deghosted trackets: ";
351 for (
const auto& tracklet : quality_tracklets_map)
354 <<
"size = " << tracklet.second.size() <<
" chi2/ndf = " << tracklet.first;
362 for (
const auto& quality_tracklet : quality_tracklets_map)
364 const tracklet_t& tracklet = quality_tracklet.second;
367 TVector3 pos_front(tracklet.front()->getPosition(0), tracklet.front()->getPosition(1), tracklet.front()->getPosition(2));
368 TVector3 pos_back(tracklet.back()->getPosition(0), tracklet.back()->getPosition(1), tracklet.back()->getPosition(2));
370 TVector3 seed_mom(pos_back - pos_front);
371 seed_mom.SetMag(120);
373 TVector3 seed_pos(pos_front);
375 std::unique_ptr<SvtxTrack_v1> svtx_track(
new SvtxTrack_v1());
380 svtx_track->
set_px(seed_mom.x());
381 svtx_track->
set_py(seed_mom.y());
382 svtx_track->
set_pz(seed_mom.z());
383 svtx_track->
set_x(seed_pos.x());
384 svtx_track->
set_y(seed_pos.y());
385 svtx_track->
set_z(seed_pos.z());
410 cout << __PRETTY_FUNCTION__ <<
" drop short tracklet size = " << tracklet.size() <<
" < " <<
minLayer << endl;
418 TVector3 pos_front(tracklet.front()->getPosition(0), tracklet.front()->getPosition(1), tracklet.front()->getPosition(2));
419 TVector3 pos_back(tracklet.back()->getPosition(0), tracklet.back()->getPosition(1), tracklet.back()->getPosition(2));
421 TVector3 seed_mom(pos_back - pos_front);
422 seed_mom.SetMag(120);
424 TVector3 seed_pos(pos_front);
425 TMatrixDSym seed_cov(6);
426 for (
int i = 0;
i < 6;
i++)
428 for (
int j = 0;
j < 6;
j++)
430 seed_cov[
i][
j] = 100.;
435 std::vector<PHGenFit::Measurement*> measurements;
436 for (
const auto cluster : tracklet)
444 cout << __PRETTY_FUNCTION__ <<
"add cluster on layer " << layer <<
": ";
447 TVector3
pos(cluster->getPosition(0), cluster->getPosition(1), cluster->getPosition(2));
450 TVector3
n(cluster->getPosition(0), cluster->getPosition(1), 0);
453 cluster->getRPhiError(),
454 cluster->getZError());
456 measurements.push_back(meas);
462 std::shared_ptr<PHGenFit::Track> phgf_track(
new PHGenFit::Track(rep, seed_pos, seed_mom,
464 phgf_track->addMeasurements(measurements);
470 cout << __PRETTY_FUNCTION__ <<
" track->getChisq() " << phgf_track->get_chi2() <<
" get_ndf " << phgf_track->get_ndf()
471 <<
" mom.X " << phgf_track->get_mom().X()
472 <<
" mom.Y " << phgf_track->get_mom().Y()
473 <<
" mom.Z " << phgf_track->get_mom().Z()
482 cout << __PRETTY_FUNCTION__ <<
" track->getChisq() " << phgf_track->get_chi2() <<
" get_ndf " << phgf_track->get_ndf()
483 <<
" mom.X " << phgf_track->get_mom().X()
484 <<
" mom.Y " << phgf_track->get_mom().Y()
485 <<
" mom.Z " << phgf_track->get_mom().Z()
488 return phgf_track->get_chi2() / phgf_track->get_ndf();
565 _eval_tree =
new TTree(
"T",
"TpcPrototypeGenFitTrkFinder Evaluation");
606 "PHCompositeNode",
"DST"));
609 cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
616 "PHCompositeNode",
"SVTX"));
622 cout <<
"SVTX node added" << endl;
630 cout <<
"Svtx/SvtxTrackMap node added" << endl;
635 tb_node->
addNode(vertexes_node);
637 cout <<
"Svtx/SvtxVertexMap node added" << endl;
644 cout <<
"Svtx/AssocInfoContainer node added" << endl;
656 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
663 _trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
666 cout <<
PHWHERE <<
" SvtxTrackMap node not found on node tree"
672 _vertexmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
675 cout <<
PHWHERE <<
" SvtxVertexrMap node not found on node tree"