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