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.
EvtAmpFactory.hh
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 #ifndef EVT_AMP_FACTORY_HH
22 #define EVT_AMP_FACTORY_HH
23 
24 #include "EvtGenBase/EvtAmpPdf.hh"
26 #include "EvtGenBase/EvtMacros.hh"
28 #include "EvtGenBase/EvtPdfMax.hh"
29 #include "EvtGenBase/EvtPdfSum.hh"
30 
31 #include <stdio.h>
32 #include <string>
33 #include <vector>
34 
35 // Abstract amplitude factory parameterized by a vector of
36 // strings. Derived classes construct the amplitude, and PDFs for sampling
37 // points.
38 
39 template <class T>
41  public:
42  EvtAmpFactory() = default;
43 
44  protected:
45  EvtAmpFactory( EvtAmpFactory<T>&& ) = default;
47  _amp( other._amp ? other._amp->clone() : nullptr ),
48  _ampConj( other._ampConj ? other._ampConj->clone() : nullptr ),
49  _pc( other._pc ? other._pc->clone() : nullptr ),
50  _names( other._names ),
51  _dm( other._dm ),
54  {
55  }
56 
57  public:
58  virtual ~EvtAmpFactory() = default;
59 
60  virtual EvtAmpFactory<T>* clone() const = 0;
61 
62  virtual void build( const EvtMultiChannelParser& parser, int nItg )
63  {
64  _amp = std::make_unique<EvtAmplitudeSum<T>>();
65  _ampConj = std::make_unique<EvtAmplitudeSum<T>>();
66  _pc = std::make_unique<EvtPdfSum<T>>();
67  _dm = parser.dm();
68  _mixAmpli = parser.mixAmpli();
69  _mixPhase = parser.mixPhase();
70 
71  printf( "Amplitude with %d terms\n", parser.getNAmp() );
72  int i;
73  for ( i = 0; i < parser.getNAmp(); i++ ) {
74  std::vector<std::string> v = parser.amp( i );
75  EvtComplex c = parser.ampCoef( i );
76  processAmp( c, v );
77  }
78 
79  printf( "Conj. amplitude with %d terms\n", parser.getNAmpConj() );
80  for ( i = 0; i < parser.getNAmpConj(); i++ ) {
81  std::vector<std::string> v = parser.ampConj( i );
82  EvtComplex c = parser.ampConjCoef( i );
83  processAmp( c, v, true );
84  }
85 
86  printf( "Calculating pole compensator integrals %d steps\n", nItg );
87  if ( nItg > 0 )
88  _pc->getItg( nItg );
89 
90  printf( "End build\n" );
91  }
92 
93  virtual void processAmp( EvtComplex c, std::vector<std::string> v,
94  bool conj = false ) = 0;
95 
96  inline bool isCPModel() const
97  {
98  return ( _ampConj->nTerms() > 0 ? true : false );
99  }
100  inline double dm() const { return _dm; }
101  inline double mixAmpli() const { return _mixAmpli; }
102  inline double mixPhase() const { return _mixPhase; }
103 
104  void setVerbose() { _verbose = true; }
105 
106  EvtAmplitudeSum<T>* getAmp() const { return _amp.get(); }
107  EvtAmplitudeSum<T>* getAmpConj() const { return _ampConj.get(); }
108  EvtPdfSum<T>* getPC() const { return _pc.get(); }
109  EvtAmplitude<T>* getAmp( int i ) const { return _amp->getTerm( i ); }
110  EvtPdf<T>* getPC( int i ) const { return _pc->getPdf( i ); }
111  const char* compName( int i ) const { return _names[i].c_str(); }
112 
113  EvtComplex getCoeff( int i ) const { return _amp->c( i ); }
114 
115  double getTermCoeff( int i ) const { return abs2( _amp->c( i ) ); }
116  double getTermCoeff( int type, int i, int j ) const
117  {
118  switch ( type ) {
119  case 0:
120  return 2 * real( _amp->c( i ) * conj( _amp->c( j ) ) ); //posre
121  case 1:
122  return -2 * real( _amp->c( i ) * conj( _amp->c( j ) ) ); //negre
123  case 2:
124  return -2 * imag( _amp->c( i ) * conj( _amp->c( j ) ) ); //posim
125  case 3:
126  return 2 * imag( _amp->c( i ) * conj( _amp->c( j ) ) ); //negim
127  default:
128  assert( 0 );
129  }
130  }
131 
132  protected:
133  std::unique_ptr<EvtAmplitudeSum<T>> _amp; // _owned_ amplitude
134  std::unique_ptr<EvtAmplitudeSum<T>> _ampConj; // _owned_ conjugate amplitude
135  std::unique_ptr<EvtPdfSum<T>> _pc; // _owned_ pole compensator
136  std::vector<std::string> _names; // names of partial amplitudes
137 
138  double _dm = 0; // Mass difference for conjugate amplitude
139  double _mixPhase; // mixing phase
140  double _mixAmpli; // cpv in mixing
141  bool _verbose = false;
142 };
143 
144 #endif
double mixAmpli() const
virtual EvtAmpFactory< T > * clone() const =0
virtual void processAmp(EvtComplex c, std::vector< std::string > v, bool conj=false)=0
virtual ~EvtAmpFactory()=default
EvtAmplitudeSum< T > * getAmpConj() const
EvtAmplitudeSum< T > * getAmp() const
EvtPdf< T > * getPC(int i) const
double mixPhase() const
Evt3Rank3C conj(const Evt3Rank3C &t2)
Definition: Evt3Rank3C.cpp:172
double abs2(const EvtComplex &c)
Definition: EvtComplex.hh:209
double getTermCoeff(int type, int i, int j) const
double getTermCoeff(int i) const
const char * compName(int i) const
double dm() const
EvtAmpFactory()=default
bool isCPModel() const
EvtPdfSum< T > * getPC() const
EvtAmplitude< T > * getAmp(int i) const
std::unique_ptr< EvtAmplitudeSum< T > > _ampConj
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:235
virtual void build(const EvtMultiChannelParser &parser, int nItg)
EvtComplex getCoeff(int i) const
Definition: EvtPdf.hh:72
EvtComplex ampConjCoef(int i) const
std::vector< std::string > amp(int i) const
EvtComplex ampCoef(int i) const
std::vector< std::string > _names
EvtAmpFactory(const EvtAmpFactory< T > &other)
std::unique_ptr< EvtAmplitudeSum< T > > _amp
std::vector< std::string > ampConj(int i) const
double real(const EvtComplex &c)
Definition: EvtComplex.hh:230
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156
std::unique_ptr< EvtPdfSum< T > > _pc