Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHTrackSelector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHTrackSelector.cc
1 #include "PHTrackSelector.h"
2 
4 
5 #include <trackbase/TrkrCluster.h> // for TrkrCluster
6 #include <trackbase/TrkrDefs.h> // for cluskey, getLayer, TrkrId
9 #include <trackbase_historic/SvtxTrack.h> // for SvtxTrack, SvtxTrack::C...
11 
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h> // for PHIODataNode
16 #include <phool/PHNode.h> // for PHNode
17 #include <phool/PHNodeIterator.h>
18 #include <phool/PHObject.h> // for PHObject
19 #include <phool/getClass.h>
20 #include <phool/phool.h>
21 
22 #include <cmath> // for sqrt, fabs, atan2, cos
23 #include <iostream> // for operator<<, basic_ostream
24 #include <map> // for map
25 #include <set> // for _Rb_tree_const_iterator
26 #include <utility> // for pair, make_pair
27 
28 //____________________________________________________________________________..
30  : SubsysReco(name)
31  , _track_map_name("SvtxTrackMap")
32  , _n_iter(1)
33  , min_tpc_clusters(40)
34  , min_mvtx_hits(2)
35  , min_intt_hits(1)
36  , max_chi2_ndf(30)
37 {
38 
39 }
40 
41 //____________________________________________________________________________..
43 {
44 
45 }
46 
47 //____________________________________________________________________________..
49 {
50  int ret = GetNodes(topNode);
51  if (ret != Fun4AllReturnCodes::EVENT_OK) return ret;
52 
53  return ret;
54 }
55 
56 //____________________________________________________________________________..
58 {
59 
60  if(Verbosity() > 0)
61  std::cout << PHWHERE << " track map size " << _track_map->size() << std::endl;
62 
63  if(_n_iter <=1) _iteration_map->Reset();
64 
65  std::set<unsigned int> track_delete_list;
66 
67  unsigned int good_track = 0; // for diagnostic output only
68  unsigned int bad_track = 0; // tracks to keep
69 
70  // make a list of tracks that did not make the keep list
71  for(auto track_it = _track_map->begin(); track_it != _track_map->end(); ++track_it)
72  {
73  auto id = track_it->first;
74  _track = track_it->second;
75  bool delete_track = false;
76  double chi2_ndf = _track->get_chisq() / _track->get_ndf();
77  int ntpc = 0;
78  int nintt = 0;
79  int nmvtx = 0;
80 
82  iter != _track->end_cluster_keys();
83  ++iter){
84  TrkrDefs::cluskey cluster_key = *iter;
85  // unsigned int layer = TrkrDefs::getLayer(cluster_key);
86 
87  if(TrkrDefs::getTrkrId(cluster_key) == TrkrDefs::mvtxId ) nmvtx++;
88  if(TrkrDefs::getTrkrId(cluster_key) == TrkrDefs::inttId ) nintt++;
89  if(TrkrDefs::getTrkrId(cluster_key) == TrkrDefs::tpcId ) ntpc++;
90 
91  }
92 
93  if(chi2_ndf > max_chi2_ndf) delete_track = true;
94  if(ntpc < min_tpc_clusters) delete_track = true;
95  if(ntpc < min_tpc_clusters) delete_track = true;
96  if(nintt < min_intt_hits) delete_track = true;
97  if(nmvtx < min_mvtx_hits) delete_track = true;
98 
99  if(delete_track){
100  track_delete_list.insert(id);
101  bad_track++;
102  }
103  else{
104  //add clusters to cluster used list
106  iter != _track->end_cluster_keys();
107  ++iter){
108  TrkrDefs::cluskey cluster_key = *iter;
109  _iteration_map->addIteration(cluster_key,_n_iter);
110  }
111  good_track++;
112  }
113 
114  }
115  if(Verbosity() > 0)
116  std::cout << " Number of good tracks is " << good_track << " bad tracks " << bad_track << std::endl;
117 
118  // delete failed tracks
119  for(auto it = track_delete_list.begin(); it != track_delete_list.end(); ++it){
120  if(Verbosity() > 1)
121  std::cout << " erasing track ID " << *it << std::endl;
122  _track_map->erase(*it);
123  }
124 
125  if(Verbosity() > 0)
126  std::cout << " track_delete_list size " << track_delete_list.size() << std::endl;
127 
128  // delete failed tracks
129  for(auto it = track_delete_list.begin(); it != track_delete_list.end(); ++it)
130  {
131  if(Verbosity() > 1)
132  std::cout << " erasing track ID " << *it << std::endl;
133  _track_map->erase(*it);
134  }
135 
136  if(Verbosity() > 0)
137  std::cout << "Track map size after choosing best silicon match: " << _track_map->size() << std::endl;
138 
140 }
141 
143 {
145 }
146 
148 {
149  PHNodeIterator iter(topNode);
150  // Looking for the DST node
151  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
152  if (!dstNode)
153  {
154  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
156  }
157 
158  // TrackClusterIterationMapv1* _iteration_map;
159  _track_map = findNode::getClass<SvtxTrackMap>(topNode, _track_map_name);
160  if (!_track_map)
161  {
162  std::cout << PHWHERE << " ERROR: Can't find SvtxTrackMap: " << std::endl;
164  }
165 
166  // Create the Cluster Iteration Map node if required
167  _iteration_map= findNode::getClass<TrkrClusterIterationMapv1>(topNode, "CLUSTER_ITERATION_MAP");
168  if (!_iteration_map)
169  {
170  PHNodeIterator dstiter(dstNode);
171  PHCompositeNode *DetNode =
172  dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", "TRKR"));
173  if (!DetNode)
174  {
175  DetNode = new PHCompositeNode("TRKR");
176  dstNode->addNode(DetNode);
177  }
178 
181  new PHIODataNode<PHObject>(_iteration_map, "CLUSTER_ITERATION_MAP", "PHObject");
182  DetNode->addNode(TrkrClusterIterationMapv1);
183  }
184 
185 
186 
188 }