ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleUtils
src
DecayParser.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// DecayParser.cxx
7
// Implementation file for class DecayParser
8
// Author: S.Binet<binet@cern.ch>
10
11
// STL includes
12
#include <algorithm>
13
#include <cctype>
14
#include <iostream>
15
#include <ranges>
16
#include <stdexcept>
17
#include <sstream>
18
#include <string_view>
19
20
// McParticleUtils includes
21
#include "
McParticleUtils/DecayParser.h
"
22
23
namespace
{
24
25
std::vector<McUtils::Strings> process_block(std::string_view cmd)
26
{
27
std::vector<McUtils::Strings>
result
;
28
if
(
cmd
.empty()) {
29
return
result
;
30
}
31
32
std::vector<std::string> slots;
33
for
(
auto
const
& token : cmd | std::views::split(
'+'
)) {
34
slots.emplace_back(token.begin(), token.end());
35
}
36
37
result
.reserve(slots.size());
38
for
(
auto
const
& slot : slots) {
39
McUtils::Strings
candidates
;
40
for
(
auto
const
& token : slot | std::views::split(
'|'
)) {
41
candidates
.emplace_back(token.begin(), token.end());
42
}
43
std::ranges::sort(candidates);
44
auto
[
first
, last] = std::ranges::unique(candidates);
45
candidates
.erase(first, last);
46
result
.emplace_back(std::move(candidates));
47
}
48
49
return
result
;
50
}
51
52
}
// anonymous namespace
53
57
60
61
DecayParser::DecayParser
(
const
std::string& cmd ) :
62
m_parents
( ),
63
m_children
( )
64
{
65
parse
(cmd);
66
}
67
68
71
DecayParser::~DecayParser
()
72
{
73
}
74
78
void
DecayParser::dump
()
const
79
{
80
std::cout <<
"--- Parents ---"
<< std::endl;
81
printMcUtilsStrings
(
m_parents
);
82
83
std::cout <<
"--- Children ---"
<< std::endl;
84
printMcUtilsStrings
(
m_children
);
85
}
86
87
int
DecayParser::pdgId
(
const
std::string& pdgIdString )
const
88
{
89
int
pdgID = 0;
90
int
iPDG = 0;
91
std::stringstream( pdgIdString ) >> iPDG;
92
pdgID = iPDG;
93
94
return
pdgID;
95
}
96
99
void
DecayParser::parse
(
const
std::string& inputCmd )
100
{
101
if
( inputCmd.empty() ) {
102
return
;
103
}
104
105
std::string cmd;
106
cmd.reserve(inputCmd.size());
107
for
(
unsigned
char
c : inputCmd) {
108
if
(!std::isspace(c)) {
109
cmd.push_back(c);
110
}
111
}
112
if
(cmd.empty()) {
113
return
;
114
}
115
116
// Reset the parents and children lists
117
m_parents
.clear();
118
m_children
.clear();
119
120
if
(cmd ==
"->"
) {
121
return
;
122
}
123
124
const
std::size_t arrowPos = cmd.find(
"->"
);
125
if
(arrowPos == std::string::npos) {
126
std::string
error
=
"missing '->' in command ["
+ inputCmd +
"]"
;
127
throw
std::runtime_error(
error
);
128
}
129
130
if
(cmd.find(
"->"
, arrowPos + 2) != std::string::npos) {
131
std::string
error
=
"multiple '->' separators in command ["
+ inputCmd +
"]"
;
132
throw
std::runtime_error(
error
);
133
}
134
135
const
std::string_view cmdView{cmd};
136
const
auto
parentsBlock = cmdView.substr(0, arrowPos);
137
const
auto
childrenBlock = cmdView.substr(arrowPos + 2);
138
139
m_parents
= process_block(parentsBlock);
140
m_children
= process_block(childrenBlock);
141
}
142
143
144
void
145
DecayParser::printMcUtilsStrings
(
const
std::vector<McUtils::Strings>& list )
const
146
{
147
unsigned
int
iSlot = 0;
148
for
( std::vector<McUtils::Strings>::const_iterator itr = list.begin();
149
itr != list.end();
150
++itr,++iSlot ) {
151
std::stringstream iSlotStr;
152
iSlotStr << iSlot;
153
const
McUtils::Strings::const_iterator candEnd = itr->end();
154
std::cout <<
"slot #"
<< iSlotStr.str() <<
": candidates= [ "
;
155
for
( McUtils::Strings::const_iterator candidate = itr->begin();
156
candidate != candEnd;
157
++candidate ) {
158
std::cout << *candidate;
159
if
( candidate+1 != candEnd ) {
160
std::cout <<
" | "
;
161
}
162
}
163
std::cout <<
" ]"
<< std::endl;
164
}
165
return
;
166
}
167
168
170
// Operators:
172
DecayParser
&
DecayParser::operator=
(
const
DecayParser
& rhs )
173
{
174
if
(
this
!= &rhs ) {
175
m_parents
= rhs.
m_parents
;
176
m_children
= rhs.
m_children
;
177
}
178
return
*
this
;
179
}
DecayParser.h
DecayParser::DecayParser
DecayParser()
Default constructor:
DecayParser::printMcUtilsStrings
void printMcUtilsStrings(const std::vector< McUtils::Strings > &list) const
Print the content of a vector of McUtils::Strings to std::cout.
Definition
DecayParser.cxx:145
DecayParser::dump
void dump() const
Const methods:
Definition
DecayParser.cxx:78
DecayParser::~DecayParser
virtual ~DecayParser()
Destructor:
Definition
DecayParser.cxx:71
DecayParser::DecayParser
DecayParser(const std::string &cmd)
Constructor with parameters:
Definition
DecayParser.cxx:61
DecayParser::m_parents
std::vector< McUtils::Strings > m_parents
List of parents : each slot of the vector is a list of candidates So one could have something like : ...
Definition
DecayParser.h:90
DecayParser::parse
void parse(const std::string &cmd)
Non-const methods:
Definition
DecayParser.cxx:99
DecayParser::pdgId
int pdgId(const std::string &pdgIdString) const
Definition
DecayParser.cxx:87
DecayParser::operator=
DecayParser & operator=(const DecayParser &obj)
Assignment operator:
Definition
DecayParser.cxx:172
DecayParser::m_children
std::vector< McUtils::Strings > m_children
List of children : each slot of the vector is a list of candidates So one could have something like :...
Definition
DecayParser.h:96
DeMoScan.first
bool first
Definition
DeMoScan.py:534
McUtils::Strings
std::vector< std::string > Strings
Definition
DecayParser.h:26
drawFromPickle.candidates
candidates
Definition
drawFromPickle.py:271
error
Definition
IImpactPoint3dEstimator.h:72
get_generator_info.result
result
Definition
get_generator_info.py:21
rerun_display.cmd
str cmd
Definition
rerun_display.py:67
Generated on
for ATLAS Offline Software by
1.17.0