00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "EvtGenBase/EvtPatches.hh"
00023 #include "EvtGenBase/EvtPatches.hh"
00024 #include "EvtGenBase/EvtParticle.hh"
00025 #include "EvtGenBase/EvtStringParticle.hh"
00026 #include "EvtGenBase/EvtParityC.hh"
00027 #include "EvtGenBase/EvtDecayTable.hh"
00028 #include "EvtGenBase/EvtPDL.hh"
00029 #include "EvtGenModels/EvtLundCharm.hh"
00030 #include "EvtGenBase/EvtReport.hh"
00031 #include <string>
00032 #include "EvtGenBase/EvtId.hh"
00033 #include <iostream>
00034 #include <iomanip>
00035 #include <fstream>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <stdio.h>
00040 using std::endl;
00041 using std::fstream;
00042 using std::ios;
00043 using std::ofstream;
00044 using std::resetiosflags;
00045 using std::setiosflags;
00046 using std::setw;
00047
00048
00049 int EvtLundCharm::nlundcharmdecays=0;
00050 EvtDecayBasePtr* EvtLundCharm::lundcharmdecays=0;
00051 int EvtLundCharm::ntable=0;
00052
00053 int EvtLundCharm::ncommand=0;
00054 int EvtLundCharm::lcommand=0;
00055 std::string* EvtLundCharm::commands=0;
00056 int EvtLundCharm::nevt=0;
00057
00058 extern "C" {
00059 extern int lucomp_(int* kf);
00060 }
00061
00062
00063 extern "C" {
00064 extern void lundcrm_(int *, int *,float *,int *,int *,int *,
00065 double *,double *,double *,double *, int *);
00066 }
00067
00068 extern "C" {
00069 extern void lugive_(const char *cnfgstr,int length);
00070 }
00071
00072 EvtLundCharm::EvtLundCharm(){}
00073
00074 EvtLundCharm::~EvtLundCharm(){
00075
00076
00077 int i;
00078
00079
00080
00081
00082 if (nlundcharmdecays==0) {
00083 delete [] commands;
00084 commands=0;
00085 return;
00086 }
00087
00088 for(i=0;i<nlundcharmdecays;i++){
00089 if (lundcharmdecays[i]==this){
00090 lundcharmdecays[i]=lundcharmdecays[nlundcharmdecays-1];
00091 nlundcharmdecays--;
00092 if (nlundcharmdecays==0) {
00093 delete [] commands;
00094 commands=0;
00095 }
00096 return;
00097 }
00098 }
00099
00100 report(ERROR,"EvtGen") << "Error in destroying LundCharm model!"<<endl;
00101
00102 }
00103
00104
00105 void EvtLundCharm::getName(std::string& model_name){
00106
00107 model_name="LUNDCHARM";
00108
00109 }
00110
00111 EvtDecayBase* EvtLundCharm::clone(){
00112
00113 return new EvtLundCharm;
00114
00115 }
00116
00117
00118 void EvtLundCharm::initProbMax(){
00119
00120 noProbMax();
00121
00122 }
00123
00124
00125 void EvtLundCharm::init(){
00126
00127
00128 parityC::readParityC();
00129
00130 if (getParentId().isAlias()){
00131
00132 report(ERROR,"EvtGen") << "EvtLundCharm finds that you are decaying the"<<endl
00133 << " aliased particle "
00134 << EvtPDL::name(getParentId()).c_str()
00135 << " with the LundCharm model"<<endl
00136 << " this does not work, please modify decay table."
00137 << endl;
00138 report(ERROR,"EvtGen") << "Will terminate execution!"<<endl;
00139 ::abort();
00140
00141 }
00142
00143 store(this);
00144
00145 }
00146
00147
00148 std::string EvtLundCharm::commandName(){
00149
00150 return std::string("LundCharmPar");
00151
00152 }
00153
00154 void EvtLundCharm::command(std::string cmd){
00155
00156 if (ncommand==lcommand){
00157
00158 lcommand=10+2*lcommand;
00159
00160 std::string* newcommands=new std::string[lcommand];
00161
00162 int i;
00163
00164 for(i=0;i<ncommand;i++){
00165 newcommands[i]=commands[i];
00166 }
00167
00168 delete [] commands;
00169
00170 commands=newcommands;
00171
00172 }
00173
00174 commands[ncommand]=cmd;
00175
00176 ncommand++;
00177
00178
00179 }
00180
00181
00182
00183 void EvtLundCharm::decay( EvtParticle *p){
00184
00185 static int iniflag=0;
00186
00187 static EvtId STRNG=EvtPDL::getId("string");
00188
00189 int istdheppar=EvtPDL::getStdHep(p->getId());
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 if(istdheppar != 443 && istdheppar != 100443 && istdheppar != 10441 &&istdheppar != 20443 &&istdheppar != 445 &&istdheppar != 10443 &&istdheppar != 441 &&istdheppar!= 30443){
00203 std::cout<<"EvtGen: EvtLundCharm cann't not decay the particle pid= "<<istdheppar<<endl;
00204 ::abort();
00205 }
00206
00207 double mp=p->mass();
00208 float xmp=mp;
00209 double totEn=0;
00210
00211
00212 EvtVector4R p4[20];
00213
00214 int i,more, pflag;;
00215 int ip=EvtPDL::getStdHep(p->getId());
00216 int ndaugjs;
00217 static int kf[100];
00218 EvtId evtnumstable[100],evtnumparton[100];
00219 int stableindex[100],partonindex[100];
00220 int numstable;
00221 int numparton;
00222 static int km[100];
00223 EvtId type[MAX_DAUG];
00224
00225 static double px[100],py[100],pz[100],e[100];
00226 static int myflag;
00227 if (iniflag==0) lundcrm_(&iniflag,&istdheppar,&xmp,&ndaugjs,kf,km,px,py,pz,e, &myflag);
00228 LundcrmInit(0);
00229
00230 if ( p->getNDaug() != 0 ) { p->deleteDaughters(true);}
00231
00232 string name_parent = EvtPDL::name(p->getId());
00233 double parityi=parityC::getC(name_parent);
00234 int count=0;
00235 double totalM=0;
00236 do{
00237
00238 iniflag=iniflag+1;
00239 lundcrm_(&iniflag,&istdheppar,&xmp,&ndaugjs,kf,km,px,py,pz,e, &myflag);
00240
00241
00242 p->setGeneratorFlag(myflag);
00243
00244 numstable=0;
00245 numparton=0;
00246
00247 totEn=0;
00248 double parityf=1;
00249 for(i=0;i<ndaugjs;i++){
00250
00251 totEn +=e[i];
00252 string name_daugi = EvtPDL::name( EvtPDL::evtIdFromStdHep(kf[i]) );
00253 parityf = parityf*parityC::getC(name_daugi);
00254 totalM += EvtPDL::getMeanMass( EvtPDL::evtIdFromStdHep(kf[i]));
00255 if (EvtPDL::evtIdFromStdHep(kf[i])==EvtId(-1,-1)) {
00256 report(ERROR,"EvtGen") << "LundCharm returned particle:"<<kf[i]<<endl;
00257 report(ERROR,"EvtGen") << "This can not be translated to evt number"<<endl;
00258 report(ERROR,"EvtGen") << "and the decay will be rejected!"<<endl;
00259 report(ERROR,"EvtGen") << "The decay was of particle:"<<ip<<endl;
00260
00261 }
00262
00263
00264 if (abs(kf[i])<=6||kf[i]==21){
00265 partonindex[numparton]=i;
00266 evtnumparton[numparton]=EvtPDL::evtIdFromStdHep(kf[i]);
00267 numparton++;
00268 }
00269 else{
00270 stableindex[numstable]=i;
00271 evtnumstable[numstable]=EvtPDL::evtIdFromStdHep(kf[i]);
00272 numstable++;
00273 }
00274
00275
00276
00277
00278
00279
00280 if (px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i]>=e[i]*e[i]){
00281
00282 e[i]=sqrt(px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i])+0.0000000001;
00283
00284 }
00285
00286 p4[i].set(e[i],px[i],py[i],pz[i]);
00287
00288
00289 }
00290
00291 int channel=EvtDecayTable::inChannelList(p->getId(),numstable,evtnumstable);
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 if(parityi!=0 && parityf!=0){
00304 pflag=(parityi!=parityf);
00305 }else{pflag=2;}
00306
00307 bool eck = fabs(xmp-totEn)>0.01;
00308
00309 more=(channel!=-1 || pflag ==1 || eck );
00310
00311
00312
00313
00314
00315
00316
00317 count++;
00318
00319 }while( more && (count<10000) );
00320
00321
00322
00323
00324
00325
00326
00327
00328 if (count>9999) {
00329 report(INFO,"EvtGen") << "Too many loops in EvtLundCharm!!!"<<endl;
00330 report(INFO,"EvtGen") << "Parent:"<<EvtPDL::name(getParentId()).c_str()<<endl;
00331 for(i=0;i<numstable;i++){
00332 report(INFO,"EvtGen") << "Daug("<<i<<")"<<EvtPDL::name(evtnumstable[i]).c_str()<<endl;
00333 }
00334
00335 }
00336
00337
00338
00339 if (numparton==0){
00340
00341 p->makeDaughters(numstable,evtnumstable);
00342 int ndaugFound=0;
00343 for(i=0;i<numstable;i++){
00344 p->getDaug(i)->init(evtnumstable[i],p4[stableindex[i]]);
00345 ndaugFound++;
00346 }
00347 if ( ndaugFound == 0 ) {
00348 report(ERROR,"EvtGen") << "Lundcharm has failed to do a decay ";
00349 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass()<<endl;
00350 assert(0);
00351 }
00352
00353 fixPolarizations(p);
00354
00355 return ;
00356
00357 }
00358 else{
00359
00360
00361
00362 EvtVector4R p4string(0.0,0.0,0.0,0.0);
00363
00364 for(i=0;i<numparton;i++){
00365 p4string+=p4[partonindex[i]];
00366 }
00367
00368 int nprimary=1;
00369 type[0]=STRNG;
00370 for(i=0;i<numstable;i++){
00371 if (km[stableindex[i]]==0){
00372 type[nprimary++]=evtnumstable[i];
00373 }
00374 }
00375
00376 p->makeDaughters(nprimary,type);
00377
00378 p->getDaug(0)->init(STRNG,p4string);
00379
00380 EvtVector4R p4partons[10];
00381
00382 for(i=0;i<numparton;i++){
00383 p4partons[i]=p4[partonindex[i]];
00384 }
00385
00386 ((EvtStringParticle*)p->getDaug(0))->initPartons(numparton,p4partons,evtnumparton);
00387
00388
00389
00390 nprimary=1;
00391
00392 for(i=0;i<numstable;i++){
00393
00394 if (km[stableindex[i]]==0){
00395 p->getDaug(nprimary++)->init(evtnumstable[i],p4[stableindex[i]]);
00396 }
00397 }
00398
00399
00400 int nsecond=0;
00401 for(i=0;i<numstable;i++){
00402 if (km[stableindex[i]]!=0){
00403 type[nsecond++]=evtnumstable[i];
00404 }
00405 }
00406
00407
00408 p->getDaug(0)->makeDaughters(nsecond,type);
00409
00410 EvtVector4R p4stringboost(p4string.get(0),-p4string.get(1),
00411 -p4string.get(2),-p4string.get(3));
00412
00413 nsecond=0;
00414 for(i=0;i<numstable;i++){
00415 if (km[stableindex[i]]!=0){
00416 p4[stableindex[i]]=boostTo(p4[stableindex[i]],p4stringboost);
00417 p->getDaug(0)->getDaug(nsecond)->init(evtnumstable[i],p4[stableindex[i]]);
00418 p->getDaug(0)->getDaug(nsecond)->setDiagonalSpinDensity();
00419 p->getDaug(0)->getDaug(nsecond)->decay();
00420 nsecond++;
00421 }
00422 }
00423
00424 if ( nsecond == 0 ) {
00425 report(ERROR,"EvtGen") << "Jetset has failed to do a decay ";
00426 report(ERROR,"EvtGen") << EvtPDL::name(p->getId()).c_str() << " " << p->mass() <<endl;
00427 assert(0);
00428 }
00429
00430 fixPolarizations(p);
00431
00432 return ;
00433
00434 }
00435
00436 }
00437
00438 void EvtLundCharm::fixPolarizations(EvtParticle *p){
00439
00440
00441
00442 int ndaug=p->getNDaug();
00443
00444 int i;
00445
00446 static EvtId Jpsi=EvtPDL::getId("J/psi");
00447
00448 for(i=0;i<ndaug;i++){
00449 if(p->getDaug(i)->getId()==Jpsi){
00450
00451 EvtSpinDensity rho;
00452
00453 rho.SetDim(3);
00454 rho.Set(0,0,0.5);
00455 rho.Set(0,1,0.0);
00456 rho.Set(0,2,0.0);
00457
00458 rho.Set(1,0,0.0);
00459 rho.Set(1,1,1.0);
00460 rho.Set(1,2,0.0);
00461
00462 rho.Set(2,0,0.0);
00463 rho.Set(2,1,0.0);
00464 rho.Set(2,2,0.5);
00465
00466 EvtVector4R p4Psi=p->getDaug(i)->getP4();
00467
00468 double alpha=atan2(p4Psi.get(2),p4Psi.get(1));
00469 double beta=acos(p4Psi.get(3)/p4Psi.d3mag());
00470
00471
00472 p->getDaug(i)->setSpinDensityForwardHelicityBasis(rho,alpha,beta,0.0);
00473 setDaughterSpinDensity(i);
00474
00475 }
00476 }
00477
00478 }
00479
00480 void EvtLundCharm::store(EvtDecayBase* jsdecay){
00481
00482 if (nlundcharmdecays==ntable){
00483
00484 EvtDecayBasePtr* newlundcharmdecays=new EvtDecayBasePtr[2*ntable+10];
00485 int i;
00486 for(i=0;i<ntable;i++){
00487 newlundcharmdecays[i]=lundcharmdecays[i];
00488 }
00489 ntable=2*ntable+10;
00490 delete [] lundcharmdecays;
00491 lundcharmdecays=newlundcharmdecays;
00492 }
00493
00494 lundcharmdecays[nlundcharmdecays++]=jsdecay;
00495
00496
00497
00498 }
00499
00500 void EvtLundCharm::LundcrmInit(int dummy){
00501
00502 static int first=1;
00503 if (first){
00504
00505 first=0;
00506 for(int i=0;i<ncommand;i++)
00507 lugive_(commands[i].c_str(),strlen(commands[i].c_str()));
00508 }
00509
00510
00511 }