47 #include <TDatabasePDG.h>
59 return !(std::isnan(vec.x()) || std::isnan(vec.y()) || std::isnan(vec.z()));
68 template<
class T>
T radius(
const T&
x,
const T&
y)
74 #include <Eigen/Dense>
75 #include <Eigen/Geometry>
79 , m_trajectories(nullptr)
87 std::cout <<
"Setup PHCosmicsTrkFitter" << std::endl;
112 std::map<long unsigned int, float> chi2Cuts;
113 chi2Cuts.insert(std::make_pair(10, 4));
114 chi2Cuts.insert(std::make_pair(12, 4));
115 chi2Cuts.insert(std::make_pair(14, 9));
116 chi2Cuts.insert(std::make_pair(16, 4));
124 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
141 m_tree = std::make_unique<TTree>(
"seedclustree",
"Tree with cosmic seeds and their clusters");
148 std::cout <<
"Finish PHCosmicsTrkFitter Setup" << std::endl;
167 std::cout <<
PHWHERE <<
"Events processed: " <<
m_event << std::endl;
168 std::cout <<
"Start PHCosmicsTrkFitter::process_event" << std::endl;
202 std::cout <<
"Reset PHCosmicsTrkFitter" << std::endl;
224 std::cout <<
"The Acts track fitter had " <<
m_nBadFits
225 <<
" fits return an error" << std::endl;
227 std::cout <<
"Finished PHCosmicsTrkFitter" << std::endl;
238 std::cout <<
" seed map size " <<
m_seedMap->
size() << std::endl;
260 std::cout <<
"TPC id " << tpcid << std::endl;
261 std::cout <<
"Silicon id " << siid << std::endl;
272 if (siseed) std::cout <<
" silicon seed position is (x,y,z) = " << siseed->
get_x() <<
" " << siseed->get_y() <<
" " << siseed->get_z() << std::endl;
273 std::cout <<
" tpc seed position is (x,y,z) = " << tpcseed->get_x() <<
" " << tpcseed->get_y() <<
" " << tpcseed->get_z() << std::endl;
305 sourceLinks.insert(sourceLinks.end(), tpcSourceLinks.begin(), tpcSourceLinks.end());
308 float cosmicslope = 0;
318 float tpcR = fabs(1. / tpcseed->get_qOverR());
319 float tpcx = tpcseed->get_X0();
320 float tpcy = tpcseed->get_Y0();
338 float slope = tpcseed->get_slope();
343 std::vector<float> tpcparams{tpcR, tpcx, tpcy, tpcseed->get_slope(),
348 auto tan = tangent.second;
349 auto pca = tangent.first;
352 if (
m_fieldMap.find(
".root") != std::string::npos)
354 p = tpcseed->get_p();
358 p = cosh(tpcseed->get_eta()) * fabs(1. / tpcseed->get_qOverR()) * (0.3 / 100) * std::stod(
m_fieldMap);
370 charge < 0 ? tan.y() : tan.y() * -1,
371 cosmicslope > 0 ? fabs(tan.z()) : -1 * fabs(tan.z()));
373 momentum.z() > 0 ? (slope < 0 ? intz :
m_vertexRadius * slope * -1 + tpcseed->get_Z0()) : (slope > 0 ? intz :
m_vertexRadius * slope * -1 + tpcseed->get_Z0()));
378 auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
392 m_Z0 = tpcseed->get_Z0();
410 charge / momentum.norm(),
416 std::cout <<
"Could not create track params, skipping track" << std::endl;
429 auto calibptr = std::make_unique<Calibrator>();
443 auto trackContainer =
444 std::make_shared<Acts::VectorTrackContainer>();
445 auto trackStateContainer =
446 std::make_shared<Acts::VectorMultiTrajectory>();
448 tracks(trackContainer, trackStateContainer);
449 auto result =
fitTrack(sourceLinks,
seed.value(), kfOptions,
473 std::cout <<
"Track fit failed for track " <<
m_seedMap->
find(track)
474 <<
" with Acts error message "
475 << result.error() <<
", " << result.error().message()
491 auto& outtrack = fitOutput.value();
492 std::vector<Acts::MultiTrajectoryTraits::IndexType> trackTips;
493 trackTips.reserve(1);
494 trackTips.emplace_back(outtrack.tipIndex());
497 indexedParams.emplace(std::pair{outtrack.tipIndex(),
499 outtrack.parameters(), outtrack.covariance(), outtrack.particleHypothesis()}});
503 std::cout <<
"Fitted parameters for track" << std::endl;
508 int otcharge = outtrack.qOverP() > 0 ? 1 : -1;
509 std::cout <<
"charge: " << otcharge << std::endl;
510 std::cout <<
" momentum : " << outtrack.momentum().transpose()
512 std::cout <<
"For trackTip == " << outtrack.tipIndex() << std::endl;
516 trackTips, indexedParams);
529 track, measurements);
535 m_evaluator->evaluateTrackFit(tracks, trackTips, indexedParams, track,
543 const std::vector<Acts::SourceLink>& sourceLinks,
553 std::vector<Acts::MultiTrajectoryTraits::IndexType>& tips,
558 const auto& mj = tracks.trackStateContainer();
561 auto& trackTip = tips.front();
565 std::cout <<
"Identify (proto) track before updating with acts results " << std::endl;
571 float pathlength = 0.0;
581 const auto& params = paramsMap.find(trackTip)->second;
588 track->
set_px(params.momentum()(0));
589 track->
set_py(params.momentum()(1));
590 track->
set_pz(params.momentum()(2));
599 if (params.covariance())
603 for (
int i = 0;
i < 6;
i++)
605 for (
int j = 0;
j < 6;
j++)
623 std::cout <<
" Identify fitted track after updating track states:"
666 <<
" Processing proto track:"
672 <<
"momentum: " << seed.
momentum().transpose()
675 std::cout <<
"charge : " << seed.
charge() << std::endl;
687 std::cerr <<
"DST node is missing, quitting" << std::endl;
688 throw std::runtime_error(
"Failed to find DST node in PHCosmicsTrkFitter::createNodes");
700 m_trajectories = findNode::getClass<std::map<const unsigned int, Trajectory>>(topNode,
"ActsTrajectories");
718 m_alignmentStateMap = findNode::getClass<SvtxAlignmentStateMap>(topNode,
"SvtxAlignmentStateMap");
729 std::cout <<
PHWHERE <<
"alignmentTransformationContainerTransient not on node tree. Bailing"
753 m_tpcSeeds = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
756 std::cout <<
PHWHERE <<
"TpcTrackSeedContainer not on node tree. Bailing"
761 m_siliconSeeds = findNode::getClass<TrackSeedContainer>(topNode,
"SiliconTrackSeedContainer");
764 std::cout <<
PHWHERE <<
"SiliconTrackSeedContainer not on node tree. Bailing"
769 m_clusterContainer = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
773 <<
"No trkr cluster container, exiting." << std::endl;
777 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
780 std::cout <<
"ActsGeometry not on node tree. Exiting."
786 m_seedMap = findNode::getClass<TrackSeedContainer>(topNode,
"SvtxTrackSeedContainer");
789 std::cout <<
"No Svtx seed map on node tree. Exiting."
795 _dcc_static = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerStatic");
798 std::cout <<
PHWHERE <<
" found static TPC distortion correction container" << std::endl;
800 _dcc_average = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerAverage");
803 std::cout <<
PHWHERE <<
" found average TPC distortion correction container" << std::endl;
805 _dcc_fluctuation = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerFluctuation");
808 std::cout <<
PHWHERE <<
" found fluctuation TPC distortion correction container" << std::endl;
854 for(
auto seed : {tpcseed, siseed})
856 for(
auto it =
seed->begin_cluster_keys();
it !=
seed->end_cluster_keys();
861 m_locx.push_back(cluster->getLocalX());
862 float ly = cluster->getLocalY();
866 double zdriftlength = cluster->getLocalY() * drift_velocity;
867 double surfCenterZ = 52.89;
868 double zloc = surfCenterZ - zdriftlength;
870 if (side == 0) zloc = -zloc;
875 m_x.push_back(glob.x());
876 m_y.push_back(glob.y());
877 m_z.push_back(glob.z());
878 float r = std::sqrt(glob.x()*glob.x()+glob.y()*glob.y());
880 TVector3 globt(glob.x(), glob.y(), glob.z());
881 m_phi.push_back(globt.Phi());
882 m_eta.push_back(globt.Eta());
883 m_phisize.push_back(cluster->getPhiSize());
884 m_zsize.push_back(cluster->getZSize());
888 m_ephi.push_back(std::sqrt(para_errors.first));
889 m_ez.push_back(std::sqrt(para_errors.second));
923 std::vector<Acts::Vector3> global_vec;
929 auto key = *clusIter;
933 std::cout <<
"MakeSourceLinks::getCharge: Failed to get cluster with key " << key <<
" for track seed" << std::endl;
938 if (!
surf) {
continue; }
947 global_vec.push_back(glob);
954 for (
int i = 0;
i < global_vec.size(); ++
i)
958 float r = radius(global.x(), global.y());
961 if (r > largestR && global.y() > 0)
963 globalMostOuter = global_vec[
i];
969 float maxdr = std::numeric_limits<float>::max();
970 for (
int i = 0;
i < global_vec.size();
i++)
972 if (global_vec[
i].
y() < 0)
continue;
974 float dr = std::sqrt(
square(globalMostOuter.x()) +
square(globalMostOuter.y())) - std::sqrt(
square(global_vec[
i].
x()) +
square(global_vec[
i].
y()));
977 if (dr < maxdr && dr > 10)
980 globalSecondMostOuter = global_vec[
i];
987 globalMostOuter -= vertex;
988 globalSecondMostOuter -= vertex;
990 const auto firstphi = atan2(globalMostOuter.y(), globalMostOuter.x());
991 const auto secondphi = atan2(globalSecondMostOuter.y(),
992 globalSecondMostOuter.x());
993 auto dphi = secondphi - firstphi;
995 if (dphi > M_PI) dphi = 2. * M_PI -
dphi;
996 if (dphi < -M_PI) dphi = 2 * M_PI +
dphi;
1007 float r1 = std::sqrt(
square(globalMostOuter.x()) +
square(globalMostOuter.y()));
1008 float r2 = std::sqrt(
square(globalSecondMostOuter.x()) +
square(globalSecondMostOuter.y()));
1009 float z1 = globalMostOuter.z();
1010 float z2 = globalSecondMostOuter.z();
1011 cosmicslope = (r2 -
r1) / (z2 - z1);