Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHActsTrackProjection.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHActsTrackProjection.cc
2 
5 #include <phool/PHDataNode.h>
6 #include <phool/PHNode.h>
7 #include <phool/PHNodeIterator.h>
8 #include <phool/PHObject.h>
9 #include <phool/PHTimer.h>
10 #include <phool/getClass.h>
11 #include <phool/phool.h>
12 
14 
21 
22 #include <calobase/RawCluster.h>
23 #include <calobase/RawClusterContainer.h>
24 #include <calobase/RawClusterUtility.h>
25 #include <calobase/TowerInfo.h>
26 #include <calobase/TowerInfoContainerv1.h>
27 #include <calobase/RawTowerGeomContainer.h>
28 #include <phgeom/PHGeomUtility.h>
29 
34 
35 #include <CLHEP/Vector/ThreeVector.h>
36 #include <math.h>
37 
39  : SubsysReco(name)
40 {
41  m_caloNames.push_back("CEMC");
42  m_caloNames.push_back("HCALIN");
43  m_caloNames.push_back("HCALOUT");
44  m_caloNames.push_back("OUTER_CEMC");
45  m_caloNames.push_back("OUTER_HCALIN");
46  m_caloNames.push_back("OUTER_HCALOUT");
47 
48  m_caloTypes.push_back(SvtxTrack::CEMC);
49  m_caloTypes.push_back(SvtxTrack::HCALIN);
54 }
55 
57 {
58  if (Verbosity() > 1)
59  {
60  std::cout << "PHActsTrackProjection begin Init" << std::endl;
61  }
62 
63  int ret = makeCaloSurfacePtrs(topNode);
64 
66  m_calosAvailable = false;
67 
68  if (getNodes(topNode) != Fun4AllReturnCodes::EVENT_OK)
69  {
71  }
72 
73  if (Verbosity() > 1)
74  {
75  std::cout << "PHActsTrackProjection finished Init" << std::endl;
76  }
77 
78  return ret;
79 }
80 
82 {
83  if (Verbosity() > 1)
84  {
85  std::cout << "PHActsTrackProjection : Starting process_event event "
86  << m_event << std::endl;
87  }
88 
89  for (int layer = 0; layer < m_nCaloLayers; layer++)
90  {
91  if (Verbosity() > 1)
92  {
93  std::cout << "Processing calo layer "
94  << m_caloNames.at(layer) << std::endl;
95  }
96 
98  {
99  continue;
100  }
101 
102  int ret = projectTracks(layer);
103  if (ret != Fun4AllReturnCodes::EVENT_OK)
104  {
106  }
107  ret = projectTracks(layer+m_nCaloLayers);
108  if (ret != Fun4AllReturnCodes::EVENT_OK)
109  {
111  }
112  }
113 
114  if (Verbosity() > 1)
115  {
116  std::cout << "PHActsTrackProjection : Finished process_event event "
117  << m_event << std::endl;
118  }
119 
120  m_event++;
121 
123 }
124 
126 {
128 }
129 
131 {
133 }
134 
135 int PHActsTrackProjection::projectTracks(const int caloLayer)
136 {
138  for (const auto& [key, track] : *m_trackMap)
139  {
140  auto params = prop.makeTrackParams(track, m_vertexMap);
141  if(!params.ok())
142  {
143  continue;
144  }
145  auto cylSurf =
146  m_caloSurfaces.find(m_caloNames.at(caloLayer))->second;
147 
148  auto result = propagateTrack(params.value(), caloLayer, cylSurf);
149  if (result.ok())
150  {
151  updateSvtxTrack(result.value(), track, caloLayer);
152  }
153  }
154 
156 }
157 
160  SvtxTrack* svtxTrack,
161  const int caloLayer)
162 {
163  float pathlength = parameters.first / Acts::UnitConstants::cm;
164  auto params = parameters.second;
165  float calorad = m_caloRadii.find(m_caloTypes.at(caloLayer))->second;
166  SvtxTrackState_v1 out(calorad);
167 
168  auto projectionPos = params.position(m_tGeometry->geometry().getGeoContext());
169  const auto momentum = params.momentum();
170  out.set_x(projectionPos.x() / Acts::UnitConstants::cm);
171  out.set_y(projectionPos.y() / Acts::UnitConstants::cm);
172  out.set_z(projectionPos.z() / Acts::UnitConstants::cm);
173  out.set_px(momentum.x());
174  out.set_py(momentum.y());
175  out.set_pz(momentum.z());
176 
177  if (Verbosity() > 1)
178  {
179  std::cout << "Adding track state for caloLayer " << caloLayer
180  << " at pathlength " << pathlength << " with position " << projectionPos.transpose() << std::endl;
181  }
182 
183  ActsTransformations transformer;
184  const auto globalCov = transformer.rotateActsCovToSvtxTrack(params);
185  for (int i = 0; i < 6; ++i)
186  {
187  for (int j = 0; j < 6; ++j)
188  {
189  out.set_error(i, j, globalCov(i, j));
190  }
191  }
192 
193  svtxTrack->insert_state(&out);
194  return;
195 }
196 
198  double eta,
199  double& minIndex,
200  double& minDphi,
201  double& minDeta,
202  double& minE)
203 {
204  double minR = DBL_MAX;
205  auto clusterMap = m_clusterContainer->getClustersMap();
206  for (const auto& [key, cluster] : clusterMap)
207  {
208  const auto clusterEta =
210  CLHEP::Hep3Vector(0, 0, 0));
211  const auto dphi = deltaPhi(phi - cluster->get_phi());
212  const auto deta = eta - clusterEta;
213  const auto r = sqrt(pow(dphi, 2) + pow(deta, 2));
214 
215  if (r < minR)
216  {
217  minIndex = key;
218  minR = r;
219  minDphi = dphi;
220  minDeta = deta;
221  minE = cluster->get_energy();
222  }
223  }
224 
225  return;
226 }
227 
229  int etaBin,
230  double& energy3x3,
231  double& energy5x5)
232 {
233  for (int iphi = phiBin - 2; iphi <= phiBin + 2; ++iphi)
234  {
235  for (int ieta = etaBin - 2; ieta <= etaBin + 2; ++ieta)
236  {
238  int wrapPhi = iphi;
239  if (wrapPhi < 0)
240  wrapPhi += m_towerGeomContainer->get_phibins();
241  if (wrapPhi >= m_towerGeomContainer->get_phibins())
242  wrapPhi -= m_towerGeomContainer->get_phibins();
243 
245  if (ieta < 0 or ieta >= m_towerGeomContainer->get_etabins())
246  continue;
247 
248  unsigned int towerkey = (ieta << 16U) + wrapPhi;
249  auto tower = m_towerContainer->get_tower_at_key(towerkey);
250 
251  if (!tower)
252  continue;
253 
254  energy5x5 += tower->get_energy();
255  if (abs(iphi - phiBin) <= 1 and abs(ieta - etaBin) <= 1)
256  energy3x3 += tower->get_energy();
257  }
258  }
259 
260  return;
261 }
262 
265  const Acts::BoundTrackParameters& params,
266  const int /*caloLayer*/,
267  const SurfacePtr& targetSurf)
268 {
269  ActsPropagator propagator(m_tGeometry);
270  propagator.constField();
271  propagator.verbosity(Verbosity());
273 
274  return propagator.propagateTrackFast(params, targetSurf);
275 }
276 
278  const int caloLayer)
279 {
280  std::string towerGeoNodeName = "TOWERGEOM_" + m_caloNames.at(caloLayer);
281  std::string towerNodeName = "TOWERINFO_CALIB_" + m_caloNames.at(caloLayer);
282  std::string clusterNodeName = "CLUSTER_" + m_caloNames.at(caloLayer);
283 
284  m_towerGeomContainer = findNode::getClass<RawTowerGeomContainer>(topNode, towerGeoNodeName.c_str());
285 
286  m_towerContainer = findNode::getClass<TowerInfoContainerv1>(topNode, towerNodeName.c_str());
287 
288  m_clusterContainer = findNode::getClass<RawClusterContainer>(topNode, clusterNodeName.c_str());
289 
290  if (m_useCemcPosRecalib and
291  m_caloNames.at(caloLayer).compare("CEMC") == 0)
292  {
293  std::string nodeName = "CLUSTER_POS_COR_" + m_caloNames.at(caloLayer);
294  m_clusterContainer = findNode::getClass<RawClusterContainer>(topNode, nodeName.c_str());
295  }
296 
297  if (!m_towerGeomContainer or !m_towerContainer or !m_clusterContainer)
298  {
299  if (m_calosAvailable)
300  {
301  std::cout << PHWHERE
302  << "Calo geometry and/or cluster container for " << m_caloNames.at(caloLayer)
303  << "not found on node tree. Track projections to calos won't be filled."
304  << std::endl;
305  }
306 
308  }
309 
311 }
312 
314 {
315  for (int caloLayer = 0; caloLayer < m_nCaloLayers; caloLayer++)
316  {
317  if (setCaloContainerNodes(topNode, caloLayer) != Fun4AllReturnCodes::EVENT_OK)
318  {
319  continue;
320  }
321 
323  double caloRadius = m_towerGeomContainer->get_radius();
324  double caloOuterRadius = m_towerGeomContainer->get_radius() + m_towerGeomContainer->get_thickness();
325 
326  if (m_caloRadii.find(m_caloTypes.at(caloLayer)) != m_caloRadii.end())
327  {
328  caloRadius = m_caloRadii.find(m_caloTypes.at(caloLayer))->second;
329  }
330  else
331  {
332  m_caloRadii.insert(std::make_pair(m_caloTypes.at(caloLayer), caloRadius));
333  }
334 
335  caloRadius *= Acts::UnitConstants::cm;
336 
337  if (m_caloRadii.find(m_caloTypes.at(caloLayer+m_nCaloLayers)) != m_caloRadii.end())
338  {
339  caloOuterRadius = m_caloRadii.find(m_caloTypes.at(caloLayer+m_nCaloLayers))->second;
340  }
341  else
342  {
343  m_caloRadii.insert(std::make_pair(m_caloTypes.at(caloLayer+m_nCaloLayers), caloOuterRadius));
344  }
345 
346  caloOuterRadius *= Acts::UnitConstants::cm;
347 
350  const auto eta = 2.5;
351  const auto theta = 2. * atan(exp(-eta));
352  const auto halfZ = caloRadius / tan(theta) * Acts::UnitConstants::cm;
353  const auto halfZOuter = caloOuterRadius / tan(theta) * Acts::UnitConstants::cm;
354 
356  auto transform = Acts::Transform3::Identity();
357 
358  std::shared_ptr<Acts::CylinderSurface> surf =
359  Acts::Surface::makeShared<Acts::CylinderSurface>(transform,
360  caloRadius,
361  halfZ);
362  std::shared_ptr<Acts::CylinderSurface> outer_surf =
363  Acts::Surface::makeShared<Acts::CylinderSurface>(transform,
364  caloOuterRadius,
365  halfZOuter);
366  if (Verbosity() > 1)
367  {
368  std::cout << "Creating cylindrical surface at " << caloRadius << std::endl;
369  std::cout << "Creating cylindrical surface at " << caloOuterRadius << std::endl;
370  }
371  m_caloSurfaces.insert(std::make_pair(m_caloNames.at(caloLayer),surf));
372  m_caloSurfaces.insert(std::make_pair(m_caloNames.at(caloLayer+m_nCaloLayers), outer_surf));
373  }
374 
375  if (Verbosity() > 1)
376  {
377  for (const auto& [name, surfPtr] : m_caloSurfaces)
378  {
379  std::cout << "Cylinder " << name << " has center "
380  << surfPtr.get()->center(m_tGeometry->geometry().getGeoContext()).transpose()
381  << std::endl;
382  }
383  }
384 
386 }
387 
389 {
390  m_vertexMap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMap");
391  if (!m_vertexMap)
392  {
393  std::cout << PHWHERE << "No vertex map on node tree, bailing."
394  << std::endl;
396  }
397 
398  m_tGeometry = findNode::getClass<ActsGeometry>(
399  topNode, "ActsGeometry");
400  if (!m_tGeometry)
401  {
402  std::cout << "ActsTrackingGeometry not on node tree. Exiting."
403  << std::endl;
404 
406  }
407 
408  m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
409  if (!m_trackMap)
410  {
411  std::cout << PHWHERE << "No SvtxTrackMap on node tree. Bailing."
412  << std::endl;
414  }
415 
417 }
418 
420 {
421  if (phi > M_PI)
422  return phi - 2. * M_PI;
423  else if (phi <= -M_PI)
424  return phi + 2. * M_PI;
425  else
426  return phi;
427 }