ATLAS Offline Software
ZeeVertexRefittingTool.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 // ZeeVertexRefittingTool.cxx, (c) ATLAS Detector software
7 // Author: Ioannis Nomidis (ioannis.nomidis@cern.ch)
9 
15 
19 
20 #include "TLorentzVector.h"
21 
22 
23 namespace DerivationFramework {
24 
25  static const SG::AuxElement::Decorator<float> sumPt2("sumPt2");
26  static const SG::AuxElement::Decorator<float> vertices_dPhi("vertices_dPhi");
27  static const SG::AuxElement::Decorator<float> vertices_sumPt("vertices_sumPt");
28  static const SG::AuxElement::Decorator<float> vertices_sumPt2("vertices_sumPt2");
29  static const SG::AuxElement::Decorator<std::vector<ElementLink<xAOD::TrackParticleContainer> > > electronTrackLinksDecor("ElectronTrackLinks");
30 
32  const std::string& n,
33  const IInterface* p) :
35  m_expression("true"),
36  m_massCut(0.0)
37  {
38  declareInterface<DerivationFramework::IAugmentationTool>(this);
39  declareProperty("ObjectRequirements", m_expression);
40  declareProperty("LowMassCut", m_massCut);
41  declareProperty("MCSamples",m_MCSamples);
42  }
43 
45  {
46 
47  CHECK( m_pvrefitter.retrieve() );
48 
49  if (!m_expression.empty()) {
51  } else {
52  ATH_CHECK(initializeParser("true"));
53  }
55  ATH_CHECK( m_primaryVertexKey.initialize() );
57  ATH_CHECK( m_refitpvKey.initialize() );
58  if (m_refitpvKey.key().empty()) {
59  ATH_MSG_ERROR("No SG name provided for the output of ZeeVertexRefittingTool!");
60  return StatusCode::FAILURE;
61  }
62 
63  return StatusCode::SUCCESS;
64  }
65 
67  {
69  return StatusCode::SUCCESS;
70  }
71 
73  {
74  // skip mc samples not included in the MCSamples list
76 
78  bool skipSample = true;
79  for (auto mcid : m_MCSamples) {
80  if (mcid==eventInfo->mcChannelNumber()) {
81  skipSample = false;
82  break;
83  }
84  }
85  if (skipSample) return StatusCode::SUCCESS;
86  }
87 
88  // check that container we want to write in SG does not yet exist
89  if (evtStore()->contains<xAOD::VertexContainer>(m_refitpvKey.key())) {
90  ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_refitpvKey.key() << " which already exists. Please use a different key");
91  return StatusCode::FAILURE;
92  }
93 
94 
96 
97  xAOD::VertexContainer* refittedPVContainer = new xAOD::VertexContainer;
98  xAOD::VertexAuxContainer* refittedPVAuxContainer = new xAOD::VertexAuxContainer;
99  refittedPVContainer->setStore( refittedPVAuxContainer );
100 
102  ATH_CHECK(vertexContainer.recordNonConst(std::unique_ptr< xAOD::VertexContainer >(refittedPVContainer),
103  std::unique_ptr< xAOD::VertexAuxContainer >(refittedPVAuxContainer)));
104 
105  const xAOD::Vertex* pv = nullptr;
106  for ( const auto *v : *pv_cont ) {
107  if (v->vertexType()==xAOD::VxType::PriVtx) {
108  pv = v;
109  break;
110  }
111  }
112  if (!pv) {
113  return StatusCode::SUCCESS;
114  }
115  ATH_MSG_DEBUG("Found PV");
116 
117  // retrieve particle collections
119 
120  // create the vector which will hold the Zee pairs
121  std::vector< std::vector<unsigned int> > eepairs;
122  CHECK( makeZeePairs( &*electrons, eepairs ) );
123 
124  ATH_MSG_DEBUG("ee pairs found: " << eepairs.size());
125 
126  for (auto pair : eepairs) {
127  std::vector<const xAOD::TrackParticle*> tps = {
130  };
131 
132  TLorentzVector v0, v1, egamVec;
133  if(electrons->at(pair[0])->caloCluster())
134  {
135  v0.SetPtEtaPhiM(electrons->at(pair[0])->e()/cosh(electrons->at(pair[0])->caloCluster()->etaBE(2)),
136  electrons->at(pair[0])->caloCluster()->etaBE(2),
137  electrons->at(pair[0])->caloCluster()->phiBE(2),
138  0.0);
139  }
140 
141  if(electrons->at(pair[1])->caloCluster())
142  {
143  v1.SetPtEtaPhiM(electrons->at(pair[1])->e()/cosh(electrons->at(pair[1])->caloCluster()->etaBE(2)),
144  electrons->at(pair[1])->caloCluster()->etaBE(2),
145  electrons->at(pair[1])->caloCluster()->phiBE(2),
146  0.0);
147  }
148 
149  egamVec = v0+v1;
150 
151  ATH_MSG_DEBUG("Refitting PV for e tracks: " << tps[0] << " " << tps[1]);
152  xAOD::Vertex* pv_ref = m_pvrefitter->refitVertex(pv,tps);
153  if (pv_ref) {
154  refittedPVContainer->push_back(pv_ref);
155 
156  int ipv = 0;
157  for (const xAOD::Vertex* v : *pv_cont) {
158  xAOD::Vertex * nv = new xAOD::Vertex();
159  nv->makePrivateStore(v);
160  if(ipv !=0 ) refittedPVContainer->push_back(nv);
161  ipv++;
162  }
163 
164  for ( xAOD::Vertex *v : *refittedPVContainer )
165  {
166  float vert_sumpt = (log10(xAOD::PVHelpers::getVertexSumPt(v)));
167  float vert_sumpt2 = (log10(xAOD::PVHelpers::getVertexSumPt(v,2, false)));
168 
169  TLorentzVector vtxmom = xAOD::PVHelpers::getVertexMomentum(v, true, "");
170  float vert_dphi = (fabs(vtxmom.DeltaPhi(egamVec)));
171  //fill vertex variables
172  vertices_sumPt(*v) = vert_sumpt;
173  vertices_sumPt2(*v) = vert_sumpt2;
174  vertices_dPhi(*v) = vert_dphi;
175  }
176 
177 
178  ATH_MSG_DEBUG("refitted PV nTP: " << pv_ref->nTrackParticles() << " -- " << pv->nTrackParticles());
179  ATH_MSG_DEBUG("refitted PV z: " << pv_ref->z() << " -- " << pv->z());
180 
181  if (pv_ref->nTrackParticles() < pv->nTrackParticles()) {
182  sumPt2(*pv_ref) = xAOD::PVHelpers::getVertexSumPt(pv_ref, 2, false);
183  //set links to electrons, used only for matching, not for vertexing
184  std::vector<ElementLink<xAOD::TrackParticleContainer> > electronTrackLinks = {
185  electrons->at(pair[0])->trackParticleLink(),
186  electrons->at(pair[1])->trackParticleLink()
187  };
188  electronTrackLinksDecor(*pv_ref) = electronTrackLinks;
189  } else {
190  ATH_MSG_DEBUG("Electrons from pair not used in the refitting ");
191  }
192  }
193  else {
194  ATH_MSG_DEBUG("refitting failed");
195  }
196  }
197 
198  ATH_MSG_DEBUG("Vertex container size: " << refittedPVContainer->size());
199 
200  return StatusCode::SUCCESS;
201  }
202 
203  StatusCode ZeeVertexRefittingTool::makeZeePairs( const xAOD::ElectronContainer *particles, std::vector<std::vector<unsigned int> > &ZeePairs) const
204  {
205  if (particles->size()<2) return StatusCode::SUCCESS;
206 
207  // flags for the result of selection for each electron
208  std::vector<int> isSelected = m_parser->evaluateAsVector();
209  unsigned int nEntries = isSelected.size();
210 
211  // if there are no particles in one of the two lists to combine, just leave function
212  if (nEntries==0) return StatusCode::SUCCESS;
213 
214  // check the sizes are compatible
215  if (particles->size() != nEntries ) {
216  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
217  return StatusCode::FAILURE;
218  }
219 
220  // Double loop to get the opposite-charge pairs with m>50 GeV
221  for (unsigned int i=0; i<nEntries-1; ++i) {
222  if (isSelected[i]!=1) continue;
223  float qi = particles->at(i)->charge();
224 
225  for (unsigned int j=i+1; j<nEntries; ++j) {
226  if (isSelected[j]!=1) continue;
227  //std::vector<int> tmpPair; tmpPair.clear();
228  float qj = particles->at(j)->charge();
229  // opposite charge
230  if (qi*qj>=0) continue;
231 
232  //invariant mass
233  float mass = (particles->at(i)->p4()+particles->at(j)->p4()).M();
234  if (mass<m_massCut) continue;
235 
236  ZeePairs.push_back( {i, j} );
237  }
238  }
239  return StatusCode::SUCCESS;
240  }
241 }
SGxAODProxyLoader.h
ExpressionParserUserBase< AthAlgTool, 1 >::finalizeParser
StatusCode finalizeParser()
xAOD::PVHelpers::getVertexSumPt
float getVertexSumPt(const xAOD::Vertex *vertex, int power=1, bool useAux=true)
Loop over track particles associated with vertex and return scalar sum of pT^power in GeV (from auxda...
Definition: PhotonVertexHelpers.cxx:215
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ExpressionParserUserBase< AthAlgTool, 1 >::m_parser
std::conditional< NUM_PARSER==1, std::unique_ptr< ExpressionParsing::ExpressionParser >, std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > >::type m_parser
Definition: ExpressionParserUser.h:100
DerivationFramework::ZeeVertexRefittingTool::addBranches
StatusCode addBranches() const override
Pass the thinning service
Definition: ZeeVertexRefittingTool.cxx:72
ElectronxAODHelpers.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition: VertexContainer.h:14
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
DerivationFramework::ZeeVertexRefittingTool::ZeeVertexRefittingTool
ZeeVertexRefittingTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: ZeeVertexRefittingTool.cxx:31
DerivationFramework::ZeeVertexRefittingTool::m_refitpvKey
SG::WriteHandleKey< xAOD::VertexContainer > m_refitpvKey
Definition: ZeeVertexRefittingTool.h:50
xAOD::EventInfo_v1::mcChannelNumber
uint32_t mcChannelNumber() const
The MC generator's channel number.
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
DerivationFramework::ZeeVertexRefittingTool::m_pvrefitter
ToolHandle< Analysis::PrimaryVertexRefitter > m_pvrefitter
Definition: ZeeVertexRefittingTool.h:55
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::ZeeVertexRefittingTool::m_massCut
float m_massCut
Definition: ZeeVertexRefittingTool.h:46
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
SGNTUPProxyLoader.h
SG::WriteHandle::recordNonConst
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
xAOD::VertexAuxContainer
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
Definition: VertexAuxContainer.h:19
parseMapping.v0
def v0
Definition: parseMapping.py:149
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
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
DerivationFramework::ZeeVertexRefittingTool::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: ZeeVertexRefittingTool.h:51
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
DerivationFramework::ZeeVertexRefittingTool::m_primaryVertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVertexKey
Definition: ZeeVertexRefittingTool.h:48
DerivationFramework::ZeeVertexRefittingTool::m_electronKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronKey
Definition: ZeeVertexRefittingTool.h:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::Vertex_v1::z
float z() const
Returns the z position.
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
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
xAOD::PVHelpers::getVertexMomentum
TLorentzVector getVertexMomentum(const xAOD::Vertex *vertex, bool useAux=true, const std::string &derivationPrefix="")
Return vector sum of tracks associated with vertex (from auxdata if available and useAux = true)
Definition: PhotonVertexHelpers.cxx:175
ZeeVertexRefittingTool.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
ExpressionParserUser< AthAlgTool >::initializeParser
StatusCode initializeParser(const ExpressionParsing::SelectionArg< 1 > &selection_string)
PhotonVertexHelpers.h
ExpressionParserUser
Definition: ExpressionParserUser.h:107
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
MultipleProxyLoader.h
python.PyAthena.v
v
Definition: PyAthena.py:157
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
python.changerun.pv
pv
Definition: changerun.py:81
xAOD::EgammaHelpers::getOriginalTrackParticle
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
Definition: ElectronxAODHelpers.cxx:11
DerivationFramework::ZeeVertexRefittingTool::makeZeePairs
StatusCode makeZeePairs(const xAOD::ElectronContainer *particles, std::vector< std::vector< unsigned int > > &ZeePairs) const
Definition: ZeeVertexRefittingTool.cxx:203
DerivationFramework::ZeeVertexRefittingTool::initialize
StatusCode initialize() override
Definition: ZeeVertexRefittingTool.cxx:44
DerivationFramework::ZeeVertexRefittingTool::finalize
StatusCode finalize() override
Definition: ZeeVertexRefittingTool.cxx:66
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::ZeeVertexRefittingTool::m_MCSamples
std::vector< unsigned int > m_MCSamples
Definition: ZeeVertexRefittingTool.h:53
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
DerivationFramework::ZeeVertexRefittingTool::m_expression
std::string m_expression
Definition: ZeeVertexRefittingTool.h:45
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
VertexAuxContainer.h
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.