BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtLundCharm.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, Pang Cai-Ying@IHEP
10//
11// Module: EvtLundCharm.cc
12// the necessary file: jetset74.F,lund_crm1_evtgen.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. Octo., 2007 Module created
19//
20//------------------------------------------------------------------------
21//
22#include "EvtLundCharm.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 EvtLundCharm::nlundcharmdecays = 0;
48EvtDecayBasePtr* EvtLundCharm::lundcharmdecays = 0;
49int EvtLundCharm::ntable = 0;
50
51int EvtLundCharm::ncommand = 0;
52int EvtLundCharm::lcommand = 0;
53std::string* EvtLundCharm::commands = 0;
54int EvtLundCharm::nevt = 0;
55
56extern "C" {
57extern int lucomp_( int* kf );
58}
59
60extern "C" {
61extern void lundcrm_( int*, int*, float*, int*, int*, int*, double*, double*, double*, double*,
62 int* );
63}
64
65extern "C" {
66extern void lugive_( const char* cnfgstr, int length );
67}
68
70
72
73 int i;
74
75 // the deletion of commands is really uggly!
76
77 if ( nlundcharmdecays == 0 )
78 {
79 delete[] commands;
80 commands = 0;
81 return;
82 }
83
84 for ( i = 0; i < nlundcharmdecays; i++ )
85 {
86 if ( lundcharmdecays[i] == this )
87 {
88 lundcharmdecays[i] = lundcharmdecays[nlundcharmdecays - 1];
89 nlundcharmdecays--;
90 if ( nlundcharmdecays == 0 )
91 {
92 delete[] commands;
93 commands = 0;
94 }
95 return;
96 }
97 }
98
99 report( ERROR, "EvtGen" ) << "Error in destroying LundCharm model!" << endl;
100}
101
102void EvtLundCharm::getName( std::string& model_name ) { model_name = "LUNDCHARM"; }
103
105
107
109
110 // checkNArg(1);
112
113 if ( getParentId().isAlias() )
114 {
115
116 report( ERROR, "EvtGen" ) << "EvtLundCharm finds that you are decaying the" << endl
117 << " aliased particle " << EvtPDL::name( getParentId() ).c_str()
118 << " with the LundCharm model" << endl
119 << " this does not work, please modify decay table." << endl;
120 report( ERROR, "EvtGen" ) << "Will terminate execution!" << endl;
121 ::abort();
122 }
123
124 store( this );
125}
126
127std::string EvtLundCharm::commandName() { return std::string( "LundCharmPar" ); }
128
129void EvtLundCharm::command( std::string cmd ) {
130
131 if ( ncommand == lcommand )
132 {
133
134 lcommand = 10 + 2 * lcommand;
135
136 std::string* newcommands = new std::string[lcommand];
137
138 int i;
139
140 for ( i = 0; i < ncommand; i++ ) { newcommands[i] = commands[i]; }
141
142 delete[] commands;
143
144 commands = newcommands;
145 }
146
147 commands[ncommand] = cmd;
148
149 ncommand++;
150}
151
153
154 static int iniflag = 0;
155
156 static EvtId STRNG = EvtPDL::getId( "string" );
157
158 int istdheppar = EvtPDL::getStdHep( p->getId() );
159
160 /*
161 if (pycomp_(&istdheppar)==0){
162 report(ERROR,"EvtGen") << "LundCharm can not decay:"
163 <<EvtPDL::name(p->getId()).c_str()<<endl;
164 return;
165 }
166 */
167
168 // std::cout<<"Lundcharm decaying "<<EvtPDL::name(p->getId())<<" mass:
169 // "<<p->getP4().mass()<<std::endl;
170
171 // no eta_c(2S) in jetset74, so we don't include it in lundcharm
172 if ( istdheppar != 443 && istdheppar != 100443 && istdheppar != 10441 &&
173 istdheppar != 20443 && istdheppar != 445 && istdheppar != 10443 && istdheppar != 441 &&
174 istdheppar != 30443 )
175 {
176 std::cout << "EvtGen: EvtLundCharm cann't not decay the particle pid= " << istdheppar
177 << endl;
178 ::abort();
179 }
180
181 double mp = p->mass();
182 float xmp = mp;
183 double totEn = 0;
184 // std::cout<<"float xmp="<<xmp<<std::endl;
185
186 EvtVector4R p4[50];
187
188 int i, more, pflag;
189 ;
190 int ip = EvtPDL::getStdHep( p->getId() );
191 int ndaugjs;
192 static int kf[100];
193 EvtId evtnumstable[100], evtnumparton[100];
194 int stableindex[100], partonindex[100];
195 int numstable;
196 int numparton;
197 static int km[100];
199
200 static double px[100], py[100], pz[100], e[100];
201 static int myflag;
202 if ( iniflag == 0 )
203 lundcrm_( &iniflag, &istdheppar, &xmp, &ndaugjs, kf, km, px, py, pz, e, &myflag );
204 LundcrmInit( 0 ); // Allow user to set LundCharmPar in decay list
205
206 if ( p->getNDaug() != 0 ) { p->deleteDaughters( true ); }
207
208 string name_parent = EvtPDL::name( p->getId() );
209 double parityi = parityC::getC( name_parent );
210 int count = 0;
211 double totalM = 0;
212 do {
213 // report(INFO,"EvtGen") << "calling lundcharm " << ip<< " " << mp <<endl;
214 iniflag = iniflag + 1; // to count the event number
215 lundcrm_( &iniflag, &istdheppar, &xmp, &ndaugjs, kf, km, px, py, pz, e, &myflag );
216 //-- change myflag to unsigned int
217
218 p->setGeneratorFlag( myflag );
219 // std::cout<<"EvtLundCharm::setGeneratorFalg= "<<myflag<<std::endl;
220 numstable = 0;
221 numparton = 0;
222 // report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
223 totEn = 0;
224 double parityf = 1;
225 for ( i = 0; i < ndaugjs; i++ )
226 {
227 // std::cout<<"ndaugjs,kf,km,px,py,pz,e: "<<i<<", "<<km[i]<<", "<<kf[i]<<", "<<px[i]<<"
228 // ,"<<py[i]<<", "<<pz[i]<<", "<<e[i]<<std::endl; //for debugging
229 totEn += e[i];
230 string name_daugi = EvtPDL::name( EvtPDL::evtIdFromStdHep( kf[i] ) );
231 parityf = parityf * parityC::getC( name_daugi );
232 totalM += EvtPDL::getMeanMass( EvtPDL::evtIdFromStdHep( kf[i] ) );
233 if ( EvtPDL::evtIdFromStdHep( kf[i] ) == EvtId( -1, -1 ) )
234 {
235 report( ERROR, "EvtGen" ) << "LundCharm returned particle:" << kf[i] << endl;
236 report( ERROR, "EvtGen" ) << "This can not be translated to evt number" << endl;
237 report( ERROR, "EvtGen" ) << "and the decay will be rejected!" << endl;
238 report( ERROR, "EvtGen" ) << "The decay was of particle:" << ip << endl;
239 }
240
241 // sort out the partons
242 if ( abs( kf[i] ) <= 6 || kf[i] == 21 )
243 {
244 partonindex[numparton] = i;
245 evtnumparton[numparton] = EvtPDL::evtIdFromStdHep( kf[i] );
246 numparton++;
247 }
248 else
249 {
250 stableindex[numstable] = i;
251 evtnumstable[numstable] = EvtPDL::evtIdFromStdHep( kf[i] );
252 numstable++;
253 }
254
255 // have to protect against negative mass^2 for massless particles
256 // i.e. neutrinos and photons.
257 // this is uggly but I need to fix it right now....
258
259 if ( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] >= e[i] * e[i] )
260 { e[i] = sqrt( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] ) + 0.0000000001; }
261
262 p4[i].set( e[i], px[i], py[i], pz[i] );
263 }
264
265 int channel = EvtDecayTable::inChannelList( p->getId(), numstable, evtnumstable );
266
267 // Test the branching fraction of lundcharm
268 // the specified decay mode is put as the 0-th channel with specifing mother particle
269 /*
270 if(ip==100443 && channel==0){
271 nevt++;
272 std::cout<<"nevt= "<<nevt<<std::endl;
273 channel=-1;
274 }
275 */
276 // std::cout<<"channel= "<<channel<<std::endl;
277 if ( parityi != 0 && parityf != 0 ) { pflag = ( parityi != parityf ); }
278 else { pflag = 2; }
279
280 bool eck = fabs( xmp - totEn ) > 0.01;
281 // std::cout<<"eck= "<<eck<<", "<<fabs(xmp-totEn)<<std::endl;
282 more = ( channel != -1 || pflag == 1 || eck );
283 // more=(channel!=-1);
284
285 //---debugging
286 // std::cout<<"parentId= "<<istdheppar<<", pflag= "<<pflag<<std::endl;
287 // if(pflag==1) abort();
288
289 count++;
290
291 } while ( more && ( count < 10000 ) );
292
293 /*
294 if(fabs(xmp-totEn)>0.01){
295 std::cout<<"Warning:LUNDCHARM generate incomplet final state, "<<mp<<" "<<totEn<<endl;
296 ::abort();
297 }
298 */
299
300 if ( count > 9999 )
301 {
302 report( INFO, "EvtGen" ) << "Too many loops in EvtLundCharm!!!" << endl;
303 report( INFO, "EvtGen" ) << "Parent:" << EvtPDL::name( getParentId() ).c_str() << endl;
304 for ( i = 0; i < numstable; i++ )
305 {
306 report( INFO, "EvtGen" ) << "Daug(" << i << ")"
307 << EvtPDL::name( evtnumstable[i] ).c_str() << endl;
308 }
309 }
310
311 if ( numparton == 0 )
312 {
313
314 p->makeDaughters( numstable, evtnumstable );
315 int ndaugFound = 0;
316 for ( i = 0; i < numstable; i++ )
317 {
318 p->getDaug( i )->init( evtnumstable[i], p4[stableindex[i]] );
319 ndaugFound++;
320 }
321 if ( ndaugFound == 0 )
322 {
323 report( ERROR, "EvtGen" ) << "Lundcharm has failed to do a decay ";
324 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
325 << endl;
326 assert( 0 );
327 }
328
329 fixPolarizations( p );
330
331 return;
332 }
333 else
334 {
335
336 // have partons in LUNDCHARM
337
338 EvtVector4R p4string( 0.0, 0.0, 0.0, 0.0 );
339
340 for ( i = 0; i < numparton; i++ ) { p4string += p4[partonindex[i]]; }
341
342 int nprimary = 1;
343 type[0] = STRNG;
344 for ( i = 0; i < numstable; i++ )
345 {
346 if ( km[stableindex[i]] == 0 ) { type[nprimary++] = evtnumstable[i]; }
347 }
348
349 p->makeDaughters( nprimary, type );
350
351 p->getDaug( 0 )->init( STRNG, p4string );
352
353 EvtVector4R p4partons[10];
354
355 for ( i = 0; i < numparton; i++ ) { p4partons[i] = p4[partonindex[i]]; }
356
357 ( (EvtStringParticle*)p->getDaug( 0 ) )->initPartons( numparton, p4partons, evtnumparton );
358
359 nprimary = 1;
360
361 for ( i = 0; i < numstable; i++ )
362 {
363
364 if ( km[stableindex[i]] == 0 )
365 { p->getDaug( nprimary++ )->init( evtnumstable[i], p4[stableindex[i]] ); }
366 }
367
368 int nsecond = 0;
369 for ( i = 0; i < numstable; i++ )
370 {
371 if ( km[stableindex[i]] != 0 ) { type[nsecond++] = evtnumstable[i]; }
372 }
373
374 p->getDaug( 0 )->makeDaughters( nsecond, type );
375
376 EvtVector4R p4stringboost( p4string.get( 0 ), -p4string.get( 1 ), -p4string.get( 2 ),
377 -p4string.get( 3 ) );
378
379 nsecond = 0;
380 for ( i = 0; i < numstable; i++ )
381 {
382 if ( km[stableindex[i]] != 0 )
383 {
384 p4[stableindex[i]] = boostTo( p4[stableindex[i]], p4stringboost );
385 p->getDaug( 0 )->getDaug( nsecond )->init( evtnumstable[i], p4[stableindex[i]] );
386 p->getDaug( 0 )->getDaug( nsecond )->setDiagonalSpinDensity();
387 p->getDaug( 0 )->getDaug( nsecond )->decay();
388 nsecond++;
389 }
390 }
391
392 if ( nsecond == 0 )
393 {
394 report( ERROR, "EvtGen" ) << "Jetset has failed to do a decay ";
395 report( ERROR, "EvtGen" ) << EvtPDL::name( p->getId() ).c_str() << " " << p->mass()
396 << endl;
397 assert( 0 );
398 }
399
400 fixPolarizations( p );
401
402 return;
403 }
404}
405
406void EvtLundCharm::fixPolarizations( EvtParticle* p ) {
407
408 // special case for now to handle the J/psi polarization
409
410 int ndaug = p->getNDaug();
411
412 int i;
413
414 static EvtId Jpsi = EvtPDL::getId( "J/psi" );
415
416 for ( i = 0; i < ndaug; i++ )
417 {
418 if ( p->getDaug( i )->getId() == Jpsi )
419 {
420
421 EvtSpinDensity rho;
422
423 rho.SetDim( 3 );
424 rho.Set( 0, 0, 0.5 );
425 rho.Set( 0, 1, 0.0 );
426 rho.Set( 0, 2, 0.0 );
427
428 rho.Set( 1, 0, 0.0 );
429 rho.Set( 1, 1, 1.0 );
430 rho.Set( 1, 2, 0.0 );
431
432 rho.Set( 2, 0, 0.0 );
433 rho.Set( 2, 1, 0.0 );
434 rho.Set( 2, 2, 0.5 );
435
436 EvtVector4R p4Psi = p->getDaug( i )->getP4();
437
438 double alpha = atan2( p4Psi.get( 2 ), p4Psi.get( 1 ) );
439 double beta = acos( p4Psi.get( 3 ) / p4Psi.d3mag() );
440
441 p->getDaug( i )->setSpinDensityForwardHelicityBasis( rho, alpha, beta, 0.0 );
443 }
444 }
445}
446
447void EvtLundCharm::store( EvtDecayBase* jsdecay ) {
448
449 if ( nlundcharmdecays == ntable )
450 {
451
452 EvtDecayBasePtr* newlundcharmdecays = new EvtDecayBasePtr[2 * ntable + 10];
453 int i;
454 for ( i = 0; i < ntable; i++ ) { newlundcharmdecays[i] = lundcharmdecays[i]; }
455 ntable = 2 * ntable + 10;
456 delete[] lundcharmdecays;
457 lundcharmdecays = newlundcharmdecays;
458 }
459
460 lundcharmdecays[nlundcharmdecays++] = jsdecay;
461}
462
463void EvtLundCharm::LundcrmInit( int dummy ) {
464
465 static int first = 1;
466 if ( first )
467 {
468
469 first = 0;
470 for ( int i = 0; i < ncommand; i++ )
471 lugive_( commands[i].c_str(), strlen( commands[i].c_str() ) );
472 }
473}
EvtDecayBase * EvtDecayBasePtr
EvtDiracSpinor boostTo(const EvtDiracSpinor &sp, const EvtVector4R p4)
void lugive_(const char *cnfgstr, int length)
void lugive_(const char *cnfgstr, int length)
int lucomp_(int *kf)
void lundcrm_(int *, int *, float *, int *, int *, int *, double *, double *, double *, double *, int *)
EvtDecayBase * EvtDecayBasePtr
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
EvtId getParentId()
void setDaughterSpinDensity(int daughter)
static int inChannelList(EvtId parent, int ndaug, EvtId *daugs)
Definition EvtId.hh:27
std::string commandName()
static void LundcrmInit(int f)
void getName(std::string &name)
EvtDecayBase * clone()
void command(std::string cmd)
void decay(EvtParticle *p)
virtual ~EvtLundCharm()
static int getStdHep(EvtId id)
Definition EvtPDL.hh:61
static double getMeanMass(EvtId i)
Definition EvtPDL.hh:43
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 setGeneratorFlag(int flag)
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)
double get(int i) const
double d3mag() const
void set(int i, double d)
static void readParityC()
Definition EvtParityC.cc:5
static double getC(string parname)
Definition EvtParityC.cc:30