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