45 std::cout <<
"SvtxClusterEval::~SvtxClusterEval() - Error Count: " <<
_errors << std::endl;
83 std::map<TrkrDefs::cluskey, std::shared_ptr<TrkrCluster>> truth_clusters;
93 truth_clusters.insert(std::make_pair(ckey, cluster));
117 return std::make_pair(0,
nullptr);
122 std::cout <<
" max truth particle by cluster energy has trackID " << max_particle->
get_track_id() << std::endl;
128 double reco_x = global(0);
129 double reco_y = global(1);
130 double reco_z = global(2);
131 double r = sqrt(reco_x * reco_x + reco_y * reco_y);
133 double reco_rphi = r * atan2(reco_y, reco_x);
136 for (
const auto& [ckey, candidate_truth_cluster] : gclusters)
143 double gx = candidate_truth_cluster->getX();
144 double gy = candidate_truth_cluster->getY();
145 double gz = candidate_truth_cluster->getZ();
146 double gr = sqrt(gx * gx + gy * gy);
147 double grphi = gr * atan2(gy, gx);
151 double dz = reco_z -
gz;
152 double drphi = reco_rphi - grphi;
155 if (cluster_layer > 6 && cluster_layer < 23)
160 return std::make_pair(ckey, candidate_truth_cluster);
163 if (cluster_layer > 22 && cluster_layer < 39)
168 return std::make_pair(ckey, candidate_truth_cluster);
171 if (cluster_layer > 38 && cluster_layer < 55)
176 return std::make_pair(ckey, candidate_truth_cluster);
179 else if (cluster_layer < 3)
184 return std::make_pair(ckey, candidate_truth_cluster);
187 else if (cluster_layer == 55)
191 return std::make_pair(ckey, candidate_truth_cluster);
194 else if (cluster_layer == 56)
198 return std::make_pair(ckey, candidate_truth_cluster);
206 return std::make_pair(ckey, candidate_truth_cluster);
211 return std::make_pair(0,
nullptr);
226 double gx = gclus->getX();
227 double gy = gclus->getY();
228 double gz = gclus->getZ();
229 double gr = sqrt(gx * gx + gy * gy);
230 double grphi = gr * atan2(gy, gx);
235 std::set<TrkrDefs::cluskey> reco_cluskeys;
237 for (
auto cont_g4hit : contributing_hits)
243 std::cout <<
" contributing g4hitID " << cont_g4hit->get_hit_id() <<
" g4trackID " << cont_g4hit->get_trkid() << std::endl;
246 for (
unsigned long iter : cluskeys)
249 if (clus_layer != truth_layer)
254 reco_cluskeys.insert(iter);
258 unsigned int nreco = reco_cluskeys.size();
262 for (
const auto& this_ckey : reco_cluskeys)
267 double this_x = global(0);
268 double this_y = global(1);
269 double this_z = global(2);
270 double this_rphi = gr * atan2(this_y, this_x);
274 double dz = this_z -
gz;
275 double drphi = this_rphi - grphi;
278 if (truth_layer > 6 && truth_layer < 23)
283 return std::make_pair(this_ckey, this_cluster);
286 if (truth_layer > 22 && truth_layer < 39)
291 return std::make_pair(this_ckey, this_cluster);
294 if (truth_layer > 38 && truth_layer < 55)
299 return std::make_pair(this_ckey, this_cluster);
302 else if (truth_layer < 3)
307 return std::make_pair(this_ckey, this_cluster);
310 else if (truth_layer == 55)
314 return std::make_pair(this_ckey, this_cluster);
317 else if (truth_layer == 56)
321 return std::make_pair(this_ckey, this_cluster);
329 return std::make_pair(this_ckey, this_cluster);
335 return std::make_pair(0,
nullptr);
343 return std::set<PHG4Hit*>();
348 std::map<TrkrDefs::cluskey, std::set<PHG4Hit*>>::iterator iter =
356 std::set<PHG4Hit*> truth_hits;
360 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
363 for (std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
364 clushititer = hitrange.first;
365 clushititer != hitrange.second; ++clushititer)
372 std::multimap<TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype>> temp_map;
376 for (
auto& htiter : temp_map)
401 truth_hits.insert(g4hit);
444 TVector3 cvec(glob(0), glob(1), glob(2));
446 std::set<PHG4Hit*> truth_hits;
448 std::multimap<PHG4HitDefs::keytype, TrkrDefs::hitkey> g4keyperhit;
449 std::vector<PHG4HitDefs::keytype> g4hitkeys;
454 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
456 for (std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
457 clushititer = hitrange.first;
458 clushititer != hitrange.second; ++clushititer)
464 std::multimap<TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype>> temp_map;
466 for (
auto& htiter : temp_map)
472 std::cout <<
" g4key: " << g4hitkey <<
" layer: " << layer << std::endl;
480 g4keyperhit.insert(std::pair<PHG4HitDefs::keytype, TrkrDefs::hitkey>(g4hitkey, local_hitkey));
481 std::vector<PHG4HitDefs::keytype>::iterator itg4keys = find(g4hitkeys.begin(), g4hitkeys.end(), g4hitkey);
482 if (itg4keys == g4hitkeys.end())
484 g4hitkeys.push_back(g4hitkey);
491 unsigned int n_max = 0;
493 if (g4hitkeys.size() == 1)
495 std::vector<PHG4HitDefs::keytype>::iterator
it = g4hitkeys.begin();
500 for (
unsigned long long& g4hitkey : g4hitkeys)
502 unsigned int ng4hit = g4keyperhit.count(g4hitkey);
507 if (this_g4hit !=
nullptr)
509 unsigned int glayer = this_g4hit->
get_layer();
552 truth_hits.insert(g4hit);
563 return std::make_pair(0, 0);
587 std::pair<int, int> out_pair;
589 out_pair.second = -1;
593 TVector3 cvec(global(0), global(1), global(2));
596 std::multimap<PHG4HitDefs::keytype, TrkrDefs::hitkey> g4keyperhit;
597 std::vector<PHG4HitDefs::keytype> g4hitkeys;
602 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
604 for (std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
605 clushititer = hitrange.first;
606 clushititer != hitrange.second; ++clushititer)
612 std::multimap<TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype>> temp_map;
615 for (
auto& htiter : temp_map)
621 std::cout <<
" g4key: " << g4hitkey <<
" layer: " << layer << std::endl;
629 g4keyperhit.insert(std::pair<PHG4HitDefs::keytype, TrkrDefs::hitkey>(g4hitkey, local_hitkey));
630 std::vector<PHG4HitDefs::keytype>::iterator itg4keys = find(g4hitkeys.begin(), g4hitkeys.end(), g4hitkey);
631 if (itg4keys == g4hitkeys.end())
633 g4hitkeys.push_back(g4hitkey);
639 unsigned int n_max = 0;
642 std::cout <<
" n matches found: " << g4hitkeys.size() <<
" phi: " << cvec.Phi() <<
" z: " << cvec.Z() <<
" ckey: " << cluster_key << std::endl;
645 if (g4hitkeys.size() == 1)
647 std::vector<PHG4HitDefs::keytype>::iterator
it = g4hitkeys.begin();
652 for (
unsigned long long& g4hitkey : g4hitkeys)
654 unsigned int ng4hit = g4keyperhit.count(g4hitkey);
659 if (this_g4hit !=
nullptr)
661 unsigned int glayer = this_g4hit->
get_layer();
667 std::cout <<
"layer: " << layer <<
" (" << glayer <<
") "
668 <<
" gtrackID: " << this_g4hit->
get_trkid() <<
" novlp: " << ng4hit <<
" phi: " <<
vec.Phi() <<
" z: " << this_g4hit->
get_avg_z() <<
" r: " <<
vec.Perp() <<
" keyg4: " << g4hitkey <<
" cz: " << cluster->
getZ() << std::endl;
681 std::cout <<
"found in layer: " << layer <<
" n_max: " << n_max <<
" max_key: " << max_key <<
" ckey: " << cluster_key << std::endl;
709 float vtx_z = vtx->
get_z();
715 TVector3 gv(gpx, gpy, gpz);
720 double deta = TMath::Abs(gpeta - this_vec.Eta());
736 out_pair.second =
layer;
752 std::map<TrkrDefs::cluskey, PHG4Hit*>::iterator iter =
762 float max_e = FLT_MAX * -1.0;
763 for (
auto hit : hits)
765 if (hit->get_edep() > max_e)
785 return std::set<PHG4Particle*>();
790 std::map<TrkrDefs::cluskey, std::set<PHG4Particle*>>::iterator iter =
798 std::set<PHG4Particle*> truth_particles;
802 for (
auto hit : g4hits)
817 truth_particles.insert(particle);
825 return truth_particles;
838 std::map<TrkrDefs::cluskey, PHG4Particle*>::iterator iter =
851 float max_e = FLT_MAX * -1.0;
856 for (
const auto& [ckey, cluster] : truth_clus)
860 float e = cluster->getError(0, 0);
891 std::map<TrkrDefs::cluskey, PHG4Particle*>::iterator iter =
902 float max_e = FLT_MAX * -1.0;
927 return std::set<TrkrDefs::cluskey>();
934 else if (!truthparticle)
937 return std::set<TrkrDefs::cluskey>();
948 std::map<PHG4Particle*, std::set<TrkrDefs::cluskey>>::iterator iter =
955 std::set<TrkrDefs::cluskey>
clusters;
961 auto Mytimer = std::make_unique<PHTimer>(
"ReCl_timer");
965 std::multimap<PHG4Particle*, TrkrDefs::cluskey> temp_clusters_from_particles;
970 for (
auto iter = range.first; iter != range.second; ++iter)
976 for (
auto candidate : particles)
978 temp_clusters_from_particles.insert(std::make_pair(candidate, cluster_key));
985 iter != range.second; ++iter)
988 std::set<TrkrDefs::cluskey>
clusters;
989 std::multimap<PHG4Particle*, TrkrDefs::cluskey>::const_iterator lower_bound = temp_clusters_from_particles.lower_bound(g4particle);
990 std::multimap<PHG4Particle*, TrkrDefs::cluskey>::const_iterator upper_bound = temp_clusters_from_particles.upper_bound(g4particle);
991 std::multimap<PHG4Particle*, TrkrDefs::cluskey>::const_iterator cfp_iter;
992 for (cfp_iter = lower_bound; cfp_iter != upper_bound; ++cfp_iter)
995 clusters.insert(cluster_key);
1008 return std::set<TrkrDefs::cluskey>();
1018 return std::set<TrkrDefs::cluskey>();
1025 std::multimap<PHG4HitDefs::keytype, TrkrDefs::cluskey> truth_cluster_map;
1026 std::set<PHG4HitDefs::keytype> all_g4hits_set;
1027 std::map<PHG4HitDefs::keytype, PHG4Hit*> all_g4hits_map;
1032 std::cout <<
"all_clusters_from_g4hit: list all reco clusters " << std::endl;
1038 for (
auto iter = range.first; iter != range.second; ++iter)
1045 std::cout <<
" layer " << layer <<
" cluster_key " << cluster_key <<
" adc " << clus->
getAdc()
1049 std::cout <<
" associated hits:";
1050 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
1052 for (std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
1053 clushititer = hitrange.first;
1054 clushititer != hitrange.second; ++clushititer)
1057 std::cout <<
" " <<
hitkey;
1059 std::cout << std::endl;
1064 for (
auto candidate : hits)
1070 int gtrackID = candidate->get_trkid();
1071 std::cout <<
" adding cluster with cluster_key " << cluster_key <<
" g4hit with g4hit_key " << g4hit_key
1072 <<
" gtrackID " << gtrackID
1076 all_g4hits_set.insert(g4hit_key);
1077 all_g4hits_map.insert(std::make_pair(g4hit_key, candidate));
1079 truth_cluster_map.insert(std::make_pair(g4hit_key, cluster_key));
1086 for (
unsigned long long g4hit_key : all_g4hits_set)
1090 std::cout <<
" associations for g4hit_key " << g4hit_key << std::endl;
1093 std::map<PHG4HitDefs::keytype, PHG4Hit*>::iterator
it = all_g4hits_map.find(g4hit_key);
1096 std::set<TrkrDefs::cluskey> assoc_clusters;
1098 std::pair<std::multimap<PHG4HitDefs::keytype, TrkrDefs::cluskey>::iterator,
1099 std::multimap<PHG4HitDefs::keytype, TrkrDefs::cluskey>::iterator>
1100 ret = truth_cluster_map.equal_range(g4hit_key);
1101 for (std::multimap<PHG4HitDefs::keytype, TrkrDefs::cluskey>::iterator jter = ret.first; jter != ret.second; ++jter)
1103 assoc_clusters.insert(jter->second);
1107 std::cout <<
" g4hit_key " << g4hit_key <<
" associated with cluster_key " << jter->second << std::endl;
1116 std::set<TrkrDefs::cluskey>
clusters;
1117 std::map<PHG4Hit*, std::set<TrkrDefs::cluskey>>::iterator iter =
1121 return iter->second;
1158 std::cout <<
"all_clusters: found # " <<
_clustermap->
size() << std::endl;
1164 for (
auto iter = range.first; iter != range.second; ++iter)
1181 if (gid_lay.second >= 0)
1188 std::cout <<
"found doublematch" << std::endl;
1189 std::cout <<
"ckey: " << cluster_key <<
" gtrackID: " << gid_lay.first <<
" layer: " << gid_lay.second << std::endl;
1202 return iter->second;
1205 return best_cluster;
1228 std::map<PHG4Hit*, TrkrDefs::cluskey>::iterator iter =
1232 return iter->second;
1237 float best_energy = 0.0;
1239 for (
unsigned long cluster_key : clusters)
1242 if (energy > best_energy)
1244 best_cluster = cluster_key;
1254 return best_cluster;
1282 std::map<std::pair<TrkrDefs::cluskey, PHG4Particle*>,
float>::iterator iter =
1286 return iter->second;
1292 for (
auto hit : hits)
1296 energy += hit->get_edep();
1339 for (
auto candidate : g4hits)
1341 if (candidate->get_hit_id() != g4hit->
get_hit_id())
1345 energy += candidate->get_edep();
1360 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"CORRECTED_TRKR_CLUSTER");
1363 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
1371 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
1375 _cluster_hit_map = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
1376 _hit_truth_map = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
1377 _truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
1379 _g4hits_tpc = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_TPC");
1380 _g4hits_intt = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_INTT");
1381 _g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MVTX");
1382 _g4hits_mms = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MICROMEGAS");
1383 _tgeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
1394 for (
auto iter = range.first; iter != range.second; ++iter)
1400 float clus_phi = atan2(glob(1), glob(0));
1407 it->second.insert(std::make_pair(clus_phi, cluster_key));
1412 it->second.insert(std::make_pair(clus_phi + 2 * M_PI, cluster_key));
1416 it->second.insert(std::make_pair(clus_phi - 2 * M_PI, cluster_key));
1450 if (fabsf(x) > fabsf(y))
1452 const float z = y /
x;
1471 const float z = x /
y;
1502 const float n1 = 0.97239411F;
1503 const float n2 = -0.19194795F;
1504 return (n1 + n2 * z * z) *
z;