EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTrack_v2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTrack_v2.cc
1 #include "SvtxTrack_v2.h"
2 #include "SvtxTrackState.h"
3 #include "SvtxTrackState_v1.h"
4 
5 #include <trackbase/TrkrDefs.h> // for cluskey
6 
7 #include <phool/PHObject.h> // for PHObject
8 
9 #include <climits>
10 #include <map>
11 #include <vector> // for vector
12 
14 {
15  for(int i = 0; i < 6; i++)
16  for(int j = 0; j < 6; j++)
17  { _acts_trajectory_covariance[i][j] = NAN; }
18 
19  // always include the pca point
20  _states.insert( std::make_pair(0, new SvtxTrackState_v1(0)));
21 
22 }
23 
25 { SvtxTrack_v2::CopyFrom( source ); }
26 
27 // have to suppress uninitMenberVar from cppcheck since it triggers many false positive
28 // cppcheck-suppress uninitMemberVar
30 { SvtxTrack_v2::CopyFrom( source ); }
31 
33 { if( this != &source ) CopyFrom( source ); return *this; }
34 
36 { clear_states(); }
37 
38 void SvtxTrack_v2::CopyFrom( const SvtxTrack& source )
39 {
40  // do nothing if copying onto oneself
41  if( this == &source ) return;
42 
43  // parent class method
44  SvtxTrack::CopyFrom( source );
45 
46  // copy acts covariance
47  for( int i = 0; i<6; ++i )
48  for( int j = 0; j<6; ++j )
49  { set_acts_covariance( i, j, source.get_acts_covariance( i, j ) ); }
50 
51  _track_id = source.get_id();
52  _vertex_id = source.get_vertex_id();
54  _chisq = source.get_chisq();
55  _ndf = source.get_ndf();
56  _dca = source.get_dca();
57  _dca_error = source.get_dca_error();
58  _dca2d = source.get_dca2d();
59  _dca2d_error = source.get_dca2d_error();
60  _dca3d_xy = source.get_dca3d_xy();
62  _dca3d_z = source.get_dca3d_z();
64 
65  // copy the states over into new state objects stored here
66  clear_states();
67  for( auto iter = source.begin_states(); iter != source.end_states(); ++iter )
68  { _states.insert( std::make_pair(iter->first, static_cast<SvtxTrackState*>(iter->second->CloneMe() ) ) ); }
69 
70  // copy over cluster ID set
71  _cluster_ids.clear();
72  std::copy( source.begin_clusters(), source.end_clusters(), std::inserter( _cluster_ids, _cluster_ids.begin() ) );
73 
74  // copy over cluster key set
75  _cluster_keys.clear();
76  std::copy( source.begin_cluster_keys(), source.end_cluster_keys(), std::inserter( _cluster_keys, _cluster_keys.begin() ) );
77 
78  // copy over calorimeter projections
79  _cal_dphi.clear();
80  _cal_deta.clear();
81  _cal_energy_3x3.clear();
82  _cal_energy_5x5.clear();
83  _cal_cluster_id.clear();
84  _cal_cluster_key.clear();
85  _cal_cluster_e.clear();
86 
88  {
89  if(!std::isnan(source.get_cal_dphi(type))) set_cal_dphi(type, source.get_cal_dphi(type));
90  if(!std::isnan(source.get_cal_deta(type))) set_cal_deta(type, source.get_cal_deta(type));
91  if(!std::isnan(source.get_cal_energy_3x3(type))) set_cal_energy_3x3(type, source.get_cal_energy_3x3(type));
92  if(!std::isnan(source.get_cal_energy_5x5(type))) set_cal_energy_5x5(type, source.get_cal_energy_5x5(type));
93  if(source.get_cal_cluster_id(type) != UINT_MAX) set_cal_cluster_id(type, source.get_cal_cluster_id(type));
94  if(source.get_cal_cluster_key(type) != UINT_MAX) set_cal_cluster_key(type, source.get_cal_cluster_key(type));
95  if(!std::isnan(source.get_cal_cluster_e(type))) set_cal_cluster_e(type, source.get_cal_cluster_e(type));
96  }
97 
98 }
99 
100 void SvtxTrack_v2::identify(std::ostream& os) const
101 {
102  os << "SvtxTrack_v2 Object ";
103  os << "id: " << get_id() << " ";
104  os << "vertex id: " << get_vertex_id() << " ";
105  os << "charge: " << get_charge() << " ";
106  os << "chisq: " << get_chisq() << " ndf:" << get_ndf() << " ";
107  os << std::endl;
108 
109  os << "(px,py,pz) = ("
110  << get_px() << ","
111  << get_py() << ","
112  << get_pz() << ")" << std::endl;
113 
114  os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << std::endl;
115 
116  if ( _cluster_ids.size() > 0 || _cluster_keys.size() > 0 )
117  {
118  os << "list of cluster IDs ";
120  iter != end_clusters();
121  ++iter)
122  {
123  unsigned int cluster_id = *iter;
124  os << cluster_id << " ";
125  }
126 
127  os << "list of cluster keys ";
129  iter != end_cluster_keys();
130  ++iter)
131  {
132  TrkrDefs::cluskey cluster_key = *iter;
133  os << cluster_key << " ";
134  }
135  }
136  else
137  os << " track has no clusters " << std::endl;
138 
139  os << std::endl;
140 
141  return;
142 }
143 
145 {
146  for( const auto& pair:_states )
147  { delete pair.second; }
148 
149  _states.clear();
150 }
151 
153 {
154  return 1;
155 }
156 
157 const SvtxTrackState* SvtxTrack_v2::get_state(float pathlength) const
158 {
159  const auto iter = _states.find(pathlength);
160  return (iter == _states.end()) ? nullptr:iter->second;
161 }
162 
164 {
165  const auto iter = _states.find(pathlength);
166  return (iter == _states.end()) ? nullptr:iter->second;
167 }
168 
170 {
171  // find closest iterator
172  const auto pathlength = state->get_pathlength();
173  auto iterator = _states.lower_bound( pathlength );
174  if( iterator == _states.end() || pathlength < iterator->first )
175  {
176  // pathlength not found. Make a copy and insert
177  const auto copy = static_cast<SvtxTrackState*> (state->CloneMe());
178  iterator = _states.insert(iterator, std::make_pair( pathlength, copy ));
179  }
180 
181  // return matching state
182  return iterator->second;
183 }
184 
185 size_t SvtxTrack_v2::erase_state(float pathlength)
186 {
187  StateIter iter = _states.find(pathlength);
188  if (iter == _states.end()) return _states.size();
189 
190  delete iter->second;
191  _states.erase(iter);
192  return _states.size();
193 }
194 
196 {
197  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_dphi.find(layer);
198  if (citer == _cal_dphi.end()) return NAN;
199  return citer->second;
200 }
201 
203 {
204  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_deta.find(layer);
205  if (citer == _cal_deta.end()) return NAN;
206  return citer->second;
207 }
208 
210 {
211  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_3x3.find(layer);
212  if (citer == _cal_energy_3x3.end()) return NAN;
213  return citer->second;
214 }
215 
217 {
218  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_5x5.find(layer);
219  if (citer == _cal_energy_5x5.end()) return NAN;
220  return citer->second;
221 }
222 
224 {
225  std::map<SvtxTrack::CAL_LAYER, int>::const_iterator citer = _cal_cluster_id.find(layer);
226  if (citer == _cal_cluster_id.end()) return UINT_MAX;
227  return citer->second;
228 }
229 
231 {
232  std::map<SvtxTrack::CAL_LAYER, TrkrDefs::cluskey>::const_iterator citer = _cal_cluster_key.find(layer);
233  if (citer == _cal_cluster_key.end()) return UINT_MAX;
234  return citer->second;
235 }
236 
238 {
239  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_cluster_e.find(layer);
240  if (citer == _cal_cluster_e.end()) return NAN;
241  return citer->second;
242 }
243 
244