Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHSiliconHelicalPropagator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHSiliconHelicalPropagator.cc
2 
6 
9 #include <phool/getClass.h>
10 
11 namespace
12 {
13  template <typename T> int sgn(const T& x)
14  {
15  if(x > 0) return 1;
16  else return -1;
17  }
18 }
19 
21  : SubsysReco(name)
22 {
23 }
24 
26 {
27 }
28 
30 {
31  _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
32  if (!_cluster_map)
33  {
34  std::cerr << PHWHERE << " ERROR: Can't find node TRKR_CLUSTER" << std::endl;
36  }
37  _cluster_crossing_map = findNode::getClass<TrkrClusterCrossingAssoc>(topNode, "TRKR_CLUSTERCROSSINGASSOC");
39  {
40  std::cerr << PHWHERE << " ERROR: Can't find TRKR_CLUSTERCROSSINGASSOC " << std::endl;
42  }
43  _tgeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
44  if (!_tgeometry)
45  {
46  std::cout << "No Acts tracking geometry, exiting." << std::endl;
48  }
49  _tpc_seeds = findNode::getClass<TrackSeedContainer>(topNode, "TpcTrackSeedContainer");
50  if (!_tpc_seeds)
51  {
52  std::cout << "No TpcTrackSeedContainer, exiting." << std::endl;
54  }
55  _si_seeds = findNode::getClass<TrackSeedContainer>(topNode, "SiliconTrackSeedContainer");
56  if (!_si_seeds)
57  {
58  std::cout << "No SiliconTrackSeedContainer, creating..." << std::endl;
59  if (createSeedContainer(_si_seeds, "SiliconTrackSeedContainer", topNode) != Fun4AllReturnCodes::EVENT_OK)
60  {
61  std::cout << "Cannot create, exiting." << std::endl;
63  }
64  }
65  _svtx_seeds = findNode::getClass<TrackSeedContainer>(topNode, _track_map_name);
66  if (!_svtx_seeds)
67  {
68  std::cout << "No " << _track_map_name << " found, creating..." << std::endl;
70  {
71  std::cout << "Cannot create, exiting." << std::endl;
73  }
74  }
76 }
77 
79 {
80  PHNodeIterator iter(topNode);
81 
82  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
83 
84  if (!dstNode)
85  {
86  std::cerr << "DST node is missing, quitting" << std::endl;
87  throw std::runtime_error("Failed to find DST node in PHSiliconHelicalPropagator::createNodes");
88  }
89 
90  PHNodeIterator dstIter(dstNode);
91  PHCompositeNode* svtxNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", "SVTX"));
92 
93  if (!svtxNode)
94  {
95  svtxNode = new PHCompositeNode("SVTX");
96  dstNode->addNode(svtxNode);
97  }
98 
99  container = findNode::getClass<TrackSeedContainer>(topNode, container_name);
100  if (!container)
101  {
102  container = new TrackSeedContainer_v1;
103  PHIODataNode<PHObject>* trackNode = new PHIODataNode<PHObject>(container, container_name, "PHObject");
104  svtxNode->addNode(trackNode);
105  }
106 
108 }
109 
111 {
112  for (unsigned int seedID = 0; seedID < _tpc_seeds->size(); ++seedID)
113  {
114  TrackSeed* tpcseed = _tpc_seeds->get(seedID);
115  if (!tpcseed) continue;
116 
117  std::vector<Acts::Vector3> clusterPositions;
118  std::vector<TrkrDefs::cluskey> clusterKeys;
119  for (auto iter = tpcseed->begin_cluster_keys();
120  iter != tpcseed->end_cluster_keys(); ++iter)
121  {
122  clusterKeys.push_back(*iter);
123  }
124  TrackFitUtils::getTrackletClusters(_tgeometry, _cluster_map, clusterPositions, clusterKeys);
125  std::vector<float> fitparams = TrackFitUtils::fitClusters(clusterPositions, clusterKeys);
127  if (fitparams.size() == 0)
128  {
129  continue;
130  }
131  std::vector<TrkrDefs::cluskey> si_clusterKeys;
132  std::vector<Acts::Vector3> si_clusterPositions;
133 
134  unsigned int nSiClusters = TrackFitUtils::addClusters(fitparams, 1000., _tgeometry, _cluster_map, si_clusterPositions, si_clusterKeys,0,6);
135 
136  if (nSiClusters > 0)
137  {
138 
139  std::unique_ptr<TrackSeed_v1> si_seed = std::make_unique<TrackSeed_v1>();
140  std::map<short, int> crossing_frequency;
141 
142  Acts::Vector3 layer0global;
143 
144  for (auto clusterkey : si_clusterKeys)
145  {
146  if(TrkrDefs::getLayer(clusterkey) == 0)
147  {
148  auto cluster = _cluster_map->findCluster(clusterkey);
149  layer0global = _tgeometry->getGlobalPosition(clusterkey, cluster);
150  }
151  if(TrkrDefs::getTrkrId(clusterkey) == TrkrDefs::mvtxId)
152  {
153  si_seed->insert_cluster_key(clusterkey);
154  }
155  else if (TrkrDefs::getTrkrId(clusterkey) == TrkrDefs::inttId)
156  {
157  auto hit_crossings = _cluster_crossing_map->getCrossings(clusterkey);
158  for (auto iter = hit_crossings.first; iter != hit_crossings.second; ++iter)
159  {
160  short crossing = iter->second;
161  if (crossing_frequency.count(crossing) == 0)
162  crossing_frequency.insert({crossing, 1});
163  else
164  crossing_frequency[crossing]++;
165  }
166 
168  auto cluster = _cluster_map->findCluster(clusterkey);
169  auto global = _tgeometry->getGlobalPosition(clusterkey, cluster);
170  if(sgn(global.x()) == sgn(layer0global.x()) && sgn(global.y()) == sgn(layer0global.y()))
171  {
172  si_seed->insert_cluster_key(clusterkey);
173  }
174  }
175 
176  }
177 
178  if (crossing_frequency.size() > 0)
179  {
180  short most_common_crossing = (std::max_element(crossing_frequency.begin(), crossing_frequency.end(),
181  [](auto entry1, auto entry2)
182  { return entry1.second > entry2.second; }))
183  ->first;
184  si_seed->set_crossing(most_common_crossing);
185  }
186  si_seed->circleFitByTaubin(_cluster_map, _tgeometry, 0, 8);
187  si_seed->lineFit(_cluster_map, _tgeometry, 0, 8);
188 
189  TrackSeed* mapped_seed = _si_seeds->insert(si_seed.get());
190 
191  std::unique_ptr<SvtxTrackSeed_v1> full_seed = std::make_unique<SvtxTrackSeed_v1>();
192  int tpc_seed_index = _tpc_seeds->find(tpcseed);
193  int si_seed_index = _si_seeds->find(mapped_seed);
194  if (Verbosity() > 0)
195  {
196  std::cout << "inserted " << nSiClusters << " silicon clusters for tpc seed " << tpc_seed_index << std::endl;
197  std::cout << "new silicon seed index: " << si_seed_index << std::endl;
198  }
199  full_seed->set_tpc_seed_index(tpc_seed_index);
200  full_seed->set_silicon_seed_index(si_seed_index);
201  _svtx_seeds->insert(full_seed.get());
202  }
203  else
204  {
205  // no Si clusters found, put TPC-only seed in SvtxTrackSeedContainer
206  std::unique_ptr<SvtxTrackSeed_v1> partial_seed = std::make_unique<SvtxTrackSeed_v1>();
207  int tpc_seed_index = _tpc_seeds->find(tpcseed);
208  partial_seed->set_tpc_seed_index(tpc_seed_index);
209  _svtx_seeds->insert(partial_seed.get());
210  }
211  }
212  if (Verbosity() > 2)
213  std::cout << "svtx seed map size is " << _svtx_seeds->size() << std::endl;
215 }
216 
218 {
220 }