ATLAS Offline Software
Loading...
Searching...
No Matches
VKalVrtFitFastSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Header include
8//-------------------------------------------------
9//
10#include "TrkTrack/TrackInfo.h"
11#include <vector>
12#include <algorithm> //for nth_element, max_element
13#include <cmath> //for abs
14
15namespace{
16 double
17 median(std::vector<double> & v){ //modifies the vector v
18 //assume we don't need to check for empty vector
19 const auto n = v.size();
20 const auto halfway =n/2;
21 //its a contiguous iterator, just use addition
22 std::vector<double>::iterator it = v.begin() + halfway;
23 std::nth_element(v.begin(), it, v.end());
24 if (n & 1){//it has an odd number of elements
25 return *it;//so just return the middle element
26 } else {
27 const double mid2 = *it;
28 //the following works because v is partially sorted by std::nth_element
29 const double mid1 = *std::max_element(v.begin(), it);
30 return (mid1 + mid2) *0.5; //return the average of the two neighbouring mid elements
31 }
32 }
33}
34
35//
36//__________________________________________________________________________
37//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
38
39
40namespace Trk{
41
42//-----------------------------------------------------------------------------------------
43// Standard (old) code
44//
45
46
47 StatusCode TrkVKalVrtFitter::VKalVrtFitFast(std::span<const xAOD::TrackParticle* const> InpTrk,
49 IVKalState& istate) const
50 {
51 double minDZ=0.;
52 return VKalVrtFitFast(InpTrk,Vertex,minDZ,istate);
53 }
54
55
56 StatusCode TrkVKalVrtFitter::VKalVrtFitFast(std::span<const xAOD::TrackParticle* const> InpTrk,
57 Amg::Vector3D& Vertex, double & minDZ,
58 IVKalState& istate) const
59 {
60 assert(dynamic_cast<State*> (&istate)!=nullptr);
61 State& state = static_cast<State&> (istate);
62//
63// Convert particles and setup reference frame
64//
65 int ntrk=0;
66 StatusCode sc = CvtTrackParticle(InpTrk,ntrk,state);
67 if(sc.isFailure() || ntrk<1 ) return StatusCode::FAILURE;
68 double fx,fy,BMAG_CUR;
69 state.m_fitField.getMagFld(0.,0.,0.,fx,fy,BMAG_CUR);
70 if(fabs(BMAG_CUR) < 0.1) BMAG_CUR=0.1;
71//
72//------ Variables and arrays needed for fitting kernel
73//
74 double out[3];
75 std::vector<double> xx,yy,zz,difz;
76 Vertex[0]=Vertex[1]=Vertex[2]=0.;
77//
78//
79 double xyz0[3]={ -state.m_refFrameX, -state.m_refFrameY, -state.m_refFrameZ};
80 if(ntrk==2){
81 minDZ=Trk::vkvFastV(&state.m_apar[0][0],&state.m_apar[1][0], xyz0, BMAG_CUR, out);
82 } else {
83 for(int i=0;i<ntrk-1; i++){
84 for(int j=i+1; j<ntrk; j++){
85 double dZ=Trk::vkvFastV(&state.m_apar[i][0],&state.m_apar[j][0], xyz0, BMAG_CUR, out);
86 xx.push_back(out[0]);
87 yy.push_back(out[1]);
88 zz.push_back(out[2]);
89 difz.push_back(dZ);
90 }
91 }
92 out[0] = median(xx);
93 out[1] = median(yy);
94 out[2] = median(zz);
95 minDZ = median(difz);
96 }
97 Vertex[0]= out[0] + state.m_refFrameX;
98 Vertex[1]= out[1] + state.m_refFrameY;
99 Vertex[2]= out[2] + state.m_refFrameZ;
100
101
102 return StatusCode::SUCCESS;
103 }
104
105
106
107 StatusCode TrkVKalVrtFitter::VKalVrtFitFast(const std::vector<const TrackParameters*>& InpTrk,
109 IVKalState& istate) const
110 {
111 assert(dynamic_cast<State*> (&istate)!=nullptr);
112 State& state = static_cast<State&> (istate);
113//
114// Convert particles and setup reference frame
115//
116 int ntrk=0;
117 StatusCode sc = CvtTrackParameters(InpTrk,ntrk,state);
118 if(sc.isFailure() || ntrk<1 ) return StatusCode::FAILURE;
119 double fx,fy,BMAG_CUR;
120 state.m_fitField.getMagFld(0.,0.,0.,fx,fy,BMAG_CUR);
121 if(fabs(BMAG_CUR) < 0.1) BMAG_CUR=0.1;
122//
123//------ Variables and arrays needed for fitting kernel
124//
125 double out[3];
126 std::vector<double> xx,yy,zz;
127 Vertex[0]=Vertex[1]=Vertex[2]=0.;
128//
129//
130 double xyz0[3]={ -state.m_refFrameX, -state.m_refFrameY, -state.m_refFrameZ};
131 if(ntrk==2){
132 Trk::vkvFastV(&state.m_apar[0][0],&state.m_apar[1][0], xyz0, BMAG_CUR, out);
133 } else {
134 for(int i=0;i<ntrk-1; i++){
135 for(int j=i+1; j<ntrk; j++){
136 Trk::vkvFastV(&state.m_apar[i][0],&state.m_apar[j][0], xyz0, BMAG_CUR, out);
137 xx.push_back(out[0]);
138 yy.push_back(out[1]);
139 zz.push_back(out[2]);
140 }
141 }
142 out[0] = median(xx);
143 out[1] = median(yy);
144 out[2] = median(zz);
145
146 }
147 Vertex[0]= out[0] + state.m_refFrameX;
148 Vertex[1]= out[1] + state.m_refFrameY;
149 Vertex[2]= out[2] + state.m_refFrameZ;
150
151
152 return StatusCode::SUCCESS;
153 }
154
155
156}
157
boost::graph_traits< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS > >::vertex_descriptor Vertex
static Double_t sc
double m_apar[NTrMaxVFit][5]
StatusCode CvtTrackParameters(const std::vector< const TrackParameters * > &InpTrk, int &ntrk, State &state) const
virtual StatusCode VKalVrtFitFast(std::span< const xAOD::TrackParticle *const >, Amg::Vector3D &Vertex, double &minDZ, IVKalState &istate) const
StatusCode CvtTrackParticle(std::span< const xAOD::TrackParticle *const > list, int &ntrk, State &state) const
virtual void getMagFld(const double, const double, const double, double &, double &, double &) override
This class is a simplest representation of a vertex candidate.
Eigen::Matrix< double, 3, 1 > Vector3D
::StatusCode StatusCode
StatusCode definition for legacy code.
float median(std::vector< float > &Vec)
Ensure that the ATLAS eigen extensions are properly loaded.
double vkvFastV(double *p1, double *p2, const double *vRef, double dbmag, double *out)
Definition VKvFast.cxx:42