00001
00002
00003
00004
00005 #include "HepPDT.h"
00006 #include "gismo/Interactor.h"
00007 #include "facilities/error.h"
00008
00009 #include <fstream>
00010 #include <strstream>
00011
00012 #include <cstring>
00013 #include <cstdio>
00014 #include <cstdlib>
00015
00016 HepPDT::HepPDT(Interactor* emint, Interactor* hadint)
00017 {
00018 if(emint)
00019 addInteractor(emint);
00020 if(hadint)
00021 addInteractor(hadint);
00022
00023 }
00024 static char * fullName(char* name, int charge, int anti=0)
00025 {
00026 static char* cname[]={"--","-","0","+","++"};
00027 static char buf1[20],buf2[20];
00028 static int which=0;
00029 which = ! which;
00030 char * buf = which ? buf1 : buf2;
00031 strcpy(buf,name);
00032 if( anti ) strcat(buf,"~");
00033 if(abs(charge)<3) strcat(buf,cname[charge+2]);
00034 return buf;
00035 }
00036
00037 void
00038 HepPDT::createTheParticles(char* name, long* id,int *charge,float mass, float width)
00039 {
00040
00041 for( int i=0; i< 4 && id[i]>0; i++)
00042 {
00043 unsigned digit[5];
00044 for(long j=0, ii=id[0]; j< 5; j++, ii/=10)
00045 digit[j] = unsigned(ii%10);
00046
00047 enum particleType {gauge, lepton, meson, baryon, diquark} type;
00048
00049 if( digit[3] ) type = id[0]&1 ? diquark: baryon;
00050 else if( digit[2] ) type = meson;
00051 else if( digit[1]==1 ) type = lepton;
00052 else type = gauge;
00053
00054
00055 int spin = digit[0];
00056 switch ( type )
00057 {
00058 case gauge:
00059 if( id[i]==22 ) setInteraction("electromagnetic");
00060 else setInteraction("weak");
00061 addParticle(name, id[i], spin, charge[i], mass, width);
00062 break;
00063
00064 case lepton:
00065 setInteraction("weak");
00066 if( charge[i]==0 )
00067 addParticle(name,id[i],1,0,mass,width);
00068 else
00069 { if( id[i]==11 ) setInteraction("electromagnetic");
00070 addParticle(fullName(name,-1),fullName(name,1),id[i],1,charge[i],mass,width);
00071 }
00072 break;
00073
00074 case meson:
00075 setInteraction("hadronic");
00076 if( charge[i]==0 )
00077 {
00078 if( digit[1]==digit[2])
00079 {
00080 if( digit[1]==1 )
00081 addParticle(fullName(name,0) ,id[i], spin,0, mass,width);
00082 else
00083 addParticle(name ,id[i], spin,0, mass,width);
00084 }
00085 else
00086 {
00087 addParticle(fullName(name,0),fullName(name,0,1),
00088 id[i], spin, charge[i], mass, width);
00089 }
00090 }
00091 else
00092 addParticle(fullName(name,charge[i]),fullName(name,-charge[i]),
00093 id[i], spin, charge[i], mass, width);
00094
00095 break;
00096
00097
00098 case baryon:
00099 setInteraction("hadronic");
00100 spin--;
00101 if( id[i]==2212 || id[i]==2112 )
00102 {
00103 addParticle(name, fullName(name,99,1),
00104 id[i], spin, charge[i], mass, width );
00105 }
00106 else
00107 {
00108 addParticle(fullName(name,charge[i]),fullName(name,-charge[i],1),
00109 id[i], spin, charge[i], mass, width);
00110 }
00111 break;
00112 default:
00113 FATAL(" unexpected particle type in PDT table ");
00114 }
00115 }
00116
00117 }
00118 HepPDT&
00119 HepPDT::readPDGMasses(const char* pdgMassFile)
00120 {
00121 std::ifstream in(pdgMassFile);
00122 if( in.bad() )
00123 {
00124 std::ostrstream error;
00125 error << "could not open pdg mass file: " << pdgMassFile << '\0';
00126 FATAL(error.str());
00127 }
00128 HepPDT& ret = readPDGMasses(in);
00129 in.close();
00130 return ret;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 HepPDT&
00144 HepPDT::readPDGMasses(std::istream& in)
00145 {
00146 for(;;)
00147 {
00148 char buf[82];
00149 long id[4];
00150 int charge[4];
00151 float mass = -1.0;
00152 char name[16];
00153 char lastLine = buf[0];
00154
00155 in.getline(buf,sizeof(buf));
00156 if( in.bad() )
00157 FATAL("file error, reading from pdg mass file");
00158 if( lastLine=='M')
00159 {
00160 float width = (!in.eof() && buf[0]=='W') ? atof(buf+26) : 0;
00161 createTheParticles(name,id,charge,mass,width);
00162 }
00163 if (in.eof() ) break;
00164
00165 if( buf[0]=='M' )
00166 {
00167 id[0] = atol(buf+2);
00168 id[1] = buf[12]!=' '? atol(buf+8) : 0;
00169 id[2] = buf[18]!=' '? atol(buf+14): 0;
00170 id[3] = buf[24]!=' '? atol(buf+20): 0;
00171 mass = atof(buf+26);
00172
00173
00174 char chargeList[9];
00175 sscanf(buf+59,"%15s %8s",name,chargeList);
00176
00177
00178
00179 int* ch = charge;
00180 for(char* token = strtok(chargeList, ",");
00181 token;
00182 token = strtok(0, ","))
00183 {
00184 if( strcmp(token,"0")==0 )
00185 *ch++ = 0;
00186 else if (strcmp(token,"+")==0)
00187 *ch++ = 1;
00188 else if (strcmp(token,"-")==0)
00189 *ch++ = -1;
00190 else if (strcmp(token,"++")==0)
00191 *ch++ = 2;
00192 else
00193 WARNING("bad charge found");
00194 }
00195 }
00196 }
00197 return *this;
00198 }
00199
00200
00201