Line data Source code
1 : //-----------------------------------------------------------------------
2 : // File and Version Information:
3 : // $Id: EvtDecayMode.cpp,v 1.3 2009-03-16 15:53:27 robbep Exp $
4 : //
5 : // Environment:
6 : // This software is part of the EvtGen package developed jointly
7 : // for the BaBar and CLEO collaborations. If you use all or part
8 : // of it, please give an appropriate acknowledgement.
9 : //
10 : // Copyright Information:
11 : // Copyright (C) 1998 Caltech, UCSB
12 : //
13 : // Module creator:
14 : // Alexei Dvoretskii, Caltech, 2001-2002.
15 : //-----------------------------------------------------------------------
16 : #include "EvtGenBase/EvtPatches.hh"
17 :
18 : // Parses a decay string to identify the name
19 : // of the mother and of the daughters. The string should
20 : // be in standard format e.g. "B+ -> pi+ pi+ pi-"
21 :
22 : #include "EvtGenBase/EvtPatches.hh"
23 : #include <assert.h>
24 : #include <iostream>
25 : #include "EvtGenBase/EvtDecayMode.hh"
26 : #include "EvtGenBase/EvtReport.hh"
27 : using std::endl;
28 : using std::ostream;
29 :
30 : using std::string;
31 : using std::vector;
32 :
33 :
34 : EvtDecayMode::EvtDecayMode(std::string mother,vector<string> dau)
35 0 : : _mother(mother),
36 0 : _dau(dau)
37 0 : {
38 0 : }
39 :
40 :
41 : EvtDecayMode::EvtDecayMode(const EvtDecayMode& other)
42 0 : : _mother(other._mother),
43 0 : _dau(other._dau)
44 0 : {
45 0 : }
46 :
47 :
48 0 : EvtDecayMode::EvtDecayMode(const char* decay)
49 0 : {
50 : // Parse the decay string, it should be in a standard
51 : // format, e.g. "B+ -> pi+ pi+ pi-" with all spaces
52 :
53 0 : string s(decay);
54 :
55 : // mother
56 :
57 0 : string::size_type i = s.find_first_not_of(" ");
58 0 : string::size_type j = s.find_first_of(" ",i);
59 :
60 0 : if(i == string::npos) {
61 :
62 0 : report(Severity::Info,"EvtGen") << "No non-space character found" << endl;
63 0 : assert(0);
64 : }
65 :
66 0 : if(j == string::npos) {
67 :
68 0 : report(Severity::Info,"EvtGen") << "No space before -> found" << endl;
69 0 : assert(0);
70 : }
71 :
72 0 : _mother = string(s,i,j-i);
73 :
74 0 : i = s.find_first_not_of(" ",j);
75 0 : j = s.find_first_of("->",j);
76 0 : if(i != j) {
77 :
78 0 : report(Severity::Info,"EvtGen") << "Multiple mothers?" << i << "," << j << endl;
79 0 : assert(0);
80 : }
81 0 : j += 2;
82 :
83 0 : while(1) {
84 :
85 0 : i = s.find_first_not_of(" ",j);
86 0 : j = s.find_first_of(" ",i);
87 :
88 0 : if(i == string::npos) break;
89 0 : if(j == string::npos) {
90 0 : _dau.push_back(string(s,i,s.size()-i+1));
91 0 : break;
92 : } else {
93 0 : _dau.push_back(string(s,i,j-i));
94 : }
95 : }
96 0 : }
97 :
98 :
99 :
100 : EvtDecayMode::~EvtDecayMode()
101 0 : {}
102 :
103 :
104 : const char* EvtDecayMode::mother() const
105 : {
106 0 : return _mother.c_str();
107 : }
108 :
109 :
110 : int EvtDecayMode::nD() const
111 : {
112 0 : return _dau.size();
113 : }
114 :
115 :
116 : const char* EvtDecayMode::dau(int i) const
117 : {
118 0 : assert(0<=i && i< (int) _dau.size());
119 0 : return _dau[i].c_str();
120 : }
121 :
122 : std::string EvtDecayMode::mode() const
123 : {
124 0 : string ret = _mother + string(" -> ");
125 :
126 0 : for(size_t i=0;i<_dau.size()-1;i++) {
127 0 : ret += string(_dau[i]) + string(" ");
128 : }
129 0 : ret += _dau[_dau.size()-1];
130 : return ret;
131 0 : }
132 :
133 :
134 : ostream& EvtDecayMode::print(ostream& os) const
135 : {
136 0 : os << _mother.c_str() << " ->";
137 0 : for(size_t i=0;i<_dau.size();i++) {
138 0 : os << " " << _dau[i].c_str();
139 : }
140 0 : return os;
141 : }
142 :
143 :
144 : std::string EvtDecayMode::m(EvtCyclic3::Pair i) const
145 : {
146 0 : string s("m(");
147 0 : s.append(dau(EvtCyclic3::first(i)));
148 0 : s.append(",");
149 0 : s.append(dau(EvtCyclic3::second(i)));
150 0 : s.append(")");
151 : return s;
152 0 : }
153 :
154 :
155 : std::string EvtDecayMode::q(EvtCyclic3::Pair i) const
156 : {
157 0 : string s("q(");
158 0 : s.append(dau(EvtCyclic3::first(i)));
159 0 : s.append(",");
160 0 : s.append(dau(EvtCyclic3::second(i)));
161 0 : s.append(")");
162 : return s;
163 0 : }
164 :
165 :
166 : std::string EvtDecayMode::dal(EvtCyclic3::Pair i, EvtCyclic3::Pair j) const
167 : {
168 0 : string s(q(i));
169 0 : s.append(":");
170 0 : s.append(q(j));
171 : return s;
172 0 : }
173 :
174 :
175 : ostream& operator<<(ostream& os, const EvtDecayMode& mode)
176 : {
177 0 : mode.print(os);
178 0 : return os;
179 : }
|