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
EvtDecayAmp.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 "EvtGenBase/EvtAmp.hh"
25#include "EvtGenBase/EvtPDL.hh"
30using std::endl;
31
32void EvtDecayAmp::makeDecay( EvtParticle* p, bool recursive )
33{
34 //original default value
35 int ntimes = 10000;
36
37 int more;
38
40 double prob, prob_max;
41
42 m_amp2.init( p->getId(), getNDaug(), getDaugs() );
43
44 do {
46 m_weight = 1.0;
47 decay( p );
48
49 rho = m_amp2.getSpinDensity();
50
51 prob = p->getSpinDensityForward().normalizedProb( rho );
52
53 if ( prob < 0.0 ) {
54 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
55 << "Negative prob:" << p->getId().getId() << " "
56 << p->getChannel() << endl;
57
58 EvtGenReport( EVTGEN_ERROR, "EvtGen" ) << "rho_forward:" << endl;
60 EvtGenReport( EVTGEN_ERROR, "EvtGen" ) << "rho decay:" << endl;
61 EvtGenReport( EVTGEN_ERROR, "EvtGen" ) << rho << endl;
62 }
63
64 if ( prob != prob ) {
65 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
66 << "Forward density matrix:" << endl;
68
69 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
70 << "Decay density matrix:" << endl;
71 EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << rho;
72
73 EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "prob:" << prob << endl;
74
75 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
76 << "Particle:" << EvtPDL::name( p->getId() ).c_str() << endl;
77 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
78 << "channel :" << p->getChannel() << endl;
79 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
80 << "Momentum:" << p->getP4() << " " << p->mass() << endl;
81 if ( p->getParent() != nullptr ) {
82 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
83 << "parent:"
84 << EvtPDL::name( p->getParent()->getId() ).c_str() << endl;
85 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
86 << "parent channel :" << p->getParent()->getChannel()
87 << endl;
88
89 EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "parent daughters :";
90 for ( size_t i = 0; i < p->getParent()->getNDaug(); i++ ) {
92 << EvtPDL::name( p->getParent()->getDaug( i )->getId() )
93 .c_str()
94 << " ";
95 }
96 EvtGenReport( EVTGEN_DEBUG, "" ) << endl;
97
98 EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "daughters :";
99 for ( size_t i = 0; i < p->getNDaug(); i++ ) {
101 << EvtPDL::name( p->getDaug( i )->getId() ).c_str()
102 << " ";
103 }
104 EvtGenReport( EVTGEN_DEBUG, "" ) << endl;
105
106 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
107 << "daughter momenta :" << endl;
108 ;
109 for ( size_t i = 0; i < p->getNDaug(); i++ ) {
111 << p->getDaug( i )->getP4() << " "
112 << p->getDaug( i )->mass();
113 EvtGenReport( EVTGEN_DEBUG, "" ) << endl;
114 }
115 }
116 }
117
118 prob /= m_weight;
119
120 prob_max = getProbMax( prob );
121 p->setDecayProb( prob / prob_max );
122
123 more = prob < EvtRandom::Flat( prob_max );
124
125 ntimes--;
126
127 } while ( ntimes && more );
128
129 if ( ntimes == 0 ) {
130 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
131 << "Tried accept/reject: 10000"
132 << " times, and rejected all the times!" << endl;
133
134 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
135 << p->getSpinDensityForward() << endl;
136 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
137 << "Is therefore accepting the last event!" << endl;
138 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
139 << "Decay of particle:" << EvtPDL::name( p->getId() ).c_str()
140 << "(channel:" << p->getChannel() << ") with mass " << p->mass()
141 << endl;
142
143 for ( size_t ii = 0; ii < p->getNDaug(); ii++ ) {
144 EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
145 << "Daughter " << ii << ":"
146 << EvtPDL::name( p->getDaug( ii )->getId() ).c_str()
147 << " with mass " << p->getDaug( ii )->mass() << endl;
148 }
149 }
150
151 EvtSpinDensity rho_list[10];
152
153 rho_list[0] = p->getSpinDensityForward();
154
155 EvtAmp ampcont;
156
157 if ( m_amp2.m_pstates != 1 ) {
158 ampcont = m_amp2.contract( 0, p->getSpinDensityForward() );
159 } else {
160 ampcont = m_amp2;
161 }
162
163 // it may be that the parent decay model has already
164 // done the decay - this should be rare and the
165 // model better know what it is doing..
166
167 if ( !daugsDecayedByParentModel() ) {
168 if ( recursive ) {
169 for ( size_t i = 0; i < p->getNDaug(); i++ ) {
170 rho.setDim( m_amp2.m_dstates[i] );
171
172 if ( m_amp2.m_dstates[i] == 1 ) {
173 rho.set( 0, 0, EvtComplex( 1.0, 0.0 ) );
174 } else {
175 rho = ampcont.contract( m_amp2.m_dnontrivial[i], m_amp2 );
176 }
177
178 if ( !rho.check() ) {
179 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
180 << "-------start error-------" << endl;
181 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
182 << "forward rho failed Check:"
183 << EvtPDL::name( p->getId() ).c_str() << " "
184 << p->getChannel() << " " << i << endl;
185
186 p->printTree();
187
188 for ( size_t idaug = 0; idaug < p->getNDaug(); idaug++ ) {
189 EvtParticle* daughter = p->getDaug( idaug );
190 if ( daughter != nullptr ) {
191 daughter->printTree();
192 }
193 }
194
195 EvtParticle* pParent = p->getParent();
196 if ( pParent != nullptr ) {
197 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
198 << "Parent:"
199 << EvtPDL::name( pParent->getId() ).c_str() << endl;
200
201 EvtParticle* grandParent = pParent->getParent();
202
203 if ( grandParent != nullptr ) {
204 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
205 << "GrandParent:"
206 << EvtPDL::name( grandParent->getId() ).c_str()
207 << endl;
208 }
209 }
210
211 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
212 << " EvtSpinDensity rho: " << rho;
213
214 m_amp2.dump();
215
216 for ( size_t ii = 0; ii < i + 1; ii++ ) {
217 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
218 << "rho_list[" << ii << "] = " << rho_list[ii];
219 }
220
221 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
222 << "-------Done with error-------" << endl;
223 }
224
225 p->getDaug( i )->setSpinDensityForward( rho );
226 p->getDaug( i )->decay();
227
228 rho_list[i + 1] = p->getDaug( i )->getSpinDensityBackward();
229
230 if ( m_amp2.m_dstates[i] != 1 ) {
231 ampcont = ampcont.contract( m_amp2.m_dnontrivial[i],
232 rho_list[i + 1] );
233 }
234 }
235
236 p->setSpinDensityBackward( m_amp2.getBackwardSpinDensity( rho_list ) );
237
238 if ( !p->getSpinDensityBackward().check() ) {
239 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
240 << "rho_backward failed Check" << p->getId().getId() << " "
241 << p->getChannel() << endl;
242
243 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
245 }
246 }
247 }
248
249 if ( ( getFSR() || EvtRadCorr::alwaysRadCorr() ) &&
251 int n_daug_orig = p->getNDaug();
253 int n_daug_new = p->getNDaug();
254 for ( int i = n_daug_orig; i < n_daug_new; i++ ) {
255 p->getDaug( i )->decay();
256 }
257 }
258}
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition EvtReport.cpp:32
@ EVTGEN_DEBUG
Definition EvtReport.hh:53
@ EVTGEN_ERROR
Definition EvtReport.hh:49
EvtSpinDensity contract(int i, const EvtAmp &a) const
Definition EvtAmp.cpp:322
EvtAmp m_amp2
void makeDecay(EvtParticle *p, bool recursive=true) override
double m_weight
bool getFSR() const
int getNDaug() const
virtual void decay(EvtParticle *p)=0
bool daugsDecayedByParentModel() const
bool m_daugsDecayedByParentModel
double getProbMax(double prob)
const EvtId * getDaugs() const
int getId() const
Definition EvtId.hh:41
static std::string name(EvtId i)
Definition EvtPDL.cpp:376
void setSpinDensityBackward(const EvtSpinDensity &rho)
void setSpinDensityForward(const EvtSpinDensity &rho)
void setDecayProb(double p)
EvtId getId() const
const EvtVector4R & getP4() const
void printTree() const
EvtParticle * getDaug(const int i)
double mass() const
size_t getNDaug() const
EvtSpinDensity getSpinDensityBackward()
int getChannel() const
EvtParticle * getParent() const
EvtSpinDensity getSpinDensityForward()
static bool alwaysRadCorr()
static bool neverRadCorr()
static void doRadCorr(EvtParticle *p)
static double Flat()
Definition EvtRandom.cpp:95
void setDim(int n)
double normalizedProb(const EvtSpinDensity &d)
void set(int i, int j, const EvtComplex &rhoij)