ATLAS Offline Software
AugmentationToolExample.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // AugmentationToolExample.cxx, (c) ATLAS Detector software
8 // Author: Thomas Gillam (thomas.gillam@cern.ch)
9 //
10 // This is a trivial example of tool that creates extra information
11 // and places it in the StoreGate
12 // The example shows how to do it with (a) simple vectors and (b) dressing
13 // of objects (tracks in this case)
14 // The same information is written into both
15 
19 #include <vector>
20 #include <string>
21 
22 namespace DerivationFramework {
23 
25  const std::string& n,
26  const IInterface* p) :
27  AthAlgTool(t,n,p)
28  {
29  declareInterface<DerivationFramework::IAugmentationTool>(this);
30  }
31 
33  {
34 
35  // Set up the vector
36  std::unique_ptr<std::vector<float> > track_z0_PV(new std::vector<float>());
37 
38  // Set up the decorators
39  SG::AuxElement::Decorator< float > decorator("DFDecoratorExample");
40 
41  // CALCULATION OF THE NEW VARIABLE
42  // Get Primary vertex
43  const xAOD::VertexContainer* vertices = evtStore()->retrieve< const xAOD::VertexContainer >("PrimaryVertices");
44 
45  if(!vertices) {
46  ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key PrimaryVertices");
47  return StatusCode::FAILURE;
48  }
49 
50  const xAOD::Vertex* pv(0);
51  for (const xAOD::Vertex* vx : *vertices) {
52  if (vx->vertexType() == xAOD::VxType::PriVtx) {
53  pv = vx;
54  break;
55  }
56  }
57 
58  // Get the track container
59  const xAOD::TrackParticleContainer* tracks = evtStore()->retrieve< const xAOD::TrackParticleContainer >("InDetTrackParticles");
60 
61  if(!tracks) {
62  ATH_MSG_ERROR ("Couldn't retrieve TrackParticleContainer with key InDetTrackParticles");
63  return StatusCode::FAILURE;
64  }
65 
66  // Get track z0 w.r.t PV: this is what we're adding
67  for (xAOD::TrackParticleContainer::const_iterator trackIt=tracks->begin(); trackIt!=tracks->end(); ++trackIt) {
68  if (pv) {
69  float z0wrtPV = (*trackIt)->z0() + (*trackIt)->vz() - pv->z(); // CALCULATE THE QUANTITY
70  track_z0_PV->push_back(z0wrtPV); // ADD TO VECTOR
71  decorator(**trackIt) = z0wrtPV; // DECORATE THE TRACK
72  } else {
73  track_z0_PV->push_back(999.);
74  decorator(**trackIt) = 999.;
75  }
76  }
77 
78  // Write decision to SG for access by downstream algs
79  if (evtStore()->contains<std::vector<float> >("DFAugmentationExample")) {
80  ATH_MSG_ERROR("Tool is attempting to write StoreGate keys which already exists. Please use a different key");
81  return StatusCode::FAILURE;
82  } else {
83  CHECK(evtStore()->record(std::move(track_z0_PV), "DFAugmentationExample"));
84  }
85 
86  return StatusCode::SUCCESS;
87  }
88 }
DerivationFramework::AugmentationToolExample::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: AugmentationToolExample.cxx:32
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AugmentationToolExample.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Utils::z0wrtPV
double z0wrtPV(const xAOD::TrackParticle *trk, const xAOD::Vertex *vtx)
Provide the trk DCA w.r.t. the PV.
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/src/Utils.cxx:8
DerivationFramework::AugmentationToolExample::AugmentationToolExample
AugmentationToolExample(const std::string &t, const std::string &n, const IInterface *p)
Definition: AugmentationToolExample.cxx:24
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.changerun.pv
pv
Definition: changerun.py:81
AthAlgTool
Definition: AthAlgTool.h:26
TrackParticleContainer.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.