Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHCosmicSiliconPropagator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHCosmicSiliconPropagator.cc
1 
3 
6 #include <phool/getClass.h>
16 
17 namespace
18 {
19  template <class T>
20  inline constexpr T square(T& x)
21  {
22  return x * x;
23  }
24  template <class T>
25  inline constexpr T r(T& x, T& y)
26  {
27  return std::sqrt(square(x) + square(y));
28  }
29 
30 } // namespace
31 //____________________________________________________________________________..
33  : SubsysReco(name)
34 {
35 }
36 
37 //____________________________________________________________________________..
39 {
40 }
41 
42 //____________________________________________________________________________..
44 {
46 }
47 
48 //____________________________________________________________________________..
50 {
51  _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
52  if (!_cluster_map)
53  {
54  std::cerr << PHWHERE << " ERROR: Can't find node TRKR_CLUSTER" << std::endl;
56  }
57 
58  _tgeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
59  if (!_tgeometry)
60  {
61  std::cout << "No Acts tracking geometry, exiting." << std::endl;
63  }
64  _tpc_seeds = findNode::getClass<TrackSeedContainer>(topNode, "TpcTrackSeedContainer");
65  if (!_tpc_seeds)
66  {
67  std::cout << "No TpcTrackSeedContainer, exiting." << std::endl;
69  }
70  _si_seeds = findNode::getClass<TrackSeedContainer>(topNode, "SiliconTrackSeedContainer");
71  if (!_si_seeds)
72  {
73  std::cout << "No SiliconTrackSeedContainer, creating..." << std::endl;
74  if (createSeedContainer(_si_seeds, "SiliconTrackSeedContainer", topNode) != Fun4AllReturnCodes::EVENT_OK)
75  {
76  std::cout << "Cannot create, exiting." << std::endl;
78  }
79  }
80  _svtx_seeds = findNode::getClass<TrackSeedContainer>(topNode, _track_map_name);
81  if (!_svtx_seeds)
82  {
83  std::cout << "No " << _track_map_name << " found, creating..." << std::endl;
85  {
86  std::cout << "Cannot create, exiting." << std::endl;
88  }
89  }
90 
92 }
93 
94 //____________________________________________________________________________..
96 {
97  if (m_resetContainer)
98  {
99  _svtx_seeds->Reset();
100  }
101 
102  for (auto& tpcseed : *_tpc_seeds)
103  {
104  if (!tpcseed)
105  {
106  continue;
107  }
108  if (Verbosity() > 3)
109  {
110  std::cout << "Tpc seed to start out is " << std::endl;
111  tpcseed->identify();
112  }
113  std::vector<Acts::Vector3> tpcClusPos;
114  std::vector<TrkrDefs::cluskey> tpcClusKeys;
115 
116  std::copy(tpcseed->begin_cluster_keys(), tpcseed->end_cluster_keys(),
117  std::back_inserter(tpcClusKeys));
118 
120  tpcClusPos, tpcClusKeys);
121  std::vector<TrkrDefs::cluskey> newClusKeys;
122  std::vector<Acts::Vector3> newClusPos;
123  unsigned int nClusters = 0;
124 
125  if (m_zeroField)
126  {
128  TrackFitUtils::position_vector_t rzpoints, xypoints;
129  for (auto& globPos : tpcClusPos)
130  {
131  xypoints.push_back(std::make_pair(globPos.x(), globPos.y()));
132  float clusr = r(globPos.x(), globPos.y());
133  if (globPos.y() < 0) clusr *= -1;
134  rzpoints.push_back(std::make_pair(globPos.z(), clusr));
135  }
136 
137  auto xyLineParams = TrackFitUtils::line_fit(xypoints);
138  auto rzLineParams = TrackFitUtils::line_fit(rzpoints);
139 
140  std::vector<TrkrDefs::cluskey> newClusKeysrz;
141  std::vector<Acts::Vector3> newClusPosrz;
142  std::vector<TrkrDefs::cluskey> newClusKeysxy;
143  std::vector<Acts::Vector3> newClusPosxy;
144  // now add clusters along lines
145  nClusters = TrackFitUtils::addClustersOnLine(xyLineParams,
146  true,
147  _dca_xy_cut,
148  _tgeometry,
149  _cluster_map,
150  newClusPosxy,
151  newClusKeysxy,
152  0, 56);
153  int nrzClusters = TrackFitUtils::addClustersOnLine(rzLineParams,
154  false,
155  _dca_z_cut,
156  _tgeometry,
157  _cluster_map,
158  newClusPosrz,
159  newClusKeysrz,
160  0, 56);
161 
162  if (Verbosity() > 3)
163  {
164  std::cout << "nrz clus " << nrzClusters << " and nxy clusters " << nClusters
165  << std::endl;
166  }
167  std::set_intersection(newClusKeysxy.begin(), newClusKeysxy.end(),
168  newClusKeysrz.begin(), newClusKeysrz.end(), std::back_inserter(newClusKeys));
169  if (m_resetContainer)
170  {
171  for (auto& keys : {newClusKeysxy, newClusKeysrz})
172  {
173  for (auto& key : keys)
174  {
176  {
177  newClusKeys.push_back(key);
178  }
179  }
180  }
181  }
182 
183  if (Verbosity() > 3)
184  {
185  for (auto key : newClusKeysxy)
186  {
187  auto cluster = _cluster_map->findCluster(key);
188  auto clusglob = _tgeometry->getGlobalPosition(key, cluster);
189  std::cout << "Found key " << key << " for xy cosmic in layer " << (unsigned int) TrkrDefs::getLayer(key)
190  << " with pos " << clusglob.transpose() << std::endl;
191  }
192  for (auto key : newClusKeysrz)
193  {
194  auto cluster = _cluster_map->findCluster(key);
195  auto clusglob = _tgeometry->getGlobalPosition(key, cluster);
196  std::cout << "Found key " << key << " for rz cosmic in layer " << (unsigned int) TrkrDefs::getLayer(key)
197  << " with pos " << clusglob.transpose() << std::endl;
198  }
199  }
200  }
201  else
202  {
203  std::vector<float> fitparams = TrackFitUtils::fitClusters(tpcClusPos, tpcClusKeys);
205  if (fitparams.size() == 0)
206  {
207  continue;
208  }
209 
210  std::vector<TrkrDefs::cluskey> ckeys;
212  newClusPos, ckeys, 0, 56);
213 
214  for (auto& key : ckeys)
215  {
216  auto cluster = _cluster_map->findCluster(key);
217  auto clusglob = _tgeometry->getGlobalPosition(key, cluster);
218  auto pca = TrackFitUtils::get_helix_pca(fitparams, clusglob);
219  float dcaz = (pca - clusglob).z();
220 
221  if (fabs(dcaz) < _dca_z_cut)
222  {
223  newClusKeys.push_back(key);
224  }
225  }
226  }
227 
229  if ((tpcClusKeys.size() + newClusKeys.size() > 25))
230  {
231  std::unique_ptr<TrackSeed_v1> si_seed = std::make_unique<TrackSeed_v1>();
232  for (auto& key : newClusKeys)
233  {
234  bool isTpcKey = false;
237  {
238  isTpcKey = true;
239  }
240  if (!isTpcKey)
241  {
242  si_seed->insert_cluster_key(key);
243  }
244  else
245  {
246  tpcseed->insert_cluster_key(key);
247  }
248  }
249 
250  si_seed->circleFitByTaubin(_cluster_map, _tgeometry, 0, 8);
251  si_seed->lineFit(_cluster_map, _tgeometry, 0, 8);
252  tpcseed->circleFitByTaubin(_cluster_map, _tgeometry, 0, 57);
253  tpcseed->lineFit(_cluster_map, _tgeometry, 0, 57);
254  TrackSeed* mapped_seed = _si_seeds->insert(si_seed.get());
255  std::unique_ptr<SvtxTrackSeed_v1> full_seed = std::make_unique<SvtxTrackSeed_v1>();
256  int tpcind = _tpc_seeds->find(tpcseed);
257  int siind = _si_seeds->find(mapped_seed);
258  full_seed->set_tpc_seed_index(tpcind);
259  if (si_seed->size_cluster_keys() > 0)
260  {
261  full_seed->set_silicon_seed_index(siind);
262  }
263  _svtx_seeds->insert(full_seed.get());
264  if (Verbosity() > 3)
265  {
266  std::cout << "final seeds" << std::endl;
267  si_seed->identify();
268  tpcseed->identify();
269  }
270  }
271  }
272 
273  if (Verbosity() > 2)
274  {
275  std::cout << "svtx seed map size is " << _svtx_seeds->size() << std::endl;
276  int i = 0;
277  for (auto& seed : *_svtx_seeds)
278  {
279  std::cout << "seed " << i << " is composed of " << std::endl;
280  _tpc_seeds->get(seed->get_tpc_seed_index())->identify();
281  if (_si_seeds->get(seed->get_silicon_seed_index()))
282  {
283  _si_seeds->get(seed->get_silicon_seed_index())->identify();
284  }
285  ++i;
286  }
287  }
289 }
290 
291 //____________________________________________________________________________..
293 {
295 }
296 
298 {
299  PHNodeIterator iter(topNode);
300 
301  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
302 
303  if (!dstNode)
304  {
305  std::cerr << "DST node is missing, quitting" << std::endl;
306  throw std::runtime_error("Failed to find DST node in PHSiliconHelicalPropagator::createNodes");
307  }
308 
309  PHNodeIterator dstIter(dstNode);
310  PHCompositeNode* svtxNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", "SVTX"));
311 
312  if (!svtxNode)
313  {
314  svtxNode = new PHCompositeNode("SVTX");
315  dstNode->addNode(svtxNode);
316  }
317 
318  container = findNode::getClass<TrackSeedContainer>(topNode, container_name);
319  if (!container)
320  {
321  container = new TrackSeedContainer_v1;
322  PHIODataNode<PHObject>* trackNode = new PHIODataNode<PHObject>(container, container_name, "PHObject");
323  svtxNode->addNode(trackNode);
324  }
325 
327 }