3 #include <calobase/RawCluster.h>
4 #include <calobase/RawClusterContainer.h>
5 #include <calobase/RawClusterv1.h>
6 #include <calobase/RawTowerDefs.h>
7 #include <calobase/RawTowerGeom.h>
8 #include <calobase/RawTowerGeomContainer.h>
9 #include <calobase/TowerInfo.h>
10 #include <calobase/TowerInfoContainer.h>
37 return (a.second > b.second);
41 {2, 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44,
42 48, 52, 55, 59, 63, 66, 70, 74, 78, 82, 86, 90};
45 {5, 9, 13, 17, 21, 25, 29, 32, 36, 40, 43, 47,
46 51, 54, 58, 62, 65, 69, 73, 77, 81, 85, 89, 93};
49 -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2,
50 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,
51 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8,
52 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11,
53 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15,
54 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18,
55 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21,
56 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, -1, -1};
60 float deta = eta1 - eta2;
61 float dphi = phi1 - phi2;
70 return sqrt(pow(deta, 2) + pow(dphi, 2));
79 std::vector<int> adjacent_towers;
82 if (this_layer == 0 || this_layer == 1)
84 for (
int delta_layer = 0; delta_layer <= 1; delta_layer++)
86 for (
int delta_eta = -1; delta_eta <= 1; delta_eta++)
90 if (delta_layer == 0 && delta_eta == 0 &&
delta_phi == 0)
95 int test_eta = this_eta + delta_eta;
101 int test_layer = (this_layer + delta_layer) % 2;
109 std::cout <<
"RawClusterBuilderTopo::get_adjacent_towers_by_ID : corner growth not allowed " << std::endl;
115 adjacent_towers.push_back(
get_ID(test_layer, test_eta, test_phi));
128 for (
int new_eta = EMCal_eta_start; new_eta <= EMCal_eta_end; new_eta++)
134 int EMCal_tower =
get_ID(2, new_eta, new_phi);
137 std::cout <<
"RawClusterBuilderTopo::get_adjacent_towers_by_ID : HCal tower with eta / phi = " << this_eta <<
" / " << this_phi <<
", adding EMCal tower with eta / phi = " << new_eta <<
" / " << new_phi << std::endl;
139 adjacent_towers.push_back(EMCal_tower);
148 for (
int delta_eta = -1; delta_eta <= 1; delta_eta++)
157 int test_eta = this_eta + delta_eta;
166 adjacent_towers.push_back(
get_ID(this_layer, test_eta, test_phi));
178 int IHCal_tower =
get_ID(0, HCal_eta, HCal_phi);
181 std::cout <<
"RawClusterBuilderTopo::get_adjacent_towers_by_ID : EMCal tower with eta / phi = " << this_eta <<
" / " << this_phi <<
", adding IHCal tower with eta / phi = " << HCal_eta <<
" / " << HCal_phi << std::endl;
183 adjacent_towers.push_back(IHCal_tower);
189 std::cout <<
"RawClusterBuilderTopo::get_adjacent_towers_by_ID : EMCal tower with eta / phi = " << this_eta <<
" / " << this_phi <<
", does not have matching IHCal due to large eta " << std::endl;
195 return adjacent_towers;
202 std::cout <<
"RawClusterBuilderTopo::export_single_cluster called " << std::endl;
205 std::map<int, std::pair<int, int> > tower_ownership;
206 for (
const int &original_tower : original_towers)
208 tower_ownership[original_tower] = std::pair<int, int>(0, -1);
210 export_clusters(original_towers, tower_ownership, 1, std::vector<float>(), std::vector<float>(), std::vector<float>());
215 void RawClusterBuilderTopo::export_clusters(
const std::vector<int> &original_towers, std::map<
int, std::pair<int, int> > tower_ownership,
unsigned int n_clusters, std::vector<float> pseudocluster_sumE, std::vector<float> pseudocluster_eta, std::vector<float> pseudocluster_phi)
221 std::cout <<
"RawClusterBuilderTopo::export_clusters called on an initial cluster with " << n_clusters <<
" final clusters " << std::endl;
226 std::vector<float> clusters_E;
227 std::vector<float> clusters_x;
228 std::vector<float> clusters_y;
229 std::vector<float> clusters_z;
231 for (
unsigned int pc = 0; pc < n_clusters; pc++)
234 clusters_E.push_back(0);
235 clusters_x.push_back(0);
236 clusters_y.push_back(0);
237 clusters_z.push_back(0);
240 for (
int original_tower : original_towers)
242 int this_ID = original_tower;
243 std::pair<int, int> the_pair = tower_ownership[this_ID];
247 std::cout <<
"RawClusterBuilderTopo::export_clusters -> assigning tower " << original_tower <<
" with ownership ( " << the_pair.first <<
", " << the_pair.second <<
" ) " << std::endl;
266 if (the_pair.second == -1)
269 clusters[the_pair.first]->addTower(this_key, this_E);
270 clusters_E[the_pair.first] = clusters_E[the_pair.first] + this_E;
271 clusters_x[the_pair.first] = clusters_x[the_pair.first] + this_E * tower_geom->
get_center_x();
272 clusters_y[the_pair.first] = clusters_y[the_pair.first] + this_E * tower_geom->
get_center_y();
273 clusters_z[the_pair.first] = clusters_z[the_pair.first] + this_E * tower_geom->
get_center_z();
277 std::cout <<
" -> tower ID " << this_ID <<
" fully assigned to pseudocluster " << the_pair.first << std::endl;
285 float r = std::exp(dR1 - dR2);
286 float frac1 = pseudocluster_sumE[the_pair.first] / (pseudocluster_sumE[the_pair.first] + r * pseudocluster_sumE[the_pair.second]);
290 std::cout <<
" tower ID " << this_ID <<
" has dR1 = " << dR1 <<
" to pseudocluster " << the_pair.first <<
" , and dR2 = " << dR2 <<
" to pseudocluster " << the_pair.second <<
", so frac1 = " << frac1 << std::endl;
292 clusters[the_pair.first]->addTower(this_key, this_E * frac1);
293 clusters_E[the_pair.first] = clusters_E[the_pair.first] + this_E * frac1;
294 clusters_x[the_pair.first] = clusters_x[the_pair.first] + this_E * tower_geom->
get_center_x() * frac1;
295 clusters_y[the_pair.first] = clusters_y[the_pair.first] + this_E * tower_geom->
get_center_y() * frac1;
296 clusters_z[the_pair.first] = clusters_z[the_pair.first] + this_E * tower_geom->
get_center_z() * frac1;
298 clusters[the_pair.second]->addTower(this_key, this_E * (1 - frac1));
299 clusters_E[the_pair.second] = clusters_E[the_pair.second] + this_E * (1 - frac1);
300 clusters_x[the_pair.second] = clusters_x[the_pair.second] + this_E * tower_geom->
get_center_x() * (1 - frac1);
301 clusters_y[the_pair.second] = clusters_y[the_pair.second] + this_E * tower_geom->
get_center_y() * (1 - frac1);
302 clusters_z[the_pair.second] = clusters_z[the_pair.second] + this_E * tower_geom->
get_center_z() * (1 - frac1);
308 for (
unsigned int cl = 0; cl < n_clusters; cl++)
310 clusters[cl]->set_energy(clusters_E[cl]);
312 float mean_x = clusters_x[cl] / clusters_E[cl];
313 float mean_y = clusters_y[cl] / clusters_E[cl];
314 float mean_z = clusters_z[cl] / clusters_E[cl];
316 clusters[cl]->set_r(std::sqrt(mean_y * mean_y + mean_x * mean_x));
317 clusters[cl]->set_phi(std::atan2(mean_y, mean_x));
318 clusters[cl]->set_z(mean_z);
324 std::cout <<
"RawClusterBuilderTopo::export_clusters: added cluster with E = " << clusters_E[cl] <<
", eta = " << -1 * log(tan(std::atan2(std::sqrt(mean_y * mean_y + mean_x * mean_x), mean_z) / 2.0)) <<
", phi = " << std::atan2(mean_y, mean_x) << std::endl;
370 catch (std::exception &
e)
372 std::cout <<
PHWHERE <<
": " << e.what() << std::endl;
378 std::cout <<
"RawClusterBuilderTopo::InitRun: initialized with EMCal enable = " <<
_enable_EMCal <<
" and I+OHCal enable = " <<
_enable_HCal << std::endl;
379 std::cout <<
"RawClusterBuilderTopo::InitRun: initialized with sigma_noise in EMCal / IHCal / OHCal = " <<
_noise_LAYER[2] <<
" / " <<
_noise_LAYER[0] <<
" / " <<
_noise_LAYER[1] << std::endl;
380 std::cout <<
"RawClusterBuilderTopo::InitRun: initialized with noise multiples for seeding / growth / perimeter ( S / N / P ) = " <<
_sigma_seed <<
" / " <<
_sigma_grow <<
" / " <<
_sigma_peri << std::endl;
381 std::cout <<
"RawClusterBuilderTopo::InitRun: initialized with allow_corner_neighbor = " <<
_allow_corner_neighbor <<
" (in HCal)" << std::endl;
382 std::cout <<
"RawClusterBuilderTopo::InitRun: initialized with do_split = " <<
_do_split <<
" , R_shower = " <<
_R_shower <<
" (angular units) " << std::endl;
391 TowerInfoContainer *towerinfosEM = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_CEMC");
392 TowerInfoContainer *towerinfosIH = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_HCALIN");
393 TowerInfoContainer *towerinfosOH = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_HCALOUT");
397 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERINFO_CALIB_CEMC does not exist, aborting " << std::endl;
402 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERINFO_CALIB_HCALIN does not exist, aborting " << std::endl;
407 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERINFO_CALIB_HCALOUT does not exist, aborting " << std::endl;
411 _geom_containers[0] = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALIN");
412 _geom_containers[1] = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALOUT");
413 _geom_containers[2] = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_CEMC");
415 if (!_geom_containers[0])
417 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERGEOM_HCALIN does not exist, aborting " << std::endl;
420 if (!_geom_containers[1])
422 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERGEOM_HCALOUT does not exist, aborting " << std::endl;
425 if (!_geom_containers[2])
427 std::cout <<
" RawClusterBuilderTopo::process_event : container TOWERGEOM_CEMC does not exist, aborting " << std::endl;
433 std::cout <<
"RawClusterBuilderTopo::process_event: " << towerinfosEM->
size() <<
" TOWERINFO_CALIB_CEMC towers" << std::endl;
434 std::cout <<
"RawClusterBuilderTopo::process_event: " << towerinfosIH->size() <<
" TOWERINFO_CALIB_HCALIN towers" << std::endl;
435 std::cout <<
"RawClusterBuilderTopo::process_event: " << towerinfosOH->size() <<
" TOWERINFO_CALIB_HCALOUT towers" << std::endl;
437 std::cout <<
"RawClusterBuilderTopo::process_event: pointer to TOWERGEOM_CEMC: " << _geom_containers[2] << std::endl;
438 std::cout <<
"RawClusterBuilderTopo::process_event: pointer to TOWERGEOM_HCALIN: " << _geom_containers[0] << std::endl;
439 std::cout <<
"RawClusterBuilderTopo::process_event: pointer to TOWERGEOM_HCALOUT: " << _geom_containers[1] << std::endl;
456 _HCAL_NETA = _geom_containers[1]->get_etabins();
457 _HCAL_NPHI = _geom_containers[1]->get_phibins();
474 for (
int ilayer = 0; ilayer < 2; ilayer++)
487 std::vector<std::pair<int, float> > list_of_seeds;
493 for (
unsigned int iEM = 0; iEM < towerinfosEM->
size(); iEM++)
496 unsigned int towerinfo_key = towerinfosEM->
encode_key(iEM);
501 RawTowerGeom *tower_geom = _geom_containers[2]->get_tower_geometry(key);
503 int ieta = _geom_containers[2]->get_etabin(tower_geom->
get_eta());
504 int iphi = _geom_containers[2]->get_phibin(tower_geom->
get_phi());
518 int ID =
get_ID(2, ieta, iphi);
519 list_of_seeds.emplace_back(ID, this_E);
522 std::cout <<
"RawClusterBuilderTopo::process_event: adding EMCal tower at ieta / iphi = " << ieta <<
" / " << iphi <<
" with E = " << this_E << std::endl;
533 for (
unsigned int iIH = 0; iIH < towerinfosIH->size(); iIH++)
535 towerInfo = towerinfosIH->get_tower_at_channel(iIH);
536 unsigned int towerinfo_key = towerinfosIH->encode_key(iIH);
537 int ti_ieta = towerinfosIH->getTowerEtaBin(towerinfo_key);
538 int ti_iphi = towerinfosIH->getTowerPhiBin(towerinfo_key);
541 RawTowerGeom *tower_geom = _geom_containers[0]->get_tower_geometry(key);
543 int ieta = _geom_containers[0]->get_etabin(tower_geom->
get_eta());
544 int iphi = _geom_containers[0]->get_phibin(tower_geom->
get_phi());
558 int ID =
get_ID(0, ieta, iphi);
559 list_of_seeds.emplace_back(ID, this_E);
562 std::cout <<
"RawClusterBuilderTopo::process_event: adding IHCal tower at ieta / iphi = " << ieta <<
" / " << iphi <<
" with E = " << this_E << std::endl;
568 for (
unsigned int iOH = 0; iOH < towerinfosOH->size(); iOH++)
570 towerInfo = towerinfosOH->get_tower_at_channel(iOH);
571 unsigned int towerinfo_key = towerinfosOH->encode_key(iOH);
572 int ti_ieta = towerinfosOH->getTowerEtaBin(towerinfo_key);
573 int ti_iphi = towerinfosOH->getTowerPhiBin(towerinfo_key);
576 RawTowerGeom *tower_geom = _geom_containers[1]->get_tower_geometry(key);
578 int ieta = _geom_containers[1]->get_etabin(tower_geom->
get_eta());
579 int iphi = _geom_containers[1]->get_phibin(tower_geom->
get_phi());
593 int ID =
get_ID(1, ieta, iphi);
594 list_of_seeds.emplace_back(ID, this_E);
597 std::cout <<
"RawClusterBuilderTopo::process_event: adding OHCal tower at ieta / iphi = " << ieta <<
" / " << iphi <<
" with E = " << this_E << std::endl;
606 for (
unsigned int n = 0;
n < list_of_seeds.size();
n++)
608 std::cout <<
"RawClusterBuilderTopo::process_event: unsorted seed element n = " <<
n <<
" , ID / E = " << list_of_seeds.at(
n).first <<
" / " << list_of_seeds.at(
n).second << std::endl;
616 for (
unsigned int n = 0;
n < list_of_seeds.size();
n++)
618 std::cout <<
"RawClusterBuilderTopo::process_event: sorted seed element n = " <<
n <<
" , ID / E = " << list_of_seeds.at(
n).first <<
" / " << list_of_seeds.at(
n).second << std::endl;
624 std::cout <<
"RawClusterBuilderTopo::process_event: initialized with " << list_of_seeds.size() <<
" seeds with E > 4*sigma " << std::endl;
627 int cluster_index = 0;
629 std::vector<std::vector<int> > all_cluster_towers;
631 while (list_of_seeds.size() > 0)
633 int seed_ID = list_of_seeds.at(0).first;
634 list_of_seeds.erase(list_of_seeds.begin());
638 std::cout <<
" RawClusterBuilderTopo::process_event: in seeded loop, current seed has ID = " << seed_ID <<
" , length of remaining seed vector = " << list_of_seeds.size() << std::endl;
643 if (seed_status > -1)
647 std::cout <<
" --> already owned by cluster # " << seed_status << std::endl;
655 std::vector<int> cluster_tower_ID;
656 cluster_tower_ID.push_back(seed_ID);
658 std::vector<int> grow_tower_ID;
659 grow_tower_ID.push_back(seed_ID);
665 std::cout <<
" RawClusterBuilderTopo::process_event: Entering Growth stage for cluster " << cluster_index << std::endl;
668 while (grow_tower_ID.size() > 0)
670 int grow_ID = grow_tower_ID.at(0);
671 grow_tower_ID.erase(grow_tower_ID.begin());
675 std::cout <<
" --> cluster " << cluster_index <<
", growth stage, examining neighbors of ID " << grow_ID <<
", " << grow_tower_ID.size() <<
" grow towers left" << std::endl;
680 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
684 std::cout <<
" --> --> --> checking possible adjacent tower with ID " << this_adjacent_tower_ID <<
" : ";
693 std::cout <<
"does not exist " << std::endl;
703 std::cout <<
"already owned by this cluster index " << cluster_index << std::endl;
713 std::cout <<
"E = " <<
get_E_from_ID(this_adjacent_tower_ID) <<
" under 2*sigma threshold " << std::endl;
723 std::cout <<
"ERROR! in growth stage, encountered >2sigma tower which is already owned?!" << std::endl;
729 grow_tower_ID.push_back(this_adjacent_tower_ID);
730 cluster_tower_ID.push_back(this_adjacent_tower_ID);
734 std::cout <<
"add this tower ( ID " << this_adjacent_tower_ID <<
" ) to grow list " << std::endl;
740 std::cout <<
" --> after examining neighbors, grow list is now " << grow_tower_ID.size() <<
", # of towers in cluster = " << cluster_tower_ID.size() << std::endl;
747 std::cout <<
" RawClusterBuilderTopo::process_event: Entering Perimeter stage for cluster " << cluster_index << std::endl;
750 int n_core_towers = cluster_tower_ID.size();
752 for (
int ic = 0; ic < n_core_towers; ic++)
754 int core_ID = cluster_tower_ID.at(ic);
758 std::cout <<
" --> cluster " << cluster_index <<
", perimeter stage, examining neighbors of ID " << core_ID <<
", core cluster # " << ic <<
" of " << n_core_towers <<
" total " << std::endl;
762 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
766 std::cout <<
" --> --> --> checking possible adjacent tower with ID " << this_adjacent_tower_ID <<
" : ";
776 std::cout <<
"does not exist " << std::endl;
786 std::cout <<
"already owned by other cluster index " <<
get_status_from_ID(this_adjacent_tower_ID) << std::endl;
796 std::cout <<
"E = " <<
get_E_from_ID(this_adjacent_tower_ID) <<
" under 0*sigma threshold " << std::endl;
802 cluster_tower_ID.push_back(this_adjacent_tower_ID);
806 std::cout <<
"add this tower ( ID " << this_adjacent_tower_ID <<
" ) to cluster " << std::endl;
812 std::cout <<
" --> after examining perimeter neighbors, # of towers in cluster is now = " << cluster_tower_ID.size() << std::endl;
817 all_cluster_towers.push_back(cluster_tower_ID);
825 std::cout <<
"RawClusterBuilderTopo::process_event: " << cluster_index <<
" topo-clusters initially reconstructed, entering splitting step" << std::endl;
828 int original_cluster_index = cluster_index;
832 for (
int cl = 0; cl < original_cluster_index; cl++)
834 std::vector<int> original_towers = all_cluster_towers.at(cl);
841 std::cout <<
"RawClusterBuilderTopo::process_event: splitting step disabled, cluster " << cluster_index <<
" is final" << std::endl;
847 std::vector<std::pair<int, float> > local_maxima_ID;
850 for (
int tower_ID : original_towers)
854 std::cout <<
" -> examining tower ID " << tower_ID <<
" for possible local maximum " << std::endl;
869 int neighbors_in_cluster = 0;
872 bool has_higher_neighbor =
false;
873 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
880 neighbors_in_cluster++;
886 std::cout <<
" -> -> has higher-energy neighbor ID / E = " << this_adjacent_tower_ID <<
" / " <<
get_E_from_ID(this_adjacent_tower_ID) << std::endl;
888 has_higher_neighbor =
true;
893 if (has_higher_neighbor)
899 if (neighbors_in_cluster < 4)
903 std::cout <<
" -> -> too few neighbors N = " << neighbors_in_cluster << std::endl;
908 local_maxima_ID.emplace_back(tower_ID,
get_E_from_ID(tower_ID));
912 for (
unsigned int n = 0;
n < local_maxima_ID.size();
n++)
915 std::pair<int, float> this_LM = local_maxima_ID.at(
n);
924 this_phi -= 2 * M_PI;
928 bool has_EM_overlap =
false;
931 for (
unsigned int n2 = 0; n2 < local_maxima_ID.size(); n2++)
939 std::pair<int, float> this_LM2 = local_maxima_ID.at(n2);
946 if (this_phi2 > M_PI)
948 this_phi -= 2 * M_PI;
953 float dR =
calculate_dR(this_eta, this_eta2, this_phi, this_phi2);
958 has_EM_overlap =
true;
961 std::cout <<
"RawClusterBuilderTopo::process_event : removing I/OHal local maximum (ID,E,phi,eta = " << this_LM.first <<
", " << this_LM.second <<
", " << this_phi <<
", " << this_eta <<
"), ";
962 std::cout <<
"due to EM overlap (ID,E,phi,eta = " << this_LM2.first <<
", " << this_LM2.second <<
", " << this_phi2 <<
", " << this_eta2 <<
"), dR = " << dR << std::endl;
971 local_maxima_ID.erase(local_maxima_ID.begin() +
n);
980 for (
auto this_LM : local_maxima_ID)
982 int tower_ID = this_LM.first;
983 std::cout <<
"RawClusterBuilderTopo::process_event in cluster " << cl <<
", tower ID " << tower_ID <<
" is LOCAL MAXIMUM with layer / E = " <<
get_ilayer_from_ID(tower_ID) <<
" / " <<
get_E_from_ID(tower_ID) <<
", ";
987 this_phi -= 2 * M_PI;
994 if (local_maxima_ID.size() <= 1)
998 std::cout <<
"RawClusterBuilderTopo::process_event cluster " << cl <<
" has only " << local_maxima_ID.size() <<
" local maxima, not splitting " << std::endl;
1009 std::cout <<
"RawClusterBuilderTopo::process_event splitting cluster " << cl <<
" into " << local_maxima_ID.size() <<
" according to local maxima!" << std::endl;
1015 std::map<int, std::pair<int, int> > tower_ownership;
1016 for (
int &original_tower : original_towers)
1018 tower_ownership[original_tower] = std::pair<int, int>(-1, -1);
1020 std::vector<int> seed_list;
1021 std::vector<int> neighbor_list;
1022 std::vector<int> shared_list;
1028 for (
unsigned int s = 0;
s < local_maxima_ID.size();
s++)
1030 tower_ownership[local_maxima_ID.at(
s).first] = std::pair<int, int>(
s, -1);
1031 neighbor_list.push_back(local_maxima_ID.at(s).first);
1036 for (
int &original_tower : original_towers)
1038 std::pair<int, int> the_pair = tower_ownership[original_tower];
1039 std::cout <<
" Debug Pre-Split: tower_ownership[ " << original_tower <<
" ] = ( " << the_pair.first <<
", " << the_pair.second <<
" ) ";
1041 std::cout << std::endl;
1045 bool first_pass =
true;
1051 std::cout <<
" -> starting split loop with " << seed_list.size() <<
" seed, " << neighbor_list.size() <<
" neighbor, and " << shared_list.size() <<
" shared towers " << std::endl;
1054 std::vector<int> new_ownerships;
1056 for (
unsigned int n = 0;
n < neighbor_list.size();
n++)
1058 int neighbor_ID = neighbor_list.at(
n);
1062 std::cout <<
" -> -> looking at neighbor " <<
n <<
" (tower ID " << neighbor_ID <<
" ) of " << neighbor_list.size() <<
" total" << std::endl;
1068 std::cout <<
" -> -> -> special first pass rules, this tower already owned by pseudocluster " << tower_ownership[neighbor_ID].first << std::endl;
1070 new_ownerships.push_back(tower_ownership[neighbor_ID].first);
1074 std::map<int, bool> pseudocluster_adjacency;
1075 for (
unsigned int s = 0;
s < local_maxima_ID.size();
s++)
1077 pseudocluster_adjacency[
s] =
false;
1082 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
1089 if (tower_ownership[this_adjacent_tower_ID].first > -1)
1093 std::cout <<
" -> -> -> adjacent tower to this one, with ID " << this_adjacent_tower_ID <<
" , is owned by pseudocluster " << tower_ownership[this_adjacent_tower_ID].first << std::endl;
1095 pseudocluster_adjacency[tower_ownership[this_adjacent_tower_ID].first] =
true;
1098 int n_pseudocluster_adjacent = 0;
1099 int last_adjacent_pseudocluster = -1;
1100 for (
unsigned int s = 0;
s < local_maxima_ID.size();
s++)
1102 if (pseudocluster_adjacency[
s])
1104 last_adjacent_pseudocluster =
s;
1105 n_pseudocluster_adjacent++;
1108 std::cout <<
" -> -> adjacent to pseudocluster " << s << std::endl;
1113 if (n_pseudocluster_adjacent == 0)
1115 std::cout <<
" -> -> ERROR! How can a neighbor tower at this stage be adjacent to no pseudoclusters?? " << std::endl;
1116 new_ownerships.push_back(9999);
1118 else if (n_pseudocluster_adjacent == 1)
1122 std::cout <<
" -> -> neighbor tower " << neighbor_ID <<
" is ONLY adjacent to one pseudocluster # " << last_adjacent_pseudocluster << std::endl;
1124 new_ownerships.push_back(last_adjacent_pseudocluster);
1130 std::cout <<
" -> -> neighbor tower " << neighbor_ID <<
" is adjacent to " << n_pseudocluster_adjacent <<
" pseudoclusters, move to shared list " << std::endl;
1132 new_ownerships.push_back(-3);
1139 std::cout <<
" -> now updating status of all " << neighbor_list.size() <<
" original neighbors " << std::endl;
1142 for (
unsigned int n = 0;
n < neighbor_list.size();
n++)
1144 int neighbor_ID = neighbor_list.at(
n);
1145 if (new_ownerships.at(
n) > -1)
1147 tower_ownership[neighbor_ID] = std::pair<int, int>(new_ownerships.at(
n), -1);
1148 seed_list.push_back(neighbor_ID);
1151 std::cout <<
" -> -> neighbor ID " << neighbor_ID <<
" has new status " << new_ownerships.at(
n) << std::endl;
1154 if (new_ownerships.at(
n) == -3)
1156 tower_ownership[neighbor_ID] = std::pair<int, int>(-3, -1);
1157 shared_list.push_back(neighbor_ID);
1160 std::cout <<
" -> -> neighbor ID " << neighbor_ID <<
" has new status " << -3 << std::endl;
1167 std::cout <<
" producing a new neighbor list ... " << std::endl;
1170 std::list<int> new_neighbor_list;
1171 for (
unsigned int n = 0;
n < neighbor_list.size();
n++)
1173 int neighbor_ID = neighbor_list.at(
n);
1174 if (new_ownerships.at(
n) > -1)
1178 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
1184 if (tower_ownership[this_adjacent_tower_ID].first == -1)
1186 new_neighbor_list.push_back(this_adjacent_tower_ID);
1189 std::cout <<
" -> queueing up to add tower " << this_adjacent_tower_ID <<
" , neighbor of tower " << neighbor_ID <<
" to new neighbor list" << std::endl;
1198 std::cout <<
" new neighbor list has size " << new_neighbor_list.size() <<
", but after removing duplicate elements: ";
1199 new_neighbor_list.sort();
1200 new_neighbor_list.unique();
1201 std::cout << new_neighbor_list.size() << std::endl;
1205 neighbor_list.clear();
1208 for (; new_neighbor_list.size() > 0;)
1210 neighbor_list.push_back(new_neighbor_list.front());
1211 new_neighbor_list.pop_front();
1216 }
while (neighbor_list.size() > 0);
1220 for (
int &original_tower : original_towers)
1222 std::pair<int, int> the_pair = tower_ownership[original_tower];
1223 std::cout <<
" Debug Mid-Split: tower_ownership[ " << original_tower <<
" ] = ( " << the_pair.first <<
", " << the_pair.second <<
" ) ";
1225 std::cout << std::endl;
1226 if (the_pair.first == -1)
1230 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
1236 std::cout <<
" -> adjacent to add tower " << this_adjacent_tower_ID <<
" , which has status " << tower_ownership[this_adjacent_tower_ID].first << std::endl;
1243 std::vector<float> pseudocluster_sumeta;
1244 std::vector<float> pseudocluster_sumphi;
1245 std::vector<float> pseudocluster_sumE;
1246 std::vector<int> pseudocluster_ntower;
1247 std::vector<float> pseudocluster_eta;
1248 std::vector<float> pseudocluster_phi;
1250 pseudocluster_sumeta.resize(local_maxima_ID.size(), 0);
1251 pseudocluster_sumphi.resize(local_maxima_ID.size(), 0);
1252 pseudocluster_sumE.resize(local_maxima_ID.size(), 0);
1253 pseudocluster_ntower.resize(local_maxima_ID.size(), 0);
1255 for (
int &original_tower : original_towers)
1257 std::pair<int, int> the_pair = tower_ownership[original_tower];
1258 if (the_pair.first > -1)
1260 float this_ID = original_tower;
1261 pseudocluster_sumE[the_pair.first] +=
get_E_from_ID(this_ID);
1265 pseudocluster_sumeta[the_pair.first] += this_eta;
1266 pseudocluster_sumphi[the_pair.first] += this_phi;
1267 pseudocluster_ntower[the_pair.first] += 1;
1271 for (
unsigned int pc = 0; pc < local_maxima_ID.size(); pc++)
1273 pseudocluster_eta.push_back(pseudocluster_sumeta.at(pc) / pseudocluster_ntower.at(pc));
1274 pseudocluster_phi.push_back(pseudocluster_sumphi.at(pc) / pseudocluster_ntower.at(pc));
1278 std::cout <<
"RawClusterBuilderTopo::process_event pseudocluster #" << pc <<
", E / eta / phi / Ntower = " << pseudocluster_sumE.at(pc) <<
" / " << pseudocluster_eta.at(pc) <<
" / " << pseudocluster_phi.at(pc) <<
" / " << pseudocluster_ntower.at(pc) << std::endl;
1284 std::cout <<
"RawClusterBuilderTopo::process_event now splitting up shared clusters (including unassigned clusters), initial shared list has size " << shared_list.size() << std::endl;
1287 while (shared_list.size() > 0)
1290 int shared_ID = shared_list.at(0);
1291 shared_list.erase(shared_list.begin());
1295 std::cout <<
" -> looking at shared tower " << shared_ID <<
", after this one there are " << shared_list.size() <<
" shared towers left " << std::endl;
1298 std::vector<bool> pseudocluster_adjacency;
1299 pseudocluster_adjacency.resize(local_maxima_ID.size(),
false);
1303 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
1309 if (tower_ownership[this_adjacent_tower_ID].first > -1)
1311 pseudocluster_adjacency[tower_ownership[this_adjacent_tower_ID].first] =
true;
1313 if (tower_ownership[this_adjacent_tower_ID].second > -1)
1315 pseudocluster_adjacency[tower_ownership[this_adjacent_tower_ID].second] =
true;
1318 if (tower_ownership[this_adjacent_tower_ID].first == -1)
1320 shared_list.push_back(this_adjacent_tower_ID);
1321 tower_ownership[this_adjacent_tower_ID] = std::pair<int, int>(-3, -1);
1324 std::cout <<
" -> while looking at neighbors, have added un-examined tower " << this_adjacent_tower_ID <<
" to shared list " << std::endl;
1330 int highest_pseudocluster_index = -1;
1331 int second_highest_pseudocluster_index = -1;
1333 float highest_pseudocluster_E = -1;
1334 float second_highest_pseudocluster_E = -2;
1336 for (
unsigned int n = 0;
n < pseudocluster_adjacency.size();
n++)
1338 if (!pseudocluster_adjacency[
n])
1343 if (pseudocluster_sumE[n] > highest_pseudocluster_E)
1345 second_highest_pseudocluster_E = highest_pseudocluster_E;
1346 second_highest_pseudocluster_index = highest_pseudocluster_index;
1348 highest_pseudocluster_E = pseudocluster_sumE[
n];
1349 highest_pseudocluster_index =
n;
1351 else if (pseudocluster_sumE[n] > second_highest_pseudocluster_E)
1353 second_highest_pseudocluster_E = pseudocluster_sumE[
n];
1354 second_highest_pseudocluster_index =
n;
1360 std::cout <<
" -> highest pseudoclusters its adjacent to are " << highest_pseudocluster_index <<
" ( E = " << highest_pseudocluster_E <<
" ) and " << second_highest_pseudocluster_index <<
" ( E = " << second_highest_pseudocluster_E <<
" ) " << std::endl;
1363 tower_ownership[shared_ID] = std::pair<int, int>(highest_pseudocluster_index, second_highest_pseudocluster_index);
1368 for (
int &original_tower : original_towers)
1370 std::pair<int, int> the_pair = tower_ownership[original_tower];
1371 std::cout <<
" Debug Post-Split: tower_ownership[ " << original_tower <<
" ] = ( " << the_pair.first <<
", " << the_pair.second <<
" ) ";
1373 std::cout << std::endl;
1374 if (the_pair.first == -1)
1378 for (
int this_adjacent_tower_ID : adjacent_tower_IDs)
1384 std::cout <<
" -> adjacent to add tower " << this_adjacent_tower_ID <<
" , which has status " << tower_ownership[this_adjacent_tower_ID].first << std::endl;
1391 export_clusters(original_towers, tower_ownership, local_maxima_ID.size(), pseudocluster_sumE, pseudocluster_eta, pseudocluster_phi);
1396 std::cout <<
"RawClusterBuilderTopo::process_event after splitting (if any) final clusters output to node are: " << std::endl;
1401 std::cout <<
"-> #" << ncl++ <<
" ";
1402 hiter->second->identify();
1403 std::cout << std::endl;
1422 std::cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
1423 throw std::runtime_error(
"Failed to find DST node in RawClusterBuilderTopo::CreateNodes");
1437 DetNode->
addNode(clusterNode);