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