Analysis Software
Documentation for sPHENIX simulation 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
10 #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() << std::endl;
53 
54  std::set<unsigned int> track_keep_list;
55  std::set<unsigned int> track_delete_list;
56 
57  unsigned int good_track = 0; // for diagnostic output only
58  unsigned int ok_track = 0; // tracks to keep
59 
60  std::multimap<unsigned int, unsigned int> tpcid_track_mmap;
61  std::set<unsigned int> tpc_id_set;
62  // loop over the fitted tracks
63  for (auto it = _track_map->begin(); it != _track_map->end(); ++it)
64  {
65  auto track_id = (*it).first;
66  auto track = (*it).second;
67  if(!track) continue;
68 
69  auto tpc_seed = track->get_tpc_seed();
70  unsigned int tpc_index = _tpc_seed_map->find(tpc_seed);
71 
72  auto tpc_track_pair = std::make_pair(tpc_index, track_id);
73 
74  tpc_id_set.insert(tpc_index);
75  tpcid_track_mmap.insert(tpc_track_pair);
76  }
77 
78  if(Verbosity() > 0)
79  std::cout << " tpcid_track_mmap size " << tpcid_track_mmap.size() << std::endl;
80 
81  // loop over the TPC seed ID's
82 
83  for(auto seed_iter = tpc_id_set.begin(); seed_iter != tpc_id_set.end(); ++seed_iter)
84  {
85  unsigned int tpc_id = *seed_iter;
86 
87  if(Verbosity() > 1)
88  std::cout << " TPC ID " << tpc_id << std::endl;
89 
90  auto tpc_range = tpcid_track_mmap.equal_range(tpc_id);
91 
92  unsigned int best_id = 99999;
93  double min_chisq_df = 99999.0;
94  unsigned int best_ndf = 1;
95  for (auto it = tpc_range.first; it !=tpc_range.second; ++it)
96  {
97  unsigned int track_id = it->second;
98 
99  // note that the track no longer exists if it failed in the Acts fitter
100  _track = _track_map->get(track_id);
101 
102  if(_track)
103  {
104  if(_pp_mode)
105  {
106  // skip tracks with no assigned crossing number in pp mode
107  if(_track->get_crossing() == SHRT_MAX)
108  {
109  if(Verbosity() > 0)
110  std::cout << " skip track ID " << track_id << " crossing " << _track->get_crossing() << " chisq " << _track->get_chisq()
111  << " ndf " << _track->get_ndf() << std::endl;
112 
113  continue;
114  }
115  }
116 
117  //Find the remaining track with the best chisq/ndf
118 
119  if(Verbosity() > 1)
120  std::cout << " track ID " << track_id << " crossing " << _track->get_crossing()
121  << " chisq " << _track->get_chisq() << " ndf " << _track->get_ndf() << " min_chisq_df " << min_chisq_df << std::endl;
122 
123  // only accept tracks with ndf > min_ndf - very small ndf means something went wrong, as does ndf undefined
124  if(_track->get_chisq()/_track->get_ndf() < min_chisq_df && _track->get_ndf() > min_ndf && _track->get_ndf() != UINT_MAX)
125  {
126  min_chisq_df = _track->get_chisq() / _track->get_ndf();
127  best_id = track_id;
128  best_ndf = _track->get_ndf();
129  }
130  }
131  }
132 
133  if(best_id != 99999)
134  {
135  double qual = min_chisq_df;
136 
137  if(Verbosity() > 1)
138  std::cout << " best track for tpc_id " << tpc_id << " has track_id " << best_id << " best_ndf " << best_ndf << " chisq/ndf " << qual << std::endl;
139 
140  if(qual < 30)
141  {
142  track_keep_list.insert(best_id);
143  ok_track++;
144  if(qual < 10.0)
145  good_track++;
146  }
147  }
148  else
149  {
150  if(Verbosity() > 1)
151  std::cout << " no track exists for tpc_id " << tpc_id << std::endl;
152  }
153  }
154 
155  if(Verbosity() > 0)
156  std::cout << " Number of good tracks with qual < 10 is " << good_track << " OK tracks " << ok_track << std::endl;
157 
158  // make a list of tracks that did not make the keep list
159  for(auto track_it = _track_map->begin(); track_it != _track_map->end(); ++track_it)
160  {
161  auto id = track_it->first;
162 
163  auto set_it = track_keep_list.find(id);
164  if(set_it == track_keep_list.end())
165  {
166  if(Verbosity() > 1)
167  std::cout << " add id " << id << " to track_delete_list " << std::endl;
168  track_delete_list.insert(id);
169  }
170  }
171 
172  if(Verbosity() > 0)
173  std::cout << " track_delete_list size " << track_delete_list.size() << std::endl;
174 
175  // delete failed tracks
176  for(auto it = track_delete_list.begin(); it != track_delete_list.end(); ++it)
177  {
178  if(Verbosity() > 1)
179  std::cout << " erasing track ID " << *it << std::endl;
180  _track_map->erase(*it);
181  }
182 
183  if(Verbosity() > 0)
184  std::cout << "Track map size after choosing best silicon match: " << _track_map->size() << std::endl;
185 
187 }
188 
190 {
192 }
193 
195 {
196  _tpc_seed_map = findNode::getClass<TrackSeedContainer>(topNode, "TpcTrackSeedContainer");
197  if (!_tpc_seed_map)
198  {
199  std::cout << PHWHERE << " ERROR: Can't find TpcTrackSeedContainer: " << std::endl;
201  }
202 
203  _track_map = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
204  if (!_track_map)
205  {
206  std::cout << PHWHERE << " ERROR: Can't find SvtxTrackMap: " << std::endl;
208  }
209 
211 }