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