File indexing completed on 2026-10-15 08:21:04
0001 #include "TopoClusterEval.h"
0002 #include "CaloRawClusterEval.h"
0003
0004 #include <calobase/RawClusterv1.h>
0005 #include <calobase/RawClusterContainer.h>
0006 #include <calobase/RawTowerContainer.h>
0007
0008 #include <g4main/PHG4Particlev2.h>
0009 #include <g4main/PHG4Shower.h>
0010
0011 #include <phool/getClass.h>
0012
0013 #include <tr1/functional>
0014
0015 #include <cassert>
0016 #include <cfloat>
0017 #include <climits>
0018 #include <cmath>
0019 #include <iostream>
0020 #include <map>
0021 #include <set>
0022 #include <string>
0023
0024 TopoClusterEval::TopoClusterEval(PHCompositeNode* topNode, const std::string &type)
0025 : _topocluster_type(type)
0026 , _clustereval_emcal(topNode, "CEMC")
0027 , _clustereval_ihcal(topNode, "HCALIN")
0028 , _clustereval_ohcal(topNode, "HCALOUT")
0029 {
0030 _clustereval_emcal.set_is_topocluster(true);
0031 _clustereval_emcal.set_topocluster_type(_topocluster_type);
0032 _clustereval_ihcal.set_is_topocluster(true);
0033 _clustereval_ihcal.set_topocluster_type(_topocluster_type);
0034 _clustereval_ohcal.set_is_topocluster(true);
0035 _clustereval_ohcal.set_topocluster_type(_topocluster_type);
0036
0037 _topo_ihcal = new RawClusterv1();
0038 _topo_ohcal = new RawClusterv1();
0039 _topo_emcal = new RawClusterv1();
0040 }
0041
0042 TopoClusterEval::~TopoClusterEval()
0043 {
0044 delete _topo_ihcal;
0045 delete _topo_ohcal;
0046 delete _topo_emcal;
0047 }
0048
0049 void TopoClusterEval::next_event(PHCompositeNode* topNode)
0050 {
0051 _clustereval_emcal.next_event(topNode);
0052 _clustereval_ihcal.next_event(topNode);
0053 _clustereval_ohcal.next_event(topNode);
0054
0055 if(_topo_ihcal)
0056 {
0057 delete _topo_ihcal;
0058 _topo_ihcal = new RawClusterv1();
0059 }
0060
0061 if(_topo_ohcal)
0062 {
0063 delete _topo_ohcal;
0064 _topo_ohcal = new RawClusterv1();
0065 }
0066
0067 if(_topo_emcal)
0068 {
0069 delete _topo_emcal;
0070 _topo_emcal = new RawClusterv1();
0071 }
0072 }
0073
0074 void TopoClusterEval::SeparateSubsystems(RawCluster *topo_cluster)
0075 {
0076 if(_topo_ihcal)
0077 {
0078 delete _topo_ihcal;
0079 _topo_ihcal = new RawClusterv1();
0080 }
0081
0082 if(_topo_ohcal)
0083 {
0084 delete _topo_ohcal;
0085 _topo_ohcal = new RawClusterv1();
0086 }
0087
0088 if(_topo_emcal)
0089 {
0090 delete _topo_emcal;
0091 _topo_emcal = new RawClusterv1();
0092 }
0093
0094 RawCluster::TowerConstRange begin_end = topo_cluster->get_towers();
0095 for(RawCluster::TowerConstIterator towerIt = begin_end.first; towerIt != begin_end.second; ++towerIt)
0096 {
0097 if(RawTowerDefs::decode_caloid(towerIt->first) == RawTowerDefs::CalorimeterId::HCALOUT)
0098 {
0099 _topo_ohcal->addTower(towerIt->first, towerIt->second);
0100 }
0101 else if(RawTowerDefs::decode_caloid(towerIt->first) == RawTowerDefs::CalorimeterId::HCALIN)
0102 {
0103 _topo_ihcal->addTower(towerIt->first, towerIt->second);
0104 }
0105 else if(RawTowerDefs::decode_caloid(towerIt->first) == RawTowerDefs::CalorimeterId::CEMC)
0106 {
0107 _topo_emcal->addTower(towerIt->first, towerIt->second);
0108 }
0109 }
0110 }
0111
0112 PHG4Particle* TopoClusterEval::get_truth_particle(RawCluster* topo_cluster)
0113 {
0114 SeparateSubsystems(topo_cluster);
0115
0116 PHG4Particle *g4particle = max_truth_primary_particle_by_energy();
0117
0118 return g4particle;
0119 }
0120
0121 std::set<PHG4Shower*> TopoClusterEval::all_truth_primary_showers()
0122 {
0123 std::set<PHG4Shower*> all_showers;
0124
0125 all_showers.merge(_clustereval_emcal.all_truth_primary_showers(_topo_emcal));
0126 all_showers.merge(_clustereval_ihcal.all_truth_primary_showers(_topo_ihcal));
0127 all_showers.merge(_clustereval_ohcal.all_truth_primary_showers(_topo_ohcal));
0128
0129 return all_showers;
0130 }
0131
0132 PHG4Shower* TopoClusterEval::max_truth_primary_shower_by_energy()
0133 {
0134 PHG4Shower *max_shower = nullptr;
0135
0136 std::set<PHG4Shower*> showers = all_truth_primary_showers();
0137
0138 float max_shower_energy = 0.;
0139
0140 for(std::set<PHG4Shower*>::iterator itr = showers.begin(); itr != showers.end(); itr++)
0141 {
0142 float shower_energy = _clustereval_emcal.get_energy_contribution(_topo_emcal, (*itr));
0143 shower_energy += _clustereval_ihcal.get_energy_contribution(_topo_ihcal, (*itr));
0144 shower_energy += _clustereval_ohcal.get_energy_contribution(_topo_ohcal, (*itr));
0145
0146 if(shower_energy > max_shower_energy)
0147 {
0148 max_shower_energy = shower_energy;
0149 max_shower = (*itr);
0150 }
0151 }
0152
0153 return max_shower;
0154 }
0155
0156 std::set<PHG4Shower*> TopoClusterEval::all_truth_primary_showers_emcal()
0157 {
0158 return _clustereval_emcal.all_truth_primary_showers(_topo_emcal);
0159 }
0160
0161 std::set<PHG4Shower*> TopoClusterEval::all_truth_primary_showers_hcal()
0162 {
0163 std::set<PHG4Shower*> all_showers = all_truth_primary_showers_ihcal();
0164
0165 all_showers.merge(all_truth_primary_showers_ohcal());
0166
0167 return all_showers;
0168 }
0169
0170 std::set<PHG4Shower*> TopoClusterEval::all_truth_primary_showers_ihcal()
0171 {
0172 return _clustereval_ihcal.all_truth_primary_showers(_topo_ihcal);
0173 }
0174
0175 std::set<PHG4Shower*> TopoClusterEval::all_truth_primary_showers_ohcal()
0176 {
0177 return _clustereval_ohcal.all_truth_primary_showers(_topo_ohcal);
0178 }
0179
0180 PHG4Shower* TopoClusterEval::max_truth_primary_shower_by_energy_emcal()
0181 {
0182 return _clustereval_emcal.max_truth_primary_shower_by_energy(_topo_emcal);
0183 }
0184
0185 PHG4Shower* TopoClusterEval::max_truth_primary_shower_by_energy_hcal()
0186 {
0187 PHG4Shower *max_shower = nullptr;
0188
0189 std::set<PHG4Shower*> showers = all_truth_primary_showers_hcal();
0190
0191 float max_shower_energy = 0.;
0192
0193 for(std::set<PHG4Shower*>::iterator itr = showers.begin(); itr != showers.end(); itr++)
0194 {
0195 float shower_energy = _clustereval_ihcal.get_energy_contribution(_topo_ihcal, (*itr));
0196 shower_energy += _clustereval_ohcal.get_energy_contribution(_topo_ohcal, (*itr));
0197
0198 if(shower_energy > max_shower_energy)
0199 {
0200 max_shower_energy = shower_energy;
0201 max_shower = (*itr);
0202 }
0203 }
0204
0205 return max_shower;
0206 }
0207
0208 PHG4Shower* TopoClusterEval::max_truth_primary_shower_by_energy_ihcal()
0209 {
0210 return _clustereval_ihcal.max_truth_primary_shower_by_energy(_topo_ihcal);
0211 }
0212
0213 PHG4Shower* TopoClusterEval::max_truth_primary_shower_by_energy_ohcal()
0214 {
0215 return _clustereval_ihcal.max_truth_primary_shower_by_energy(_topo_ohcal);
0216 }
0217
0218 std::set<PHG4Particle*> TopoClusterEval::all_truth_primary_particles()
0219 {
0220 std::set<PHG4Particle*> all_primaries;
0221
0222 all_primaries.merge(_clustereval_emcal.all_truth_primary_particles(_topo_emcal));
0223 all_primaries.merge(_clustereval_ihcal.all_truth_primary_particles(_topo_ihcal));
0224 all_primaries.merge(_clustereval_ohcal.all_truth_primary_particles(_topo_ohcal));
0225
0226 return all_primaries;
0227 }
0228
0229 std::set<PHG4Particle*> TopoClusterEval::all_truth_primary_particles_emcal()
0230 {
0231 return _clustereval_emcal.all_truth_primary_particles(_topo_emcal);
0232 }
0233
0234 std::set<PHG4Particle*> TopoClusterEval::all_truth_primary_particles_hcal()
0235 {
0236 std::set<PHG4Particle*> all_primaries = all_truth_primary_particles_ihcal();
0237
0238 all_primaries.merge(all_truth_primary_particles_ohcal());
0239
0240 return all_primaries;
0241 }
0242
0243 std::set<PHG4Particle*> TopoClusterEval::all_truth_primary_particles_ihcal()
0244 {
0245 return _clustereval_ihcal.all_truth_primary_particles(_topo_ihcal);
0246 }
0247
0248 std::set<PHG4Particle*> TopoClusterEval::all_truth_primary_particles_ohcal()
0249 {
0250 return _clustereval_ohcal.all_truth_primary_particles(_topo_ohcal);
0251 }
0252
0253 PHG4Particle* TopoClusterEval::max_truth_primary_particle_by_energy()
0254 {
0255 PHG4Particle *max_primary = nullptr;
0256
0257 std::set<PHG4Particle*> primaries = all_truth_primary_particles();
0258
0259 float max_primary_energy = 0.;
0260
0261 for(std::set<PHG4Particle*>::iterator itr = primaries.begin(); itr != primaries.end(); itr++)
0262 {
0263 float primary_energy = _clustereval_emcal.get_energy_contribution(_topo_emcal, (*itr));
0264 primary_energy += _clustereval_ihcal.get_energy_contribution(_topo_ihcal, (*itr));
0265 primary_energy += _clustereval_ohcal.get_energy_contribution(_topo_ohcal, (*itr));
0266
0267 if(primary_energy > max_primary_energy)
0268 {
0269 max_primary_energy = primary_energy;
0270 max_primary = (*itr);
0271 }
0272 }
0273
0274 return max_primary;
0275 }
0276
0277 PHG4Particle* TopoClusterEval::max_truth_primary_particle_by_energy_emcal()
0278 {
0279 return _clustereval_emcal.max_truth_primary_particle_by_energy(_topo_emcal);
0280 }
0281
0282 PHG4Particle* TopoClusterEval::max_truth_primary_particle_by_energy_hcal()
0283 {
0284 PHG4Particle *max_primary = nullptr;
0285
0286 std::set<PHG4Particle*> primaries = all_truth_primary_particles_hcal();
0287
0288 float max_primary_energy = 0.;
0289
0290 for(std::set<PHG4Particle*>::iterator itr = primaries.begin(); itr != primaries.end(); itr++)
0291 {
0292 float primary_energy = _clustereval_ihcal.get_energy_contribution(_topo_ihcal, (*itr));
0293 primary_energy += _clustereval_ohcal.get_energy_contribution(_topo_ohcal, (*itr));
0294
0295 if(primary_energy > max_primary_energy)
0296 {
0297 max_primary_energy = primary_energy;
0298 max_primary = (*itr);
0299 }
0300 }
0301
0302 return max_primary;
0303 }
0304
0305 PHG4Particle* TopoClusterEval::max_truth_primary_particle_by_energy_ihcal()
0306 {
0307 return _clustereval_ihcal.max_truth_primary_particle_by_energy(_topo_ihcal);
0308 }
0309
0310 PHG4Particle* TopoClusterEval::max_truth_primary_particle_by_energy_ohcal()
0311 {
0312 return _clustereval_ohcal.max_truth_primary_particle_by_energy(_topo_ohcal);
0313 }