47 inline constexpr
T square(
const T&
x ) {
return x*
x; }
61 bool circle_line_intersection(
62 double r,
double xc,
double yc,
63 double x0,
double y0,
double nx,
double ny,
64 double &xplus,
double &yplus,
double &xminus,
double &yminus)
73 if( delta < 0 )
return false;
75 const double sqdelta = std::sqrt( delta );
77 yminus = yc - sqdelta;
82 const double b = -2.*(
square(ny)*xc +
square(nx)*x0 + nx*ny*(y0-yc) );
84 const double delta =
square(b) - 4.*a*
c;
85 if( delta < 0 )
return false;
87 const double sqdelta = std::sqrt( delta );
88 xplus = (-b + sqdelta)/(2.*a);
89 xminus = (-b - sqdelta)/(2.*a);
91 yplus = y0 -(nx/
ny)*(xplus-x0);
92 yminus = y0 - (nx/
ny)*(xminus-x0);
101 [[maybe_unused]]
inline std::ostream&
operator << (std::ostream&
out,
const TVector3& vector )
103 out <<
"( " << vector.x() <<
"," << vector.y() <<
"," << vector.z() <<
")";
118 std::cout << std::endl <<
PHWHERE
129 std::cout <<
PHWHERE <<
"Could not find CYLINDERGEOM_MICROMEGAS_FULL." << std::endl;
136 std::cout <<
PHWHERE <<
"Inconsistent number of micromegas layers." << std::endl;
155 _iteration_map = findNode::getClass<TrkrClusterIterationMapv1>(topNode,
"CLUSTER_ITERATION_MAP");
158 std::cerr <<
PHWHERE <<
"Cluster Iteration Map missing, aborting." << std::endl;
171 for (
unsigned int seedID = 0;
175 auto siID =
seed->get_silicon_seed_index();
177 if(!tracklet_si)
continue;
180 if (crossing == SHRT_MAX)
183 std::cout <<
" svtx seed " << seedID <<
" with si seed " << siID <<
" crossing not defined: crossing = " << crossing <<
" skip this track" << std::endl;
187 auto tpcID =
seed->get_tpc_seed_index();
190 if(!tracklet_tpc) {
continue; }
194 std::cout << std::endl
196 <<
": Processing TPC seed track: " << tpcID
197 <<
": crossing: " << crossing
198 <<
": nhits: " << tracklet_tpc-> size_cluster_keys()
205 std::map<unsigned int, TrkrCluster*> outer_clusters;
207 std::vector<Acts::Vector3> clusGlobPos;
209 for (
auto key_iter = tracklet_tpc->begin_cluster_keys(); key_iter != tracklet_tpc->end_cluster_keys(); ++key_iter)
219 if(!tpc_clus)
continue;
221 outer_clusters.insert(std::make_pair(layer, tpc_clus));
222 clusters.push_back(tpc_clus);
226 clusGlobPos.push_back(global);
232 <<
" TPC cluster key " << cluster_key <<
" in layer " << layer <<
" side " << side <<
" crossing " << crossing
233 <<
" with local position " << tpc_clus->
getLocalX() <<
" " << tpc_clus->
getLocalY() << std::endl;
234 std::cout <<
" raw global position " << global_raw[0] <<
" " << global_raw[1] <<
" " << global_raw[2]
235 <<
" corrected global position " << global[0] <<
" " << global[1] <<
" " << global[2]
241 if(outer_clusters.size() < 3)
243 if(
Verbosity() > 3) std::cout <<
PHWHERE <<
" -- skip this tpc tracklet, not enough outer clusters " << std::endl;
249 if(
Verbosity() > 10) std::cout <<
" Fitted circle has R " <<
R <<
" X0 " << X0 <<
" Y0 " <<
Y0 << std::endl;
252 if(
R < 40.0)
continue;
256 if(
Verbosity() > 10) std::cout <<
" Fitted line has A " <<
A <<
" B " << B << std::endl;
265 const auto layer_radius = layergeom->
get_radius();
271 if( !std::isfinite(xplus) )
275 std::cout <<
PHWHERE <<
" circle/circle intersection calculation failed, skip this case" << std::endl;
276 std::cout <<
PHWHERE <<
" mm_radius " << layer_radius <<
" fitted R " <<
R <<
" fitted X0 " << X0 <<
" fitted Y0 " <<
Y0 << std::endl;
283 const double last_clus_phi = std::atan2(clusGlobPos.back()(1), clusGlobPos.back()(0));
284 double phi_plus = std::atan2(yplus, xplus);
285 double phi_minus = std::atan2(yminus, xminus);
288 double r = layer_radius;
293 double phi = std::abs(last_clus_phi - phi_plus) < std::abs(last_clus_phi - phi_minus) ? phi_plus:phi_minus;
296 const TVector3 world_intersection_cylindrical( r*std::cos(phi), r*std::sin(phi), z );
299 int tileid = layergeom->find_tile_cylindrical( world_intersection_cylindrical );
300 if( tileid < 0 )
continue;
303 const auto tile_center = layergeom->get_world_from_local_coords( tileid,
_tGeometry, {0, 0} );
304 const double x0 = tile_center.x();
305 const double y0 = tile_center.y();
307 const auto tile_norm = layergeom->get_world_from_local_vect( tileid,
_tGeometry, {0, 0, 1 } );
308 const double nx = tile_norm.x();
309 const double ny = tile_norm.y();
312 if( !circle_line_intersection(
R, X0,
Y0, x0, y0, nx, ny, xplus, yplus, xminus, yminus) )
315 { std::cout <<
PHWHERE <<
"circle_line_intersection - failed" << std::endl; }
320 phi_plus = std::atan2(yplus, xplus);
321 phi_minus = std::atan2(yminus, xminus);
322 const bool is_plus = (std::abs(last_clus_phi - phi_plus) < std::abs(last_clus_phi - phi_minus));
325 const double x = (is_plus ? xplus:xminus);
326 const double y = (is_plus ? yplus:yminus);
334 const TVector3 world_intersection_planar( x, y, z );
337 const auto local_intersection_planar = layergeom->get_local_from_world_coords( tileid,
_tGeometry, world_intersection_planar );
340 const auto segmentation_type = layergeom->get_segmentation_type();
347 for(
auto clusiter = mm_clusrange.first; clusiter != mm_clusrange.second; ++clusiter)
357 const auto& [key, cluster] = *clusiter;
361 const double drphi = local_intersection_planar.x() - cluster->getLocalX();
362 const double dz = local_intersection_planar.y() - cluster->getLocalY();
367 tracklet_tpc->insert_cluster_key(key);
370 std::cout <<
" Match to MM's found for seedID " << seedID <<
" tpcID " << tpcID <<
" siID " << siID << std::endl;
378 const double mm_clus_rphi =
get_r( glob.x(), glob.y() ) * std::atan2( glob.y(), glob.x() );
379 const double mm_clus_z = glob.z();
382 const double rphi_proj =
get_r( world_intersection_planar.x(), world_intersection_planar.y() ) * std::atan2( world_intersection_planar.y(), world_intersection_planar.x() );
383 const double z_proj = world_intersection_planar.z();
391 <<
" Try_mms: " << (int) layer
392 <<
" drphi " << drphi
394 <<
" mm_clus_rphi " << mm_clus_rphi <<
" mm_clus_z " << mm_clus_z
395 <<
" rphi_proj " << rphi_proj <<
" z_proj " << z_proj
405 { tracklet_tpc->identify(); }
425 _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER_TRUTH");
428 _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
433 std:: cerr <<
PHWHERE <<
" ERROR: Can't find node TRKR_CLUSTER" << std::endl;
437 _tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
440 std::cerr <<
PHWHERE <<
"No acts tracking geometry, can't continue."
445 _svtx_seed_map = findNode::getClass<TrackSeedContainer>(topNode,
"SvtxTrackSeedContainer");
448 std::cerr <<
PHWHERE <<
" ERROR: Can't find "<<
"SvtxTrackSeedContainer" << std::endl;
452 _tpc_track_map = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
455 std::cerr <<
PHWHERE <<
" ERROR: Can't find "<<
"TpcTrackSeedContainer" << std::endl;
459 _si_track_map = findNode::getClass<TrackSeedContainer>(topNode,
"SiliconTrackSeedContainer");
462 std::cerr <<
PHWHERE <<
" ERROR: Can't find "<<
"SiliconTrackSeedContainer" << std::endl;
470 std::cout <<
PHWHERE <<
"Could not find CYLINDERGEOM_MICROMEGAS_FULL." << std::endl;
475 m_dcc_static = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerStatic");
478 std::cout <<
PHWHERE <<
" found static TPC distortion correction container" << std::endl;
481 m_dcc_average = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerAverage");
484 std::cout <<
PHWHERE <<
" found average TPC distortion correction container" << std::endl;
487 m_dcc_fluctuation = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerFluctuation");
490 std::cout <<
PHWHERE <<
" found fluctuation TPC distortion correction container" << std::endl;
523 return globalPosition;