19 #include <phfield/PHField.h>
20 #include <phfield/PHFieldUtility.h>
21 #include <phfield/PHFieldConfig.h>
22 #include <phfield/PHFieldConfigv1.h>
44 #include <Geant4/G4SystemOfUnits.hh>
47 #include <Eigen/Dense>
55 #define LogDebug(exp) std::cout << "DEBUG: " << __FILE__ << ": " << __LINE__ << ": " << exp
57 #define LogDebug(exp) (void)0
60 #define LogError(exp) std::cout << "ERROR: " << __FILE__ << ": " << __LINE__ << ": " << exp
61 #define LogWarning(exp) std::cout << "WARNING: " << __FILE__ << ": " << __LINE__ << ": " << exp
67 template<
class T>
inline constexpr
T square(
const T&
x ) {
return x*
x; }
70 using keylist = std::vector<TrkrDefs::cluskey>;
88 char *calibrationsroot = getenv(
"CALIBRATIONROOT");
91 std::string(
"/Field/Map/sphenix3dtrackingmapxyz.root");
113 double p[4] = {x*
cm,y*
cm,z*
cm,0.*cm};
128 return bfield[2]/tesla;
137 _tgeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
140 std::cout <<
"No Acts tracking geometry, exiting." << std::endl;
145 m_dcc = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainer");
147 { std::cout <<
"PHSimpleKFProp::InitRun - found TPC distortion correction container" << std::endl; }
150 _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER_TRUTH");
152 _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
156 std::cerr <<
PHWHERE <<
" ERROR: Can't find node TRKR_CLUSTER" << std::endl;
160 _track_map = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
163 std::cerr <<
PHWHERE <<
" ERROR: Can't find TrackSeedContainer " << std::endl;
168 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
171 std::cerr <<
PHWHERE <<
"ERROR: Can't find node CYLINDERCELLGEOM_SVTX" << std::endl;
175 for(
int i=7;
i<=54;
i++)
186 _iteration_map = findNode::getClass<TrkrClusterIterationMapv1>(topNode,
"CLUSTER_ITERATION_MAP");
188 std::cerr <<
PHWHERE <<
"Cluster Iteration Map missing, aborting." << std::endl;
198 if(
Verbosity()>0) std::cout <<
"starting Process" << std::endl;
200 if(
Verbosity()>0) std::cout <<
"prepared KD trees" << std::endl;
202 std::vector<std::vector<TrkrDefs::cluskey>> new_chains;
203 std::vector<TrackSeed_v1> unused_tracks;
204 for(
int track_it = 0; track_it !=
_track_map->
size(); ++track_it )
206 if(
Verbosity()>0) std::cout <<
"TPC seed " << track_it << std::endl;
209 const bool is_tpc = std::any_of(
216 std::vector<std::vector<TrkrDefs::cluskey>>
keylist;
217 std::vector<TrkrDefs::cluskey> dumvec;
218 std::map<TrkrDefs::cluskey, Acts::Vector3> trackClusPositions;
223 dumvec.push_back(*iter);
224 auto pos = globalPositions.at(*iter);
225 trackClusPositions.insert(std::make_pair(*iter,
pos));
229 if(dumvec.size() < 3)
232 keylist.push_back(dumvec);
236 std::vector<float> trackChi2;
240 auto seedpair =
fitter->ALICEKalmanFilter(keylist,
false,
241 trackClusPositions, trackChi2);
245 { std::cout <<
"single track ALICEKF time " << timer.
elapsed()
251 track->
lineFit(trackClusPositions, 7, 55);
254 { std::cout <<
"single track circle fit time " << timer.
elapsed() << std::endl; }
255 if(seedpair.first.size() == 0 || seedpair.second.size() == 0)
257 if(
Verbosity()>0) std::cout <<
"is tpc track" << std::endl;
262 if(
Verbosity()>0) std::cout <<
"propagate first round" << std::endl;
263 auto preseed =
PropagateTrack(track,seedpair.second.at(0),globalPositions);
265 if(
Verbosity()>0) std::cout <<
"preseed size " << preseed.size() << std::endl;
267 if(preseed.size()>40){
268 new_chains.push_back(preseed);
272 std::vector<std::vector<TrkrDefs::cluskey>> kl;
273 kl.push_back(preseed);
275 if(
Verbosity()>0) std::cout <<
"kl size " << kl.size() << std::endl;
276 std::vector<float> pretrackChi2;
277 auto prepair =
fitter->ALICEKalmanFilter(kl,
false,globalPositions,pretrackChi2);
278 if(prepair.first.size()==0 || prepair.second.size()==0)
continue;
280 auto pretrack = prepair.first.at(0);
281 std::vector<TrkrDefs::cluskey> dumvec2;
282 std::map<TrkrDefs::cluskey, Acts::Vector3> pretrackClusPositions;
284 iter != pretrack.end_cluster_keys();
287 dumvec2.push_back(*iter);
288 auto pos = globalPositions.at(*iter);
289 pretrackClusPositions.insert(std::make_pair(*iter,
pos));
292 pretrack.circleFitByTaubin(pretrackClusPositions, 7, 55);
293 pretrack.lineFit(pretrackClusPositions, 7, 55);
295 new_chains.push_back(
PropagateTrack(&pretrack, prepair.second.at(0),
298 auto propagatetime = timer.
elapsed();
300 { std::cout <<
"propagate track time " << propagatetime << std::endl; }
305 if(
Verbosity()>0) std::cout <<
"is NOT tpc track" << std::endl;
306 unused_tracks.push_back(*track);
314 std::vector<std::vector<TrkrDefs::cluskey>> clean_chains =
RemoveBadClusters(new_chains, globalPositions);
319 std::vector<float> trackChi2;
320 auto seeds =
fitter->ALICEKalmanFilter(clean_chains,
true, globalPositions,
323 auto alicekftime = timer.
elapsed();
325 { std::cout <<
"full alice kf time all tracks " << alicekftime << std::endl; }
331 auto circlefittime = timer.
elapsed();
333 { std::cout <<
"circle fit all tracks time " << circlefittime << std::endl; }
345 { std::cout <<
"ghost rejection time " << timer.
elapsed() << std::endl; }
365 std::vector<std::vector<std::vector<double> > > kdhits;
369 std::cout <<
"WARNING: (tracking.PHTpcTrackerUtil.convert_clusters_to_hits) cluster map is not provided" << std::endl;
370 return globalPositions;
380 if(!cluster)
continue;
392 const Acts::Vector3 globalpos = { (float) globalpos_d.x(), (float) globalpos_d.y(), (float) globalpos_d.z()};
393 globalPositions.insert(std::make_pair(cluskey, globalpos));
396 std::vector<double> kdhit(4);
397 kdhit[0] = globalpos_d.x();
398 kdhit[1] = globalpos_d.y();
399 kdhit[2] = globalpos_d.z();
401 std::memcpy(&kdhit[3], &key,
sizeof(key));
408 kdhits[
layer].push_back(kdhit);
413 for(
size_t l=0;l<kdhits.size();++l)
415 if(
Verbosity()>0) std::cout <<
"l: " << l << std::endl;
416 _ptclouds[l] = std::make_shared<KDPointCloud<double>>();
418 if(
Verbosity()>0) std::cout <<
"resized to " << kdhits[l].size() << std::endl;
419 for(
size_t i=0;
i<kdhits[l].size();++
i)
427 return globalPositions;
435 std::vector<TrkrDefs::cluskey> ckeys;
440 std::reverse(ckeys.begin(),ckeys.end());
443 double track_x = track->
get_x();
444 double track_y = track->
get_y();
445 double track_z = track->
get_z();
447 if(
Verbosity()>0) std::cout <<
"track (x,y,z) = (" << track_x <<
", " << track_y <<
", " << track_z <<
")" << std::endl;
449 double track_px = NAN;
450 double track_py = NAN;
451 double track_pz = NAN;
456 track_px = pt * std::cos(phi);
457 track_py = pt * std::sin(phi);
464 track_pz = track->
get_pz();
467 if(
Verbosity()>0) std::cout <<
"track (px,py,pz) = (" << track_px <<
", " << track_py <<
", " << track_pz <<
")" << std::endl;
472 if(
Verbosity()>0) std::cout <<
"WARNING: moving track into TPC" << std::endl;
473 std::vector<Acts::Vector3> trkGlobPos;
474 for(
const auto& ckey : ckeys)
477 { trkGlobPos.push_back(globalPositions.at(ckey)); }
483 inner_index = ckeys.size()-1;
490 double xc = track->
get_X0();
491 double yc = track->
get_Y0();
492 double cluster_x = trkGlobPos.at(inner_index)(0);
493 double cluster_y = trkGlobPos.at(inner_index)(1);
494 double dy = cluster_y-yc;
495 double dx = cluster_x-xc;
496 double phi = atan2(dy,dx);
497 double dx0 = trkGlobPos.at(0)(0) - xc;
498 double dy0 = trkGlobPos.at(0)(1) - yc;
499 double phi0 = atan2(dy0, dx0);
500 double dx1 = trkGlobPos.at(1)(0) - xc;
501 double dy1 = trkGlobPos.at(1)(1) - yc;
502 double phi1 = atan2(dy1, dx1);
503 double dphi = phi1 - phi0;
510 double pt = sqrt(track_px*track_px+track_py*track_py);
512 track_px = pt * cos(phi);
513 track_py = pt * sin(phi);
514 track_x = trkGlobPos.at(0)(0);
515 track_y = trkGlobPos.at(0)(1);
516 track_z = trkGlobPos.at(0)(2);
518 if(
Verbosity()>0) std::cout <<
"new track (x,y,z) = " << track_x <<
", " << track_y <<
", " << track_z <<
")" << std::endl;
519 if(
Verbosity()>0) std::cout <<
"new track (px,py,pz) = " << track_px <<
", " << track_py <<
", " << track_pz <<
")" << std::endl;
523 double track_pt = sqrt(track_px*track_px + track_py*track_py);
524 if(
Verbosity()>0) std::cout <<
"track pt: " << track_pt << std::endl;
529 float track_phi = atan2(track_y,track_x);
530 if(
Verbosity()>0) std::cout <<
"track phi: " << track_phi << std::endl;
533 float track_pX = track_px*cos(track_phi)+track_py*sin(track_phi);
534 float track_pY = -track_px * sin(track_phi) + track_py * cos(track_phi);
538 kftrack.
SetDzDs(-track_pz/track_pt);
546 const double track_pt3 = std::pow( track_pt, 3. );
548 Eigen::Matrix<double,6,5> Jrot;
566 Jrot(3,2) = -track_py*track_px/track_pt3;
567 Jrot(4,2) = track_px*track_px/track_pt3;
573 Jrot(3,3) = -track_px*track_pz/track_pt3;
574 Jrot(4,3) = -track_py*track_pz/track_pt3;
575 Jrot(5,3) = 1./track_pt;
580 Jrot(3,4) = -track_px/track_pt3;
581 Jrot(4,4) = -track_py/track_pt3;
584 Eigen::Matrix<double,5,5> kfCov = Jrot.transpose()*xyzCov*Jrot;
599 std::vector<TrkrDefs::cluskey> propagated_track;
601 kftrack.
SetX(track_x*cos(track_phi)+track_y*sin(track_phi));
602 kftrack.
SetY(-track_x*sin(track_phi)+track_y*cos(track_phi));
603 kftrack.
SetZ(track_z);
607 std::cout <<
"initial track params:" << std::endl;
608 std::cout <<
"X: " << kftrack.
GetX() << std::endl;
609 std::cout <<
"Y: " << kftrack.
GetY() << std::endl;
610 std::cout <<
"Z: " << kftrack.
GetZ() << std::endl;
611 std::cout <<
"SinPhi: " << kftrack.
GetSinPhi() << std::endl;
612 std::cout <<
"DzDs: " << kftrack.
GetDzDs() << std::endl;
613 std::cout <<
"QPt: " << kftrack.
GetQPt() << std::endl;
614 std::cout <<
"cov: " << std::endl;
615 for(
int i=0;
i<15;
i++) std::cout << kftrack.
GetCov(
i) <<
", ";
616 std::cout << std::endl;
621 std::vector<unsigned int> layers;
624 double old_phi = track_phi;
626 if(
Verbosity()>0) std::cout <<
"first layer: " << old_layer << std::endl;
627 if(
Verbosity()>0) std::cout <<
"cluster (x,y,z) = (" << globalPositions.at(ckeys[0])(0) <<
", " << globalPositions.at(ckeys[0])(1) <<
", " << globalPositions.at(ckeys[0])(2) <<
")" << std::endl;
628 propagated_track.push_back(ckeys[0]);
635 for(
unsigned int l=old_layer+1;l<=54;l++)
637 if(std::isnan(kftrack.
GetX()) ||
638 std::isnan(kftrack.
GetY()) ||
639 std::isnan(kftrack.
GetZ()))
continue;
640 if(fabs(kftrack.
GetZ())>105.)
continue;
641 if(
Verbosity()>0) std::cout <<
"\nlayer " << l <<
":" << std::endl;
644 bool layer_filled =
false;
646 for(
int k=layers.size()-1;
k>=0;
k--)
648 if(layer_filled)
continue;
652 next_ckey = ckeys[
k];
658 if(
Verbosity()>0) std::cout <<
"layer is filled" << std::endl;
660 auto globalpos = globalPositions.at(next_ckey);
661 double cx = globalpos(0);
662 double cy = globalpos(1);
663 double cz = globalpos(2);
664 double cphi = atan2(cy,cx);
665 double cxerr = sqrt(
fitter->getClusterError(nc,next_ckey,globalpos,0,0));
666 double cyerr = sqrt(
fitter->getClusterError(nc,next_ckey,globalpos,1,1));
667 double czerr = sqrt(
fitter->getClusterError(nc,next_ckey,globalpos,2,2));
668 double alpha = cphi-old_phi;
669 double tX = kftrack.
GetX();
670 double tY = kftrack.
GetY();
671 double tx = tX*cos(old_phi)-tY*sin(old_phi);
672 double ty = tX*sin(old_phi)+tY*cos(old_phi);
673 double tz = kftrack.
GetZ();
676 if(
Verbosity()>0) std::cout <<
"track position: (" << tx <<
", " << ty <<
", " << tz <<
")" << std::endl;
677 kftrack.
Rotate(alpha/2.,kfline,10.);
678 double newX = cx*cos(cphi)+cy*sin(cphi);
680 kftrack.
Rotate(alpha/2.,kfline,10.);
682 if(std::isnan(kftrack.
GetX()) ||
683 std::isnan(kftrack.
GetY()) ||
684 std::isnan(kftrack.
GetZ()))
continue;
687 tx = tX*cos(cphi)-tY*sin(cphi);
688 ty = tX*sin(cphi)+tY*cos(cphi);
690 double tYerr = sqrt(kftrack.
GetCov(0));
691 double tzerr = sqrt(kftrack.
GetCov(5));
692 double txerr = fabs(tYerr*sin(cphi));
693 double tyerr = fabs(tYerr*cos(cphi));
694 if(
Verbosity()>0) std::cout <<
"cluster position: (" << cx <<
", " << cy <<
", " << cz <<
")" << std::endl;
695 if(
Verbosity()>0) std::cout <<
"cluster position errors: (" << cxerr <<
", " << cyerr <<
", " << czerr <<
")" << std::endl;
696 if(
Verbosity()>0) std::cout <<
"new track position: (" << kftrack.
GetX()*cos(cphi)-kftrack.
GetY()*sin(cphi) <<
", " << kftrack.
GetX()*sin(cphi)+kftrack.
GetY()*cos(cphi) <<
", " << kftrack.
GetZ() <<
")" << std::endl;
697 if(
Verbosity()>0) std::cout <<
"track position errors: (" << txerr <<
", " << tyerr <<
", " << tzerr <<
")" << std::endl;
703 if(
Verbosity()>0) std::cout <<
"Kept cluster" << std::endl;
704 propagated_track.push_back(next_ckey);
713 std::cout <<
"Rejected cluster" << std::endl;
714 std::cout <<
"dx: " << fabs(tx-cx) <<
" when max = " <<
_max_dist*sqrt(txerr*txerr+cxerr*cxerr) << std::endl;
715 std::cout <<
"dy: " << fabs(ty-cy) <<
" when max = " <<
_max_dist*sqrt(tyerr*tyerr+cyerr*cyerr) << std::endl;
716 std::cout <<
"dz: " << fabs(tz-cz) <<
" when max = " <<
_max_dist*sqrt(tzerr*tzerr+czerr*czerr) << std::endl;
726 if(
Verbosity()>0) std::cout <<
"layer not filled" << std::endl;
728 double tX = kftrack.
GetX();
729 double tY = kftrack.
GetY();
730 double tx = tX*cos(old_phi)-tY*sin(old_phi);
731 double ty = tX*sin(old_phi)+tY*cos(old_phi);
732 double tz = kftrack.
GetZ();
735 double newX =
radii[l-7];
736 double alpha = atan2(ty,tx)-old_phi;
737 kftrack.
Rotate(alpha/2.,kfline,10.);
739 kftrack.
Rotate(alpha/2.,kfline,10.);
741 if(std::isnan(kftrack.
GetX()) ||
742 std::isnan(kftrack.
GetY()) ||
743 std::isnan(kftrack.
GetZ()))
continue;
747 double tYerr = sqrt(kftrack.
GetCov(0));
748 double tzerr = sqrt(kftrack.
GetCov(5));
749 tx = tX*cos(old_phi)-tY*sin(old_phi);
750 ty = tX*sin(old_phi)+tY*cos(old_phi);
752 double query_pt[3] = {tx, ty, tz};
760 double proj_radius = sqrt(tx*tx+ty*ty);
761 if(proj_radius > 78.0 || abs(tz) > 105.5)
continue;
765 std::cout <<
" call distortion correction for layer " << l <<
" tx " << tx <<
" ty " << ty <<
" tz " << tz <<
" radius " << proj_radius << std::endl;
768 double radius = sqrt(proj_pt[0]*proj_pt[0] + proj_pt[1]*proj_pt[1]);
771 std::cout <<
" call transport again for layer " << l <<
" x " << proj_pt[0] <<
" y " << proj_pt[1] <<
" z " << proj_pt[2]
772 <<
" radius " << radius << std::endl;
773 double newX = radius;
774 double alpha = atan2(ty,tx)-old_phi;
775 kftrack.
Rotate(alpha/2.,kfline,10.);
777 kftrack.
Rotate(alpha/2.,kfline,10.);
779 if(std::isnan(kftrack.
GetX()) ||
780 std::isnan(kftrack.
GetY()) ||
781 std::isnan(kftrack.
GetZ()))
continue;
784 tYerr = sqrt(kftrack.
GetCov(0));
785 tzerr = sqrt(kftrack.
GetCov(5));
786 tx = tX*cos(old_phi)-tY*sin(old_phi);
787 ty = tX*sin(old_phi)+tY*cos(old_phi);
794 double txerr = fabs(tYerr*sin(old_phi));
795 double tyerr = fabs(tYerr*cos(old_phi));
796 if(
Verbosity()>0) std::cout <<
"transported to " <<
radii[l-7] <<
"\n";
797 if(
Verbosity()>0) std::cout <<
"track position: (" << tx <<
", " << ty <<
", " << tz <<
")" << std::endl;
798 if(
Verbosity()>0) std::cout <<
"track position error: (" << txerr <<
", " << tyerr <<
", " << tzerr <<
")" << std::endl;
805 std::vector<long unsigned int> index_out(1);
806 std::vector<double> distance_out(1);
807 int n_results =
_kdtrees[l]->knnSearch(&query_pt[0],1,&index_out[0],&distance_out[0]);
808 if(
Verbosity()>0) std::cout <<
"index_out: " << index_out[0] << std::endl;
809 if(
Verbosity()>0) std::cout <<
"squared_distance_out: " << distance_out[0] << std::endl;
810 if(
Verbosity()>0) std::cout <<
"solid_angle_dist: " << atan2(sqrt(distance_out[0]),radii[l-7]) << std::endl;
811 if(n_results==0)
continue;
815 auto ccglob = globalPositions.at(closest_ckey);
816 double ccX = ccglob(0);
817 double ccY = ccglob(1);
818 double ccZ = ccglob(2);
864 double cxerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob,0,0));
865 double cyerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob,1,1));
866 double czerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob,2,2));
867 double ccphi = atan2(ccY,ccX);
868 if(
Verbosity()>0) std::cout <<
"cluster position: (" << ccX <<
", " << ccY <<
", " << ccZ <<
")" << std::endl;
869 if(
Verbosity()>0) std::cout <<
"cluster position error: (" << cxerr <<
", " << cyerr <<
", " << czerr <<
")" << std::endl;
870 if(
Verbosity()>0) std::cout <<
"cluster X: " << ccX*cos(ccphi)+ccY*sin(ccphi) << std::endl;
871 if(fabs(tx-ccX)<
_max_dist*sqrt(txerr*txerr+cxerr*cxerr) &&
872 fabs(ty-ccY)<
_max_dist*sqrt(tyerr*tyerr+cyerr*cyerr) &&
873 fabs(tz-ccZ)<
_max_dist*sqrt(tzerr*tzerr+czerr*czerr))
875 propagated_track.push_back(closest_ckey);
886 double alpha = ccphi-old_phi;
887 kftrack.
Rotate(alpha,kfline,10.);
891 double ccaY = -ccX*sin(ccphi)+ccY*cos(ccphi);
892 double ccerrY =
fitter->getClusterError(cc,closest_ckey,ccglob,0,0)*sin(ccphi)*sin(ccphi)+
fitter->getClusterError(cc,closest_ckey,ccglob,0,1)*sin(ccphi)*cos(ccphi)+
fitter->getClusterError(cc,closest_ckey,ccglob,1,1)*cos(ccphi)*cos(ccphi);
893 double ccerrZ =
fitter->getClusterError(cc,closest_ckey,ccglob,2,2);
895 if(
Verbosity()>0) std::cout <<
"added cluster" << std::endl;
904 if(
Verbosity()>0) std::cout <<
"\nlayers after outward propagation:" << std::endl;
905 for(
int i=0;
i<propagated_track.size();
i++)
908 if(
Verbosity()>0) std::cout << layers[
i] << std::endl;
911 for(
unsigned int l=old_layer-1;l>=7;l--)
913 if(std::isnan(kftrack.
GetX()) ||
914 std::isnan(kftrack.
GetY()) ||
915 std::isnan(kftrack.
GetZ()))
continue;
916 if(
Verbosity()>0) std::cout <<
"\nlayer " << l <<
":" << std::endl;
919 bool layer_filled =
false;
921 for(
size_t k=0;
k<layers.size();
k++)
923 if(layer_filled)
continue;
927 next_ckey = propagated_track[
k];
933 if(
Verbosity()>0) std::cout <<
"layer is filled" << std::endl;
934 auto ncglob = globalPositions.at(next_ckey);
935 double cx = ncglob(0);
936 double cy = ncglob(1);
937 double cz = ncglob(2);
938 double cphi = atan2(cy,cx);
939 double alpha = cphi-old_phi;
940 double tX = kftrack.
GetX();
941 double tY = kftrack.
GetY();
942 double tx = tX*cos(old_phi)-tY*sin(old_phi);
943 double ty = tX*sin(old_phi)+tY*cos(old_phi);
944 double tz = kftrack.
GetZ();
947 kftrack.
Rotate(alpha/2.,kfline,10.);
948 double newX = cx*cos(cphi)+cy*sin(cphi);
950 kftrack.
Rotate(alpha/2.,kfline,10.);
952 if(std::isnan(kftrack.
GetX()) ||
953 std::isnan(kftrack.
GetY()) ||
954 std::isnan(kftrack.
GetZ()))
continue;
955 if(
Verbosity()>0) std::cout <<
"transported to " <<
radii[l-7] <<
"\n";
956 if(
Verbosity()>0) std::cout <<
"track position: (" << kftrack.
GetX()*cos(cphi)-kftrack.
GetY()*sin(cphi) <<
", " << kftrack.
GetX()*sin(cphi)+kftrack.
GetY()*cos(cphi) <<
", " << kftrack.
GetZ() <<
")" << std::endl;
957 if(
Verbosity()>0) std::cout <<
"cluster position: (" << cx <<
", " << cy <<
", " << cz <<
")" << std::endl;
967 if(
Verbosity()>0) std::cout <<
"layer not filled" << std::endl;
968 double tX = kftrack.
GetX();
969 double tY = kftrack.
GetY();
970 double tx = tX*cos(old_phi)-tY*sin(old_phi);
971 double ty = tX*sin(old_phi)+tY*cos(old_phi);
972 double tz = kftrack.
GetZ();
975 double newX =
radii[l-7];
976 double alpha = atan2(ty,tx)-old_phi;
977 kftrack.
Rotate(alpha/2.,kfline,10.);
979 kftrack.
Rotate(alpha/2.,kfline,10.);
981 if(std::isnan(kftrack.
GetX()) ||
982 std::isnan(kftrack.
GetY()) ||
983 std::isnan(kftrack.
GetZ()))
continue;
986 double tYerr = sqrt(kftrack.
GetCov(0));
987 double tzerr = sqrt(kftrack.
GetCov(5));
988 tx = tX*cos(old_phi)-tY*sin(old_phi);
989 ty = tX*sin(old_phi)+tY*cos(old_phi);
991 double query_pt[3] = {tx, ty, tz};
999 double proj_radius = sqrt(tx*tx+ty*ty);
1000 if(proj_radius > 78.0 || abs(tz) > 105.5)
continue;
1004 std::cout <<
" call distortion correction for layer " << l <<
" tx " << tx <<
" ty " << ty <<
" tz " << tz <<
" radius " << proj_radius << std::endl;
1007 double radius = sqrt(proj_pt[0]*proj_pt[0] + proj_pt[1]*proj_pt[1]);
1011 std::cout <<
" call transport again for layer " << l <<
" x " << proj_pt[0] <<
" y " << proj_pt[1] <<
" z " << proj_pt[2]
1012 <<
" radius " << radius << std::endl;
1013 double newX = radius;
1014 double alpha = atan2(ty,tx)-old_phi;
1015 kftrack.
Rotate(alpha/2.,kfline,10.);
1017 kftrack.
Rotate(alpha/2.,kfline,10.);
1019 if(std::isnan(kftrack.
GetX()) ||
1020 std::isnan(kftrack.
GetY()) ||
1021 std::isnan(kftrack.
GetZ()))
continue;
1022 tX = kftrack.
GetX();
1023 tY = kftrack.
GetY();
1024 tYerr = sqrt(kftrack.
GetCov(0));
1025 tzerr = sqrt(kftrack.
GetCov(5));
1026 tx = tX*cos(old_phi)-tY*sin(old_phi);
1027 ty = tX*sin(old_phi)+tY*cos(old_phi);
1028 tz = kftrack.
GetZ();
1034 double txerr = fabs(tYerr*sin(old_phi));
1035 double tyerr = fabs(tYerr*cos(old_phi));
1036 if(
Verbosity()>0) std::cout <<
"transported to " <<
radii[l-7] <<
"\n";
1037 if(
Verbosity()>0) std::cout <<
"track position: (" << kftrack.
GetX()*cos(old_phi)-kftrack.
GetY()*sin(old_phi) <<
", " << kftrack.
GetX()*sin(old_phi)+kftrack.
GetY()*cos(old_phi) <<
", " << kftrack.
GetZ() <<
")" << std::endl;
1038 if(
Verbosity()>0) std::cout <<
"track position errors: (" << txerr <<
", " << tyerr <<
", " << tzerr <<
")" << std::endl;
1040 std::vector<long unsigned int> index_out(1);
1041 std::vector<double> distance_out(1);
1042 int n_results =
_kdtrees[l]->knnSearch(&query_pt[0],1,&index_out[0],&distance_out[0]);
1043 if(
Verbosity()>0) std::cout <<
"index_out: " << index_out[0] << std::endl;
1044 if(
Verbosity()>0) std::cout <<
"squared_distance_out: " << distance_out[0] << std::endl;
1045 if(
Verbosity()>0) std::cout <<
"solid_angle_dist: " << atan2(sqrt(distance_out[0]),radii[l-7]) << std::endl;
1046 if(n_results==0)
continue;
1050 auto ccglob2 = globalPositions.at(closest_ckey);
1051 double ccX = ccglob2(0);
1052 double ccY = ccglob2(1);
1053 double ccZ = ccglob2(2);
1099 double cxerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob2,0,0));
1100 double cyerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob2,1,1));
1101 double czerr = sqrt(
fitter->getClusterError(cc,closest_ckey,ccglob2,2,2));
1102 if(
Verbosity()>0) std::cout <<
"cluster position: (" << ccX <<
", " << ccY <<
", " << ccZ <<
")" << std::endl;
1103 double ccphi = atan2(ccY,ccX);
1104 if(
Verbosity()>0) std::cout <<
"cluster position errors: (" << cxerr <<
", " << cyerr <<
", " << czerr <<
")" << std::endl;
1105 if(
Verbosity()>0) std::cout <<
"cluster X: " << ccX*cos(ccphi)+ccY*sin(ccphi) << std::endl;
1106 double alpha2 = ccphi-old_phi;
1107 if(fabs(tx-ccX)<
_max_dist*sqrt(txerr*txerr+cxerr*cxerr) &&
1108 fabs(ty-ccY)<
_max_dist*sqrt(tyerr*tyerr+cyerr*cyerr) &&
1109 fabs(tz-ccZ)<
_max_dist*sqrt(tzerr*tzerr+czerr*czerr))
1111 propagated_track.push_back(closest_ckey);
1123 kftrack.
Rotate(alpha2,kfline,10.);
1124 double ccaY = -ccX*sin(ccphi)+ccY*cos(ccphi);
1125 double ccerrY =
fitter->getClusterError(cc,closest_ckey,ccglob2,0,0)*sin(ccphi)*sin(ccphi)+
fitter->getClusterError(cc,closest_ckey,ccglob2,1,0)*sin(ccphi)*cos(ccphi)+
fitter->getClusterError(cc,closest_ckey,ccglob2,1,1)*cos(ccphi)*cos(ccphi);
1126 double ccerrZ =
fitter->getClusterError(cc,closest_ckey,ccglob2,2,2);
1131 if(
Verbosity()>0) std::cout <<
"added cluster" << std::endl;
1137 std::sort(propagated_track.begin(),propagated_track.end(),
1140 return propagated_track;
1145 if(
Verbosity()>0) std::cout <<
"removing bad clusters" << std::endl;
1146 std::vector<keylist> clean_chains;
1147 for(
const keylist& chain : chains)
1149 if(chain.size()<3)
continue;
1152 std::vector<std::pair<double,double>> xy_pts;
1153 std::vector<std::pair<double,double>> rz_pts;
1156 auto global = globalPositions.at(ckey);
1157 xy_pts.push_back(std::make_pair(global(0),global(1)));
1158 float r = sqrt(global(0)*global(0) + global(1)*global(1));
1159 rz_pts.push_back(std::make_pair(r,global(2)));
1161 if(
Verbosity()>0) std::cout <<
"chain size: " << chain.size() << std::endl;
1171 for(
size_t i=0;
i<chain.size();
i++)
1174 clean_chain.push_back(chain[
i]);
1176 clean_chains.push_back(clean_chain);
1177 if(
Verbosity()>0) std::cout <<
"pushed clean chain with " << clean_chain.size() <<
" clusters" << std::endl;
1179 return clean_chains;
1186 for(
auto&
seed: seeds )
1189 int q =
seed.get_charge();
1193 seed.set_qOverR(fabs(
seed.get_qOverR()) * q);
1200 for(
const auto&
seed:seeds )