ATLAS Offline Software
TrackParametersCnv_p2.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: TrackParametersCnv_p2.h
8 // author: edward.moyse@cern.ch
9 //
10 //-----------------------------------------------------------------------------
11 
15 #include "TrkSurfaces/Surface.h"
23 
28 
29 #include <cassert>
30 #include <iostream>
31 
33  const Trk ::TrackParameters_p2* ,
34  Trk ::TrackParameters* , MsgStream& ) {
35  throw std::runtime_error(
36  "TrackParametersCnv_p2::persToTrans shouldn't be called any more!");
37 }
38 
40  const Trk::TrackParameters_p2* persObj, MsgStream& log) {
41  // ---- Covariance matrix
42  std::optional<AmgSymMatrix(5)> cov = std::nullopt;
43  auto transcov =
44  std::unique_ptr<AmgSymMatrix(5)>(transErrorMatrix(persObj, log));
45  if (transcov) {
46  cov = (*transcov);
47  }
48  // ---- Parameters
49  Trk::TrackParameters *transObj=nullptr;
50  unsigned int size=persObj->m_parameters.size();
51  if (size==7){ // size 7 means we chose to write
52  // as a Curvillinear representation
53  // In principle we could check
54  // the persObject for Trk::SurfaceType::Curvilinear
56  for (unsigned int i=0; i<size; ++i) parameters[i]=persObj->m_parameters[i];
58  return transObj;
59  } else {
60  // Not a curvilinear representation.
61  // We need to have a surface to handle local->global transformations etc/
62  // Get surface type
63  Trk::SurfaceType type = static_cast<Trk::SurfaceType>(persObj->m_surfaceType);
64  // Get surface & fill parameter vector
65  const Trk::Surface* surface = transSurface(persObj, type, log);
67  for (unsigned int i = 0; i < size; ++i){
68  parameters[i] = persObj->m_parameters[i];
69  }
70  // Now create concrete parameters ...
71  if (surface){
73  transObj = new Trk::Perigee(
74  parameters, static_cast<const Trk::PerigeeSurface*>(surface), cov);
75  return transObj;
76  } else if (type == Trk::SurfaceType::Plane) {
77  transObj = new Trk::AtaPlane(
78  parameters, static_cast<const Trk::PlaneSurface*>(surface), cov);
79  return transObj;
80  } else if (type == Trk::SurfaceType::Line) {
81  transObj = new Trk::AtaStraightLine(
82  parameters,
83  static_cast<const Trk::StraightLineSurface*>(surface),
84  cov);
85  return transObj;
86  }
87  } else if (!m_nosurf) {
88  // FIXME: next line changed to DEBUG to avoid filling the derivation job
89  // options with garbage. Underlying issue should be fixed.
90  log << MSG::DEBUG << "No surface of type=" << static_cast<int>(type)
91  << " created - so these parameters cannot be made!" << endmsg;
92  return nullptr;
93  }
94  }
95  return nullptr;
96 }
97 
98 AmgSymMatrix(5)* TrackParametersCnv_p2::transErrorMatrix(const Trk :: TrackParameters_p2 *persObj,MsgStream& log){
99  AmgSymMatrix(5)* cov=nullptr;
100  if (!persObj->m_errorMatrix.isNull()){
101  // fill errormatrix
102  cov = new AmgSymMatrix(5);
104  fillTransFromPStore( &m_emConverter, persObj->m_errorMatrix, &dummy, log );
105  Amg::expand(dummy.values.begin(), dummy.values.end(), *cov);
106  }
107  return cov;
108 }
109 
110 const Trk::Surface*
111 TrackParametersCnv_p2::transSurface(const Trk ::TrackParameters_p2* persObj,
113  MsgStream& log)
114 {
115  const Trk::Surface* surface = nullptr;
116  // check if surface had transform.
117  if (!persObj->m_transform.empty()){
118  auto transform = std::make_unique<Amg::Transform3D>();
119  EigenHelpers::vectorToEigenTransform3D( persObj->m_transform, *transform.get());
120  // recreate free surface
122  surface = new Trk::PerigeeSurface(*transform);
123  } else if (type==Trk::SurfaceType::Plane){
124  surface = new Trk::PlaneSurface(*transform);
125  } else if (type==Trk::SurfaceType::Line){
126  surface = new Trk::StraightLineSurface(*transform);
127  }
128  if (!surface){
129  log << MSG::WARNING << "Free surface of type=" << static_cast<int>(type)
130  << " isn't currently supported in TrackParametersCnv_p2" << endmsg;
131  return nullptr;
132  }
133  } else {
134  // Surface must have belonged to a ReadoutElement, or some part of the geometry or have a nominal/default perigee surface.
136  Identifier id=Identifier32(persObj->m_associatedDetElementId);
137  if (!id.get_compact() && persObj->m_associatedDetElementId != 0)
138  id = Identifier(persObj->m_associatedDetElementId);
139  if (m_nosurf)surface = nullptr;
140  else {
141  const Trk::Surface* detSurf = m_eventCnvTool->getSurface(id);
142  if (!detSurf){
143  log << MSG::WARNING << "Surface of type=" << static_cast<int>(type)
144  << " was not found by the eventCnvTool." << endmsg;
145  }
146  surface = detSurf;
147  }
148  } else {
149  surface = new Trk::PerigeeSurface(); // FIXME! How do we support nominal Perigee Surfaces now?
150  }
151  }
152  return surface;
153 }
154 
156  Trk ::TrackParameters_p2* persObj,
157  MsgStream& log) {
158 
159  bool isCurvilinear = (transObj->type() == Trk::Curvilinear);
160  bool deleteAtEnd = false;
161  if (isCurvilinear){
162  convertTransCurvilinearToPers(transObj,persObj);
163  // Not bothering with Surface here - not relevant for curvilinear
164  } else {
165  // normal track parameters - check if the type is 'permitted' to be written.
166  if (isPersistifiableType(transObj)) {
167  unsigned int nRows = transObj->parameters().rows();
168  persObj->m_parameters.resize( nRows);
169  for( unsigned int i = 0; i < nRows; i++ ){
170  persObj->m_parameters[i] = transObj->parameters()[i];
171  }
172  fillPersSurface(transObj, persObj, log);
173  } else { // if not, convert to curvilinear
174  std::optional<AmgSymMatrix(5)> newcov = std::nullopt;
175  if (transObj->covariance()) {
176  newcov = *(transObj->covariance());
177  }
178  const Trk::CurvilinearParameters* curvilinear =
179  new Trk::CurvilinearParameters(transObj->position(),
180  transObj->momentum(),
181  transObj->charge(), newcov);
182  transObj = curvilinear;
183  deleteAtEnd = true; // Because the curvilinear will leak otherwise
184  convertTransCurvilinearToPers(transObj, persObj);
185  }
186  }
187 
188  // Errormatrix
189  if (transObj->covariance()){
190  Trk::ErrorMatrix pMat;
191  EigenHelpers::eigenMatrixToVector(pMat.values, *transObj->covariance(), "TrackParametersCnv_p2");
192  persObj->m_errorMatrix = toPersistent( &m_emConverter, &pMat, log );
193  }
194 
195  if (deleteAtEnd) {
196  delete transObj;
197  }
198 }
199 
201  const Trk ::TrackParameters* transObj, Trk ::TrackParameters_p2* persObj) {
202  // Curvilinear: here we store the 3 position + 3 momentum, rather than the 5
203  // parameters.
204  // This avoids writing the surface
205  persObj->m_parameters.resize(7);
206  for (unsigned int i = 0; i < 3; ++i) {
207  persObj->m_parameters[i] = transObj->position()[i];
208  persObj->m_parameters[i + 3] = transObj->momentum()[i];
209  }
210  persObj->m_parameters[6] = transObj->charge();
211  // And lets remember to always set the type of the surface
212  persObj->m_surfaceType = static_cast<uint8_t>(Trk::SurfaceType::Curvilinear);
213 }
214 
216  const Trk::Surface* surf = transObj->associatedSurface ().baseSurface();
217  assert (surf);
218  Trk::SurfaceType type = surf->type();
220 }
221 
222 void TrackParametersCnv_p2::fillPersSurface(const Trk :: TrackParameters *transObj, Trk :: TrackParameters_p2 *persObj, MsgStream& /*log*/){
223  //----- Surface
224  const Trk::Surface* surf = transObj->associatedSurface ().baseSurface();
225  assert (surf);
226  persObj->m_surfaceType = static_cast<uint8_t>(surf->type()); // Store type
227 
228  persObj->m_associatedDetElementId = surf->associatedDetectorElementIdentifier().get_identifier32().get_compact();
229  static const Trk::PerigeeSurface s_nominalPerigeeSurface; // FIXME - should there be a common 'nominal' surface ie on Perigee, as before?
230  // Need to write out transforms for TG owned surfaces, and 'free' (noOwn) surfaces - i.e. anything which isn't on det element
231  if( surf->cachedTransform()!=nullptr ) {
232  // FIXME - I think maybe we can just remove all of the code below and ALWAYS write out the transform if it exists - i.e. it won't exist if the surface is 'nominal'
233  if (surf->type() != Trk::SurfaceType::Perigee ||
234  (surf->type() == Trk::SurfaceType::Perigee &&
235  *surf != s_nominalPerigeeSurface)) {
237  persObj->m_transform);
238  }
239  }
240 }
241 
242 
Identifier32
Definition: Identifier32.h:25
CLHEPHelpers.h
StraightLineSurface.h
TrackParameters.h
PerigeeSurface.h
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
Surface.h
TrackParametersCnv_p2.h
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::TrackParameters_p2
Definition: TrackParameters_p2.h:20
Trk::CurvilinearParameters
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:29
EventPrimitivesHelpers.h
Trk::Surface::associatedDetectorElementIdentifier
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
TrackParametersCnv_p2::m_emConverter
ErrorMatrixCnv_p1 * m_emConverter
Definition: TrackParametersCnv_p2.h:64
Trk::SurfaceType
SurfaceType
Definition: SurfaceTypes.h:17
TrackParametersCnv_p2::fillPersSurface
static void fillPersSurface(const Trk ::TrackParameters *transObj, Trk ::TrackParameters_p2 *persObj, MsgStream &log)
Definition: TrackParametersCnv_p2.cxx:222
Trk::Curvilinear
@ Curvilinear
Definition: ParametersCommon.h:29
EigenHelpers::eigenTransform3DToVector
static void eigenTransform3DToVector(const Amg::Transform3D &trans, T &vec)
Convert HepGeom::Transform3D to std :: vector<double>
Definition: EigenHelpers.h:55
Trk::TrackParameters_p2::m_parameters
std::vector< float > m_parameters
Definition: TrackParameters_p2.h:27
TrackParametersCnv_p2::transToPers
void transToPers(const Trk::TrackParameters *transObj, Trk::TrackParameters_p2 *persObj, MsgStream &log)
Definition: TrackParametersCnv_p2.cxx:155
Trk::Perigee
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:33
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
ITPConverterFor< TRANS_BASE >::fillTransFromPStore
void fillTransFromPStore(CNV **cnv, const TPObjRef &ref, TRANS_T *trans, MsgStream &log) const
Convert persistent object, stored in the the top-level persistent object and referenced by the TP Ref...
Definition: TPConverter.h:145
Amg::expand
void expand(std::vector< float >::const_iterator it, std::vector< float >::const_iterator, AmgSymMatrix(N) &covMatrix)
Definition: EventPrimitivesHelpers.h:75
xAOD::TrackParameters
TrackParameters_v1 TrackParameters
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParameters.h:11
Trk::Surface::baseSurface
virtual const Trk::Surface * baseSurface() const
return the base surface (simplified for persistification)
Trk::ErrorMatrix
Definition: ErrorMatrixCnv_p1.h:25
Trk::AtaStraightLine
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:35
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ConeSurface.h
CurvilinearParametersT.h
TrackParametersCnv_p2::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: TrackParametersCnv_p2.h:65
Trk::Surface::cachedTransform
const Amg::Transform3D * cachedTransform() const
Return the cached transformation directly.
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
ParametersT.h
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CylinderSurface.h
EigenHelpers.h
python.xAODType.dummy
dummy
Definition: xAODType.py:4
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::CurvilinearParametersT
Definition: CurvilinearParametersT.h:48
Trk::TrackParameters_p2::m_surfaceType
uint8_t m_surfaceType
Used to recreate the correct TrackParameters.
Definition: TrackParameters_p2.h:29
EigenHelpers::eigenMatrixToVector
static void eigenMatrixToVector(VECTOR &vec, COVARIANCE &cov, const char *)
Helper fn to get raw data (vec<float>) from the covariance.
Definition: EigenHelpers.h:30
EigenHelpers::vectorToEigenTransform3D
static void vectorToEigenTransform3D(const T &vec, Amg::Transform3D &trans)
Convert std :: vector<double> to Amg::Transform3D.
Definition: EigenHelpers.h:36
TrackParametersCnv_p2::m_nosurf
bool m_nosurf
Definition: TrackParametersCnv_p2.h:66
ITPConverterFor< TRANS_BASE >::toPersistent
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
Persistify an object and store the persistent represenation in the storage vector of the top-level pe...
Definition: TPConverter.h:119
TrackParametersCnv_p2::isPersistifiableType
static bool isPersistifiableType(const Trk ::TrackParameters *transObj)
Definition: TrackParametersCnv_p2.cxx:215
Trk::SurfaceType::Perigee
@ Perigee
TrackParametersCnv_p2::persToTrans
void persToTrans(const Trk ::TrackParameters_p2 *persObj, Trk ::TrackParameters *transObj, MsgStream &log)
Definition: TrackParametersCnv_p2.cxx:32
xAOD::Curvilinear
@ Curvilinear
Definition: TrackingPrimitives.h:558
TrackParametersCnv_p2::convertTransCurvilinearToPers
static void convertTransCurvilinearToPers(const Trk ::TrackParameters *transObj, Trk ::TrackParameters_p2 *persObj)
Definition: TrackParametersCnv_p2.cxx:200
Trk::ErrorMatrix::values
std::vector< float > values
Definition: ErrorMatrixCnv_p1.h:27
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AmgSymMatrix
AmgSymMatrix(5) *TrackParametersCnv_p2
Definition: TrackParametersCnv_p2.cxx:98
DEBUG
#define DEBUG
Definition: page_access.h:11
Trk::AtaPlane
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:34
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DiscSurface.h
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
Trk::SurfaceType::Plane
@ Plane
RPDUtils::nRows
unsigned constexpr int nRows
Definition: RPDUtils.h:24
Trk::SurfaceType::Line
@ Line
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
TrackParametersCnv_p2::createTransient
Trk::TrackParameters * createTransient(const Trk::TrackParameters_p2 *persObj, MsgStream &log)
Definition: TrackParametersCnv_p2.cxx:39
Trk::Surface::type
constexpr virtual SurfaceType type() const =0
Returns the Surface type to avoid dynamic casts.
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
Identifier
Definition: IdentifierFieldParser.cxx:14