Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:54

0001 
0002 #include "CaloRawClusterEval.h"
0003 #include "CaloTruthEval.h"
0004 
0005 #include <calobase/RawCluster.h>
0006 #include <calobase/RawClusterContainer.h>
0007 #include <calobase/RawTowerContainer.h>
0008 #include <calobase/TowerInfo.h>
0009 #include <calobase/TowerInfoContainer.h>
0010 #include <calobase/TowerInfoDefs.h>
0011 
0012 #include <phool/getClass.h>
0013 
0014 #include <cassert>
0015 #include <cfloat>
0016 #include <climits>
0017 #include <cmath>
0018 #include <iostream>
0019 #include <map>
0020 #include <set>
0021 #include <string>
0022 
0023 class RawTower;
0024 
0025 CaloRawClusterEval::CaloRawClusterEval(PHCompositeNode* topNode, const std::string& caloname)
0026   : _caloname(caloname)
0027   , _towereval(topNode, caloname)
0028 {
0029   get_node_pointers(topNode);
0030 }
0031 
0032 CaloRawClusterEval::~CaloRawClusterEval()
0033 {
0034   if (_verbosity > 0)
0035   {
0036     if ((_errors > 0) || (_verbosity > 1))
0037     {
0038       std::cout << "CaloRawClusterEval::~CaloRawClusterEval() - Error Count: " << _errors << std::endl;
0039     }
0040   }
0041 }
0042 
0043 void CaloRawClusterEval::next_event(PHCompositeNode* topNode)
0044 {
0045   _cache_all_truth_primary_showers.clear();
0046   _cache_max_truth_primary_shower_by_energy.clear();
0047   _cache_all_clusters_from_primary_shower.clear();
0048   _cache_best_cluster_from_primary_shower.clear();
0049   _cache_get_energy_contribution_primary_shower.clear();
0050 
0051   _cache_all_truth_primary_particles.clear();
0052   _cache_max_truth_primary_particle_by_energy.clear();
0053   _cache_all_clusters_from_primary_particle.clear();
0054   _cache_best_cluster_from_primary_particle.clear();
0055   _cache_get_energy_contribution_primary_particle.clear();
0056 
0057   _cache_all_truth_hits.clear();
0058 
0059   _towereval.next_event(topNode);
0060 
0061   get_node_pointers(topNode);
0062 }
0063 
0064 bool CaloRawClusterEval::has_reduced_node_pointers()
0065 {
0066   if (!get_rawtower_eval()->has_reduced_node_pointers())
0067   {
0068     return false;
0069   }
0070 
0071   if (_strict)
0072   {
0073     assert(_clusters);
0074   }
0075   else if (!_clusters)
0076   {
0077     return false;
0078   }
0079 
0080   if (_strict)
0081   {
0082     assert(_towers || _towerinfos);
0083   }
0084   else if (!_towers && !_towerinfos)
0085   {
0086     return false;
0087   }
0088 
0089   return true;
0090 }
0091 
0092 std::set<PHG4Shower*> CaloRawClusterEval::all_truth_primary_showers(RawCluster* cluster)
0093 {
0094   if (!has_reduced_node_pointers())
0095   {
0096     ++_errors;
0097     return std::set<PHG4Shower*>();
0098   }
0099 
0100   if (_strict)
0101   {
0102     assert(cluster);
0103   }
0104   else if (!cluster)
0105   {
0106     ++_errors;
0107     return std::set<PHG4Shower*>();
0108   }
0109 
0110   if (_do_cache)
0111   {
0112     std::map<RawCluster*, std::set<PHG4Shower*> >::iterator iter =
0113         _cache_all_truth_primary_showers.find(cluster);
0114     if (iter != _cache_all_truth_primary_showers.end())
0115     {
0116       return iter->second;
0117     }
0118   }
0119 
0120   std::set<PHG4Shower*> truth_primary_showers;
0121 
0122   // loop over all the clustered towers
0123   if (_usetowerinfo)
0124   {
0125     const RawCluster::TowerMap& tower_map = cluster->get_towermap();
0126     for (auto tower_iter : tower_map)
0127     {
0128       RawTowerDefs::keytype tower_key = tower_iter.first;
0129       unsigned int towerinfo_key = get_towerinfo_key(tower_key);
0130       TowerInfo* tower = _towerinfos->get_tower_at_key(towerinfo_key);
0131       if (_strict)
0132       {
0133         assert(tower);
0134       }
0135       else if (!tower)
0136       {
0137         ++_errors;
0138         continue;
0139       }
0140 
0141       std::set<PHG4Shower*> new_primary_showers = _towereval.all_truth_primary_showers(tower);
0142 
0143       for (auto shower : new_primary_showers)
0144       {
0145         if (_strict)
0146         {
0147           assert(shower);
0148         }
0149         else if (!shower)
0150         {
0151           ++_errors;
0152           continue;
0153         }
0154 
0155         truth_primary_showers.insert(shower);
0156       }
0157     }
0158   }
0159   else
0160   {
0161     RawCluster::TowerConstRange begin_end = cluster->get_towers();
0162     for (RawCluster::TowerConstIterator iter = begin_end.first;
0163          iter != begin_end.second;
0164          ++iter)
0165     {
0166       RawTower* tower = _towers->getTower(iter->first);
0167 
0168       if (_strict)
0169       {
0170         assert(tower);
0171       }
0172       else if (!tower)
0173       {
0174         ++_errors;
0175         continue;
0176       }
0177 
0178       std::set<PHG4Shower*> new_primary_showers = _towereval.all_truth_primary_showers(tower);
0179 
0180       for (auto shower : new_primary_showers)
0181       {
0182         if (_strict)
0183         {
0184           assert(shower);
0185         }
0186         else if (!shower)
0187         {
0188           ++_errors;
0189           continue;
0190         }
0191 
0192         truth_primary_showers.insert(shower);
0193       }
0194     }
0195   }
0196   if (_do_cache)
0197   {
0198     _cache_all_truth_primary_showers.insert(std::make_pair(cluster, truth_primary_showers));
0199   }
0200 
0201   return truth_primary_showers;
0202 }
0203 
0204 PHG4Shower* CaloRawClusterEval::max_truth_primary_shower_by_energy(RawCluster* cluster)
0205 {
0206   if (!has_reduced_node_pointers())
0207   {
0208     ++_errors;
0209     return nullptr;
0210   }
0211 
0212   if (_strict)
0213   {
0214     assert(cluster);
0215   }
0216   else if (!cluster)
0217   {
0218     ++_errors;
0219     return nullptr;
0220   }
0221 
0222   if (_do_cache)
0223   {
0224     std::map<RawCluster*, PHG4Shower*>::iterator iter =
0225         _cache_max_truth_primary_shower_by_energy.find(cluster);
0226     if (iter != _cache_max_truth_primary_shower_by_energy.end())
0227     {
0228       return iter->second;
0229     }
0230   }
0231 
0232   // loop over all primaries associated with this cluster and
0233   // get the energy contribution for each one, record the max
0234   PHG4Shower* max_primary = nullptr;
0235   float max_e = FLT_MAX * -1.0;
0236   std::set<PHG4Shower*> primary_showers = all_truth_primary_showers(cluster);
0237   for (auto primary : primary_showers)
0238   {
0239     if (_strict)
0240     {
0241       assert(primary);
0242     }
0243     else if (!primary)
0244     {
0245       ++_errors;
0246       continue;
0247     }
0248 
0249     float e = get_energy_contribution(cluster, primary);
0250     if (std::isnan(e))
0251     {
0252       continue;
0253     }
0254     if (e > max_e)
0255     {
0256       max_e = e;
0257       max_primary = primary;
0258     }
0259   }
0260 
0261   if (_do_cache)
0262   {
0263     _cache_max_truth_primary_shower_by_energy.insert(std::make_pair(cluster, max_primary));
0264   }
0265 
0266   return max_primary;
0267 }
0268 
0269 std::set<RawCluster*> CaloRawClusterEval::all_clusters_from(PHG4Shower* primary)
0270 {
0271   if (!has_reduced_node_pointers())
0272   {
0273     ++_errors;
0274     return std::set<RawCluster*>();
0275   }
0276 
0277   if (_strict)
0278   {
0279     assert(primary);
0280   }
0281   else if (!primary)
0282   {
0283     ++_errors;
0284     return std::set<RawCluster*>();
0285   }
0286 
0287   if (!get_truth_eval()->is_primary(primary))
0288   {
0289     return std::set<RawCluster*>();
0290   }
0291 
0292   primary = get_truth_eval()->get_primary_shower(primary);
0293 
0294   if (_strict)
0295   {
0296     assert(primary);
0297   }
0298   else if (!primary)
0299   {
0300     ++_errors;
0301     return std::set<RawCluster*>();
0302   }
0303 
0304   if (_do_cache)
0305   {
0306     std::map<PHG4Shower*, std::set<RawCluster*> >::iterator iter =
0307         _cache_all_clusters_from_primary_shower.find(primary);
0308     if (iter != _cache_all_clusters_from_primary_shower.end())
0309     {
0310       return iter->second;
0311     }
0312   }
0313 
0314   std::set<RawCluster*> clusters;
0315 
0316   // loop over all the clusters
0317   for (RawClusterContainer::Iterator iter = _clusters->getClusters().first;
0318        iter != _clusters->getClusters().second;
0319        ++iter)
0320   {
0321     RawCluster* cluster = iter->second;
0322 
0323     std::set<PHG4Shower*> primary_showers = all_truth_primary_showers(cluster);
0324     for (auto candidate : primary_showers)
0325     {
0326       if (_strict)
0327       {
0328         assert(candidate);
0329       }
0330       else if (!candidate)
0331       {
0332         ++_errors;
0333         continue;
0334       }
0335 
0336       if (get_truth_eval()->are_same_shower(candidate, primary))
0337       {
0338         clusters.insert(cluster);
0339       }
0340     }
0341   }
0342 
0343   if (_do_cache)
0344   {
0345     _cache_all_clusters_from_primary_shower.insert(std::make_pair(primary, clusters));
0346   }
0347 
0348   return clusters;
0349 }
0350 
0351 RawCluster* CaloRawClusterEval::best_cluster_from(PHG4Shower* primary)
0352 {
0353   if (!has_reduced_node_pointers())
0354   {
0355     ++_errors;
0356     return nullptr;
0357   }
0358 
0359   if (_strict)
0360   {
0361     assert(primary);
0362   }
0363   else if (!primary)
0364   {
0365     ++_errors;
0366     return nullptr;
0367   }
0368 
0369   if (!get_truth_eval()->is_primary(primary))
0370   {
0371     return nullptr;
0372   }
0373 
0374   primary = get_truth_eval()->get_primary_shower(primary);
0375 
0376   if (_strict)
0377   {
0378     assert(primary);
0379   }
0380   else if (!primary)
0381   {
0382     ++_errors;
0383     return nullptr;
0384   }
0385 
0386   if (_do_cache)
0387   {
0388     std::map<PHG4Shower*, RawCluster*>::iterator iter =
0389         _cache_best_cluster_from_primary_shower.find(primary);
0390     if (iter != _cache_best_cluster_from_primary_shower.end())
0391     {
0392       return iter->second;
0393     }
0394   }
0395 
0396   RawCluster* best_cluster = nullptr;
0397   float best_energy = FLT_MAX * -1.0;
0398   std::set<RawCluster*> clusters = all_clusters_from(primary);
0399   for (auto cluster : clusters)
0400   {
0401     if (_strict)
0402     {
0403       assert(cluster);
0404     }
0405     else if (!cluster)
0406     {
0407       ++_errors;
0408       continue;
0409     }
0410 
0411     float energy = get_energy_contribution(cluster, primary);
0412     if (std::isnan(energy))
0413     {
0414       continue;
0415     }
0416     if (energy > best_energy)
0417     {
0418       best_cluster = cluster;
0419       best_energy = energy;
0420     }
0421   }
0422 
0423   if (_do_cache)
0424   {
0425     _cache_best_cluster_from_primary_shower.insert(std::make_pair(primary, best_cluster));
0426   }
0427 
0428   return best_cluster;
0429 }
0430 
0431 float CaloRawClusterEval::get_energy_contribution(RawCluster* cluster, PHG4Shower* primary)
0432 {
0433   if (!has_reduced_node_pointers())
0434   {
0435     ++_errors;
0436     return NAN;
0437   }
0438 
0439   if (_strict)
0440   {
0441     assert(cluster);
0442     assert(primary);
0443   }
0444   else if (!cluster || !primary)
0445   {
0446     ++_errors;
0447     return NAN;
0448   }
0449 
0450   if (!get_truth_eval()->is_primary(primary))
0451   {
0452     return NAN;
0453   }
0454 
0455   // reduce cache misses by using only pointer from PrimaryMap
0456   primary = get_truth_eval()->get_primary_shower(primary);
0457 
0458   if (_strict)
0459   {
0460     assert(primary);
0461   }
0462   else if (!primary)
0463   {
0464     ++_errors;
0465     return NAN;
0466   }
0467 
0468   if (_do_cache)
0469   {
0470     std::map<std::pair<RawCluster*, PHG4Shower*>, float>::iterator iter =
0471         _cache_get_energy_contribution_primary_shower.find(std::make_pair(cluster, primary));
0472     if (iter != _cache_get_energy_contribution_primary_shower.end())
0473     {
0474       return iter->second;
0475     }
0476   }
0477 
0478   float energy = 0.0;
0479 
0480   // loop over all the clustered towers
0481   if (_usetowerinfo)
0482   {
0483     const RawCluster::TowerMap& tower_map = cluster->get_towermap();
0484     for (auto tower_iter : tower_map)
0485     {
0486       RawTowerDefs::keytype tower_key = tower_iter.first;
0487       unsigned int towerinfo_key = get_towerinfo_key(tower_key);
0488       TowerInfo* tower = _towerinfos->get_tower_at_key(towerinfo_key);
0489       if (_strict)
0490       {
0491         assert(tower);
0492       }
0493       else if (!tower)
0494       {
0495         ++_errors;
0496         continue;
0497       }
0498 
0499       float edep = get_rawtower_eval()->get_energy_contribution(tower, primary);
0500       if (!std::isnan(edep))
0501       {
0502         energy += edep;
0503       }
0504     }
0505   }
0506 
0507   else
0508   {
0509     RawCluster::TowerConstRange begin_end = cluster->get_towers();
0510     for (RawCluster::TowerConstIterator iter = begin_end.first;
0511          iter != begin_end.second;
0512          ++iter)
0513     {
0514       RawTower* tower = _towers->getTower(iter->first);
0515 
0516       if (_strict)
0517       {
0518         assert(tower);
0519       }
0520       else if (!tower)
0521       {
0522         ++_errors;
0523         continue;
0524       }
0525 
0526       float edep = get_rawtower_eval()->get_energy_contribution(tower, primary);
0527       if (!std::isnan(edep))
0528       {
0529         energy += edep;
0530       }
0531     }
0532   }
0533 
0534   if (_do_cache)
0535   {
0536     _cache_get_energy_contribution_primary_shower.insert(std::make_pair(std::make_pair(cluster, primary), energy));
0537   }
0538 
0539   return energy;
0540 }
0541 
0542 std::set<PHG4Particle*> CaloRawClusterEval::all_truth_primary_particles(RawCluster* cluster)
0543 {
0544   if (!has_reduced_node_pointers())
0545   {
0546     ++_errors;
0547     return std::set<PHG4Particle*>();
0548   }
0549 
0550   if (_strict)
0551   {
0552     assert(cluster);
0553   }
0554   else if (!cluster)
0555   {
0556     ++_errors;
0557     return std::set<PHG4Particle*>();
0558   }
0559 
0560   if (_do_cache)
0561   {
0562     std::map<RawCluster*, std::set<PHG4Particle*> >::iterator iter =
0563         _cache_all_truth_primary_particles.find(cluster);
0564     if (iter != _cache_all_truth_primary_particles.end())
0565     {
0566       return iter->second;
0567     }
0568   }
0569 
0570   std::set<PHG4Particle*> truth_primary_particles;
0571 
0572   std::set<PHG4Shower*> primary_showers = all_truth_primary_showers(cluster);
0573 
0574   for (auto shower : primary_showers)
0575   {
0576     if (_strict)
0577     {
0578       assert(shower);
0579     }
0580     else if (!shower)
0581     {
0582       ++_errors;
0583       continue;
0584     }
0585 
0586     PHG4Particle* particle = get_truth_eval()->get_primary_particle(shower);
0587 
0588     if (_strict)
0589     {
0590       assert(particle);
0591     }
0592     else if (!particle)
0593     {
0594       ++_errors;
0595       continue;
0596     }
0597 
0598     truth_primary_particles.insert(particle);
0599   }
0600 
0601   if (_do_cache)
0602   {
0603     _cache_all_truth_primary_particles.insert(std::make_pair(cluster, truth_primary_particles));
0604   }
0605 
0606   return truth_primary_particles;
0607 }
0608 
0609 PHG4Particle* CaloRawClusterEval::max_truth_primary_particle_by_energy(RawCluster* cluster)
0610 {
0611   if (!has_reduced_node_pointers())
0612   {
0613     ++_errors;
0614     return nullptr;
0615   }
0616 
0617   if (_strict)
0618   {
0619     assert(cluster);
0620   }
0621   else if (!cluster)
0622   {
0623     ++_errors;
0624     return nullptr;
0625   }
0626 
0627   if (_do_cache)
0628   {
0629     std::map<RawCluster*, PHG4Particle*>::iterator iter =
0630         _cache_max_truth_primary_particle_by_energy.find(cluster);
0631     if (iter != _cache_max_truth_primary_particle_by_energy.end())
0632     {
0633       return iter->second;
0634     }
0635   }
0636 
0637   PHG4Particle* max_primary = nullptr;
0638   PHG4Shower* max_shower = max_truth_primary_shower_by_energy(cluster);
0639 
0640   if (max_shower)
0641   {
0642     max_primary = get_truth_eval()->get_primary_particle(max_shower);
0643   }
0644 
0645   if (_do_cache)
0646   {
0647     _cache_max_truth_primary_particle_by_energy.insert(std::make_pair(cluster, max_primary));
0648   }
0649 
0650   return max_primary;
0651 }
0652 
0653 std::set<RawCluster*> CaloRawClusterEval::all_clusters_from(PHG4Particle* primary)
0654 {
0655   if (!has_reduced_node_pointers())
0656   {
0657     ++_errors;
0658     return std::set<RawCluster*>();
0659   }
0660 
0661   if (_strict)
0662   {
0663     assert(primary);
0664   }
0665   else if (!primary)
0666   {
0667     ++_errors;
0668     return std::set<RawCluster*>();
0669   }
0670 
0671   if (!get_truth_eval()->is_primary(primary))
0672   {
0673     return std::set<RawCluster*>();
0674   }
0675 
0676   primary = get_truth_eval()->get_primary_particle(primary);
0677 
0678   if (_strict)
0679   {
0680     assert(primary);
0681   }
0682   else if (!primary)
0683   {
0684     ++_errors;
0685     return std::set<RawCluster*>();
0686   }
0687 
0688   if (_do_cache)
0689   {
0690     std::map<PHG4Particle*, std::set<RawCluster*> >::iterator iter =
0691         _cache_all_clusters_from_primary_particle.find(primary);
0692     if (iter != _cache_all_clusters_from_primary_particle.end())
0693     {
0694       return iter->second;
0695     }
0696   }
0697 
0698   std::set<RawCluster*> clusters;
0699 
0700   PHG4Shower* shower = get_truth_eval()->get_primary_shower(primary);
0701 
0702   if (shower)
0703   {
0704     clusters = all_clusters_from(shower);
0705   }
0706 
0707   if (_do_cache)
0708   {
0709     _cache_all_clusters_from_primary_particle.insert(std::make_pair(primary, clusters));
0710   }
0711 
0712   return clusters;
0713 }
0714 
0715 RawCluster* CaloRawClusterEval::best_cluster_from(PHG4Particle* primary)
0716 {
0717   if (!has_reduced_node_pointers())
0718   {
0719     ++_errors;
0720     return nullptr;
0721   }
0722 
0723   if (_strict)
0724   {
0725     assert(primary);
0726   }
0727   else if (!primary)
0728   {
0729     ++_errors;
0730     return nullptr;
0731   }
0732 
0733   if (!get_truth_eval()->is_primary(primary))
0734   {
0735     return nullptr;
0736   }
0737 
0738   primary = get_truth_eval()->get_primary_particle(primary);
0739 
0740   if (_strict)
0741   {
0742     assert(primary);
0743   }
0744   else if (!primary)
0745   {
0746     ++_errors;
0747     return nullptr;
0748   }
0749 
0750   if (_do_cache)
0751   {
0752     std::map<PHG4Particle*, RawCluster*>::iterator iter =
0753         _cache_best_cluster_from_primary_particle.find(primary);
0754     if (iter != _cache_best_cluster_from_primary_particle.end())
0755     {
0756       return iter->second;
0757     }
0758   }
0759 
0760   RawCluster* best_cluster = nullptr;
0761 
0762   PHG4Shower* shower = get_truth_eval()->get_primary_shower(primary);
0763   if (shower)
0764   {
0765     best_cluster = best_cluster_from(shower);
0766   }
0767 
0768   if (_do_cache)
0769   {
0770     _cache_best_cluster_from_primary_particle.insert(std::make_pair(primary, best_cluster));
0771   }
0772 
0773   return best_cluster;
0774 }
0775 
0776 float CaloRawClusterEval::get_energy_contribution(RawCluster* cluster, PHG4Particle* primary)
0777 {
0778   if (!has_reduced_node_pointers())
0779   {
0780     ++_errors;
0781     return NAN;
0782   }
0783 
0784   if (_strict)
0785   {
0786     assert(cluster);
0787     assert(primary);
0788   }
0789   else if (!cluster || !primary)
0790   {
0791     ++_errors;
0792     return NAN;
0793   }
0794 
0795   if (!get_truth_eval()->is_primary(primary))
0796   {
0797     return NAN;
0798   }
0799 
0800   // reduce cache misses by using only pointer from PrimaryMap
0801   primary = get_truth_eval()->get_primary_particle(primary);
0802 
0803   if (_strict)
0804   {
0805     assert(primary);
0806   }
0807   else if (!primary)
0808   {
0809     ++_errors;
0810     return 0.;
0811   }
0812 
0813   if (_do_cache)
0814   {
0815     std::map<std::pair<RawCluster*, PHG4Particle*>, float>::iterator iter =
0816         _cache_get_energy_contribution_primary_particle.find(std::make_pair(cluster, primary));
0817     if (iter != _cache_get_energy_contribution_primary_particle.end())
0818     {
0819       return iter->second;
0820     }
0821   }
0822 
0823   float energy = 0.0;
0824   PHG4Shower* shower = get_truth_eval()->get_primary_shower(primary);
0825   if (shower)
0826   {
0827     float edep = get_energy_contribution(cluster, shower);
0828     if (!std::isnan(edep))
0829     {
0830       energy += edep;
0831     }
0832   }
0833 
0834   if (_do_cache)
0835   {
0836     _cache_get_energy_contribution_primary_particle.insert(std::make_pair(std::make_pair(cluster, primary), energy));
0837   }
0838 
0839   return energy;
0840 }
0841 
0842 bool CaloRawClusterEval::has_full_node_pointers()
0843 {
0844   if (!get_rawtower_eval()->has_full_node_pointers())
0845   {
0846     return false;
0847   }
0848 
0849   if (_strict)
0850   {
0851     assert(_clusters);
0852   }
0853   else if (!_clusters)
0854   {
0855     return false;
0856   }
0857 
0858   if (_strict)
0859   {
0860     assert(_towers);
0861   }
0862   else if (!_towers)
0863   {
0864     return false;
0865   }
0866 
0867   return true;
0868 }
0869 
0870 std::set<PHG4Hit*> CaloRawClusterEval::all_truth_hits(RawCluster* cluster)
0871 {
0872   if (!has_full_node_pointers())
0873   {
0874     ++_errors;
0875     return std::set<PHG4Hit*>();
0876   }
0877 
0878   if (_strict)
0879   {
0880     assert(cluster);
0881   }
0882   else if (!cluster)
0883   {
0884     ++_errors;
0885     return std::set<PHG4Hit*>();
0886   }
0887 
0888   if (_do_cache)
0889   {
0890     std::map<RawCluster*, std::set<PHG4Hit*> >::iterator iter =
0891         _cache_all_truth_hits.find(cluster);
0892     if (iter != _cache_all_truth_hits.end())
0893     {
0894       return iter->second;
0895     }
0896   }
0897 
0898   std::set<PHG4Hit*> truth_hits;
0899 
0900   // loop over all the clustered towers
0901   if (_usetowerinfo)
0902   {
0903     const RawCluster::TowerMap& tower_map = cluster->get_towermap();
0904     for (auto tower_iter : tower_map)
0905     {
0906       RawTowerDefs::keytype tower_key = tower_iter.first;
0907       unsigned int towerinfo_key = get_towerinfo_key(tower_key);
0908       TowerInfo* tower = _towerinfos->get_tower_at_key(towerinfo_key);
0909       if (_strict)
0910       {
0911         assert(tower);
0912       }
0913       else if (!tower)
0914       {
0915         ++_errors;
0916         continue;
0917       }
0918 
0919       std::set<PHG4Hit*> new_hits = get_rawtower_eval()->all_truth_hits(tower);
0920 
0921       for (auto g4hit : new_hits)
0922       {
0923         if (_strict)
0924         {
0925           assert(g4hit);
0926         }
0927         else if (!g4hit)
0928         {
0929           ++_errors;
0930           continue;
0931         }
0932 
0933         truth_hits.insert(g4hit);
0934       }
0935     }
0936   }
0937   else
0938   {
0939     RawCluster::TowerConstRange begin_end = cluster->get_towers();
0940     for (RawCluster::TowerConstIterator iter = begin_end.first;
0941          iter != begin_end.second;
0942          ++iter)
0943     {
0944       RawTower* tower = _towers->getTower(iter->first);
0945 
0946       if (_strict)
0947       {
0948         assert(tower);
0949       }
0950       else if (!tower)
0951       {
0952         ++_errors;
0953         continue;
0954       }
0955 
0956       std::set<PHG4Hit*> new_hits = get_rawtower_eval()->all_truth_hits(tower);
0957 
0958       for (auto g4hit : new_hits)
0959       {
0960         if (_strict)
0961         {
0962           assert(g4hit);
0963         }
0964         else if (!g4hit)
0965         {
0966           ++_errors;
0967           continue;
0968         }
0969 
0970         truth_hits.insert(g4hit);
0971       }
0972     }
0973   }
0974   if (_do_cache)
0975   {
0976     _cache_all_truth_hits.insert(std::make_pair(cluster, truth_hits));
0977   }
0978 
0979   return truth_hits;
0980 }
0981 
0982 void CaloRawClusterEval::get_node_pointers(PHCompositeNode* topNode)
0983 {
0984   // need things off of the DST...
0985   std::string nodename = "CLUSTERINFO_" + _caloname;
0986   if (!_usetowerinfo)
0987   {
0988     nodename = "CLUSTER_" + _caloname;
0989   }
0990   _clusters = findNode::getClass<RawClusterContainer>(topNode, nodename.c_str());
0991 
0992   std::string towername = "TOWER_CALIB_" + _caloname;
0993   _towers = findNode::getClass<RawTowerContainer>(topNode, towername.c_str());
0994 
0995   std::string towerinfoname = "TOWERINFO_CALIB_" + _caloname;
0996   _towerinfos = findNode::getClass<TowerInfoContainer>(topNode, towerinfoname.c_str());
0997 
0998   return;
0999 }
1000 
1001 unsigned int CaloRawClusterEval::get_towerinfo_key(RawTowerDefs::keytype tower_key)
1002 {
1003   int ix = RawTowerDefs::decode_index2(tower_key);  // iphi
1004   int iy = RawTowerDefs::decode_index1(tower_key);  // ieta
1005   RawTowerDefs::CalorimeterId caloid =
1006       RawTowerDefs::decode_caloid(tower_key);
1007   // the encoding for calo are actually all the same
1008   //  this is for safety and furture compatibility(s.l.)
1009   unsigned int towerinfokey = UINT_MAX;
1010   if (caloid == RawTowerDefs::CalorimeterId::CEMC)
1011   {
1012     towerinfokey = TowerInfoDefs::encode_emcal(iy, ix);
1013   }
1014   else if (caloid == RawTowerDefs::CalorimeterId::HCALIN || caloid == RawTowerDefs::CalorimeterId::HCALOUT)
1015   {
1016     towerinfokey = TowerInfoDefs::encode_hcal(iy, ix);
1017   }
1018   else
1019   {
1020     std::cout << "CaloRawClusterEval::get_towerinfo_key - unknown caloid: " << caloid << std::endl;
1021   }
1022 
1023   return towerinfokey;
1024 }