00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <string>
00011 #include <algorithm>
00012 #include <iostream>
00013 #include <sstream>
00014
00015 #include "HepPDT/defs.h"
00016 #include "HepPDT/TableBuilder.hh"
00017 #include "HepPDT/TempParticleData.hh"
00018
00019 namespace HepPDT {
00020
00021 bool getEvtGenLineType( std::string & ltype, int & id, std::string & name, const std::string & pdline );
00022 void parseEvtGenLine( TempParticleData & tpd, const std::string & pdline );
00023 void parseEvtGenAlias( TempAliasData & tad, const std::string & pdline );
00024 bool parseEvtGenDecayLine( TempParticleData & tpd, const std::string & pdline );
00025 bool parseEvtGenAliasDecayLine( TempAliasData & tad, const std::string & pdline );
00026 void parseEvtGenConj( std::string & cname, const std::string & pdline );
00027 void parseEvtGenDefinition( std::string & def, double & val, const std::string & pdline );
00028
00029 bool addEvtGenParticles( std::istream & pdfile, TableBuilder & tb )
00030 {
00031 std::string pdline, ltype, def, name, cname;
00032 int id, eid;
00033 double val;
00034 TempAliasData tad;
00035
00036 DefTable & dt = tb.definitions();
00037
00038 while( std::getline( pdfile, pdline) ) {
00039 if( getEvtGenLineType( ltype, eid, name, pdline ) ) {
00040 if( ltype == "add" ) {
00041
00042 id = HepPID::translateEvtGentoPDT( eid );
00043 TempParticleData& tpd = tb.getParticleData( ParticleID( id ) );
00044 parseEvtGenLine( tpd, pdline );
00045 tb.addParticle( tpd );
00046 } else if( ltype=="Define" ) {
00047
00048 parseEvtGenDefinition( def, val, pdline );
00049 dt.addDefinition( def, val );
00050 } else if( ltype=="Alias" ) {
00051
00052 TempAliasData ntad;
00053 parseEvtGenAlias( ntad, pdline );
00054 tb.addAlias( ntad );
00055 } else if( ltype=="sets" ) {
00056
00057 } else if( ltype=="ChargeConj" ) {
00058
00059 if( tb.hasAlias( name ) ) {
00060 parseEvtGenConj( cname, pdline );
00061 tad = tb.aliasData( name );
00062 tad.tempChargeConj = cname;
00063 } else {
00064 std::cout << "HepPDT TableBuilder: " << name << " is not an alias" << std::endl;
00065 }
00066 } else if( ltype=="Decay" ) {
00067
00068
00069 if( tb.hasParticleData( name ) ) {
00070 TempParticleData& tpd = tb.getParticleData( name );
00071
00072 while( parseEvtGenDecayLine( tpd, pdline ) ) {
00073 std::getline( pdfile, pdline);
00074 }
00075 } else if( tb.hasAlias( name ) ) {
00076
00077 tad = tb.aliasData( name );
00078
00079 while( parseEvtGenAliasDecayLine( tad, pdline ) ) {
00080 std::getline( pdfile, pdline);
00081 }
00082 } else {
00083 std::cout << "HepPDT TableBuilder: could not match name " << name << std::endl;
00084 }
00085 } else if( ltype=="CDecay" ) {
00086
00087 } else if( ltype=="JetSetPar" ) {
00088
00089 } else if( ltype=="yesPhotos" ) {
00090
00091 } else if( ltype=="ModelAlias" ) {
00092
00093 } else if( ltype=="SetLineshapePW" ) {
00094
00095 }
00096 }
00097 }
00098 std::cout << "found " << tb.size() << " particles and "
00099 << tb.aliasSize() << " aliases" << std::endl;
00100
00101 return true;
00102 }
00103
00104 bool getEvtGenLineType( std::string & ltype, int & id, std::string & name, const std::string & pdline )
00105 {
00106 std::string s1, s2;
00107 int sl = pdline.length();
00108 std::string firstc = pdline.substr(0,1);
00109 id = 0;
00110 name = "";
00111 ltype = "";
00112
00113 if( firstc == "*" || firstc == "#" ) { return false; }
00114
00115
00116 if( sl > 5 ){
00117 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00118 thisline >> ltype;
00119 if( ltype == "add" ) {
00120 thisline >> s1 >> s2 >> name >> id;
00121 } else if( ltype=="Alias" ) {
00122 thisline >> name;
00123 } else if( ltype=="ChargeConj" ) {
00124 thisline >> name;
00125 } else if( ltype == "Decay" ) {
00126 thisline >> name;
00127 } else if( ltype == "CDecay" ) {
00128 thisline >> name;
00129 }
00130 return true;
00131 } else {
00132 return false;
00133 }
00134 }
00135
00136 void parseEvtGenLine( TempParticleData & tpd, const std::string & pdline )
00137 {
00138
00139 std::string s1, s2, ltype, name;
00140 int id, chg, spin, lid;
00141 double mass, width, wcut, lifet, dspin;
00142
00143
00144 if( tpd.tempID.pid() == 0 ) { return; }
00145
00146 int sl = pdline.length();
00147 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00148 thisline >> ltype >> s1 >> s2 >> name >> id >> mass >> width >> wcut
00149 >> chg >> spin >> lifet >> lid;
00150
00151
00152
00153 if( ltype != "add" ) {
00154 std::cout << "called parseEvtGenLine with wrong line type" << std::endl;
00155 return;
00156 }
00157 tpd.tempParticleName = name;
00158 tpd.tempSource = "EvtGen";
00159 tpd.tempOriginalID = id;
00160 tpd.tempCharge = double(chg)/3.0;
00161 tpd.tempMass = Measurement( mass, 0.0 );
00162 tpd.tempHighCutoff = wcut;
00163 tpd.tempWidth = Measurement( calculateWidthFromLifetime( lifet ), 0.0 );
00164 dspin = double(spin)/2.;
00165 if( tpd.tempSpin.totalSpin() != dspin ) {
00166
00167
00168 tpd.tempSpin.setTotalSpin( dspin );
00169 }
00170 }
00171
00172 bool parseEvtGenDecayLine( TempParticleData & tpd, const std::string & pdline )
00173 {
00174 std::string ltype;
00175
00176 if( tpd.tempID.pid() == 0 ) { return false; }
00177
00178 int sl = pdline.length();
00179
00180 if( sl < 5 ) { return true; }
00181 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00182
00183 std::string firstc = pdline.substr(0,1);
00184 if( firstc == "*" || firstc == "#" || firstc == ";" ) { return true; }
00185
00186 thisline >> ltype;
00187 if( ltype == "Decay" ) {
00188
00189 return true;
00190 } else if( ltype == "" ) {
00191
00192 return true;
00193 } else if( ltype == "Enddecay" ) {
00194
00195 return false;
00196 }
00197
00198 return true;
00199 }
00200
00201 bool parseEvtGenAliasDecayLine( TempAliasData & tad, const std::string & pdline )
00202 {
00203 std::string ltype;
00204 int sl = pdline.length();
00205 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00206
00207 std::string firstc = pdline.substr(0,1);
00208 if( firstc == "*" || firstc == "#" ) { return true; }
00209
00210 thisline >> ltype;
00211 if( ltype == "Decay" ) {
00212
00213 return true;
00214 } else if( ltype == "Enddecay" ) {
00215
00216 return false;
00217 }
00218
00219 return true;
00220 }
00221
00222 void parseEvtGenAlias( TempAliasData & tad, const std::string & pdline )
00223 {
00224
00225 std::string ltype, alias, name;
00226
00227 int sl = pdline.length();
00228 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00229 thisline >> ltype >> alias >> name;
00230
00231 if( ltype != "Alias" ) {
00232 std::cout << "called parseEvtGenAlias with wrong line type: " << ltype << std::endl;
00233 return;
00234 }
00235 tad.tempAlias = alias;
00236 tad.tempAliasedParticle = name;
00237 }
00238
00239 void parseEvtGenConj( std::string & cname, const std::string & pdline )
00240 {
00241 std::string ltype, alias;
00242
00243 int sl = pdline.length();
00244 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00245 thisline >> ltype >> alias >> cname;
00246
00247 if( ltype != "ChargeConj" ) {
00248 std::cout << "called parseEvtGenConj with wrong line type: " << ltype << std::endl;
00249 cname = "";
00250 return;
00251 }
00252 }
00253
00254 void parseEvtGenDefinition( std::string & def, double & val, const std::string & pdline )
00255 {
00256 std::string ltype;
00257
00258 int sl = pdline.length();
00259 std::istringstream thisline( pdline.substr(0,sl).c_str() );
00260 thisline >> ltype >> def >> val;
00261
00262 if( ltype != "Define" ) {
00263 std::cout << "called parseEvtGenDefinition with wrong line type: " << ltype << std::endl;
00264 val = 0.0;
00265 def = "";
00266 }
00267 }
00268
00269 }