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