ATLAS Offline Software
TrkToLeptonPVTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
14 #include "GaudiKernel/EventContext.h"
15 //
16 //Constructor--------------------------------------------------------------
18  const std::string& name,
19  const IInterface* parent):
21  {
22  declareInterface<ITrkToLeptonPV>(this);
23  }
24 
25 //Destructor---------------------------------------------------------------
27  ATH_MSG_DEBUG("TrkToLeptonPVTool destructor called");
28  }
29 
30 //Initialize---------------------------------------------------------------
32  //-----
33  if (m_fitterSvc.retrieve().isFailure()) {
34  ATH_MSG_DEBUG("Can't find Trk::TrkVKalVrtFitter");
35  return StatusCode::FAILURE;
36  } else {
37  ATH_MSG_DEBUG("TrkToLeptonPVTool TrkVKalVrtFitter found");
38  }
39  //-----
41  //-----
42  return StatusCode::SUCCESS;
43  }
44 
46  {
47  ATH_MSG_DEBUG(" finalize()");
48  return StatusCode::SUCCESS;
49  }
50 
51 
52  std::unique_ptr<xAOD::Vertex> TrkToLeptonPVTool::matchTrkToPV( const xAOD::TrackParticle *trk, const xAOD::Vertex * PV,
53  const xAOD::EventInfo * eventINFO) const
54  {
55  if(trk->isAvailable<float>("vy")) {
56  std::vector<const xAOD::TrackParticle *> tpv(1,trk);
57  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(tpv,(*PV)));
58  }
59 
60  //---DAOD case
61  if( !eventINFO ) return {nullptr};
62  std::unique_ptr< SG::AuxStoreInternal > pAux;
64  std::vector<const xAOD::TrackParticle*> wrkTrkC(1);
65  pAux = std::make_unique< SG::AuxStoreInternal >();
66  TPC.setStore( pAux.get() );
67  TPC.reserve( 1 );
68  TPC.push_back(new (std::nothrow) xAOD::TrackParticle(*trk));
69  if(!TPC[0])return {nullptr};
70  const EventContext& ctx = Gaudi::Hive::currentContext();
71  const float mvx= (eventINFO) ? eventINFO->beamPosX() : 0.;
72  const float mvy= (eventINFO) ? eventINFO->beamPosY() : 0.;
73  const float mvz= (trk->isAvailable<float>("vz")) ? trk->vz() : 0.;
74  TPC[0]->setParametersOrigin( mvx, mvy, mvz);
75  wrkTrkC[0]=TPC[0];
76  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,wrkTrkC,(*PV)));
77 
78  }
79 
80 
81  std::unique_ptr<xAOD::Vertex>TrkToLeptonPVTool::npartVertex( const std::vector<const xAOD::TrackParticle*> & particles,
82  const xAOD::EventInfo * eventINFO) const
83  {
84  if(particles.empty()) return {nullptr};
85 
86  std::vector<const xAOD::TrackParticle*> tmpp(particles);
87  std::sort(tmpp.begin(),tmpp.end());
88  auto tst=std::unique(tmpp.begin(),tmpp.end());
89  if( tst != tmpp.end()) {
90  ATH_MSG_DEBUG(" Duplicated particles on input!");
91  return {nullptr};
92  }
93 
94  bool fullxAOD=false; if(particles[0]->isAvailable<float>("vy")) fullxAOD=true;
95 
96  xAOD::Vertex BEAM;
97  BEAM.makePrivateStore();
98  BEAM.setX(0.); BEAM.setY(0.); BEAM.setZ(0.);
99  std::vector<float> defaultCovar={0.015*0.015,0.,0.015*0.015,0.,0.,1.e6};
100  BEAM.setCovariance(defaultCovar);
101  float beamtiltX=0.;
102  float beamtiltY=0.;
103  AmgSymMatrix(3) beamcov;
104  beamcov.setIdentity();
105  //-------------------------------
106  if(eventINFO){
107  BEAM.setX(eventINFO->beamPosX());
108  BEAM.setY(eventINFO->beamPosY());
109  BEAM.setZ(eventINFO->beamPosZ());
110  beamcov(0,0) = eventINFO->beamPosSigmaX() * eventINFO->beamPosSigmaX();
111  beamcov(1,0) = beamcov(0,1) = eventINFO->beamPosSigmaXY();
112  beamcov(1,1) = eventINFO->beamPosSigmaY() * eventINFO->beamPosSigmaY();
113  beamcov(2,2) = eventINFO->beamPosSigmaZ() * eventINFO->beamPosSigmaZ()*1.e6; //Remove any constraint in Z direction
114  BEAM.setCovariancePosition(beamcov);
115  beamtiltX= eventINFO->beamTiltXZ();
116  beamtiltY= eventINFO->beamTiltYZ();
117  }
119 
120  if(beamSpotHandle.isValid() && fullxAOD ){
121  ATH_MSG_DEBUG("Beam service is present");
122  BEAM.setPosition(beamSpotHandle->beamVtx().position());
123  beamcov = beamSpotHandle->beamVtx().covariancePosition();
124  beamcov(2,2) *= 1.e6; //Remove any constraint in Z direction
125  BEAM.setCovariancePosition(beamcov);
126  beamtiltX= beamSpotHandle->beamTilt(0);
127  beamtiltY= beamSpotHandle->beamTilt(1);
128  }
129  if(fullxAOD){ ATH_MSG_DEBUG("xAOD data"); }
130  else { ATH_MSG_DEBUG("DxAOD data");}
131  ATH_MSG_DEBUG("BEAM x,y,z="<<BEAM.x()<<","<<BEAM.y()<<","<<BEAM.z());
132  ATH_MSG_DEBUG("BEAM covariance="<<BEAM.covariance()[0]<<","<<BEAM.covariance()[1]<<","<<BEAM.covariance()[2]
133  <<","<<BEAM.covariance()[3]<<","<<BEAM.covariance()[4]<<","<<BEAM.covariance()[5]);
134  ATH_MSG_DEBUG("BEAM tiltX,Y="<<beamtiltX<<","<<beamtiltY);
135 
136  const EventContext& ctx = Gaudi::Hive::currentContext();
137 
138  if(fullxAOD){
139  //---If beam is tilted -> make pre-fit and translate beam constraint to pre-fitted position
140  if( beamtiltX!=0. || beamtiltY!=0.) {
141  std::unique_ptr<xAOD::Vertex> iniVertex = m_fitterSvc->fit(ctx,particles,BEAM);
142  if(!iniVertex) return {nullptr};
143  BEAM.setX(BEAM.x()+beamtiltX*iniVertex->z());
144  BEAM.setY(BEAM.y()+beamtiltY*iniVertex->z());
145  }
146  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,particles,BEAM));
147  }
148 
149  //
150  //---DxAOD case
151  //
152  int NPRT=particles.size();
153  std::unique_ptr< SG::AuxStoreInternal > pAux;
155  std::vector<const xAOD::TrackParticle*> wrkTrkC(NPRT);
156  pAux = std::make_unique< SG::AuxStoreInternal >();
157  TPC.setStore( pAux.get() );
158  TPC.reserve( NPRT );
159  for(int i=0; i<NPRT; i++){
160  TPC.push_back(new (std::nothrow) xAOD::TrackParticle(*particles[i]));
161  if(!TPC[i])return {nullptr};
162  const float mvx= (eventINFO) ? eventINFO->beamPosX() : 0.;
163  const float mvy= (eventINFO) ? eventINFO->beamPosY() : 0.;
164  const float mvz= (particles[i]->isAvailable<float>("vz")) ? particles[i]->vz() : 0.;
165  TPC[i]->setParametersOrigin( mvx, mvy, mvz);
166  wrkTrkC[i]=TPC[i];
167  }
168 
169  //---If beam is tilted -> make pre-fit and translate beam constraint to pre-fitted position
170  if( beamtiltX!=0. || beamtiltY!=0.) {
171  std::unique_ptr<xAOD::Vertex> iniVertex = m_fitterSvc->fit(ctx,wrkTrkC,BEAM);
172  if(!iniVertex) return {nullptr};
173  BEAM.setX(BEAM.x()+beamtiltX*iniVertex->z());
174  BEAM.setY(BEAM.y()+beamtiltY*iniVertex->z());
175  }
176  return std::unique_ptr<xAOD::Vertex>(m_fitterSvc->fit(ctx,wrkTrkC,BEAM));
177  }
178 
179 
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:52
TrkToLeptonPVTool::finalize
virtual StatusCode finalize() override
Definition: TrkToLeptonPVTool.cxx:45
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.
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:52
TrkVKalVrtFitter.h
TrkToLeptonPVTool::TrkToLeptonPVTool
TrkToLeptonPVTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrkToLeptonPVTool.cxx:17
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:31
TrkToLeptonPVTool::~TrkToLeptonPVTool
virtual ~TrkToLeptonPVTool()
Definition: TrkToLeptonPVTool.cxx:26
xAOD::Vertex_v1::setY
void setY(float value)
Sets the y position.
lumiFormat.i
int i
Definition: lumiFormat.py:92
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< xAOD::TrackParticle_v1 >
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:192
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:172
xAOD::IParticle::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if a user property is available for reading or not.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:131
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::Vertex_v1::y
float y() const
Returns the y position.
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
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:81
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
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.