ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHTrackCleaner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHTrackCleaner.cc
1 #include "PHTrackCleaner.h"
2 
3 #include "PHTrackCleaner.h"
4 
6 
7 #include <trackbase/TrkrCluster.h> // for TrkrCluster
8 #include <trackbase/TrkrDefs.h> // for cluskey, getLayer, TrkrId
11 #include <trackbase_historic/SvtxTrack.h> // for SvtxTrack, SvtxTrack::C...
13 
15 
16 #include <phool/getClass.h>
17 #include <phool/phool.h>
18 
19 #include <cmath> // for sqrt, fabs, atan2, cos
20 #include <iostream> // for operator<<, basic_ostream
21 #include <map> // for map
22 #include <set> // for _Rb_tree_const_iterator
23 #include <utility> // for pair, make_pair
24 
25 //____________________________________________________________________________..
27  : SubsysReco(name)
28 {
29 
30 }
31 
32 //____________________________________________________________________________..
34 {
35 
36 }
37 
38 //____________________________________________________________________________..
40 {
41  int ret = GetNodes(topNode);
42  if (ret != Fun4AllReturnCodes::EVENT_OK) return ret;
43 
44  return ret;
45 }
46 
47 //____________________________________________________________________________..
49 {
50 
51  if(Verbosity() > 0)
52  std::cout << PHWHERE << " track map size " << _track_map->size()
53  << " _seed_track_map size " << _seed_track_map->size() << std::endl;
54 
55  std::set<unsigned int> track_keep_list;
56  std::set<unsigned int> track_delete_list;
57 
58  unsigned int good_track = 0; // for diagnostic output only
59  unsigned int ok_track = 0; // tracks to keep
60 
61  // loop over the TPC seed - track map and make a set containing all TPC seed ID's
62  std::set<unsigned int> seed_id_list;
63  auto map_range = _seed_track_map->getAll();
64  for(auto it = map_range.first; it != map_range.second; ++it)
65  {
66  seed_id_list.insert( (*it).first );
67  }
68 
69  if(Verbosity() > 0)
70  std::cout << " seed_id_list size " << seed_id_list.size() << std::endl;
71 
72  // loop over the TPC seed ID's
73 
74  for(auto seed_iter = seed_id_list.begin(); seed_iter != seed_id_list.end(); ++seed_iter)
75  {
76  unsigned int tpc_id = *seed_iter;
77 
78  if(Verbosity() > 1)
79  std::cout << " TPC ID " << tpc_id << std::endl;
80 
81  auto tpc_range = _seed_track_map->getAssocTracks(tpc_id);
82 
83  unsigned int best_id = 99999;
84  double min_chisq = 99999.0;
85  unsigned int best_ndf = 1;
86  for (auto it = tpc_range.first; it !=tpc_range.second; ++it)
87  {
88  unsigned int track_id = it->second;
89 
90  // note that the track no longer exists if it failed in the Acts fitter
91  _track = _track_map->get(track_id);
92  if(_track)
93  {
94  if(Verbosity() > 1)
95  std::cout << " track ID " << track_id << " chisq " << _track->get_chisq() << " ndf " << _track->get_ndf() << " min_chisq " << min_chisq << std::endl;
96 
97  // only accept tracks with nclus > min_clusters
98  if(_track->get_chisq() < min_chisq && _track->size_cluster_keys() > min_clusters)
99  {
100  min_chisq = _track->get_chisq();
101  best_id = track_id;
102  best_ndf = _track->get_ndf();
103  }
104  }
105  }
106 
107  if(best_id != 99999)
108  {
109  double qual = min_chisq / best_ndf;
110 
111  if(Verbosity() > 1)
112  std::cout << " best track for tpc_id " << tpc_id << " has track_id " << best_id << " chisq " << min_chisq << " chisq/ndf " << qual << std::endl;
113 
114  if(qual < 30)
115  {
116  track_keep_list.insert(best_id);
117  ok_track++;
118  if(qual < 10.0)
119  good_track++;
120  }
121  }
122  else
123  {
124  if(Verbosity() > 1)
125  std::cout << " no track exists for tpc_id " << tpc_id << std::endl;
126  }
127  }
128 
129  if(Verbosity() > 0)
130  std::cout << " Number of good tracks with qual < 10 is " << good_track << " OK tracks " << ok_track << std::endl;
131 
132  // make a list of tracks that did not make the keep list
133  for(auto track_it = _track_map->begin(); track_it != _track_map->end(); ++track_it)
134  {
135  auto id = track_it->first;
136 
137  auto set_it = track_keep_list.find(id);
138  if(set_it == track_keep_list.end())
139  {
140  if(Verbosity() > 1)
141  std::cout << " add id " << id << " to track_delete_list " << std::endl;
142  track_delete_list.insert(id);
143  }
144  }
145 
146  if(Verbosity() > 0)
147  std::cout << " track_delete_list size " << track_delete_list.size() << std::endl;
148 
149  // delete failed tracks
150  for(auto it = track_delete_list.begin(); it != track_delete_list.end(); ++it)
151  {
152  if(Verbosity() > 1)
153  std::cout << " erasing track ID " << *it << std::endl;
154  _track_map->erase(*it);
155  }
156 
157  if(Verbosity() > 0)
158  std::cout << "Track map size after choosing best silicon match: " << _track_map->size() << std::endl;
159 
161 }
162 
164 {
166 }
167 
169 {
170 
171  _track_map = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
172  if (!_track_map)
173  {
174  std::cout << PHWHERE << " ERROR: Can't find SvtxTrackMap: " << std::endl;
176  }
177 
178  _seed_track_map = findNode::getClass<TpcSeedTrackMap>(topNode, "TpcSeedTrackMap");
179  if (!_seed_track_map)
180  {
181  std::cout << PHWHERE << " ERROR: Can't find node TpcSeedTrackMap: " << std::endl;
183  }
184 
186 }