ATLAS Offline Software
TruthPVCollectionMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TruthPVCollectionMaker.cxx
7 // Makes a small collection of 'primary' vertices, one per event
8 // A bit like a collection of 'reconstructable' vertices
9 // Future option: try to add b-decay vertices, or LLP vertices?
10 
13 #include "StoreGate/ReadHandle.h"
14 #include "StoreGate/WriteHandle.h"
15 
17 
18 // Constructor
20  const std::string& n,
21  const IInterface* p)
22  : AthAlgTool(t,n,p)
23  {
24  declareInterface<DerivationFramework::IAugmentationTool>(this);
25 }
26 
27 // Destructor
29 // Athena initialize
31 {
32  ATH_MSG_VERBOSE("initialize() ...");
33 
34  // Check configuration, print errors, warning, and information for the user
35  ATH_CHECK(m_eventsKey.initialize());
36  ATH_MSG_INFO("Using " << m_eventsKey.fullKey() << " as the source collections for new truth collections");
37  ATH_CHECK(m_outVtxKey.initialize());
38  ATH_MSG_INFO("New truth vertex collection key: " << m_outVtxKey.fullKey() );
39 
40  return StatusCode::SUCCESS;
41 }
42 
43 
44 // Selection and collection creation
46 {
47  const EventContext& ctx{Gaudi::Hive::currentContext()};
48  // Retrieve truth collections
49  SG::ReadHandle<xAOD::TruthEventContainer> importedTruthEvents{m_eventsKey, ctx};
50  if (!importedTruthEvents.isValid()) {
51  ATH_MSG_ERROR("No TruthEvent collection with name " << m_eventsKey.fullKey() << " found in StoreGate!");
52  return StatusCode::FAILURE;
53  }
54 
55  // Create the new vertex containers
56  SG::WriteHandle<xAOD::TruthVertexContainer> writeHandleVtx{m_outVtxKey, ctx};
57  ATH_CHECK(writeHandleVtx.record(std::make_unique<xAOD::TruthVertexContainer>(),
58  std::make_unique<xAOD::TruthVertexAuxContainer>()));
59  xAOD::TruthVertexContainer* newVertexCollection = writeHandleVtx.ptr();
60  ATH_MSG_DEBUG( "Recorded new TruthVertexContainer with key: " << m_outVtxKey.fullKey());
61 
62  // Go through the events, add one vertex for each event
63  for (const auto * event : *importedTruthEvents){
64  // Just in case there is a place-holder
65  if (!event) continue;
66  // Try with the signal process vertex
67  const xAOD::TruthVertex* old_vert(event->signalProcessVertex());
68  // If that's not there, grab the first vertex
69  if (!old_vert && event->nTruthVertices()>0){
70  old_vert = event->truthVertex(0);
71  }
72  if (old_vert){
73  // Hit -- copy it!
74  // Make a new vertex and add it to the container
75  xAOD::TruthVertex* xTruthVertex = new xAOD::TruthVertex();
76  newVertexCollection->push_back( xTruthVertex );
77  // Set properties
78  xTruthVertex->setId(HepMC::status(old_vert));
79  xTruthVertex->setBarcode(HepMC::barcode(old_vert)); // FIXME barcode-based
80  xTruthVertex->setX(old_vert->x());
81  xTruthVertex->setY(old_vert->y());
82  xTruthVertex->setZ(old_vert->z());
83  xTruthVertex->setT(old_vert->t());
84  } else {
85  ATH_MSG_WARNING("No signal vertex or vertices associated to an input event!");
86  }
87  }
88  return StatusCode::SUCCESS;
89 }
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DerivationFramework::TruthPVCollectionMaker::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TruthPVCollectionMaker.cxx:45
xAOD::TruthVertex_v1::setT
void setT(float value)
Set the vertex time.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::TruthVertex_v1::setY
void setY(float value)
Set the y displacement of the vertex.
xAOD::TruthVertex_v1::y
float y() const
Vertex y displacement.
DerivationFramework::TruthPVCollectionMaker::initialize
StatusCode initialize()
Definition: TruthPVCollectionMaker.cxx:30
xAOD::TruthVertex_v1::t
float t() const
Vertex time.
WriteHandle.h
Handle class for recording to StoreGate.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
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
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition: TruthVertex.h:15
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TruthVertexAuxContainer.h
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthVertex_v1::setId
void setId(int value)
Obsolete function Set vertex ID code HepMC2 id == HepMC3 status, i.e.
xAOD::TruthVertex_v1::x
float x() const
Vertex x displacement.
xAOD::TruthVertex_v1::setZ
void setZ(float value)
Set the vertex's longitudinal distance from the origin.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::TruthVertex_v1::setBarcode
void setBarcode(int value)
Set barcode.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TruthVertex_v1::z
float z() const
Vertex longitudinal distance along the beam line form the origin.
DerivationFramework::TruthPVCollectionMaker::TruthPVCollectionMaker
TruthPVCollectionMaker(const std::string &t, const std::string &n, const IInterface *p)
Definition: TruthPVCollectionMaker.cxx:19
DerivationFramework::TruthPVCollectionMaker::~TruthPVCollectionMaker
~TruthPVCollectionMaker()
TruthPVCollectionMaker.h
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
HepMC::status
int status(const T &p)
Definition: MagicNumbers.h:138
HepMCHelpers.h
xAOD::TruthVertex_v1::setX
void setX(float value)
Set the x displacement of the vertex.