Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:10

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 
0059     addClustersToIterationMap(silseed);
0060  
0061     }
0062     if(tpcseed)
0063     {
0064     addClustersToIterationMap(tpcseed);
0065   }
0066   }
0067 
0068   return Fun4AllReturnCodes::EVENT_OK;
0069 }
0070 
0071 void TrackingIterationCounter::addClustersToIterationMap(TrackSeed *seed)
0072 {
0073   for (auto clusIter = seed->begin_cluster_keys();
0074        clusIter != seed->end_cluster_keys();
0075        ++clusIter)
0076   {
0077     TrkrDefs::cluskey key = *clusIter;
0078     m_iterMap->addIteration(key, m_iteration);
0079   }
0080 }
0081 
0082 //____________________________________________________________________________..
0083 int TrackingIterationCounter::End(PHCompositeNode *)
0084 {
0085   return Fun4AllReturnCodes::EVENT_OK;
0086 }
0087 int TrackingIterationCounter::createNodes(PHCompositeNode *topNode)
0088 {
0089   PHNodeIterator iter(topNode);
0090 
0091   PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0092 
0093   if (!dstNode)
0094   {
0095     std::cerr << "DST node is missing, quitting" << std::endl;
0096     throw std::runtime_error("Failed to find DST node in PHActsTrkFitter::createNodes");
0097   }
0098 
0099   PHNodeIterator dstIter(topNode);
0100   PHCompositeNode *svtxNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", "SVTX"));
0101 
0102   if (!svtxNode)
0103   {
0104     svtxNode = new PHCompositeNode("SVTX");
0105     dstNode->addNode(svtxNode);
0106   }
0107 
0108   m_iterMap = findNode::getClass<TrkrClusterIterationMap>(topNode, "TrkrClusterIterationMap");
0109   if (!m_iterMap)
0110   {
0111     m_iterMap = new TrkrClusterIterationMapv1;
0112     auto node =
0113         new PHIODataNode<PHObject>(m_iterMap, "TrkrClusterIterationMap", "PHObject");
0114     svtxNode->addNode(node);
0115   }
0116 
0117   return Fun4AllReturnCodes::EVENT_OK;
0118 }
0119 int TrackingIterationCounter::getNodes(PHCompositeNode *topNode)
0120 {
0121   m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, m_trackMapName);
0122   if (!m_trackMap)
0123   {
0124     std::cout << PHWHERE << "No track map, bailing. " << std::endl;
0125     return Fun4AllReturnCodes::ABORTEVENT;
0126   }
0127 
0128   return Fun4AllReturnCodes::EVENT_OK;
0129 }