EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawClusterBuilderkV3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawClusterBuilderkV3.cc
1 #include "RawClusterBuilderkV3.h"
3 
4 #include <calobase/RawCluster.h>
5 #include <calobase/RawClusterContainer.h>
6 #include <calobase/RawClusterDefs.h>
7 #include <calobase/RawClusterv1.h>
8 #include <calobase/RawTower.h>
9 #include <calobase/RawTowerContainer.h>
10 #include <calobase/RawTowerDefs.h>
11 #include <calobase/RawTowerGeom.h>
12 #include <calobase/RawTowerGeomContainer.h>
13 
15 #include <fun4all/SubsysReco.h>
16 
17 #include <phool/PHCompositeNode.h>
18 #include <phool/PHIODataNode.h>
19 #include <phool/PHNode.h>
20 #include <phool/PHNodeIterator.h>
21 #include <phool/PHObject.h>
22 #include <phool/getClass.h>
23 #include <phool/phool.h>
24 
25 #include <algorithm>
26 #include <cassert>
27 #include <cmath>
28 #include <exception>
29 #include <iostream>
30 #include <map>
31 #include <stdexcept>
32 #include <utility>
33 #include <vector>
34 
35 using namespace std;
36 
39 {
40 }
41 
42 void RawClusterBuilderkV3::cluster(std::vector<towersStrct> &input_towers, uint caloId)
43 {
44  // Next we'll sort the towers from most energetic to least
45  // This is from https://github.com/FriederikeBock/AnalysisSoftwareEIC/blob/642aeb13b13271820dfee59efe93380e58456289/treeAnalysis/clusterizer.cxx#L281
46  std::sort(input_towers.begin(), input_towers.end(), &towerECompare);
47  std::vector<towersStrct> cluster_towers;
48  // And run kV3 clustering
49  while (!input_towers.empty())
50  {
51  cluster_towers.clear();
52  // always start with highest energetic tower
53  if (input_towers.at(0).tower_E > _seed_e)
54  {
56  _clusters->AddCluster(cluster); // Add cluster to cluster container
57  // fill seed cell information into current cluster
58  cluster->addTower(input_towers.at(0).twr->get_id(), input_towers.at(0).tower_E);
59  // std::cout << "Started new cluster! " << input_towers.at(0).tower_E << std::endl;
60  cluster_towers.push_back(input_towers.at(0));
61  // kV3 Clustering
62  input_towers.erase(input_towers.begin());
63  for (int tit = 0; tit < (int) cluster_towers.size(); tit++)
64  {
65  // Now go recursively to the next 4 neighbours and add them to the cluster if they fulfill the conditions
66  int iEtaTwr = cluster_towers.at(tit).tower_iEta;
67  int iPhiTwr = cluster_towers.at(tit).tower_iPhi;
68  for (int ait = 0; ait < (int) input_towers.size(); ait++)
69  {
70  int iEtaTwrAgg = input_towers.at(ait).tower_iEta;
71  int iPhiTwrAgg = input_towers.at(ait).tower_iPhi;
72 
73  if (!IsForwardCalorimeter(caloId))
74  {
75  if (iPhiTwr < 5 && iPhiTwrAgg > caloTowersPhi(caloId) - 5)
76  {
77  iPhiTwrAgg = iPhiTwrAgg - caloTowersPhi(caloId);
78  }
79  if (iPhiTwr > caloTowersPhi(caloId) - 5 && iPhiTwrAgg < 5)
80  {
81  iPhiTwr = iPhiTwr - caloTowersPhi(caloId);
82  }
83  }
84  int deltaEta = std::abs(iEtaTwrAgg - iEtaTwr);
85  int deltaPhi = std::abs(iPhiTwrAgg - iPhiTwr);
86 
87  if ((deltaEta + deltaPhi) == 1)
88  {
89  // only aggregate towers with lower energy than current tower
90  if (input_towers.at(ait).tower_E >= (cluster_towers.at(tit).tower_E + _agg_e)) continue;
91  cluster->addTower(input_towers.at(ait).twr->get_id(), input_towers.at(ait).tower_E); // Add tower to cluster
92  // std::cout << "Added a tower to the cluster! " << input_towers.at(ait).tower_E << std::endl;
93  cluster_towers.push_back(input_towers.at(ait));
94  input_towers.erase(input_towers.begin() + ait);
95  ait--;
96  }
97  }
98  }
99  }
100  else
101  {
102  input_towers.clear();
103  }
104  }
105 }