Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTrack_v3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTrack_v3.cc
1 #include "SvtxTrack_v3.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_v3::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_v3::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  _track_crossing = source.get_crossing();
58  _dca = source.get_dca();
59  _dca_error = source.get_dca_error();
60  _dca2d = source.get_dca2d();
61  _dca2d_error = source.get_dca2d_error();
62  _dca3d_xy = source.get_dca3d_xy();
64  _dca3d_z = source.get_dca3d_z();
66 
67  // copy the states over into new state objects stored here
68  clear_states();
69  for( auto iter = source.begin_states(); iter != source.end_states(); ++iter )
70  { _states.insert( std::make_pair(iter->first, static_cast<SvtxTrackState*>(iter->second->CloneMe() ) ) ); }
71 
72  // copy over cluster ID set
73  _cluster_ids.clear();
74  std::copy( source.begin_clusters(), source.end_clusters(), std::inserter( _cluster_ids, _cluster_ids.begin() ) );
75 
76  // copy over cluster key set
77  _cluster_keys.clear();
78  std::copy( source.begin_cluster_keys(), source.end_cluster_keys(), std::inserter( _cluster_keys, _cluster_keys.begin() ) );
79 
80  // copy over calorimeter projections
81  _cal_dphi.clear();
82  _cal_deta.clear();
83  _cal_energy_3x3.clear();
84  _cal_energy_5x5.clear();
85  _cal_cluster_id.clear();
86  _cal_cluster_key.clear();
87  _cal_cluster_e.clear();
88 
90  {
91  if(!std::isnan(source.get_cal_dphi(type))) set_cal_dphi(type, source.get_cal_dphi(type));
92  if(!std::isnan(source.get_cal_deta(type))) set_cal_deta(type, source.get_cal_deta(type));
93  if(!std::isnan(source.get_cal_energy_3x3(type))) set_cal_energy_3x3(type, source.get_cal_energy_3x3(type));
94  if(!std::isnan(source.get_cal_energy_5x5(type))) set_cal_energy_5x5(type, source.get_cal_energy_5x5(type));
95  if(source.get_cal_cluster_id(type) != UINT_MAX) set_cal_cluster_id(type, source.get_cal_cluster_id(type));
96  if(source.get_cal_cluster_key(type) != UINT_MAX) set_cal_cluster_key(type, source.get_cal_cluster_key(type));
97  if(!std::isnan(source.get_cal_cluster_e(type))) set_cal_cluster_e(type, source.get_cal_cluster_e(type));
98  }
99 
100 }
101 
102 void SvtxTrack_v3::identify(std::ostream& os) const
103 {
104  os << "SvtxTrack_v3 Object ";
105  os << "id: " << get_id() << " ";
106  os << "vertex id: " << get_vertex_id() << " ";
107  os << "charge: " << get_charge() << " ";
108  os << "chisq: " << get_chisq() << " ndf:" << get_ndf() << " ";
109  os << std::endl;
110 
111  os << "(px,py,pz) = ("
112  << get_px() << ","
113  << get_py() << ","
114  << get_pz() << ")" << std::endl;
115 
116  os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << std::endl;
117 
118  if ( _cluster_ids.size() > 0 || _cluster_keys.size() > 0 )
119  {
120  os << "list of cluster IDs ";
122  iter != end_clusters();
123  ++iter)
124  {
125  unsigned int cluster_id = *iter;
126  os << cluster_id << " ";
127  }
128 
129  os << "list of cluster keys ";
131  iter != end_cluster_keys();
132  ++iter)
133  {
134  TrkrDefs::cluskey cluster_key = *iter;
135  os << cluster_key << " ";
136  }
137  }
138  else
139  os << " track has no clusters " << std::endl;
140 
141  os << std::endl;
142 
143  return;
144 }
145 
147 {
148  for( const auto& pair:_states )
149  { delete pair.second; }
150 
151  _states.clear();
152 }
153 
155 {
156  return 1;
157 }
158 
159 const SvtxTrackState* SvtxTrack_v3::get_state(float pathlength) const
160 {
161  const auto iter = _states.find(pathlength);
162  return (iter == _states.end()) ? nullptr:iter->second;
163 }
164 
166 {
167  const auto iter = _states.find(pathlength);
168  return (iter == _states.end()) ? nullptr:iter->second;
169 }
170 
172 {
173  // find closest iterator
174  const auto pathlength = state->get_pathlength();
175  auto iterator = _states.lower_bound( pathlength );
176  if( iterator == _states.end() || pathlength < iterator->first )
177  {
178  // pathlength not found. Make a copy and insert
179  const auto copy = static_cast<SvtxTrackState*> (state->CloneMe());
180  iterator = _states.insert(iterator, std::make_pair( pathlength, copy ));
181  }
182 
183  // return matching state
184  return iterator->second;
185 }
186 
187 size_t SvtxTrack_v3::erase_state(float pathlength)
188 {
189  StateIter iter = _states.find(pathlength);
190  if (iter == _states.end()) return _states.size();
191 
192  delete iter->second;
193  _states.erase(iter);
194  return _states.size();
195 }
196 
198 {
199  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_dphi.find(layer);
200  if (citer == _cal_dphi.end()) return NAN;
201  return citer->second;
202 }
203 
205 {
206  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_deta.find(layer);
207  if (citer == _cal_deta.end()) return NAN;
208  return citer->second;
209 }
210 
212 {
213  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_3x3.find(layer);
214  if (citer == _cal_energy_3x3.end()) return NAN;
215  return citer->second;
216 }
217 
219 {
220  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_energy_5x5.find(layer);
221  if (citer == _cal_energy_5x5.end()) return NAN;
222  return citer->second;
223 }
224 
226 {
227  std::map<SvtxTrack::CAL_LAYER, int>::const_iterator citer = _cal_cluster_id.find(layer);
228  if (citer == _cal_cluster_id.end()) return UINT_MAX;
229  return citer->second;
230 }
231 
233 {
234  std::map<SvtxTrack::CAL_LAYER, TrkrDefs::cluskey>::const_iterator citer = _cal_cluster_key.find(layer);
235  if (citer == _cal_cluster_key.end()) return UINT_MAX;
236  return citer->second;
237 }
238 
240 {
241  std::map<SvtxTrack::CAL_LAYER, float>::const_iterator citer = _cal_cluster_e.find(layer);
242  if (citer == _cal_cluster_e.end()) return NAN;
243  return citer->second;
244 }
245 
246