60 explicit range_adaptor(
const T& range)
64 inline const typename T::first_type&
begin() {
return m_range.first; }
65 inline const typename T::second_type&
end() {
return m_range.second; }
94 T get_p(
T px,
T py,
T pz)
103 return std::log((p + pz) / (p - pz)) / 2;
185 trackStruct.
mask = get_mask(track);
186 trackStruct.
nclusters_mvtx = get_clusters<TrkrDefs::mvtxId>(track);
187 trackStruct.
nclusters_intt = get_clusters<TrkrDefs::inttId>(track);
188 trackStruct.
nclusters_tpc = get_clusters<TrkrDefs::tpcId>(track);
194 trackStruct.
x = track->
get_x();
195 trackStruct.
y = track->
get_y();
196 trackStruct.
z = track->
get_z();
197 trackStruct.
r =
get_r(trackStruct.
x, trackStruct.
y);
198 trackStruct.
phi = std::atan2(trackStruct.
y, trackStruct.
x);
203 trackStruct.
pt = get_pt(trackStruct.
px, trackStruct.
py);
204 trackStruct.
p = get_p(trackStruct.
px, trackStruct.
py, trackStruct.
pz);
205 trackStruct.
eta = get_eta(trackStruct.
p, trackStruct.
pz);
215 cluster_struct.
x = cluster->
getX();
216 cluster_struct.
y = cluster->
getY();
217 cluster_struct.
z = cluster->
getZ();
218 cluster_struct.
r =
get_r(cluster_struct.
x, cluster_struct.
y);
219 cluster_struct.
phi = std::atan2(cluster_struct.
y, cluster_struct.
x);
222 std::cout <<
" (x|y|z|r|l) "
223 << cluster_struct.
x <<
" | "
224 << cluster_struct.
y <<
" | "
225 << cluster_struct.
z <<
" | "
226 << cluster_struct.
r <<
" | "
227 << cluster_struct.
layer <<
" | "
229 std::cout <<
" (xl|yl) "
233 return cluster_struct;
241 const auto dr = cluster.
r - trk_r;
243 const auto trk_dxdr = state->
get_px() / trk_drdt;
244 const auto trk_dydr = state->
get_py() / trk_drdt;
245 const auto trk_dzdr = state->
get_pz() / trk_drdt;
248 cluster.
trk_x = state->
get_x() + dr * trk_dxdr;
249 cluster.
trk_y = state->
get_y() + dr * trk_dydr;
250 cluster.
trk_z = state->
get_z() + dr * trk_dzdr;
263 const auto cosphi(std::cos(cluster.
trk_phi));
264 const auto sinphi(std::sin(cluster.
trk_phi));
265 const auto trk_pphi = -state->
get_px() * sinphi + state->
get_py() * cosphi;
266 const auto trk_pr = state->
get_px() * cosphi + state->
get_py() * sinphi;
267 const auto trk_pz = state->
get_pz();
268 cluster.
trk_alpha = std::atan2(trk_pphi, trk_pr);
269 cluster.
trk_beta = std::atan2(trk_pz, trk_pr);
277 if (!cluster_hit_map)
return;
278 const auto range = cluster_hit_map->
getHits(clus_key);
298 for (
const auto& [first, hit_key] : range_adaptor(range))
325 cluster.
z_size = zbins.size();
335 if (!(cluster_hit_map && hitsetcontainer))
return;
342 const auto hitset = hitsetcontainer->
findHitSet(hitset_key);
345 const auto range = cluster_hit_map->
getHits(clus_key);
349 for (
const auto& pair : range_adaptor(range))
351 const auto hit = hitset->getHit(pair.second);
354 const auto energy = hit->getEnergy();
366 const auto rextrap = cluster.
r;
371 cluster.
truth_x = interpolate<&PHG4Hit::get_x>(hits, rextrap);
372 cluster.
truth_y = interpolate<&PHG4Hit::get_y>(hits, rextrap);
373 cluster.
truth_z = interpolate<&PHG4Hit::get_z>(hits, rextrap);
378 cluster.
truth_px = interpolate<&PHG4Hit::get_px>(hits, rextrap);
379 cluster.
truth_py = interpolate<&PHG4Hit::get_py>(hits, rextrap);
380 cluster.
truth_pz = interpolate<&PHG4Hit::get_pz>(hits, rextrap);
382 std::cout <<
"inter2"
389 const auto cosphi(std::cos(cluster.
truth_phi));
390 const auto sinphi(std::sin(cluster.
truth_phi));
391 const auto truth_pphi = -cluster.
truth_px * sinphi + cluster.
truth_py * cosphi;
392 const auto truth_pr = cluster.
truth_px * cosphi + cluster.
truth_py * sinphi;
394 cluster.
truth_alpha = std::atan2(truth_pphi, truth_pr);
399 double truth_alpha = 0;
400 double truth_beta = 0;
402 for (
const auto& hit : hits)
404 const auto px = hit->get_x(1) - hit->get_x(0);
405 const auto py = hit->get_y(1) - hit->get_y(0);
406 const auto pz = hit->get_z(1) - hit->get_z(0);
407 const auto pphi = -px * sinphi + py * cosphi;
408 const auto pr = px * cosphi + py * sinphi;
410 const auto w = hit->get_edep();
414 truth_alpha += w * std::atan2(pphi, pr);
415 truth_beta += w * std::atan2(pz, pr);
417 truth_alpha /= sum_w;
444 int inSabotage,
bool compress)
446 , _filename(filename)
449 , sabotage(inSabotage)
450 , apply_compression(compress)
463 _dst_data =
new TNtuple(
"dst_data",
"dst data",
465 "c3x:c3y:c3z:c3p:t3x:t3y:t3z:"
466 "c2x:c2y:c2r:c2l:t2x:t2y:t2r:t2l:"
469 "pt:eta:phi:charge");
476 std::cout <<
"DSTEmulator::Init - DST Node missing" << std::endl;
486 std::cout <<
"DSTEmulator::Init - EVAL node missing - creating" << std::endl;
488 dstNode->addNode(evalNode);
492 evalNode->addNode(newNode);
529 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
534 <<
"ActsTrackingGeometry not found on node tree. Exiting"
578 m_track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMapTPCOnly");
581 std::cout <<
" DSTEmulator: Using TPC Only Track Map node " << std::endl;
585 std::cout <<
" DSTEmulator: TPC Only Track Map node not found, using default" << std::endl;
586 m_track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
590 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"CORRECTED_TRKR_CLUSTER");
595 std::cout <<
" DSTEmulator: Using CORRECTED_TRKR_CLUSTER node " << std::endl;
599 std::cout <<
" DSTEmulator: CORRECTED_TRKR_CLUSTER node not found, using TRKR_CLUSTER" << std::endl;
600 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
605 std::cout <<
" DSTEmulator: CORRECTED_TRKR_CLUSTER node not found at all, using TRKR_CLUSTER" << std::endl;
606 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
610 m_cluster_hit_map = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
613 m_hit_truth_map = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
616 m_container = findNode::getClass<TrackEvaluationContainerv1>(topNode,
"TrackEvaluationContainer");
619 m_hitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
622 m_g4hits_tpc = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_TPC");
623 m_g4hits_intt = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_INTT");
624 m_g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MVTX");
628 m_g4truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
653 const auto track = trackpair.second;
654 auto track_struct = create_track(track);
658 track_struct.contributors = contributors;
662 track_struct.embed =
get_embed(particle);
666 auto state_iter = track->begin_states();
669 for (
auto key_iter = track->begin_cluster_keys(); key_iter != track->end_cluster_keys(); ++key_iter)
671 const auto& cluster_key = *key_iter;
677 std::cout <<
"DSTEmulator::evaluate_tracks - unable to find cluster for key " << cluster_key << std::endl;
693 float radius =
get_r(globalpos_d[0], globalpos_d[1]);
694 float clu_phi = std::atan2(globalpos_d[0], globalpos_d[1]);
695 std::cout <<
"radius " << radius << std::endl;
697 for (
auto iter = state_iter; iter != track->end_states(); ++iter)
699 const auto dr = std::abs(radius -
get_r(iter->second->get_x(), iter->second->get_y()));
700 if (dr_min < 0 || dr < dr_min)
714 std::cout <<
"NEW (xg|yg) "
715 << globalpos_d[0] <<
" | "
718 std::cout <<
"NEW (xl|yl) "
719 << cluster->getLocalX() <<
" | "
720 << cluster->getLocalY()
728 const auto trk_r =
get_r(state_iter->second->get_x(), state_iter->second->get_y());
729 std::cout <<
" trk_r " << trk_r << std::endl;
730 const auto dr =
get_r(globalpos_d[0], globalpos_d[1]) - trk_r;
731 std::cout <<
" dr " << dr << std::endl;
732 const auto trk_drdt = (state_iter->second->get_x() * state_iter->second->get_px() + state_iter->second->get_y() * state_iter->second->get_py()) / trk_r;
733 std::cout <<
" trk_drdt " << trk_drdt << std::endl;
734 const auto trk_dxdr = state_iter->second->get_px() / trk_drdt;
735 std::cout <<
" trk_dxdr " << trk_dxdr << std::endl;
736 const auto trk_dydr = state_iter->second->get_py() / trk_drdt;
737 std::cout <<
" trk_dydr " << trk_dydr << std::endl;
738 const auto trk_dzdr = state_iter->second->get_pz() / trk_drdt;
739 std::cout <<
" trk_dzdr " << trk_dzdr << std::endl;
743 float trk_x = state_iter->second->get_x() + dr * trk_dxdr;
744 float trk_y = state_iter->second->get_y() + dr * trk_dydr;
745 float trk_z = state_iter->second->get_z() + dr * trk_dzdr;
746 std::cout <<
"trk_x " << state_iter->second->get_x() <<
"trk_y" << state_iter->second->get_y() <<
"trk_z " << state_iter->second->get_z() << std::endl;
783 <<
"Error: hitsetkey not found in clusterSurfaceMap, layer = " << trk_r
785 << hitsetkey << std::endl;
788 std::cout <<
" g0: " << global[0] <<
" g1: " << global[1] <<
" g2:" << global[2] << std::endl;
794 std::vector<Surface> surf_vec = mapIter->second;
796 Acts::Vector3 world(globalpos_d[0], globalpos_d[1], globalpos_d[2]);
797 double world_phi = std::atan2(world[1], world[0]);
798 double world_z = world[2];
800 double fraction = (world_phi + M_PI) / (2.0 * M_PI);
801 double rounded_nsurf =
round((
double) (surf_vec.size() / 2) * fraction - 0.5);
802 unsigned int nsurf = (
unsigned int) rounded_nsurf;
805 nsurf += surf_vec.size() / 2;
814 double TrkRadius = std::sqrt(trk_x * trk_x + trk_y * trk_y);
815 double rTrkPhi = TrkRadius * std::atan2(trk_y, trk_x);
816 double surfRadius = std::sqrt(center(0) * center(0) + center(1) * center(1));
817 double surfPhiCenter = std::atan2(center[1], center[0]);
818 double surfRphiCenter = surfPhiCenter * surfRadius;
819 double surfZCenter = center[2];
825 delta_r = TrkRadius - surfRadius;
826 trklocX = rTrkPhi - surfRphiCenter;
827 trklocY = trk_z - surfZCenter;
839 float delta_x = trklocX - cluster->getLocalX();
840 float delta_y = trklocY - cluster->getLocalY();
848 comp_dx =
rnd.Uniform(-1, 1) * delta_x;
849 comp_dy =
rnd.Uniform(-1, 1) * delta_y;
853 comp_dx =
rnd.Uniform(-10, 10);
854 comp_dy =
rnd.Uniform(-10, 10);
866 (
float) globalpos_d[0],
867 (float) globalpos_d[1],
868 (
float) globalpos_d[2],
873 cluster->getLocalX(),
874 cluster->getLocalY(),
875 get_r((
float) globalpos_d[0], (
float) globalpos_d[1]),
889 (
float) track_struct.charge};
891 std::cout <<
"filled"
896 cluster->setLocalX(trklocX - comp_dx);
897 cluster->setLocalY(trklocY - comp_dy);
920 std::cout <<
"DSTEmulator::evaluate_tracks - tracks: " <<
m_container->
tracks().size() << std::endl;
949 auto map_iter =
m_g4hit_map.lower_bound(cluster_key);
950 if (map_iter !=
m_g4hit_map.end() && cluster_key == map_iter->first)
952 return map_iter->second;
965 for (
auto& truth_iter : g4hit_map)
967 const auto g4hit_key = truth_iter.second.second;
1010 std::cout <<
"DSTEmulator::find_g4hits - g4hit not found " << g4hit_key << std::endl;
1028 using IdMap = std::map<int, int>;
1029 IdMap contributor_map;
1034 const auto& cluster_key = *key_iter;
1037 const int trkid = hit->get_trkid();
1038 auto iter = contributor_map.lower_bound(trkid);
1039 if (iter == contributor_map.end() || iter->first != trkid)
1041 contributor_map.insert(iter, std::make_pair(trkid, 1));
1050 if (contributor_map.empty())
1056 return *std::max_element(
1057 contributor_map.cbegin(), contributor_map.cend(),
1059 {
return first.second < second.second; });