26 const std::string &
name,
27 const IInterface *
parent) :
30 declareInterface<InDet::ITRT_SegmentToTrackTool>(
this );
59 return StatusCode::SUCCESS;
84 std::string s1;
for(
int i=0;
i<
n; ++
i) s1.append(
" "); s1.append(
"|");
86 std::string
s2;
for(
int i=0;
i<
n; ++
i)
s2.append(
" ");
s2.append(
"|");
88 std::string s5;
for(
int i=0;
i<
n; ++
i) s5.append(
" "); s5.append(
"|");
92 <<
"|----------------------------------------------------------------------"
93 <<
"-------------------|"<<std::endl;
94 out<<
"| Tool for final track refitting | "<<
m_fitterTool.type() <<s1<<std::endl;
97 out<<
"|----------------------------------------------------------------------"
98 <<
"-------------------|";
122 ATH_MSG_DEBUG(
"Transforming the TRT segment into a track...");
151 ATH_MSG_DEBUG(
"Could not get initial TRT segment parameters! ");
157 auto ntsos = std::make_unique<Trk::TrackStates>();
170 std::unique_ptr<Trk::TrackParameters>
tmp =
172 std::unique_ptr<Trk::Perigee> perParm =
nullptr;
180 ATH_MSG_DEBUG(
"Failed to build perigee parameters.Discard...");
188 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
192 nullptr, std::move(perParm),
nullptr, typePattern);
194 ntsos->push_back(par_tsos);
203 double pseudotheta = 0;
206 const Trk::Surface *firstsurf =
nullptr, *firstecsurf =
nullptr,
210 int nbarrel = 0, nendcap = 0;
212 std::vector<std::pair<double, double>>
points;
277 std::abs(tmpphi - oldphi) >
M_PI) {
308 ntsos->push_back(seg_tsos);
329 double myqoverp = 0, myphi = 0, myd0 = 0, myz0 = 0, mytheta = pseudotheta;
343 std::unique_ptr<const Trk::TrackParameters>
tmp =
345 std::unique_ptr<const Trk::Perigee> tempper =
nullptr;
357 myd0 = tempper->parameters()[
Trk::d0];
358 myphi = tempper->parameters()[
Trk::phi0];
366 double sx = 0,
sy = 0, sxx = 0, sxy = 0,
d = 0;
370 for (
auto & point :
points) {
373 sxy += point.first * point.second;
374 sxx += point.first * point.first;
375 if (std::abs(point.first) > std::abs(
zmax)) {
378 if (std::abs(point.first) < std::abs(
zmin)) {
383 if (std::abs(pseudotheta) < 1.
e-6) {
390 double diff_z (meas_zmax.z() - meas_zmin.z());
391 if (std::abs(diff_z)>1
e-6) {
392 double diff_r( meas_zmax.perp() - meas_zmin.perp());
393 pseudotheta = std::atan2(diff_r, diff_z);
394 ATH_MSG_DEBUG(
"Initial pseudo theta is zero. Compute pseudo from inner- and outermost endcap measurements. delta R: " <<
395 meas_zmax.perp() <<
" - " << meas_zmin.perp() <<
" = " << diff_r
396 <<
" , diff Z: " << meas_zmax.z() <<
" - " << meas_zmin.z()
398 <<
" " << pseudotheta);
402 if (std::abs(pseudotheta) < 1.
e-6) {
403 constexpr std::array<float,2> boundary_r {644., 1004.};
405 bool is_across_sides=std::signbit(
zmin)!=std::signbit(
zmax);
406 double r_path=is_across_sides ? 2 * boundary_r[1] : boundary_r[1]-boundary_r[0];
409 if (surf_zmin && surf_zmax) {
410 bool is_reverse=std::abs(surf_zmin->
center().z())>std::abs(surf_zmax->
center().z());
417 std::array<const Trk::Surface *,2> boundary_surface{
418 is_reverse ? surf_zmax : surf_zmin,
419 is_reverse ? surf_zmin : surf_zmax};
421 std::array<Amg::Vector2D,2> translation;
422 std::array<Amg::Vector2D,2> height;
423 for (
unsigned int boundary_i=boundary_surface.size(); boundary_i-->0;) {
427 cylinder_bounds =
dynamic_cast<const Trk::CylinderBounds &
>(boundary_surface[boundary_i]->bounds());
428 height[boundary_i]= project2D( boundary_surface[boundary_i]->
transform().
rotation()
430 translation[boundary_i]=project2D( boundary_surface[boundary_i]->
transform().translation() );
433 r1 = (translation[1] + height[1] - ( translation[0] + height[0])).perp();
434 r2 = (translation[1] + height[1] - ( translation[0] - height[0])).perp();
438 pseudotheta = std::atan2(r_path,
zmax -
zmin);
439 ATH_MSG_DEBUG(
"Initial pseudo theta is zero. Pseudo theta from inner- and outermost surfaces. Deleta r " << r2 <<
" - " << r1 <<
" -> " << r_path
441 <<
" " << pseudotheta);
447 double dphidz = ((
points.size() * sxy -
sy *
sx) /
d);
448 myqoverp = (std::abs(pseudotheta) > 1
e-6)
449 ? -dphidz / (0.6 *
std::tan(pseudotheta))
462 double halfz2 = 200.;
468 Amg::Vector3D strawdir2 = -lastsurf->transform().rotation().col(2);
473 if (std::abs(lastsurf->center().z()) < 2650 *
mm) {
474 pos2 = lastsurf->center() + halfz2 * strawdir2;
476 double dr = std::abs(
std::tan(pseudotheta) * (lastsurf->center().z() -
477 firstsurf->
center().z()));
478 pos1 = firstsurf->
center() + (halfz -
dr) * strawdir1;
480 double dz = std::abs((pos2.perp() - firstsurf->
center().perp()) /
484 double z1 = pos2.z() + dz;
490 (lastsurf->center().z() - firstsurf->
center().z()));
491 pos2 = lastsurf->center() + (
dr - halfz2) * strawdir2;
492 pos1 = firstsurf->
center() - halfz * strawdir1;
499 lastsurf->center().z())) < 250 *
mm &&
500 std::abs(firstsurf->
center().z()) > 1000 *
mm) {
504 (**ntsos->begin()).measurementOnTrack();
508 newcov(1, 1) = (myqoverp != 0) ? .0001 * myqoverp * myqoverp : 1.
e-8;
512 std::make_unique<Trk::PseudoMeasurementOnTrack>(
517 ntsos->erase(ntsos->begin());
518 ntsos->insert(ntsos->begin(),
531 if (fieldCondObj ==
nullptr) {
533 "segToTrack: Failed to retrieve AtlasFieldCacheCondObj with key "
537 fieldCondObj->getInitializedCache(fieldCache);
545 double phideflection =
546 -.3 * (pos2 - pos1).
perp() * field1.z() * myqoverp /
std::sin(pseudotheta);
547 double precisephi = (nbarrel == 0)
548 ? (pos2 - pos1).phi() - .5 * phideflection
549 : (pos2 - pos1).phi() + .5 * phideflection;
550 double radius = (myqoverp != 0. && field1.z() != 0.)
551 ? -
std::sin(pseudotheta) / (.3 * field1.z() * myqoverp)
553 double precisetheta =
555 ? std::atan2(std::abs(
radius * phideflection), pos2.z() - pos1.z())
557 if (precisetheta < 0)
558 precisetheta +=
M_PI;
559 if (precisephi < -
M_PI)
560 precisephi += 2 *
M_PI;
561 if (precisephi >
M_PI)
562 precisephi -= 2 *
M_PI;
572 ATH_MSG_ERROR(
"Cast of surface failed, should never happen");
581 m_extrapolator->extrapolateDirectly(ctx, ataline, persurf).release();
586 myphi = extrappar->parameters()[
Trk::phi0];
587 myd0 = extrappar->parameters()[
Trk::d0];
591 double z0 = extrappar->parameters()[
Trk::z0];
594 std::abs((
z0 - pos1.z()) / pos1.z()));
597 std::abs((
z0 - pos2.z()) / pos2.z()));
608 while (myphi < -
M_PI)
611 double P[5] = { myd0, myz0, myphi, mytheta, myqoverp };
617 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
621 nullptr, std::move(per),
nullptr, typePattern);
622 ntsos->insert(ntsos->begin(), seg_tsos);
653 if ((*parit)->covariance() &&
655 firstmeaspar = *parit;
657 }
while (firstmeaspar ==
nullptr &&
666 if (!perTrack || !perTrack->covariance()) {
667 ATH_MSG_ERROR(
"Cast of perigee fails, should never happen !");
670 ATH_MSG_VERBOSE (
"Perigee after refit with fudges to make it converge : " << (*perTrack) );
672 if(firstmeaspar && firstmeaspar->
position().perp()<2000*
mm && std::abs(firstmeaspar->
position().z())<3000*
mm){
677 double scaleZ = std::sqrt(tS.
localCovariance()(1,1))/std::sqrt( (fcovmat)(1,1));
678 double scaleTheta = std::sqrt(tS.
localCovariance()(3,3))/std::sqrt( (fcovmat)(3,3));
680 fcovmat(1,0)=scaleZ*((fcovmat)(1,0));
681 fcovmat(0,1) = (fcovmat)(1,0);
683 fcovmat(2,1)=scaleZ*((fcovmat)(2,1));
684 fcovmat(1,2) = (fcovmat)(2,1);
685 fcovmat(3,1)=scaleZ*scaleTheta*((fcovmat)(3,1));
686 fcovmat(1,3) = (fcovmat)(3,1);
687 fcovmat(4,1)=scaleZ*((fcovmat)(4,1));
688 fcovmat(1,4) = (fcovmat)(4,1);
689 fcovmat(3,0)=scaleTheta*((fcovmat)(3,0));
690 fcovmat(0,3) = (fcovmat)(3,0);
691 fcovmat(3,2)=scaleTheta*((fcovmat)(3,2));
692 fcovmat(2,3) = (fcovmat)(3,2);
694 fcovmat(4,3)=scaleTheta*((fcovmat)(4,3));
695 fcovmat(3,4) = (fcovmat)(4,3);
706 std::move(fcovmat)).release();
716 delete updatedPars; updatedPars =
nullptr;
718 if (!newperpar || !newperpar->covariance()) {
719 ATH_MSG_WARNING (
"Can not hack perigee parameters, extrapolation failed");
720 delete newperpar; newperpar =
nullptr;
727 errmat = *newperpar->covariance();
728 delete newperpar; newperpar =
nullptr;
731 if( CM(1,1)==0.||CM(3,3)==0. ) {
732 ATH_MSG_DEBUG (
"Hacked perigee covariance is CRAP, reject track");
733 delete fitTrack;
return nullptr;
735 ATH_MSG_VERBOSE (
"Perigee after fit with scaled covariance matrix : " << *perTrack);
749 ATH_MSG_DEBUG (
"Checking whether the TRT segment has already been used...");
755 if (
m_assoTool.isEnabled()&& !prd_to_track_map)
ATH_MSG_ERROR(
"PRDtoTrackMap to be used but not provided by the client");
765 if (!trtcircle)
continue;
769 if(!RawDataClus)
continue;
774 if(
m_assoTool.isEnabled() && prd_to_track_map && prd_to_track_map->
isUsed(*RawDataClus)) nShared++;
778 ATH_MSG_DEBUG (
"Too many shared hits.Will drop the TRT segment");
789 ATH_MSG_DEBUG (
"Try to recover low TRT DC segments in crack...");
792 int nEC = 0;
int nBRL = 0;
int firstWheel = -999;
int lastLayer = -999;
803 if(!trtcircle)
continue;
809 if (isB==2 || isB==-2) {
814 else if (isB==1 || isB==-1) {
822 return (nEC>0 && nBRL>0) ||
824 (nEC==0 && nBRL>0 && lastLayer<2) ||
826 (nEC>0 && nBRL==0 && (firstWheel>10 || firstWheel<2));
835 bool passBasicSelections =
m_scoringTool->passBasicSelections(*trk);
836 if(passBasicSelections){
866 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map;
868 prd_to_track_map=
m_assoTool->createPRDtoTrackMap();
869 if (prd_to_track_map_in) {
870 *prd_to_track_map = *prd_to_track_map_in;
875 std::unique_ptr<TrackCollection> final_tracks = std::make_unique<TrackCollection>();
879 [](
const std::pair< Trk::TrackScore, Trk::Track* > &
a,
880 const std::pair< Trk::TrackScore, Trk::Track* > &
b)
881 { return a.first < b.first; });
883 for (std::pair< Trk::TrackScore, Trk::Track* > &track_score : event_data.
m_trackScores) {
885 ATH_MSG_DEBUG (
"--- Trying next track "<<track_score.second<<
"\t with score "<<-track_score.first);
892 const Trk::TrackStates* tsos = (track_score.second)->trackStateOnSurfaces();
922 ATH_MSG_DEBUG (
"TRT-only has " << nHits <<
" hits and " << nShared <<
" of them are shared");
929 delete track_score.second;
934 final_tracks->
push_back(track_score.second);
941 if(
m_assoTool->addPRDs(*prd_to_track_map,*(track_score.second)).isFailure()) {
948 return final_tracks.release();