ATLAS Offline Software
Loading...
Searching...
No Matches
TwoTrackVrtBDTSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
7
8
9// Header include
13
14#include "GaudiKernel/ConcurrencyFlags.h"
15#include "TFile.h"
16#include "TTree.h"
17#include "Math/Vector3D.h"
18
19#include "MVAUtils/BDT.h"
20
21
22namespace Rec {
23
24//
25//Constructor--------------------------------------------------------------
27 const std::string& name,
28 const IInterface* parent):
29 AthAlgTool(type,name,parent),
30 m_SV2T_BDT(nullptr),
31 m_instanceName(name)
32 {
33//
34// Declare additional interface
35//
36 declareInterface< ITwoTrackVertexSelector >(this);
37//
41 }
42
43//Destructor---------------------------------------------------------------
45 ATH_MSG_DEBUG("TwoTrackVertBDTSelector destructor called");
46 }
47
48//Initialize---------------------------------------------------------------
50 ATH_MSG_DEBUG( "Initialising TwoTrackVrtBDTSelector" );
51
52 ATH_CHECK( m_fitSvc.retrieve() );
53//--------------------------------------------------------
54 //std::string fileName="NewVrtSecInclusiveTool/Fake2TrVertexReject.MVA.v01.root"; ///For local calibration file
55 //std::string rootFilePath = PathResolver::find_file(fileName, "DATAPATH"); ///
56 std::string rootFilePath = PathResolver::find_calib_file("NewVrtSecInclusiveTool/"+m_calibFileName);
57 std::unique_ptr<TFile> rootFile(TFile::Open(rootFilePath.c_str(), "READ"));
58 if (!rootFile) {
59 ATH_MSG_FATAL("Could not retrieve root file: " << m_calibFileName);
60 return StatusCode::FAILURE;
61 }
62 std::unique_ptr<TTree> training((TTree*)rootFile->Get("BDT"));
63 m_SV2T_BDT = std::make_unique<MVAUtils::BDT>(training.get());
64//--------------------------------------------------------
65 return StatusCode::SUCCESS;
66 }
67
68
69
71 {
72 ATH_MSG_DEBUG("TwoTrackVrtBDTSelector finalize()");
73 return StatusCode::SUCCESS;
74 }
75
76
77 bool TwoTrackVrtBDTSelector::isgood( const std::pair<const xAOD::TrackParticle*,const xAOD::TrackParticle*> iTrks,
78 const xAOD::Vertex & candV,
79 std::pair<ROOT::Math::XYZTVector,ROOT::Math::XYZTVector> moms,
80 const xAOD::Vertex & tPV) const
81 {
82 float quality;
83 return isgood(iTrks, candV, moms,tPV,quality);
84 }
85
86 bool TwoTrackVrtBDTSelector::isgood( const std::pair<const xAOD::TrackParticle*,const xAOD::TrackParticle*> iTrks,
87 const xAOD::Vertex & candV,
88 std::pair<ROOT::Math::XYZTVector,ROOT::Math::XYZTVector> moms,
89 const xAOD::Vertex & tPV,
90 float & quality) const
91 {
92 quality=-99.;
93 double Prob2v=TMath::Prob(candV.chiSquared(),1);
94 if( Prob2v < m_sel2VrtProbCut ) return false; // Vertex probability check
95 double vrtR=candV.position().perp();
96 auto sumMom=moms.first+moms.second;
97 if( sumMom.M() > m_vrt2TrMassLimit ) return false; // Invariant mass check
98 if( vrtR > m_maxSVRadiusCut) return false; // Too far from interaction point
99 if( sumMom.Pt() < m_vrt2TrPtMin) return false; // Summary momentum > minimal allowed 2-track vertex pt
100 if( sumMom.Pt() > m_vrt2TrPtMax) return false; // Maximal allowed 2-track vertex Pt
101
102 ROOT::Math::XYZVector vSVPV(candV.x()-tPV.x(),candV.y()-tPV.y(),candV.z()-tPV.z());
103 double cosSVPV=vSVPV.Unit().Dot(sumMom.Vect().Unit());
104 if(cosSVPV < m_cosSVPVCut) return false; // Angle between tV-PV direction and summary momentum
105
106
107 double vrtRErr=vrtRadiusError(candV.position(),candV.covariance() );
108//
109// Check pixel hits vs vertex positions.
110 int ihitIBL = getIBLHit(iTrks.first);
111 int jhitIBL = getIBLHit(iTrks.second);
112 if( m_do2TrkIBLChecks && ( (ihitIBL==0&&jhitIBL>0) || (ihitIBL>0&&jhitIBL==0) ) ) return false;
113 int ihitBL = getBLHit (iTrks.first);
114 int jhitBL = getBLHit (iTrks.second);
115//--Very general cleaning cuts based on ID geometry and applicable to all processes
116 if( m_do2TrkIBLChecks && vrtR<m_firstPixelLayerR-2.*vrtRErr ){
117 if( ihitIBL<1 && ihitBL<1) return false;
118 if( jhitIBL<1 && jhitBL<1) return false;
119 }
120 float ihitR = iTrks.first->radiusOfFirstHit();
121 float jhitR = iTrks.second->radiusOfFirstHit();
122 if(std::abs(ihitR-jhitR)>50.)return false; //- FMPs are in very different layers
123 if( vrtR-std::min(ihitR,jhitR) > 50.) return false; //- FMP is closer to (0,0) than SV itself
124 if(ihitR-vrtR > 180.+2.*vrtRErr)return false; //- Distance FMP-vertex should be less then SCT-Pixel gap
125 if(jhitR-vrtR > 180.+2.*vrtRErr)return false; //- Distance FMP-vertex should be less then SCT-Pixel gap
126//-------------------------------------------------------
127 if(m_useVertexCleaning){ //More agressive cleaning
128 if(std::abs(ihitR-jhitR)>12.) return false;
129 if( ihitR-vrtR > 36.) return false; // Too big dR between vertex and hit in pixel
130 if( jhitR-vrtR > 36.) return false; // Should be another layer in between
131 if( ihitR-vrtR <-2.*vrtRErr) return false; // Vertex is behind hit in pixel
132 if( jhitR-vrtR <-2.*vrtRErr) return false; // Vertex is behind hit in pixel
133 }
134//-------------------BDT based rejection
135 std::vector<double> impact,impactError;
136 m_fitSvc->VKalGetImpact( iTrks.first, tPV.position(), 1, impact, impactError);
137 float trk1Signif = sqrt( impact[0]*impact[0]/impactError[0] + impact[1]*impact[1]/impactError[2]);
138 m_fitSvc->VKalGetImpact( iTrks.second, tPV.position(), 1, impact, impactError);
139 float trk2Signif = sqrt( impact[0]*impact[0]/impactError[0] + impact[1]*impact[1]/impactError[2]);
140 float minPtT = std::min(iTrks.first->pt(),iTrks.second->pt());
141 std::vector<float> VARS(10);
142 VARS[0]=Prob2v;
143 VARS[1]=log(sumMom.Pt());
144 VARS[2]=log(minPtT);
145 VARS[3]=log(vrtR<20. ? vSVPV.Rho() : vrtR);
146 VARS[4]=log(std::min(trk1Signif,trk2Signif));
147 VARS[5]=log(std::max(trk1Signif,trk2Signif));
148 VARS[6]=sumMom.M();
149 VARS[7]=sqrt(std::abs(1.-cosSVPV*cosSVPV));
150 VARS[8]=vSVPV.Eta();
151 VARS[9]=std::max(ihitR,jhitR);
152 quality=m_SV2T_BDT->GetGradBoostMVA(VARS);
153 if(quality<m_v2tBDTCut) return false; // BDT rejection
154
155 return true;
156 }
157
158//----------------------------
159// Vertex error along radius
160//----------------------------
161 double TwoTrackVrtBDTSelector::vrtRadiusError(const Amg::Vector3D & SecVrt, const std::vector<float> & VrtErr)
162 {
163 double DirX=SecVrt.x(), DirY=SecVrt.y();
164 double Covar = DirX*VrtErr[0]*DirX
165 +2.*DirX*VrtErr[1]*DirY
166 +DirY*VrtErr[2]*DirY;
167 Covar /= DirX*DirX + DirY*DirY;
168 Covar=std::sqrt(std::abs(Covar));
169 if(Covar != Covar) Covar = 0.;
170 return Covar;
171 }
172 //
173 // IBL/BL hit-on-track getters
175 {
176 uint8_t IBLhit,IBLexp;
177 if(!Part->summaryValue( IBLexp, xAOD::expectInnermostPixelLayerHit) ) IBLexp = 0;
178 if( IBLexp==0 ) return -1;
179 if(!Part->summaryValue( IBLhit, xAOD::numberOfInnermostPixelLayerHits) ) IBLhit = 0;
180 if(IBLhit) return 1;
181 else return 0;
182 }
184 {
185 uint8_t BLhit,BLexp;
186 if(!Part->summaryValue( BLexp, xAOD::expectNextToInnermostPixelLayerHit) ) BLexp = 0;
187 if( BLexp==0 ) return -1;
188 if(!Part->summaryValue( BLhit, xAOD::numberOfNextToInnermostPixelLayerHits) ) BLhit = 0;
189 if(BLhit) return 1;
190 else return 0;
191 }
192
193} // end Rec namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
Define macros for attributes used to control the static checker.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
static std::string find_calib_file(const std::string &logical_file_name)
Gaudi::Property< bool > m_useVertexCleaning
Gaudi::Property< float > m_vrt2TrMassLimit
Gaudi::Property< float > m_maxSVRadiusCut
ToolHandle< Trk::TrkVKalVrtFitter > m_fitSvc
std::unique_ptr< MVAUtils::BDT > m_SV2T_BDT
static int getIBLHit(const xAOD::TrackParticle *Part)
Gaudi::Property< float > m_cosSVPVCut
Gaudi::Property< float > m_vrt2TrPtMin
Gaudi::Property< bool > m_do2TrkIBLChecks
Gaudi::Property< std::string > m_calibFileName
bool isgood(const std::pair< const xAOD::TrackParticle *, const xAOD::TrackParticle * > tracks, const xAOD::Vertex &candV, std::pair< ROOT::Math::XYZTVector, ROOT::Math::XYZTVector > moms, const xAOD::Vertex &tPV) const final
static int getBLHit(const xAOD::TrackParticle *Part)
Gaudi::Property< float > m_firstPixelLayerR
Gaudi::Property< float > m_sel2VrtProbCut
Gaudi::Property< float > m_vrt2TrPtMax
static double vrtRadiusError(const Amg::Vector3D &secVrt, const std::vector< float > &vrtErr)
TwoTrackVrtBDTSelector(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< float > m_v2tBDTCut
float z() const
Returns the z position.
float y() const
Returns the y position.
float chiSquared() const
Returns the of the vertex fit as float.
const Amg::Vector3D & position() const
Returns the 3-pos.
float x() const
Returns the x position.
const std::vector< float > & covariance() const
Returns the covariance matrix as a simple vector of values.
Eigen::Matrix< double, 3, 1 > Vector3D
Gaudi Tools.
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
@ numberOfNextToInnermostPixelLayerHits
these are the hits in the 1st pixel barrel layer
@ expectNextToInnermostPixelLayerHit
Do we expect a 1st-layer barrel hit for this track?
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer