BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtLunda.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 @IHEP
10//
11// Module: EvtLunda.cc
12// the necessary file: lundar.F
13// fist.inc,gen.inc mix.inc stdhep.inc
14// Description: Modified Lund model at tau-charm energy level, see
15// PHYSICAL REVIEW D, VOLUME 62, 034003
16// Modification history:
17//
18// Ping R.-G. Jan.25, 2010 Module created
19// The random engine RLU0 is unified with RLU for BesEvtGen
20//------------------------------------------------------------------------
21//
22#include "EvtLunda.hh"
30#include <fstream>
31#include <iomanip>
32#include <iostream>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <string>
37#include <unistd.h>
38using std::endl;
39using std::fstream;
40using std::ios;
41using std::ofstream;
42using std::resetiosflags;
43using std::setiosflags;
44using std::setw;
45
46int EvtLunda::nlundadecays = 0;
47EvtDecayBasePtr* EvtLunda::lundadecays = 0;
48int EvtLunda::ntable = 0;
49
50int EvtLunda::ncommand = 0;
51int EvtLunda::lcommand = 0;
52std::string* EvtLunda::commands = 0;
53int EvtLunda::nevt = 0;
54
55extern "C" {
56extern void lundar_( int*, int*, float*, int*, int*, int*, double*, double*, double*,
57 double* );
58}
59
60extern "C" {
61extern int lucomp_( int* kf );
62}
63
64extern "C" {
65extern void lugive0_( const char* cnfgstr, int length );
66}
67
68// COMMON/CHECKTAG/DECAYTAG
69extern "C" struct {
70 double decaytag;
72
73/*
74extern struct
75{
76 char mypdg[200];
77}mypdgfile_;
78*/
79
80/*
81extern struct
82{
83 int xpdg; // pdg code for e+e- -> X particle, see subroutine LUBECN( , ) in luarlw.F,
84}nores_;
85*/
86
89
90 int i;
91
92 // the deletion of commands is really uggly!
93
94 if ( nlundadecays == 0 )
95 {
96 delete[] commands;
97 commands = 0;
98 return;
99 }
100
101 for ( i = 0; i < nlundadecays; i++ )
102 {
103 if ( lundadecays[i] == this )
104 {
105 lundadecays[i] = lundadecays[nlundadecays - 1];
106 nlundadecays--;
107 if ( nlundadecays == 0 )
108 {
109 delete[] commands;
110 commands = 0;
111 }
112 return;
113 }
114 }
115
116 report( ERROR, "EvtGen" ) << "Error in destroying Lunda model!" << endl;
117}
118
119void EvtLunda::getName( std::string& model_name ) { model_name = "LUNDA"; }
120
122
124
126
127 // checkNArg(1);
128 std::string strpdg = getenv( "BESEVTGENROOT" );
129 strpdg += "/share/r_pdg.dat";
130 // strcpy(mypdgfile_.mypdg, strpdg.c_str());
131 std::cout << "mypdg= " << strpdg << std::endl;
132
133 if ( getNArg() > 2 )
134 {
135 std::cout << "Parameter can be 1 or 2, You have " << getNArg() << std::endl;
136 ::abort();
137 }
138
139 if ( getParentId().isAlias() )
140 {
141
142 report( ERROR, "EvtGen" ) << "EvtLunda finds that you are decaying the" << endl
143 << " aliased particle " << EvtPDL::name( getParentId() ).c_str()
144 << " with the Lunda model" << endl
145 << " this does not work, please modify decay table." << endl;
146 report( ERROR, "EvtGen" ) << "Will terminate execution!" << endl;
147 ::abort();
148 }
149
150 store( this );
151}
152
153std::string EvtLunda::commandName() { return std::string( "LundaPar" ); }
154
155void EvtLunda::command( std::string cmd ) {
156 if ( ncommand == lcommand )
157 {
158 lcommand = 10 + 2 * lcommand;
159 std::string* newcommands = new std::string[lcommand];
160 int i;
161 for ( i = 0; i < ncommand; i++ ) { newcommands[i] = commands[i]; }
162 delete[] commands;
163 commands = newcommands;
164 }
165 commands[ncommand] = cmd;
166 ncommand++;
167}
168
170
171 static int iniflag = 1;
172
173 static EvtId STRNG = EvtPDL::getId( "string" );
174
175 int istdheppar = EvtPDL::getStdHep( p->getId() );
176
177 /*
178 int Xpdg=0;
179 if(getNArg()==1){
180 Xpdg = getArg(0);
181 if(Xpdg == 100443) Xpdg = 30443; //chage the curent pdg code to jetset pdg code for
182 psiprime
183 }
184 nores_.xpdg = Xpdg;
185 */
186
187 /*
188 if (pycomp_(&istdheppar)==0){
189 report(ERROR,"EvtGen") << "Lunda can not decay:"
190 <<EvtPDL::name(p->getId()).c_str()<<endl;
191 return;
192 }
193 */
194 double mp = p->mass();
195 float xmp = mp;
196 // std::cout<<"float xmp="<<xmp<<std::endl;
197
198 EvtVector4R p4[50];
199
200 int i, more;
201 int ip = EvtPDL::getStdHep( p->getId() );
202 int ndaugjs;
203 static int kf[4000];
204 EvtId evtnumstable[100], evtnumparton[100];
205 int stableindex[100], partonindex[100];
206 int numstable;
207 int numparton;
208 static int km[4000];
210
211 int isr = 1; // open ISR (default)
212 if ( getNArg() > 0 ) { isr = getArg( 0 ); }
213
214 static double px[4000], py[4000], pz[4000], e[4000];
215 if ( iniflag == 1 ) lundar_( &isr, &iniflag, &xmp, &ndaugjs, kf, km, px, py, pz, e );
216
217 if ( p->getNDaug() != 0 ) { p->deleteDaughters( true ); }
218
219 int count = 0;
220 bool mtg = 0;
221
222 do {
223 // report(INFO,"EvtGen") << "calling lunda " << ip<< " " << mp <<endl;
224 iniflag = iniflag + 1; // to count the event number
225 // std::cout<<"Event number by Lunda: "<<iniflag<<std::endl;
226 modeSelection:
227 lundar_( &isr, &iniflag, &xmp, &ndaugjs, kf, km, px, py, pz, e );
228
229 mtg = checktag_.decaytag == 1;
230 if ( mtg ) std::cout << "checktag_.decaytag=" << checktag_.decaytag << std::endl;
231 // if the Ecms is too low, Lunda fails to decay, so change to 3pi decay exclusively
232 // if(mtg) {ExclusiveDecay(p); return;} //see SUBROUTINE LUBEGN(KFL,ECM) in luarlw.F
233
234 LundaInit( 0 ); // allow user to set LundaPar in the decay list
235 numstable = 0;
236 numparton = 0;
237 // report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
238 double esum = 0;
239 // for debugging
240 // for(int i=0;i<ndaugjs;i++){
241 // std::cout<<"ndaugjs,kf,km,px,py,pz,e: "<<i<<", "<<km[i]<<",
242 // "<<EvtPDL::name(EvtPDL::evtIdFromStdHep(kf[i]))<<", "<<px[i]<<" ,"<<py[i]<<",
243 // "<<pz[i]<<", "<<e[i]<<std::endl;
244 // }
245
246 for ( i = 0; i < ndaugjs; i++ )
247 {
248 if ( fabs( kf[i] ) == 11 || kf[i] == 92 || kf[i] == 22 )
249 continue; // fill out the unstatble particle
250 // std::cout<<i<<", "<<km[i]<<", "<<kf[i]<<",
251 // "<<EvtPDL::name(EvtPDL::evtIdFromStdHep(kf[i]))<<" "<<px[i]<<" ,"<<py[i]<<",
252 // "<<pz[i]<<", "<<e[i]<<std::endl; //for debugging
253 if ( EvtPDL::evtIdFromStdHep( kf[i] ) == EvtId( -1, -1 ) )
254 {
255 report( ERROR, "EvtGen" ) << "Lunda returned particle:" << kf[i] << endl;
256 report( ERROR, "EvtGen" ) << "This can not be translated to evt number" << endl;
257 report( ERROR, "EvtGen" ) << "and the decay will be rejected!" << endl;
258 report( ERROR, "EvtGen" ) << "The decay was of particle:" << ip << endl;
259 // xmp=(1+0.01)*xmp;
260 std::cout << "xmp= " << xmp << std::endl;
261 goto modeSelection;
262 }
263
264 // sort out the partons
265 if ( fabs( kf[i] ) <= 6 || kf[i] == 21 )
266 {
267 partonindex[numparton] = i;
268 evtnumparton[numparton] = EvtPDL::evtIdFromStdHep( kf[i] );
269 numparton++;
270 }
271 else
272 {
273 stableindex[numstable] = i;
274 evtnumstable[numstable] = EvtPDL::evtIdFromStdHep( kf[i] );
275 numstable++;
276 }
277
278 esum += e[i];
279 // have to protect against negative mass^2 for massless particles
280 // i.e. neutrinos and photons.
281 // this is uggly but I need to fix it right now....
282
283 if ( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] >= e[i] * e[i] )
284 { e[i] = sqrt( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] ) + 0.0000000001; }
285
286 p4[i].set( e[i], px[i], py[i], pz[i] );
287 }
288
289 int channel = EvtDecayTable::inChannelList( p->getId(), numstable, evtnumstable );
290
291 // Test the branching fraction of lunda
292 // the specified decay mode is put as the 0-th channel with specifing mother particle
293 more = ( channel != -1 );
294 // debugging
295 if ( fabs( esum - xmp ) > 0.001 )
296 {
297 std::cout << "Unexpected final states from Lunda with total energy " << esum
298 << " unequal to " << xmp << std::endl;
299 // xmp=(1+0.01)*xmp;
300 std::cout << "xmp= " << xmp << std::endl;
301 goto modeSelection;
302 }
303
304 count++;
305 } while ( more && ( count < 10000 ) && mtg );
306 // }while( more && (count<10000) );
307
308 if ( count > 9999 )
309 {
310 report( INFO, "EvtGen" ) << "Too many loops in EvtLunda!!!" << endl;
311 report( INFO, "EvtGen" ) << "Parent:" << EvtPDL::name( getParentId() ).c_str() << endl;
312 for ( i = 0; i < numstable; i++ )
313 {
314 report( INFO, "EvtGen" ) << "Daug(" << i << ")"
315 << EvtPDL::name( evtnumstable[i] ).c_str() << endl;
316 }
317 }
318
319 if ( numparton == 0 )
320 {
321
322 p->makeDaughters( numstable, evtnumstable );
323 int ndaugFound = 0;
324 for ( i = 0; i < numstable; i++ )
325 {
326 p->getDaug( i )->init( evtnumstable[i], p4[stableindex[i]] );
327 ndaugFound++;
328 }
329 if ( ndaugFound == 0 )
330 {
331 report( ERROR, "EvtGen" ) << "Lunda has failed to do a decay ";
332 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
333 << endl;
334 assert( 0 );
335 }
336
337 fixPolarizations( p );
338 // debugging
339 // p->printTree();
340
341 return;
342 }
343 else
344 {
345
346 // have partons in LUNDA
347
348 EvtVector4R p4string( 0.0, 0.0, 0.0, 0.0 );
349
350 for ( i = 0; i < numparton; i++ ) { p4string += p4[partonindex[i]]; }
351
352 int nprimary = 1;
353 type[0] = STRNG;
354 for ( i = 0; i < numstable; i++ )
355 {
356 if ( km[stableindex[i]] == 0 ) { type[nprimary++] = evtnumstable[i]; }
357 }
358
359 p->makeDaughters( nprimary, type );
360
361 p->getDaug( 0 )->init( STRNG, p4string );
362
363 EvtVector4R p4partons[10];
364
365 for ( i = 0; i < numparton; i++ ) { p4partons[i] = p4[partonindex[i]]; }
366
367 ( (EvtStringParticle*)p->getDaug( 0 ) )->initPartons( numparton, p4partons, evtnumparton );
368
369 nprimary = 1;
370
371 for ( i = 0; i < numstable; i++ )
372 {
373
374 if ( km[stableindex[i]] == 0 )
375 { p->getDaug( nprimary++ )->init( evtnumstable[i], p4[stableindex[i]] ); }
376 }
377
378 int nsecond = 0;
379 for ( i = 0; i < numstable; i++ )
380 {
381 if ( km[stableindex[i]] != 0 ) { type[nsecond++] = evtnumstable[i]; }
382 }
383
384 p->getDaug( 0 )->makeDaughters( nsecond, type );
385
386 EvtVector4R p4stringboost( p4string.get( 0 ), -p4string.get( 1 ), -p4string.get( 2 ),
387 -p4string.get( 3 ) );
388
389 nsecond = 0;
390 for ( i = 0; i < numstable; i++ )
391 {
392 if ( km[stableindex[i]] != 0 )
393 {
394 p4[stableindex[i]] = boostTo( p4[stableindex[i]], p4stringboost );
395 p->getDaug( 0 )->getDaug( nsecond )->init( evtnumstable[i], p4[stableindex[i]] );
396 p->getDaug( 0 )->getDaug( nsecond )->setDiagonalSpinDensity();
397 p->getDaug( 0 )->getDaug( nsecond )->decay();
398 nsecond++;
399 }
400 }
401
402 if ( nsecond == 0 )
403 {
404 report( ERROR, "EvtGen" ) << "Jetset has failed to do a decay ";
405 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
406 << endl;
407 assert( 0 );
408 }
409
410 fixPolarizations( p );
411
412 return;
413 }
414}
415
416void EvtLunda::fixPolarizations( EvtParticle* p ) {
417
418 // special case for now to handle the J/psi polarization
419
420 int ndaug = p->getNDaug();
421
422 int i;
423
424 static EvtId Jpsi = EvtPDL::getId( "J/psi" );
425
426 for ( i = 0; i < ndaug; i++ )
427 {
428 if ( p->getDaug( i )->getId() == Jpsi )
429 {
430
431 EvtSpinDensity rho;
432
433 rho.SetDim( 3 );
434 rho.Set( 0, 0, 0.5 );
435 rho.Set( 0, 1, 0.0 );
436 rho.Set( 0, 2, 0.0 );
437
438 rho.Set( 1, 0, 0.0 );
439 rho.Set( 1, 1, 1.0 );
440 rho.Set( 1, 2, 0.0 );
441
442 rho.Set( 2, 0, 0.0 );
443 rho.Set( 2, 1, 0.0 );
444 rho.Set( 2, 2, 0.5 );
445
446 EvtVector4R p4Psi = p->getDaug( i )->getP4();
447
448 double alpha = atan2( p4Psi.get( 2 ), p4Psi.get( 1 ) );
449 double beta = acos( p4Psi.get( 3 ) / p4Psi.d3mag() );
450
451 p->getDaug( i )->setSpinDensityForwardHelicityBasis( rho, alpha, beta, 0.0 );
453 }
454 }
455}
456
457void EvtLunda::store( EvtDecayBase* jsdecay ) {
458
459 if ( nlundadecays == ntable )
460 {
461
462 EvtDecayBasePtr* newlundadecays = new EvtDecayBasePtr[2 * ntable + 10];
463 int i;
464 for ( i = 0; i < ntable; i++ ) { newlundadecays[i] = lundadecays[i]; }
465 ntable = 2 * ntable + 10;
466 delete[] lundadecays;
467 lundadecays = newlundadecays;
468 }
469
470 lundadecays[nlundadecays++] = jsdecay;
471}
472
473void EvtLunda::LundaInit( int dummy ) {
474
475 static int first = 1;
476 if ( first )
477 {
478
479 first = 0;
480 for ( int i = 0; i < ncommand; i++ )
481 lugive0_( commands[i].c_str(), strlen( commands[i].c_str() ) );
482 }
483}
484
486 EvtId daugs[8];
487 int _ndaugs = 4;
488 daugs[0] = EvtPDL::getId( std::string( "pi+" ) );
489 daugs[1] = EvtPDL::getId( std::string( "pi-" ) );
490 daugs[2] = EvtPDL::getId( std::string( "pi+" ) );
491 daugs[3] = EvtPDL::getId( std::string( "pi-" ) );
492checkA:
493 p->makeDaughters( _ndaugs, daugs );
494 double totMass = 0;
495 for ( int i = 0; i < _ndaugs; i++ )
496 {
497 EvtParticle* di = p->getDaug( i );
498 double xmi = EvtPDL::getMass( di->getId() );
499 di->setMass( xmi );
500 totMass += xmi;
501 }
502 if ( totMass > p->mass() ) goto checkA;
503 p->initializePhaseSpace( _ndaugs, daugs );
504}
EvtDecayBase * EvtDecayBasePtr
EvtDiracSpinor boostTo(const EvtDiracSpinor &sp, const EvtVector4R p4)
int lucomp_(int *kf)
void lundar_(int *, int *, float *, int *, int *, int *, double *, double *, double *, double *)
void lugive0_(const char *cnfgstr, int length)
double decaytag
Definition EvtLunda.cc:70
struct @266045204252233114312134205125322121371134010276 checktag_
EvtDecayBase * EvtDecayBasePtr
Definition EvtLunda.hh:29
const int MAX_DAUG
DOUBLE_PRECISION count[3]
double alpha
double mp
ostream & report(Severity severity, const char *facility)
Definition EvtReport.cc:34
@ ERROR
Definition EvtReport.hh:49
@ INFO
Definition EvtReport.hh:52
double getArg(int j)
EvtId getParentId()
void setDaughterSpinDensity(int daughter)
static int inChannelList(EvtId parent, int ndaug, EvtId *daugs)
Definition EvtId.hh:27
void LundaInit(int dummy)
Definition EvtLunda.cc:473
void initProbMax()
Definition EvtLunda.cc:123
std::string commandName()
Definition EvtLunda.cc:153
void decay(EvtParticle *p)
Definition EvtLunda.cc:169
void ExclusiveDecay(EvtParticle *p)
Definition EvtLunda.cc:485
virtual ~EvtLunda()
Definition EvtLunda.cc:88
void command(std::string cmd)
Definition EvtLunda.cc:155
EvtDecayBase * clone()
Definition EvtLunda.cc:121
void init()
Definition EvtLunda.cc:125
void getName(std::string &name)
Definition EvtLunda.cc:119
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 double getMass(EvtId i)
Definition EvtPDL.hh:44
static EvtId getId(const std::string &name)
Definition EvtPDL.cc:272
void setMass(double m)
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
double initializePhaseSpace(int numdaughter, EvtId *daughters, double poleSize=-1., int whichTwo1=0, int whichTwo2=1)
void Set(int i, int j, const EvtComplex &rhoij)
void SetDim(int n)
double get(int i) const
double d3mag() const
void set(int i, double d)