12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/ParticleProperty.h"
15 #include "GaudiKernel/PhysicalConstants.h"
16 #include "GaudiKernel/IFileAccess.h"
17 #include "GaudiKernel/System.h"
43 ParticlePropertySvc::ParticlePropertySvc
44 ( const
std::
string& name ,
48 , m_filename ( "ParticleTable.txt" )
66 m_filename +=
"/data/ParticleTable.txt";
69 declareProperty (
"ParticlePropertiesFile" , m_filename ) ;
70 declareProperty (
"OtherFiles" , m_other ) ;
71 declareProperty (
"Particles" , m_particles ) ;
76 ParticlePropertySvc::~ParticlePropertySvc()
78 for ( Set::iterator
i = m_owned.begin();
i != m_owned.end() ; ++
i )
79 {
if ( 0 != *
i ) {
delete *
i ; } }
99 sc = service(
"VFSSvc",m_fileAccess);
112 if ( !m_particles.empty() )
114 sc = addParticles () ;
130 log <<
MSG::DEBUG <<
"StdHepID Map size =" << m_stdhepidmap.size()
133 log <<
MSG::DEBUG <<
"PythiaID Map size =" << m_pythiaidmap.size()
136 if ( !m_replaced.empty() )
139 <<
"Properties have been redefined for "
140 << m_replaced.size() <<
" particles : "
152 if ( !m_other.empty() )
156 <<
"Additional Properties have been read from files: "
161 if ( !m_replaced.empty() )
165 <<
"Properties have been redefined for "
166 << m_replaced.size() <<
" particles : "
172 m_fileAccess->release();
183 (
const std::string& particle ,
189 const std::string& evtName ,
194 ( particle , geantId , jetsetId ,
195 charge , mass , tlife ,
196 evtName , pythiaId , maxWidth ) ;
198 m_owned.insert ( pp ) ;
200 return push_back( pp );
212 MapID::const_iterator ifind = m_idmap.find( ID ) ;
213 if ( m_idmap.end() != ifind && 0 != m_idmap[ ID ])
215 diff ( ifind->second , pp ) ;
216 m_replaced.insert( m_idmap[ ID ]->particle() ) ;
223 const std::string& particle = pp->
particle() ;
225 MapName::const_iterator ifind = m_namemap.find( particle ) ;
226 if ( m_namemap.end() != ifind && 0 != m_namemap[ particle ] )
228 diff ( ifind->second , pp ) ;
229 m_replaced.insert( m_namemap[ particle ]->particle() ) ;
232 m_namemap[ particle ] =
pp ;
241 MapStdHepID::const_iterator ifind = m_stdhepidmap.find( ID ) ;
242 if ( m_stdhepidmap.end() != ifind && 0 != m_stdhepidmap[ ID ])
244 diff ( ifind->second , pp ) ;
245 m_replaced.insert( m_stdhepidmap[ ID ]->particle() ) ;
248 m_stdhepidmap[ ID ] =
pp ;
259 MapPythiaID::const_iterator ifind = m_pythiaidmap.find( ID ) ;
260 if ( m_pythiaidmap.end() != ifind && 0 != m_pythiaidmap[ ID ])
262 diff ( ifind->second , pp ) ;
263 m_replaced.insert( m_pythiaidmap[ ID ]->particle() ) ;
266 m_pythiaidmap[ ID ] =
pp ;
279 typename MAP::iterator
i = m.begin() ;
280 for ( ; m.end() !=
i ; ++
i ) {
if ( i->second == pp ) { break ; } }
281 if ( m.end() !=
i ) { m.erase ( i ) ; }
289 _remove_ ( m_idmap , pp ) ;
290 _remove_ ( m_namemap , pp ) ;
291 _remove_ ( m_stdhepidmap , pp ) ;
292 _remove_ ( m_pythiaidmap , pp ) ;
307 for ( Files::const_iterator
file = m_other.begin() ;
316 if ( m_namemap.size() == 0 )
320 <<
"Format of input file inconsistent with what expected"
321 <<
" - Check you are using ParticleData.txt" <<
endmsg;
335 std::auto_ptr<std::istream> infileptr;
336 if (m_fileAccess) infileptr = m_fileAccess->open(file);
338 if ( infileptr.get() == 0 )
340 log <<
MSG::ERROR <<
"Unable to open properties file : " << file
345 std::istream &infile = *infileptr;
348 <<
"Opened particle properties file : " << file <<
endmsg;
354 infile.getline( line, 255 );
356 if ( line[0] ==
'#' )
continue;
362 #pragma warning(disable:4996)
364 std::string
par, gid, jid, chg, mas, lif,
evt, pyt, mwi ;
365 char* token = strtok( line,
" " );
366 if ( token ) { par = token; token = strtok( NULL,
" " );}
else continue;
367 if ( token ) { gid = token; token = strtok( NULL,
" " );}
else continue;
368 if ( token ) { jid = token; token = strtok( NULL,
" " );}
else continue;
369 if ( token ) { chg = token; token = strtok( NULL,
" " );}
else continue;
370 if ( token ) { mas = token; token = strtok( NULL,
" " );}
else continue;
371 if ( token ) { lif = token; token = strtok( NULL,
" " );}
else continue;
372 if ( token ) { evt = token; token = strtok( NULL,
" " );}
else continue;
373 if ( token ) { pyt = token; token = strtok( NULL,
" " );}
else continue;
374 if ( token ) { mwi = token; token = strtok( NULL,
" " );}
else continue;
375 if ( token != NULL )
continue;
379 double mass = atof( mas.c_str() ) * Gaudi::Units::GeV;
380 double tlife = atof( lif.c_str() ) * Gaudi::Units::s;
381 long ljid = atoi( jid.c_str() );
382 long lgid = atoi( gid.c_str() );
383 long lpyt = atoi( pyt.c_str() ) ;
384 double mW = atof( mwi.c_str() ) * Gaudi::Units::GeV ;
388 ljid = 10000000*lgid;
392 sc = push_back( par, lgid, ljid,
393 atof( chg.c_str() ), mass, tlife, evt, lpyt, mW ) ;
397 <<
"Error from ParticlePropertySvc::push_back for particle='"
417 if ( 0 == pp ) {
return 0 ; }
418 const int ID = pp->
pdgID() ;
419 const int antiID = -1 * ID ;
420 for (
const_iterator it = m_vectpp.begin() ; m_vectpp.end() != it ; ++it )
423 if ( 0 == ap ) { continue ; }
424 if ( antiID == ap->
pdgID() ) {
return ap ; }
438 for (
iterator ip = m_vectpp.begin() ; m_vectpp.end() != ip ; ++ip )
441 if ( 0 == pp ) { continue ; }
456 for (
typename MAP::iterator i = m.begin() ; m.end() !=
i ; ++
i )
457 { result.insert ( i->second ); }
465 m_vectpp.reserve ( m_idmap.size() + 100 ) ;
467 _load_ ( m_idmap , local ) ;
468 _load_ ( m_namemap , local ) ;
469 _load_ ( m_stdhepidmap , local ) ;
470 _load_ ( m_pythiaidmap , local ) ;
472 for ( Set::iterator i = local.begin() ; local.end() !=
i ; ++
i )
473 { m_vectpp.push_back ( *i ) ; }
474 return setAntiParticles() ;
484 for ( Particles::const_iterator ip = m_particles.begin() ;
485 m_particles.end() != ip ; ++ip )
487 const std::string
item = *ip ;
488 std::istringstream input( item ) ;
496 std::string p_evtgen ;
511 <<
" Add/Modify the particle: "
512 <<
" name='" << p_name <<
"'"
513 <<
" geant=" << p_geant
514 <<
" jetset=" << p_jetset
515 <<
" charge=" << p_charge
516 <<
" mass=" << p_mass
517 <<
" ltime=" << p_ltime
518 <<
" evtgen='" << p_evtgen <<
"'"
519 <<
" pythia=" << p_pythia
520 <<
" maxwid=" << p_maxwid <<
endmsg ;
527 p_mass * Gaudi::Units::GeV ,
528 p_ltime * Gaudi::Units::s ,
531 p_maxwid * Gaudi::Units::GeV ) ;
537 <<
" could not parse '" << item <<
"'" <<
endmsg ;
548 #pragma warning(push)
549 #pragma warning(disable:1572)
551 bool ParticlePropertySvc::diff
557 if ( o == n ) {
return false ; }
561 if ( 0 == o || 0 == n )
567 bool result = false ;
568 if ( o -> particle () != n -> particle () )
571 log <<
" Name:'" << o -> particle () <<
"'/'" << n -> particle () <<
"'" ;
573 if ( o -> geantID () != n -> geantID () )
576 log <<
" G3ID:" << o -> geantID () <<
"/" << n -> geantID () <<
"'" ;
578 if ( o -> pdgID () != n -> pdgID () )
581 log <<
" PDGID:" << o -> pdgID () <<
"/" << n -> pdgID () <<
"'" ;
583 if ( o -> pythiaID () != n -> pythiaID () )
586 log <<
" PYID:" << o -> pythiaID () <<
"/" << n -> pythiaID () <<
"'" ;
588 if ( o -> charge () != n -> charge () )
591 log <<
" Q:" << o -> charge () <<
"/" << n -> charge () <<
"'" ;
593 if ( o -> mass () != n -> mass () )
596 log <<
" M:" << o -> mass () <<
"/" << n -> mass () <<
"'" ;
598 if ( o -> lifetime () != n -> lifetime () )
601 log <<
" T:" << o -> lifetime () <<
"/" << n -> lifetime () <<
"'" ;
603 if ( o -> evtGenName () != n -> evtGenName () )
606 log <<
" EvtGen:" << o -> evtGenName () <<
"/" << n -> evtGenName () <<
"'" ;
608 if ( o -> maxWidth () != n -> maxWidth () )
611 log <<
" WMAX:" << o -> maxWidth () <<
"/" << n -> maxWidth () <<
"'" ;
613 if ( result ) { log <<
endmsg ; }