39 declareInterface<InDetV0FinderTool>(
this);
121 std::string BDTPathName =
"InDetV0FinderTool/BDT/v1/" +
m_BDTFile;
124 std::unique_ptr<TFile> rootFile(TFile::Open(fullPathToFile.c_str(),
"READ"));
125 std::string strBDTName =
"xgboost";
126 std::unique_ptr<TTree> training( (TTree*)rootFile->Get(strBDTName.c_str()) );
127 m_BDT = std::make_unique<MVAUtils::BDT>(training.get());
143 auto gendata = std::make_shared<GenData>();
163 ATH_MSG_FATAL(
"The vertex fitter passed is not a V0 Vertex Fitter");
164 return StatusCode::FAILURE;
172 return StatusCode::SUCCESS;
181 const EventContext& ctx
186 std::vector<const xAOD::TrackParticleContainer*> trackCols;
189 trackCols.push_back(handle.cptr());
199 return StatusCode::SUCCESS;
207 return StatusCode::SUCCESS;
209 ATH_MSG_DEBUG(
"Track particle container size " << TPC->size());
217 beamspot = beamSpotHandle->beamPos();
222 beamspot =
Amg::Vector3D(beamPosX(0), beamPosY(0), beamPosZ(0));
225 std::vector<const xAOD::TrackParticle*> posTracks; posTracks.clear();
226 std::vector<const xAOD::TrackParticle*> negTracks; negTracks.clear();
228 if (
m_pv && primaryVertex) vx = primaryVertex;
230 if (TPC->size() > 1) {
232 for ( tpIt=TPC->begin(); tpIt!=TPC->end(); ++tpIt )
243 for (
const auto *
const vx : *vertices)
253 if (foundVertex)
break;
256 bool useTrack =
false;
258 if (
m_useorigin && foundVertex ==
nullptr) useTrack =
true;
259 if (!useTrack)
continue;
263 bool d0wrtVertex =
true;
265 if ( !
d0Pass(TP,vertColl, ctx) ) d0wrtVertex =
false;
269 if ( !
d0Pass(TP,primaryVertex, ctx) ) d0wrtVertex =
false;
271 if ( !
d0Pass(TP,beamspot, ctx) ) d0wrtVertex =
false;
274 if (!d0wrtVertex)
continue;
277 posTracks.push_back(TP);
278 negTracks.push_back(TP);
281 posTracks.push_back(*tpIt);
283 negTracks.push_back(*tpIt);
289 ATH_MSG_DEBUG(
"number of tracks passing preselection, positive " << posTracks.size() <<
" negative " << negTracks.size());
291 if (!posTracks.empty() && !negTracks.empty())
308 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt1;
309 std::vector<const xAOD::TrackParticle*>::const_iterator tpIt2;
311 for (tpIt1 = posTracks.begin(); tpIt1 != posTracks.end(); ++tpIt1)
318 double pt1 = TP1->
pt();
321 for (tpIt2 = negTracks.begin(); tpIt2 != negTracks.end(); ++tpIt2)
323 if (*tpIt1 == *tpIt2)
continue;
331 ATH_MSG_DEBUG(
"nclus1 " << (
int)nclus1 <<
" nclus2 " << (
int)nclus2);
336 double pt2 = TP2->
pt();
338 bool trk_cut1 =
false;
339 bool trk_cut2 =
false;
340 if (nclus1 != 0) trk_cut1 =
true;
341 if (nclus1 == 0 && pt1 >=
m_ptTRT) trk_cut1 =
true;
342 if (!trk_cut1)
continue;
343 if (nclus2 != 0) trk_cut2 =
true;
344 if (nclus2 == 0 && pt2 >=
m_ptTRT) trk_cut2 =
true;
345 if (!trk_cut2)
continue;
353 if (errorcode != 0) {startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
354 bool errorCode =
false;
355 if (errorcode == 0 || errorcode == 5 || errorcode == 6 || errorcode == 8) errorCode =
true;
356 if (!errorCode)
continue;
359 bool d0wrtVertex =
true;
361 if ( !
d0Pass(TP1,TP2,vertColl, ctx) ) d0wrtVertex =
false;
363 if (!d0wrtVertex)
continue;
367 if (
doFit(TP1,TP2,startingPoint, ctx) )
369 std::vector<const xAOD::TrackParticle*> pairV0;
371 pairV0.push_back(TP1);
372 pairV0.push_back(TP2);
377 std::unique_ptr<xAOD::Vertex> myVxCandidate;
389 bool doKshortFit =
false;
390 doKshortFit =
doMassFit(myVxCandidate.get(),310);
391 bool doLambdaFit =
false;
392 doLambdaFit =
doMassFit(myVxCandidate.get(),3122);
393 bool doLambdabarFit =
false;
394 doLambdabarFit =
doMassFit(myVxCandidate.get(),-3122);
396 if (doKshortFit || doLambdaFit || doLambdabarFit)
398 bool pointAtVert =
true;
400 if ( !
pointAtVertexColl(myVxCandidate.get(),vertColl,score) ) pointAtVert =
false;
403 if ( !
pointAtVertex(myVxCandidate.get(),primaryVertex,score) ) pointAtVert =
false;
410 std::unique_ptr<xAOD::Vertex> myKshort;
411 std::unique_ptr<xAOD::Vertex> myLambda;
412 std::unique_ptr<xAOD::Vertex> myLambdabar;
413 std::unique_ptr<xAOD::Vertex> myGamma;
414 bool foundKshort =
false;
415 bool foundLambda =
false;
416 bool foundLambdabar =
false;
419 myKshort =
massFit(ctx, 310, pairV0, vertex);
429 myLambda =
massFit(ctx, 3122, pairV0, vertex);
439 myLambdabar =
massFit(ctx, -3122, pairV0, vertex);
443 foundLambdabar =
true;
448 bool doGamma =
false;
450 double gamma_prob = -1., gamma_mass = -1., gamma_massErr = -1.;
451 if (foundKshort || foundLambda || foundLambdabar) doGamma =
true;
460 myVxCandidate->clearTracks();
463 myVxCandidate->addTrackAtVertex(newLink1);
464 myVxCandidate->addTrackAtVertex(newLink2);
465 v0Container->
push_back(myVxCandidate.release());
467 v0_BDTScore( *(v0Container->
back()) ) = score;
471 myKshort->clearTracks();
474 myKshort->addTrackAtVertex(ksLink1);
475 myKshort->addTrackAtVertex(ksLink2);
476 ksContainer->
push_back(myKshort.release());
480 v0LinksDecorks(*(ksContainer->
back())) = v0Link;
484 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
486 v0_ksLinksDecor(*(v0Container->
back())) = ksLink;
490 myLambda->clearTracks();
493 myLambda->addTrackAtVertex(laLink1);
494 myLambda->addTrackAtVertex(laLink2);
495 laContainer->
push_back(myLambda.release());
499 v0LinksDecorlb(*(laContainer->
back())) = v0Link;
503 v0_laLinksDecor(*(v0Container->
back())) = laLink;
505 v0_laLinksDecor(*(v0Container->
back())) = laLink;
509 myLambdabar->clearTracks();
512 myLambdabar->addTrackAtVertex(lbLink1);
513 myLambdabar->addTrackAtVertex(lbLink2);
514 lbContainer->
push_back(myLambdabar.release());
518 v0LinksDecorlbb(*(lbContainer->
back())) = v0Link;
522 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
524 v0_lbLinksDecor(*(v0Container->
back())) = lbLink;
527 myGamma =
massFit(ctx, 22, pairV0, vertex);
530 gamma_prob =
m_V0Tools->vertexProbability(myGamma.get());
535 mDecor_gfit( *(v0Container->
back()) ) = gamma_fit;
536 mDecor_gmass( *(v0Container->
back()) ) = gamma_mass;
537 mDecor_gmasserr( *(v0Container->
back()) ) = gamma_massErr;
538 mDecor_gprob( *(v0Container->
back()) ) = gamma_prob;
560 if (v0Container->
empty())
ATH_MSG_DEBUG(
"No Candidates found. Empty container returned");
561 if (ksContainer->
empty())
ATH_MSG_DEBUG(
"No Kshort Candidates found. Empty container returned");
562 if (laContainer->
empty())
ATH_MSG_DEBUG(
"No Lambda Candidates found. Empty container returned");
563 if (lbContainer->
empty())
ATH_MSG_DEBUG(
"No Lambdabar Candidates found. Empty container returned");
565 return StatusCode::SUCCESS;
571 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg
578 msg(MSG::DEBUG) <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
endmsg;
580 return StatusCode::SUCCESS;
593 double srxy = startingPoint.perp();
596 double massKshort_i=2000001., massLambda_i=2000001., massLambdabar_i=2000001.;
599 std::vector<std::unique_ptr<const Trk::TrackParameters> > cleanup;
603 if (extrapolatedPerigee1 ==
nullptr) extrapolatedPerigee1 = &track1->
perigeeParameters();
604 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee1));
607 if (extrapolatedPerigee2 ==
nullptr) extrapolatedPerigee2 = &track2->
perigeeParameters();
608 else cleanup.push_back(std::unique_ptr<const Trk::TrackParameters>(extrapolatedPerigee2));
610 if (extrapolatedPerigee1 !=
nullptr && extrapolatedPerigee2 !=
nullptr) {
616 (massLambdabar_i >=
m_ulamin && massLambdabar_i <=
m_ulamax)) ) pass =
true;
627 bool hasInnerPixHit1 =
true;
628 bool hasInnerPixHit2 =
true;
630 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
631 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
632 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
633 uint8_t nInnerHits2 = numberOfInnermostPixelLayerHits(*track2);
634 if (nInnerHits2 == 0) hasInnerPixHit2 =
false;
636 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
640 if (per1 ==
nullptr)
continue;
642 if (per2 ==
nullptr)
continue;
643 double d0_1 = per1->parameters()[
Trk::d0];
644 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
645 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
646 double d0_2 = per2->parameters()[
Trk::d0];
647 double sig_d0_2 = sqrt((*per2->covariance())(0,0));
648 double delta_z0_2 = track2->
z0() + track2->
vz() - PV->
z();
649 bool IP_check1 = (std::abs(d0_1/sig_d0_1) >
m_d0_cut) || !hasInnerPixHit1;
652 bool IP_check2 = (std::abs(d0_2/sig_d0_2) >
m_d0_cut) || !hasInnerPixHit2;
655 if (IP_check1 && IP_check2)
return true;
665 bool hasInnerPixHit1 =
true;
667 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
668 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
669 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
671 for (
auto vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr )
675 if (per1 ==
nullptr)
continue;
676 double d0_1 = per1->parameters()[
Trk::d0];
677 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
678 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
679 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
680 (!hasInnerPixHit1)) &&
691 bool hasInnerPixHit1 =
true;
693 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
694 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
695 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
698 if (per1 ==
nullptr)
return pass;
699 double d0_1 = per1->parameters()[
Trk::d0];
700 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
701 double delta_z0_1 = track1->
z0() + track1->
vz() - PV->
z();
702 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
703 (!hasInnerPixHit1)) &&
712 bool hasInnerPixHit1 =
true;
714 SG::AuxElement::ConstAccessor<uint8_t> numberOfInnermostPixelLayerHits(
"numberOfInnermostPixelLayerHits");
715 uint8_t nInnerHits1 = numberOfInnermostPixelLayerHits(*track1);
716 if (nInnerHits1 == 0) hasInnerPixHit1 =
false;
719 if (per1 ==
nullptr)
return pass;
720 double d0_1 = per1->parameters()[
Trk::d0];
721 double sig_d0_1 = sqrt((*per1->covariance())(0,0));
722 double delta_z0_1 = track1->
z0() + track1->
vz() - PV.z();
723 if (((std::abs(d0_1/sig_d0_1) >
m_d0_cut) ||
724 (!hasInnerPixHit1)) &&
734 float v0lxyError =
m_V0Tools->lxyError(v0,PV);
739 float prob =
m_V0Tools->vertexProbability(v0);
740 float nLogProb = 999999;
741 if (prob>0) nLogProb = -1*log10f(prob);
742 if (v0lxyError == 0.){
743 throw std::runtime_error(
"v0lxyError is zero in division.");
745 std::vector<float> bdt_vars = {
752 float this_Score=
m_BDT->GetClassification(bdt_vars);
753 if (this_Score > score) {
770 for ( vItr=vertColl->
begin(); vItr!=vertColl->
end(); ++vItr ) {
if (
pointAtVertex(v0,(*vItr),score)) pass =
true; }
776 double e1sq = per1->
momentum().mag2() + m1*m1;
777 double e1 = (e1sq>0.) ? sqrt(e1sq) : 0.;
778 double e2sq = per2->
momentum().mag2() + m2*m2;
779 double e2 = (e2sq>0.) ? sqrt(e2sq) : 0.;
781 double msq = (e1+e2+p)*(e1+e2-p);
782 double mass = (msq>0.) ? sqrt(msq) : 0.;
789 double mass = 1000000000.;
790 double error = 1000000001.;
791 bool in_mass_window =
false;
792 double winmass_min = 0., winmass_max = 0.;
799 if (mass >= winmass_min && mass <= winmass_max &&
error <=
m_errmass) in_mass_window =
true;
800 }
else if (pdgID == 3122 || pdgID == -3122) {
806 }
else if (pdgID == -3122) {
810 if (mass >= winmass_min && mass <= winmass_max &&
error <=
m_errmass) in_mass_window =
true;
812 if (in_mass_window) pass =
true;
819 std::unique_ptr<xAOD::Vertex> vxCandidate;
820 std::vector<double> masses;
824 }
else if (pdgID == 3122) {
827 }
else if (pdgID == -3122) {
830 }
else if (pdgID == 22) {
852 if (pdgID == -3122) {
864 const std::vector<const xAOD::TrackParticleContainer*>& trackcols)
const
868 bool elementSet =
false;
869 if(trackcols.empty()){
874 auto itr = std::find(trkcol->begin(), trkcol->end(), tp);
875 if(itr != trkcol->end()){
882 if(!elementSet)
ATH_MSG_ERROR(
"Track was not found when linking");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_FATAL(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].