ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawClusterBuilderkMA.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawClusterBuilderkMA.cc
2 #include <RawClusterBuilderkMA.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 <TMath.h>
26 
27 #include <algorithm>
28 #include <cassert>
29 #include <string>
30 #include <utility>
31 
34 {
35 }
36 
37 void RawClusterBuilderkMA::cluster(std::vector<towersStrct> &input_towers, uint caloId)
38 {
39  std::sort(input_towers.begin(), input_towers.end(), &towerECompare);
40  std::vector<towersStrct> cluster_towers;
41  while (!input_towers.empty())
42  {
43  cluster_towers.clear();
44 
45  // always start with highest energetic tower
46  if (input_towers.at(0).tower_E > _seed_e)
47  {
48  // std::cout << "new cluster" << std::endl;
49  // fill seed cell information into current cluster
50  cluster_towers.push_back(input_towers.at(0));
52  _clusters->AddCluster(cluster);
53  cluster->addTower(input_towers.at(0).twr->get_id(), input_towers.at(0).tower_E);
54  // std::cout << "running MA" << std::endl;
55  // remove seed tower from sample
56  input_towers.erase(input_towers.begin());
57  for (int tit = 0; tit < (int) cluster_towers.size(); tit++)
58  {
59  // std::cout << "recurse" << std::endl;
60  // Now go recursively to all neighbours and add them to the cluster if they fulfill the conditions
61  int iEtaTwr = cluster_towers.at(tit).tower_iEta;
62  int iPhiTwr = cluster_towers.at(tit).tower_iPhi;
63  int iLTwr = cluster_towers.at(tit).tower_iL;
64  int refC = 0;
65  for (int ait = 0; ait < (int) input_towers.size(); ait++)
66  {
67  int iEtaTwrAgg = input_towers.at(ait).tower_iEta;
68  int iPhiTwrAgg = input_towers.at(ait).tower_iPhi;
69  int iLTwrAgg = input_towers.at(ait).tower_iL;
70 
71  if (!IsForwardCalorimeter(caloId))
72  {
73  if (iPhiTwr < 5 && iPhiTwrAgg > caloTowersPhi(caloId) - 5)
74  {
75  iPhiTwrAgg = iPhiTwrAgg - caloTowersPhi(caloId);
76  }
77  if (iPhiTwr > caloTowersPhi(caloId) - 5 && iPhiTwrAgg < 5)
78  {
79  iPhiTwr = iPhiTwr - caloTowersPhi(caloId);
80  }
81  }
82 
83  int deltaL = TMath::Abs(iLTwrAgg - iLTwr);
84  int deltaPhi = TMath::Abs(iPhiTwrAgg - iPhiTwr);
85  int deltaEta = TMath::Abs(iEtaTwrAgg - iEtaTwr);
86  // std::cout << "DeltaL: " << deltaL;
87  // std::cout << "\tDeltaPhi: " << deltaPhi;
88  // std::cout << "\tDeltaEta: " << deltaEta << std::endl;
89  bool neighbor = (deltaL + deltaPhi + deltaEta == 1);
90  bool corner2D = (deltaL == 0 && deltaPhi == 1 && deltaEta == 1) || (deltaL == 1 && deltaPhi == 0 && deltaEta == 1) || (deltaL == 1 && deltaPhi == 1 && deltaEta == 0);
91  // first condition asks for V3-like neighbors, while second condition also checks diagonally attached towers
92  if (neighbor || corner2D)
93  {
94  // only aggregate towers with lower energy than current tower
95  // if(caloId != RawTowerDefs::LFHCAL){ // TODO Why?
96  if (input_towers.at(ait).tower_E >= (cluster_towers.at(tit).tower_E + _agg_e)) continue;
97  // }
98  cluster_towers.push_back(input_towers.at(ait));
99  // std::cout << "added a tower to the cluster" << std::endl;
100  cluster->addTower(input_towers.at(ait).twr->get_id(), input_towers.at(ait).tower_E); // Add tower to cluster)
101  input_towers.erase(input_towers.begin() + ait);
102  if (Verbosity() > 2) std::cout << "aggregated: " << iEtaTwrAgg << "\t" << iPhiTwrAgg << "\t" << iLTwrAgg << "\t E:" << input_towers.at(ait).tower_E << "\t reference: " << refC << "\t" << iEtaTwr << "\t" << iPhiTwr << "\t" << iLTwr << "\t cond.: \t" << neighbor << "\t" << corner2D << "\t diffs: " << deltaEta << "\t" << deltaPhi << "\t" << deltaL << std::endl;
103  ait--;
104  refC++;
105  }
106  }
107  }
108  }
109  else
110  {
111  input_towers.clear();
112  }
113  }
114 }