15 #include "AthLinks/ElementLink.h"
30 declareInterface<IVertexFinder>(
this);
33 InDetConversionFinderTools::~InDetConversionFinderTools()=
default;
39 ATH_MSG_FATAL(
"Unable to initialize InDetConversionFinderTools");
40 return StatusCode::FAILURE;
43 if (m_iVertexFitter.retrieve().isFailure()) {
45 return StatusCode::FAILURE;
50 if (m_trackPairsSelector.retrieve().isFailure()) {
51 ATH_MSG_FATAL(
"Failed to retrieve tool " << m_trackPairsSelector);
52 return StatusCode::FAILURE;
57 if (m_vertexEstimator.retrieve().isFailure()) {
58 ATH_MSG_FATAL(
"Failed to retrieve tool " << m_vertexEstimator);
59 return StatusCode::FAILURE;
64 if (m_postSelector.retrieve().isFailure()) {
66 return StatusCode::FAILURE;
71 if (m_singleTrkConvTool.retrieve().isFailure()) {
72 ATH_MSG_FATAL(
"Failed to retrieve tool " << m_singleTrkConvTool);
73 return StatusCode::FAILURE;
78 if (m_trkSelector.retrieve().isFailure()) {
80 return StatusCode::FAILURE;
85 return StatusCode::SUCCESS;
90 return StatusCode::SUCCESS;
94 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
95 InDetConversionFinderTools::findVertex(
const EventContext& ,
99 ATH_MSG_ERROR(
"Using Track Container not currently supported returning an empty conatiner");
104 InDetConversionContainer->setStore( InDetConversionContainerAux );
106 return std::make_pair(InDetConversionContainer,InDetConversionContainerAux);
110 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
111 InDetConversionFinderTools::findVertex(
const EventContext& ctx,
119 InDetConversionContainer->setStore(InDetConversionContainerAux);
121 int numConversions = 0;
129 std::vector<const xAOD::TrackParticle*> negSelectedTracks;
130 negSelectedTracks.clear();
131 std::vector<const xAOD::TrackParticle*> posSelectedTracks;
132 posSelectedTracks.clear();
133 std::vector<int> negIndx;
134 std::vector<int> posIndx;
139 for (iter = (*trk_coll).begin(); iter != (*trk_coll).end(); ++iter) {
140 if (m_trkSelector->decision(
144 if ((*iter)->charge() < 0) {
145 negSelectedTracks.push_back(*iter);
146 negIndx.push_back(0);
148 posSelectedTracks.push_back(*iter);
149 posIndx.push_back(0);
156 std::vector<const xAOD::TrackParticle*>::const_iterator iter_pos;
157 std::vector<const xAOD::TrackParticle*>::const_iterator iter_neg;
158 std::vector<Amg::Vector3D> positionList;
159 positionList.clear();
160 std::vector<const xAOD::TrackParticle*> trackParticleList;
161 trackParticleList.clear();
162 std::vector<const xAOD::TrackParticle*> singleTrackConvList;
163 singleTrackConvList.clear();
167 for (iter_pos = posSelectedTracks.begin();
168 iter_pos != posSelectedTracks.end();
173 for (iter_neg = negSelectedTracks.begin();
174 iter_neg != negSelectedTracks.end();
179 std::map<std::string, float> intersectionDecors;
180 if (!passPreSelection(cache,
186 intersectionDecors)) {
187 positionList.clear();
192 if (positionList.size() < 2) {
194 positionList.clear();
198 trackParticleList.push_back(*iter_pos);
199 trackParticleList.push_back(*iter_neg);
201 std::unique_ptr<xAOD::Vertex> myVertex =
202 m_iVertexFitter->fit(ctx, trackParticleList, initPos);
203 trackParticleList.clear();
209 if ((m_isConversion && m_postSelector->selectConversionCandidate(
210 myVertex.get(),
flag, positionList)) ||
212 m_postSelector->selectSecVtxCandidate(
213 myVertex.get(),
flag, positionList,
type))) {
220 if (!m_isConversion && !(
type == 101) && !(
type == 110) &&
228 if (m_decorateVertices) {
230 "Decorating vertex with values used in track pair selector");
231 for (
const auto& kv :
232 m_trackPairsSelector->getLastValues(cache)) {
234 acc (*myVertex) = kv.second;
236 ATH_MSG_DEBUG(
"Decorating vertex with values used in vertex "
238 for (
const auto& kv : intersectionDecors) {
240 acc (*myVertex) = kv.second;
253 if (m_isConversion) {
255 InDetConversionContainer->
push_back(std::move(myVertex));
259 InDetConversionContainer->
push_back(std::move(myVertex));
268 ATH_MSG_DEBUG(
"VxCandidate failed the post selection cuts!");
274 positionList.clear();
277 ATH_MSG_DEBUG(
"Number of conversions found passing post selection cuts: "
281 if (m_isConversion) {
282 for (
int ip = 0;
ip <
int(posIndx.size()); ++
ip) {
283 if (posIndx[
ip] == 0)
284 singleTrackConvList.push_back(posSelectedTracks[
ip]);
286 for (
int in = 0; in <
int(negIndx.size()); ++in) {
287 if (negIndx[in] == 0)
288 singleTrackConvList.push_back(negSelectedTracks[in]);
292 itke = singleTrackConvList.end();
294 for (itk = singleTrackConvList.begin(); itk != itke; ++itk) {
295 if (!m_singleTrkConvTool->selectSingleTrackParticleConversion((*itk)))
296 ATH_MSG_DEBUG(
"Track failed single track conversion selection");
299 sConver = m_singleTrkConvTool->buildSingleTrackParticleConversion(
300 (*itk), InDetConversionContainer);
302 sConver->clearTracks();
306 sConver->addTrackAtVertex(newLink);
310 if (m_decorateVertices) {
311 ATH_MSG_DEBUG(
"Decorating single track vertex with dummy values "
312 "used in track pair selector");
313 for (
const auto& kv : m_trackPairsSelector->getLastValues(cache)) {
318 ATH_MSG_DEBUG(
"Decorating single track vertex with dummy values "
319 "used in vertex point estimator");
320 for (
const std::string&
k : m_vertexEstimator->decorKeys()) {
325 ATH_MSG_DEBUG(
"Decorating single track vertex with dummy values "
326 "used in post selector");
327 m_postSelector->decorateVertex(*sConver, 0., 0., 0., 0., 0.);
332 ATH_MSG_DEBUG(
"Number successful reconstructed single track conversion: "
336 return std::make_pair(InDetConversionContainer,
337 InDetConversionContainerAux);
341 InDetConversionFinderTools::passPreSelection(
342 TrackPairsSelector::Cache& cache,
345 std::vector<Amg::Vector3D>& trackList,
348 std::map<std::string, float>& intersectionDecors)
const
370 if(nclusNeg>0 && nclusPos>0)
flag= 0;
371 if((nclusNeg>0 && nclusPos==0) || (nclusNeg==0 && nclusPos>0))
flag = 1;
372 if(nclusNeg==0 && nclusPos==0)
flag = 2;
373 if(m_removeTrt && (
flag==1 ||
flag==2))
return false;
375 if (m_trackPairsSelector->selectTrackParticlePair( track_pos,track_neg,cache)){
381 m_vertexEstimator->getCirclesIntersectionPoint(
382 &perPos, &perNeg,
flag, errorcode, intersectionDecors));
383 if(m_isConversion && errorcode != 0)
return false;
385 Amg::Vector3D v_direction = perPos.momentum() + perNeg.momentum();
386 double d_alpha = (startingPoint.adjoint()*v_direction)[0]/(startingPoint.mag()*v_direction.mag());
387 if(d_alpha<m_MinFlightAngle)
return false;
389 initPos = startingPoint;
390 double startingPointR = startingPoint.perp();
391 if(startingPointR<800.) {
408 ATH_MSG_WARNING(
"Track Particle does not contain first Measurement track parameters");
422 ATH_MSG_WARNING(
"Track Particle does not contain first Measurement track parameters");
428 double posR = trkPar_pos.
position().perp();
429 double negR = trkPar_neg.
position().perp();
430 double diffR = 1000.;
431 if((startingPointR-posR)<(startingPointR-negR)) diffR = startingPointR-posR;
432 else diffR = startingPointR-negR;
433 if(startingPointR<m_MinInitVtxR)
return false;
434 if(diffR<m_mindR || diffR>m_maxdR)
return false;
441 trackList.push_back(trkPar_pos.
position());
442 trackList.push_back(trkPar_neg.
position());