File indexing completed on 2025-08-06 08:18:36
0001 #include "TrackingIterationCounter.h"
0002
0003 #include <trackbase/TrkrClusterIterationMapv1.h>
0004 #include <trackbase/TrkrDefs.h>
0005
0006 #include <trackbase_historic/SvtxTrack.h>
0007 #include <trackbase_historic/SvtxTrackMap.h>
0008 #include <trackbase_historic/TrackSeed.h>
0009
0010 #include <fun4all/Fun4AllReturnCodes.h>
0011 #include <phool/PHCompositeNode.h>
0012 #include <phool/PHDataNode.h>
0013 #include <phool/PHNode.h>
0014 #include <phool/PHNodeIterator.h>
0015 #include <phool/PHObject.h>
0016 #include <phool/PHTimer.h>
0017 #include <phool/getClass.h>
0018 #include <phool/phool.h>
0019
0020 TrackingIterationCounter::TrackingIterationCounter(const std::string &name)
0021 : SubsysReco(name)
0022 {
0023 }
0024
0025
0026 TrackingIterationCounter::~TrackingIterationCounter()
0027 {
0028 }
0029
0030
0031 int TrackingIterationCounter::Init(PHCompositeNode *)
0032 {
0033 return Fun4AllReturnCodes::EVENT_OK;
0034 }
0035
0036
0037 int TrackingIterationCounter::InitRun(PHCompositeNode *topNode)
0038 {
0039 int val = getNodes(topNode);
0040 if (val != Fun4AllReturnCodes::EVENT_OK)
0041 {
0042 return Fun4AllReturnCodes::ABORTEVENT;
0043 }
0044
0045 val = createNodes(topNode);
0046 return val;
0047 }
0048
0049
0050 int TrackingIterationCounter::process_event(PHCompositeNode *)
0051 {
0052 for (const auto &[key, track] : *m_trackMap)
0053 {
0054 auto silseed = track->get_silicon_seed();
0055 auto tpcseed = track->get_tpc_seed();
0056 if(silseed)
0057 {
0058 addClustersToIterationMap(silseed);
0059 }
0060 if(tpcseed)
0061 {
0062 addClustersToIterationMap(tpcseed);
0063 }
0064 }
0065
0066 return Fun4AllReturnCodes::EVENT_OK;
0067 }
0068
0069 void TrackingIterationCounter::addClustersToIterationMap(TrackSeed *seed)
0070 {
0071 for (auto clusIter = seed->begin_cluster_keys();
0072 clusIter != seed->end_cluster_keys();
0073 ++clusIter)
0074 {
0075 TrkrDefs::cluskey key = *clusIter;
0076 m_iterMap->addIteration(key, m_iteration);
0077 }
0078 }
0079
0080
0081 int TrackingIterationCounter::End(PHCompositeNode *)
0082 {
0083 return Fun4AllReturnCodes::EVENT_OK;
0084 }
0085 int TrackingIterationCounter::createNodes(PHCompositeNode *topNode)
0086 {
0087 PHNodeIterator iter(topNode);
0088
0089 PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0090
0091 if (!dstNode)
0092 {
0093 std::cerr << "DST node is missing, quitting" << std::endl;
0094 throw std::runtime_error("Failed to find DST node in PHActsTrkFitter::createNodes");
0095 }
0096
0097 PHNodeIterator dstIter(topNode);
0098 PHCompositeNode *svtxNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", "SVTX"));
0099
0100 if (!svtxNode)
0101 {
0102 svtxNode = new PHCompositeNode("SVTX");
0103 dstNode->addNode(svtxNode);
0104 }
0105
0106 m_iterMap = findNode::getClass<TrkrClusterIterationMap>(topNode, "TrkrClusterIterationMap");
0107 if (!m_iterMap)
0108 {
0109 m_iterMap = new TrkrClusterIterationMapv1;
0110 auto node =
0111 new PHIODataNode<PHObject>(m_iterMap, "TrkrClusterIterationMap", "PHObject");
0112 svtxNode->addNode(node);
0113 }
0114
0115 return Fun4AllReturnCodes::EVENT_OK;
0116 }
0117 int TrackingIterationCounter::getNodes(PHCompositeNode *topNode)
0118 {
0119 m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
0120 if (!m_trackMap)
0121 {
0122 std::cout << PHWHERE << "No track map, bailing. " << std::endl;
0123 return Fun4AllReturnCodes::ABORTEVENT;
0124 }
0125
0126 return Fun4AllReturnCodes::EVENT_OK;
0127 }