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