17 #include "HepPDT/ParticleDataTable.hh"
25 typedef std::vector<const xAOD::TrackParticle*>
TrackBag;
56 return StatusCode::SUCCESS;
62 std::vector<Trk::VxCascadeInfo*> cascadeinfoContainer;
63 constexpr
int topoN = 2;
64 std::array<xAOD::VertexContainer*, topoN> Vtxwritehandles;
65 std::array<xAOD::VertexAuxContainer*, topoN> Vtxwritehandlesaux;
68 for(
int i =0;
i<topoN;
i++){
71 Vtxwritehandles[
i]->setStore(Vtxwritehandlesaux[
i]);
84 if (pvContainer->
size()==0){
86 return StatusCode::RECOVERABLE;
88 primaryVertex = (*pvContainer)[0];
105 refPvContainer->setStore(refPvAuxContainer);
140 ATH_MSG_DEBUG(
"cascadeinfoContainer size " << cascadeinfoContainer.size());
152 return StatusCode::FAILURE;
173 const std::vector<xAOD::Vertex*> &cascadeVertices =
x->vertices();
174 if(cascadeVertices.size()!=topoN)
176 if(cascadeVertices[0] ==
nullptr || cascadeVertices[1] ==
nullptr)
ATH_MSG_ERROR(
"Error null vertex");
178 for(
int i =0;
i<topoN;
i++) Vtxwritehandles[
i]->push_back(cascadeVertices[
i]);
180 x->setSVOwnership(
false);
181 const auto mainVertex = cascadeVertices[1];
182 const std::vector< std::vector<TLorentzVector> > &moms =
x->getParticleMoms();
185 std::vector<const xAOD::Vertex*> verticestoLink;
186 verticestoLink.push_back(cascadeVertices[0]);
187 if(Vtxwritehandles[1] ==
nullptr)
ATH_MSG_ERROR(
"Vtxwritehandles[1] is null");
192 const xAOD::Vertex* jpsipiVertex = BPhysPVCascadeTools::FindVertex<3>(jpsipiContainer, cascadeVertices[1]);
193 ATH_MSG_DEBUG(
"1 pt Jpsi+pi tracks " << cascadeVertices[1]->trackParticle(0)->
pt() <<
", " << cascadeVertices[1]->trackParticle(1)->
pt() <<
", " << cascadeVertices[1]->trackParticle(2)->
pt());
197 const xAOD::Vertex* d0Vertex = BPhysPVCascadeTools::FindVertex<2>(d0Container, cascadeVertices[0]);;
198 ATH_MSG_DEBUG(
"1 pt D0 tracks " << cascadeVertices[0]->trackParticle(0)->
pt() <<
", " << cascadeVertices[0]->trackParticle(1)->
pt());
202 std::vector<const xAOD::Vertex*> jpsipiVerticestoLink;
203 if (jpsipiVertex) jpsipiVerticestoLink.push_back(jpsipiVertex);
208 std::vector<const xAOD::Vertex*> d0VerticestoLink;
209 if (d0Vertex) d0VerticestoLink.push_back(d0Vertex);
221 std::vector<double> massesJpsipi;
225 std::vector<double> massesD0;
233 std::vector<double> Masses;
255 PtErr_decor(*mainVertex) =
m_CascadeTools->pTError(moms[1],
x->getCovariance()[1]);
257 chi2_decor(*mainVertex) =
x->fitChi2();
258 ndof_decor(*mainVertex) =
x->nDoF();
262 TLorentzVector p4_mu1, p4_mu2;
269 massMumu = (p4_mu1 + p4_mu2).M();
271 MassMumu_decor(*mainVertex) = massMumu;
275 TLorentzVector p4_ka, p4_pi;
291 massKpi = (p4_ka + p4_pi).M();
293 MassKpi_svdecor(*mainVertex) = massKpi;
294 MassJpsi_decor(*mainVertex) = (moms[1][0] + moms[1][1]).M();
295 MassPiD0_decor(*mainVertex) = (moms[1][2] + moms[1][3]).M();
303 Mass_svdecor(*mainVertex) =
m_CascadeTools->invariantMass(moms[0]);
304 MassErr_svdecor(*mainVertex) =
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0]);
306 PtErr_svdecor(*mainVertex) =
m_CascadeTools->pTError(moms[0],
x->getCovariance()[0]);
307 Lxy_svdecor(*mainVertex) =
m_CascadeTools->lxy(moms[0],cascadeVertices[0],cascadeVertices[1]);
308 LxyErr_svdecor(*mainVertex) =
m_CascadeTools->lxyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1]);
309 Tau_svdecor(*mainVertex) =
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1]);
310 TauErr_svdecor(*mainVertex) =
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1]);
314 <<
" chi2_1 " <<
m_V0Tools->chisq(cascadeVertices[0])
315 <<
" chi2_2 " <<
m_V0Tools->chisq(cascadeVertices[1])
319 <<
" error " <<
m_V0Tools->invariantMassError(cascadeVertices[0],massesD0)
320 <<
" mass_J " <<
m_V0Tools->invariantMass(cascadeVertices[1],massesJpsipi)
321 <<
" error " <<
m_V0Tools->invariantMassError(cascadeVertices[1],massesJpsipi));
325 double Mass_B_err =
m_CascadeTools->invariantMassError(moms[1],
x->getCovariance()[1]);
326 double Mass_D0_err =
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0]);
327 ATH_MSG_DEBUG(
"Mass_B " << Mass_B <<
" Mass_D0 " << Mass_D0);
328 ATH_MSG_DEBUG(
"Mass_B_err " << Mass_B_err <<
" Mass_D0_err " << Mass_D0_err);
330 double mprob_D0 =
m_CascadeTools->massProbability(mass_d0,Mass_D0,Mass_D0_err);
331 ATH_MSG_DEBUG(
"mprob_B " << mprob_B <<
" mprob_D0 " << mprob_D0);
334 <<
" Mass_d0 " <<
m_CascadeTools->invariantMass(moms[0],massesD0));
336 <<
" Mass_d0_err " <<
m_CascadeTools->invariantMassError(moms[0],
x->getCovariance()[0],massesD0));
339 <<
" pt_d0 " <<
m_V0Tools->pT(cascadeVertices[0]));
341 <<
" ptErr_d " <<
m_CascadeTools->pTError(moms[0],
x->getCovariance()[0])
342 <<
" ptErr_d0 " <<
m_V0Tools->pTError(cascadeVertices[0]));
346 <<
" lxyErr_d " <<
m_CascadeTools->lxyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
347 <<
" lxyErr_d0 " <<
m_V0Tools->lxyError(cascadeVertices[0],cascadeVertices[1]));
349 <<
" tau_d0 " <<
m_V0Tools->tau(cascadeVertices[0],cascadeVertices[1],massesD0));
351 <<
" tau_d " <<
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1])
352 <<
" tau_D " <<
m_CascadeTools->tau(moms[0],cascadeVertices[0],cascadeVertices[1],mass_d0));
354 <<
" tauErr_d " <<
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
355 <<
" tauErr_d0 " <<
m_V0Tools->tauError(cascadeVertices[0],cascadeVertices[1],massesD0));
357 <<
" TauErr_d " <<
m_CascadeTools->tauError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1],mass_d0)
358 <<
" TauErr_d0 " <<
m_V0Tools->tauError(cascadeVertices[0],cascadeVertices[1],massesD0,mass_d0));
360 ATH_MSG_DEBUG(
"CascadeTools main vert wrt PV " <<
" CascadeTools SV " <<
" V0Tools SV");
362 <<
", " <<
m_CascadeTools->a0z(moms[0],cascadeVertices[0],cascadeVertices[1])
363 <<
", " <<
m_V0Tools->a0z(cascadeVertices[0],cascadeVertices[1]));
365 <<
", " <<
m_CascadeTools->a0zError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
366 <<
", " <<
m_V0Tools->a0zError(cascadeVertices[0],cascadeVertices[1]));
368 <<
", " <<
m_CascadeTools->a0xy(moms[0],cascadeVertices[0],cascadeVertices[1])
369 <<
", " <<
m_V0Tools->a0xy(cascadeVertices[0],cascadeVertices[1]));
371 <<
", " <<
m_CascadeTools->a0xyError(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
372 <<
", " <<
m_V0Tools->a0xyError(cascadeVertices[0],cascadeVertices[1]));
374 <<
", " <<
m_CascadeTools->a0(moms[0],cascadeVertices[0],cascadeVertices[1])
375 <<
", " <<
m_V0Tools->a0(cascadeVertices[0],cascadeVertices[1]));
377 <<
", " <<
m_CascadeTools->a0Error(moms[0],
x->getCovariance()[0],cascadeVertices[0],cascadeVertices[1])
378 <<
", " <<
m_V0Tools->a0Error(cascadeVertices[0],cascadeVertices[1]));
381 ATH_MSG_DEBUG(
"X0 " << primaryVertex->
x() <<
" Y0 " << primaryVertex->
y() <<
" Z0 " << primaryVertex->
z());
384 ATH_MSG_DEBUG(
"Rxy0 wrt PV " <<
m_V0Tools->rxy(cascadeVertices[0],primaryVertex) <<
" RxyErr0 wrt PV " <<
m_V0Tools->rxyError(cascadeVertices[0],primaryVertex));
385 ATH_MSG_DEBUG(
"Rxy1 wrt PV " <<
m_V0Tools->rxy(cascadeVertices[1],primaryVertex) <<
" RxyErr1 wrt PV " <<
m_V0Tools->rxyError(cascadeVertices[1],primaryVertex));
386 ATH_MSG_DEBUG(
"number of covariance matrices " << (
x->getCovariance()).size());
391 for (
auto x : cascadeinfoContainer)
delete x;
393 return StatusCode::SUCCESS;
398 m_vertexContainerKey(
""),
399 m_vertexD0ContainerKey(
""),
400 m_cascadeOutputsKeys{
"JpsiPlusDpstCascadeVtx1",
"JpsiPlusDpstCascadeVtx2" },
401 m_VxPrimaryCandidateName(
"PrimaryVertices"),
402 m_jpsiMassLower(0.0),
403 m_jpsiMassUpper(10000.0),
404 m_jpsipiMassLower(0.0),
405 m_jpsipiMassUpper(10000.0),
407 m_D0MassUpper(10000.0),
409 m_DstMassUpper(10000.0),
411 m_MassUpper(20000.0),
414 m_vtx0Daug1MassHypo(-1),
415 m_vtx0Daug2MassHypo(-1),
416 m_vtx0Daug3MassHypo(-1),
417 m_vtx1Daug1MassHypo(-1),
418 m_vtx1Daug2MassHypo(-1),
424 m_iVertexFitter(
"Trk::TrkVKalVrtFitter"),
425 m_pvRefitter(
"Analysis::PrimaryVertexRefitter"),
426 m_V0Tools(
"Trk::V0Tools"),
427 m_CascadeTools(
"DerivationFramework::CascadeTools")
429 declareProperty(
"JpsipiVertices", m_vertexContainerKey);
430 declareProperty(
"D0Vertices", m_vertexD0ContainerKey);
431 declareProperty(
"VxPrimaryCandidateName", m_VxPrimaryCandidateName);
432 declareProperty(
"RefPVContainerName", m_refPVContainerName =
"RefittedPrimaryVertices");
433 declareProperty(
"JpsiMassLowerCut", m_jpsiMassLower);
434 declareProperty(
"JpsiMassUpperCut", m_jpsiMassUpper);
435 declareProperty(
"JpsipiMassLowerCut", m_jpsipiMassLower);
436 declareProperty(
"JpsipiMassUpperCut", m_jpsipiMassUpper);
437 declareProperty(
"D0MassLowerCut", m_D0MassLower);
438 declareProperty(
"D0MassUpperCut", m_D0MassUpper);
439 declareProperty(
"DstMassLowerCut", m_DstMassLower);
440 declareProperty(
"DstMassUpperCut", m_DstMassUpper);
441 declareProperty(
"MassLowerCut", m_MassLower);
442 declareProperty(
"MassUpperCut", m_MassUpper);
443 declareProperty(
"HypothesisName", m_hypoName =
"Bc");
444 declareProperty(
"Vtx0MassHypo", m_vtx0MassHypo);
445 declareProperty(
"Vtx1MassHypo", m_vtx1MassHypo);
446 declareProperty(
"Vtx0Daug1MassHypo", m_vtx0Daug1MassHypo);
447 declareProperty(
"Vtx0Daug2MassHypo", m_vtx0Daug2MassHypo);
448 declareProperty(
"Vtx0Daug3MassHypo", m_vtx0Daug3MassHypo);
449 declareProperty(
"Vtx1Daug1MassHypo", m_vtx1Daug1MassHypo);
450 declareProperty(
"Vtx1Daug2MassHypo", m_vtx1Daug2MassHypo);
451 declareProperty(
"JpsiMass", m_mass_jpsi);
452 declareProperty(
"DxHypothesis", m_Dx_pid);
453 declareProperty(
"ApplyD0MassConstraint", m_constrD0);
454 declareProperty(
"ApplyJpsiMassConstraint", m_constrJpsi);
455 declareProperty(
"Chi2Cut", m_chi2cut);
456 declareProperty(
"RefitPV", m_refitPV =
true);
457 declareProperty(
"MaxnPV", m_PV_max = 999);
458 declareProperty(
"MinNTracksInPV", m_PV_minNTracks = 0);
459 declareProperty(
"DoVertexType", m_DoVertexType = 7);
460 declareProperty(
"TrkVertexFitterTool", m_iVertexFitter);
461 declareProperty(
"PVRefitter", m_pvRefitter);
462 declareProperty(
"V0Tools", m_V0Tools);
463 declareProperty(
"CascadeTools", m_CascadeTools);
464 declareProperty(
"CascadeVertexCollections", m_cascadeOutputsKeys);
472 assert(cascadeinfoContainer!=
nullptr);
487 std::vector<const xAOD::TrackParticle*> tracksJpsipi;
488 std::vector<const xAOD::TrackParticle*> tracksJpsi;
489 std::vector<const xAOD::TrackParticle*> tracksD0;
490 std::vector<const xAOD::TrackParticle*> tracksBc;
491 std::vector<double> massesJpsipi;
495 std::vector<double> massesD0;
498 std::vector<double> massesD0b;
501 std::vector<double> Masses;
508 std::vector<const xAOD::Vertex*> selectedJpsipiCandidates;
509 for(
auto vxcItr=jpsipiContainer->
cbegin(); vxcItr!=jpsipiContainer->
cend(); ++vxcItr) {
515 if(!flagAcc1(*vtx))
continue;
519 TLorentzVector p4Mup_in, p4Mum_in;
520 p4Mup_in.SetPtEtaPhiM((*vxcItr)->trackParticle(0)->pt(),
521 (*vxcItr)->trackParticle(0)->eta(),
523 p4Mum_in.SetPtEtaPhiM((*vxcItr)->trackParticle(1)->pt(),
524 (*vxcItr)->trackParticle(1)->eta(),
526 double mass_Jpsi = (p4Mup_in + p4Mum_in).M();
529 ATH_MSG_DEBUG(
" Original Jpsi candidate rejected by the mass cut: mass = "
535 double mass_Jpsipi =
m_V0Tools->invariantMass(*vxcItr, massesJpsipi);
538 ATH_MSG_DEBUG(
" Original Jpsipi candidate rejected by the mass cut: mass = "
543 selectedJpsipiCandidates.push_back(*vxcItr);
545 if(selectedJpsipiCandidates.size()<1)
return StatusCode::SUCCESS;
548 std::vector<const xAOD::Vertex*> selectedD0Candidates;
549 for(
auto vxcItr=d0Container->
cbegin(); vxcItr!=d0Container->
cend(); ++vxcItr) {
558 if(!flagAcc1(*vtx)) isD0 =
false;
561 if(!flagAcc2(*vtx)) isD0b =
false;
563 if(!(isD0||isD0b))
continue;
566 if ((*vxcItr)->trackParticle(0)->charge() != 1 || (*vxcItr)->trackParticle(1)->charge() != -1) {
567 ATH_MSG_DEBUG(
" Original D0/D0-bar candidate rejected by the charge requirement: "
568 << (*vxcItr)->trackParticle(0)->charge() <<
", " << (*vxcItr)->trackParticle(1)->charge() );
573 double mass_D0 =
m_V0Tools->invariantMass(*vxcItr,massesD0);
574 double mass_D0b =
m_V0Tools->invariantMass(*vxcItr,massesD0b);
575 ATH_MSG_DEBUG(
"D0 mass " << mass_D0 <<
", D0b mass "<<mass_D0b);
577 ATH_MSG_DEBUG(
" Original D0 candidate rejected by the mass cut: mass = "
583 selectedD0Candidates.push_back(*vxcItr);
585 if(selectedD0Candidates.size()<1)
return StatusCode::SUCCESS;
589 for(
auto jpsipiItr=selectedJpsipiCandidates.cbegin(); jpsipiItr!=selectedJpsipiCandidates.cend(); ++jpsipiItr) {
591 size_t jpsipiTrkNum = (*jpsipiItr)->nTrackParticles();
592 tracksJpsipi.clear();
594 for(
unsigned int it=0;
it<jpsipiTrkNum;
it++) tracksJpsipi.push_back((*jpsipiItr)->trackParticle(
it));
595 for(
unsigned int it=0;
it<jpsipiTrkNum-1;
it++) tracksJpsi.push_back((*jpsipiItr)->trackParticle(
it));
597 if (tracksJpsipi.size() != 3 || massesJpsipi.size() != 3 ) {
602 if(abs(
m_Dx_pid)==421 && (*jpsipiItr)->trackParticle(2)->charge()==-1) tagD0 =
false;
604 TLorentzVector p4_pi1;
605 p4_pi1.SetPtEtaPhiM((*jpsipiItr)->trackParticle(2)->pt(),
606 (*jpsipiItr)->trackParticle(2)->eta(),
610 for(
auto d0Itr=selectedD0Candidates.cbegin(); d0Itr!=selectedD0Candidates.cend(); ++d0Itr) {
613 if(
std::find(tracksJpsipi.cbegin(), tracksJpsipi.cend(), (*d0Itr)->trackParticle(0)) != tracksJpsipi.cend())
continue;
614 if(
std::find(tracksJpsipi.cbegin(), tracksJpsipi.cend(), (*d0Itr)->trackParticle(1)) != tracksJpsipi.cend())
continue;
617 TLorentzVector p4_ka, p4_pi2;
619 p4_pi2.SetPtEtaPhiM((*d0Itr)->trackParticle(0)->pt(),
620 (*d0Itr)->trackParticle(0)->eta(),
622 p4_ka.SetPtEtaPhiM( (*d0Itr)->trackParticle(1)->pt(),
623 (*d0Itr)->trackParticle(1)->eta(),
626 p4_pi2.SetPtEtaPhiM((*d0Itr)->trackParticle(1)->pt(),
627 (*d0Itr)->trackParticle(1)->eta(),
629 p4_ka.SetPtEtaPhiM( (*d0Itr)->trackParticle(0)->pt(),
630 (*d0Itr)->trackParticle(0)->eta(),
634 double mass_Dst= (p4_pi1 + p4_ka + p4_pi2).M();
637 ATH_MSG_DEBUG(
" Original D*+/- candidate rejected by the mass cut: mass = "
642 size_t d0TrkNum = (*d0Itr)->nTrackParticles();
644 for(
unsigned int it=0;
it<d0TrkNum;
it++) tracksD0.push_back((*d0Itr)->trackParticle(
it));
645 if (tracksD0.size() != 2 || massesD0.size() != 2 ) {
649 ATH_MSG_DEBUG(
"using tracks" << tracksJpsipi[0] <<
", " << tracksJpsipi[1] <<
", " << tracksJpsipi[2] <<
", " << tracksD0[0] <<
", " << tracksD0[1]);
650 ATH_MSG_DEBUG(
"Charge of Jpsi+pi tracks: "<<(*jpsipiItr)->trackParticle(0)->charge()<<
", "<<(*jpsipiItr)->trackParticle(1)->charge()<<
", "<<(*jpsipiItr)->trackParticle(2)->charge());
651 ATH_MSG_DEBUG(
"Charge of D0 tracks: "<<(*d0Itr)->trackParticle(0)->charge()<<
", "<<(*d0Itr)->trackParticle(1)->charge());
654 for(
unsigned int it=0;
it<jpsipiTrkNum;
it++) tracksBc.push_back((*jpsipiItr)->trackParticle(
it));
655 for(
unsigned int it=0;
it<d0TrkNum;
it++) tracksBc.push_back((*d0Itr)->trackParticle(
it));
666 std::vector<Trk::VertexID> vrtList;
670 if(tagD0) vID =
m_iVertexFitter->startVertex(tracksD0,massesD0,*state,mass_d0);
671 else vID =
m_iVertexFitter->startVertex(tracksD0,massesD0b,*state,mass_d0);
673 if(tagD0) vID =
m_iVertexFitter->startVertex(tracksD0,massesD0,*state);
676 vrtList.push_back(vID);
680 std::vector<Trk::VertexID> cnstV;
695 << ((
result->vertices())[0])->trackParticle(1) <<
", "
696 << ((
result->vertices())[1])->trackParticle(0) <<
", "
697 << ((
result->vertices())[1])->trackParticle(1) <<
", "
698 << ((
result->vertices())[1])->trackParticle(2));
700 result->setSVOwnership(
true);
707 const std::vector< std::vector<TLorentzVector> > &moms =
result->getParticleMoms();
711 cascadeinfoContainer->push_back(
result.release());
723 ATH_MSG_DEBUG(
"cascadeinfoContainer size " << cascadeinfoContainer->size());
725 return StatusCode::SUCCESS;