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