The Gaudi Framework  master (37c0b60a)
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>
14 #include <Gaudi/ParticleProperty.h>
15 #include <sstream>
16 
17 namespace Decays = Gaudi::Decays;
18 
25  if ( m_pp ) {
26  m_name = m_pp->particle();
27  m_pid = m_pp->particleID();
28  }
29 }
30 
32 
33 Decays::Decay::Item::Item( const Gaudi::ParticleID& pid ) : m_pid( pid ) {}
34 
36  if ( m_pp ) {
37  m_name = m_pp->particle();
38  m_pid = m_pp->particleID();
39  return StatusCode::SUCCESS;
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();
48  return StatusCode::SUCCESS;
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();
55  return StatusCode::SUCCESS;
56  }
57  return StatusCode::FAILURE;
58 }
59 
61  if ( m_pp && !pp ) {
62  m_name = m_pp->particle();
63  m_pid = m_pp->particleID();
64  return StatusCode::SUCCESS;
65  } else if ( pp ) {
66  m_pp = pp;
67  m_name = m_pp->particle();
68  m_pid = m_pp->particleID();
69  return StatusCode::SUCCESS;
70  }
71  return StatusCode::FAILURE;
72 }
73 
76  : m_mother( mother ) {
78 }
79 
80 Decays::Decay::Decay( const std::string& mother, const std::vector<std::string>& daughters ) : m_mother( mother ) {
82 }
83 
85  : m_mother( mother ) {
87 }
88 
90  : m_mother( mother ), m_daughters( 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 
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 
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 
129  fillStream( s );
130  return s.str();
131 }
132 
134  m_daughters.clear();
135  for ( const auto& pp : daugs ) *this += pp;
136 }
137 
139  m_daughters.clear();
140  for ( const auto& pp : daugs ) *this += pp;
141 }
142 
144  m_daughters.clear();
145  for ( const auto& pp : daugs ) *this += pp;
146 }
147 
148 void Decays::Decay::setDaughters( const Decays::Decay::Items& daugs ) { m_daughters = daugs; }
149 
150 Decays::Decay& Decays::Decay::operator+=( const std::string& child ) { return ( *this ) += Item( child ); }
151 
152 Decays::Decay& Decays::Decay::operator+=( const Gaudi::ParticleID& child ) { return ( *this ) += Item( child ); }
153 
154 Decays::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  */
166 const 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 
171 void Decays::Decay::setMother( const Decays::Decay::Item& mom ) { m_mother = mom; }
172 
173 void Decays::Decay::setMother( const Gaudi::ParticleProperty* mom ) { setMother( Item( mom ) ); }
174 
175 void Decays::Decay::setMother( const Gaudi::ParticleID& mom ) { setMother( Item( mom ) ); }
176 
177 void Decays::Decay::setMother( const std::string& mom ) { setMother( Item( mom ) ); }
std::string
STL class.
Gaudi::Decays::Decay::Item::m_name
std::string m_name
the particle name
Definition: Decay.h:65
Gaudi::Decays::Decay::setDaughters
void setDaughters(const Items &daugs)
set the daughters
Definition: Decay.cpp:148
Gaudi::Decays::Decay::setMother
void setMother(const Item &mom)
set the mother
Definition: Decay.cpp:171
Gaudi::Decays::Decay
Definition: Decay.h:32
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector
STL class.
Gaudi::ParticleProperty::particle
const std::string & particle() const
Get the particle name.
Definition: ParticleProperty.h:78
Gaudi::Decays::Decay::Item::m_pid
Gaudi::ParticleID m_pid
the particle PID
Definition: Decay.h:67
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::Decays::Decay::daughters
const Items & daughters() const
get all daughters
Definition: Decay.h:106
ParticleID.h
IParticlePropertySvc.h
Gaudi::Decays::Decay::toString
std::string toString() const
the conversion to the string
Definition: Decay.cpp:127
Gaudi::Decays::Decay::Item::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
validate the item using the service
Definition: Decay.cpp:35
Gaudi::Decays::Decay::fillStream
std::ostream & fillStream(std::ostream &s) const
the default printout
Definition: Decay.cpp:105
Gaudi::Decays::Decay::operator+=
Decay & operator+=(const std::string &child)
add the child
Definition: Decay.cpp:150
StatusCode
Definition: StatusCode.h:65
Gaudi::Decays::Decay::Item::fillStream
std::ostream & fillStream(std::ostream &s) const
the default printout
Definition: Decay.cpp:114
Gaudi::Decays::Decay::Item::m_pp
const Gaudi::ParticleProperty * m_pp
the source of properties
Definition: Decay.h:69
std::ostream
STL class.
Gaudi::ParticleProperty
Definition: ParticleProperty.h:37
GaudiPartProp.decorators.Decays
Decays
Definition: decorators.py:33
std::ostringstream
STL class.
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Decays
Definition: CC.h:17
Gaudi::ParticleProperty::particleID
const Gaudi::ParticleID & particleID() const
get the particle ID
Definition: ParticleProperty.h:82
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Decay.h
Gaudi::Interfaces::IParticlePropertySvc::find
virtual const ParticleProperty * find(const std::string &name) const =0
Retrieve an object by name:
Gaudi::ParticleID
Definition: ParticleID.h:43
GaudiPartProp.decorators.Item
Item
Definition: decorators.py:306
Gaudi::Decays::Decay::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
validate the decay using the service
Definition: Decay.cpp:92
Gaudi::Decays::Decay::operator()
const Item & operator()(const unsigned int index) const
get the component by the number
Definition: Decay.cpp:166
Gaudi::Decays::Decay::Item
Definition: Decay.h:39
Gaudi::Decays::Decay::m_mother
Item m_mother
the head of the decay
Definition: Decay.h:169
Gaudi::Decays::Decay::mother
const Item & mother() const
get the mother(head) of the decay
Definition: Decay.h:104
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Decays::Decay::Decay
Decay()=default
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
ParticleProperty.h
Gaudi::Decays::Decay::Item::Item
Item(const Gaudi::ParticleProperty *pp=0)
the constructor from the particle property
Definition: Decay.cpp:24
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39