EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
EvtCyclic3.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 <assert.h>
24#include <iostream>
25#include <string.h>
26using std::ostream;
27
28using namespace EvtCyclic3;
29
31{
32 if ( p == ABC )
33 return i;
34 else if ( p == BCA ) {
35 if ( i == A )
36 return C;
37 else if ( i == B )
38 return A;
39 else if ( i == C )
40 return B;
41 } else if ( p == BCA ) {
42 if ( i == A )
43 return C;
44 else if ( i == B )
45 return A;
46 else if ( i == C )
47 return B;
48 } else if ( p == CAB ) {
49 if ( i == A )
50 return B;
51 else if ( i == B )
52 return C;
53 else if ( i == C )
54 return A;
55 } else if ( p == CBA ) {
56 if ( i == A )
57 return C;
58 else if ( i == B )
59 return B;
60 else if ( i == C )
61 return A;
62 } else if ( p == BAC ) {
63 if ( i == A )
64 return B;
65 else if ( i == B )
66 return A;
67 else if ( i == C )
68 return C;
69 } else if ( p == ACB ) {
70 if ( i == A )
71 return A;
72 else if ( i == B )
73 return C;
74 else if ( i == C )
75 return B;
76 }
77 assert( 0 );
78 return A;
79}
80
81Perm EvtCyclic3::permutation( Index i1, Index i2, [[maybe_unused]] Index i3 )
82{
83 assert( i1 != i2 && i2 != i3 && i3 != i1 );
84
85 if ( i1 == A )
86 return ( i2 == B ) ? ABC : ACB;
87 if ( i1 == B )
88 return ( i2 == C ) ? BCA : BAC;
89 if ( i1 == C )
90 return ( i2 == A ) ? CAB : CBA;
91
92 assert( 0 );
93 return ABC;
94}
95
97{
98 Index i1 = permute( permute( A, i ), p );
99 Index i2 = permute( permute( B, i ), p );
100 Index i3 = permute( permute( C, i ), p );
101
102 return permutation( i1, i2, i3 );
103}
104
106{
107 Index i1 = permute( first( i ), p );
108 Index i2 = permute( second( i ), p );
109 return combine( i1, i2 );
110}
111
113{
114 assert( 0 <= i && i <= 2 );
115 switch ( i ) {
116 case 0:
117 return BC;
118 case 1:
119 return CA;
120 case 2:
121 return AB;
122 }
123 assert( 0 );
124 return AB; // should never get here
125}
126
128{
129 switch ( i ) {
130 case A:
131 return C;
132 case B:
133 return A;
134 case C:
135 return B;
136 }
137 assert( 0 );
138 return A; // should never get here
139}
140
142{
143 switch ( i ) {
144 case A:
145 return B;
146 case B:
147 return C;
148 case C:
149 return A;
150 }
151 assert( 0 );
152 return A; // should never get here
153}
154
156{
157 assert( i != j );
158 switch ( i ) {
159 case A:
160 switch ( j ) {
161 case B:
162 return C;
163 case C:
164 return B;
165 default:
166 assert( 0 );
167 }
168 case B:
169 switch ( j ) {
170 case C:
171 return A;
172 case A:
173 return C;
174 default:
175 assert( 0 );
176 }
177 case C:
178 switch ( j ) {
179 case A:
180 return B;
181 case B:
182 return A;
183 default:
184 assert( 0 );
185 }
186 }
187 assert( 0 );
188 return A; // should never get here
189}
190
191// Index-to-pair conversions
192
194{
195 switch ( i ) {
196 case A:
197 return BC;
198 case B:
199 return CA;
200 case C:
201 return AB;
202 }
203 assert( 0 );
204 return AB; // should never get here
205}
206
208{
209 return other( other( i, j ) );
210}
211
212// Pair-to-pair conversions
213
215{
216 switch ( i ) {
217 case BC:
218 return AB;
219 case CA:
220 return BC;
221 case AB:
222 return CA;
223 }
224 assert( 0 );
225 return AB; // should never get here
226}
227
229{
230 switch ( i ) {
231 case BC:
232 return CA;
233 case CA:
234 return AB;
235 case AB:
236 return BC;
237 }
238 assert( 0 );
239 return AB; // should never get here
240}
241
243{
244 return combine( other( i ), other( j ) );
245}
246
247// Pair-to-index conversions
248
250{
251 switch ( i ) {
252 case BC:
253 return B;
254 case CA:
255 return C;
256 case AB:
257 return A;
258 }
259 assert( 0 );
260 return A; // should never get here
261}
262
264{
265 switch ( i ) {
266 case BC:
267 return C;
268 case CA:
269 return A;
270 case AB:
271 return B;
272 }
273 assert( 0 );
274 return A; // should never get here
275}
276
278{
279 switch ( i ) {
280 case BC:
281 return A;
282 case CA:
283 return B;
284 case AB:
285 return C;
286 }
287 assert( 0 );
288 return A; // should never get here
289}
290
292{
293 return other( other( i, j ) );
294}
295
297{
298 if ( strcmp( str, "A" ) )
299 return A;
300 else if ( strcmp( str, "B" ) )
301 return B;
302 else if ( strcmp( str, "C" ) )
303 return C;
304 else
305 assert( 0 );
306 return A;
307}
308
309Pair EvtCyclic3::strToPair( const char* str )
310{
311 if ( !strcmp( str, "AB" ) || !strcmp( str, "BA" ) )
312 return AB;
313 else if ( !strcmp( str, "BC" ) || !strcmp( str, "CB" ) )
314 return BC;
315 else if ( !strcmp( str, "CA" ) || !strcmp( str, "AC" ) )
316 return CA;
317 else
318 assert( 0 );
319 return AB;
320}
321
322const char* EvtCyclic3::c_str( Index i )
323{
324 switch ( i ) {
325 case A:
326 return "A";
327 case B:
328 return "B";
329 case C:
330 return "C";
331 }
332 assert( 0 );
333 return nullptr; // sngh
334}
335
336const char* EvtCyclic3::c_str( Pair i )
337{
338 switch ( i ) {
339 case BC:
340 return "BC";
341 case CA:
342 return "CA";
343 case AB:
344 return "AB";
345 }
346 assert( 0 );
347 return nullptr; // sngh
348}
349
350const char* EvtCyclic3::c_str( Perm p )
351{
352 if ( p == ABC )
353 return "ABC";
354 if ( p == BCA )
355 return "BCA";
356 if ( p == CAB )
357 return "CAB";
358 if ( p == CBA )
359 return "CBA";
360 if ( p == BAC )
361 return "BAC";
362 if ( p == ACB )
363 return "ACB";
364 assert( 0 );
365 return "ABC";
366}
367
368char* EvtCyclic3::append( const char* str, EvtCyclic3::Index i )
369{
370 // str + null + 1 character
371 char* s = new char[strlen( str ) + 2];
372 strcpy( s, str );
373 strcat( s, c_str( i ) );
374
375 return s;
376}
377
378char* EvtCyclic3::append( const char* str, EvtCyclic3::Pair i )
379{
380 // str + null + 2 characters
381 char* s = new char[strlen( str ) + 3];
382 strcpy( s, str );
383 strcat( s, c_str( i ) );
384
385 return s;
386}
387
388ostream& operator<<( ostream& os, EvtCyclic3::Index i )
389{
390 switch ( i ) {
391 case A: {
392 os << "A";
393 return os;
394 }
395 case B: {
396 os << "B";
397 return os;
398 }
399 case C: {
400 os << "C";
401 return os;
402 }
403 }
404 assert( 0 );
405 return os; // should never get here
406}
407
408ostream& operator<<( ostream& os, EvtCyclic3::Pair i )
409{
410 switch ( i ) {
411 case BC: {
412 os << "BC";
413 return os;
414 }
415 case CA: {
416 os << "CA";
417 return os;
418 }
419 case AB: {
420 os << "AB";
421 return os;
422 }
423 }
424 assert( 0 );
425 return os; // should never get here
426}
ostream & operator<<(ostream &os, EvtCyclic3::Index i)
Index permute(Index i, Perm p)
Index next(Index i)
Index strToIndex(const char *str)
Perm permutation(Index i1, Index i2, Index i3)
char * append(const char *str, EvtCyclic3::Index i)
Index common(Pair i, Pair j)
Pair strToPair(const char *str)
Pair combine(Index i, Index j)
Index second(Pair i)
Pair i2pair(int i)
Index prev(Index i)
const char * c_str(Index i)
Index other(Index i, Index j)
Index first(Pair i)