22 #include "GaudiKernel/SystemOfUnits.h"
26 #include "CLHEP/Vector/LorentzVector.h"
37 std::vector<const T*> asVec (
const std::vector<std::unique_ptr<T> >&
v)
39 std::vector<const T*> ret;
40 ret.reserve(
v.size());
42 for (
const std::unique_ptr<T>&
p :
v) {
43 ret.push_back (
p.get());
49 std::vector<const Trk::TrackParameters*>
50 asVec (
const std::vector<std::unique_ptr<Trk::Perigee> >&
v)
52 std::vector<const Trk::TrackParameters*> ret;
53 ret.reserve(
v.size());
55 for (
const std::unique_ptr<Trk::Perigee>&
p :
v) {
56 ret.push_back (
p.get());
62 std::vector<const Trk::NeutralParameters*>
63 asVec (
const std::vector<std::unique_ptr<Trk::NeutralPerigee> >&
v)
65 std::vector<const Trk::NeutralParameters*> ret;
66 ret.reserve(
v.size());
68 for (
const std::unique_ptr<Trk::NeutralPerigee>&
p :
v) {
69 ret.push_back (
p.get());
83 using PerigeeUVec_t = std::
vector<std::unique_ptr<
Trk::Perigee> >;
84 PerigeeUVec_t makePerigees1()
97 ret.emplace_back (std::make_unique<Trk::Perigee>(pos1a, mom1a, 1, pos1a, cov5()).
release());
98 ret.emplace_back (std::make_unique<Trk::Perigee>(pos1b, mom1b, -1, pos1b, cov5()).
release());
99 ret.emplace_back (std::make_unique<Trk::Perigee>(pos1c, mom1c, -1, pos1c, cov5()).
release());
105 using NeutralUVec_t = std::vector<std::unique_ptr<Trk::NeutralPerigee> >;
106 NeutralUVec_t makeNeutrals1()
119 ret.emplace_back (std::make_unique<Trk::NeutralPerigee>(pos1a, mom1a, 1, pos1a, cov5()).
release());
120 ret.emplace_back (std::make_unique<Trk::NeutralPerigee>(pos1b, mom1b, 1, pos1b, cov5()).
release());
121 ret.emplace_back (std::make_unique<Trk::NeutralPerigee>(pos1c, mom1c, 1, pos1c, cov5()).
release());
127 using TrackUVec_t = std::vector<std::unique_ptr<Trk::Track> >;
128 TrackUVec_t makeTracks (PerigeeUVec_t&& perigees)
132 for (std::unique_ptr<Trk::Perigee>&
p : perigees) {
134 auto fqual = std::make_unique<Trk::FitQuality> (0, 0);
135 auto tsos = std::make_unique<Trk::TrackStates>();
136 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern(0);
138 tsos->push_back(std::make_unique<Trk::TrackStateOnSurface>(
139 nullptr, std::move(
p),
nullptr, typePattern));
141 std::make_unique<Trk::Track>(
info, std::move(tsos), std::move(fqual)));
153 tp.setDefiningParameters(perigee.parameters()[
Trk::d0],
161 std::vector<float> covMatrixVec;
164 tp.setDefiningParametersCovMatrixVec(covMatrixVec);
166 tp.setParametersOrigin(surfaceCenter.x(), surfaceCenter.y(), surfaceCenter.z() );
171 tp.setDefiningParameters(perigee.parameters()[
Trk::d0],
179 std::vector<float> covMatrixVec;
182 tp.setDefiningParametersCovMatrixVec(covMatrixVec);
184 tp.setParametersOrigin(surfaceCenter.x(), surfaceCenter.y(), surfaceCenter.z() );
188 using xAODTPUVec_t = std::vector<std::unique_ptr<xAOD::TrackParticle> >;
189 xAODTPUVec_t makexAODTP (PerigeeUVec_t&& perigees)
193 for (std::unique_ptr<Trk::Perigee>&
p : perigees) {
194 auto tp = std::make_unique<xAOD::TrackParticle>();
195 tp->makePrivateStore();
196 setDefiningParameters (*
tp, *
p);
197 tracks.push_back (std::move (
tp));
204 using xAODNPUVec_t = std::vector<std::unique_ptr<xAOD::NeutralParticle> >;
205 xAODNPUVec_t makexAODNP (NeutralUVec_t&& perigees)
209 for (std::unique_ptr<Trk::NeutralPerigee>&
p : perigees) {
210 auto tp = std::make_unique<xAOD::NeutralParticle>();
211 tp->makePrivateStore();
212 setDefiningParameters (*
tp, *
p);
213 tracks.push_back (std::move (
tp));
222 for (
int i=0;
i < 5;
i++) {
223 for (
int j=0; j < 5; j++) {
224 std::cout <<
m(
i,j) <<
", ";
233 std::cout <<
"vvv\n";
234 std::cout <<
v.x() <<
", " <<
v.y() <<
", " <<
v.z() <<
"\n";
236 if (vertexTypeAcc.isAvailable (
v)) {
237 std::cout <<
"vertexType " <<
v.vertexType() <<
"\n";
239 std::cout <<
"chi2/ndof " <<
v.chiSquared() <<
", " <<
v.numberDoF() <<
"\n";
242 for (
float f :
v.covariance()) {
243 std::cout <<
f <<
", ";
248 if (trackParticleLinksAcc.isAvailable(
v)) {
249 std::cout <<
"tplinks ";
251 std::cout <<
l.dataID() <<
"/" <<
l.index() <<
" ";
257 if (trackWeightsAcc.isAvailable(
v)) {
259 for (
float f :
v.trackWeights()) {
260 std::cout <<
f <<
" ";
266 if (neutralParticleLinksAcc.isAvailable(
v)) {
267 std::cout <<
"nplinks ";
269 std::cout <<
l.dataID() <<
"/" <<
l.index() <<
" ";
275 if (neutralWeightsAcc.isAvailable(
v)) {
277 for (
float f :
v.neutralWeights()) {
278 std::cout <<
f <<
" ";
283 std::cout <<
v.vxTrackAtVertexAvailable() <<
"\n";
287 if (
vv.perigeeAtVertex()) {
288 dumpCovariance (*
vv.perigeeAtVertex()->covariance());
291 std::cout <<
"(null)";
298 void assertVec3D (
const char*
which,
306 std::cerr <<
"TrkVKalVrtFitterTestAlg::assertVec3D mismatch " <<
which
322 if (!
a && !
b)
return;
323 if (!
a || !
b) std::abort();
324 assertVec3D (
"perigee pos",
a->position(),
b->position());
325 assertVec3D (
"perigee mom",
a->momentum(),
b->momentum());
326 assert (
a->charge() ==
b->charge());
327 assertVec3D (
"perigee surf",
328 a->associatedSurface().center(),
329 b->associatedSurface().center());
335 assertVec3D (
"vertex pos",
a.position(),
b.position());
339 assert (
a.covariance().size() ==
b.covariance().size());
340 for (
unsigned int i = 0;
i <
a.covariance().
size();
i++) {
341 if (std::isinf(
a.covariance()[
i]) && std::isinf(
b.covariance()[
i]))
continue;
345 assert (
a.vxTrackAtVertexAvailable() ==
b.vxTrackAtVertexAvailable());
346 if (
a.vxTrackAtVertexAvailable()) {
347 const std::vector< Trk::VxTrackAtVertex >& avec =
a.vxTrackAtVertex();
348 const std::vector< Trk::VxTrackAtVertex >& bvec =
b.vxTrackAtVertex();
349 assert (avec.size() == bvec.size());
350 for (
unsigned int i = 0;
i < avec.size();
i++) {
351 comparePerigee (avec[
i].initialPerigee(), bvec[
i].initialPerigee());
352 comparePerigee (avec[
i].perigeeAtVertex(), bvec[
i].perigeeAtVertex());
356 assert (avec[
i].trackQuality().numberDoF() ==
357 bvec[
i].trackQuality().numberDoF());
365 std::vector< Trk::VxTrackAtVertex >&
vec =
v.vxTrackAtVertex();
366 if (
vec.size() <=
i)
vec.resize(
i+1);
367 vec[
i].setInitialPerigee (
p);
371 void setInitialPerigees (
xAOD::Vertex&
v,
const TrackUVec_t& tracks)
374 for (
const std::unique_ptr<Trk::Track>&
t : tracks) {
375 setInitialPerigee (
v,
i,
t->perigeeParameters());
384 v.setInitialPerigee (
static_cast<const Trk::Perigee*
>(
nullptr));
393 const std::vector<float>&
c)
395 std::vector< Trk::VxTrackAtVertex >&
vec =
v.vxTrackAtVertex();
396 if (
vec.size() <=
i)
vec.resize(
i+1);
399 for (
int i=0;
i < 5;
i++) {
400 for (
int j=0; j < 5; j++) {
401 unsigned ipos =
i*5 + j;
402 (
cov)(
i,j) = ipos <
c.size() ?
c[ipos] : 0;
407 auto p = std::make_unique<Trk::Perigee> (
pos,
mom,
charge, vpos,
409 vec[
i].setPerigeeAtVertex (
p.release());
415 std::vector< Trk::VxTrackAtVertex >&
vec =
v.vxTrackAtVertex();
416 if (
vec.size() <=
i)
vec.resize(
i+1);
433 return StatusCode::SUCCESS;
445 return StatusCode::SUCCESS;
456 {28.318, 26.913, 37.8531, 17.3323, 17.3041, 23.6152});
457 setFitQuality (exp_v0, 0, 0.936, 1);
458 setFitQuality (exp_v0, 1, 0.000, 2);
459 setFitQuality (exp_v0, 2, 0.000, 2);
461 NeutralUVec_t neutrals = makeNeutrals1();
462 std::unique_ptr<xAOD::Vertex> v1 (
m_fitter->fit (std::vector<const Trk::TrackParameters*>(),
464 compareVertex (*v1, exp_v0);
466 return StatusCode::SUCCESS;
474 exp_v0.
setPosition ({-0.666051, 1.88126, -4.2844});
477 {25.8826, 26.6122, 91.0458, 6.34189, 14.6174, 13.9884});
482 { 1.58753, 0.380882, -10.2063 },
483 { 399.6301520, 600.2463141, 200.0002601 },
484 { 1.58278, -0.618193, -0.821391, 0.00010879, -0.171884, -0.618193,
485 2.32566, 0.908938, 0.800925, 0.346876, -0.821391, 0.908938,
486 1.20816, -0.000294073, 0.461137, 0.00010879, 0.800925, -0.000294073,
487 1, -0.000269915, -0.171884, 0.346876, 0.461137, -0.000269915,
489 setFitQuality (exp_v0, 0, 0.000, 2);
494 { -0.209537, 1.1947, -2.59698 },
495 { 600.4814296, 399.2766328, -200.0005578 },
496 { 3.53014, 0.466334, -2.04043, 0.000621337, -0.653413, 0.466334,
497 3.53405, -0.415368, 1.56192, -0.206492, -2.04043, -0.415368,
498 1.81448, -0.000856625, 0.901728, 0.000621337, 1.56192, -0.000856625,
499 1, -0.000578862, -0.653413, -0.206492, 0.901728, -0.000578862,
501 setFitQuality (exp_v0, 1, 0.017, 2);
502 setRefittedPerigee(exp_v0,
505 { 1.20591, 1.3197, -6.99803 },
506 { 299.9873170, 1000.0038041, 100.0000072 },
532 setFitQuality (exp_v0, 2, 0.020, 2);
533 setFitQuality (exp_v0, 3, 0.136, 2);
534 setFitQuality (exp_v0, 4, 0.000, 2);
535 setFitQuality (exp_v0, 5, 0.000, 2);
539 TrackUVec_t tracks = makeTracks (makePerigees1());
540 setInitialPerigees (exp_v0, tracks);
542 PerigeeUVec_t perigees = makePerigees1();
543 NeutralUVec_t neutrals = makeNeutrals1();
544 std::unique_ptr<xAOD::Vertex> v1 (
m_fitter->fit (asVec (perigees),
547 compareVertex (*v1, exp_v0);
549 xAODTPUVec_t xtps = makexAODTP (makePerigees1());
550 xAODNPUVec_t xaodnp = makexAODNP (makeNeutrals1());
551 std::unique_ptr<xAOD::Vertex>
v2 (
m_fitter->fit (asVec (xtps),
554 clearInitialPerigees (exp_v0);
555 compareVertex (*
v2, exp_v0);
557 return StatusCode::SUCCESS;
569 {1.183, 0.0323074, 1.21271,
570 0.00903037, 0.0167373, 1.12584});
575 { 5.1719083, 5.7335618, -8.4196568 },
576 { 402.8346276, 598.1012479, 199.9979000 },
577 { 135.368, 4.54292, 41.4349, -0.0182748, -10.0936,
578 4.54292, 38.8427, 1.48244, -6.13913, -0.389733,
579 41.4349, 1.48244, 13.5349, -0.00640884, -3.54057,
580 -0.0182748, -6.13913, -0.00640884, 1, 0.00218082,
581 -10.0936, -0.389733, -3.54057, 0.00218082, 1 });
582 setFitQuality (exp_v0, 0, 0.682, 2);
584 setRefittedPerigee(exp_v0,
587 { 5.4869777, 5.0058724, -4.4978936 },
588 { 598.2006961, 402.6869274, -199.9979142 },
589 { 111.922, -11.1715, 35.7532, -0.0162277, -9.04482,
590 -11.1715, 35.9577, -3.83303, -5.80842, 1.04702,
591 35.7532, -3.83303, 12.2632, -0.0060222, -3.35579,
592 -0.0162277, -5.80842, -0.0060222, 1, 0.00216502,
593 -9.04482, 1.04702, -3.35579, 0.00216502, 1 });
594 setFitQuality (exp_v0, 1, 0.061, 2);
600 { 2.7708142, 6.5661849, -6.4736255 },
601 { 296.8467752, 1000.9403742, 100.0017963 },
602 { 114.181, -7.37341, 35.593, -0.0172367, -9.10529,
603 -7.37341, 32.345, -2.46816, -5.55155, 0.684107,
604 35.593, -2.46816, 11.9239, -0.00626001, -3.30551,
605 -0.0172367, -5.55155, -0.00626001, 1, 0.00180269,
606 -9.10529, 0.684107, -3.30551, 0.00180269, 1 });
607 setFitQuality (exp_v0, 2, 0.352, 2);
608 setFitQuality (exp_v0, 3, 1.119, 1);
609 setFitQuality (exp_v0, 4, 0.000, 2);
610 setFitQuality (exp_v0, 5, 0.000, 2);
617 pnt2covar.setIdentity();
620 TrackUVec_t tracks = makeTracks (makePerigees1());
621 setInitialPerigees (exp_v0, tracks);
623 PerigeeUVec_t perigees = makePerigees1();
624 NeutralUVec_t neutrals = makeNeutrals1();
625 std::unique_ptr<xAOD::Vertex> v1 (
m_fitter->fit (asVec (perigees),
628 compareVertex (*v1, exp_v0);
630 xAODTPUVec_t xtps = makexAODTP (makePerigees1());
631 xAODNPUVec_t xaodnp = makexAODNP (makeNeutrals1());
632 std::unique_ptr<xAOD::Vertex>
v2 (
m_fitter->fit (asVec (xtps),
635 clearInitialPerigees (exp_v0);
636 compareVertex (*
v2, exp_v0);
638 return StatusCode::SUCCESS;