BOSS 7.0.8
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[50];
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 double totalM=0;
236 do{
237 //report(INFO,"EvtGen") << "calling lundcharm " << ip<< " " << mp <<endl;
238 iniflag=iniflag+1; //to count the event number
239 lundcrm_(&iniflag,&istdheppar,&xmp,&ndaugjs,kf,km,px,py,pz,e, &myflag);
240 //-- change myflag to unsigned int
241
242 p->setGeneratorFlag(myflag);
243 // std::cout<<"EvtLundCharm::setGeneratorFalg= "<<myflag<<std::endl;
244 numstable=0;
245 numparton=0;
246 //report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
247 totEn=0;
248 double parityf=1;
249 for(i=0;i<ndaugjs;i++){
250 //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
251 totEn +=e[i];
252 string name_daugi = EvtPDL::name( EvtPDL::evtIdFromStdHep(kf[i]) );
253 parityf = parityf*parityC::getC(name_daugi);
255 if (EvtPDL::evtIdFromStdHep(kf[i])==EvtId(-1,-1)) {
256 report(ERROR,"EvtGen") << "LundCharm returned particle:"<<kf[i]<<endl;
257 report(ERROR,"EvtGen") << "This can not be translated to evt number"<<endl;
258 report(ERROR,"EvtGen") << "and the decay will be rejected!"<<endl;
259 report(ERROR,"EvtGen") << "The decay was of particle:"<<ip<<endl;
260
261 }
262
263 //sort out the partons
264 if (abs(kf[i])<=6||kf[i]==21){
265 partonindex[numparton]=i;
266 evtnumparton[numparton]=EvtPDL::evtIdFromStdHep(kf[i]);
267 numparton++;
268 }
269 else{
270 stableindex[numstable]=i;
271 evtnumstable[numstable]=EvtPDL::evtIdFromStdHep(kf[i]);
272 numstable++;
273 }
274
275
276 // have to protect against negative mass^2 for massless particles
277 // i.e. neutrinos and photons.
278 // this is uggly but I need to fix it right now....
279
280 if (px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i]>=e[i]*e[i]){
281
282 e[i]=sqrt(px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i])+0.0000000001;
283
284 }
285
286 p4[i].set(e[i],px[i],py[i],pz[i]);
287
288
289 }
290
291 int channel=EvtDecayTable::inChannelList(p->getId(),numstable,evtnumstable);
292
293 // Test the branching fraction of lundcharm
294 // the specified decay mode is put as the 0-th channel with specifing mother particle
295 /*
296 if(ip==100443 && channel==0){
297 nevt++;
298 std::cout<<"nevt= "<<nevt<<std::endl;
299 channel=-1;
300 }
301 */
302 // std::cout<<"channel= "<<channel<<std::endl;
303 if(parityi!=0 && parityf!=0){
304 pflag=(parityi!=parityf);
305 }else{pflag=2;}
306
307 bool eck = fabs(xmp-totEn)>0.01;
308 // std::cout<<"eck= "<<eck<<", "<<fabs(xmp-totEn)<<std::endl;
309 more=(channel!=-1 || pflag ==1 || eck );
310 // more=(channel!=-1);
311
312 //---debugging
313 //std::cout<<"parentId= "<<istdheppar<<", pflag= "<<pflag<<std::endl;
314 //if(pflag==1) abort();
315
316
317 count++;
318
319 }while( more && (count<10000) );
320
321 /*
322 if(fabs(xmp-totEn)>0.01){
323 std::cout<<"Warning:LUNDCHARM generate incomplet final state, "<<mp<<" "<<totEn<<endl;
324 ::abort();
325 }
326 */
327
328 if (count>9999) {
329 report(INFO,"EvtGen") << "Too many loops in EvtLundCharm!!!"<<endl;
330 report(INFO,"EvtGen") << "Parent:"<<EvtPDL::name(getParentId()).c_str()<<endl;
331 for(i=0;i<numstable;i++){
332 report(INFO,"EvtGen") << "Daug("<<i<<")"<<EvtPDL::name(evtnumstable[i]).c_str()<<endl;
333 }
334
335 }
336
337
338
339 if (numparton==0){
340
341 p->makeDaughters(numstable,evtnumstable);
342 int ndaugFound=0;
343 for(i=0;i<numstable;i++){
344 p->getDaug(i)->init(evtnumstable[i],p4[stableindex[i]]);
345 ndaugFound++;
346 }
347 if ( ndaugFound == 0 ) {
348 report(ERROR,"EvtGen") << "Lundcharm has failed to do a decay ";
349 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass()<<endl;
350 assert(0);
351 }
352
353 fixPolarizations(p);
354
355 return ;
356
357 }
358 else{
359
360 //have partons in LUNDCHARM
361
362 EvtVector4R p4string(0.0,0.0,0.0,0.0);
363
364 for(i=0;i<numparton;i++){
365 p4string+=p4[partonindex[i]];
366 }
367
368 int nprimary=1;
369 type[0]=STRNG;
370 for(i=0;i<numstable;i++){
371 if (km[stableindex[i]]==0){
372 type[nprimary++]=evtnumstable[i];
373 }
374 }
375
376 p->makeDaughters(nprimary,type);
377
378 p->getDaug(0)->init(STRNG,p4string);
379
380 EvtVector4R p4partons[10];
381
382 for(i=0;i<numparton;i++){
383 p4partons[i]=p4[partonindex[i]];
384 }
385
386 ((EvtStringParticle*)p->getDaug(0))->initPartons(numparton,p4partons,evtnumparton);
387
388
389
390 nprimary=1;
391
392 for(i=0;i<numstable;i++){
393
394 if (km[stableindex[i]]==0){
395 p->getDaug(nprimary++)->init(evtnumstable[i],p4[stableindex[i]]);
396 }
397 }
398
399
400 int nsecond=0;
401 for(i=0;i<numstable;i++){
402 if (km[stableindex[i]]!=0){
403 type[nsecond++]=evtnumstable[i];
404 }
405 }
406
407
408 p->getDaug(0)->makeDaughters(nsecond,type);
409
410 EvtVector4R p4stringboost(p4string.get(0),-p4string.get(1),
411 -p4string.get(2),-p4string.get(3));
412
413 nsecond=0;
414 for(i=0;i<numstable;i++){
415 if (km[stableindex[i]]!=0){
416 p4[stableindex[i]]=boostTo(p4[stableindex[i]],p4stringboost);
417 p->getDaug(0)->getDaug(nsecond)->init(evtnumstable[i],p4[stableindex[i]]);
418 p->getDaug(0)->getDaug(nsecond)->setDiagonalSpinDensity();
419 p->getDaug(0)->getDaug(nsecond)->decay();
420 nsecond++;
421 }
422 }
423
424 if ( nsecond == 0 ) {
425 report(ERROR,"EvtGen") << "Jetset has failed to do a decay ";
426 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass() <<endl;
427 assert(0);
428 }
429
430 fixPolarizations(p);
431
432 return ;
433
434 }
435
436}
437
438void EvtLundCharm::fixPolarizations(EvtParticle *p){
439
440 //special case for now to handle the J/psi polarization
441
442 int ndaug=p->getNDaug();
443
444 int i;
445
446 static EvtId Jpsi=EvtPDL::getId("J/psi");
447
448 for(i=0;i<ndaug;i++){
449 if(p->getDaug(i)->getId()==Jpsi){
450
451 EvtSpinDensity rho;
452
453 rho.SetDim(3);
454 rho.Set(0,0,0.5);
455 rho.Set(0,1,0.0);
456 rho.Set(0,2,0.0);
457
458 rho.Set(1,0,0.0);
459 rho.Set(1,1,1.0);
460 rho.Set(1,2,0.0);
461
462 rho.Set(2,0,0.0);
463 rho.Set(2,1,0.0);
464 rho.Set(2,2,0.5);
465
466 EvtVector4R p4Psi=p->getDaug(i)->getP4();
467
468 double alpha=atan2(p4Psi.get(2),p4Psi.get(1));
469 double beta=acos(p4Psi.get(3)/p4Psi.d3mag());
470
471
474
475 }
476 }
477
478}
479
480void EvtLundCharm::store(EvtDecayBase* jsdecay){
481
482 if (nlundcharmdecays==ntable){
483
484 EvtDecayBasePtr* newlundcharmdecays=new EvtDecayBasePtr[2*ntable+10];
485 int i;
486 for(i=0;i<ntable;i++){
487 newlundcharmdecays[i]=lundcharmdecays[i];
488 }
489 ntable=2*ntable+10;
490 delete [] lundcharmdecays;
491 lundcharmdecays=newlundcharmdecays;
492 }
493
494 lundcharmdecays[nlundcharmdecays++]=jsdecay;
495
496
497
498}
499
501
502 static int first=1;
503 if (first){
504
505 first=0;
506 for(int i=0;i<ncommand;i++)
507 lugive_(commands[i].c_str(),strlen(commands[i].c_str()));
508 }
509
510
511}
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
Definition: EvtParticle.hh:38
DOUBLE_PRECISION count[3]
ostream & report(Severity severity, const char *facility)
Definition: EvtReport.cc:36
@ ERROR
Definition: EvtReport.hh:49
@ INFO
Definition: EvtReport.hh:52
const double alpha
void noProbMax()
EvtId getParentId()
Definition: EvtDecayBase.hh:60
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 initProbMax()
void command(std::string cmd)
void decay(EvtParticle *p)
virtual ~EvtLundCharm()
Definition: EvtLundCharm.cc:74
static int getStdHep(EvtId id)
Definition: EvtPDL.hh:56
static double getMeanMass(EvtId i)
Definition: EvtPDL.hh:45
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)
Definition: EvtParticle.cc:178
void makeDaughters(int ndaug, EvtId *id)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
void decay()
Definition: EvtParticle.cc:404
EvtId getId() const
Definition: EvtParticle.cc:113
void setGeneratorFlag(int flag)
Definition: EvtParticle.hh:141
void setDiagonalSpinDensity()
Definition: EvtParticle.cc:133
const EvtVector4R & getP4() const
Definition: EvtParticle.cc:121
int getNDaug() const
Definition: EvtParticle.cc:125
EvtParticle * getDaug(int i)
Definition: EvtParticle.cc:85
void deleteDaughters(bool keepChannel=false)
Definition: EvtParticle.cc:540
double mass() const
Definition: EvtParticle.cc:127
void Set(int i, int j, const EvtComplex &rhoij)
void SetDim(int n)
double get(int i) const
Definition: EvtVector4R.hh:179
double d3mag() const
Definition: EvtVector4R.cc:186
void set(int i, double d)
Definition: EvtVector4R.hh:183
static void readParityC()
Definition: EvtParityC.cc:6
static double getC(string parname)
Definition: EvtParityC.cc:26
const double mp
Definition: incllambda.cxx:45