38 declareInterface<InDetV0FinderTool>(
this);
120 std::string BDTPathName =
"InDetV0FinderTool/BDT/v1/" +
m_BDTFile;
123 std::unique_ptr<TFile> rootFile(TFile::Open(fullPathToFile.c_str(),
"READ"));
124 std::string strBDTName =
"xgboost";
125 std::unique_ptr<TTree> training( (TTree*)rootFile->Get(strBDTName.c_str()) );
126 m_BDT = std::make_unique<MVAUtils::BDT>(training.get());
142 auto gendata = std::make_shared<GenData>();
162 ATH_MSG_FATAL(
"The vertex fitter passed is not a V0 Vertex Fitter");
163 return StatusCode::FAILURE;
171 return StatusCode::SUCCESS;
180 const EventContext& ctx
185 std::vector<const xAOD::TrackParticleContainer*> trackCols;
188 trackCols.push_back(handle.cptr());
198 return StatusCode::SUCCESS;
206 return StatusCode::SUCCESS;
208 ATH_MSG_DEBUG(
"Track particle container size " << TPC->size());
216 beamspot = beamSpotHandle->beamPos();
221 beamspot =
Amg::Vector3D(beamPosX(0), beamPosY(0), beamPosZ(0));
224 std::vector<const xAOD::TrackParticle*> posTracks; posTracks.clear();
225 std::vector<const xAOD::TrackParticle*> negTracks; negTracks.clear();
227 if (
m_pv && primaryVertex) vx = primaryVertex;
229 if (TPC->size() > 1) {
231 for ( tpIt=TPC->begin(); tpIt!=TPC->end(); ++tpIt )
242 for (
const auto *
const vx : *vertices)
252 if (foundVertex)
break;
255 bool useTrack =
false;
257 if (
m_useorigin && foundVertex ==
nullptr) useTrack =
true;
258 if (!useTrack)
continue;
262 bool d0wrtVertex =
true;
264 if ( !
d0Pass(TP,vertColl, ctx) ) d0wrtVertex =
false;
268 if ( !
d0Pass(TP,primaryVertex, ctx) ) d0wrtVertex =
false;
270 if ( !
d0Pass(TP,beamspot, ctx) ) d0wrtVertex =
false;
273 if (!d0wrtVertex)
continue;
276 posTracks.push_back(TP);
277 negTracks.push_back(TP);
280 posTracks.push_back(*tpIt);
282 negTracks.push_back(*tpIt);
288 ATH_MSG_DEBUG(
"number of tracks passing preselection, positive " << posTracks.size() <<
" negative " << negTracks.size());
290 if (!posTracks.empty() && !negTracks.empty())
307 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt1;
308 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt2;
310 for (tpIt1 = posTracks.begin(); tpIt1 != posTracks.end(); ++tpIt1)
317 double pt1 = TP1->
pt();
320 for (tpIt2 = negTracks.begin(); tpIt2 != negTracks.end(); ++tpIt2)
322 if (*tpIt1 == *tpIt2)
continue;
330 ATH_MSG_DEBUG(
"nclus1 " << (
int)nclus1 <<
" nclus2 " << (
int)nclus2);
335 double pt2 = TP2->
pt();
337 bool trk_cut1 =
false;
338 bool trk_cut2 =
false;
339 if (nclus1 != 0) trk_cut1 =
true;
340 if (nclus1 == 0 && pt1 >=
m_ptTRT) trk_cut1 =
true;
341 if (!trk_cut1)
continue;
342 if (nclus2 != 0) trk_cut2 =
true;
343 if (nclus2 == 0 && pt2 >=
m_ptTRT) trk_cut2 =
true;
344 if (!trk_cut2)
continue;
352 if (errorcode != 0) {startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
353 bool errorCode =
false;
354 if (errorcode == 0 || errorcode == 5 || errorcode == 6 || errorcode == 8) errorCode =
true;
355 if (!errorCode)
continue;
358 bool d0wrtVertex =
true;
360 if ( !
d0Pass(TP1,TP2,vertColl, ctx) ) d0wrtVertex =
false;
362 if (!d0wrtVertex)
continue;
366 if (
doFit(TP1,TP2,startingPoint, ctx) )
368 std::vector<const xAOD::TrackParticle*> pairV0;
370 pairV0.push_back(TP1);
371 pairV0.push_back(TP2);
376 std::unique_ptr<xAOD::Vertex> myVxCandidate;
388 bool doKshortFit =
false;
389 doKshortFit =
doMassFit(myVxCandidate.get(),310);
390 bool doLambdaFit =
false;
391 doLambdaFit =
doMassFit(myVxCandidate.get(),3122);
392 bool doLambdabarFit =
false;
393 doLambdabarFit =
doMassFit(myVxCandidate.get(),-3122);
395 if (doKshortFit || doLambdaFit || doLambdabarFit)
397 bool pointAtVert =
true;
399 if ( !
pointAtVertexColl(myVxCandidate.get(),vertColl,score) ) pointAtVert =
false;
402 if ( !
pointAtVertex(myVxCandidate.get(),primaryVertex,score) ) pointAtVert =
false;
409 std::unique_ptr<xAOD::Vertex> myKshort;
410 std::unique_ptr<xAOD::Vertex> myLambda;
411 std::unique_ptr<xAOD::Vertex> myLambdabar;
412 std::unique_ptr<xAOD::Vertex> myGamma;
413 bool foundKshort =
false;
414 bool foundLambda =
false;
415 bool foundLambdabar =
false;
418 myKshort =
massFit(ctx, 310, pairV0, vertex);
428 myLambda =
massFit(ctx, 3122, pairV0, vertex);
438 myLambdabar =
massFit(ctx, -3122, pairV0, vertex);
442 foundLambdabar =
true;
447 bool doGamma =
false;
449 double gamma_prob = -1., gamma_mass = -1., gamma_massErr = -1.;
450 if (foundKshort || foundLambda || foundLambdabar) doGamma =
true;
459 myVxCandidate->clearTracks();
462 myVxCandidate->addTrackAtVertex(newLink1);
463 myVxCandidate->addTrackAtVertex(newLink2);
464 v0Container->
push_back(myVxCandidate.release());
466 v0_BDTScore( *(v0Container->
back()) ) = score;
470 myKshort->clearTracks();
473 myKshort->addTrackAtVertex(ksLink1);
474 myKshort->addTrackAtVertex(ksLink2);
475 ksContainer->
push_back(myKshort.release());
479 v0LinksDecorks(*(ksContainer->
back())) = v0Link;
483 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
485 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
489 myLambda->clearTracks();
492 myLambda->addTrackAtVertex(laLink1);
493 myLambda->addTrackAtVertex(laLink2);
494 laContainer->
push_back(myLambda.release());
498 v0LinksDecorlb(*(laContainer->
back())) = v0Link;
502 v0_laLinksDecor(*(v0Container->
back())) = laLink;
504 v0_laLinksDecor(*(v0Container->
back())) = laLink;
508 myLambdabar->clearTracks();
511 myLambdabar->addTrackAtVertex(lbLink1);
512 myLambdabar->addTrackAtVertex(lbLink2);
513 lbContainer->
push_back(myLambdabar.release());
517 v0LinksDecorlbb(*(lbContainer->
back())) = v0Link;
521 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
523 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
526 myGamma =
massFit(ctx, 22, pairV0, vertex);
529 gamma_prob =
m_V0Tools->vertexProbability(myGamma.get());
534 mDecor_gfit( *(v0Container->
back()) ) = gamma_fit;
535 mDecor_gmass( *(v0Container->
back()) ) = gamma_mass;
536 mDecor_gmasserr( *(v0Container->
back()) ) = gamma_massErr;
537 mDecor_gprob( *(v0Container->
back()) ) = gamma_prob;
559 if (v0Container->
empty())
ATH_MSG_DEBUG(
"No Candidates found. Empty container returned");
560 if (ksContainer->
empty())
ATH_MSG_DEBUG(
"No Kshort Candidates found. Empty container returned");
561 if (laContainer->
empty())
ATH_MSG_DEBUG(
"No Lambda Candidates found. Empty container returned");
562 if (lbContainer->
empty())
ATH_MSG_DEBUG(
"No Lambdabar Candidates found. Empty container returned");
564 return StatusCode::SUCCESS;
570 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg
577 msg(MSG::DEBUG) <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg;
579 return StatusCode::SUCCESS;
592 double srxy = startingPoint.perp();
595 double massKshort_i=2000001., massLambda_i=2000001., massLambdabar_i=2000001.;
598 std::vector<std::unique_ptr<const Trk::TrackParameters> > cleanup;
602 if (extrapolatedPerigee1 ==
nullptr) extrapolatedPerigee1 = &track1->
perigeeParameters();
603 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee1));
606 if (extrapolatedPerigee2 ==
nullptr) extrapolatedPerigee2 = &track2->
perigeeParameters();
607 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee2));
609 if (extrapolatedPerigee1 !=
nullptr && extrapolatedPerigee2 !=
nullptr) {
615 (massLambdabar_i >=
m_ulamin && massLambdabar_i <=
m_ulamax)) ) pass =
true;
626 bool hasInnerPixHit1 =
true;
627 bool hasInnerPixHit2 =
true;
629 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
630 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
631 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
632 uint8_t nInnerHits2 = numberOfInnermostPixelLayerHits(*track2);
633 if (nInnerHits2 == 0) hasInnerPixHit2 =
false;
635 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
639 if (per1 ==
nullptr)
continue;
641 if (per2 ==
nullptr)
continue;
642 double d0_1 = per1->parameters()[
Trk::d0];
643 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
644 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
645 double d0_2 = per2->parameters()[
Trk::d0];
646 double sig_d0_2 = sqrt((*per2->covariance())(0,0));
647 double delta_z0_2 = track2->
z0() + track2->
vz() - PV->
z();
648 bool IP_check1 = (std::abs(d0_1/sig_d0_1) >
m_d0_cut) || !hasInnerPixHit1;
651 bool IP_check2 = (std::abs(d0_2/sig_d0_2) >
m_d0_cut) || !hasInnerPixHit2;
654 if (IP_check1 && IP_check2)
return true;
664 bool hasInnerPixHit1 =
true;
666 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
667 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
668 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
670 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
674 if (per1 ==
nullptr)
continue;
675 double d0_1 = per1->parameters()[
Trk::d0];
676 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
677 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
678 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
679 (!hasInnerPixHit1)) &&
690 bool hasInnerPixHit1 =
true;
692 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
693 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
694 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
697 if (per1 ==
nullptr)
return pass;
698 double d0_1 = per1->parameters()[
Trk::d0];
699 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
700 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
701 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
702 (!hasInnerPixHit1)) &&
711 bool hasInnerPixHit1 =
true;
713 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
714 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
715 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
718 if (per1 ==
nullptr)
return pass;
719 double d0_1 = per1->parameters()[
Trk::d0];
720 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
721 double delta_z0_1 = track1->
z0() + track1->
vz() - PV.z();
722 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
723 (!hasInnerPixHit1)) &&
733 float v0lxyError =
m_V0Tools->lxyError(v0,PV);
738 float prob =
m_V0Tools->vertexProbability(v0);
739 float nLogProb = 999999;
740 if (prob>0) nLogProb = -1*log10f(prob);
741 std::vector<float> bdt_vars = {
748 float this_Score=
m_BDT->GetClassification(bdt_vars);
749 if (this_Score > score) {
766 for ( vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr ) {
if (
pointAtVertex(v0,(*vItr),score)) pass =
true; }
772 double e1sq = per1->
momentum().mag2() + m1*m1;
773 double e1 = (e1sq>0.) ? sqrt(e1sq) : 0.;
774 double e2sq = per2->
momentum().mag2() + m2*m2;
775 double e2 = (e2sq>0.) ? sqrt(e2sq) : 0.;
777 double msq = (e1+e2+p)*(e1+e2-p);
778 double mass = (msq>0.) ? sqrt(msq) : 0.;
785 double mass = 1000000000.;
786 double error = 1000000001.;
787 bool in_mass_window =
false;
788 double winmass_min = 0., winmass_max = 0.;
795 if (mass >= winmass_min && mass <= winmass_max &&
error <=
m_errmass) in_mass_window =
true;
796 }
else if (pdgID == 3122 || pdgID == -3122) {
802 }
else if (pdgID == -3122) {
806 if (mass >= winmass_min && mass <= winmass_max &&
error <=
m_errmass) in_mass_window =
true;
808 if (in_mass_window) pass =
true;
815 std::unique_ptr<xAOD::Vertex> vxCandidate;
816 std::vector<double> masses;
820 }
else if (pdgID == 3122) {
823 }
else if (pdgID == -3122) {
826 }
else if (pdgID == 22) {
848 if (pdgID == -3122) {
860 const std::vector<const xAOD::TrackParticleContainer*>& trackcols)
const
864 bool elementSet =
false;
865 if(trackcols.empty()){
870 auto itr = std::find(trkcol->begin(), trkcol->end(), tp);
871 if(itr != trkcol->end()){
878 if(!elementSet)
ATH_MSG_ERROR(
"Track was not found when linking");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
double charge(const T &p)
ATLAS-specific HepMC functions.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
DataModel_detail::const_iterator< DataVector > const_iterator
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
bool setElement(ElementType element)
Set link to point to an Element (slowest).
bool setStorableObject(BaseConstReference data, bool replace=false)
Set link storable to data object pointed by data (slower).
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
const Amg::Vector3D & momentum() const
Access method for the momentum.
Class describing the Line to which the Perigee refers to.
This class implements a vertex fitting algorithm optimised for V0 finding.
float z0() const
Returns the parameter.
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
float vz() const
The z origin for the parameters.
bool summaryValue(uint8_t &value, const SummaryType &information) const
Accessor for TrackSummary values.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
float charge() const
Returns the charge.
float z() const
Returns the z position.
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
const Amg::Vector3D & position() const
Returns the 3-pos.
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Eigen::Matrix< double, 3, 1 > Vector3D
static const int ELECTRON
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersBase< TrackParametersDim, Charged > TrackParameters
@ V0Vtx
Vertex from V0 decay.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].