PHG4Hit* SvtxClusterEval::max_truth_hit_by_energy(SvtxCluster* cluster) { if (!has_node_pointers()) {++_errors; return NULL;} if (_strict) {assert(cluster);} else if (!cluster) {++_errors; return NULL;} if (_do_cache) { std::map<SvtxCluster*,PHG4Hit*>::iterator iter = _cache_max_truth_hit_by_energy.find(cluster); if (iter != _cache_max_truth_hit_by_energy.end()) { return iter->second; } } std::set<PHG4Hit*> hits = all_truth_hits(cluster); PHG4Hit* max_hit = NULL; float max_e = FLT_MAX*-1.0; for (std::set<PHG4Hit*>::iterator iter = hits.begin(); iter != hits.end(); ++iter) { PHG4Hit *hit = *iter; if (hit->get_edep() > max_e) { max_e = hit->get_edep(); max_hit = hit; } } if (_do_cache) _cache_max_truth_hit_by_energy.insert(make_pair(cluster,max_hit)); return max_hit; }
float SvtxClusterEval::get_energy_contribution(SvtxCluster* cluster, PHG4Hit* g4hit) { if (!has_node_pointers()) {++_errors; return NAN;} if (_strict) { assert(cluster); assert(g4hit); } else if (!cluster||!g4hit) { ++_errors; return NAN; } if ((_do_cache) && (_cache_get_energy_contribution_g4hit.find(make_pair(cluster,g4hit)) != _cache_get_energy_contribution_g4hit.end())) { return _cache_get_energy_contribution_g4hit[make_pair(cluster,g4hit)]; } // this is a fairly simple existance check right now, but might be more // complex in the future, so this is here mostly as future-proofing. float energy = 0.0; std::set<PHG4Hit*> g4hits = all_truth_hits(cluster); for (std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit* candidate = *iter; if (candidate->get_hit_id() != g4hit->get_hit_id()) continue; energy += candidate->get_edep(); } if (_do_cache) _cache_get_energy_contribution_g4hit.insert(make_pair(make_pair(cluster,g4hit),energy)); return energy; }
// overlap calculations float SvtxClusterEval::get_energy_contribution(SvtxCluster* cluster, PHG4Particle* particle) { if (!has_node_pointers()) {++_errors; return NAN;} if (_strict) { assert(cluster); assert(particle); } else if (!cluster||!particle) { ++_errors; return NAN; } if (_do_cache) { std::map<std::pair<SvtxCluster*,PHG4Particle*>, float>::iterator iter = _cache_get_energy_contribution_g4particle.find(make_pair(cluster,particle)); if (iter != _cache_get_energy_contribution_g4particle.end()) { return iter->second; } } float energy = 0.0; std::set<PHG4Hit*> hits = all_truth_hits(cluster); for (std::set<PHG4Hit*>::iterator iter = hits.begin(); iter != hits.end(); ++iter) { PHG4Hit* hit = *iter; if (get_truth_eval()->is_g4hit_from_particle(hit,particle)) { energy += hit->get_edep(); } } if (_do_cache) _cache_get_energy_contribution_g4particle.insert(make_pair(make_pair(cluster,particle),energy)); return energy; }