ATLAS Offline Software
Loading...
Searching...
No Matches
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"
22
27
28#include <cassert>
29#include <iostream>
30
32 const Trk ::TrackParameters_p2* ,
33 Trk ::TrackParameters* , MsgStream& ) {
34 throw std::runtime_error(
35 "TrackParametersCnv_p2::persToTrans shouldn't be called any more!");
36}
37
39 const Trk::TrackParameters_p2* persObj, MsgStream& log) {
40 // ---- Covariance matrix
41 std::optional<AmgSymMatrix(5)> cov = std::nullopt;
42 auto transcov =
43 std::unique_ptr<AmgSymMatrix(5)>(transErrorMatrix(persObj, log));
44 if (transcov) {
45 cov = (*transcov);
46 }
47 // ---- Parameters
48 Trk::TrackParameters *transObj=nullptr;
49 unsigned int size=persObj->m_parameters.size();
50 if (size==7){ // size 7 means we chose to write
51 // as a Curvillinear representation
52 // In principle we could check
53 // the persObject for Trk::SurfaceType::Curvilinear
54 AmgVector(7) parameters;
55 for (unsigned int i=0; i<size; ++i) parameters[i]=persObj->m_parameters[i];
56 transObj= new Trk::CurvilinearParameters(parameters, cov);
57 return transObj;
58 } else {
59 // Not a curvilinear representation.
60 // We need to have a surface to handle local->global transformations etc/
61 // Get surface type
62 Trk::SurfaceType type = static_cast<Trk::SurfaceType>(persObj->m_surfaceType);
63 // Get surface & fill parameter vector
64 const Trk::Surface* surface = transSurface(persObj, type, log);
65 AmgVector(5) parameters;
66 for (unsigned int i = 0; i < size; ++i){
67 parameters[i] = persObj->m_parameters[i];
68 }
69 // Now create concrete parameters ...
70 if (surface){
72 transObj = new Trk::Perigee(
73 parameters, static_cast<const Trk::PerigeeSurface*>(surface), cov);
74 return transObj;
75 } else if (type == Trk::SurfaceType::Plane) {
76 transObj = new Trk::AtaPlane(
77 parameters, static_cast<const Trk::PlaneSurface*>(surface), cov);
78 return transObj;
79 } else if (type == Trk::SurfaceType::Line) {
80 transObj = new Trk::AtaStraightLine(
81 parameters,
82 static_cast<const Trk::StraightLineSurface*>(surface),
83 cov);
84 return transObj;
85 }
86 } else if (!m_nosurf) {
87 // FIXME: next line changed to DEBUG to avoid filling the derivation job
88 // options with garbage. Underlying issue should be fixed.
89 log << MSG::DEBUG << "No surface of type=" << static_cast<int>(type)
90 << " created - so these parameters cannot be made!" << endmsg;
91 return nullptr;
92 }
93 }
94 return nullptr;
95}
96
97AmgSymMatrix(5)* TrackParametersCnv_p2::transErrorMatrix(const Trk :: TrackParameters_p2 *persObj,MsgStream& log){
98 AmgSymMatrix(5)* cov=nullptr;
99 if (!persObj->m_errorMatrix.isNull()){
100 // fill errormatrix
101 cov = new AmgSymMatrix(5);
102 Trk::ErrorMatrix dummy;
103 fillTransFromPStore( &m_emConverter, persObj->m_errorMatrix, &dummy, log );
104 Amg::expand(dummy.values.begin(), dummy.values.end(), *cov);
105 }
106 return cov;
107}
108
109const Trk::Surface*
110TrackParametersCnv_p2::transSurface(const Trk ::TrackParameters_p2* persObj,
112 MsgStream& log)
113{
114 const Trk::Surface* surface = nullptr;
115 // check if surface had transform.
116 if (!persObj->m_transform.empty()){
117 auto transform = std::make_unique<Amg::Transform3D>();
118 EigenHelpers::vectorToEigenTransform3D( persObj->m_transform, *transform.get());
119 // recreate free surface
121 surface = new Trk::PerigeeSurface(*transform);
122 } else if (type==Trk::SurfaceType::Plane){
123 surface = new Trk::PlaneSurface(*transform);
124 } else if (type==Trk::SurfaceType::Line){
125 surface = new Trk::StraightLineSurface(*transform);
126 }
127 if (!surface){
128 log << MSG::WARNING << "Free surface of type=" << static_cast<int>(type)
129 << " isn't currently supported in TrackParametersCnv_p2" << endmsg;
130 return nullptr;
131 }
132 } else {
133 // Surface must have belonged to a ReadoutElement, or some part of the geometry or have a nominal/default perigee surface.
135 Identifier id=Identifier32(persObj->m_associatedDetElementId);
136 if (!id.get_compact() && persObj->m_associatedDetElementId != 0)
137 id = Identifier(persObj->m_associatedDetElementId);
138 if (m_nosurf)surface = nullptr;
139 else {
140 const Trk::Surface* detSurf = m_eventCnvTool->getSurface(id);
141 if (!detSurf){
142 log << MSG::WARNING << "Surface of type=" << static_cast<int>(type)
143 << " was not found by the eventCnvTool." << endmsg;
144 }
145 surface = detSurf;
146 }
147 } else {
148 surface = new Trk::PerigeeSurface(); // FIXME! How do we support nominal Perigee Surfaces now?
149 }
150 }
151 return surface;
152}
153
154void TrackParametersCnv_p2::transToPers(const Trk ::TrackParameters* transObj,
155 Trk ::TrackParameters_p2* persObj,
156 MsgStream& log) {
157
158 bool isCurvilinear = (transObj->type() == Trk::Curvilinear);
159 bool deleteAtEnd = false;
160 if (isCurvilinear){
161 convertTransCurvilinearToPers(transObj,persObj);
162 // Not bothering with Surface here - not relevant for curvilinear
163 } else {
164 // normal track parameters - check if the type is 'permitted' to be written.
165 if (isPersistifiableType(transObj)) {
166 unsigned int nRows = transObj->parameters().rows();
167 persObj->m_parameters.resize( nRows);
168 for( unsigned int i = 0; i < nRows; i++ ){
169 persObj->m_parameters[i] = transObj->parameters()[i];
170 }
171 fillPersSurface(transObj, persObj, log);
172 } else { // if not, convert to curvilinear
173 std::optional<AmgSymMatrix(5)> newcov = std::nullopt;
174 if (transObj->covariance()) {
175 newcov = *(transObj->covariance());
176 }
177 const Trk::CurvilinearParameters* curvilinear =
178 new Trk::CurvilinearParameters(transObj->position(),
179 transObj->momentum(),
180 transObj->charge(), newcov);
181 transObj = curvilinear;
182 deleteAtEnd = true; // Because the curvilinear will leak otherwise
183 convertTransCurvilinearToPers(transObj, persObj);
184 }
185 }
186
187 // Errormatrix
188 if (transObj->covariance()){
189 Trk::ErrorMatrix pMat;
190 EigenHelpers::eigenMatrixToVector(pMat.values, *transObj->covariance(), "TrackParametersCnv_p2");
191 persObj->m_errorMatrix = toPersistent( &m_emConverter, &pMat, log );
192 }
193
194 if (deleteAtEnd) {
195 delete transObj;
196 }
197}
198
200 const Trk ::TrackParameters* transObj, Trk ::TrackParameters_p2* persObj) {
201 // Curvilinear: here we store the 3 position + 3 momentum, rather than the 5
202 // parameters.
203 // This avoids writing the surface
204 persObj->m_parameters.resize(7);
205 for (unsigned int i = 0; i < 3; ++i) {
206 persObj->m_parameters[i] = transObj->position()[i];
207 persObj->m_parameters[i + 3] = transObj->momentum()[i];
208 }
209 persObj->m_parameters[6] = transObj->charge();
210 // And lets remember to always set the type of the surface
211 persObj->m_surfaceType = static_cast<uint8_t>(Trk::SurfaceType::Curvilinear);
212}
213
214bool TrackParametersCnv_p2::isPersistifiableType(const Trk :: TrackParameters *transObj) {
215 const Trk::Surface* surf = transObj->associatedSurface ().baseSurface();
216 assert (surf);
217 Trk::SurfaceType type = surf->type();
219}
220
221void TrackParametersCnv_p2::fillPersSurface(const Trk :: TrackParameters *transObj, Trk :: TrackParameters_p2 *persObj, MsgStream& /*log*/){
222 //----- Surface
223 const Trk::Surface* surf = transObj->associatedSurface ().baseSurface();
224 assert (surf);
225 persObj->m_surfaceType = static_cast<uint8_t>(surf->type()); // Store type
226
227 persObj->m_associatedDetElementId = surf->associatedDetectorElementIdentifier().get_identifier32().get_compact();
228 static const Trk::PerigeeSurface s_nominalPerigeeSurface; // FIXME - should there be a common 'nominal' surface ie on Perigee, as before?
229 // Need to write out transforms for TG owned surfaces, and 'free' (noOwn) surfaces - i.e. anything which isn't on det element
230 if( surf->cachedTransform()!=nullptr ) {
231 // 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'
232 if (surf->type() != Trk::SurfaceType::Perigee ||
233 (surf->type() == Trk::SurfaceType::Perigee &&
234 *surf != s_nominalPerigeeSurface)) {
235 EigenHelpers::eigenTransform3DToVector(*(surf->cachedTransform()),
236 persObj->m_transform);
237 }
238 }
239}
240
241
#define endmsg
#define AmgSymMatrix(dim)
#define AmgVector(rows)
void fillTransFromPStore(CNV **cnv, const TPObjRef &ref, TRANS_T *trans, MsgStream &log) const
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
void persToTrans(const Trk ::TrackParameters_p2 *persObj, Trk ::TrackParameters *transObj, MsgStream &log)
Trk::TrackParameters * createTransient(const Trk::TrackParameters_p2 *persObj, MsgStream &log)
ErrorMatrixCnv_p1 * m_emConverter
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
void transToPers(const Trk::TrackParameters *transObj, Trk::TrackParameters_p2 *persObj, MsgStream &log)
static void convertTransCurvilinearToPers(const Trk ::TrackParameters *transObj, Trk ::TrackParameters_p2 *persObj)
static void fillPersSurface(const Trk ::TrackParameters *transObj, Trk ::TrackParameters_p2 *persObj, MsgStream &log)
AmgSymMatrix(5) *transErrorMatrix(const Trk const Trk::Surface * transSurface(const Trk ::TrackParameters_p2 *persObj, Trk::SurfaceType type, MsgStream &log)
static bool isPersistifiableType(const Trk ::TrackParameters *transObj)
std::vector< float > values
Class describing the Line to which the Perigee refers to.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
Abstract Base Class for tracking surfaces.
const Amg::Transform3D * cachedTransform() const
Return the cached transformation directly.
virtual const Trk::Surface * baseSurface() const
return the base surface (simplified for persistification)
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
virtual constexpr SurfaceType type() const =0
Returns the Surface type to avoid dynamic casts.
std::vector< float > m_parameters
uint8_t m_surfaceType
Used to recreate the correct TrackParameters.
void expand(std::vector< float >::const_iterator it, std::vector< float >::const_iterator, AmgSymMatrix(N) &covMatrix)
static void eigenMatrixToVector(VECTOR &vec, COVARIANCE &cov, const char *)
SurfaceType
This enumerator simplifies the persistency & calculations,.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
ParametersBase< TrackParametersDim, Charged > TrackParameters
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane