23#include "Math/Vector4D.h"
45 return std::hypot(
px(),
py() );
61 return p4().Rapidity();
65 if (
accPx.isAvailable(*
this) &&
accPy.isAvailable(*
this)
66 &&
accPz.isAvailable(*
this) &&
accE.isAvailable(*
this) ) {
68 const double px =
static_cast<double>(
accPx(*
this));
69 const double py =
static_cast<double>(
accPy(*
this));
70 const double pz =
static_cast<double>(
accPz(*
this));
71 const double e =
static_cast<double>(
accE(*
this));
77 const std::vector<int> partIndices;
78 return p4( partIndices );
84 if (
accPx.isAvailable(*
this) &&
accPy.isAvailable(*
this)
85 &&
accPz.isAvailable(*
this) &&
accE.isAvailable(*
this) ) {
87 const double px =
static_cast<double>(
accPx(*
this));
88 const double py =
static_cast<double>(
accPy(*
this));
89 const double pz =
static_cast<double>(
accPz(*
this));
90 const double e =
static_cast<double>(
accE(*
this));
96 const std::vector<int> partIndices;
98 return GenVecFourMom_t(fourmom.Px(), fourmom.Py(), fourmom.Pz(), fourmom.E());
103 return Type::CompositeParticle;
133 accPx( *
this ) =
static_cast<float>(
vec.Px());
134 accPy( *
this ) =
static_cast<float>(
vec.Py());
135 accPz( *
this ) =
static_cast<float>(
vec.Pz());
136 accE( *
this ) =
static_cast<float>(
vec.E());
192 for ( std::size_t i=0; i<
nParts; ++i ) {
195 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle!");
218 return pdgAcc.isAvailable( *
this );
241 fourMom.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
243 if ( partIndices.empty() ) {
246 for ( std::size_t i=0; i<
nParts; ++i ) {
249 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle!");
256 double px = met->
mpx();
257 double py = met->
mpy();
262 for (
int i : partIndices ) {
265 double px = met->
mpx();
266 double py = met->
mpy();
270 throw std::runtime_error(
"Got a negative index which is not -1");
273 const xAOD::IParticle*
part = this->
part(i);
275 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle");
277 fourMom +=
part->p4();
286 return (this->
p4(partIndices)).Pt();
290 return (this->
p4(partIndices)).Eta();
294 return (this->
p4(partIndices)).Phi();
298 return (this->
p4(partIndices)).M();
302 return (this->
p4(partIndices)).P();
306 return (this->
p4(partIndices)).E();
310 return (this->
p4(partIndices)).Rapidity();
314 return (this->
p4(partIndices)).Px();
318 return (this->
p4(partIndices)).Py();
322 return (this->
p4(partIndices)).Pz();
326 return (this->
p4(partIndices)).Et();
349 throw std::runtime_error(
"Got a zero pointer to an xAOD::MissingET when calling mt");
351 const double mpx( metObj->
mpx() );
352 const double mpy( metObj->
mpy() );
353 const double met( metObj->
met() );
356 const double px( fourMom.Px() );
357 const double py( fourMom.Py() );
358 const double part2 = (
px+mpx)*(
px+mpx) + (
py+mpy)*(
py+mpy);
360 double mll2( fourMom.M2() );
362 mll2 = mll2 < 0.0 ? -mll2 : mll2;
363 const double etll( std::sqrt( (
px*
px +
py*
py) + mll2 ) );
364 const double part1( (etll+met)*(etll+met) );
367 if ( part1 < part2 ) {
369 throw std::runtime_error(
"Got an invalid mt calculation");
371 return std::sqrt( part1 - part2 );
392 const std::vector<int>& partIndices )
const {
396 for (
const std::string& varName : varNames ) {
398 if (
varName.empty() ) {
continue; }
399 const xAOD::IParticle::ConstAccessor<float> varAcc(varName);
401 if ( partIndices.empty() ) {
406 for (
int i : partIndices ) {
409 if ( met && varAcc.isAvailable(*met) ) {
weight *= varAcc(*met); }
413 throw std::runtime_error(
"Got a negative index which is not -1");
416 const xAOD::IParticle*
part = this->
part(i);
429 const xAOD::IParticle::ConstAccessor<float>& varAcc )
const {
431 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle!");
434 return varAcc(*
part);
443 const xAOD::CompositeParticle_v1*
compPart =
static_cast<const xAOD::CompositeParticle_v1*
>(
part);
446 for ( std::size_t i=0;
i<
nParts; ++
i ) {
447 const xAOD::IParticle* part2 =
compPart->part(i);
467 partLinksAcc(
"partLinks" );
476 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle when adding constituent!");
482 if ( updateFourMom ) {
489 const std::size_t partIdx =
part->index();
492 constitLinks.push_back(
IParticleLink( *partCont, partIdx ) );
503 throw std::runtime_error(
"Got an invalid ElementLink when adding constituent!");
508 if ( updateFourMom ) {
509 this->
setP4( this->
p4() + (*partLink)->p4() );
522 bool updateFourMom ) {
523 for ( xAOD::IParticleLinkContainer::const_iterator
524 constitItr = partLinkCont.begin(),
525 constitItrEnd = partLinkCont.end();
526 constitItr != constitItrEnd;
529 this->
addPart( currentLink, updateFourMom );
537 bool updateFourMom ) {
541 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle when adding constituent!");
545 const std::size_t partIdx =
part->index();
556 bool updateFourMom ) {
560 throw std::runtime_error(
"Got an invalid ElementLink when adding constituent!");
565 for ( xAOD::IParticleLinkContainer::iterator
566 constitItr = constitLinks.begin(),
567 constitItrEnd = constitLinks.end();
568 constitItr != constitItrEnd;
573 if ( updateFourMom ) {
574 this->
setP4( this->
p4() - (*partLink)->p4() );
580 constitLinks.erase( constitItr );
609 bool updateFourMom ) {
613 throw std::runtime_error(
"Got a zero pointer to xAOD::MissingET when adding it!");
617 if ( updateFourMom ) {
619 double metpx =
met->mpx();
620 double metpy =
met->mpy();
621 metP4.SetPxPyPzE( metpx, metpy, 0.0, std::sqrt(metpx*metpx + metpy*metpy) );
622 this->
setP4( this->
p4() + metP4 );
626 const std::size_t metIdx =
met->index();
644 if ( updateFourMom ) {
646 double metpx =
met->mpx();
647 double metpy =
met->mpy();
648 metP4.SetPxPyPzE( metpx, metpy, 0.0, std::sqrt(metpx*metpx + metpy*metpy) );
649 this->
setP4( this->
p4() - metP4 );
671 if ( thisMet ==
met ) {
676 if ( (*thisMet) == (*
met) ) {
689 for ( xAOD::IParticleLinkContainer::const_iterator
690 constitItr = constitLinks.begin(),
691 constitItrEnd = constitLinks.end();
692 constitItr != constitItrEnd;
695 if ( ! currentLink.
isValid() )
continue;
697 if (
part == currentPart ) {
708 for ( xAOD::IParticleLinkContainer::const_iterator
709 constitItr = constitLinks.begin(),
710 constitItrEnd = constitLinks.end();
711 constitItr != constitItrEnd;
723 if( partLinksAcc.isAvailable( *
this ) ) {
724 return partLinksAcc( *this ).size();
732#define NUM_PARTS( FUNCNAME, OBJTYPE ) \
733 std::size_t CompositeParticle_v1::FUNCNAME() const { \
735 std::size_t nParts = this->nParts(); \
736 for ( std::size_t i=0; i<nParts; ++i ) { \
737 const xAOD::IParticle* part = this->part(i); \
738 if (!part) { throw std::runtime_error("Got a zero pointer to an xAOD::IParticle!"); } \
739 if ( part->type() == xAOD::Type::OBJTYPE ) { n += 1; } \
757#define NUM_TRUTHPARTS( FUNCNAME, PIDMETHOD ) \
758 std::size_t CompositeParticle_v1::FUNCNAME() const { \
760 std::size_t nParts = this->nParts(); \
761 for ( std::size_t i=0; i<nParts; ++i ) { \
762 const xAOD::IParticle* part = this->part(i); \
763 if (!part) { throw std::runtime_error("Got a zero pointer to an xAOD::IParticle!"); } \
764 if ( part->type() != xAOD::Type::TruthParticle ) { continue; } \
765 const xAOD::TruthParticle* truthParticle = dynamic_cast<const xAOD::TruthParticle*>(part); \
766 if (!truthParticle) { throw std::runtime_error("Zero pointer to xAOD::TruthParticle"); } \
767 if ( PIDMETHOD(truthParticle->pdgId()) ) { n += 1; } \
787 if ( ! constitLink.
isValid() ) {
811 template<
typename CONTTYPE>
817 for ( std::size_t i=0; i<
nParts; ++i ) {
821 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle!");
834 xAOD::CompositeParticle_v1*
836 const std::vector<int>& otherPartIndices,
837 bool updateFourMom )
const {
840 for (
int i : partIndices ) {
846 compPart->addPart( pLink, updateFourMom );
849 throw std::runtime_error(
"Got a non-valid index");
852 for (
int i : otherPartIndices ) {
855 compPart->addPart( pLink, updateFourMom );
858 throw std::runtime_error(
"Got a non-valid index for an other particle");
877 otherPartLinksAcc(
"otherPartLinks" );
886 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle when adding constituent!");
891 const std::size_t partIdx =
part->index();
905 throw std::runtime_error(
"Got an invalid ElementLink when adding constituent!");
917 for ( xAOD::IParticleLinkContainer::const_iterator
918 constitItr = partLinkCont.begin(),
919 constitItrEnd = partLinkCont.end();
920 constitItr != constitItrEnd;
934 throw std::runtime_error(
"Got a zero pointer to an xAOD::IParticle when adding constituent!");
938 const std::size_t partIdx =
part->index();
952 throw std::runtime_error(
"Got an invalid ElementLink when adding constituent!");
957 for ( xAOD::IParticleLinkContainer::iterator
960 constitItr != constitItrEnd;
977 for ( xAOD::IParticleLinkContainer::const_iterator
980 constitItr != constitItrEnd;
983 if ( ! currentLink.
isValid() )
continue;
985 if (
part == currentPart ) {
996 for ( xAOD::IParticleLinkContainer::const_iterator
999 constitItr != constitItrEnd;
1011 if( otherPartLinksAcc.isAvailable( *
this ) ) {
1012 return otherPartLinksAcc( *this ).size();
1020#define NUM_OTHERPARTS( FUNCNAME, OBJTYPE ) \
1021 std::size_t CompositeParticle_v1::FUNCNAME() const { \
1023 std::size_t nParts = this->nOtherParts(); \
1024 for ( std::size_t i=0; i<nParts; ++i ) { \
1025 const xAOD::IParticle* part = this->otherPart(i); \
1026 if (!part) { throw std::runtime_error("Got a zero pointer to an xAOD::IParticle!"); } \
1027 if ( part->type() == xAOD::Type::OBJTYPE ) { n += 1; } \
1045#define NUM_OTHERTRUTHPARTS( FUNCNAME, PIDMETHOD ) \
1046 std::size_t CompositeParticle_v1::FUNCNAME() const { \
1048 std::size_t nParts = this->nOtherParts(); \
1049 for ( std::size_t i=0; i<nParts; ++i ) { \
1050 const xAOD::IParticle* part = this->otherPart(i); \
1051 if (!part) { throw std::runtime_error("Got a zero pointer to an xAOD::IParticle!"); } \
1052 if ( part->type() != xAOD::Type::TruthParticle ) { continue; } \
1053 const xAOD::TruthParticle* truthParticle = dynamic_cast<const xAOD::TruthParticle*>(part); \
1054 if (!truthParticle) { throw std::runtime_error("Zero pointer to xAOD::TruthParticle"); } \
1055 if ( PIDMETHOD(truthParticle->pdgId()) ) { n += 1; } \
1103 if( partLinksAcc.isAvailableWritable( *
this ) ) {
1104 for ( xAOD::IParticleLinkContainer::iterator
1105 itr = partLinksAcc( *this ).begin(),
1106 itrEnd = partLinksAcc( *this ).end();
1109 itr->toPersistent();
#define AUXSTORE_PRIMITIVE_SETTER_WITH_CAST(CL, PERSTYPE, TRANSTYPE, NAME, SETTER)
Macro creating a setter function with a type conversion.
#define AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of primitive auxiliary properties.
#define AUXSTORE_OBJECT_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of complex auxiliary properties.
std::vector< size_t > vec
#define NUM_PARTS(FUNCNAME, OBJTYPE)
#define NUM_TRUTHPARTS(FUNCNAME, PIDMETHOD)
#define NUM_OTHERTRUTHPARTS(FUNCNAME, PIDMETHOD)
#define NUM_OTHERPARTS(FUNCNAME, OBJTYPE)
ATLAS-specific HepMC functions.
class which is made from the composition of other particles.
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DV::const_value_type const * const_pointer
ElementLink implementation for ROOT usage.
bool isValid() const
Test to see if the link can be dereferenced.
SG::Accessor< T, ALLOC > Accessor
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Description of a composite particle, i.e.
bool containsOther(const xAOD::IParticle *part) const
Check if a given xAOD::IParticle is an other constituent.
bool hasPdgId() const
Check if this composite particle has its charge set.
std::size_t nOtherLeptons() const
Number of other constituent leptons (electrons, muons, and taus).
virtual double phi() const
The azimuthal angle ( ) of the particle.
double pz() const
Get the pz momentum component of the particle.
const xAOD::IParticle * part(std::size_t index=0) const
Get the constituent IParticle number i.
std::size_t nOtherMuons() const
Number of other constituent muons.
std::size_t nOtherTruthTaus() const
Number of other constituent truth taus.
std::size_t nElectrons() const
Number of constituent electrons.
const xAOD::IParticleLinkContainer & partLinks() const
Get all constituents in one go.
std::size_t nOtherTruthMuons() const
Number of other constituent truth muons.
const xAOD::IParticleLink & partLink(std::size_t index=0) const
Get the constituent IParticle number i as an ElementLink.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
std::size_t nOtherElectrons() const
Number of other constituent electrons.
bool hasCharge() const
Check if this composite particle has its charge set.
double py() const
Get the py momentum component of the particle.
void removeOtherPart(const xAOD::IParticle *part)
Remove a particle as an other constituent from this CompostiteParticle.
double p(const std::vector< int > &partIndices) const
The total 3-momentum.
void setPxPyPzE(double px, double py, double pz, double e)
Set the 4-vec.
CompositeParticle_v1()
Default constructor.
std::size_t nMuons() const
Number of constituent muons.
void addOtherPart(const xAOD::IParticle *part)
Add a particle as an additional other constituent.
std::size_t nOtherTaus() const
Number of other constituent taus.
double et() const
The transverse energy ( ) of the particle.
IParticle::FourMom_t FourMom_t
Definition of the 4-momentum type.
virtual Type::ObjectType type() const
The type of the object as a simple enumeration.
double px() const
Get the px momentum component of the particle.
const xAOD::IParticle * otherPart(std::size_t index=0) const
Get the other constituent IParticle number i.
float weight(const std::vector< std::string > &varNames, const std::vector< int > &partIndices={}) const
Get the weight for this xAOD::CompositeParticle by providing a vector of variable names that will be ...
virtual double e() const
The total energy of the particle.
void setCharge(float charge)
Set the electric charge.
const xAOD::MissingET * missingET() const
Get the MissingET object that is associated with this CompositeParticle.
void addPart(const xAOD::IParticle *part, bool updateFourMom=true)
Add a particle as an additional constituent.
std::size_t nTruthElectrons() const
Number of constituent truth electrons.
double mt(const std::vector< int > &partIndices, MT::Method method=MT::DEFAULT) const
Get the transverse mass.
std::size_t nParts() const
Number of constituent particles.
std::size_t nTruthLeptons() const
Number of constituent truth leptons (truth electrons, truth muons, and truth taus).
std::size_t nLeptons() const
Number of constituent leptons (electrons, muons, and taus).
void addOtherParts(const xAOD::IParticleLinkContainer &partLinkCont)
Add many other constituents at the same time.
float charge() const
Return the electric charge.
void toPersistent()
Function preparing the object to be persistified.
std::size_t nOtherParts() const
Number of other constituent particles.
std::size_t nOtherTruthElectrons() const
Number of other constituent truth electrons.
bool contains(const xAOD::MissingET *met) const
Check if a given xAOD::MissingET object is part of this CompositeParticle.
void removeMissingET(bool updateFourMom=true)
Remove the existing MissingET object from this CompositeParticle.
void setP4(const FourMom_t &vec)
Set the 4-vec.
const xAOD::IParticleLinkContainer & otherPartLinks() const
Get all other constituents in one go.
xAOD::CompositeParticle_v1 * compPart(const std::vector< int > &partIndices, const std::vector< int > &otherPartIndices=std::vector< int >{}, bool updateFourMom=true) const
Get a CompositeParticle that is build on the fly from the constituent particles associated to the ind...
std::size_t nOtherTruthLeptons() const
Number of other constituent truth leptons (truth electrons, truth muons, and truth taus).
std::size_t nTruthTaus() const
Number of constituent truth taus.
ConstDataVector< CONTTYPE > * parts() const
Method to return a DataVector<T>, e.g., a MuonContainer, for all the constituent particles,...
float weightHelper(const xAOD::IParticle *part, const xAOD::IParticle::ConstAccessor< float > &varAcc) const
This is a private helper method to calculate the weight.
const xAOD::IParticleLink & otherPartLink(std::size_t index=0) const
Get the other constituent IParticle number i as an ElementLink.
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > GenVecFourMom_t
Base 4 Momentum type (GenVector)
void removePart(const xAOD::IParticle *part, bool updateFourMom=true)
Remove a particle as a constituent from this CompostiteParticle.
virtual double eta() const
The pseudorapidity ( ) of the particle.
GenVecFourMom_t genvecP4() const
The full 4-momentum of the particle : GenVector form Note: can be slower than just p4 for this class;...
virtual double rapidity() const
The true rapidity (y) of the particle.
std::size_t nTruthMuons() const
Number of constituent truth muons.
void setMissingET(const xAOD::MissingET *met, bool updateFourMom=true)
Set the MissingET for this CompositeParticle.
virtual double m() const
The invariant mass of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
void addParts(const xAOD::IParticleLinkContainer &partLinkCont, bool updateFourMom=true)
Add many constituents at the same time Note that the 4-momentum of this CompositeParticle will be upd...
std::size_t nTaus() const
Number of constituent taus.
Class describing an electron.
Class providing the definition of the 4-vector interface.
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
TLorentzVector FourMom_t
Definition of the 4-momentum type.
SG::Accessor< T, ALLOC > Accessor
float met() const
Returns .
float mpx() const
Returns .
float mpy() const
Returns .
Class describing an photon.
bool isPhoton(const T &p)
bool isElectron(const T &p)
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
str varName
end cluster ToT and charge
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
@ CompositeParticle
Particle composed of other particles.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Jet_v1 Jet
Definition of the current "jet version".
static const SG::AuxElement::Accessor< float > accPx("px")
AUXSTORE_PRIMITIVE_SETTER_WITH_CAST(CompositeParticle_v1, float, double, px, setPx) AUXSTORE_PRIMITIVE_SETTER_WITH_CAST(CompositeParticle_v1
static const SG::AuxElement::Accessor< float > accPy("py")
MissingET_v1 MissingET
Version control by type defintion.
static const SG::AuxElement::Accessor< int > pdgAcc("pdgId")
static const SG::AuxElement::Accessor< float > accPz("pz")
IParticleLinkContainer_v1 IParticleLinkContainer
Define the latest version of the IParticleLinkContainer class.
static const SG::AuxElement::Accessor< float > accE("e")
IParticleLink_v1 IParticleLink
Define the latest version of the IParticleLink class.
MissingETContainer_v1 MissingETContainer
static const SG::AuxElement::Accessor< float > chargeAcc("charge")
TruthParticle_v1 TruthParticle
Typedef to implementation.
static const SG::AuxElement::Accessor< ElementLink< xAOD::MissingETContainer > > metLinkAcc("missingETLink")
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.