Analysis Software
Documentation for sPHENIX simulation 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 missingMemberCopy from cppcheck, it does not
28 // go down to the CopyFrom method where things are done correctly
29 // cppcheck-suppress missingMemberCopy
31 { SvtxTrack_v2::CopyFrom( source ); }
32 
34 { if( this != &source ) CopyFrom( source ); return *this; }
35 
37 { clear_states(); }
38 
40 {
41  // do nothing if copying onto oneself
42  if( this == &source ) return;
43 
44  // parent class method
45  SvtxTrack::CopyFrom( source );
46 
47  // copy acts covariance
48  for( int i = 0; i<6; ++i )
49  for( int j = 0; j<6; ++j )
50  { set_acts_covariance( i, j, source.get_acts_covariance( i, j ) ); }
51 
52  _track_id = source.get_id();
53  _vertex_id = source.get_vertex_id();
55  _chisq = source.get_chisq();
56  _ndf = source.get_ndf();
57  _dca = source.get_dca();
58  _dca_error = source.get_dca_error();
59  _dca2d = source.get_dca2d();
60  _dca2d_error = source.get_dca2d_error();
61  _dca3d_xy = source.get_dca3d_xy();
63  _dca3d_z = source.get_dca3d_z();
65 
66  // copy the states over into new state objects stored here
67  clear_states();
68  for( auto iter = source.begin_states(); iter != source.end_states(); ++iter )
69  { _states.insert( std::make_pair(iter->first, static_cast<SvtxTrackState*>(iter->second->CloneMe() ) ) ); }
70 
71  // copy over cluster ID set
72  _cluster_ids.clear();
73  std::copy( source.begin_clusters(), source.end_clusters(), std::inserter( _cluster_ids, _cluster_ids.begin() ) );
74 
75  // copy over cluster key set
76  _cluster_keys.clear();
77  std::copy( source.begin_cluster_keys(), source.end_cluster_keys(), std::inserter( _cluster_keys, _cluster_keys.begin() ) );
78 
79  // copy over calorimeter projections
80  _cal_dphi.clear();
81  _cal_deta.clear();
82  _cal_energy_3x3.clear();
83  _cal_energy_5x5.clear();
84  _cal_cluster_id.clear();
85  _cal_cluster_key.clear();
86  _cal_cluster_e.clear();
87 
89  {
90  if(!std::isnan(source.get_cal_dphi(type))) set_cal_dphi(type, source.get_cal_dphi(type));
91  if(!std::isnan(source.get_cal_deta(type))) set_cal_deta(type, source.get_cal_deta(type));
92  if(!std::isnan(source.get_cal_energy_3x3(type))) set_cal_energy_3x3(type, source.get_cal_energy_3x3(type));
93  if(!std::isnan(source.get_cal_energy_5x5(type))) set_cal_energy_5x5(type, source.get_cal_energy_5x5(type));
94  if(source.get_cal_cluster_id(type) != UINT_MAX) set_cal_cluster_id(type, source.get_cal_cluster_id(type));
95  if(source.get_cal_cluster_key(type) != UINT_MAX) set_cal_cluster_key(type, source.get_cal_cluster_key(type));
96  if(!std::isnan(source.get_cal_cluster_e(type))) set_cal_cluster_e(type, source.get_cal_cluster_e(type));
97  }
98 
99 }
100 
101 void SvtxTrack_v2::identify(std::ostream& os) const
102 {
103  os << "SvtxTrack_v2 Object ";
104  os << "id: " << get_id() << " ";
105  os << "vertex id: " << get_vertex_id() << " ";
106  os << "charge: " << get_charge() << " ";
107  os << "chisq: " << get_chisq() << " ndf:" << get_ndf() << " ";
108  os << std::endl;
109 
110  os << "(px,py,pz) = ("
111  << get_px() << ","
112  << get_py() << ","
113  << get_pz() << ")" << std::endl;
114 
115  os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << std::endl;
116 
117  if ( _cluster_ids.size() > 0 || _cluster_keys.size() > 0 )
118  {
119  os << "list of cluster IDs ";
121  iter != end_clusters();
122  ++iter)
123  {
124  unsigned int cluster_id = *iter;
125  os << cluster_id << " ";
126  }
127 
128  os << "list of cluster keys ";
130  iter != end_cluster_keys();
131  ++iter)
132  {
133  TrkrDefs::cluskey cluster_key = *iter;
134  os << cluster_key << " ";
135  }
136  }
137  else
138  os << " track has no clusters " << std::endl;
139 
140  os << std::endl;
141 
142  return;
143 }
144 
146 {
147  for( const auto& pair:_states )
148  { delete pair.second; }
149 
150  _states.clear();
151 }
152 
154 {
155  return 1;
156 }
157 
158 const SvtxTrackState* SvtxTrack_v2::get_state(float pathlength) const
159 {
160  const auto iter = _states.find(pathlength);
161  return (iter == _states.end()) ? nullptr:iter->second;
162 }
163 
165 {
166  const auto iter = _states.find(pathlength);
167  return (iter == _states.end()) ? nullptr:iter->second;
168 }
169 
171 {
172  // find closest iterator
173  const auto pathlength = state->get_pathlength();
174  auto iterator = _states.lower_bound( pathlength );
175  if( iterator == _states.end() || pathlength < iterator->first )
176  {
177  // pathlength not found. Make a copy and insert
178  const auto copy = static_cast<SvtxTrackState*> (state->CloneMe());
179  iterator = _states.insert(iterator, std::make_pair( pathlength, copy ));
180  }
181 
182  // return matching state
183  return iterator->second;
184 }
185 
186 size_t SvtxTrack_v2::erase_state(float pathlength)
187 {
188  StateIter iter = _states.find(pathlength);
189  if (iter == _states.end()) return _states.size();
190 
191  delete iter->second;
192  _states.erase(iter);
193  return _states.size();
194 }
195 
197 {
198  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_dphi.find(layer);
199  if (citer == _cal_dphi.end()) return NAN;
200  return citer->second;
201 }
202 
204 {
205  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_deta.find(layer);
206  if (citer == _cal_deta.end()) return NAN;
207  return citer->second;
208 }
209 
211 {
212  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_3x3.find(layer);
213  if (citer == _cal_energy_3x3.end()) return NAN;
214  return citer->second;
215 }
216 
218 {
219  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_5x5.find(layer);
220  if (citer == _cal_energy_5x5.end()) return NAN;
221  return citer->second;
222 }
223 
225 {
226  std::map<SvtxTrack::CAL_LAYER, int>::const_iterator citer = _cal_cluster_id.find(layer);
227  if (citer == _cal_cluster_id.end()) return UINT_MAX;
228  return citer->second;
229 }
230 
232 {
233  std::map<SvtxTrack::CAL_LAYER, TrkrDefs::cluskey>::const_iterator citer = _cal_cluster_key.find(layer);
234  if (citer == _cal_cluster_key.end()) return UINT_MAX;
235  return citer->second;
236 }
237 
239 {
240  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_cluster_e.find(layer);
241  if (citer == _cal_cluster_e.end()) return NAN;
242  return citer->second;
243 }
244 
245