The Gaudi Framework  master (fb0007c6)
Loading...
Searching...
No Matches
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>
17#include <boost/algorithm/string.hpp>
18#include <iostream>
19#include <map>
20
21namespace Decays = Gaudi::Decays;
22
31namespace {
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
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 */
129bool Decays::Symbols::addSymbol( std::string sym, const Decays::iNode& node, const std::string& help,
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 */
148void Decays::Symbols::addCC( std::string sym, std::string ccsym ) {
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?
157bool Decays::Symbols::valid( std::string sym ) const {
158 // trim the argument
159 boost::trim( sym );
160 return m_nodes.end() != m_nodes.find( sym );
161}
162// help for the symbol
163const std::string& Decays::Symbols::symbol( std::string sym ) const {
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 */
177StatusCode Decays::Symbols::symbol( std::string sym, Decays::Node& node ) const {
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}
The generic class to hold the pointer to other node.
Definition iNode.h:74
the most simple node in the decay tree: it matches to all valid the Gaudi::Particles
Definition NodesPIDs.h:34
The trivial node : it match the Baryon.
Definition NodesPIDs.h:231
The trivial node : it match the Charged.
Definition NodesPIDs.h:246
The trivial node : it match any charged lepton.
Definition NodesPIDs.h:151
The trivial node : it match any negative lepton.
Definition NodesPIDs.h:184
The trivial node : it match any positive lepton.
Definition NodesPIDs.h:168
The trivial node : it match the Hadron.
Definition NodesPIDs.h:201
The trivial node : it match the quark content.
Definition NodesPIDs.h:321
the most simple node to represent the invalid node it matches to all valid the Gaudi::Particles
Definition Nodes.h:74
The trivial node : it match the 2J+1 spin.
Definition NodesPIDs.h:342
The trivial node : it match the Lepton.
Definition NodesPIDs.h:119
The trivial node : it match the meson.
Definition NodesPIDs.h:216
The trivial node : it match the negatively charged particles.
Definition NodesPIDs.h:276
The trivial node : it match the Neutral.
Definition NodesPIDs.h:291
The trivial node : it match any neutral lepton.
Definition NodesPIDs.h:134
The trivial node : it match the Nucleus.
Definition NodesPIDs.h:306
The trivial node : it match the positively charged particles.
Definition NodesPIDs.h:261
represent simple predicate for short-lived particles
Definition NodesPIDs.h:490
represent simple predicate for Stable+Charged particles
Definition NodesPIDs.h:538
represent simple predicate for Stable particles
Definition NodesPIDs.h:523
Helper class to obtain the information about the valid symbols for particles, decay descriptors and N...
Definition Symbols.h:45
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
const CCMap & cc() const
get CC-map
Definition Symbols.cpp:121
CCMap m_cc
the map of cc-symbols
Definition Symbols.h:124
static Symbols & instance()
static accessor to teh singleton
Definition Symbols.cpp:39
void addCC(std::string sym, std::string ccsym="")
add cc-pair to the internal map
Definition Symbols.cpp:148
std::vector< std::string > Names
the actual type for the list of names
Definition Symbols.h:50
std::map< std::string, std::string > CCMap
Definition Symbols.h:51
const std::string & symbol(std::string sym) const
help for the basic primitive special symbol
Definition Symbols.cpp:163
StatusCode particles(const Gaudi::Interfaces::IParticlePropertySvc *svc, Names &parts) const
get all known particle names
Definition Symbols.cpp:202
bool valid(std::string sym) const
valid basic/primitive symbol?
Definition Symbols.cpp:157
size_t symbols(Names &names) const
get all known basic primitive special symbols
Definition Symbols.cpp:189
HelpMap m_help
the actual help-map
Definition Symbols.h:122
Symbols()
the default constructor is protected:
Definition Symbols.cpp:44
NodeMap m_nodes
the actual map of symbols
Definition Symbols.h:120
The abstract class which represents the single "node" of decay tree.
Definition iNode.h:35
The abstract interface to Particle Property Service.
virtual iterator begin() const =0
get the begin-iterator for the container of particle properties It is assumed that the container is p...
virtual iterator end() const =0
get the end-iterator for the container of particle properties It is assumed that the container is pro...
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
constexpr static const auto SUCCESS
Definition StatusCode.h:99
void help(const std::string &argv0)
a bit specific comparison of strings, useful for ordering according to the length as the primary para...
Definition CC.h:24
represent simple predicate for Long-lived particles
Definition NodesPIDs.h:507