ATLAS Offline Software
TruthVertex_v1.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 // System include(s):
6 #include <cmath>
7 
8 // xAOD include(s):
10 
11 // Local include(s):
14 
15 namespace xAOD {
16 
18  : SG::AuxElement() {
19 
20  }
21 
23  //
24  // Implementation for the "MC specific" functions
25  //
26 
29  setBarcode )
30 
31  //
33 
35  //
36  // Implementation for the links to the truth particles
37  //
38 
41  setIncomingParticleLinks )
42 
44  static const SG::AuxElement::Accessor< TruthVertex_v1::TPLinks_t >
45  incomingParticleLinksAcc( "incomingParticleLinks" );
46 
47  size_t TruthVertex_v1::nIncomingParticles() const {
48 
49  // Check if the variable is available:
50  if( ! incomingParticleLinksAcc.isAvailable( *this ) ) {
51  // If not, just tell the user that there aren't any incoming particles:
52  return 0;
53  }
54 
55  // Return the size of the vector:
56  return incomingParticleLinksAcc( *this ).size();
57  }
58 
59  std::vector<const TruthParticle*> TruthVertex_v1::particles_in() const {
60  std::vector<const TruthParticle*> res;
61  for (size_t i=0; i<nIncomingParticles();i++) res.push_back(incomingParticle(i));
62  return res;
63  }
64  std::vector<const TruthParticle*> TruthVertex_v1::particles_out() const {
65  std::vector<const TruthParticle*> res;
66  for (size_t i=0; i<nOutgoingParticles();i++) res.push_back(outgoingParticle(i));
67  return res;
68  }
70 
71  // Check that the variable exists, and that it has enough elements in it:
72  if( ( ! incomingParticleLinksAcc.isAvailable( *this ) ) ||
73  ( incomingParticleLinksAcc( *this ).size() <= index ) ) {
74  return nullptr;
75  }
76 
77  // Retrieve the link object and check its validity:
78  const TPLink_t& ipl = incomingParticleLinksAcc( *this )[ index ];
79  if( ! ipl.isValid() ) {
80  return nullptr;
81  }
82 
83  // Finally, de-reference the link:
84  return *ipl;
85  }
86 
88 
89  incomingParticleLinksAcc( *this ).push_back( link );
90  return;
91  }
92 
94 
95  incomingParticleLinksAcc( *this ).clear();
96  return;
97  }
98 
100  outgoingParticleLinks,
101  setOutgoingParticleLinks )
102 
103 
105  outgoingParticleLinksAcc( "outgoingParticleLinks" );
106 
107  size_t TruthVertex_v1::nOutgoingParticles() const {
108 
109  // Check if the variable is available:
110  if( ! outgoingParticleLinksAcc.isAvailable( *this ) ) {
111  // If not, just tell the user that there aren't any outgoing particles:
112  return 0;
113  }
114 
115  // Return the size of the vector:
116  return outgoingParticleLinksAcc( *this ).size();
117  }
118 
120 
121  // Check that the variable exists, and that it has enough elements in it:
122  if( ( ! outgoingParticleLinksAcc.isAvailable( *this ) ) ||
123  ( outgoingParticleLinksAcc( *this ).size() <= index ) ) {
124  return nullptr;
125  }
126 
127  // Retrieve the link object and check its validity:
128  const TPLink_t& opl = outgoingParticleLinksAcc( *this )[ index ];
129  if( ! opl.isValid() ) {
130  return nullptr;
131  }
132 
133  // Finally, de-reference the link:
134  return *opl;
135  }
136 
138 
139  outgoingParticleLinksAcc( *this ).push_back( link );
140  return;
141  }
142 
144 
145  outgoingParticleLinksAcc( *this ).clear();
146  return;
147  }
148 
149  //
151 
153  //
154  // Implementation of the functions specifying the vertex's position
155  //
156 
158 
160 
162 
164 
165  // Do the calculation by hand. Could make it faster than this even in a
166  // future iteration...
167  return std::sqrt( x() * x() + y() * y() );
168  }
169 
170  float TruthVertex_v1::eta() const {
171 
172  // This is not necessarily what Andy was thinking about...
173  return genvecV4().Eta();
174  }
175 
176  float TruthVertex_v1::phi() const {
177 
178  // This is not necessarily what Andy was thinking about...
179  return genvecV4().Phi();
180  }
181 
183 
185  return FourVec_t(x(), y(), z(), t());
186  }
187 
189  return GenVecFourVec_t(x(), y(), z(), t());
190  }
191 
192  //
194 
196 
197  return Type::TruthVertex;
198  }
199 
201 
202  // Prepare the incoming particle links for persistification:
203  if( incomingParticleLinksAcc.isAvailableWritable( *this ) ) {
204  TPLinks_t::iterator itr = incomingParticleLinksAcc( *this ).begin();
205  TPLinks_t::iterator end = incomingParticleLinksAcc( *this ).end();
206  for( ; itr != end; ++itr ) {
207  itr->toPersistent();
208  }
209  }
210 
211  // Prepare the outgoing particle links for persistification:
212  if( outgoingParticleLinksAcc.isAvailableWritable( *this ) ) {
213  TPLinks_t::iterator itr = outgoingParticleLinksAcc( *this ).begin();
214  TPLinks_t::iterator end = outgoingParticleLinksAcc( *this ).end();
215  for( ; itr != end; ++itr ) {
216  itr->toPersistent();
217  }
218  }
219 
220  return;
221  }
222 
223 } // namespace xAOD
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::TruthVertex_v1::clearOutgoingParticleLinks
void clearOutgoingParticleLinks()
Remove all outgoing particles.
Definition: TruthVertex_v1.cxx:143
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
xAOD::AUXSTORE_PRIMITIVE_SETTER_AND_GETTER
AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(BTagging_v1, float, IP2D_pb, setIP2D_pb) AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(BTagging_v1
xAOD::incomingParticleLinks
incomingParticleLinks
Definition: TruthVertex_v1.cxx:40
xAOD::TruthVertex_v1::GenVecFourVec_t
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > GenVecFourVec_t
Base 4 Momentum type for TruthVector.
Definition: TruthVertex_v1.h:145
xAOD::TruthVertex_v1::phi
float phi() const
Vertex azimuthal angle.
Definition: TruthVertex_v1.cxx:176
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
xAOD::TruthVertex_v1::FourVec_t
TLorentzVector FourVec_t
The 4-vector type.
Definition: TruthVertex_v1.h:139
xAOD::TruthVertex_v1::particles_in
std::vector< const TruthParticle * > particles_in() const
Get the incoming particles.
Definition: TruthVertex_v1.cxx:59
xAOD::float
float
Definition: BTagging_v1.cxx:168
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:44
AuxStoreAccessorMacros.h
xAOD::TruthVertex_v1::clearIncomingParticleLinks
void clearIncomingParticleLinks()
Remove all incoming particles.
Definition: TruthVertex_v1.cxx:93
index
Definition: index.py:1
TruthParticleContainer.h
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
TruthVertex_v1.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::TruthVertex_v1::addOutgoingParticleLink
void addOutgoingParticleLink(const TPLink_t &link)
Add one outgoing particle.
Definition: TruthVertex_v1.cxx:137
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
x
#define x
xAOD::TruthVertex_v1::y
float y() const
Vertex y displacement.
xAOD::TruthVertex_v1::t
float t() const
Vertex time.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
JetVar::Accessor
SG::AuxElement::Accessor< T > Accessor
Definition: JetVariable.h:31
SG::IAuxElement::index
size_t index() const
Return the index of this element within its container.
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:69
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition: TruthVertex.h:15
xAOD::TruthVertex_v1::toPersistent
void toPersistent()
Function making sure that the object is ready for persistification.
Definition: TruthVertex_v1.cxx:200
xAOD::TruthVertex_v1::TPLinks_t
std::vector< TPLink_t > TPLinks_t
Type used to save the links to incoming and outgoing particles.
Definition: TruthVertex_v1.h:74
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
xAOD::TruthVertex_v1::particles_out
std::vector< const TruthParticle * > particles_out() const
Get the outgoing particles.
Definition: TruthVertex_v1.cxx:64
xAOD::TruthVertex_v1::x
float x() const
Vertex x displacement.
y
#define y
xAOD::TruthVertex_v1::eta
float eta() const
Vertex pseudorapidity.
Definition: TruthVertex_v1.cxx:170
xAOD::TruthVertex_v1::nIncomingParticles
size_t nIncomingParticles() const
Get the number of incoming particles.
Definition: TruthVertex_v1.cxx:47
xAOD::TruthVertex_v1::type
Type::ObjectType type() const
The type of the object as a simple enumeration.
Definition: TruthVertex_v1.cxx:195
xAOD::TruthVertex_v1::TruthVertex_v1
TruthVertex_v1()
Default constructor.
Definition: TruthVertex_v1.cxx:17
xAOD::TruthVertex_v1::z
float z() const
Vertex longitudinal distance along the beam line form the origin.
xAOD::TruthVertex_v1::genvecV4
GenVecFourVec_t genvecV4() const
The full 4-vector of the particle : GenVector form.
Definition: TruthVertex_v1.cxx:188
xAODType::ObjectType
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition: ObjectType.h:32
xAOD::TruthVertex_v1::addIncomingParticleLink
void addIncomingParticleLink(const TPLink_t &link)
Add one incoming particle.
Definition: TruthVertex_v1.cxx:87
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:119
xAOD::AUXSTORE_OBJECT_SETTER_AND_GETTER
AUXSTORE_OBJECT_SETTER_AND_GETTER(CaloRings_v1, RingSetLinks, ringSetLinks, setRingSetLinks) unsigned CaloRings_v1
Definition: CaloRings_v1.cxx:27