24 #include "HepPDT/ParticleDataTable.hh"
38 declareInterface<InDetV0FinderTool>(
this);
122 std::string BDTPathName =
"InDetV0FinderTool/BDT/v1/" +
m_BDTFile;
125 std::unique_ptr<TFile>
rootFile(TFile::Open(fullPathToFile.c_str(),
"READ"));
126 std::string strBDTName =
"xgboost";
127 std::unique_ptr<TTree> training( (TTree*)
rootFile->Get(strBDTName.c_str()) );
128 m_BDT = std::make_unique<MVAUtils::BDT>(training.get());
134 for (
const std::string
beam : {
"beamPosX",
"beamPosY",
"beamPosZ"}) {
173 ATH_MSG_FATAL(
"The vertex fitter passed is not a V0 Vertex Fitter");
174 return StatusCode::FAILURE;
182 return StatusCode::SUCCESS;
191 const EventContext& ctx
196 std::vector<const xAOD::TrackParticleContainer*> trackCols;
199 trackCols.push_back(handle.
cptr());
206 if (!vertices.isValid())
209 return StatusCode::SUCCESS;
214 if ( !TPC.isValid() )
217 return StatusCode::SUCCESS;
219 ATH_MSG_DEBUG(
"Track particle container size " << TPC->size());
227 beamspot = beamSpotHandle->beamPos();
232 beamspot =
Amg::Vector3D(beamPosX(0), beamPosY(0), beamPosZ(0));
235 std::vector<const xAOD::TrackParticle*> posTracks; posTracks.clear();
236 std::vector<const xAOD::TrackParticle*> negTracks; negTracks.clear();
238 if (
m_pv && primaryVertex) vx = primaryVertex;
240 if (TPC->size() > 1) {
242 for ( tpIt=TPC->begin(); tpIt!=TPC->end(); ++tpIt )
253 for (
const auto *
const vx : *vertices)
263 if (foundVertex)
break;
266 bool useTrack =
false;
268 if (
m_useorigin && foundVertex ==
nullptr) useTrack =
true;
269 if (!useTrack)
continue;
273 bool d0wrtVertex =
true;
275 if ( !
d0Pass(TP,vertColl, ctx) ) d0wrtVertex =
false;
279 if ( !
d0Pass(TP,primaryVertex, ctx) ) d0wrtVertex =
false;
281 if ( !
d0Pass(TP,beamspot, ctx) ) d0wrtVertex =
false;
284 if (!d0wrtVertex)
continue;
287 posTracks.push_back(TP);
288 negTracks.push_back(TP);
291 posTracks.push_back(*tpIt);
293 negTracks.push_back(*tpIt);
299 ATH_MSG_DEBUG(
"number of tracks passing preselection, positive " << posTracks.size() <<
" negative " << negTracks.size());
301 if (!posTracks.empty() && !negTracks.empty())
318 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt1;
319 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt2;
321 for (tpIt1 = posTracks.begin(); tpIt1 != posTracks.end(); ++tpIt1)
328 double pt1 = TP1->
pt();
331 for (tpIt2 = negTracks.begin(); tpIt2 != negTracks.end(); ++tpIt2)
333 if (*tpIt1 == *tpIt2)
continue;
341 ATH_MSG_DEBUG(
"nclus1 " << (
int)nclus1 <<
" nclus2 " << (
int)nclus2);
346 double pt2 = TP2->
pt();
348 bool trk_cut1 =
false;
349 bool trk_cut2 =
false;
350 if (nclus1 != 0) trk_cut1 =
true;
351 if (nclus1 == 0 && pt1 >=
m_ptTRT) trk_cut1 =
true;
352 if (!trk_cut1)
continue;
353 if (nclus2 != 0) trk_cut2 =
true;
354 if (nclus2 == 0 && pt2 >=
m_ptTRT) trk_cut2 =
true;
355 if (!trk_cut2)
continue;
363 if (errorcode != 0) {startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
364 bool errorCode =
false;
365 if (errorcode == 0 || errorcode == 5 || errorcode == 6 || errorcode == 8) errorCode =
true;
366 if (!errorCode)
continue;
369 bool d0wrtVertex =
true;
371 if ( !
d0Pass(TP1,TP2,vertColl, ctx) ) d0wrtVertex =
false;
373 if (!d0wrtVertex)
continue;
377 if (
doFit(TP1,TP2,startingPoint, ctx) )
379 std::vector<const xAOD::TrackParticle*> pairV0;
381 pairV0.push_back(TP1);
382 pairV0.push_back(TP2);
387 std::unique_ptr<xAOD::Vertex> myVxCandidate;
391 myVxCandidate = std::unique_ptr<xAOD::Vertex>(
m_iVKVertexFitter->fit(pairV0, startingPoint) );
399 bool doKshortFit =
false;
400 doKshortFit =
doMassFit(myVxCandidate.get(),310);
401 bool doLambdaFit =
false;
402 doLambdaFit =
doMassFit(myVxCandidate.get(),3122);
403 bool doLambdabarFit =
false;
404 doLambdabarFit =
doMassFit(myVxCandidate.get(),-3122);
406 if (doKshortFit || doLambdaFit || doLambdabarFit)
408 bool pointAtVert =
true;
420 std::unique_ptr<xAOD::Vertex> myKshort;
421 std::unique_ptr<xAOD::Vertex> myLambda;
422 std::unique_ptr<xAOD::Vertex> myLambdabar;
423 std::unique_ptr<xAOD::Vertex> myGamma;
424 bool foundKshort =
false;
425 bool foundLambda =
false;
426 bool foundLambdabar =
false;
429 myKshort = std::unique_ptr<xAOD::Vertex>(
massFit(310, pairV0, vertex) );
439 myLambda = std::unique_ptr<xAOD::Vertex>(
massFit(3122, pairV0, vertex) );
449 myLambdabar = std::unique_ptr<xAOD::Vertex>(
massFit(-3122, pairV0, vertex));
453 foundLambdabar =
true;
458 bool doGamma =
false;
460 double gamma_prob = -1., gamma_mass = -1., gamma_massErr = -1.;
461 if (foundKshort || foundLambda || foundLambdabar) doGamma =
true;
475 v0Container->
push_back(myVxCandidate.release());
477 v0_BDTScore( *(v0Container->
back()) ) =
score;
486 ksContainer->
push_back(myKshort.release());
490 v0LinksDecorks(*(ksContainer->
back())) = v0Link;
494 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
496 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
505 laContainer->
push_back(myLambda.release());
509 v0LinksDecorlb(*(laContainer->
back())) = v0Link;
513 v0_laLinksDecor(*(v0Container->
back())) = laLink;
515 v0_laLinksDecor(*(v0Container->
back())) = laLink;
524 lbContainer->
push_back(myLambdabar.release());
528 v0LinksDecorlbb(*(lbContainer->
back())) = v0Link;
532 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
534 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
537 myGamma = std::unique_ptr<xAOD::Vertex>(
massFit(22, pairV0, vertex) );
540 gamma_prob =
m_V0Tools->vertexProbability(myGamma.get());
545 mDecor_gfit( *(v0Container->
back()) ) = gamma_fit;
546 mDecor_gmass( *(v0Container->
back()) ) = gamma_mass;
547 mDecor_gmasserr( *(v0Container->
back()) ) = gamma_massErr;
548 mDecor_gprob( *(v0Container->
back()) ) = gamma_prob;
570 if (v0Container->
empty())
ATH_MSG_DEBUG(
"No Candidates found. Empty container returned");
571 if (ksContainer->
empty())
ATH_MSG_DEBUG(
"No Kshort Candidates found. Empty container returned");
572 if (laContainer->
empty())
ATH_MSG_DEBUG(
"No Lambda Candidates found. Empty container returned");
573 if (lbContainer->
empty())
ATH_MSG_DEBUG(
"No Lambdabar Candidates found. Empty container returned");
575 return StatusCode::SUCCESS;
581 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg
588 msg(
MSG::DEBUG) <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg;
590 return StatusCode::SUCCESS;
603 double srxy = startingPoint.perp();
606 double massKshort_i=2000001., massLambda_i=2000001., massLambdabar_i=2000001.;
609 std::vector<std::unique_ptr<const Trk::TrackParameters> > cleanup;
612 extrapolatedPerigee1 =
m_extrapolator->extrapolate(ctx,track1->perigeeParameters(), perigeeSurface).release();
613 if (extrapolatedPerigee1 ==
nullptr) extrapolatedPerigee1 = &track1->perigeeParameters();
614 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee1));
616 extrapolatedPerigee2 =
m_extrapolator->extrapolate(ctx,track2->perigeeParameters(), perigeeSurface).release();
617 if (extrapolatedPerigee2 ==
nullptr) extrapolatedPerigee2 = &track2->perigeeParameters();
618 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee2));
620 if (extrapolatedPerigee1 !=
nullptr && extrapolatedPerigee2 !=
nullptr) {
626 (massLambdabar_i >=
m_ulamin && massLambdabar_i <=
m_ulamax)) ) pass =
true;
637 bool hasInnerPixHit1 =
true;
638 bool hasInnerPixHit2 =
true;
642 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
644 if (nInnerHits2 == 0) hasInnerPixHit2 =
false;
646 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
650 if (per1 ==
nullptr)
continue;
652 if (per2 ==
nullptr)
continue;
653 double d0_1 = per1->parameters()[
Trk::d0];
654 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
655 double delta_z0_1 = track1->z0() + track1->vz() - PV->
z();
656 double d0_2 = per2->parameters()[
Trk::d0];
657 double sig_d0_2 = sqrt((*per2->covariance())(0,0));
658 double delta_z0_2 = track2->z0() + track2->vz() - PV->
z();
659 bool IP_check1 = (std::abs(d0_1/sig_d0_1) >
m_d0_cut) || !hasInnerPixHit1;
662 bool IP_check2 = (std::abs(d0_2/sig_d0_2) >
m_d0_cut) || !hasInnerPixHit2;
665 if (IP_check1 && IP_check2)
return true;
675 bool hasInnerPixHit1 =
true;
679 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
681 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
685 if (per1 ==
nullptr)
continue;
686 double d0_1 = per1->parameters()[
Trk::d0];
687 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
688 double delta_z0_1 = track1->z0() + track1->vz() - PV->
z();
689 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
690 (!hasInnerPixHit1)) &&
701 bool hasInnerPixHit1 =
true;
705 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
708 if (per1 ==
nullptr)
return pass;
710 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
711 double delta_z0_1 = track1->z0() + track1->vz() - PV->
z();
712 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
713 (!hasInnerPixHit1)) &&
722 bool hasInnerPixHit1 =
true;
726 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
729 if (per1 ==
nullptr)
return pass;
731 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
732 double delta_z0_1 = track1->z0() + track1->vz() - PV.z();
733 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
734 (!hasInnerPixHit1)) &&
750 float nLogProb = 999999;
752 std::vector<float> bdt_vars = {
759 float this_Score=
m_BDT->GetClassification(bdt_vars);
760 if (this_Score >
score) {
784 double e1 = (e1sq>0.) ? sqrt(e1sq) : 0.;
786 double e2 = (e2sq>0.) ? sqrt(e2sq) : 0.;
789 double mass = (msq>0.) ? sqrt(msq) : 0.;
796 double mass = 1000000000.;
797 double error = 1000000001.;
798 bool in_mass_window =
false;
799 double winmass_min = 0., winmass_max = 0.;
807 }
else if (pdgID == 3122 || pdgID == -3122) {
813 }
else if (pdgID == -3122) {
819 if (in_mass_window) pass =
true;
827 std::vector<double>
masses;
831 }
else if (pdgID == 3122) {
834 }
else if (pdgID == -3122) {
837 }
else if (pdgID == 22) {
859 if (pdgID == -3122) {
871 const std::vector<const xAOD::TrackParticleContainer*>& trackcols)
const
875 bool elementSet =
false;
876 if(trackcols.empty()){
882 if(itr != trkcol->end()){
889 if(!elementSet)
ATH_MSG_ERROR(
"Track was not found when linking");