13 #include "GaudiKernel/IChronoStatSvc.h"
27 TLorentzVector& Momentum,
31 std::vector< std::vector<double> >& TrkAtVrt,
36 assert(
dynamic_cast<State*
> (&istate)!=
nullptr);
44 if(
sc.isFailure())
return StatusCode::FAILURE;
47 Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
48 if (ierr)
return StatusCode::FAILURE;
49 return StatusCode::SUCCESS;
55 const std::vector<const xAOD::NeutralParticle*> & InpTrkN,
57 TLorentzVector& Momentum,
61 std::vector< std::vector<double> >& TrkAtVrt,
66 assert(
dynamic_cast<State*
> (&istate)!=
nullptr);
77 std::vector<const TrackParameters*> tmpInputC(0);
78 std::vector<std::unique_ptr<const TrackParameters>> TParamOwner(0);
80 double closestHitR=1.e6;
85 if(msgLvl(MSG::WARNING))
msg()<<
"No InDet extrapolator given."<<
86 "Can't use FirstMeasuredPoint with xAOD::TrackParticle!!!" <<
endmsg;
87 return StatusCode::FAILURE;
89 std::vector<const xAOD::TrackParticle*>::const_iterator i_ntrk;
90 if(msgLvl(
MSG::DEBUG))
msg()<<
"Start FirstMeasuredPoint handling"<<
'\n';
91 unsigned int indexFMP;
92 for (i_ntrk = InpTrkC.begin(); i_ntrk < InpTrkC.end(); ++i_ntrk) {
94 if(msgLvl(
MSG::DEBUG))
msg()<<
"FirstMeasuredPoint on track is discovered. Use it."<<
'\n';
96 TParamOwner.emplace_back(std::make_unique<CurvilinearParameters>(
97 (*i_ntrk)->curvilinearParameters(indexFMP)));
99 tmpInputC.push_back((TParamOwner.back()).get());
102 msg()<<
"FirstMeasuredPoint on track is absent."<<
103 "Try extrapolation from Perigee to FisrtMeasuredPoint radius"<<
endmsg;
108 tmpInputC.push_back((TParamOwner.back()).get());
110 if( (*i_ntrk)->radiusOfFirstHit() < closestHitR ) {
111 closestHitR=(*i_ntrk)->radiusOfFirstHit();
113 if(tmpInputC[tmpInputC.size()-1]==
nullptr){
115 if(msgLvl(MSG::WARNING)){
116 msg()<<
"InDetExtrapolator can't etrapolate xAOD::TrackParticle Perigee "<<
117 "to FirstMeasuredPoint radius! Stop vertex fit!" <<
endmsg;
119 return StatusCode::FAILURE;
125 return StatusCode::FAILURE;
129 if(!InpTrkC.empty()) {
133 if(
sc.isFailure())
return StatusCode::FAILURE;
134 if(!InpTrkN.empty()){
sc=
CvtNeutralParticle(InpTrkN,ntrk,state);
if(
sc.isFailure())
return StatusCode::FAILURE;}
136 int ierr =
VKalVrtFit3( ntrk,
Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt, Chi2, state, ifCovV0 ) ;
137 if (ierr)
return StatusCode::FAILURE;
140 state.m_planeCnstNDOF = 0;
144 if(state.m_globalFirstHit)cnstRefPoint=state.m_globalFirstHit->position();
145 else if(closestHitR < 1.e6){
148 cnstRefPoint=
Vertex+(closestHitR-
Vertex.perp())*unitMom;
151 if(
Vertex.perp()>cnstRefPoint.perp() && cnstRefPoint.perp()>0.){
153 state.m_planeCnstNDOF = 1;
154 double pp[3]={Momentum.Px()/Momentum.Rho(),Momentum.Py()/Momentum.Rho(),Momentum.Pz()/Momentum.Rho()};
155 double D= pp[0]*(cnstRefPoint.x()-state.m_refFrameX)
156 +pp[1]*(cnstRefPoint.y()-state.m_refFrameY)
157 +pp[2]*(cnstRefPoint.z()-state.m_refFrameZ);
158 state.m_vkalFitControl.setUsePlaneCnst( pp[0], pp[1], pp[2], D);
159 std::vector<double> saveApproxV(3,0.); state.m_ApproximateVertex.swap(saveApproxV);
160 state.m_ApproximateVertex[0]=cnstRefPoint.x();
161 state.m_ApproximateVertex[1]=cnstRefPoint.y();
162 state.m_ApproximateVertex[2]=cnstRefPoint.z();
163 ierr =
VKalVrtFit3( ntrk,
Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt, Chi2, state, ifCovV0 );
164 state.m_vkalFitControl.setUsePlaneCnst(0.,0.,0.,0.);
166 ierr =
VKalVrtFit3(ntrk,
Vertex,Momentum,Charge,ErrorMatrix,Chi2PerTrk,TrkAtVrt,Chi2, state, ifCovV0);
167 state.m_planeCnstNDOF = 0;
169 state.m_ApproximateVertex.swap(saveApproxV);
173 if (ierr)
return StatusCode::FAILURE;
174 return StatusCode::SUCCESS;
179 const std::vector<const NeutralParameters*> & InpTrkN,
181 TLorentzVector& Momentum,
185 std::vector< std::vector<double> >& TrkAtVrt,
190 assert(
dynamic_cast<State*
> (&istate)!=
nullptr);
198 if(!InpTrkC.empty()){
200 if(
sc.isFailure())
return StatusCode::FAILURE;
202 if(!InpTrkN.empty()){
204 if(
sc.isFailure())
return StatusCode::FAILURE;
207 if(state.m_ApproximateVertex.empty() && state.m_globalFirstHit){
208 state.m_ApproximateVertex.reserve(3);
209 state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().x());
210 state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().y());
211 state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().z());
213 int ierr =
VKalVrtFit3( ntrk,
Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
214 if (ierr)
return StatusCode::FAILURE;
217 state.m_planeCnstNDOF = 0;
221 state.m_planeCnstNDOF = 1;
222 double pp[3]={Momentum.Px()/Momentum.Rho(),Momentum.Py()/Momentum.Rho(),Momentum.Pz()/Momentum.Rho()};
223 double D= pp[0]*(state.m_globalFirstHit->position().x()-state.m_refFrameX)
224 +pp[1]*(state.m_globalFirstHit->position().y()-state.m_refFrameY)
225 +pp[2]*(state.m_globalFirstHit->position().z()-state.m_refFrameZ);
226 state.m_vkalFitControl.setUsePlaneCnst( pp[0], pp[1], pp[2], D);
227 std::vector<double> saveApproxV(3,0.); state.m_ApproximateVertex.swap(saveApproxV);
228 state.m_ApproximateVertex[0]=state.m_globalFirstHit->position().x();
229 state.m_ApproximateVertex[1]=state.m_globalFirstHit->position().y();
230 state.m_ApproximateVertex[2]=state.m_globalFirstHit->position().z();
231 ierr =
VKalVrtFit3( ntrk,
Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
232 state.m_vkalFitControl.setUsePlaneCnst(0.,0.,0.,0.);
234 ierr =
VKalVrtFit3(ntrk,
Vertex,Momentum,Charge,ErrorMatrix,Chi2PerTrk,TrkAtVrt,Chi2, state, ifCovV0 ) ;
235 state.m_planeCnstNDOF = 0;
237 state.m_ApproximateVertex.swap(saveApproxV);
240 if (ierr)
return StatusCode::FAILURE;
241 return StatusCode::SUCCESS;
254 TLorentzVector& Momentum,
258 std::vector< std::vector<double> >& TrkAtVrt,
267 double xyz0[3],covf[21],chi2f=-10.;
269 double xyzfit[3]={0.};
293 xyz0[0]=xyz0[1]=xyz0[2]=0.;
298 Chi2PerTrk.resize (ntrk);
300 xyzfit, state.
m_parfs, ptot, covf, chi2f,
309 if(ptot[0]*ptot[0]+ptot[1]*ptot[1] == 0.)
return -5;
315 int SymCovMtxSize=(3*ntrk+3)*(3*ntrk+4)/2;
324 Momentum.SetPxPyPzE( ptot[0], ptot[1], ptot[2], ptot[3] );
339 double fx,fy,BMAG_CUR;
341 if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01;
343 Charge=0;
for(
i=0;
i<ntrk;
i++){Charge+=state.
m_ich[
i];};
347 TrkAtVrt.clear(); TrkAtVrt.reserve(ntrk);
348 for(
i=0;
i<ntrk;
i++){
349 std::vector<double> TrkPar(3);
351 TrkPar[0],TrkPar[1],TrkPar[2]);
352 TrkPar[2] = -TrkPar[2];
353 TrkAtVrt.push_back( TrkPar );
365 const TLorentzVector& Momentum,
366 const dvect& CovVrtMom,
367 const long int& Charge,
372 assert(
dynamic_cast<State*
> (&istate)!=
nullptr);
375 double Vrt[3],PMom[4],Cov0[21],Per[5],CovPer[15];
378 for(
i=0;
i<3;
i++) PMom[
i]=Momentum[
i];
379 for(ij=
i=0;
i<6;
i++){
381 Cov0[ij]=CovVrtMom[ij];
386 long int vkCharge=-Charge;
390 double fx,fy,BMAG_CUR;
392 if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01;
394 Trk::xyztrp( vkCharge, Vrt, PMom, Cov0, BMAG_CUR, Per, CovPer );
399 for(
i=0;
i<5;
i++)
Perigee.push_back((
double)Per[
i]);
400 for(
i=0;
i<15;
i++) CovPerigee.push_back((
double)CovPer[
i]);
402 return StatusCode::SUCCESS;
407 double& tp1,
double& tp2,
double& tp3)
const
411 tp3= vp3 *
std::sin( vp1 ) /(m_CNVMAG*curBMAG);
412 constexpr
double pi =
M_PI;
414 while ( tp1 >
pi) tp1 -= 2.*
pi;
415 while ( tp1 <-
pi) tp1 += 2.*
pi;
417 while ( tp2 >
pi) tp2 -= 2.*
pi;
418 while ( tp2 <-
pi) tp2 += 2.*
pi;
420 tp2 = fabs(tp2); tp1 +=
pi;
421 while ( tp1 >
pi) tp1 -= 2.*
pi;
438 assert(
dynamic_cast<State*
> (&istate)!=
nullptr);
441 if(NTrk<1)
return StatusCode::FAILURE;
442 if(NTrk>
NTrMaxVFit)
return StatusCode::FAILURE;
443 if(state.
m_ErrMtx.empty())
return StatusCode::FAILURE;
447 double fx,fy,BMAG_CUR;
449 if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01;
453 int i,j,ik,jk,
ip,iTrk;
455 std::vector<std::vector<double> > Deriv (DIM);
456 for (std::vector<double>&
v : Deriv)
v.resize (DIM);
457 std::vector<double> CovMtxOld(DIM*DIM);
460 CovVrtTrk.resize(DIM*(DIM+1)/2);
463 for(
i=0;
i<DIM;
i++) {
464 for( j=0; j<=
i; j++) {
465 CovMtxOld[
i*DIM+j]=CovMtxOld[j*DIM+
i]=state.
m_ErrMtx[
ip++];
471 for(
i=0;
i<DIM;
i++){
for(j=0;j<DIM;j++) {Deriv[
i][j]=0.;}}
478 for( iTrk=0; iTrk<NTrk; iTrk++){
486 Deriv[iSt ][iSt+1] = 1;
487 Deriv[iSt+1][iSt ] = 1;
495 Deriv[iSt ][iSt ]= 0;
496 Deriv[iSt ][iSt+1]= -
py;
497 Deriv[iSt ][iSt+2]= -
px/invR;
499 Deriv[iSt+1][iSt ]= 0;
500 Deriv[iSt+1][iSt+1]=
px;
501 Deriv[iSt+1][iSt+2]= -
py/invR;
504 Deriv[iSt+2][iSt+1]= 0;
505 Deriv[iSt+2][iSt+2]= -
pz/invR;
514 for(ik=0;ik<DIM;ik++){
515 if(Deriv[
i][ik] == 0.)
continue;
517 for(jk=DIM-1;jk>=0;jk--){
518 if(Deriv[j][jk] == 0.)
continue;
519 tmpTmp += CovMtxOld[ik*DIM+jk]*Deriv[j][jk];
521 tmp += Deriv[
i][ik]*tmpTmp;
523 CovVrtTrk[ipnt++]=
tmp;
526 return StatusCode::SUCCESS;
537 assert(
dynamic_cast<const State*
> (&istate)!=
nullptr);
538 const State& state =
static_cast<const State&
> (istate);
542 return StatusCode::SUCCESS;
549 assert(
dynamic_cast<const State*
> (&istate)!=
nullptr);
550 const State& state =
static_cast<const State&
> (istate);
558 return StatusCode::SUCCESS;