File indexing completed on 2026-08-31 08:21:35
0001 #include "SvtxTrack_v5.h"
0002 #include "SvtxTrackState.h"
0003 #include "SvtxTrackState_v1.h"
0004 #include "TrackSeed.h"
0005
0006 #include <trackbase/TrkrDefs.h>
0007
0008 #include <phool/PHObject.h>
0009
0010 #include <algorithm>
0011 #include <cmath>
0012 #include <limits>
0013 #include <map>
0014 #include <utility>
0015
0016 namespace
0017 {
0018 void count_cluster_key(TrkrDefs::cluskey key,
0019 unsigned int& nmvtx,
0020 unsigned int& nintt,
0021 unsigned int& ntpc,
0022 unsigned int& ntpot)
0023 {
0024 switch (TrkrDefs::getTrkrId(key))
0025 {
0026 case TrkrDefs::mvtxId:
0027 ++nmvtx;
0028 break;
0029 case TrkrDefs::inttId:
0030 ++nintt;
0031 break;
0032 case TrkrDefs::tpcId:
0033 ++ntpc;
0034 break;
0035 case TrkrDefs::micromegasId:
0036 ++ntpot;
0037 break;
0038 default:
0039 break;
0040 }
0041 }
0042
0043 void count_seed_clusters(const TrackSeed* seed,
0044 unsigned int& nmvtx,
0045 unsigned int& nintt,
0046 unsigned int& ntpc,
0047 unsigned int& ntpot)
0048 {
0049 if (!seed)
0050 {
0051 return;
0052 }
0053
0054 for (auto iter = seed->begin_cluster_keys(); iter != seed->end_cluster_keys(); ++iter)
0055 {
0056 count_cluster_key(*iter, nmvtx, nintt, ntpc, ntpot);
0057 }
0058 }
0059 }
0060
0061 SvtxTrack_v5::SvtxTrack_v5()
0062 {
0063
0064 _states.insert(std::make_pair(0, new SvtxTrackState_v1(0)));
0065 }
0066
0067 SvtxTrack_v5::SvtxTrack_v5(const SvtxTrack& source)
0068 {
0069 SvtxTrack_v5::CopyFrom(source);
0070 }
0071
0072
0073
0074
0075 SvtxTrack_v5::SvtxTrack_v5(const SvtxTrack_v5& source)
0076 : SvtxTrack(source)
0077 {
0078 SvtxTrack_v5::CopyFrom(source);
0079 }
0080
0081 SvtxTrack_v5& SvtxTrack_v5::operator=(const SvtxTrack_v5& source)
0082 {
0083 if (this != &source)
0084 {
0085 CopyFrom(source);
0086 }
0087 return *this;
0088 }
0089
0090 SvtxTrack_v5::~SvtxTrack_v5()
0091 {
0092 clear_states();
0093 }
0094
0095 void SvtxTrack_v5::CopyFrom(const SvtxTrack& source)
0096 {
0097
0098 if (this == &source)
0099 {
0100 return;
0101 }
0102
0103
0104 SvtxTrack::CopyFrom(source);
0105
0106 _track_id = source.get_id();
0107 _vertex_id = source.get_vertex_id();
0108 m_charge = static_cast<signed char>((source.get_charge() > 0) ? 1 : -1);
0109 _chisq = source.get_chisq();
0110 set_ndf(source.get_ndf());
0111 _track_crossing = source.get_crossing();
0112
0113 clear_states();
0114 for (auto iter = source.begin_states(); iter != source.end_states(); ++iter)
0115 {
0116 _states.insert(std::make_pair(iter->first, static_cast<SvtxTrackState*>(iter->second->CloneMe())));
0117 }
0118
0119 const auto* source_v5 = dynamic_cast<const SvtxTrack_v5*>(&source);
0120 if (source_v5)
0121 {
0122 set_nmvtx_clusters(source_v5->get_nmvtx_clusters());
0123 set_nintt_clusters(source_v5->get_nintt_clusters());
0124 set_ntpc_clusters(source_v5->get_ntpc_clusters());
0125 set_ntpot_clusters(source_v5->get_ntpot_clusters());
0126 return;
0127 }
0128
0129 unsigned int nmvtx = 0;
0130 unsigned int nintt = 0;
0131 unsigned int ntpc = 0;
0132 unsigned int ntpot = 0;
0133
0134 const auto begin_cluster_keys = source.begin_cluster_keys();
0135 const auto end_cluster_keys = source.end_cluster_keys();
0136 if (begin_cluster_keys != end_cluster_keys)
0137 {
0138 for (auto iter = begin_cluster_keys; iter != end_cluster_keys; ++iter)
0139 {
0140 count_cluster_key(*iter, nmvtx, nintt, ntpc, ntpot);
0141 }
0142 }
0143 else
0144 {
0145 count_seed_clusters(source.get_silicon_seed(), nmvtx, nintt, ntpc, ntpot);
0146 count_seed_clusters(source.get_tpc_seed(), nmvtx, nintt, ntpc, ntpot);
0147 }
0148
0149 set_nmvtx_clusters(nmvtx);
0150 set_nintt_clusters(nintt);
0151 set_ntpc_clusters(ntpc);
0152 set_ntpot_clusters(ntpot);
0153 }
0154
0155 void SvtxTrack_v5::identify(std::ostream& os) const
0156 {
0157 os << "SvtxTrack_v5 Object ";
0158 os << "id: " << get_id() << " ";
0159 os << "vertex id: " << get_vertex_id() << " ";
0160 os << "charge: " << get_charge() << " ";
0161 os << "chisq: " << get_chisq() << " ndf:" << get_ndf() << " ";
0162 os << "crossing: " << get_crossing() << " ";
0163 os << "clusters: MVTX " << get_nmvtx_clusters()
0164 << " INTT " << get_nintt_clusters()
0165 << " TPC " << get_ntpc_clusters()
0166 << " TPOT " << get_ntpot_clusters() << " ";
0167 os << "nstates: " << _states.size() << " ";
0168 os << std::endl;
0169
0170 os << "(px,py,pz) = ("
0171 << get_px() << ","
0172 << get_py() << ","
0173 << get_pz() << ")" << std::endl;
0174
0175 os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << std::endl;
0176 }
0177
0178 int SvtxTrack_v5::isValid() const
0179 {
0180 return 1;
0181 }
0182
0183 void SvtxTrack_v5::set_ndf(int ndf)
0184 {
0185 _ndf = static_cast<unsigned char>(std::max(0, std::min(ndf, static_cast<int>(std::numeric_limits<unsigned char>::max()))));
0186 }
0187
0188 float SvtxTrack_v5::get_x() const
0189 {
0190 const auto* state = get_pca_state();
0191 return state ? state->get_x() : NAN;
0192 }
0193
0194 void SvtxTrack_v5::set_x(float x)
0195 {
0196 get_pca_state()->set_x(x);
0197 }
0198
0199 float SvtxTrack_v5::get_y() const
0200 {
0201 const auto* state = get_pca_state();
0202 return state ? state->get_y() : NAN;
0203 }
0204
0205 void SvtxTrack_v5::set_y(float y)
0206 {
0207 get_pca_state()->set_y(y);
0208 }
0209
0210 float SvtxTrack_v5::get_z() const
0211 {
0212 const auto* state = get_pca_state();
0213 return state ? state->get_z() : NAN;
0214 }
0215
0216 void SvtxTrack_v5::set_z(float z)
0217 {
0218 get_pca_state()->set_z(z);
0219 }
0220
0221 float SvtxTrack_v5::get_pos(unsigned int i) const
0222 {
0223 const auto* state = get_pca_state();
0224 return state ? state->get_pos(i) : NAN;
0225 }
0226
0227 float SvtxTrack_v5::get_px() const
0228 {
0229 const auto* state = get_pca_state();
0230 return state ? state->get_px() : NAN;
0231 }
0232
0233 void SvtxTrack_v5::set_px(float px)
0234 {
0235 get_pca_state()->set_px(px);
0236 }
0237
0238 float SvtxTrack_v5::get_py() const
0239 {
0240 const auto* state = get_pca_state();
0241 return state ? state->get_py() : NAN;
0242 }
0243
0244 void SvtxTrack_v5::set_py(float py)
0245 {
0246 get_pca_state()->set_py(py);
0247 }
0248
0249 float SvtxTrack_v5::get_pz() const
0250 {
0251 const auto* state = get_pca_state();
0252 return state ? state->get_pz() : NAN;
0253 }
0254
0255 void SvtxTrack_v5::set_pz(float pz)
0256 {
0257 get_pca_state()->set_pz(pz);
0258 }
0259
0260 float SvtxTrack_v5::get_mom(unsigned int i) const
0261 {
0262 const auto* state = get_pca_state();
0263 return state ? state->get_mom(i) : NAN;
0264 }
0265
0266 float SvtxTrack_v5::get_error(int i, int j) const
0267 {
0268 const auto* state = get_pca_state();
0269 return state ? state->get_error(i, j) : NAN;
0270 }
0271
0272 void SvtxTrack_v5::set_error(int i, int j, float value)
0273 {
0274 get_pca_state()->set_error(i, j, value);
0275 }
0276
0277 void SvtxTrack_v5::clear_states()
0278 {
0279 for (const auto& pair : _states)
0280 {
0281 delete pair.second;
0282 }
0283
0284 _states.clear();
0285 }
0286
0287 const SvtxTrackState* SvtxTrack_v5::get_state(float pathlength) const
0288 {
0289 const auto iter = _states.find(pathlength);
0290 return (iter == _states.end()) ? nullptr : iter->second;
0291 }
0292
0293 SvtxTrackState* SvtxTrack_v5::get_state(float pathlength)
0294 {
0295 const auto iter = _states.find(pathlength);
0296 return (iter == _states.end()) ? nullptr : iter->second;
0297 }
0298
0299 SvtxTrackState* SvtxTrack_v5::insert_state(const SvtxTrackState* state)
0300 {
0301 if (!state)
0302 {
0303 return nullptr;
0304 }
0305
0306 const auto pathlength = state->get_pathlength();
0307 auto iterator = _states.lower_bound(pathlength);
0308 if (iterator == _states.end() || pathlength < iterator->first)
0309 {
0310 auto* const copy = static_cast<SvtxTrackState*>(state->CloneMe());
0311 iterator = _states.insert(iterator, std::make_pair(pathlength, copy));
0312 }
0313
0314 return iterator->second;
0315 }
0316
0317 size_t SvtxTrack_v5::erase_state(float pathlength)
0318 {
0319 StateIter iter = _states.find(pathlength);
0320 if (iter == _states.end())
0321 {
0322 return _states.size();
0323 }
0324
0325 delete iter->second;
0326 _states.erase(iter);
0327 return _states.size();
0328 }
0329
0330 unsigned char SvtxTrack_v5::compress_cluster_count(unsigned int nclusters)
0331 {
0332 return static_cast<unsigned char>(std::min(nclusters, static_cast<unsigned int>(std::numeric_limits<unsigned char>::max())));
0333 }
0334
0335 const SvtxTrackState* SvtxTrack_v5::get_pca_state() const
0336 {
0337 const auto iter = _states.find(0.0);
0338 return (iter == _states.end()) ? nullptr : iter->second;
0339 }
0340
0341 SvtxTrackState* SvtxTrack_v5::get_pca_state()
0342 {
0343 auto iter = _states.find(0.0);
0344 if (iter == _states.end())
0345 {
0346 iter = _states.insert(std::make_pair(0.0, new SvtxTrackState_v1(0.0))).first;
0347 }
0348
0349 return iter->second;
0350 }