53 #include <TDatabasePDG.h>
64 return !(std::isnan(vec.x()) || std::isnan(vec.y()) || std::isnan(vec.z()));
74 #include <Eigen/Dense>
75 #include <Eigen/Geometry>
79 , m_trajectories(nullptr)
87 std::cout <<
"Setup PHActsTrkFitter" << std::endl;
119 std::map<long unsigned int, float> chi2Cuts;
120 chi2Cuts.insert(std::make_pair(10, 4));
121 chi2Cuts.insert(std::make_pair(12, 4));
122 chi2Cuts.insert(std::make_pair(14, 9));
123 chi2Cuts.insert(std::make_pair(16, 4));
134 h_eventTime =
new TH1F(
"h_eventTime",
";time [ms]",
136 h_fitTime =
new TH2F(
"h_fitTime",
";p_{T} [GeV];time [ms]",
137 80, 0, 40, 100000, 0, 1000);
141 h_rotTime =
new TH1F(
"h_rotTime",
";time [ms]",
143 h_stateTime =
new TH1F(
"h_stateTime",
";time [ms]",
156 std::cout <<
"Finish PHActsTrkFitter Setup" << std::endl;
164 PHTimer eventTimer(
"eventTimer");
179 std::cout <<
PHWHERE <<
"Events processed: " <<
m_event << std::endl;
180 std::cout <<
"Start PHActsTrkFitter::process_event" << std::endl;
204 std::cout <<
"PHActsTrkFitter total event time "
211 std::cout <<
"PHActsTrkFitter::process_event finished"
228 std::cout <<
"Reset PHActsTrkFitter" << std::endl;
257 std::cout <<
"The Acts track fitter had " <<
m_nBadFits
258 <<
" fits return an error" << std::endl;
260 std::cout <<
"Finished PHActsTrkFitter" << std::endl;
271 std::cout <<
" seed map size " <<
m_seedMap->
size() << std::endl;
290 if (
m_pp_mode && siid == std::numeric_limits<unsigned int>::max())
292 if (
Verbosity() > 3) std::cout <<
" tpcid " << tpcid <<
" siid " << siid <<
" running in pp mode and SvtxSeedTrack has no silicon match, skip it" << std::endl;
298 short crossing = SHRT_MAX;
305 if (
m_pp_mode && crossing == SHRT_MAX && crossing_estimate == SHRT_MAX)
308 if (
Verbosity() > 3) std::cout <<
"tpcid " << tpcid <<
" siid " << siid <<
" crossing and crossing_estimate not determined, skipping track" << std::endl;
314 std::cout <<
"tpc and si id " << tpcid <<
", " << siid <<
" crossing " << crossing <<
" crossing estimate " << crossing_estimate << std::endl;
325 std::cout <<
"no tpc seed" << std::endl;
331 if (siseed) std::cout <<
" silicon seed position is (x,y,z) = " << siseed->
get_x() <<
" " << siseed->get_y() <<
" " << siseed->get_z() << std::endl;
332 std::cout <<
" tpc seed position is (x,y,z) = " << tpcseed->get_x() <<
" " << tpcseed->get_y() <<
" " << tpcseed->get_z() << std::endl;
335 PHTimer trackTimer(
"TrackTimer");
339 short int this_crossing = crossing;
340 bool use_estimate =
false;
342 std::vector<float> chisq_ndf;
343 std::vector<SvtxTrack_v4> svtx_vec;
345 if(
Verbosity() > 1) { std::cout <<
" INTT crossing " << crossing <<
" crossing_estimate " << crossing_estimate << std::endl; }
347 if(crossing == SHRT_MAX)
352 if(
Verbosity() > 1) { std::cout <<
" No INTT crossing: use crossing_estimate " << crossing_estimate <<
" with nvary " << nvary << std::endl; }
357 crossing_estimate = crossing;
364 for(
short int ivary = -nvary; ivary <= nvary; ++ivary)
366 this_crossing = crossing_estimate + ivary;
370 std::cout <<
" nvary " << nvary <<
" trial fit with ivary " << ivary <<
" this_crossing = " << this_crossing << std::endl;
403 sourceLinks.insert(sourceLinks.end(), tpcSourceLinks.begin(), tpcSourceLinks.end());
424 if (sourceLinks.empty())
436 if (surfaces.empty())
continue;
440 std::none_of(surfaces.begin(), surfaces.end(), [
this](
const auto&
surface)
450 if (
m_fieldMap.find(
".root") != std::string::npos)
454 pz = tpcseed->get_pz();
458 float pt = fabs(1. / tpcseed->get_qOverR()) * (0.3 / 100) * std::stod(
m_fieldMap);
460 px = pt * std::cos(phi);
461 py = pt * std::sin(phi);
462 pz = pt * std::cosh(tpcseed->get_eta()) * std::cos(tpcseed->get_theta());
468 auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
476 int charge = tpcseed->get_charge();
484 charge / momentum.norm(),
497 auto calibptr = std::make_unique<Calibrator>();
515 auto trackContainer =
516 std::make_shared<Acts::VectorTrackContainer>();
517 auto trackStateContainer =
518 std::make_shared<Acts::VectorMultiTrajectory>();
520 tracks(trackContainer, trackStateContainer);
523 surfaces, calibrator, tracks);
529 std::cout <<
"PHActsTrkFitter Acts fit time " << fitTime << std::endl;
548 chisq_ndf.push_back(chi2ndf);
549 svtx_vec.push_back(newTrack);
550 if(
Verbosity() > 1) { std::cout <<
" tpcid " << tpcid <<
" siid " << siid <<
" ivary " << ivary <<
" this_crossing " << this_crossing <<
" chi2ndf " << chi2ndf << std::endl; }
553 if(ivary != nvary) {
continue; }
556 if(
Verbosity() > 1) { std::cout <<
"Finished with trial fits, chisq_ndf size is " << chisq_ndf.size() <<
" chisq_ndf values are:" << std::endl; }
557 float best_chisq = 1000.0;
558 short int best_ivary = 0;
559 for(
unsigned int i = 0;
i<chisq_ndf.size(); ++
i)
561 if(chisq_ndf[
i] < best_chisq)
563 best_chisq = chisq_ndf[
i];
566 if(
Verbosity() > 1) { std::cout <<
" trial " <<
i <<
" chisq_ndf " << chisq_ndf[
i] <<
" best_chisq " << best_chisq <<
" best_ivary " << best_ivary << std::endl; }
569 svtx_vec[best_ivary].set_id(trid);
608 std::cout <<
"Track fit failed for track " <<
m_seedMap->
find(track)
609 <<
" with Acts error message "
610 << result.error() <<
", " << result.error().message()
621 std::cout <<
"PHActsTrkFitter total single track time " << trackTime << std::endl;
635 std::vector<Acts::MultiTrajectoryTraits::IndexType> trackTips;
636 trackTips.reserve(1);
637 auto& outtrack = fitOutput.value();
638 if (outtrack.hasReferenceSurface())
640 trackTips.emplace_back(outtrack.tipIndex());
642 indexedParams.emplace(std::pair{outtrack.tipIndex(),
644 outtrack.parameters(), outtrack.covariance(), outtrack.particleHypothesis()}});
648 std::cout <<
"Fitted parameters for track" << std::endl;
652 int otcharge = outtrack.qOverP() > 0 ? 1 : -1;
653 std::cout <<
"charge: " << otcharge << std::endl;
654 std::cout <<
" momentum : " << outtrack.momentum().transpose()
656 std::cout <<
"For trackTip == " << outtrack.tipIndex() << std::endl;
661 PHTimer updateTrackTimer(
"UpdateTrackTimer");
662 updateTrackTimer.
stop();
671 track, measurements);
675 updateTrackTimer.
stop();
679 std::cout <<
"PHActsTrkFitter update SvtxTrack time "
680 << updateTime << std::endl;
688 trackTips, indexedParams);
694 m_evaluator->evaluateTrackFit(tracks, trackTips, indexedParams, track,
705 const std::vector<Acts::SourceLink>& sourceLinks,
715 surfSequence, calibrator,
tracks);
732 for (
const auto& sl : sourceLinks)
737 std::cout <<
"SL available on : " << asl.
geometryId() << std::endl;
748 siliconMMSls.push_back(sl);
749 surfaces.push_back(
surf);
755 if (!surfaces.empty())
762 for (
const auto&
surf : surfaces)
764 std::cout <<
"Surface vector : " <<
surf->geometryId() << std::endl;
773 for (
int i = 0;
i < surfaces.size() - 1;
i++)
775 const auto&
surface = surfaces.at(
i);
776 const auto thisVolume =
surface->geometryId().volume();
777 const auto thisLayer =
surface->geometryId().layer();
779 const auto nextSurface = surfaces.at(
i + 1);
780 const auto nextVolume = nextSurface->geometryId().volume();
781 const auto nextLayer = nextSurface->geometryId().layer();
784 if (nextVolume == thisVolume)
786 if (nextLayer < thisLayer)
789 <<
"PHActsTrkFitter::checkSurfaceVec - "
790 <<
"Surface not in order... removing surface"
791 <<
surface->geometryId() << std::endl;
793 surfaces.erase(surfaces.begin() +
i);
802 if (nextVolume < thisVolume)
805 <<
"PHActsTrkFitter::checkSurfaceVec - "
806 <<
"Volume not in order... removing surface"
807 <<
surface->geometryId() << std::endl;
809 surfaces.erase(surfaces.begin() +
i);
824 const auto& mj = tracks.trackStateContainer();
827 auto& trackTip = tips.front();
831 std::cout <<
"Identify (proto) track before updating with acts results " << std::endl;
842 float pathlength = 0.0;
852 const auto& params = paramsMap.find(trackTip)->second;
859 track->
set_px(params.momentum()(0));
860 track->
set_py(params.momentum()(1));
861 track->
set_pz(params.momentum()(2));
870 if (params.covariance())
874 for (
int i = 0;
i < 6;
i++)
876 for (
int j = 0;
j < 6;
j++)
885 PHTimer trackStateTimer(
"TrackStateTimer");
886 trackStateTimer.
stop();
895 trackStateTimer.
stop();
899 std::cout <<
"PHActsTrkFitter update SvtxTrackStates time "
900 << stateTime << std::endl;
909 std::cout <<
" Identify fitted track after updating track states:"
935 0., 0., 0.1, 0., 0., 0.,
936 0., 0., 0., 0.1, 0., 0.,
937 0., 0., 0., 0., 0.005, 0.,
938 0., 0., 0., 0., 0., 1.;
966 <<
" Processing proto track:"
972 <<
"momentum: " << seed.
momentum().transpose()
975 std::cout <<
"charge : " << seed.
charge() << std::endl;
987 std::cerr <<
"DST node is missing, quitting" << std::endl;
988 throw std::runtime_error(
"Failed to find DST node in PHActsTrkFitter::createNodes");
1003 "SvtxSiliconMMTrackMap");
1015 m_trajectories = findNode::getClass<std::map<const unsigned int, Trajectory>>(topNode,
"ActsTrajectories");
1033 m_alignmentStateMap = findNode::getClass<SvtxAlignmentStateMap>(topNode,
"SvtxAlignmentStateMap");
1064 std::cout <<
PHWHERE <<
"alignmentTransformationContainer not on node tree. Bailing"
1072 std::cout <<
PHWHERE <<
"alignmentTransformationContainerTransient not on node tree. Bailing"
1078 m_tpcSeeds = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
1081 std::cout <<
PHWHERE <<
"TpcTrackSeedContainer not on node tree. Bailing"
1086 m_siliconSeeds = findNode::getClass<TrackSeedContainer>(topNode,
"SiliconTrackSeedContainer");
1089 std::cout <<
PHWHERE <<
"SiliconTrackSeedContainer not on node tree. Bailing"
1094 m_clusterContainer = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
1098 <<
"No trkr cluster container, exiting." << std::endl;
1102 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
1105 std::cout <<
"ActsGeometry not on node tree. Exiting."
1111 m_seedMap = findNode::getClass<TrackSeedContainer>(topNode,
"SvtxTrackSeedContainer");
1114 std::cout <<
"No Svtx seed map on node tree. Exiting."
1120 _dcc_static = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerStatic");
1123 std::cout <<
PHWHERE <<
" found static TPC distortion correction container" << std::endl;
1125 _dcc_average = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerAverage");
1128 std::cout <<
PHWHERE <<
" found average TPC distortion correction container" << std::endl;
1130 _dcc_fluctuation = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerFluctuation");
1133 std::cout <<
PHWHERE <<
" found fluctuation TPC distortion correction container" << std::endl;