Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHTrackClusterAssociator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHTrackClusterAssociator.cc
1 
3 
5 
7 #include <phool/PHIODataNode.h>
8 #include <phool/PHNode.h>
9 #include <phool/PHNodeIterator.h>
10 #include <phool/PHObject.h>
11 #include <phool/getClass.h>
12 #include <phool/phool.h>
13 
17 
20 
21 #include <calobase/RawCluster.h>
22 #include <calobase/RawClusterContainer.h>
23 #include <calobase/RawClusterUtility.h>
24 #include <calobase/TowerInfo.h>
25 #include <calobase/TowerInfoContainerv1.h>
26 #include <calobase/RawTowerGeomContainer.h>
27 #include <phgeom/PHGeomUtility.h>
28 
29 namespace
30 {
31  template <class T>
32  inline constexpr T deltaPhi(const T& dphi)
33  {
34  if (dphi > M_PI)
35  return dphi - 2. * M_PI;
36  else if (dphi <= -M_PI)
37  return dphi + 2. * M_PI;
38  else
39  return dphi;
40  }
41 } // namespace
42 
43 //____________________________________________________________________________..
45  : SubsysReco(name)
46 {
47  m_caloNames.push_back("CEMC");
48  m_caloNames.push_back("HCALIN");
49  m_caloNames.push_back("HCALOUT");
50 }
51 
52 //____________________________________________________________________________..
54 {
55 }
56 
57 //____________________________________________________________________________..
59 {
60  int ret = getNodes(topNode);
62  {
63  return ret;
64  }
65 
66  ret = createNodes(topNode);
68  {
69  return ret;
70  }
71 
72  return ret;
73 }
74 
75 //____________________________________________________________________________..
77 {
78  if (!m_calosAvailable)
79  {
81  }
82 
83  for (int layer = 0; layer < m_nCaloLayers; layer++)
84  {
85  if (Verbosity() > 1)
86  {
87  std::cout << "Processing calo layer "
88  << m_caloNames.at(layer) << std::endl;
89  }
90 
91  int ret = matchTracks(topNode, layer);
93  {
95  }
96  }
97 
98  if (Verbosity() > 3)
99  {
100  for (const auto& [track, clustervec] : *m_trackClusterMap)
101  {
102  track->identify();
103  std::cout << " has clusters associated to it : " << std::endl;
104  for (auto cluster : clustervec)
105  {
106  cluster->identify();
107  }
108  }
109  }
110 
112 }
113 
115  const int caloLayer)
116 {
117  if (getCaloNodes(topNode, caloLayer) != Fun4AllReturnCodes::EVENT_OK)
118  {
120  }
121 
123  double caloRadius = m_towerGeomContainer->get_radius();
124  if (m_caloRadii.find(m_caloNames.at(caloLayer)) != m_caloRadii.end())
125  {
126  caloRadius = m_caloRadii.find(m_caloNames.at(caloLayer))->second;
127  }
128 
129  for (const auto& [key, track] : *m_trackMap)
130  {
131  const SvtxTrackState* state = track->get_state(caloRadius);
132  const float statex = state->get_x();
133  const float statey = state->get_y();
134  const float statez = state->get_z();
135  const float statephi = atan2(statey, statex);
136  const float stateeta = asinh(statez /
137  sqrt(statex * statex + statey * statey));
138 
139  const int vertexid = track->get_vertex_id();
140  const auto vertex = m_vertexMap->get(vertexid);
141  const auto cluster = getCluster(statephi, stateeta, vertex);
142  if (Verbosity() > 1)
143  {
144  if (!cluster)
145  {
146  std::cout << "no cluster found, continuing to next track"
147  << std::endl;
148  continue;
149  }
150  else
151  {
152  std::cout << "matching cluster " << cluster->get_id() << " to track " << track->get_id() << std::endl;
153  }
154  }
155 
156  m_trackClusterMap->insert(track, cluster);
157  }
158 
160 }
161 
163  double eta,
165 {
166  double minR = std::numeric_limits<double>::max();
167  auto clusterMap = m_clusterContainer->getClustersMap();
168  RawCluster* returncluster = nullptr;
169  Acts::Vector3 vert = Acts::Vector3::Zero();
170  if (vertex)
171  {
172  vert(0) = vertex->get_x();
173  vert(1) = vertex->get_y();
174  vert(2) = vertex->get_z();
175  }
176 
177  for (const auto& [key, cluster] : clusterMap)
178  {
179  const auto clusterEta =
181  CLHEP::Hep3Vector(vert(0), vert(1), vert(2)));
182  const auto dphi = deltaPhi(phi - cluster->get_phi());
183  const auto deta = eta - clusterEta;
184  const auto r = sqrt(pow(dphi, 2) + pow(deta, 2));
185 
186  if (r < minR)
187  {
188  minR = r;
189  returncluster = cluster;
190  }
191  }
192 
193  return returncluster;
194 }
195 
197 {
198  m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
199  if (!m_trackMap)
200  {
201  std::cout << PHWHERE << "No track map, can't continue" << std::endl;
203  }
204 
205  m_vertexMap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMap");
206  if (!m_vertexMap)
207  {
208  std::cout << PHWHERE << "No vertex map, can't continue" << std::endl;
210  }
211 
213 }
214 
216  const int caloLayer)
217 {
218  std::string towerGeoNodeName = "TOWERGEOM_" + m_caloNames.at(caloLayer);
219  std::string towerNodeName = "TOWERINFO_CALIB_" + m_caloNames.at(caloLayer);
220  std::string clusterNodeName = "CLUSTER_" + m_caloNames.at(caloLayer);
221 
222  m_towerGeomContainer = findNode::getClass<RawTowerGeomContainer>(topNode, towerGeoNodeName.c_str());
223 
224  m_towerContainer = findNode::getClass<TowerInfoContainerv1>(topNode, towerNodeName.c_str());
225 
226  m_clusterContainer = findNode::getClass<RawClusterContainer>(topNode, clusterNodeName.c_str());
227 
228  if (m_useCemcPosRecalib and
229  m_caloNames.at(caloLayer).compare("CEMC") == 0)
230  {
231  std::string nodeName = "CLUSTER_POS_COR_" + m_caloNames.at(caloLayer);
232  m_clusterContainer = findNode::getClass<RawClusterContainer>(topNode, nodeName.c_str());
233  }
234 
235  if (!m_towerGeomContainer or !m_towerContainer or !m_clusterContainer)
236  {
237  std::cout << PHWHERE
238  << "Calo geometry and/or cluster container not found on node tree. Track-Calo cluster map won't be filled."
239  << std::endl;
240  m_calosAvailable = false;
242  }
243 
245 }
246 
248 {
249  PHNodeIterator iter(topNode);
250 
251  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
252 
253  if (!dstNode)
254  {
255  std::cerr << "DST node is missing, quitting" << std::endl;
256  throw std::runtime_error("Failed to find DST node in PHActsSiliconSeeding::createNodes");
257  }
258 
259  PHNodeIterator dstIter(dstNode);
260  PHCompositeNode* svtxNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", "SVTX"));
261 
262  if (!svtxNode)
263  {
264  svtxNode = new PHCompositeNode("SVTX");
265  dstNode->addNode(svtxNode);
266  }
267 
268  m_trackClusterMap = findNode::getClass<SvtxTrackCaloClusterMap>(topNode, "TrackCaloClusterMap");
269  if (!m_trackClusterMap)
270  {
273  m_trackClusterMap, "TrackCaloClusterMap", "PHObject");
274  svtxNode->addNode(node);
275  }
276 
278 }
279 
280 //____________________________________________________________________________..
282 {
284 }
285 
286 //____________________________________________________________________________..
288 {
290 }