/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/BesEvtGen/BesEvtGen-00-03-58/src/EvtGen/EvtGenModels/EvtLundCharm.cc

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------  
00002 //   
00003 // Environment:  
00004 //      This software is part of models developed at BES collaboration  
00005 //      based on the EvtGen framework.  If you use all or part  
00006 //      of it, please give an appropriate acknowledgement.  
00007 //        
00008 // Copyright Information: See EvtGen/BesCopyright  
00009 //      Copyright (A) 2006      Ping Rong-Gang, Pang Cai-Ying@IHEP  
00010 //        
00011 // Module: EvtLundCharm.cc
00012 //         the necessary file: jetset74.F,lund_crm1_evtgen.F
00013 //                             fist.inc,gen.inc  mix.inc  stdhep.inc
00014 // Description: Modified Lund model at tau-charm energy level, see
00015 //               PHYSICAL REVIEW D, VOLUME 62, 034003
00016 // Modification history:
00017 //   
00018 //   Ping R.-G.    Octo., 2007       Module created    
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   //the deletion of commands is really uggly!
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 //  checkNArg(1);
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   if (pycomp_(&istdheppar)==0){
00193     report(ERROR,"EvtGen") << "LundCharm can not decay:"
00194       <<EvtPDL::name(p->getId()).c_str()<<endl;
00195     return;
00196   }
00197 */
00198 
00199 //  std::cout<<"Lundcharm decaying "<<EvtPDL::name(p->getId())<<" mass: "<<p->getP4().mass()<<std::endl;
00200 
00201 // no eta_c(2S) in jetset74, so we don't include it in lundcharm
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 //  std::cout<<"float xmp="<<xmp<<std::endl;
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); // Allow user to set LundCharmPar in decay list
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     //report(INFO,"EvtGen") << "calling lundcharm " << ip<< " " << mp <<endl;
00238     iniflag=iniflag+1;  //to count the event number
00239     lundcrm_(&iniflag,&istdheppar,&xmp,&ndaugjs,kf,km,px,py,pz,e, &myflag);
00240     //-- change myflag to unsigned int
00241 
00242     p->setGeneratorFlag(myflag);
00243     // std::cout<<"EvtLundCharm::setGeneratorFalg= "<<myflag<<std::endl; 
00244     numstable=0;
00245     numparton=0;
00246     //report(INFO,"EvtGen") << "found some daughters " << ndaugjs << endl;
00247     totEn=0;    
00248     double parityf=1;
00249     for(i=0;i<ndaugjs;i++){
00250       //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
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       //sort out the partons
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       // have to protect against negative mass^2 for massless particles
00277       // i.e. neutrinos and photons.
00278       // this is uggly but I need to fix it right now....
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     // Test the branching fraction of lundcharm
00294     // the specified decay mode is put as the 0-th channel with specifing mother particle
00295     /*
00296     if(ip==100443 && channel==0){
00297       nevt++;
00298       std::cout<<"nevt= "<<nevt<<std::endl;
00299       channel=-1;
00300     }
00301     */
00302     // std::cout<<"channel= "<<channel<<std::endl;
00303    if(parityi!=0 && parityf!=0){
00304       pflag=(parityi!=parityf);
00305    }else{pflag=2;}
00306 
00307     bool eck = fabs(xmp-totEn)>0.01;
00308       // std::cout<<"eck= "<<eck<<", "<<fabs(xmp-totEn)<<std::endl;
00309     more=(channel!=-1 || pflag ==1 || eck );
00310   // more=(channel!=-1);
00311 
00312     //---debugging
00313     //std::cout<<"parentId= "<<istdheppar<<", pflag= "<<pflag<<std::endl;
00314     //if(pflag==1) abort();
00315 
00316 
00317   count++;
00318 
00319   }while( more && (count<10000) );
00320 
00321   /*
00322   if(fabs(xmp-totEn)>0.01){ 
00323     std::cout<<"Warning:LUNDCHARM generate incomplet final state, "<<mp<<" "<<totEn<<endl;
00324     ::abort();
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     //have partons in LUNDCHARM
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   //special case for now to handle the J/psi polarization
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 }

Generated on Tue Nov 29 23:12:20 2016 for BOSS_7.0.2 by  doxygen 1.4.7