ATLAS Offline Software
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 
22 namespace Rec {
23 
24 //
25 //Constructor--------------------------------------------------------------
27  const std::string& name,
28  const IInterface* 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
Rec::TwoTrackVrtBDTSelector::m_useVertexCleaning
Gaudi::Property< bool > m_useVertexCleaning
Definition: TwoTrackVrtBDTSelector.h:73
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:235
BDT.h
xAOD::Vertex_v1::x
float x() const
Returns the x position.
Rec::TwoTrackVrtBDTSelector::finalize
StatusCode finalize()
Definition: TwoTrackVrtBDTSelector.cxx:70
Trk::proton
@ proton
Definition: ParticleHypothesis.h:34
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Rec::TwoTrackVrtBDTSelector::m_massP
double m_massP
Definition: TwoTrackVrtBDTSelector.h:89
Rec::TwoTrackVrtBDTSelector::isgood
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
Definition: TwoTrackVrtBDTSelector.cxx:77
Rec::TwoTrackVrtBDTSelector::m_cosSVPVCut
Gaudi::Property< float > m_cosSVPVCut
Definition: TwoTrackVrtBDTSelector.h:69
Rec::TwoTrackVrtBDTSelector::m_calibFileName
Gaudi::Property< std::string > m_calibFileName
Definition: TwoTrackVrtBDTSelector.h:78
Rec::TwoTrackVrtBDTSelector::m_vrt2TrPtMin
Gaudi::Property< float > m_vrt2TrPtMin
Definition: TwoTrackVrtBDTSelector.h:65
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
Rec::TwoTrackVrtBDTSelector::m_fitSvc
ToolHandle< Trk::TrkVKalVrtFitter > m_fitSvc
Definition: TwoTrackVrtBDTSelector.h:82
Rec::TwoTrackVrtBDTSelector::m_sel2VrtProbCut
Gaudi::Property< float > m_sel2VrtProbCut
Definition: TwoTrackVrtBDTSelector.h:67
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
Rec::TwoTrackVrtBDTSelector::m_maxSVRadiusCut
Gaudi::Property< float > m_maxSVRadiusCut
Definition: TwoTrackVrtBDTSelector.h:68
Rec::TwoTrackVrtBDTSelector::initialize
StatusCode initialize()
Definition: TwoTrackVrtBDTSelector.cxx:49
xAOD::expectInnermostPixelLayerHit
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
Definition: TrackingPrimitives.h:237
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
Rec::TwoTrackVrtBDTSelector::m_SV2T_BDT
std::unique_ptr< MVAUtils::BDT > m_SV2T_BDT
Definition: TwoTrackVrtBDTSelector.h:80
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Rec::TwoTrackVrtBDTSelector::m_firstPixelLayerR
Gaudi::Property< float > m_firstPixelLayerR
Definition: TwoTrackVrtBDTSelector.h:74
Rec::TwoTrackVrtBDTSelector::~TwoTrackVrtBDTSelector
virtual ~TwoTrackVrtBDTSelector()
Definition: TwoTrackVrtBDTSelector.cxx:44
xAOD::expectNextToInnermostPixelLayerHit
@ expectNextToInnermostPixelLayerHit
Do we expect a 1st-layer barrel hit for this track?
Definition: TrackingPrimitives.h:248
Rec
Name: MuonSpContainer.h Package : offline/Reconstruction/MuonIdentification/muonEvent.
Definition: FakeTrackBuilder.h:10
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::electron
@ electron
Definition: ParticleHypothesis.h:30
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::pion
@ pion
Definition: ParticleHypothesis.h:32
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
makeComparison.rootFile
rootFile
Definition: makeComparison.py:27
xAOD::Vertex_v1::z
float z() const
Returns the z position.
Trk::ParticleMasses::mass
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:56
xAOD::numberOfNextToInnermostPixelLayerHits
@ numberOfNextToInnermostPixelLayerHits
these are the hits in the 1st pixel barrel layer
Definition: TrackingPrimitives.h:249
PathResolver.h
Rec::TwoTrackVrtBDTSelector::m_vrt2TrPtMax
Gaudi::Property< float > m_vrt2TrPtMax
Definition: TwoTrackVrtBDTSelector.h:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
Rec::TwoTrackVrtBDTSelector::m_do2TrkIBLChecks
Gaudi::Property< bool > m_do2TrkIBLChecks
Definition: TwoTrackVrtBDTSelector.h:72
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Rec::TwoTrackVrtBDTSelector::m_massPi
double m_massPi
Definition: TwoTrackVrtBDTSelector.h:88
Rec::TwoTrackVrtBDTSelector::vrtRadiusError
static double vrtRadiusError(const Amg::Vector3D &secVrt, const std::vector< float > &vrtErr)
Definition: TwoTrackVrtBDTSelector.cxx:161
xAOD::Vertex_v1::covariance
const std::vector< float > & covariance() const
Returns the covariance matrix as a simple vector of values.
Rec::TwoTrackVrtBDTSelector::m_massE
double m_massE
Definition: TwoTrackVrtBDTSelector.h:90
Rec::TwoTrackVrtBDTSelector::TwoTrackVrtBDTSelector
TwoTrackVrtBDTSelector(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TwoTrackVrtBDTSelector.cxx:26
xAOD::Vertex_v1::chiSquared
float chiSquared() const
Returns the of the vertex fit as float.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.TrackLeptonConfig.quality
quality
Definition: TrackLeptonConfig.py:16
xAOD::Vertex_v1::y
float y() const
Returns the y position.
Rec::TwoTrackVrtBDTSelector::m_v2tBDTCut
Gaudi::Property< float > m_v2tBDTCut
Definition: TwoTrackVrtBDTSelector.h:77
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DetType::Part
Part
Definition: DetType.h:14
Rec::TwoTrackVrtBDTSelector::m_vrt2TrMassLimit
Gaudi::Property< float > m_vrt2TrMassLimit
Definition: TwoTrackVrtBDTSelector.h:64
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Rec::TwoTrackVrtBDTSelector::getBLHit
static int getBLHit(const xAOD::TrackParticle *Part)
Definition: TwoTrackVrtBDTSelector.cxx:183
AthAlgTool
Definition: AthAlgTool.h:26
checker_macros.h
Define macros for attributes used to control the static checker.
Rec::TwoTrackVrtBDTSelector::getIBLHit
static int getIBLHit(const xAOD::TrackParticle *Part)
Definition: TwoTrackVrtBDTSelector.cxx:174
TwoTrackVrtBDTSelector.h
xAOD::numberOfInnermostPixelLayerHits
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
Definition: TrackingPrimitives.h:238