ATLAS Offline Software
TruthVertex_v1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: TruthVertex_v1.cxx 624338 2014-10-27 15:08:55Z krasznaa $
6 
7 // System include(s):
8 #include <cmath>
9 
10 // xAOD include(s):
12 
13 // Local include(s):
16 
17 namespace xAOD {
18 
20  : SG::AuxElement() {
21 
22  }
23 
25  //
26  // Implementation for the "MC specific" functions
27  //
28 
31  setBarcode )
32 
33  //
35 
37  //
38  // Implementation for the links to the truth particles
39  //
40 
43  setIncomingParticleLinks )
44 
46  static const SG::AuxElement::Accessor< TruthVertex_v1::TPLinks_t >
47  incomingParticleLinksAcc( "incomingParticleLinks" );
48 
49  size_t TruthVertex_v1::nIncomingParticles() const {
50 
51  // Check if the variable is available:
52  if( ! incomingParticleLinksAcc.isAvailable( *this ) ) {
53  // If not, just tell the user that there aren't any incoming particles:
54  return 0;
55  }
56 
57  // Return the size of the vector:
58  return incomingParticleLinksAcc( *this ).size();
59  }
60 
61  std::vector<const TruthParticle*> TruthVertex_v1::particles_in() const {
62  std::vector<const TruthParticle*> res;
63  for (size_t i=0; i<nIncomingParticles();i++) res.push_back(incomingParticle(i));
64  return res;
65  }
66  std::vector<const TruthParticle*> TruthVertex_v1::particles_out() const {
67  std::vector<const TruthParticle*> res;
68  for (size_t i=0; i<nOutgoingParticles();i++) res.push_back(outgoingParticle(i));
69  return res;
70  }
72 
73  // Check that the variable exists, and that it has enough elements in it:
74  if( ( ! incomingParticleLinksAcc.isAvailable( *this ) ) ||
75  ( incomingParticleLinksAcc( *this ).size() <= index ) ) {
76  return nullptr;
77  }
78 
79  // Retrieve the link object and check its validity:
80  const TPLink_t& ipl = incomingParticleLinksAcc( *this )[ index ];
81  if( ! ipl.isValid() ) {
82  return nullptr;
83  }
84 
85  // Finally, de-reference the link:
86  return *ipl;
87  }
88 
90 
91  incomingParticleLinksAcc( *this ).push_back( link );
92  return;
93  }
94 
96 
97  incomingParticleLinksAcc( *this ).clear();
98  return;
99  }
100 
102  outgoingParticleLinks,
103  setOutgoingParticleLinks )
104 
105 
107  outgoingParticleLinksAcc( "outgoingParticleLinks" );
108 
109  size_t TruthVertex_v1::nOutgoingParticles() const {
110 
111  // Check if the variable is available:
112  if( ! outgoingParticleLinksAcc.isAvailable( *this ) ) {
113  // If not, just tell the user that there aren't any outgoing particles:
114  return 0;
115  }
116 
117  // Return the size of the vector:
118  return outgoingParticleLinksAcc( *this ).size();
119  }
120 
122 
123  // Check that the variable exists, and that it has enough elements in it:
124  if( ( ! outgoingParticleLinksAcc.isAvailable( *this ) ) ||
125  ( outgoingParticleLinksAcc( *this ).size() <= index ) ) {
126  return nullptr;
127  }
128 
129  // Retrieve the link object and check its validity:
130  const TPLink_t& opl = outgoingParticleLinksAcc( *this )[ index ];
131  if( ! opl.isValid() ) {
132  return nullptr;
133  }
134 
135  // Finally, de-reference the link:
136  return *opl;
137  }
138 
140 
141  outgoingParticleLinksAcc( *this ).push_back( link );
142  return;
143  }
144 
146 
147  outgoingParticleLinksAcc( *this ).clear();
148  return;
149  }
150 
151  //
153 
155  //
156  // Implementation of the functions specifying the vertex's position
157  //
158 
160 
162 
164 
166 
167  // Do the calculation by hand. Could make it faster than this even in a
168  // future iteration...
169  return std::sqrt( x() * x() + y() * y() );
170  }
171 
172  float TruthVertex_v1::eta() const {
173 
174  // This is not necessarily what Andy was thinking about...
175  return genvecV4().Eta();
176  }
177 
178  float TruthVertex_v1::phi() const {
179 
180  // This is not necessarily what Andy was thinking about...
181  return genvecV4().Phi();
182  }
183 
185 
187  return FourVec_t(x(), y(), z(), t());
188  }
189 
191  return GenVecFourVec_t(x(), y(), z(), t());
192  }
193 
194  //
196 
198 
199  return Type::TruthVertex;
200  }
201 
203 
204  // Prepare the incoming particle links for persistification:
205  if( incomingParticleLinksAcc.isAvailableWritable( *this ) ) {
206  TPLinks_t::iterator itr = incomingParticleLinksAcc( *this ).begin();
207  TPLinks_t::iterator end = incomingParticleLinksAcc( *this ).end();
208  for( ; itr != end; ++itr ) {
209  itr->toPersistent();
210  }
211  }
212 
213  // Prepare the outgoing particle links for persistification:
214  if( outgoingParticleLinksAcc.isAvailableWritable( *this ) ) {
215  TPLinks_t::iterator itr = outgoingParticleLinksAcc( *this ).begin();
216  TPLinks_t::iterator end = outgoingParticleLinksAcc( *this ).end();
217  for( ; itr != end; ++itr ) {
218  itr->toPersistent();
219  }
220  }
221 
222  return;
223  }
224 
225 } // 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:145
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:42
xAOD::TruthVertex_v1::GenVecFourVec_t
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > GenVecFourVec_t
Base 4 Momentum type for TruthVector.
Definition: TruthVertex_v1.h:149
TruthVertex
HepMC::GenVertex TruthVertex
Definition: Simulation/G4Sim/MCTruth/MCTruth/TruthEvent.h:12
xAOD::TruthVertex_v1::phi
float phi() const
Vertex azimuthal angle.
Definition: TruthVertex_v1.cxx:178
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:143
xAOD::TruthVertex_v1::particles_in
std::vector< const TruthParticle * > particles_in() const
Get the incoming particles.
Definition: TruthVertex_v1.cxx:61
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:66
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:35
AuxStoreAccessorMacros.h
xAOD::TruthVertex_v1::clearIncomingParticleLinks
void clearIncomingParticleLinks()
Remove all incoming particles.
Definition: TruthVertex_v1.cxx:95
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
atn_test_sgProducerConsumerDataPool_jobOptions.end
end
Definition: atn_test_sgProducerConsumerDataPool_jobOptions.py:25
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:139
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
x
#define x
xAOD::TruthVertex_v1::y
float y() const
Vertex y displacement.
xAOD::TruthVertex_v1::t
float t() const
Vertex time.
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:92
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:41
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:71
xAOD::TruthVertex_v1::toPersistent
void toPersistent()
Function making sure that the object is ready for persistification.
Definition: TruthVertex_v1.cxx:202
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:78
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:41
xAOD::TruthVertex_v1::particles_out
std::vector< const TruthParticle * > particles_out() const
Get the outgoing particles.
Definition: TruthVertex_v1.cxx:66
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:172
xAOD::TruthVertex_v1::nIncomingParticles
size_t nIncomingParticles() const
Get the number of incoming particles.
Definition: TruthVertex_v1.cxx:49
xAOD::TruthVertex_v1::type
Type::ObjectType type() const
The type of the object as a simple enumeration.
Definition: TruthVertex_v1.cxx:197
xAOD::TruthVertex_v1::TruthVertex_v1
TruthVertex_v1()
Default constructor.
Definition: TruthVertex_v1.cxx:19
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:190
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:89
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:121
xAOD::AUXSTORE_OBJECT_SETTER_AND_GETTER
AUXSTORE_OBJECT_SETTER_AND_GETTER(CaloRings_v1, RingSetLinks, ringSetLinks, setRingSetLinks) unsigned CaloRings_v1
Definition: CaloRings_v1.cxx:27