ATLAS Offline Software
NewVrtSecInclusiveAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6  // NewVrtSecInclusiveAlg.cxx, (c) ATLAS Detector software
7  // Author: Vadim Kostyukhin (vadim.kostyukhin@cern.ch)
13 
14 #include "TLorentzVector.h"
15 #include "CxxUtils/sincos.h"
16 
17 namespace Rec {
18 
19  static const SG::AuxElement::Decorator<float> bvrtM("bvrtM");
20  static const SG::AuxElement::Decorator<float> bvrtPt("bvrtPt");
21  static const SG::AuxElement::Decorator<float> bvrtPhi("bvrtPhi");
22  static const SG::AuxElement::Decorator<float> bvrtEta("bvrtEta");
23  static const SG::AuxElement::Decorator<float> mindRjetP("mindRjetP");
24  static const SG::AuxElement::Decorator<float> mindRjetV("mindRjetV");
25  static const SG::AuxElement::Decorator<float> mindRBTagSV("mindRBTagSV");
26 
27  NewVrtSecInclusiveAlg::NewVrtSecInclusiveAlg(const std::string& name, ISvcLocator* pSvcLocator) :
28  AthReentrantAlgorithm( name, pSvcLocator ),
29  m_bvertextool("Rec::NewVrtSecInclusiveTool/SVTool",this)
30  {
31  declareProperty("BVertexTool",m_bvertextool);
32  }
33 
35  {
37  ATH_CHECK( m_pvContainerKey.initialize() );
38  ATH_CHECK( m_jetContainerKey.initialize() );
39  ATH_CHECK( m_btsvContainerKey.initialize() );
40  ATH_CHECK( m_foundVerticesKey.initialize() );
41  ATH_CHECK( m_bvertextool.retrieve() );
42  return StatusCode::SUCCESS;
43  }
44 
46  {
47  return StatusCode::SUCCESS;
48  }
49 
50  StatusCode NewVrtSecInclusiveAlg::execute(const EventContext &ctx) const
51  {
52 
53  const xAOD::Vertex* pv = nullptr;
54  std::vector<const xAOD::TrackParticle*> trkparticles(0);
55 
56  //-- Extract TrackParticles
58  if ( !tp_cont.isValid() ) {
59  ATH_MSG_WARNING( "No TrackParticle container found in TES" );
60  }else{
61  for(const auto *tp : (*tp_cont)) trkparticles.push_back(tp);
62  }
63 
64  //-- Extract Primary Vertex
66  if ( !pv_cont.isValid() ) {
67  ATH_MSG_WARNING( "No Primary Vertices container found in TDS" );
68  }else{
69  //-- Extract PV itself
70  for ( const auto *v : *pv_cont ) {
71  if (v->vertexType()==xAOD::VxType::PriVtx) { pv = v; break; }
72  }
73  }
74 
75  //-- Extract SV from b-jets Vertices
77  if ( !btsv_cont.isValid() ) {
78  ATH_MSG_WARNING( "No BTagging Vertices container found in TDS" );
79  }
80 
81  //-- Extract Jets
83  if ( !jet_cont.isValid() ) {
84  ATH_MSG_WARNING( "No AntiKt4EMPFlowJet container found in TES" );
85  }
86 
87  //-- create container for new vertices
88  auto bVertexContainer = std::make_unique<xAOD::VertexContainer>();
89  auto bVertexAuxContainer = std::make_unique<xAOD::VertexAuxContainer>();
90  bVertexContainer->setStore(bVertexAuxContainer.get());
91 
92  if( pv && trkparticles.size()>2 ){
93  std::unique_ptr<Trk::VxSecVertexInfo> foundVrts = m_bvertextool->findAllVertices(trkparticles,*pv);
94  if(foundVrts && !foundVrts->vertices().empty()){
95  const std::vector<xAOD::Vertex*> vtmp=foundVrts->vertices();
96  double mindRSVPV=1.e3; // Check coincidence with existing SV1 vertex
97  for(const auto & iv : vtmp) {
98  if( btsv_cont.isValid() ){
99  for ( const auto *btsv : *btsv_cont ) mindRSVPV=std::min(Amg::deltaR(btsv->position()-pv->position(),iv->position()-pv->position()),mindRSVPV);
100  }
101  bVertexContainer->push_back(iv);
102  std::vector< Trk::VxTrackAtVertex > & vtrk = iv->vxTrackAtVertex();
103  TLorentzVector VSUM(0.,0.,0.,0.);
104  TLorentzVector tmp;
105  for(auto & it : vtrk){
106  const Trk::Perigee* mPer = dynamic_cast<const Trk::Perigee*>(it.perigeeAtVertex());
107  CxxUtils::sincos phi(mPer->parameters()[Trk::phi]);
108  CxxUtils::sincos theta(mPer->parameters()[Trk::theta]);
109  double absP = 1./std::abs(mPer->parameters()[Trk::qOverP]);
110  tmp.SetXYZM( phi.cs*theta.sn*absP, phi.sn*theta.sn*absP, theta.cs*absP, Trk::ParticleMasses::mass[Trk::pion]);
111  VSUM+=tmp;
112  }
113  bvrtM(*iv) =VSUM.M();
114  bvrtPt(*iv) =VSUM.Pt();
115  bvrtEta(*iv)=VSUM.Eta();
116  bvrtPhi(*iv)=VSUM.Phi();
117  TVector3 SVmPV(iv->x()-pv->x(),iv->y()-pv->y(),iv->z()-pv->z());
118  double mindRMOM=1.e3, mindRSV=1.e3;
119  if( jet_cont.isValid() ){
120  for(const auto *jet : (*jet_cont)) {
121  mindRMOM=std::min(VSUM.DeltaR(jet->p4()),mindRMOM);
122  mindRSV =std::min(SVmPV.DeltaR(jet->p4().Vect()),mindRSV);
123  }
124  }
125  mindRBTagSV(*iv) =mindRSVPV;
126  mindRjetP(*iv) =mindRMOM;
127  mindRjetV(*iv) =mindRSV;
128  }
129  }
130  }
131  ATH_MSG_DEBUG("Found Vertices in this event: " << bVertexContainer->size());
132  //
133  //--Update track ElementLinks
134  for(auto iv : (*bVertexContainer)){
135  std::vector< ElementLink< xAOD::TrackParticleContainer > > newLinkVec;
136  for(auto &it : iv->trackParticleLinks()){
138  tmpLnk.setStorableObject(*tp_cont);
139  newLinkVec.push_back(tmpLnk);
140  }
141  iv->setTrackParticleLinks(newLinkVec);
142  }
143 
145  ATH_CHECK( vrtInThisEvent.record (std::move(bVertexContainer),
146  std::move(bVertexAuxContainer)) );
147  return StatusCode::SUCCESS;
148  }
149 }
150 
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Rec::NewVrtSecInclusiveAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: NewVrtSecInclusiveAlg.cxx:50
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::VxSecVertexInfo::vertices
const std::vector< xAOD::Vertex * > & vertices() const
Definition: VxSecVertexInfo.cxx:100
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Rec::NewVrtSecInclusiveAlg::m_btsvContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_btsvContainerKey
Definition: NewVrtSecInclusiveAlg.h:46
sincos.h
Helper to simultaneously calculate sin and cos of the same angle.
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Rec::NewVrtSecInclusiveAlg::finalize
StatusCode finalize() override
Definition: NewVrtSecInclusiveAlg.cxx:45
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Rec::NewVrtSecInclusiveAlg::m_pvContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_pvContainerKey
Definition: NewVrtSecInclusiveAlg.h:44
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
Rec
Name: MuonSpContainer.h Package : offline/Reconstruction/MuonIdentification/muonEvent.
Definition: FakeTrackBuilder.h:10
Trk::theta
@ theta
Definition: ParamDefs.h:66
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::pion
@ pion
Definition: ParticleHypothesis.h:29
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
Rec::NewVrtSecInclusiveAlg::m_bvertextool
ToolHandle< Rec::IVrtInclusive > m_bvertextool
Definition: NewVrtSecInclusiveAlg.h:49
Rec::NewVrtSecInclusiveAlg::m_jetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
Definition: NewVrtSecInclusiveAlg.h:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
min
#define min(a, b)
Definition: cfImp.cxx:40
Trk::ParticleMasses::mass
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:53
NewVrtSecInclusiveAlg.h
Rec::NewVrtSecInclusiveAlg::NewVrtSecInclusiveAlg
NewVrtSecInclusiveAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NewVrtSecInclusiveAlg.cxx:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
EventInfo.h
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Amg::deltaR
double deltaR(const Amg::Vector3D &v1, const Amg::Vector3D &v2)
Definition: GeoPrimitivesHelpers.h:122
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
GeoPrimitivesHelpers.h
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
python.changerun.pv
pv
Definition: changerun.py:81
CxxUtils::sincos
Helper to simultaneously calculate sin and cos of the same angle.
Definition: sincos.h:76
Trk::phi
@ phi
Definition: ParamDefs.h:75
Rec::NewVrtSecInclusiveAlg::initialize
StatusCode initialize() override
Definition: NewVrtSecInclusiveAlg.cxx:34
Rec::NewVrtSecInclusiveAlg::m_tpContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tpContainerKey
Definition: NewVrtSecInclusiveAlg.h:43
VertexAuxContainer.h
Rec::NewVrtSecInclusiveAlg::m_foundVerticesKey
SG::WriteHandleKey< xAOD::VertexContainer > m_foundVerticesKey
Definition: NewVrtSecInclusiveAlg.h:48