evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtDecayMode.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
22 
23 #include "EvtGenBase/EvtPatches.hh"
24 #include "EvtGenBase/EvtReport.hh"
25 
26 #include <assert.h>
27 #include <iostream>
28 using std::endl;
29 using std::ostream;
30 
31 using std::string;
32 using std::vector;
33 
34 EvtDecayMode::EvtDecayMode( std::string mother, vector<string> dau ) :
35  _mother( mother ), _dau( dau )
36 {
37 }
38 
40  _mother( other._mother ), _dau( other._dau )
41 {
42 }
43 
44 EvtDecayMode::EvtDecayMode( const char* decay )
45 {
46  // Parse the decay string, it should be in a standard
47  // format, e.g. "B+ -> pi+ pi+ pi-" with all spaces
48 
49  string s( decay );
50 
51  // mother
52 
53  string::size_type i = s.find_first_not_of( " " );
54  string::size_type j = s.find_first_of( " ", i );
55 
56  if ( i == string::npos ) {
57  EvtGenReport( EVTGEN_INFO, "EvtGen" )
58  << "No non-space character found" << endl;
59  assert( 0 );
60  }
61 
62  if ( j == string::npos ) {
63  EvtGenReport( EVTGEN_INFO, "EvtGen" )
64  << "No space before -> found" << endl;
65  assert( 0 );
66  }
67 
68  _mother = string( s, i, j - i );
69 
70  i = s.find_first_not_of( " ", j );
71  j = s.find_first_of( "->", j );
72  if ( i != j ) {
73  EvtGenReport( EVTGEN_INFO, "EvtGen" )
74  << "Multiple mothers?" << i << "," << j << endl;
75  assert( 0 );
76  }
77  j += 2;
78 
79  while ( 1 ) {
80  i = s.find_first_not_of( " ", j );
81  j = s.find_first_of( " ", i );
82 
83  if ( i == string::npos )
84  break;
85  if ( j == string::npos ) {
86  _dau.push_back( string( s, i, s.size() - i + 1 ) );
87  break;
88  } else {
89  _dau.push_back( string( s, i, j - i ) );
90  }
91  }
92 }
93 
94 const char* EvtDecayMode::mother() const
95 {
96  return _mother.c_str();
97 }
98 
99 int EvtDecayMode::nD() const
100 {
101  return _dau.size();
102 }
103 
104 const char* EvtDecayMode::dau( int i ) const
105 {
106  assert( 0 <= i && i < (int)_dau.size() );
107  return _dau[i].c_str();
108 }
109 
110 std::string EvtDecayMode::mode() const
111 {
112  string ret = _mother + string( " -> " );
113 
114  for ( size_t i = 0; i < _dau.size() - 1; i++ ) {
115  ret += string( _dau[i] ) + string( " " );
116  }
117  ret += _dau[_dau.size() - 1];
118  return ret;
119 }
120 
121 ostream& EvtDecayMode::print( ostream& os ) const
122 {
123  os << _mother.c_str() << " ->";
124  for ( size_t i = 0; i < _dau.size(); i++ ) {
125  os << " " << _dau[i].c_str();
126  }
127  return os;
128 }
129 
130 std::string EvtDecayMode::m( EvtCyclic3::Pair i ) const
131 {
132  string s( "m(" );
133  s.append( dau( EvtCyclic3::first( i ) ) );
134  s.append( "," );
135  s.append( dau( EvtCyclic3::second( i ) ) );
136  s.append( ")" );
137  return s;
138 }
139 
140 std::string EvtDecayMode::q( EvtCyclic3::Pair i ) const
141 {
142  string s( "q(" );
143  s.append( dau( EvtCyclic3::first( i ) ) );
144  s.append( "," );
145  s.append( dau( EvtCyclic3::second( i ) ) );
146  s.append( ")" );
147  return s;
148 }
149 
151 {
152  string s( q( i ) );
153  s.append( ":" );
154  s.append( q( j ) );
155  return s;
156 }
157 
158 ostream& operator<<( ostream& os, const EvtDecayMode& mode )
159 {
160  mode.print( os );
161  return os;
162 }
std::string _mother
Definition: EvtDecayMode.hh:50
ostream & operator<<(ostream &os, const EvtDecayMode &mode)
EvtDecayMode(const char *decay)
std::vector< std::string > _dau
Definition: EvtDecayMode.hh:51
std::string q(EvtCyclic3::Pair i) const
int nD() const
std::ostream & print(std::ostream &) const
const char * dau(int i) const
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
std::string dal(EvtCyclic3::Pair i, EvtCyclic3::Pair j) const
std::string m(EvtCyclic3::Pair i) const
const char * mother() const
std::string mode() const
Index second(Pair i)
Definition: EvtCyclic3.cpp:264
Index first(Pair i)
Definition: EvtCyclic3.cpp:250
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156