The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
Decay.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include <Gaudi/Decays/Decay.h>
13#include <Gaudi/ParticleID.h>
15#include <sstream>
16
17namespace Decays = Gaudi::Decays;
18
25 if ( m_pp ) {
26 m_name = m_pp->particle();
27 m_pid = m_pp->particleID();
28 }
29}
30
31Decays::Decay::Item::Item( const std::string& name ) : m_name( name ) {}
32
34
36 if ( m_pp ) {
37 m_name = m_pp->particle();
38 m_pid = m_pp->particleID();
40 }
41 // it not possible to validate it!
42 if ( 0 == svc ) { return StatusCode::FAILURE; }
43 // check by name
44 if ( !m_name.empty() ) {
45 m_pp = svc->find( m_name );
46 if ( !m_pp ) { return StatusCode::FAILURE; }
47 m_pid = m_pp->particleID();
49 }
50 // check by PID
51 if ( Gaudi::ParticleID() != m_pid ) {
52 m_pp = svc->find( m_pid );
53 if ( !m_pp ) { return StatusCode::FAILURE; }
54 m_name = m_pp->particle();
56 }
58}
59
61 if ( m_pp && !pp ) {
62 m_name = m_pp->particle();
63 m_pid = m_pp->particleID();
65 } else if ( pp ) {
66 m_pp = pp;
67 m_name = m_pp->particle();
68 m_pid = m_pp->particleID();
70 }
72}
73
75 const std::vector<const Gaudi::ParticleProperty*>& daughters )
76 : m_mother( mother ) {
78}
79
80Decays::Decay::Decay( const std::string& mother, const std::vector<std::string>& daughters ) : m_mother( mother ) {
82}
83
84Decays::Decay::Decay( const Gaudi::ParticleID& mother, const std::vector<Gaudi::ParticleID>& daughters )
85 : m_mother( mother ) {
87}
88
89Decays::Decay::Decay( const Decays::Decay::Item& mother, const std::vector<Decays::Decay::Item>& daughters )
91
93 // validate the mother
94 StatusCode sc = m_mother.validate( svc );
95 if ( sc.isFailure() ) { return sc; }
96 if ( m_daughters.empty() ) { return StatusCode::FAILURE; }
97 // loop over daughters
98 for ( auto idau = m_daughters.begin(); m_daughters.end() != idau; ++idau ) {
99 sc = idau->validate( svc );
100 if ( sc.isFailure() ) { return sc; }
101 }
102 return sc;
103}
104
105std::ostream& Decays::Decay::fillStream( std::ostream& s ) const {
106 m_mother.fillStream( s );
107 if ( m_daughters.empty() ) { return s; }
108 s << "->";
109 // loop over daughters
110 for ( const auto& dau : m_daughters ) { dau.fillStream( s ); }
111 return s;
112}
113
114std::ostream& Decays::Decay::Item::fillStream( std::ostream& s ) const {
115 if ( m_name.empty() ) {
116 if ( m_pp ) {
117 m_name = m_pp->particle();
118 } else if ( Gaudi::ParticleID() != m_pid ) {
119 return s << ' ' << m_pid.pid() << ' ';
120 } else {
121 return s << " ? ";
122 }
123 }
124 return s << ' ' << m_name << ' ';
125}
126
127std::string Decays::Decay::toString() const {
128 std::ostringstream s;
129 fillStream( s );
130 return s.str();
131}
132
133void Decays::Decay::setDaughters( const std::vector<const Gaudi::ParticleProperty*>& daugs ) {
134 m_daughters.clear();
135 for ( const auto& pp : daugs ) *this += pp;
136}
137
138void Decays::Decay::setDaughters( const std::vector<std::string>& daugs ) {
139 m_daughters.clear();
140 for ( const auto& pp : daugs ) *this += pp;
141}
142
143void Decays::Decay::setDaughters( const std::vector<Gaudi::ParticleID>& daugs ) {
144 m_daughters.clear();
145 for ( const auto& pp : daugs ) *this += pp;
146}
147
149
150Decays::Decay& Decays::Decay::operator+=( const std::string& child ) { return ( *this ) += Item( child ); }
151
152Decays::Decay& Decays::Decay::operator+=( const Gaudi::ParticleID& child ) { return ( *this ) += Item( child ); }
153
154Decays::Decay& Decays::Decay::operator+=( const Gaudi::ParticleProperty* child ) { return ( *this ) += Item( child ); }
155
157 m_daughters.push_back( child );
158 return *this;
159}
160
161/* get the component by the number
162 * @attention index 0 corresponds to the mother particle
163 * @param index the index (0 corresponds to the mother particle)
164 * @return the component
165 */
166const Decays::Decay::Item& Decays::Decay::operator()( const unsigned int index ) const {
167 if ( 0 == index ) { return m_mother; }
168 return m_daughters[index - 1];
169}
170
172
174
176
177void Decays::Decay::setMother( const std::string& mom ) { setMother( Item( mom ) ); }
the helper representation of the item in the decay chain
Definition Decay.h:39
std::string m_name
the particle name
Definition Decay.h:65
const Gaudi::ParticleProperty * pp() const
get the particle property
Definition Decay.h:53
const Gaudi::ParticleID & pid() const
get the particle PID
Definition Decay.h:51
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
validate the item using the service
Definition Decay.cpp:35
Gaudi::ParticleID m_pid
the particle PID
Definition Decay.h:67
Item(const Gaudi::ParticleProperty *pp=0)
the constructor from the particle property
Definition Decay.cpp:24
const Gaudi::ParticleProperty * m_pp
the source of properties
Definition Decay.h:69
std::ostream & fillStream(std::ostream &s) const
the default printout
Definition Decay.cpp:114
const std::string & name() const
get the particle name
Definition Decay.h:49
The simple representation of "simple 1-step" decay (there are no trees!
Definition Decay.h:32
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
validate the decay using the service
Definition Decay.cpp:92
Decay & operator+=(const std::string &child)
add the child
Definition Decay.cpp:150
std::string toString() const
the conversion to the string
Definition Decay.cpp:127
std::ostream & fillStream(std::ostream &s) const
the default printout
Definition Decay.cpp:105
Items m_daughters
the daughter particles
Definition Decay.h:171
const Item & operator()(const unsigned int index) const
get the component by the number
Definition Decay.cpp:166
void setDaughters(const Items &daugs)
set the daughters
Definition Decay.cpp:148
const Item & mother() const
get the mother(head) of the decay
Definition Decay.h:104
std::vector< Item > Items
the vector of items (the obvious representation of daughter particles)
Definition Decay.h:73
const Items & daughters() const
get all daughters
Definition Decay.h:106
Item m_mother
the head of the decay
Definition Decay.h:169
void setMother(const Item &mom)
set the mother
Definition Decay.cpp:171
The abstract interface to Particle Property Service.
virtual const ParticleProperty * find(const std::string &name) const =0
Retrieve an object by name:
Holds PDG + LHCb extension particle code, following the PDG particle numbering scheme (pdg....
Definition ParticleID.h:43
A trivial class to hold information about a single particle properties.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100