]>
Commit | Line | Data |
---|---|---|
da0e9ce3 | 1 | //----------------------------------------------------------------------- |
2 | // File and Version Information: | |
0ca57c2f | 3 | // $Id: EvtDecayMode.cpp,v 1.3 2009-03-16 15:53:27 robbep Exp $ |
da0e9ce3 | 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 | ||
0ca57c2f | 33 | |
da0e9ce3 | 34 | EvtDecayMode::EvtDecayMode(std::string mother,vector<string> dau) |
35 | : _mother(mother), | |
36 | _dau(dau) | |
37 | { | |
38 | } | |
39 | ||
40 | ||
41 | EvtDecayMode::EvtDecayMode(const EvtDecayMode& other) | |
42 | : _mother(other._mother), | |
43 | _dau(other._dau) | |
44 | { | |
45 | } | |
46 | ||
47 | ||
48 | EvtDecayMode::EvtDecayMode(const char* decay) | |
49 | { | |
50 | // Parse the decay string, it should be in a standard | |
51 | // format, e.g. "B+ -> pi+ pi+ pi-" with all spaces | |
52 | ||
53 | string s(decay); | |
54 | ||
55 | // mother | |
56 | ||
57 | string::size_type i = s.find_first_not_of(" "); | |
58 | string::size_type j = s.find_first_of(" ",i); | |
59 | ||
60 | if(i == string::npos) { | |
61 | ||
62 | report(INFO,"EvtGen") << "No non-space character found" << endl; | |
63 | assert(0); | |
64 | } | |
65 | ||
66 | if(j == string::npos) { | |
67 | ||
68 | report(INFO,"EvtGen") << "No space before -> found" << endl; | |
69 | assert(0); | |
70 | } | |
71 | ||
72 | _mother = string(s,i,j-i); | |
73 | ||
74 | i = s.find_first_not_of(" ",j); | |
75 | j = s.find_first_of("->",j); | |
76 | if(i != j) { | |
77 | ||
78 | report(INFO,"EvtGen") << "Multiple mothers?" << i << "," << j << endl; | |
79 | assert(0); | |
80 | } | |
81 | j += 2; | |
82 | ||
83 | while(1) { | |
84 | ||
85 | i = s.find_first_not_of(" ",j); | |
86 | j = s.find_first_of(" ",i); | |
87 | ||
88 | if(i == string::npos) break; | |
89 | if(j == string::npos) { | |
90 | _dau.push_back(string(s,i,s.size()-i+1)); | |
91 | break; | |
92 | } else { | |
93 | _dau.push_back(string(s,i,j-i)); | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | ||
99 | ||
100 | EvtDecayMode::~EvtDecayMode() | |
101 | {} | |
102 | ||
103 | ||
104 | const char* EvtDecayMode::mother() const | |
105 | { | |
106 | return _mother.c_str(); | |
107 | } | |
108 | ||
109 | ||
110 | int EvtDecayMode::nD() const | |
111 | { | |
112 | return _dau.size(); | |
113 | } | |
114 | ||
115 | ||
116 | const char* EvtDecayMode::dau(int i) const | |
117 | { | |
118 | assert(0<=i && i< (int) _dau.size()); | |
119 | return _dau[i].c_str(); | |
120 | } | |
121 | ||
122 | std::string EvtDecayMode::mode() const | |
123 | { | |
124 | string ret = _mother + string(" -> "); | |
125 | ||
126 | for(size_t i=0;i<_dau.size()-1;i++) { | |
127 | ret += string(_dau[i]) + string(" "); | |
128 | } | |
129 | ret += _dau[_dau.size()-1]; | |
130 | return ret; | |
131 | } | |
132 | ||
133 | ||
134 | ostream& EvtDecayMode::print(ostream& os) const | |
135 | { | |
136 | os << _mother.c_str() << " ->"; | |
137 | for(size_t i=0;i<_dau.size();i++) { | |
138 | os << " " << _dau[i].c_str(); | |
139 | } | |
140 | return os; | |
141 | } | |
142 | ||
143 | ||
144 | std::string EvtDecayMode::m(EvtCyclic3::Pair i) const | |
145 | { | |
146 | string s("m("); | |
147 | s.append(dau(EvtCyclic3::first(i))); | |
148 | s.append(","); | |
149 | s.append(dau(EvtCyclic3::second(i))); | |
150 | s.append(")"); | |
151 | return s; | |
152 | } | |
153 | ||
154 | ||
155 | std::string EvtDecayMode::q(EvtCyclic3::Pair i) const | |
156 | { | |
157 | string s("q("); | |
158 | s.append(dau(EvtCyclic3::first(i))); | |
159 | s.append(","); | |
160 | s.append(dau(EvtCyclic3::second(i))); | |
161 | s.append(")"); | |
162 | return s; | |
163 | } | |
164 | ||
165 | ||
166 | std::string EvtDecayMode::dal(EvtCyclic3::Pair i, EvtCyclic3::Pair j) const | |
167 | { | |
168 | string s(q(i)); | |
169 | s.append(":"); | |
170 | s.append(q(j)); | |
171 | return s; | |
172 | } | |
173 | ||
174 | ||
175 | ostream& operator<<(ostream& os, const EvtDecayMode& mode) | |
176 | { | |
177 | mode.print(os); | |
178 | return os; | |
179 | } |