ATLAS Offline Software
TrkToLeptonPVTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /*
5  Tool to match a track to a Primary Vertex obtained with other leptons/tracks
6 
7  Author: Vadim Kostyukhin
8  e-mail: vadim.kostyukhin@cern.ch
9 */
11 
15 #include "GaudiKernel/EventContext.h"
16 //
17 //Constructor--------------------------------------------------------------
19  const std::string& name,
20  const IInterface* parent):
22  {
23  declareInterface<ITrkToLeptonPV>(this);
24  }
25 
26 //Destructor---------------------------------------------------------------
28  ATH_MSG_DEBUG("TrkToLeptonPVTool destructor called");
29  }
30 
31 //Initialize---------------------------------------------------------------
33  //-----
34  if (m_fitterSvc.retrieve().isFailure()) {
35  ATH_MSG_DEBUG("Can't find Trk::TrkVKalVrtFitter");
36  return StatusCode::FAILURE;
37  } else {
38  ATH_MSG_DEBUG("TrkToLeptonPVTool TrkVKalVrtFitter found");
39  }
40  //-----
42  //-----
43  return StatusCode::SUCCESS;
44  }
45 
47  {
48  ATH_MSG_DEBUG(" finalize()");
49  return StatusCode::SUCCESS;
50  }
51 
52 
53  std::unique_ptr<xAOD::Vertex> TrkToLeptonPVTool::matchTrkToPV( const xAOD::TrackParticle *trk, const xAOD::Vertex * PV,
54  const xAOD::EventInfo * eventINFO) const
55  {
56  static const SG::ConstAccessor<float> vyAcc("vy");
57  if(vyAcc.isAvailable(*trk)) {
58  std::vector<const xAOD::TrackParticle *> tpv(1,trk);
59  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(tpv,(*PV)));
60  }
61 
62  //---DAOD case
63  if( !eventINFO ) return {nullptr};
64  std::unique_ptr< SG::AuxStoreInternal > pAux;
66  std::vector<const xAOD::TrackParticle*> wrkTrkC(1);
67  pAux = std::make_unique< SG::AuxStoreInternal >();
68  TPC.setStore( pAux.get() );
69  TPC.reserve( 1 );
70  TPC.push_back(new (std::nothrow) xAOD::TrackParticle(*trk));
71  if(!TPC[0])return {nullptr};
72  const EventContext& ctx = Gaudi::Hive::currentContext();
73  const float mvx= (eventINFO) ? eventINFO->beamPosX() : 0.;
74  const float mvy= (eventINFO) ? eventINFO->beamPosY() : 0.;
75  static const SG::ConstAccessor<float> vzAcc("vz");
76  const float mvz= (vzAcc.isAvailable(*trk)) ? trk->vz() : 0.;
77  TPC[0]->setParametersOrigin( mvx, mvy, mvz);
78  wrkTrkC[0]=TPC[0];
79  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,wrkTrkC,(*PV)));
80 
81  }
82 
83 
84  std::unique_ptr<xAOD::Vertex>TrkToLeptonPVTool::npartVertex( const std::vector<const xAOD::TrackParticle*> & particles,
85  const xAOD::EventInfo * eventINFO) const
86  {
87  if(particles.empty()) return {nullptr};
88 
89  std::vector<const xAOD::TrackParticle*> tmpp(particles);
90  std::sort(tmpp.begin(),tmpp.end());
91  auto tst=std::unique(tmpp.begin(),tmpp.end());
92  if( tst != tmpp.end()) {
93  ATH_MSG_DEBUG(" Duplicated particles on input!");
94  return {nullptr};
95  }
96 
97  static const SG::ConstAccessor<float> vyAcc("vy");
98  bool fullxAOD=false; if(vyAcc.isAvailable(*particles[0])) fullxAOD=true;
99 
100  xAOD::Vertex BEAM;
101  BEAM.makePrivateStore();
102  BEAM.setX(0.); BEAM.setY(0.); BEAM.setZ(0.);
103  std::vector<float> defaultCovar {0.015f*0.015f,0.f,0.015f*0.015f,0.f,0.f,1.e6};
104  BEAM.setCovariance(defaultCovar);
105  float beamtiltX=0.;
106  float beamtiltY=0.;
107  AmgSymMatrix(3) beamcov;
108  beamcov.setIdentity();
109  //-------------------------------
110  if(eventINFO){
111  BEAM.setX(eventINFO->beamPosX());
112  BEAM.setY(eventINFO->beamPosY());
113  BEAM.setZ(eventINFO->beamPosZ());
114  beamcov(0,0) = eventINFO->beamPosSigmaX() * eventINFO->beamPosSigmaX();
115  beamcov(1,0) = beamcov(0,1) = eventINFO->beamPosSigmaXY();
116  beamcov(1,1) = eventINFO->beamPosSigmaY() * eventINFO->beamPosSigmaY();
117  beamcov(2,2) = eventINFO->beamPosSigmaZ() * eventINFO->beamPosSigmaZ()*1.e6; //Remove any constraint in Z direction
118  BEAM.setCovariancePosition(beamcov);
119  beamtiltX= eventINFO->beamTiltXZ();
120  beamtiltY= eventINFO->beamTiltYZ();
121  }
123 
124  if(beamSpotHandle.isValid() && fullxAOD ){
125  ATH_MSG_DEBUG("Beam service is present");
126  BEAM.setPosition(beamSpotHandle->beamVtx().position());
127  beamcov = beamSpotHandle->beamVtx().covariancePosition();
128  beamcov(2,2) *= 1.e6; //Remove any constraint in Z direction
129  BEAM.setCovariancePosition(beamcov);
130  beamtiltX= beamSpotHandle->beamTilt(0);
131  beamtiltY= beamSpotHandle->beamTilt(1);
132  }
133  if(fullxAOD){ ATH_MSG_DEBUG("xAOD data"); }
134  else { ATH_MSG_DEBUG("DxAOD data");}
135  ATH_MSG_DEBUG("BEAM x,y,z="<<BEAM.x()<<","<<BEAM.y()<<","<<BEAM.z());
136  ATH_MSG_DEBUG("BEAM covariance="<<BEAM.covariance()[0]<<","<<BEAM.covariance()[1]<<","<<BEAM.covariance()[2]
137  <<","<<BEAM.covariance()[3]<<","<<BEAM.covariance()[4]<<","<<BEAM.covariance()[5]);
138  ATH_MSG_DEBUG("BEAM tiltX,Y="<<beamtiltX<<","<<beamtiltY);
139 
140  const EventContext& ctx = Gaudi::Hive::currentContext();
141 
142  if(fullxAOD){
143  //---If beam is tilted -> make pre-fit and translate beam constraint to pre-fitted position
144  if( beamtiltX!=0. || beamtiltY!=0.) {
145  std::unique_ptr<xAOD::Vertex> iniVertex = m_fitterSvc->fit(ctx,particles,BEAM);
146  if(!iniVertex) return {nullptr};
147  BEAM.setX(BEAM.x()+beamtiltX*iniVertex->z());
148  BEAM.setY(BEAM.y()+beamtiltY*iniVertex->z());
149  }
150  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,particles,BEAM));
151  }
152 
153  //
154  //---DxAOD case
155  //
156  int NPRT=particles.size();
157  std::unique_ptr< SG::AuxStoreInternal > pAux;
159  std::vector<const xAOD::TrackParticle*> wrkTrkC(NPRT);
160  pAux = std::make_unique< SG::AuxStoreInternal >();
161  TPC.setStore( pAux.get() );
162  TPC.reserve( NPRT );
163  static const SG::ConstAccessor<float> vzAcc("vz");
164  for(int i=0; i<NPRT; i++){
165  TPC.push_back(new (std::nothrow) xAOD::TrackParticle(*particles[i]));
166  if(!TPC[i])return {nullptr};
167  const float mvx= (eventINFO) ? eventINFO->beamPosX() : 0.;
168  const float mvy= (eventINFO) ? eventINFO->beamPosY() : 0.;
169  const float mvz= (vzAcc.isAvailable(*particles[i])) ? particles[i]->vz() : 0.;
170  TPC[i]->setParametersOrigin( mvx, mvy, mvz);
171  wrkTrkC[i]=TPC[i];
172  }
173 
174  //---If beam is tilted -> make pre-fit and translate beam constraint to pre-fitted position
175  if( beamtiltX!=0. || beamtiltY!=0.) {
176  std::unique_ptr<xAOD::Vertex> iniVertex = m_fitterSvc->fit(ctx,wrkTrkC,BEAM);
177  if(!iniVertex) return {nullptr};
178  BEAM.setX(BEAM.x()+beamtiltX*iniVertex->z());
179  BEAM.setY(BEAM.y()+beamtiltY*iniVertex->z());
180  }
181  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,wrkTrkC,BEAM));
182  }
183 
184 
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::Vertex_v1::setPosition
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAOD::EventInfo_v1::beamTiltXZ
float beamTiltXZ() const
The beam's tilt in radians in XZ.
TrkToLeptonPVTool::matchTrkToPV
virtual std::unique_ptr< xAOD::Vertex > matchTrkToPV(const xAOD::TrackParticle *trk, const xAOD::Vertex *PV, const xAOD::EventInfo *=0) const override final
Method to match any tracks to a known Primary Vertex.
Definition: TrkToLeptonPVTool.cxx:53
TrkToLeptonPVTool::finalize
virtual StatusCode finalize() override
Definition: TrkToLeptonPVTool.cxx:46
xAOD::TrackParticle_v1::vz
float vz() const
The z origin for the parameters.
xAOD::EventInfo_v1::beamTiltYZ
float beamTiltYZ() const
The beam's tilt in radians in YZ.
xAOD::EventInfo_v1::beamPosSigmaX
float beamPosSigmaX() const
The width of the beam spot in the X direction.
SG::ConstAccessor< float >
xAOD::Vertex_v1::setX
void setX(float value)
Sets the x position.
xAOD::Vertex_v1::setCovariance
void setCovariance(const std::vector< float > &value)
Sets the covariance matrix as a simple vector of values.
xAOD::EventInfo_v1::beamPosX
float beamPosX() const
X coordinate of the beam spot position.
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:50
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TrkVKalVrtFitter.h
TrkToLeptonPVTool::TrkToLeptonPVTool
TrkToLeptonPVTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrkToLeptonPVTool.cxx:18
TrkToLeptonPVTool::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: TrkToLeptonPVTool.h:50
xAOD::EventInfo_v1::beamPosY
float beamPosY() const
Y coordinate of the beam spot position.
xAOD::Vertex_v1::setZ
void setZ(float value)
Sets the z position.
TrkToLeptonPVTool::initialize
virtual StatusCode initialize() override
Definition: TrkToLeptonPVTool.cxx:32
TrkToLeptonPVTool::~TrkToLeptonPVTool
virtual ~TrkToLeptonPVTool()
Definition: TrkToLeptonPVTool.cxx:27
xAOD::Vertex_v1::setY
void setY(float value)
Sets the y position.
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
xAOD::EventInfo_v1::beamPosSigmaZ
float beamPosSigmaZ() const
The length of the beam spot in the Z direction.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Vertex_v1::z
float z() const
Returns the z position.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
xAOD::EventInfo_v1::beamPosSigmaY
float beamPosSigmaY() const
The width of the beam spot in the Y direction.
TrkToLeptonPVTool::m_fitterSvc
ToolHandle< Trk::IVertexFitter > m_fitterSvc
Definition: TrkToLeptonPVTool.h:51
xAOD::EventInfo_v1::beamPosZ
float beamPosZ() const
Z coordinate of the beam spot position.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TrkToLeptonPVTool.h
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::Vertex_v1::covariance
const std::vector< float > & covariance() const
Returns the covariance matrix as a simple vector of values.
xAOD::EventInfo_v1::beamPosSigmaXY
float beamPosSigmaXY() const
The beam spot shape's X-Y correlation.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::Vertex_v1::y
float y() const
Returns the y position.
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
TrkToLeptonPVTool::npartVertex
virtual std::unique_ptr< xAOD::Vertex > npartVertex(const std::vector< const xAOD::TrackParticle * > &, const xAOD::EventInfo *=0) const override final
Method to create a Primary Vertex using N(>=2) identified tracks (e.g.
Definition: TrkToLeptonPVTool.cxx:84
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
AthAlgTool
Definition: AthAlgTool.h:26
AuxStoreInternal.h
An auxiliary data store that holds data internally.
xAOD::Vertex_v1::setCovariancePosition
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.