The Gaudi Framework  master (37c0b60a)
Symbols.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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/CC.h>
12 #include <Gaudi/Decays/NodesPIDs.h>
13 #include <Gaudi/Decays/Symbols.h>
15 #include <Gaudi/ParticleProperty.h>
16 #include <GaudiKernel/StatusCode.h>
17 #include <boost/algorithm/string.hpp>
18 #include <iostream>
19 #include <map>
20 
21 namespace Decays = Gaudi::Decays;
22 
31 namespace {
37  const std::string s_EMPTY = "";
38 } // namespace
40  static Decays::Symbols s_symbols;
41  return s_symbols;
42 }
43 // constructor
45  addSymbol( "X", Decays::Nodes::Any(), "Any particle" );
46  //
47  addSymbol( "Hadron", Decays::Nodes::Hadron(), "Any hadron" );
48  addSymbol( "Meson", Decays::Nodes::Meson(), "Any meson" );
49  addSymbol( "Baryon", Decays::Nodes::Baryon(), "Any baryon" );
50  addSymbol( "Nucleus", Decays::Nodes::Nucleus(), "Any nucleus" );
51  addSymbol( "Lepton", Decays::Nodes::Lepton(), "Any lepton" );
52  addSymbol( "l", Decays::Nodes::Ell(), "Any charged lepton" );
53  addSymbol( "l+", Decays::Nodes::EllPlus(), "Any positive lepton", "l-" );
54  addSymbol( "l-", Decays::Nodes::EllMinus(), "Any negative lepton", "l+" );
55  addSymbol( "Nu", Decays::Nodes::Nu(), "Any neutral lepton" );
56  addSymbol( "Neutrino", Decays::Nodes::Nu(), "Any neutral lepton" );
57  //
58  addSymbol( "X0", Decays::Nodes::Neutral(), "Any neutral particle" );
59  addSymbol( "Xq", Decays::Nodes::Charged(), "Any charged particle" );
60  addSymbol( "X+", Decays::Nodes::Positive(), "Any positive particle", "X-" );
61  addSymbol( "X-", Decays::Nodes::Negative(), "Any negative particle", "X+" );
62  //
63  addSymbol( "ID+", Decays::Nodes::PosID(), "Any particle with positive ID", "ID-" );
64  addSymbol( "ID-", Decays::Nodes::NegID(), "Any particle with negative ID", "ID+" );
65  //
66  addSymbol( "Xd", Decays::Nodes::HasQuark( Gaudi::ParticleID::down ), "Any particle with d-quark" );
67  addSymbol( "Xu", Decays::Nodes::HasQuark( Gaudi::ParticleID::up ), "Any particle with u-quark" );
68  addSymbol( "Xs", Decays::Nodes::HasQuark( Gaudi::ParticleID::strange ), "Any particle with s-quark" );
69  addSymbol( "Xc", Decays::Nodes::HasQuark( Gaudi::ParticleID::charm ), "Any particle with c-quark" );
70  addSymbol( "Xb", Decays::Nodes::HasQuark( Gaudi::ParticleID::bottom ), "Any particle with b-quark" );
71  addSymbol( "Xt", Decays::Nodes::HasQuark( Gaudi::ParticleID::top ), "Any particle with t-quark" );
72  //
73  addSymbol( "Down", Decays::Nodes::HasQuark( Gaudi::ParticleID::down ), "Any particle with d-quark" );
74  addSymbol( "Up", Decays::Nodes::HasQuark( Gaudi::ParticleID::up ), "Any particle with u-quark" );
75  addSymbol( "Strange", Decays::Nodes::HasQuark( Gaudi::ParticleID::strange ), "Any particle with s-quark" );
76  addSymbol( "Charm", Decays::Nodes::HasQuark( Gaudi::ParticleID::charm ), "Any particle with c-quark" );
77  addSymbol( "Bottom", Decays::Nodes::HasQuark( Gaudi::ParticleID::bottom ), "Any particle with b-quark" );
78  addSymbol( "Beauty", Decays::Nodes::HasQuark( Gaudi::ParticleID::bottom ), "Any particle with b-quark" );
79  addSymbol( "Top", Decays::Nodes::HasQuark( Gaudi::ParticleID::top ), "Any particle with t-quark" );
80  //
81  addSymbol( "Scalar", Decays::Nodes::JSpin( 1 ), "Any scalar particle j=0" );
82  addSymbol( "Spinor", Decays::Nodes::JSpin( 2 ), "Any spinor particle j=1/2" );
83  addSymbol( "OneHalf", Decays::Nodes::JSpin( 2 ), "Any spinor particle j=1/2" );
84  addSymbol( "Vector", Decays::Nodes::JSpin( 3 ), "Any vector particle j=1" );
85  addSymbol( "ThreeHalf", Decays::Nodes::JSpin( 4 ), "Any particle with spin j=3/2" );
86  addSymbol( "Tensor", Decays::Nodes::JSpin( 5 ), "Any tensor particle j=2" );
87  addSymbol( "FiveHalf", Decays::Nodes::JSpin( 6 ), "Any particle with spin j=5/2" );
88  //
89  addSymbol( "ShortLived", Decays::Nodes::ShortLived_(), "Any short-ilved particle" );
90  addSymbol( "LongLived", Decays::Nodes::LongLived_(), "Any long-lived particle" );
91  addSymbol( "Stable", Decays::Nodes::Stable(), "Any 'stable' particle" );
92  addSymbol( "StableCharged", Decays::Nodes::StableCharged(), "Any 'trackable' particle: stable & charged" );
93  // special CC-symbols, protect them...
94  addCC( "cc" );
95  addCC( "CC" );
96  addCC( "os" );
97  addCC( "nos" );
98  addCC( "HasQuark" );
99  addCC( "JSpin" );
100  addCC( "LSpin" );
101  addCC( "SSpin" );
102  addCC( "ShortLived" );
103  addCC( "LongLived" );
104  addCC( "ShortLived_" );
105  addCC( "LongLived_" );
106  addCC( "Stable" );
107  addCC( "Light" );
108  addCC( "Heavy" );
109  addCC( "CTau" );
110  addCC( "Mass" );
111  addCC( "up" );
112  addCC( "down" );
113  addCC( "strange" );
114  addCC( "charm" );
115  addCC( "beauty" );
116  addCC( "bottom" );
117  addCC( "top" );
118 }
119 
120 // get CC-map
121 const Decays::Symbols::CCMap& Decays::Symbols::cc() const { return m_cc; }
122 /* add new symbol to the internal structure
123  * @param symbol the symbol definition
124  * @param node the actual node
125  * @param help the help string
126  * @param ccsym the symbol for charge coonjugation
127  * @return true if the symbol is added into the storage
128  */
130  const std::string& ccsym ) {
131  // trim the arguments
132  boost::trim( sym );
133  auto ifind = m_nodes.find( sym );
134  if ( m_nodes.end() != ifind ) { return false; }
135  // add the node into the map
136  bool inserted = m_nodes.insert( sym, node ).second;
137  if ( !inserted ) { return false; }
138  // add the help-string
139  m_help[sym] = help;
140  // add cc-symbols
141  addCC( sym, ccsym );
142  return true;
143 }
144 /* add cc-pair to the internal map
145  * @param sym the symbol
146  * @param ccsym the symbol for charge conjugation
147  */
149  // trim the arguments
150  boost::trim( sym );
151  boost::trim( ccsym );
152  if ( ccsym.empty() ) { ccsym = sym; }
153  m_cc[sym] = ccsym;
154  if ( ccsym != sym ) { m_cc[ccsym] = sym; }
155 }
156 // valid symbol?
158  // trim the argument
159  boost::trim( sym );
160  return m_nodes.end() != m_nodes.find( sym );
161 }
162 // help for the symbol
164  // trim the argument
165  boost::trim( sym );
166  NodeMap::const_iterator ifind = m_nodes.find( sym );
167  if ( m_nodes.end() == ifind ) { return s_EMPTY; }
168  HelpMap::const_iterator ihelp = m_help.find( sym );
169  if ( m_help.end() == ihelp ) { return s_EMPTY; }
170  return ihelp->second;
171 }
172 /* get the node by symbol
173  * @param (INPUT) sym the symbol name
174  * @param (OUTPUT) the symbol
175  * @return status code
176  */
178  // trim the argument
179  boost::trim( sym );
180  auto ifind = m_nodes.find( sym );
181  if ( m_nodes.end() != ifind ) {
182  node = ifind->second;
183  return StatusCode::SUCCESS;
184  }
185  node = Decays::Nodes::Invalid();
186  return StatusCode( InvalidSymbol );
187 }
188 // get all known symbols
190  // clear names ;
191  names.clear();
192  for ( auto inode = m_nodes.begin(); m_nodes.end() != inode; ++inode ) { names.push_back( inode->first ); }
193  // sort it according to CC-criteria ATTENTION!
194  std::stable_sort( names.begin(), names.end(), Decays::CC::CmpCC() );
195  return names.size();
196 }
197 /* get all known particle names
198  * @param service (INPUT) particle property service
199  * @param parts (OUTPUT) vector of particle names
200  * @return status code
201  */
203  Decays::Symbols::Names& parts ) const {
204  // clear the output
205  parts.clear();
206  // check the service
207  if ( 0 == service ) { return StatusCode( InvalidService ); }
208 
209  auto begin = service->begin();
210  auto end = service->end();
211  for ( ; end != begin; ++begin ) {
212  const Gaudi::ParticleProperty* pp = *begin;
213  if ( !pp ) { continue; }
214  parts.push_back( pp->particle() );
215  }
216  // sort it according to CC-criteria ATTENTION!
217  std::stable_sort( parts.begin(), parts.end(), Decays::CC::CmpCC() );
218 
219  return StatusCode::SUCCESS;
220 }
Gaudi::Decays::Nodes::Any
Definition: NodesPIDs.h:34
Gaudi::Interfaces::IParticlePropertySvc::end
virtual iterator end() const =0
get the end-iterator for the container of particle properties It is assumed that the container is pro...
Gaudi::Decays::Node
Definition: iNode.h:74
std::string
STL class.
Gaudi::Decays::Symbols::Symbols
Symbols()
the default constructor is protected:
Definition: Symbols.cpp:44
Gaudi::Decays::Nodes::EllMinus
Definition: NodesPIDs.h:184
std::vector< std::string >
std::vector::size
T size(T... args)
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::ParticleID::bottom
@ bottom
Definition: ParticleID.h:48
Gaudi::Decays::Symbols::instance
static Symbols & instance()
static accessor to teh singleton
Definition: Symbols.cpp:39
Symbols.h
IParticlePropertySvc.h
Gaudi::ParticleID::up
@ up
Definition: ParticleID.h:48
Gaudi::Decays::Nodes::Meson
Definition: NodesPIDs.h:216
Gaudi::Decays::Nodes::JSpin
Definition: NodesPIDs.h:342
help
void help(const std::string &argv0)
Definition: listcomponents.cpp:28
StatusCode.h
Gaudi::Decays::Nodes::EllPlus
Definition: NodesPIDs.h:168
EventStatus::Invalid
@ Invalid
Definition: IAlgExecStateSvc.h:72
Gaudi::Decays::Nodes::Baryon
Definition: NodesPIDs.h:231
std::vector::clear
T clear(T... args)
GaudiUtils::VectorMap< std::string, Decays::Nodes::_Node >::const_iterator
_vector::const_iterator const_iterator
visible const_iterator (exported)
Definition: VectorMap.h:152
std::vector::push_back
T push_back(T... args)
Gaudi::Decays::Nodes::Stable
Definition: NodesPIDs.h:523
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
Gaudi::Decays::Symbols::symbols
size_t symbols(Names &names) const
get all known basic primitive special symbols
Definition: Symbols.cpp:189
StatusCode
Definition: StatusCode.h:65
Gaudi::Decays::Nodes::HasQuark
Definition: NodesPIDs.h:321
Gaudi::Decays::Nodes::Nu
Definition: NodesPIDs.h:134
NodesPIDs.h
Gaudi::ParticleID::down
@ down
Definition: ParticleID.h:48
Gaudi::Decays::Nodes::StableCharged
Definition: NodesPIDs.h:538
Gaudi::ParticleID::strange
@ strange
Definition: ParticleID.h:48
Gaudi::Decays::Symbols
Definition: Symbols.h:45
Gaudi::Decays::Symbols::valid
bool valid(std::string sym) const
valid basic/primitive symbol?
Definition: Symbols.cpp:157
std::map< std::string, std::string >
Gaudi::ParticleProperty
Definition: ParticleProperty.h:37
Gaudi::Decays::Nodes::Hadron
Definition: NodesPIDs.h:201
Gaudi::Decays::Nodes::Negative
Definition: NodesPIDs.h:276
Gaudi::Decays::Symbols::cc
const CCMap & cc() const
get CC-map
Definition: Symbols.cpp:121
Gaudi::Decays::Nodes::Lepton
Definition: NodesPIDs.h:119
GaudiPartProp.decorators.Decays
Decays
Definition: decorators.py:33
Gaudi::Decays::Nodes::Neutral
Definition: NodesPIDs.h:291
Gaudi::Decays
Definition: CC.h:17
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::vector::begin
T begin(T... args)
Gaudi::ParticleID::charm
@ charm
Definition: ParticleID.h:48
Gaudi::Decays::Nodes::Nucleus
Definition: NodesPIDs.h:306
CC.h
Gaudi::Decays::Nodes::NegID
Definition: NodesPIDs.h:630
Gaudi::Decays::CC::CmpCC
Definition: CC.h:24
Gaudi::Decays::Nodes::Positive
Definition: NodesPIDs.h:261
std::string::empty
T empty(T... args)
Gaudi::Decays::iNode
Definition: iNode.h:35
Gaudi::Decays::Symbols::addCC
void addCC(std::string sym, std::string ccsym="")
add cc-pair to the internal map
Definition: Symbols.cpp:148
Gaudi::Decays::Nodes::LongLived_
Definition: NodesPIDs.h:507
std::vector::end
T end(T... args)
Gaudi::Decays::Nodes::Charged
Definition: NodesPIDs.h:246
IOTest.end
end
Definition: IOTest.py:125
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
Gaudi::Decays::Nodes::Ell
Definition: NodesPIDs.h:151
std::stable_sort
T stable_sort(T... args)
Gaudi::Decays::Symbols::symbol
const std::string & symbol(std::string sym) const
help for the basic primitive special symbol
Definition: Symbols.cpp:163
Gaudi::ParticleID::top
@ top
Definition: ParticleID.h:48
Gaudi::Interfaces::IParticlePropertySvc::begin
virtual iterator begin() const =0
get the begin-iterator for the container of particle properties It is assumed that the container is p...
ParticleProperty.h
Gaudi::Decays::Symbols::addSymbol
bool addSymbol(std::string sym, const Decays::iNode &node, const std::string &help, const std::string &ccsym="")
add new symbol to the internal structure
Definition: Symbols.cpp:129
Gaudi::Decays::Symbols::particles
StatusCode particles(const Gaudi::Interfaces::IParticlePropertySvc *svc, Names &parts) const
get all known particle names
Definition: Symbols.cpp:202
Gaudi::Decays::Nodes::PosID
Definition: NodesPIDs.h:608
Gaudi::Decays::Nodes::ShortLived_
Definition: NodesPIDs.h:490