61 explicit range_adaptor(
const T& range)
65 inline const typename T::first_type&
begin() {
return m_range.first; }
66 inline const typename T::second_type&
end() {
return m_range.second; }
95 T get_p(
T px,
T py,
T pz)
104 return std::log((p + pz) / (p - pz)) / 2;
108 struct interpolation_data_t
110 using list = std::vector<interpolation_data_t>;
111 double x()
const {
return position.x(); }
112 double y()
const {
return position.y(); }
113 double z()
const {
return position.z(); }
115 double px()
const {
return momentum.x(); }
116 double py()
const {
return momentum.y(); }
117 double pz()
const {
return momentum.z(); }
125 template <
double (
interpolation_data_t::*accessor)() const>
126 double average(
const interpolation_data_t::list& hits)
134 for (
const auto& hit : hits)
136 const double x = (hit.*accessor)();
142 const double w = hit.weight;
163 std::vector<TrkrDefs::cluskey>
out;
168 std::copy(
seed->begin_cluster_keys(),
seed->end_cluster_keys(), std::back_inserter(out));
185 return std::accumulate(cluster_keys.begin(), cluster_keys.end(), int64_t(0),
197 return std::count_if(cluster_keys.begin(), cluster_keys.end(),
209 trackStruct.
mask = get_mask(track);
210 trackStruct.
nclusters_mvtx = get_clusters<TrkrDefs::mvtxId>(track);
211 trackStruct.
nclusters_intt = get_clusters<TrkrDefs::inttId>(track);
212 trackStruct.
nclusters_tpc = get_clusters<TrkrDefs::tpcId>(track);
218 trackStruct.
x = track->
get_x();
219 trackStruct.
y = track->
get_y();
220 trackStruct.
z = track->
get_z();
221 trackStruct.
r =
get_r(trackStruct.
x, trackStruct.
y);
222 trackStruct.
phi = std::atan2(trackStruct.
y, trackStruct.
x);
227 trackStruct.
pt = get_pt(trackStruct.
px, trackStruct.
py);
228 trackStruct.
p = get_p(trackStruct.
px, trackStruct.
py, trackStruct.
pz);
229 trackStruct.
eta = get_eta(trackStruct.
p, trackStruct.
pz);
252 if (!(cluster_hit_map && hitsetcontainer))
265 const auto hitset = hitsetcontainer->
findHitSet(hitset_key);
271 const auto range = cluster_hit_map->
getHits(clus_key);
275 for (
const auto& pair : range_adaptor(range))
277 const auto hit = hitset->getHit(pair.second);
280 const auto energy = hit->getEnergy();
310 double line_circle_intersection(
const TVector3& p0,
const TVector3& p1,
double radius)
312 const double A =
square(p1.x() - p0.x()) +
square(p1.y() - p0.y());
313 const double B = 2 * p0.x() * (p1.x() - p0.x()) + 2 * p0.y() * (p1.y() - p0.y());
322 const double tup = (-B + std::sqrt(delta)) / (2 * A);
323 if (tup >= 0 && tup < 1)
329 const double tdn = (-B - sqrt(delta)) / (2 * A);
330 if (tdn >= 0 && tdn < 1)
342 out <<
"ClusterStruct" << std::endl;
343 out <<
" cluster: (" << cluster.
x <<
"," << cluster.
y <<
"," << cluster.
z <<
")" << std::endl;
344 out <<
" track: (" << cluster.
trk_x <<
"," << cluster.
trk_y <<
"," << cluster.
trk_z <<
")" << std::endl;
345 out <<
" truth: (" << cluster.
truth_x <<
"," << cluster.
truth_y <<
"," << cluster.
truth_z <<
")" << std::endl;
349 [[maybe_unused]]
inline std::ostream&
operator<<(std::ostream& out,
const TVector3&
position)
351 out <<
"(" << position.x() <<
", " << position.y() <<
", " << position.z() <<
")";
371 std::cout <<
"TrackEvaluation::Init - DST Node missing" << std::endl;
381 std::cout <<
"TrackEvaluation::Init - EVAL node missing - creating" << std::endl;
383 dstNode->addNode(evalNode);
387 evalNode->addNode(newNode);
409 std::cout <<
"start..." << std::endl;
414 std::cout <<
"event..." << std::endl;
419 std::cout <<
"clusters..." << std::endl;
424 std::cout <<
"tracks..." << std::endl;
429 std::cout <<
"end..." << std::endl;
445 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
449 m_track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
452 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"CORRECTED_TRKR_CLUSTER");
455 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
459 m_cluster_hit_map = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
462 m_hit_truth_map = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
465 m_container = findNode::getClass<TrackEvaluationContainerv1>(topNode,
"TrackEvaluationContainer");
468 m_hitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
471 m_g4hits_tpc = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_TPC");
472 m_g4hits_intt = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_INTT");
473 m_g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MVTX");
477 m_g4truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
480 m_tpc_geom_container = findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
481 assert(m_tpc_geom_container);
514 event.nclusters_mvtx += nclusters;
517 event.nclusters_intt += nclusters;
520 event.nclusters_tpc += nclusters;
523 event.nclusters_micromegas += nclusters;
527 event.nclusters[
layer] += nclusters;
553 add_cluster_size(cluster_struct, cluster);
587 auto track_struct = create_track(track);
591 track_struct.contributors = contributors;
595 track_struct.embed =
get_embed(particle);
599 auto state_iter = track->begin_states();
606 std::cout <<
"TrackEvaluation::evaluate_tracks - unable to find cluster for key " << cluster_key << std::endl;
610 auto cluster_struct =
create_cluster(cluster_key, cluster, track);
611 add_cluster_size(cluster_struct, cluster);
628 const auto radius(cluster_struct.r);
630 for (
auto iter = state_iter; iter != track->end_states(); ++iter)
632 const auto dr = std::abs(radius -
get_r(iter->second->get_x(), iter->second->get_y()));
633 if (dr_min < 0 || dr < dr_min)
656 track_struct.clusters.push_back(cluster_struct);
672 auto map_iter =
m_g4hit_map.lower_bound(cluster_key);
673 if (map_iter !=
m_g4hit_map.end() && cluster_key == map_iter->first)
675 return map_iter->second;
688 for (
auto& truth_iter : g4hit_map)
690 const auto g4hit_key = truth_iter.second.second;
733 std::cout <<
"TrackEvaluation::find_g4hits - g4hit not found " << g4hit_key << std::endl;
751 using IdMap = std::map<int, int>;
752 IdMap contributor_map;
759 const int trkid = hit->get_trkid();
760 auto iter = contributor_map.lower_bound(trkid);
761 if (iter == contributor_map.end() || iter->first != trkid)
763 contributor_map.insert(iter, std::make_pair(trkid, 1));
772 if (contributor_map.empty())
778 return *std::max_element(
779 contributor_map.cbegin(), contributor_map.cend(),
781 {
return first.second < second.second; });
796 if (track !=
nullptr)
806 cluster_struct.
x = global.x();
807 cluster_struct.
y = global.y();
808 cluster_struct.
z = global.z();
809 cluster_struct.
r =
get_r(cluster_struct.
x, cluster_struct.
y);
810 cluster_struct.
phi = std::atan2(cluster_struct.
y, cluster_struct.
x);
818 if (track !=
nullptr)
820 float r = cluster_struct.
r;
822 if (cluster_struct.
layer >= 7)
828 cluster_struct.
para_phi_error = sqrt(para_errors_mm.first) / cluster_struct.
r;
829 cluster_struct.
para_z_error = sqrt(para_errors_mm.second);
838 cluster_struct.
phi_error = sqrt(para_errors_mvtx.first) / cluster_struct.
r;
839 cluster_struct.
z_error = sqrt(para_errors_mvtx.second);
847 return cluster_struct;
855 const auto dr = cluster.
r - trk_r;
857 const auto trk_dxdr = state->
get_px() / trk_drdt;
858 const auto trk_dydr = state->
get_py() / trk_drdt;
859 const auto trk_dzdr = state->
get_pz() / trk_drdt;
862 cluster.
trk_x = state->
get_x() + dr * trk_dxdr;
863 cluster.
trk_y = state->
get_y() + dr * trk_dydr;
864 cluster.
trk_z = state->
get_z() + dr * trk_dzdr;
877 const auto cosphi(std::cos(cluster.
trk_phi));
878 const auto sinphi(std::sin(cluster.
trk_phi));
879 const auto trk_pphi = -state->
get_px() * sinphi + state->
get_py() * cosphi;
880 const auto trk_pr = state->
get_px() * cosphi + state->
get_py() * sinphi;
881 const auto trk_pz = state->
get_pz();
882 cluster.
trk_alpha = std::atan2(trk_pphi, trk_pr);
883 cluster.
trk_beta = std::atan2(trk_pz, trk_pr);
897 const TVector3 cluster_world(cluster.
x, cluster.
y, cluster.
z);
898 const auto cluster_local = layergeom->get_local_from_world_coords(tileid,
m_tGeometry, cluster_world);
902 TVector3 track_local = layergeom->get_local_from_world_coords(tileid,
m_tGeometry, track_world);
906 const TVector3 direction_local = layergeom->get_local_from_world_vect(tileid,
m_tGeometry, direction_world);
909 const auto delta_z = cluster_local.z() - track_local.z();
910 track_local += TVector3(
911 delta_z * direction_local.x() / direction_local.z(),
912 delta_z * direction_local.y() / direction_local.z(),
916 track_world = layergeom->get_world_from_local_coords(tileid,
m_tGeometry, track_local);
919 cluster.
trk_x = track_world.x();
920 cluster.
trk_y = track_world.y();
921 cluster.
trk_z = track_world.z();
934 const auto cosphi(std::cos(cluster.
trk_phi));
935 const auto sinphi(std::sin(cluster.
trk_phi));
936 const auto trk_pphi = -state->
get_px() * sinphi + state->
get_py() * cosphi;
937 const auto trk_pr = state->
get_px() * cosphi + state->
get_py() * sinphi;
938 const auto trk_pz = state->
get_pz();
939 cluster.
trk_alpha = std::atan2(trk_pphi, trk_pr);
940 cluster.
trk_beta = std::atan2(trk_pz, trk_pr);
959 interpolation_data_t::list hits;
960 for (
const auto& g4hit : g4hits)
962 interpolation_data_t::list tmp_hits;
963 const auto weight = g4hit->get_edep();
964 for (
int i = 0;
i < 2; ++
i)
966 const TVector3 g4hit_world(g4hit->get_x(
i), g4hit->get_y(
i), g4hit->get_z(
i));
967 const TVector3 momentum_world(g4hit->get_px(
i), g4hit->get_py(
i), g4hit->get_pz(
i));
968 tmp_hits.push_back({.position = g4hit_world, .momentum = momentum_world, .weight = weight});
975 auto r0 =
get_r(tmp_hits[0].
x(), tmp_hits[0].
y());
976 auto r1 =
get_r(tmp_hits[1].
x(), tmp_hits[1].
y());
984 if (r1 <= rin || r0 >= rout)
990 const auto dr_old =
r1 -
r0;
995 const auto t = line_circle_intersection(tmp_hits[0].position, tmp_hits[1].position, rin);
1001 tmp_hits[0].position = tmp_hits[0].position * (1. -
t) + tmp_hits[1].position *
t;
1002 tmp_hits[0].momentum = tmp_hits[0].momentum * (1. -
t) + tmp_hits[1].
momentum *
t;
1008 const auto t = line_circle_intersection(tmp_hits[0].position, tmp_hits[1].position, rout);
1014 tmp_hits[1].position = tmp_hits[0].position * (1. -
t) + tmp_hits[1].position *
t;
1015 tmp_hits[1].momentum = tmp_hits[0].momentum * (1. -
t) + tmp_hits[1].
momentum *
t;
1020 const auto dr_new =
r1 -
r0;
1021 tmp_hits[0].weight *= dr_new / dr_old;
1022 tmp_hits[1].weight *= dr_new / dr_old;
1031 cluster.
truth_x = average<&interpolation_data_t::x>(hits);
1032 cluster.
truth_y = average<&interpolation_data_t::y>(hits);
1033 cluster.
truth_z = average<&interpolation_data_t::z>(hits);
1036 cluster.
truth_px = average<&interpolation_data_t::px>(hits);
1037 cluster.
truth_py = average<&interpolation_data_t::py>(hits);
1038 cluster.
truth_pz = average<&interpolation_data_t::pz>(hits);
1047 const auto cosphi(std::cos(cluster.
truth_phi));
1048 const auto sinphi(std::sin(cluster.
truth_phi));
1049 const auto truth_pphi = -cluster.
truth_px * sinphi + cluster.
truth_py * cosphi;
1050 const auto truth_pr = cluster.
truth_px * cosphi + cluster.
truth_py * sinphi;
1052 cluster.
truth_alpha = std::atan2(truth_pphi, truth_pr);
1067 const TVector3 cluster_world(cluster.
x, cluster.
y, cluster.
z);
1068 const auto cluster_local = layergeom->get_local_from_world_coords(tileid,
m_tGeometry, cluster_world);
1071 interpolation_data_t::list hits;
1072 for (
const auto& g4hit : g4hits)
1074 const auto weight = g4hit->get_edep();
1075 for (
int i = 0;
i < 2; ++
i)
1078 TVector3 g4hit_world(g4hit->get_x(
i), g4hit->get_y(
i), g4hit->get_z(
i));
1079 auto g4hit_local = layergeom->get_local_from_world_coords(tileid,
m_tGeometry, g4hit_world);
1082 TVector3 momentum_world(g4hit->get_px(
i), g4hit->get_py(
i), g4hit->get_pz(
i));
1083 TVector3 momentum_local = layergeom->get_local_from_world_vect(tileid,
m_tGeometry, momentum_world);
1085 hits.push_back({.position = g4hit_local, .momentum = momentum_local, .weight = weight});
1090 const TVector3 interpolation_local(
1091 average<&interpolation_data_t::x>(hits),
1092 average<&interpolation_data_t::y>(hits),
1093 average<&interpolation_data_t::z>(hits));
1096 const TVector3 interpolation_world = layergeom->get_world_from_local_coords(tileid,
m_tGeometry, interpolation_local);
1099 const TVector3 momentum_local(
1100 average<&interpolation_data_t::px>(hits),
1101 average<&interpolation_data_t::py>(hits),
1102 average<&interpolation_data_t::pz>(hits));
1105 const TVector3 momentum_world = layergeom->get_world_from_local_vect(tileid,
m_tGeometry, momentum_local);
1107 cluster.
truth_x = interpolation_world.x();
1108 cluster.
truth_y = interpolation_world.y();
1109 cluster.
truth_z = interpolation_world.z();
1114 cluster.
truth_px = momentum_world.x();
1115 cluster.
truth_py = momentum_world.y();
1116 cluster.
truth_pz = momentum_world.z();
1122 const auto cosphi(std::cos(cluster.
truth_phi));
1123 const auto sinphi(std::sin(cluster.
truth_phi));
1124 const auto truth_pphi = -cluster.
truth_px * sinphi + cluster.
truth_py * cosphi;
1125 const auto truth_pr = cluster.
truth_px * cosphi + cluster.
truth_py * sinphi;
1127 cluster.
truth_alpha = std::atan2(truth_pphi, truth_pr);