18 #include "HepPDT/ParticleDataTable.hh"
25 typedef std::vector<const xAOD::TrackParticle*>
TrackBag;
58 return StatusCode::SUCCESS;
65 std::vector<Trk::VxCascadeInfo*> cascadeinfoContainer;
66 constexpr
int topoN = 2;
67 std::array<xAOD::VertexContainer*, topoN> Vtxwritehandles;
68 std::array<xAOD::VertexAuxContainer*, topoN> Vtxwritehandlesaux;
71 for(
int i =0;
i<topoN;
i++){
74 Vtxwritehandles[
i]->setStore(Vtxwritehandlesaux[
i]);
87 if (pvContainer->
size()==0){
89 return StatusCode::RECOVERABLE;
91 primaryVertex = (*pvContainer)[0];
108 refPvContainer->setStore(refPvAuxContainer);
118 return StatusCode::FAILURE;
187 const std::vector<xAOD::Vertex*> &cascadeVertices =
x->vertices();
188 if(cascadeVertices.size()!=topoN)
190 if(cascadeVertices[0] ==
nullptr || cascadeVertices[1] ==
nullptr)
ATH_MSG_ERROR(
"Error null vertex");
192 for(
int i =0;
i<topoN;
i++) Vtxwritehandles[
i]->push_back(cascadeVertices[
i]);
194 x->setSVOwnership(
false);
195 const auto mainVertex = cascadeVertices[1];
196 const std::vector< std::vector<TLorentzVector> > &moms =
x->getParticleMoms();
199 std::vector<const xAOD::Vertex*> verticestoLink;
200 verticestoLink.push_back(cascadeVertices[0]);
201 if(Vtxwritehandles[1] ==
nullptr)
ATH_MSG_ERROR(
"Vtxwritehandles[1] is null");
206 const xAOD::Vertex* MuPiVertex = BPhysPVCascadeTools::FindVertex<2>(MuPiContainer, cascadeVertices[1]);
207 ATH_MSG_DEBUG(
"1 pt mu+pi_soft tracks " << cascadeVertices[1]->trackParticle(0)->
pt() <<
", " << cascadeVertices[1]->trackParticle(1)->
pt());
211 const xAOD::Vertex* d0Vertex = BPhysPVCascadeTools::FindVertex<2>(d0Container, cascadeVertices[0]);;
212 ATH_MSG_DEBUG(
"1 pt D0 tracks " << cascadeVertices[0]->trackParticle(0)->
pt() <<
", " << cascadeVertices[0]->trackParticle(1)->
pt());
216 std::vector<const xAOD::Vertex*> MuPiVerticestoLink;
217 if (MuPiVertex) MuPiVerticestoLink.push_back(MuPiVertex);
222 std::vector<const xAOD::Vertex*> d0VerticestoLink;
223 if (d0Vertex) d0VerticestoLink.push_back(d0Vertex);
235 std::vector<double> massesMuPi;
238 std::vector<double> massesD0;
246 std::vector<double> Masses;
268 PtErr_decor(*mainVertex) =
m_CascadeTools->pTError(moms[1],
x->getCovariance()[1]);
270 chi2_decor(*mainVertex) =
x->fitChi2();
271 ndof_decor(*mainVertex) =
x->nDoF();
272 Chi2Mu_decor(*mainVertex) = cascadeVertices[1]->trackParticle(0)->chiSquared();
273 nDoFMu_decor(*mainVertex) = cascadeVertices[1]->trackParticle(0)->numberDoF();
276 std::vector< Trk::VxTrackAtVertex > trkAtB = cascadeVertices[1]->vxTrackAtVertex();
277 MuChi2B_decor(*mainVertex) = trkAtB.at(0).trackQuality().chiSquared();
278 MunDoFB_decor(*mainVertex) = trkAtB.at(0).trackQuality().numberDoF();
282 TLorentzVector p4_mu1, p4_pi_s;
289 massMuPi = (p4_mu1 + p4_pi_s).M();
293 massMuPi_decor(*mainVertex) = massMuPi;
297 TLorentzVector p4_ka, p4_pi;
320 MassMuPiAft_decor(*mainVertex) = (moms[1][0] + moms[1][1]).M();
321 MassPiD0_decor(*mainVertex) = (moms[1][1] + moms[0][0] + moms[0][1]).M();
322 MassKpi_svdecor(*mainVertex) = (moms[0][0] + moms[0][1]).M();
323 MassMuPiPiK_decor(*mainVertex) =
m_CascadeTools->invariantMass(moms[1]);
329 Mass_svdecor(*mainVertex) =
m_CascadeTools->invariantMass(moms[0]);
330 MassErr_svdecor(*mainVertex) =
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0]);
332 PtErr_svdecor(*mainVertex) =
m_CascadeTools->pTError(moms[0],
x->getCovariance()[0]);
333 Lxy_svdecor(*mainVertex) =
m_CascadeTools->lxy(moms[0],cascadeVertices[0],cascadeVertices[1]);
334 LxyErr_svdecor(*mainVertex) =
m_CascadeTools->lxyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1]);
335 Tau_svdecor(*mainVertex) =
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1]);
336 TauErr_svdecor(*mainVertex) =
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1]);
341 <<
" chi2_1 " <<
m_V0Tools->chisq(cascadeVertices[0])
342 <<
" chi2_2 " <<
m_V0Tools->chisq(cascadeVertices[1])
346 <<
" error " <<
m_V0Tools->invariantMassError(cascadeVertices[0],massesD0)
347 <<
" mass_J " <<
m_V0Tools->invariantMass(cascadeVertices[1],massesMuPi)
348 <<
" error " <<
m_V0Tools->invariantMassError(cascadeVertices[1],massesMuPi));
352 double Mass_B_err =
m_CascadeTools->invariantMassError(moms[1],
x->getCovariance()[1]);
353 double Mass_D0_err =
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0]);
354 ATH_MSG_DEBUG(
"Mass_B " << Mass_B <<
" Mass_D0 " << Mass_D0);
355 ATH_MSG_DEBUG(
"Mass_B_err " << Mass_B_err <<
" Mass_D0_err " << Mass_D0_err);
357 double mprob_D0 =
m_CascadeTools->massProbability(mass_d0,Mass_D0,Mass_D0_err);
358 ATH_MSG_DEBUG(
"mprob_B " << mprob_B <<
" mprob_D0 " << mprob_D0);
361 <<
" Mass_d0 " <<
m_CascadeTools->invariantMass(moms[0],massesD0));
363 <<
" Mass_d0_err " <<
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0],massesD0));
366 <<
" pt_d0 " <<
m_V0Tools->pT(cascadeVertices[0]));
368 <<
" ptErr_d " <<
m_CascadeTools->pTError(moms[0],
x->getCovariance()[0])
369 <<
" ptErr_d0 " <<
m_V0Tools->pTError(cascadeVertices[0]));
373 <<
" lxyErr_d " <<
m_CascadeTools->lxyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
374 <<
" lxyErr_d0 " <<
m_V0Tools->lxyError(cascadeVertices[0],cascadeVertices[1]));
376 <<
" tau_d0 " <<
m_V0Tools->tau(cascadeVertices[0],cascadeVertices[1],massesD0));
378 <<
" tau_d " <<
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1])
379 <<
" tau_D " <<
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1],mass_d0));
381 <<
" tauErr_d " <<
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
382 <<
" tauErr_d0 " <<
m_V0Tools->tauError(cascadeVertices[0],cascadeVertices[1],massesD0));
384 <<
" TauErr_d " <<
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1],mass_d0)
385 <<
" TauErr_d0 " <<
m_V0Tools->tauError(cascadeVertices[0],cascadeVertices[1],massesD0,mass_d0));
387 ATH_MSG_DEBUG(
"CascadeTools main vert wrt PV " <<
" CascadeTools SV " <<
" V0Tools SV");
389 <<
", " <<
m_CascadeTools->a0z(moms[0],cascadeVertices[0],cascadeVertices[1])
390 <<
", " <<
m_V0Tools->a0z(cascadeVertices[0],cascadeVertices[1]));
392 <<
", " <<
m_CascadeTools->a0zError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
393 <<
", " <<
m_V0Tools->a0zError(cascadeVertices[0],cascadeVertices[1]));
395 <<
", " <<
m_CascadeTools->a0xy(moms[0],cascadeVertices[0],cascadeVertices[1])
396 <<
", " <<
m_V0Tools->a0xy(cascadeVertices[0],cascadeVertices[1]));
398 <<
", " <<
m_CascadeTools->a0xyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
399 <<
", " <<
m_V0Tools->a0xyError(cascadeVertices[0],cascadeVertices[1]));
401 <<
", " <<
m_CascadeTools->a0(moms[0],cascadeVertices[0],cascadeVertices[1])
402 <<
", " <<
m_V0Tools->a0(cascadeVertices[0],cascadeVertices[1]));
404 <<
", " <<
m_CascadeTools->a0Error(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
405 <<
", " <<
m_V0Tools->a0Error(cascadeVertices[0],cascadeVertices[1]));
408 ATH_MSG_DEBUG(
"X0 " << primaryVertex->
x() <<
" Y0 " << primaryVertex->
y() <<
" Z0 " << primaryVertex->
z());
411 ATH_MSG_DEBUG(
"Rxy0 wrt PV " <<
m_V0Tools->rxy(cascadeVertices[0],primaryVertex) <<
" RxyErr0 wrt PV " <<
m_V0Tools->rxyError(cascadeVertices[0],primaryVertex));
412 ATH_MSG_DEBUG(
"Rxy1 wrt PV " <<
m_V0Tools->rxy(cascadeVertices[1],primaryVertex) <<
" RxyErr1 wrt PV " <<
m_V0Tools->rxyError(cascadeVertices[1],primaryVertex));
413 ATH_MSG_DEBUG(
"number of covariance matrices " << (
x->getCovariance()).size());
418 for (
auto x : cascadeinfoContainer)
delete x;
420 return StatusCode::SUCCESS;
425 m_vertexContainerKey(
""),
426 m_vertexD0ContainerKey(
""),
427 m_cascadeOutputsKeys{
"MuPlusDpstCascadeVtx1",
"MuPlusDpstCascadeVtx2" },
428 m_VxPrimaryCandidateName(
"PrimaryVertices"),
429 m_MuPiMassLower(0.0),
430 m_MuPiMassUpper(10000.0),
432 m_D0MassUpper(10000.0),
434 m_DstMassUpper(10000.0),
435 m_DstMassUpperAft(10000.0),
437 m_MassUpper(20000.0),
440 m_vtx0Daug1MassHypo(-1),
441 m_vtx0Daug2MassHypo(-1),
442 m_vtx1Daug1MassHypo(-1),
443 m_vtx1Daug2MassHypo(-1),
448 m_iVertexFitter(
"Trk::TrkVKalVrtFitter"),
449 m_pvRefitter(
"Analysis::PrimaryVertexRefitter",
this),
450 m_V0Tools(
"Trk::V0Tools"),
451 m_CascadeTools(
"DerivationFramework::CascadeTools")
453 declareProperty(
"MuPiVertices", m_vertexContainerKey);
454 declareProperty(
"D0Vertices", m_vertexD0ContainerKey);
455 declareProperty(
"VxPrimaryCandidateName", m_VxPrimaryCandidateName);
456 declareProperty(
"RefPVContainerName", m_refPVContainerName =
"RefittedPrimaryVertices");
457 declareProperty(
"MuPiMassLowerCut", m_MuPiMassLower);
458 declareProperty(
"MuPiMassUpperCut", m_MuPiMassUpper);
459 declareProperty(
"D0MassLowerCut", m_D0MassLower);
460 declareProperty(
"D0MassUpperCut", m_D0MassUpper);
461 declareProperty(
"DstMassLowerCut", m_DstMassLower);
462 declareProperty(
"DstMassUpperCut", m_DstMassUpper);
463 declareProperty(
"DstMassUpperCutAft", m_DstMassUpperAft);
464 declareProperty(
"MassLowerCut", m_MassLower);
465 declareProperty(
"MassUpperCut", m_MassUpper);
466 declareProperty(
"HypothesisName", m_hypoName =
"B");
467 declareProperty(
"Vtx0MassHypo", m_vtx0MassHypo);
468 declareProperty(
"Vtx1MassHypo", m_vtx1MassHypo);
469 declareProperty(
"Vtx0Daug1MassHypo", m_vtx0Daug1MassHypo);
470 declareProperty(
"Vtx0Daug2MassHypo", m_vtx0Daug2MassHypo);
471 declareProperty(
"Vtx0Daug3MassHypo", m_vtx0Daug2MassHypo);
472 declareProperty(
"Vtx1Daug1MassHypo", m_vtx1Daug1MassHypo);
473 declareProperty(
"Vtx1Daug2MassHypo", m_vtx1Daug2MassHypo);
474 declareProperty(
"DxHypothesis", m_Dx_pid);
475 declareProperty(
"ApplyD0MassConstraint", m_constrD0);
476 declareProperty(
"ApplyMuPiMassConstraint", m_constrMuPi);
477 declareProperty(
"Chi2Cut", m_chi2cut);
478 declareProperty(
"RefitPV", m_refitPV =
true);
479 declareProperty(
"MaxnPV", m_PV_max = 999);
480 declareProperty(
"MinNTracksInPV", m_PV_minNTracks = 0);
481 declareProperty(
"DoVertexType", m_DoVertexType = 7);
482 declareProperty(
"TrkVertexFitterTool", m_iVertexFitter);
483 declareProperty(
"PVRefitter", m_pvRefitter);
484 declareProperty(
"V0Tools", m_V0Tools);
485 declareProperty(
"CascadeTools", m_CascadeTools);
486 declareProperty(
"CascadeVertexCollections", m_cascadeOutputsKeys);
494 assert(cascadeinfoContainer!=
nullptr);
509 std::vector<const xAOD::TrackParticle*> tracksMuPi;
510 std::vector<const xAOD::TrackParticle*> tracksD0;
511 std::vector<double> massesMuPi;
514 std::vector<double> massesD0;
517 std::vector<double> massesD0b;
520 std::vector<double> Masses;
528 std::vector<const xAOD::Vertex*> selectedMuPiCandidates;
529 for (
auto vxcItr : *MuPiContainer ){
531 TLorentzVector p4Mup_in, p4Mum_in;
532 p4Mup_in.SetPtEtaPhiM(vxcItr->trackParticle(0)->pt(),
533 vxcItr->trackParticle(0)->eta(),
535 p4Mum_in.SetPtEtaPhiM(vxcItr->trackParticle(1)->pt(),
536 vxcItr->trackParticle(1)->eta(),
538 double mass_MuPi = (p4Mup_in + p4Mum_in).M();
541 ATH_MSG_DEBUG(
" Original mu & pi_soft candidate rejected by the mass cut: mass = "
549 ATH_MSG_DEBUG(
" Original mu & pi_soft candidate rejected by the track's cut level - loose");
553 selectedMuPiCandidates.push_back(vxcItr);
555 if(selectedMuPiCandidates.size()<1)
return StatusCode::SUCCESS;
558 std::vector<const xAOD::Vertex*> selectedD0Candidates;
559 for(
auto vxcItr : *d0Container){
567 if(!flagAcc1(*vtx)) isD0 =
false;
570 if(!flagAcc2(*vtx)) isD0b =
false;
572 if(!(isD0||isD0b))
continue;
576 ATH_MSG_DEBUG(
" Original D0/D0-bar candidate rejected by the track's cut level - loose ");
580 ATH_MSG_DEBUG(
" Original D0/D0-bar candidate rejected by the track's cut level - loose ");
586 if (vxcItr->trackParticle(0)->charge() != 1 || vxcItr->trackParticle(1)->charge() != -1) {
587 ATH_MSG_DEBUG(
" Original D0/D0-bar candidate rejected by the charge requirement: "
588 << vxcItr->trackParticle(0)->charge() <<
", " << vxcItr->trackParticle(1)->charge() );
593 double mass_D0 =
m_V0Tools->invariantMass(vxcItr,massesD0);
594 double mass_D0b =
m_V0Tools->invariantMass(vxcItr,massesD0b);
595 ATH_MSG_DEBUG(
"D0 mass " << mass_D0 <<
", D0b mass "<<mass_D0b);
597 ATH_MSG_DEBUG(
" Original D0/D0-bar candidate rejected by the mass cut: mass = "
603 selectedD0Candidates.push_back(vxcItr);
605 if(selectedD0Candidates.size()<1)
return StatusCode::SUCCESS;
609 for(
auto MuPiItr:selectedMuPiCandidates){
610 size_t MuPiTrkNum = MuPiItr->nTrackParticles();
613 for(
unsigned int it=0;
it<MuPiTrkNum;
it++) tracksMuPi.push_back(MuPiItr->trackParticle(
it));
615 if (tracksMuPi.size() != 2 || massesMuPi.size() != 2 ) {
620 if(std::abs(
m_Dx_pid)==421 && MuPiItr->trackParticle(1)->charge()==-1) tagD0 =
false;
622 TLorentzVector p4_pi1;
623 p4_pi1.SetPtEtaPhiM(MuPiItr->trackParticle(1)->pt(),
624 MuPiItr->trackParticle(1)->eta(),
627 for(
auto d0Itr : selectedD0Candidates){
630 if(
std::find(tracksMuPi.cbegin(), tracksMuPi.cend(), d0Itr->trackParticle(0)) != tracksMuPi.cend())
continue;
631 if(
std::find(tracksMuPi.cbegin(), tracksMuPi.cend(), d0Itr->trackParticle(1)) != tracksMuPi.cend())
continue;
633 TLorentzVector p4_ka, p4_pi2;
635 p4_pi2.SetPtEtaPhiM(d0Itr->trackParticle(0)->pt(),
636 d0Itr->trackParticle(0)->eta(),
638 p4_ka.SetPtEtaPhiM( d0Itr->trackParticle(1)->pt(),
639 d0Itr->trackParticle(1)->eta(),
642 p4_pi2.SetPtEtaPhiM(d0Itr->trackParticle(1)->pt(),
643 d0Itr->trackParticle(1)->eta(),
645 p4_ka.SetPtEtaPhiM( d0Itr->trackParticle(0)->pt(),
646 d0Itr->trackParticle(0)->eta(),
650 double mass_Dst= (p4_pi1 + p4_ka + p4_pi2).M();
653 ATH_MSG_DEBUG(
" Original D*+/- candidate rejected by the mass cut: mass = "
658 size_t d0TrkNum = d0Itr->nTrackParticles();
660 for(
unsigned int it=0;
it<d0TrkNum;
it++) tracksD0.push_back(d0Itr->trackParticle(
it));
661 if (tracksD0.size() != 2 || massesD0.size() != 2 ) {
678 std::vector<Trk::VertexID> vrtList;
682 if(tagD0) vID =
m_iVertexFitter->startVertex(tracksD0,massesD0, *state,mass_d0);
683 else vID =
m_iVertexFitter->startVertex(tracksD0,massesD0b, *state,mass_d0);
685 if(tagD0) vID =
m_iVertexFitter->startVertex(tracksD0, massesD0,*state);
688 vrtList.push_back(vID);
692 std::vector<Trk::VertexID> cnstV;
707 << ((
result->vertices())[0])->trackParticle(1) <<
", "
708 << ((
result->vertices())[1])->trackParticle(0) <<
", "
709 << ((
result->vertices())[1])->trackParticle(1));
711 result->setSVOwnership(
true);
718 const std::vector< std::vector<TLorentzVector> > &moms =
result->getParticleMoms();
719 const std::vector<xAOD::Vertex*> &cascadeVertices =
result->vertices();
722 double DstMassAft = (moms[1][1] + moms[0][0] + moms[0][1]).M();
727 if (
m_CascadeTools->lxy(moms[0],cascadeVertices[0],cascadeVertices[1]) > 0){
730 cascadeinfoContainer->push_back(
result.release());
745 ATH_MSG_DEBUG(
"cascadeinfoContainer size " << cascadeinfoContainer->size());
746 return StatusCode::SUCCESS;