@@ -64,22 +64,21 @@ std::set<PHG4Hit*> CaloRawClusterEval::all_truth_hits(RawCluster* cluster) {
6464 }
6565
6666 std ::set < PHG4Hit * > truth_hits ;
67-
67+
6868 // loop over all the clustered towers
6969 RawCluster ::TowerConstRange begin_end = cluster -> get_towers ();
7070 RawCluster ::TowerConstIterator iter ;
7171 for (iter = begin_end .first ; iter != begin_end .second ; ++ iter )
7272 {
7373 RawTower * tower = _towers -> getTower (iter -> first );
7474
75- std ::set < PHG4Hit * > new_hits = _towereval .all_truth_hits (tower );
76- std ::set < PHG4Hit * > union_hits ;
75+ std ::set < PHG4Hit * > new_hits = get_rawtower_eval ()-> all_truth_hits (tower );
7776
78- std ::set_union ( truth_hits .begin (), truth_hits . end (),
79- new_hits .begin (), new_hits . end (),
80- std :: inserter ( union_hits , union_hits . begin ()));
81-
82- std :: swap ( truth_hits , union_hits ); // swap union into truth_particles
77+ for ( std ::set < PHG4Hit * > :: iterator iter = new_hits .begin ();
78+ iter != new_hits .end ();
79+ ++ iter ) {
80+ truth_hits . insert ( * iter );
81+ }
8382 }
8483
8584 if (_do_cache ) _cache_all_truth_hits .insert (make_pair (cluster ,truth_hits ));
@@ -106,13 +105,12 @@ std::set<PHG4Particle*> CaloRawClusterEval::all_truth_primaries(RawCluster* clus
106105 {
107106 RawTower * tower = _towers -> getTower (iter -> first );
108107 std ::set < PHG4Particle * > new_primaries = _towereval .all_truth_primaries (tower );
109- std ::set < PHG4Particle * > union_primaries ;
110108
111- std ::set_union ( truth_primaries .begin (), truth_primaries . end (),
112- new_primaries .begin (), new_primaries . end (),
113- std :: inserter ( union_primaries , union_primaries . begin ()));
114-
115- std :: swap ( truth_primaries , union_primaries ); // swap union into truth_particles
109+ for ( std ::set < PHG4Particle * > :: iterator iter = new_primaries .begin ();
110+ iter != new_primaries .end ();
111+ ++ iter ) {
112+ truth_primaries . insert ( * iter );
113+ }
116114 }
117115
118116 if (_do_cache ) _cache_all_truth_primaries .insert (make_pair (cluster ,truth_primaries ));
@@ -141,6 +139,7 @@ PHG4Particle* CaloRawClusterEval::max_truth_primary_by_energy(RawCluster* cluste
141139
142140 PHG4Particle * primary = * iter ;
143141 float e = get_energy_contribution (cluster ,primary );
142+ if (isnan (e )) continue ;
144143 if (e > max_e ) {
145144 max_e = e ;
146145 max_primary = primary ;
@@ -154,15 +153,18 @@ PHG4Particle* CaloRawClusterEval::max_truth_primary_by_energy(RawCluster* cluste
154153
155154std ::set < RawCluster * > CaloRawClusterEval ::all_clusters_from (PHG4Particle * primary ) {
156155
157- CaloTruthEval * trutheval = _towereval .get_truth_eval ();
158- if (!trutheval -> is_primary (primary )) return std ::set < RawCluster * > ();
159-
160- if ((_do_cache ) &&
161- (_cache_all_clusters_from_primary .find (primary ) != _cache_all_clusters_from_primary .end ())) {
162- return _cache_all_clusters_from_primary [primary ];
156+ if (!get_truth_eval ()-> is_primary (primary )) return std ::set < RawCluster * > ();
157+
158+ primary = get_truth_eval ()-> get_primary_particle (primary );
159+
160+ if (_do_cache ) {
161+ std ::map < PHG4Particle * ,std ::set < RawCluster * > > ::iterator iter =
162+ _cache_all_clusters_from_primary .find (primary );
163+ if (iter != _cache_all_clusters_from_primary .end ()) {
164+ return iter -> second ;
165+ }
163166 }
164167
165-
166168 std ::set < RawCluster * > clusters ;
167169
168170 // loop over all the clusters
@@ -191,8 +193,9 @@ std::set<RawCluster*> CaloRawClusterEval::all_clusters_from(PHG4Particle* primar
191193
192194RawCluster * CaloRawClusterEval ::best_cluster_from (PHG4Particle * primary ) {
193195
194- CaloTruthEval * trutheval = _towereval .get_truth_eval ();
195- if (!trutheval -> is_primary (primary )) return NULL ;
196+ if (!get_truth_eval ()-> is_primary (primary )) return NULL ;
197+
198+ primary = get_truth_eval ()-> get_primary_particle (primary );
196199
197200 if (_do_cache ) {
198201 std ::map < PHG4Particle * ,RawCluster * > ::iterator iter =
@@ -203,13 +206,14 @@ RawCluster* CaloRawClusterEval::best_cluster_from(PHG4Particle* primary) {
203206 }
204207
205208 RawCluster * best_cluster = NULL ;
206- float best_energy = 0 .0 ;
209+ float best_energy = FLT_MAX * -1 .0 ;
207210 std ::set < RawCluster * > clusters = all_clusters_from (primary );
208211 for (std ::set < RawCluster * > ::iterator iter = clusters .begin ();
209212 iter != clusters .end ();
210213 ++ iter ) {
211214 RawCluster * cluster = * iter ;
212215 float energy = get_energy_contribution (cluster ,primary );
216+ if (isnan (energy )) continue ;
213217 if (energy > best_energy ) {
214218 best_cluster = cluster ;
215219 best_energy = energy ;
@@ -224,8 +228,10 @@ RawCluster* CaloRawClusterEval::best_cluster_from(PHG4Particle* primary) {
224228// overlap calculations
225229float CaloRawClusterEval ::get_energy_contribution (RawCluster * cluster , PHG4Particle * primary ) {
226230
227- CaloTruthEval * trutheval = _towereval .get_truth_eval ();
228- if (!trutheval -> is_primary (primary )) return NAN ;
231+ if (!get_truth_eval ()-> is_primary (primary )) return NAN ;
232+
233+ // reduce cache misses by using only pointer from PrimaryMap
234+ primary = get_truth_eval ()-> get_primary_particle (primary );
229235
230236 if (_do_cache ) {
231237 std ::map < std ::pair < RawCluster * ,PHG4Particle * > ,float > ::iterator iter =
@@ -241,7 +247,8 @@ float CaloRawClusterEval::get_energy_contribution(RawCluster* cluster, PHG4Parti
241247 iter != g4hits .end ();
242248 ++ iter ) {
243249 PHG4Hit * g4hit = * iter ;
244- if (g4hit -> get_trkid () == primary -> get_track_id ()) {
250+ PHG4Particle * candidate = get_truth_eval ()-> get_primary_particle (g4hit );
251+ if (candidate -> get_track_id () == primary -> get_track_id ()) {
245252 energy += g4hit -> get_edep ();
246253 }
247254 }
0 commit comments