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