ATLAS Offline Software
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 
16 namespace {
17 unsigned int
18 keepTSOS(const Trk::TrackStateOnSurface* tsos)
19 {
20  if (!tsos) {
21  return false;
22  }
23  std::bitset<Trk::TrackStateOnSurface::NumberOfPersistencyHints>
24  persHints = tsos->hints();
25  return (!persHints.test(Trk::TrackStateOnSurface::PartialPersistification) ||
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()) {
57  isMulti =
59  cnv) != nullptr);
60  }
61 
62  if (isMulti) {
63  std::unique_ptr<MultiComponentStateOnSurfaceDV> sink(
65  transObj->m_trackStateVector = std::move(sink);
66  } else {
67  std::unique_ptr<Trk::TrackStates> sink(
69  transObj->m_trackStateVector = std::move(sink);
70  }
71 }
72 
73 //-----------------------------------------------------------------------------
74 // Transient to persistent
75 //-----------------------------------------------------------------------------
76 void
77 TrackCnv_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  }
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  }
138  }
139  } else { // We need to persistify all TSOS
140  if (!isMulti) {
141  //Track with std TSOS
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
153  }
154 }
Trk::TrackInfo::NumberOfTrackRecoInfo
@ NumberOfTrackRecoInfo
Maximum number of enums.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:268
Trk::Track_p4::m_patternRecognition
unsigned int m_patternRecognition
Definition: Track_p4.h:27
Trk::TrackInfo::m_properties
std::bitset< NumberOfTrackProperties > m_properties
A bitset providing information on the properties of the track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:378
ITPConverterFor
Definition: TPConverter.h:37
Trk::Track::fitQuality
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
TrackCnv_p4::m_multiStateVectorCnv
MultiStateOSVectorCnv_p1 m_multiStateVectorCnv
Definition: TrackCnv_p4.h:54
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
Trk::Track_p4::m_numberDoF
float m_numberDoF
Definition: Track_p4.h:32
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
TPPolyCnvBase::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
Trk::TrackStateOnSurface::PersistifyTrackParameters
@ PersistifyTrackParameters
Mark track parameters for persisitification.
Definition: TrackStateOnSurface.h:167
Trk::Track::info
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
Trk::Track_p4::m_extPatternRecognition
unsigned int m_extPatternRecognition
overflow if bitset>32 bits
Definition: Track_p4.h:28
Trk::Track_p4::m_fitter
unsigned int m_fitter
Definition: Track_p4.h:24
TopLevelTPCnvBase::converterForRef
ITPConverter * converterForRef(const TPObjRef &ref) const
Find and return a TP converter for persistent type referenced by ref.
Definition: TopLevelTPCnvBase.h:89
Trk::Track_p4::m_trackState
std::vector< TPObjRef > m_trackState
Definition: Track_p4.h:34
Trk::Track_p4::m_properties
unsigned int m_properties
Definition: Track_p4.h:26
Trk::TrackStateOnSurface::PersistifyMeasurement
@ PersistifyMeasurement
Mark the measuremenet for persistification.
Definition: TrackStateOnSurface.h:162
Trk::Track_p4
Definition: Track_p4.h:19
TrackCnv_p4.h
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
TrackCnv_p4::persToTrans
virtual void persToTrans(const Trk::Track_p4 *, Trk::Track *, MsgStream &)
Definition: TrackCnv_p4.cxx:34
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
Trk::Track::m_fitQuality
std::unique_ptr< FitQuality > m_fitQuality
A pointer to the Track's FitQuality.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:293
Trk::Track_p4::m_particleHypo
unsigned int m_particleHypo
Definition: Track_p4.h:25
Track.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trk::TrackInfo::m_patternRecognition
std::bitset< NumberOfTrackRecoInfo > m_patternRecognition
A bitset providing information on the actual pattern recognition algotithm.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:384
Trk::TrackInfo::m_particleHypo
ParticleHypothesis m_particleHypo
This is an enum, which stores the particle hypothesis (if any) used for the track fitting.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:372
Trk::TrackInfo::TrackFitter
TrackFitter
enums to identify who created this track and what propertis does it have.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:39
TrackCnv_p4::transToPers
virtual void transToPers(const Trk::Track *, Trk::Track_p4 *, MsgStream &)
Definition: TrackCnv_p4.cxx:77
lumiFormat.i
int i
Definition: lumiFormat.py:92
Trk::Track::m_trackStateVector
std::unique_ptr< TrackStates > m_trackStateVector
TrackStateOnSurface.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:248
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
TrackCnv_p4::m_trackStateVectorCnv
TrackStateOSVectorCnv_p3 m_trackStateVectorCnv
Definition: TrackCnv_p4.h:47
TPPtrVectorCnv::transToPers
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
Definition: TPConverter.h:948
TrackCnv_p4::m_topCnv
AthenaPoolTopLevelTPCnvBase * m_topCnv
Definition: TrackCnv_p4.h:56
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::TrackInfo::m_fitter
TrackFitter m_fitter
This is an enum, which stores the identity of where the track was created.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:366
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
TrackInfo.h
Trk::Track_p4::m_chiSquared
float m_chiSquared
Definition: Track_p4.h:31
Trk::TrackInfo::dumpInfo
std::string dumpInfo() const
Returns a string with the name of the fitter of this track (i.e.
Definition: Tracking/TrkEvent/TrkTrack/src/TrackInfo.cxx:45
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Trk::MultiComponentStateOnSurface
Definition: MultiComponentStateOnSurface.h:42
Trk::TrackStateOnSurface::hints
const std::bitset< NumberOfPersistencyHints > hints() const
Use this method to get the persistification hints.
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
Trk::TrackStateOnSurface::MultiComponent
@ MultiComponent
Definition: TrackStateOnSurface.h:214
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ITPConverter
Definition: TPTools/TPTools/ITPConverter.h:32
Trk::TrackStateOnSurface::PartialPersistification
@ PartialPersistification
Definition: TrackStateOnSurface.h:158
TrackStateOnSurface.h