![]() |
HepPDT Reference DocumentationHepPDT |
00001 // ---------------------------------------------------------------------- 00002 // 00003 // addEvtGenParticles.cc 00004 // Author: Lynn Garren 00005 // 00006 // this has the functions used by addEvtGenParticles 00007 // 00008 // ---------------------------------------------------------------------- 00009 00010 #include <string> 00011 #include <algorithm> // min() 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( 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 // get definition table 00036 DefTable & dt = tb.definitions(); 00037 // read and parse each line 00038 while( std::getline( pdfile, pdline) ) { 00039 if( getEvtGenLineType( ltype, eid, name, pdline ) ) { 00040 if( ltype == "add" ) { 00041 // this is a new particle definition 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 // EvtGen definition 00048 parseEvtGenDefinition( def, val, pdline ); 00049 dt.addDefinition( def, val ); 00050 } else if( ltype=="Alias" ) { 00051 // EvtGen alias information 00052 TempAliasData ntad; 00053 parseEvtGenAlias( ntad, pdline ); 00054 tb.addAlias( ntad ); 00055 } else if( ltype=="sets" ) { 00056 // put something here 00057 } else if( ltype=="ChargeConj" ) { 00058 // EvtGen charge conjugate alias 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 // EvtGen assumes that all particles have been defined before 00068 // they are used in the decay table 00069 if( tb.hasParticleData( name ) ) { 00070 TempParticleData& tpd = tb.getParticleData( name ); 00071 // read lines until we reach an "Enddecay" 00072 while( parseEvtGenDecayLine( tpd, pdline ) ) { 00073 std::getline( pdfile, pdline); 00074 } 00075 } else if( tb.hasAlias( name ) ) { 00076 // alias decays are maintained separately in temporary storage 00077 tad = tb.aliasData( name ); 00078 // read lines until we reach an "Enddecay" 00079 while( parseEvtGenAliasDecayLine( 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 // have to generate a charge conjugate decay table 00087 } else if( ltype=="JetSetPar" ) { 00088 // put something here 00089 } else if( ltype=="yesPhotos" ) { 00090 // put something here 00091 } else if( ltype=="ModelAlias" ) { 00092 // put something here 00093 } else if( ltype=="SetLineshapePW" ) { 00094 // put something here 00095 } 00096 } 00097 } 00098 std::cout << "found " << tb.size() << " particles and " 00099 << tb.aliasSize() << " aliases" << std::endl; 00100 // dt.writeDefinitions(); 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 // check for comments 00113 if( firstc == "*" || firstc == "#" ) { return false; } 00114 // a # may be anywhere on the line 00115 // check for empty lines 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 // this line defines a particle 00139 std::string s1, s2, ltype, name; 00140 int id, chg, spin, lid; 00141 double mass, width, wcut, lifet, dspin; 00142 00143 // check for valid TempParticleData 00144 if( tpd.tempID.pid() == 0 ) { return; } 00145 // have a valid PID, so proceed 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 // std::cout << ltype << " " << s1 << " " << s2 << " " << id << " " << name 00151 // << " " << chg << " " << spin << " " << mass << " " << width << " " 00152 // << wcut << " " << lifet << " " << lid << std::endl; 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 // std::cout << "EvtGen spin " << dspin << " does not match ParticleID spin " 00167 // << tpd.tempSpin.totalSpin() << std::endl; 00168 tpd.tempSpin.setTotalSpin( dspin ); 00169 } 00170 } 00171 00172 bool parseEvtGenDecayLine( TempParticleData & tpd, const std::string & pdline ) 00173 { 00174 std::string ltype; 00175 // check for valid TempParticleData 00176 if( tpd.tempID.pid() == 0 ) { return false; } 00177 // have a valid PID, so proceed 00178 int sl = pdline.length(); 00179 // check for empty lines 00180 if( sl < 5 ) { return true; } 00181 std::istringstream thisline( pdline.substr(0,sl).c_str() ); 00182 // better check for comments and blank lines..... 00183 std::string firstc = pdline.substr(0,1); 00184 if( firstc == "*" || firstc == "#" || firstc == ";" ) { return true; } 00185 // check line type 00186 thisline >> ltype; 00187 if( ltype == "Decay" ) { 00188 // begin decay 00189 return true; 00190 } else if( ltype == "" ) { 00191 // blank line with white space 00192 return true; 00193 } else if( ltype == "Enddecay" ) { 00194 // end decay 00195 return false; 00196 } 00197 // this is a good decay line 00198 return true; 00199 } 00200 00201 bool parseEvtGenAliasDecayLine( 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 // better check for comments and blank lines..... 00207 std::string firstc = pdline.substr(0,1); 00208 if( firstc == "*" || firstc == "#" ) { return true; } 00209 // check line type 00210 thisline >> ltype; 00211 if( ltype == "Decay" ) { 00212 // begin decay 00213 return true; 00214 } else if( ltype == "Enddecay" ) { 00215 // end decay 00216 return false; 00217 } 00218 // this is a good decay line 00219 return true; 00220 } 00221 00222 void parseEvtGenAlias( TempAliasData & tad, const std::string & pdline ) 00223 { 00224 // this line defines a particle alias 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 // std::cout << ltype << " " << alias << " " << name << std::endl; 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 // std::cout << ltype << " " << alias << " " << cname << std::endl; 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 // std::cout << ltype << " " << def << " " << val << std::endl; 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 } // HepPDT