ATLAS Offline Software
VertexIterativeFitMergingTool.h
Go to the documentation of this file.
1 // This is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef PROMPT_VERTEXITERATIVEFITMERGINGTOOL_H
8 #define PROMPT_VERTEXITERATIVEFITMERGINGTOOL_H
9 
10 /**********************************************************************************
11  * @Package: LeptonTaggers
12  * @Class : VertexIterativeFitMergingTool
13  * @Author : Fudong He
14  * @Author : Rustem Ospanov
15  *
16  * @Brief :
17  *
18  * Merge the input vertices and output merged vertices.
19  *
20  **********************************************************************************/
21 
22 // Local
24 #include "IVertexMergingTool.h"
25 #include "IVertexFittingTool.h"
26 
27 // Athena
31 #include "GaudiKernel/ITHistSvc.h"
32 #include "GaudiKernel/ToolHandle.h"
33 #include "GaudiKernel/ServiceHandle.h"
34 
35 // xAOD
36 #include "xAODTracking/Vertex.h"
38 
39 // ROOT
40 #include "TH1.h"
41 
42 
43 namespace Prompt
44 {
45  /*
46  A 2-track vertex.
47  */
48  struct TwoTrackVtx
49  {
50  TwoTrackVtx():vertex(nullptr), trackId0(0), trackId1(0), vertexFitProb(1000.0), sumTrackPt(0.0) {}
51 
55 
56  double vertexFitProb;
57  double sumTrackPt;
58  };
59 
60  //=============================================================================
62  {
63  bool operator()(const TwoTrackVtx &lhs, const TwoTrackVtx &rhs) { return lhs.sumTrackPt > rhs.sumTrackPt; }
64  };
65 
66  //=============================================================================
67  struct SortTracksByPt
68  {
69  bool operator()(const xAOD::TrackParticle *lhs, const xAOD::TrackParticle *rhs) { return lhs->pt() > rhs->pt(); }
70  };
71 
72 
73  //=============================================================================
75  {
76  explicit SortTwoTrackVtxByDistToSeed(const xAOD::Vertex *seed_):seed(seed_) {}
77 
78  bool operator()(const TwoTrackVtx &lhs, const TwoTrackVtx &rhs)
79  {
80  return Prompt::getDistance(seed, lhs.vertex) < Prompt::getDistance(seed, rhs.vertex);
81  }
82 
83  const xAOD::Vertex *seed;
84  };
85 
86  //======================================================================================================
87  // Vertex Merging Tool
88  //
89  class VertexIterativeFitMergingTool: public AthAlgTool, virtual public IVertexMergingTool
90  {
91  public:
92 
93  VertexIterativeFitMergingTool(const std::string &name,
94  const std::string &type,
95  const IInterface *parent);
96 
97  virtual StatusCode initialize() override;
98 
99  /*
100  Perform a deep merge of the initial vertices.
101 
102  In the r21 version, the input initVtxs was defined as
103  a const std::vector<xAOD::Vertex*> object. The const-ness
104  had to be removed to work with unique_ptr objects. However,
105  we should avoid modifying the underlying objects in initVtxs.
106  */
108  const FittingInput &input,
109  const xAOD::TrackParticle *tracklep,
110  std::vector<std::unique_ptr<xAOD::Vertex>> &initVtxs,
111  const std::vector<const xAOD::TrackParticle *> &selectedTracks
112  ) override;
113 
114  private:
115 
117  const FittingInput &input,
118  std::vector<std::unique_ptr<xAOD::Vertex>> &initVtxs,
120  const VtxType vtxType
121  );
122 
123  /*
124  Given a seed vertex, this function generates a new merged vertex.
125 
126  A new vertex is created and assigned to the newMergedVtx reference.
127  */
128  void getNewMergedVertex(
129  xAOD::Vertex* seedVtx,
130  std::unique_ptr<xAOD::Vertex> &newMergedVtx,
131  const FittingInput &input,
133  std::vector<TwoTrackVtx> &vtxs2Track,
134  const VtxType vtxType
135  );
136 
137  /*
138  Iteratively fit a new vertex from a seed vertex and group
139  of two-track vertices.
140 
141  A new vertex will be created. Because of the complicated ownership
142  semantics of the recursive calls, we release the unique_ptr that is
143  generated when this vertex is created. The caller must capture the
144  bare pointer!
145  */
147  const FittingInput &input,
148  xAOD::Vertex* seedVtx,
149  const VtxType vtxType,
150  std::vector<TwoTrackVtx> &others
151  );
152  /*
153  Second signature for the iterative vertex fit.
154  This one assumes the seed is owned by the caller.
155  Used to prevent memory leaks within the recursion step
156  */
158  const FittingInput &input,
159  std::unique_ptr<xAOD::Vertex> & seedVtx,
160  const VtxType vtxType,
161  std::vector<TwoTrackVtx> &others
162  );
163 
164  std::unique_ptr<xAOD::Vertex> fitSeedPlusOtherVertex(
165  const FittingInput &input,
166  const xAOD::Vertex *seedVtx,
167  const xAOD::Vertex *otherVtx,
168  const VtxType vtxType
169  );
170 
171  bool passVertexSelection(const xAOD::Vertex *vtx) const;
172 
173  /*
174  Remove 2-tracks that are succesfully merged into one vertex.
175 
176  This is done by iterating over the list of 2-track vertices and removing
177  those for which both tracks overlap with the mergedVtx.
178  */
180  const xAOD::Vertex *mergedVtx,
181  std::vector<TwoTrackVtx> &vtxs
182  ) const;
183 
184  void plotVertexDistances(const std::vector<TwoTrackVtx> &others);
185 
186  std::vector<const xAOD::TrackParticle *> getTracksWithoutVertex(
187  const std::vector<xAOD::Vertex*> &passVtxs,
188  const std::vector<const xAOD::TrackParticle *> &selectedTracks
189  );
190 
191  /*
192  Fit new 2-track vertices from a list of tracks.
193 
194  Since this fits new vertices, it returns a list of unique_ptr
195  so that the caller will handle memory.
196  */
197  std::vector<std::unique_ptr<xAOD::Vertex>> fit2TrackVertexes(
198  const FittingInput &input,
199  std::vector<const xAOD::TrackParticle *> &selectedTracks,
200  const VtxType vtxType
201  );
202 
203  StatusCode makeHist(TH1 *&h, const std::string &key, int nbin, double xmin, double xmax);
204 
205  //
206  // Properties:
207  //
208  ToolHandle<Prompt::IVertexFittingTool> m_vertexFitterTool {
209  this, "VertexFittingTool",
210  "Prompt::VertexFittingTool/VertexFittingTool"
211  };
213  this, "THistSvc", "THistSvc/THistSvc"
214  };
215 
216  Gaudi::Property<double> m_minFitProb {this, "minFitProb", 0.01,
217  "minimum fit probability requirement for a vertex"
218  };
219  Gaudi::Property<double> m_minCandOverSeedFitProbRatio {
220  this, "minCandOverSeedFitProbRatio", 0.2,
221  "minimum requirement of the fit probability of new merged vertex / fit probability of seed vertex"
222  };
223  Gaudi::Property<unsigned> m_maxExtraTracks {
224  this, "maxExtraTracks", 10,
225  "maximum number of tracks without good lepton+track vertex that we will used for further fitting of vertexes without lepton"
226  };
227 
228  Gaudi::Property<std::string> m_outputStream {
229  this, "outputStream", ""
230  };
231 
232  //
233  // Development histograms
234  //
239 
242 
247 
253 
258 
262 
267  };
268 }
269 
270 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
Prompt::VertexIterativeFitMergingTool::m_histSelectedTrackCountAll
TH1 * m_histSelectedTrackCountAll
Definition: VertexIterativeFitMergingTool.h:269
Prompt::VertexIterativeFitMergingTool::m_histVtx2trkPairDistZoom
TH1 * m_histVtx2trkPairDistZoom
Definition: VertexIterativeFitMergingTool.h:265
Prompt::VertexIterativeFitMergingTool::m_minFitProb
Gaudi::Property< double > m_minFitProb
Definition: VertexIterativeFitMergingTool.h:226
Prompt::VertexIterativeFitMergingTool::m_histNvtxMerged
TH1 * m_histNvtxMerged
Definition: VertexIterativeFitMergingTool.h:248
Prompt::VertexIterativeFitMergingTool::fitSeedVertexCluster
xAOD::Vertex * fitSeedVertexCluster(const FittingInput &input, xAOD::Vertex *seedVtx, const VtxType vtxType, std::vector< TwoTrackVtx > &others)
Definition: VertexIterativeFitMergingTool.cxx:428
Prompt
Definition: DecoratePromptLeptonImproved.h:45
PromptUtils.h
Prompt::VertexIterativeFitMergingTool::m_histVtxWithoutLepton2TrkNPass
TH1 * m_histVtxWithoutLepton2TrkNPass
Definition: VertexIterativeFitMergingTool.h:274
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitDistToCurr
TH1 * m_histNewVtxFitDistToCurr
Definition: VertexIterativeFitMergingTool.h:253
get_generator_info.result
result
Definition: get_generator_info.py:21
Prompt::TwoTrackVtx::TwoTrackVtx
TwoTrackVtx()
Definition: VertexIterativeFitMergingTool.h:70
Prompt::VertexIterativeFitMergingTool::fitSeedPlusOtherVertex
std::unique_ptr< xAOD::Vertex > fitSeedPlusOtherVertex(const FittingInput &input, const xAOD::Vertex *seedVtx, const xAOD::Vertex *otherVtx, const VtxType vtxType)
Definition: VertexIterativeFitMergingTool.cxx:702
Prompt::VertexIterativeFitMergingTool::mergeInitVertices
virtual MergeResultNotOwner mergeInitVertices(const FittingInput &input, const xAOD::TrackParticle *tracklep, std::vector< std::unique_ptr< xAOD::Vertex >> &initVtxs, const std::vector< const xAOD::TrackParticle * > &selectedTracks) override
Definition: VertexIterativeFitMergingTool.cxx:68
Prompt::SortTracksByPt::operator()
bool operator()(const xAOD::TrackParticle *lhs, const xAOD::TrackParticle *rhs)
Definition: VertexIterativeFitMergingTool.h:79
Prompt::VertexIterativeFitMergingTool::fit2TrackVertexes
std::vector< std::unique_ptr< xAOD::Vertex > > fit2TrackVertexes(const FittingInput &input, std::vector< const xAOD::TrackParticle * > &selectedTracks, const VtxType vtxType)
Definition: VertexIterativeFitMergingTool.cxx:772
Prompt::VertexIterativeFitMergingTool::m_maxExtraTracks
Gaudi::Property< unsigned > m_maxExtraTracks
Definition: VertexIterativeFitMergingTool.h:233
Prompt::VertexIterativeFitMergingTool::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Definition: VertexIterativeFitMergingTool.h:222
Prompt::VertexIterativeFitMergingTool::m_histVtxWithoutLepton2TrkNMerged
TH1 * m_histVtxWithoutLepton2TrkNMerged
Definition: VertexIterativeFitMergingTool.h:276
Prompt::VertexIterativeFitMergingTool::makeHist
StatusCode makeHist(TH1 *&h, const std::string &key, int nbin, double xmin, double xmax)
Definition: VertexIterativeFitMergingTool.cxx:841
Prompt::TwoTrackVtx::vertex
xAOD::Vertex * vertex
Definition: VertexIterativeFitMergingTool.h:72
Prompt::VertexIterativeFitMergingTool::VertexIterativeFitMergingTool
VertexIterativeFitMergingTool(const std::string &name, const std::string &type, const IInterface *parent)
Definition: VertexIterativeFitMergingTool.cxx:16
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProbCandOverSeed3Trk
TH1 * m_histNewVtxFitProbCandOverSeed3Trk
Definition: VertexIterativeFitMergingTool.h:261
Prompt::VertexIterativeFitMergingTool::plotVertexDistances
void plotVertexDistances(const std::vector< TwoTrackVtx > &others)
Definition: VertexIterativeFitMergingTool.cxx:620
Prompt::SortTwoTrackVtxByDistToSeed::SortTwoTrackVtxByDistToSeed
SortTwoTrackVtxByDistToSeed(const xAOD::Vertex *seed_)
Definition: VertexIterativeFitMergingTool.h:86
Prompt::VertexIterativeFitMergingTool::m_histVtxWithoutLepton2TrkNTrack
TH1 * m_histVtxWithoutLepton2TrkNTrack
Definition: VertexIterativeFitMergingTool.h:273
IVertexFittingTool.h
Prompt::FittingInput
Definition: IVertexFittingTool.h:60
Prompt::VertexIterativeFitMergingTool::m_minCandOverSeedFitProbRatio
Gaudi::Property< double > m_minCandOverSeedFitProbRatio
Definition: VertexIterativeFitMergingTool.h:229
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProbCandOverSeedPass
TH1 * m_histNewVtxFitProbCandOverSeedPass
Definition: VertexIterativeFitMergingTool.h:259
Prompt::VertexIterativeFitMergingTool::m_histSelectedTrackCountMatch2Vtx
TH1 * m_histSelectedTrackCountMatch2Vtx
Definition: VertexIterativeFitMergingTool.h:270
Prompt::TwoTrackVtx::sumTrackPt
double sumTrackPt
Definition: VertexIterativeFitMergingTool.h:77
Prompt::VertexIterativeFitMergingTool
Definition: VertexIterativeFitMergingTool.h:100
AthAlgorithm.h
Prompt::VertexIterativeFitMergingTool::removeMerged2TrackVertexes
unsigned removeMerged2TrackVertexes(const xAOD::Vertex *mergedVtx, std::vector< TwoTrackVtx > &vtxs) const
Definition: VertexIterativeFitMergingTool.cxx:568
Prompt::VertexIterativeFitMergingTool::getTracksWithoutVertex
std::vector< const xAOD::TrackParticle * > getTracksWithoutVertex(const std::vector< xAOD::Vertex * > &passVtxs, const std::vector< const xAOD::TrackParticle * > &selectedTracks)
Definition: VertexIterativeFitMergingTool.cxx:638
Prompt::SortTwoTrackVtxByDistToSeed::operator()
bool operator()(const TwoTrackVtx &lhs, const TwoTrackVtx &rhs)
Definition: VertexIterativeFitMergingTool.h:88
Prompt::VertexIterativeFitMergingTool::passVertexSelection
bool passVertexSelection(const xAOD::Vertex *vtx) const
Definition: VertexIterativeFitMergingTool.cxx:680
Prompt::VertexIterativeFitMergingTool::m_histVtx2TrkPairSig2
TH1 * m_histVtx2TrkPairSig2
Definition: VertexIterativeFitMergingTool.h:267
Prompt::getDistance
double getDistance(const xAOD::Vertex *vtx1, const xAOD::Vertex *vtx2)
Definition: PromptUtils.cxx:41
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitDistToSeedFail
TH1 * m_histNewVtxFitDistToSeedFail
Definition: VertexIterativeFitMergingTool.h:256
xmin
double xmin
Definition: listroot.cxx:60
Prompt::VertexIterativeFitMergingTool::initialize
virtual StatusCode initialize() override
Definition: VertexIterativeFitMergingTool.cxx:27
Prompt::VertexIterativeFitMergingTool::m_histVtx2TrkPairSig1
TH1 * m_histVtx2TrkPairSig1
Definition: VertexIterativeFitMergingTool.h:266
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Prompt::TwoTrackVtx::trackId0
const xAOD::TrackParticle * trackId0
Definition: VertexIterativeFitMergingTool.h:73
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitChi2
TH1 * m_histNewVtxFitChi2
Definition: VertexIterativeFitMergingTool.h:250
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Prompt::TwoTrackVtx::vertexFitProb
double vertexFitProb
Definition: VertexIterativeFitMergingTool.h:76
Prompt::VertexIterativeFitMergingTool::m_histVtxWithoutLepton2TrkNPassUnmerged
TH1 * m_histVtxWithoutLepton2TrkNPassUnmerged
Definition: VertexIterativeFitMergingTool.h:275
Prompt::VertexIterativeFitMergingTool::getNewMergedVertex
void getNewMergedVertex(xAOD::Vertex *seedVtx, std::unique_ptr< xAOD::Vertex > &newMergedVtx, const FittingInput &input, std::vector< TwoTrackVtx >::iterator &currVit, std::vector< TwoTrackVtx > &vtxs2Track, const VtxType vtxType)
Definition: VertexIterativeFitMergingTool.cxx:386
Prompt::SortTwoTrackVtxBySumTrackPt::operator()
bool operator()(const TwoTrackVtx &lhs, const TwoTrackVtx &rhs)
Definition: VertexIterativeFitMergingTool.h:73
Vertex.h
Prompt::VertexIterativeFitMergingTool::m_histSelectedTrackCountWithout2Vtx
TH1 * m_histSelectedTrackCountWithout2Vtx
Definition: VertexIterativeFitMergingTool.h:271
Prompt::IVertexMergingTool
Definition: PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/IVertexMergingTool.h:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProb
TH1 * m_histNewVtxFitProb
Definition: VertexIterativeFitMergingTool.h:251
Prompt::VtxType
VtxType
Definition: IVertexFittingTool.h:48
Prompt::VertexIterativeFitMergingTool::m_histNvtx2TrkPass
TH1 * m_histNvtx2TrkPass
Definition: VertexIterativeFitMergingTool.h:246
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitDistToSeed
TH1 * m_histNewVtxFitDistToSeed
Definition: VertexIterativeFitMergingTool.h:254
TrackParticle.h
Prompt::TwoTrackVtx::trackId1
const xAOD::TrackParticle * trackId1
Definition: VertexIterativeFitMergingTool.h:74
Prompt::VertexIterativeFitMergingTool::m_histNvtx2TrkInit
TH1 * m_histNvtx2TrkInit
Definition: VertexIterativeFitMergingTool.h:245
Prompt::SortTwoTrackVtxByDistToSeed
Definition: VertexIterativeFitMergingTool.h:85
h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Prompt::TwoTrackVtx
Definition: VertexIterativeFitMergingTool.h:59
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitDistToSeedPass
TH1 * m_histNewVtxFitDistToSeedPass
Definition: VertexIterativeFitMergingTool.h:255
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TH1
Definition: rootspy.cxx:268
xmax
double xmax
Definition: listroot.cxx:61
Prompt::SortTwoTrackVtxByDistToSeed::seed
const xAOD::Vertex * seed
Definition: VertexIterativeFitMergingTool.h:93
Prompt::SortTwoTrackVtxBySumTrackPt
Definition: VertexIterativeFitMergingTool.h:72
Prompt::VertexIterativeFitMergingTool::m_histVtx2TrkPairDist
TH1 * m_histVtx2TrkPairDist
Definition: VertexIterativeFitMergingTool.h:264
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
IVertexMergingTool.h
Prompt::VertexIterativeFitMergingTool::mergeIteratively2TrackVtxs
bool mergeIteratively2TrackVtxs(const FittingInput &input, std::vector< std::unique_ptr< xAOD::Vertex >> &initVtxs, MergeResultNotOwner &result, const VtxType vtxType)
Definition: VertexIterativeFitMergingTool.cxx:227
Prompt::VertexIterativeFitMergingTool::m_vertexFitterTool
ToolHandle< Prompt::IVertexFittingTool > m_vertexFitterTool
Definition: VertexIterativeFitMergingTool.h:218
Prompt::VertexIterativeFitMergingTool::m_histNvtx2TrkUnmerged
TH1 * m_histNvtx2TrkUnmerged
Definition: VertexIterativeFitMergingTool.h:247
Prompt::VertexIterativeFitMergingTool::m_outputStream
Gaudi::Property< std::string > m_outputStream
Definition: VertexIterativeFitMergingTool.h:238
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProbCandOverSeed
TH1 * m_histNewVtxFitProbCandOverSeed
Definition: VertexIterativeFitMergingTool.h:258
ServiceHandle< ITHistSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Prompt::MergeResultNotOwner
Definition: PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/IVertexMergingTool.h:69
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProbCandOverSeedFail
TH1 * m_histNewVtxFitProbCandOverSeedFail
Definition: VertexIterativeFitMergingTool.h:260
Prompt::VertexIterativeFitMergingTool::m_histNewVtxFitProbCandOverSeed3TrkPass
TH1 * m_histNewVtxFitProbCandOverSeed3TrkPass
Definition: VertexIterativeFitMergingTool.h:262