ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCnv_p4.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5//-----------------------------------------------------------------------------
6//
7// file: TrackCnv_p4.cxx
8//
9//-----------------------------------------------------------------------------
10#include "TrkTrack/Track.h"
11#include "TrkTrack/TrackInfo.h"
15
16namespace {
17unsigned int
18keepTSOS(const Trk::TrackStateOnSurface* tsos)
19{
20 if (!tsos) {
21 return false;
22 }
23 std::bitset<Trk::TrackStateOnSurface::NumberOfPersistencyHints>
24 persHints = tsos->hints();
28}
29}
30
31//-----------------------------------------------------------------------------
32// Persistent to transient
33//-----------------------------------------------------------------------------
35 Trk::Track *transObj,
36 MsgStream &log )
37{
38 using namespace Trk;
39 transObj->info().m_fitter = static_cast<Trk::TrackInfo::TrackFitter>(persObj->m_fitter);
40 transObj->info().m_particleHypo = static_cast<Trk::ParticleHypothesis>(persObj->m_particleHypo);
41
42 transObj->info().m_properties = std::bitset<Trk::TrackInfo::NumberOfTrackProperties>(persObj->m_properties);
43
44 // set first 32 bits
45 transObj->info().m_patternRecognition = std::bitset<Trk::TrackInfo::NumberOfTrackRecoInfo>(persObj->m_patternRecognition);
46 for (unsigned int i = 32;i<Trk::TrackInfo::NumberOfTrackRecoInfo;++i){
47 unsigned int mask = (1<<(i-32));
48 transObj->info().m_patternRecognition[i] = (persObj->m_extPatternRecognition & mask );
49 }
50
51 // Should always be a FQ so let's just go ahead and make it...
52 transObj->m_fitQuality = std::make_unique<FitQuality>(persObj->m_chiSquared, persObj->m_numberDoF);
53
54 bool isMulti = false;
55 if (!persObj->m_trackState.empty()) {
56 ITPConverter* cnv = m_topCnv->converterForRef(persObj->m_trackState[0]);
57 isMulti =
59 cnv) != nullptr);
60 }
61
62 if (isMulti) {
63 std::unique_ptr<MultiComponentStateOnSurfaceDV> sink(
64 m_multiStateVectorCnv.createTransient(&persObj->m_trackState, log));
65 transObj->m_trackStateVector = std::move(sink);
66 } else {
67 std::unique_ptr<Trk::TrackStates> sink(
68 m_trackStateVectorCnv.createTransient(&persObj->m_trackState, log));
69 transObj->m_trackStateVector = std::move(sink);
70 }
71}
72
73//-----------------------------------------------------------------------------
74// Transient to persistent
75//-----------------------------------------------------------------------------
76void
77TrackCnv_p4::transToPers(const Trk::Track* transObj, Trk::Track_p4* persObj, MsgStream& log)
78{
79
80 persObj->m_fitter = static_cast<unsigned int>(transObj->info().m_fitter);
81 persObj->m_particleHypo = static_cast<unsigned int>(transObj->info().m_particleHypo);
82 persObj->m_properties = transObj->info().m_properties.to_ulong();
83
84 if (transObj->info().m_patternRecognition.size()<32) {
85 persObj->m_patternRecognition = transObj->info().m_patternRecognition.to_ulong();
86 } else {
87 // more 32 bits so have to do it the hard way.
88 unsigned int i = 0;
89 unsigned int size = transObj->info().m_patternRecognition.size();
90 for (; i < 32; ++i) {
91 persObj->m_patternRecognition |= ((transObj->info().m_patternRecognition[i]) << i);
92 }
93 for (i = 32; i < size; ++i) {
94 persObj->m_extPatternRecognition |= ((transObj->info().m_patternRecognition[i]) << (i - 32));
95 }
96 }
97
98 assert(transObj->fitQuality());
99 if (transObj->m_fitQuality) {
100 persObj->m_chiSquared = transObj->m_fitQuality->chiSquared();
101 persObj->m_numberDoF = transObj->m_fitQuality->numberDoF();
102 } else {
103 log << MSG::WARNING << "No FitQuality on track at [" << transObj << "]"
104 << " with info=" << transObj->info().dumpInfo() << endmsg;
105 }
106
107 if (transObj->m_trackStateVector && ! transObj->m_trackStateVector->empty()) {
108 // Hints based slimming check if we need to persistify less TSOS
109 unsigned int n_elms = 0;
110 for (const Trk::TrackStateOnSurface* tsos : *(transObj->m_trackStateVector)) {
111 if (keepTSOS(tsos)) {
112 ++n_elms;
113 }
114 }
115 //Check if we have a Track with Multi TSOS
116 bool isMulti = (transObj->m_trackStateVector->at(0)->variety() == Trk::TrackStateOnSurface::MultiComponent);
117 if (n_elms != transObj->m_trackStateVector->size()) { //We need to persistify less TSOS
118 if (!isMulti) {
119 // Track std TSOS
121 tsosDV.reserve(n_elms);
122 for (const Trk::TrackStateOnSurface* tsos : *(transObj->m_trackStateVector)) {
123 if (keepTSOS(tsos)) {
124 tsosDV.push_back(tsos);
125 }
126 }
127 m_trackStateVectorCnv.transToPers(tsosDV.asDataVector(), &persObj->m_trackState, log);
128 } else {
129 // Track with Multi TSOS
131 multiDV.reserve(n_elms);
132 for (const Trk::TrackStateOnSurface* tsos : *(transObj->m_trackStateVector)) {
133 if (keepTSOS(tsos)) {
134 multiDV.push_back(static_cast<const Trk::MultiComponentStateOnSurface*>(tsos));
135 }
136 }
137 m_multiStateVectorCnv.transToPers(multiDV.asDataVector(), &persObj->m_trackState, log);
138 }
139 } else { // We need to persistify all TSOS
140 if (!isMulti) {
141 //Track with std TSOS
142 m_trackStateVectorCnv.transToPers(transObj->m_trackStateVector.get(), &persObj->m_trackState, log);
143 } else {
144 // Multi TSOS so we cast the container to the "right" type
145 const MultiComponentStateOnSurfaceDV* multiDV =
146 dynamic_cast<MultiComponentStateOnSurfaceDV*>(
147 transObj->m_trackStateVector.get());
148 m_multiStateVectorCnv.transToPers(multiDV, &persObj->m_trackState, log);
149 }
150 }
151 } else { // empty
152 m_trackStateVectorCnv.transToPers(transObj->m_trackStateVector.get(), &persObj->m_trackState, log);
153 }
154}
#define endmsg
DataVector adapter that acts like it holds const pointers.
DataVector< const Trk::MultiComponentStateOnSurface > MultiComponentStateOnSurfaceDV
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
Common base class for all TP converters, specialized for a given transient type.
Definition TPConverter.h:37
Base interface class for all TP converters - typeless.
MultiStateOSVectorCnv_p1 m_multiStateVectorCnv
Definition TrackCnv_p4.h:49
virtual void persToTrans(const Trk::Track_p4 *, Trk::Track *, MsgStream &)
TrackStateOSVectorCnv_p3 m_trackStateVectorCnv
Definition TrackCnv_p4.h:42
AthenaPoolTopLevelTPCnvBase * m_topCnv
Definition TrackCnv_p4.h:51
virtual void transToPers(const Trk::Track *, Trk::Track_p4 *, MsgStream &)
std::string dumpInfo() const
Returns a string with the name of the fitter of this track (i.e.
std::bitset< NumberOfTrackProperties > m_properties
A bitset providing information on the properties of the track.
TrackFitter
enums to identify who created this track and what propertis does it have.
std::bitset< NumberOfTrackRecoInfo > m_patternRecognition
A bitset providing information on the actual pattern recognition algotithm.
TrackFitter m_fitter
This is an enum, which stores the identity of where the track was created.
ParticleHypothesis m_particleHypo
This is an enum, which stores the particle hypothesis (if any) used for the track fitting.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const std::bitset< NumberOfPersistencyHints > hints() const
Use this method to get the persistification hints.
@ PersistifyMeasurement
Mark the measuremenet for persistification.
@ PersistifyTrackParameters
Mark track parameters for persisitification.
unsigned int m_particleHypo
Definition Track_p4.h:25
unsigned int m_properties
Definition Track_p4.h:26
float m_chiSquared
Definition Track_p4.h:31
unsigned int m_extPatternRecognition
overflow if bitset>32 bits
Definition Track_p4.h:28
unsigned int m_fitter
Definition Track_p4.h:24
unsigned int m_patternRecognition
Definition Track_p4.h:27
float m_numberDoF
Definition Track_p4.h:32
std::vector< TPObjRef > m_trackState
Definition Track_p4.h:34
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
std::unique_ptr< TrackStates > m_trackStateVector
TrackStateOnSurface.
std::unique_ptr< FitQuality > m_fitQuality
A pointer to the Track's FitQuality.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Ensure that the ATLAS eigen extensions are properly loaded.
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.