BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtTauola.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of models developed at BES collaboration
5// based on the EvtGen framework. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/BesCopyright
9// Copyright (A) 2006 Ping Rong-Gang
10//
11// Module: EvtTauola.cc
12// the necessary file: tauola2.4.F
13//
14// Description: interface to the tauola package
15//
16// Modification history:
17//
18// Ping R.-G. 2008-07-13 Module created
19//
20//------------------------------------------------------------------------
21//
22#include "EvtTauola.hh"
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <string>
38#include <unistd.h>
39using std::endl;
40using std::fstream;
41using std::ios;
42using std::ofstream;
43using std::resetiosflags;
44using std::setiosflags;
45using std::setw;
46
47int EvtTauola::ntauoladecays = 0;
48EvtDecayBasePtr* EvtTauola::tauoladecays = 0;
49int EvtTauola::ntable = 0;
50
51int EvtTauola::ncommand = 0;
52int EvtTauola::lcommand = 0;
53std::string* EvtTauola::commands = 0;
54
55extern "C" {
56extern void dectes_( int*, int*, int*, int*, int*, double*, double*, double*, double* );
57}
58
60
62
63 int i;
64
65 // the deletion of commands is really uggly!
66
67 if ( ntauoladecays == 0 )
68 {
69 delete[] commands;
70 commands = 0;
71 return;
72 }
73
74 for ( i = 0; i < ntauoladecays; i++ )
75 {
76 if ( tauoladecays[i] == this )
77 {
78 tauoladecays[i] = tauoladecays[ntauoladecays - 1];
79 ntauoladecays--;
80 if ( ntauoladecays == 0 )
81 {
82 delete[] commands;
83 commands = 0;
84 }
85 return;
86 }
87 }
88
89 report( ERROR, "EvtGen" ) << "Error in destroying Tauola model!" << endl;
90}
91
92void EvtTauola::getName( std::string& model_name ) { model_name = "TAUOLA"; }
93
95
97
99
100 // checkNArg(1);
101
102 if ( getParentId().isAlias() )
103 {
104
105 report( ERROR, "EvtGen" ) << "EvtTauola finds that you are decaying the" << endl
106 << " aliased particle " << EvtPDL::name( getParentId() ).c_str()
107 << " with the Tauola model" << endl
108 << " this does not work, please modify decay table." << endl;
109 report( ERROR, "EvtGen" ) << "Will terminate execution!" << endl;
110 ::abort();
111 }
112
113 store( this );
114 // std::cout<<"Tauola initialization"<<std::endl;
115}
116
117std::string EvtTauola::commandName() { return std::string( "TauolaPar" ); }
118
119void EvtTauola::command( std::string cmd ) {
120
121 if ( ncommand == lcommand )
122 {
123
124 lcommand = 10 + 2 * lcommand;
125
126 std::string* newcommands = new std::string[lcommand];
127
128 int i;
129
130 for ( i = 0; i < ncommand; i++ ) { newcommands[i] = commands[i]; }
131
132 delete[] commands;
133
134 commands = newcommands;
135 }
136
137 commands[ncommand] = cmd;
138
139 ncommand++;
140}
141
143
144 static int iniflag = 0;
145
146 static EvtId STRNG = EvtPDL::getId( "string" );
147
148 int istdheppar = EvtPDL::getStdHep( p->getId() );
149
150 /*
151 if (pycomp_(&istdheppar)==0){
152 report(ERROR,"EvtGen") << "Tauola can not decay:"
153 <<EvtPDL::name(p->getId()).c_str()<<endl;
154 return;
155 }
156 */
157
158 EvtVector4R p4[20];
159
160 int i, more;
161 int idtau = EvtPDL::getStdHep( p->getId() );
162 int ndaugjs;
163 static int kf[20];
164 EvtId evtnumstable[20], evtnumparton[20];
165 int stableindex[20], partonindex[20];
166 int numstable;
167 int numparton;
168 static int km[20];
170
171 static double px[20], py[20], pz[20], e[20];
172
173 // std::cout<<"cc: inifag,idtau,taup,polt"<<iniflag<<"; "<<idtau<<"; "<<taup[0]<<";
174 // "<<polt[3]<<endl;
175 if ( iniflag == 0 ) dectes_( &iniflag, &idtau, &ndaugjs, kf, km, px, py, pz, e );
176 // std::cout<<"Tauola initialized"<<endl;
177 if ( p->getNDaug() != 0 ) { p->deleteDaughters( true ); }
178
179 int count = 0;
180
181 do {
182 // report(INFO,"EvtGen") << "calling tauola " << idtau<< " " << mp <<endl;
183 iniflag = iniflag + 1; // to count the event number
184 dectes_( &iniflag, &idtau, &ndaugjs, kf, km, px, py, pz, e );
185
186 numstable = 0;
187 numparton = 0;
188 // report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
189 for ( i = 0; i < ndaugjs; i++ )
190 {
191 // std::cout<<"ndaugjs,kf,km,px,py,pz,e: "<<i<<", "<<km[i]<<", "<<kf[i]<<", "<<px[i]<<"
192 // ,"<<py[i]<<", "<<pz[i]<<", "<<e[i]<<std::endl; //for debugging
193
194 if ( EvtPDL::evtIdFromStdHep( kf[i] ) == EvtId( -1, -1 ) )
195 {
196 report( ERROR, "EvtGen" ) << "Tauola returned particle:" << kf[i] << endl;
197 report( ERROR, "EvtGen" ) << "This can not be translated to evt number" << endl;
198 report( ERROR, "EvtGen" ) << "and the decay will be rejected!" << endl;
199 report( ERROR, "EvtGen" ) << "The decay was of particle:" << idtau << endl;
200 }
201
202 // sort out the partons
203 if ( abs( kf[i] ) <= 6 || kf[i] == 21 )
204 {
205 partonindex[numparton] = i;
206 evtnumparton[numparton] = EvtPDL::evtIdFromStdHep( kf[i] );
207 numparton++;
208 }
209 else
210 {
211 stableindex[numstable] = i;
212 evtnumstable[numstable] = EvtPDL::evtIdFromStdHep( kf[i] );
213 numstable++;
214 }
215
216 // have to protect against negative mass^2 for massless particles
217 // i.e. neutrinos and photons.
218 // this is uggly but I need to fix it right now....
219
220 if ( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] >= e[i] * e[i] )
221 { e[i] = sqrt( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] ) + 0.0000000001; }
222
223 p4[i].set( e[i], px[i], py[i], pz[i] );
224 }
225
226 int channel = EvtDecayTable::inChannelList( p->getId(), numstable, evtnumstable );
227
228 more = ( channel != -1 );
229
230 count++;
231
232 } while ( more && ( count < 10000 ) );
233
234 if ( count > 9999 )
235 {
236 report( INFO, "EvtGen" ) << "Too many loops in EvtTauola!!!" << endl;
237 report( INFO, "EvtGen" ) << "Parent:" << EvtPDL::name( getParentId() ).c_str() << endl;
238 for ( i = 0; i < numstable; i++ )
239 {
240 report( INFO, "EvtGen" ) << "Daug(" << i << ")"
241 << EvtPDL::name( evtnumstable[i] ).c_str() << endl;
242 }
243 }
244
245 if ( numparton == 0 )
246 {
247
248 p->makeDaughters( numstable, evtnumstable );
249 int ndaugFound = 0;
250 for ( i = 0; i < numstable; i++ )
251 {
252 p->getDaug( i )->init( evtnumstable[i], p4[stableindex[i]] );
253 ndaugFound++;
254 }
255 if ( ndaugFound == 0 )
256 {
257 report( ERROR, "EvtGen" ) << "Tauola has failed to do a decay ";
258 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
259 << endl;
260 assert( 0 );
261 }
262
263 fixPolarizations( p );
264
265 return;
266 }
267 else
268 {
269
270 // have partons in TAUOLA
271
272 EvtVector4R p4string( 0.0, 0.0, 0.0, 0.0 );
273
274 for ( i = 0; i < numparton; i++ ) { p4string += p4[partonindex[i]]; }
275
276 int nprimary = 1;
277 type[0] = STRNG;
278 for ( i = 0; i < numstable; i++ )
279 {
280 if ( km[stableindex[i]] == 0 ) { type[nprimary++] = evtnumstable[i]; }
281 }
282
283 p->makeDaughters( nprimary, type );
284
285 p->getDaug( 0 )->init( STRNG, p4string );
286
287 EvtVector4R p4partons[10];
288
289 for ( i = 0; i < numparton; i++ ) { p4partons[i] = p4[partonindex[i]]; }
290
291 ( (EvtStringParticle*)p->getDaug( 0 ) )->initPartons( numparton, p4partons, evtnumparton );
292
293 nprimary = 1;
294
295 for ( i = 0; i < numstable; i++ )
296 {
297
298 if ( km[stableindex[i]] == 0 )
299 { p->getDaug( nprimary++ )->init( evtnumstable[i], p4[stableindex[i]] ); }
300 }
301
302 int nsecond = 0;
303 for ( i = 0; i < numstable; i++ )
304 {
305 if ( km[stableindex[i]] != 0 ) { type[nsecond++] = evtnumstable[i]; }
306 }
307
308 p->getDaug( 0 )->makeDaughters( nsecond, type );
309
310 EvtVector4R p4stringboost( p4string.get( 0 ), -p4string.get( 1 ), -p4string.get( 2 ),
311 -p4string.get( 3 ) );
312
313 nsecond = 0;
314 for ( i = 0; i < numstable; i++ )
315 {
316 if ( km[stableindex[i]] != 0 )
317 {
318 p4[stableindex[i]] = boostTo( p4[stableindex[i]], p4stringboost );
319 p->getDaug( 0 )->getDaug( nsecond )->init( evtnumstable[i], p4[stableindex[i]] );
320 p->getDaug( 0 )->getDaug( nsecond )->setDiagonalSpinDensity();
321 p->getDaug( 0 )->getDaug( nsecond )->decay();
322 nsecond++;
323 }
324 }
325
326 if ( nsecond == 0 )
327 {
328 report( ERROR, "EvtGen" ) << "Jetset has failed to do a decay ";
329 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
330 << endl;
331 assert( 0 );
332 }
333
334 fixPolarizations( p );
335
336 return;
337 }
338}
339
340void EvtTauola::fixPolarizations( EvtParticle* p ) {
341
342 // special case for now to handle the tau polarization
343
344 int ndaug = p->getNDaug();
345
346 int i;
347
348 // static EvtId tau=EvtPDL::getId("tau-");
349 static EvtId tau = getParentId();
350
351 for ( i = 0; i < ndaug; i++ )
352 {
353 if ( p->getDaug( i )->getId() == tau )
354 {
355
356 EvtSpinDensity rho;
357
358 rho.SetDim( 2 );
359 rho.Set( 0, 0, 1.0 );
360 rho.Set( 0, 1, 0.0 );
361
362 rho.Set( 1, 0, 0.0 );
363 rho.Set( 1, 1, 1.0 );
364
365 EvtVector4R p4Psi = p->getDaug( i )->getP4();
366
367 double alpha = atan2( p4Psi.get( 2 ), p4Psi.get( 1 ) );
368 double beta = acos( p4Psi.get( 3 ) / p4Psi.d3mag() );
369
370 p->getDaug( i )->setSpinDensityForwardHelicityBasis( rho, alpha, beta, 0.0 );
372 }
373 }
374}
375
376void EvtTauola::store( EvtDecayBase* jsdecay ) {
377
378 if ( ntauoladecays == ntable )
379 {
380
381 EvtDecayBasePtr* newtauoladecays = new EvtDecayBasePtr[2 * ntable + 10];
382 int i;
383 for ( i = 0; i < ntable; i++ ) { newtauoladecays[i] = tauoladecays[i]; }
384 ntable = 2 * ntable + 10;
385 delete[] tauoladecays;
386 tauoladecays = newtauoladecays;
387 }
388
389 tauoladecays[ntauoladecays++] = jsdecay;
390}
EvtDecayBase * EvtDecayBasePtr
EvtDiracSpinor boostTo(const EvtDiracSpinor &sp, const EvtVector4R p4)
const int MAX_DAUG
DOUBLE_PRECISION count[3]
double alpha
ostream & report(Severity severity, const char *facility)
Definition EvtReport.cc:34
@ ERROR
Definition EvtReport.hh:49
@ INFO
Definition EvtReport.hh:52
void dectes_(int *, int *, int *, int *, int *, double *, double *, double *, double *)
EvtDecayBase * EvtDecayBasePtr
Definition EvtTauola.hh:29
EvtId getParentId()
void setDaughterSpinDensity(int daughter)
static int inChannelList(EvtId parent, int ndaug, EvtId *daugs)
Definition EvtId.hh:27
static int getStdHep(EvtId id)
Definition EvtPDL.hh:61
static EvtId evtIdFromStdHep(int stdhep)
Definition EvtPDL.cc:232
static std::string name(EvtId i)
Definition EvtPDL.hh:70
static EvtId getId(const std::string &name)
Definition EvtPDL.cc:272
void setSpinDensityForwardHelicityBasis(const EvtSpinDensity &rho)
void makeDaughters(int ndaug, EvtId *id)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
EvtId getId() const
void setDiagonalSpinDensity()
const EvtVector4R & getP4() const
int getNDaug() const
EvtParticle * getDaug(int i)
void deleteDaughters(bool keepChannel=false)
double mass() const
void Set(int i, int j, const EvtComplex &rhoij)
void SetDim(int n)
void init()
Definition EvtTauola.cc:98
std::string commandName()
Definition EvtTauola.cc:117
void getName(std::string &name)
Definition EvtTauola.cc:92
void command(std::string cmd)
Definition EvtTauola.cc:119
EvtDecayBase * clone()
Definition EvtTauola.cc:94
void decay(EvtParticle *p)
Definition EvtTauola.cc:142
virtual ~EvtTauola()
Definition EvtTauola.cc:61
void initProbMax()
Definition EvtTauola.cc:96
double get(int i) const
double d3mag() const
void set(int i, double d)