Gaudi::ParticlePropertySvc Class Reference

This service provides access to particle properties. More...

#include <src/ParticlePropertySvc.h>

Inheritance diagram for Gaudi::ParticlePropertySvc:
Collaboration diagram for Gaudi::ParticlePropertySvc:

Public Types

typedef ParticlePropertymapped_type
 
typedef std::map< int, mapped_typeMapID
 
typedef std::map< std::string, mapped_typeMapName
 
typedef std::map< int, mapped_typeMapStdHepID
 
typedef std::map< int, mapped_typeMapPythiaID
 
typedef std::vector< ParticleProperty * > VectPP
 
typedef std::vector< ParticleProperty * > VectPP
 
typedef VectPP::const_iterator const_iterator
 
typedef VectPP::const_iterator const_iterator
 
typedef VectPP::iterator iterator
 
typedef VectPP::iterator iterator
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

StatusCode initialize () override
 Initialise the service. More...
 
StatusCode finalize () override
 Finalise the service. More...
 
StatusCode push_back (const std::string &particle, int geantId, int jetsetId, double charge, double mass, double tlife, const std::string &evtName, int pythiaId, double maxWidth) override
 Create a new particle property. More...
 
StatusCode push_back (ParticleProperty *pp) override
 Add a new particle property. More...
 
const_iterator begin () const override
 Get a const reference to the beginning of the container. More...
 
const_iterator end () const override
 Get a const reference to the end of the container. More...
 
int size () const override
 Get the container size. More...
 
ParticlePropertyfind (int geantId) override
 Retrieve a property by geant3 id. More...
 
ParticlePropertyfind (const std::string &name) override
 Retrieve a property by particle name. More...
 
ParticlePropertyfindByStdHepID (int stdHepId) override
 Retrieve a property by StdHep id. More...
 
ParticlePropertyfindByPythiaID (int pythiaID) override
 Retrieve a property by Pythia id. More...
 
StatusCode erase (int geantId) override
 Erase a property by geant3 id. More...
 
StatusCode erase (const std::string &name) override
 Erase a property by particle name. More...
 
StatusCode eraseByStdHepID (int stdHepId) override
 Erase a property by StdHep id ??? More...
 
 ParticlePropertySvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor. More...
 
 ~ParticlePropertySvc () override=default
 Destructor. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Protected Member Functions

const ParticlePropertyanti (const ParticleProperty *pp) const
 helper (protected) function to find an antiparticle for the given particle ID (StdHepID) More...
 
StatusCode setAntiParticles ()
 helper (protected) function to set the valid particle<–>antiparticle relations More...
 
StatusCode rebuild ()
 rebuild "the linear container" from the map More...
 
StatusCode erase (const ParticleProperty *pp)
 remove particle property from all maps More...
 
StatusCode parse (const std::string &file)
 parse the file More...
 
StatusCode parse ()
 Parses the file and fill all the maps. More...
 
StatusCode addParticles ()
 
bool diff (const ParticleProperty *o, const ParticleProperty *n, const MSG::Level l=MSG::DEBUG) const
 

Private Types

typedef std::vector< std::string > Files
 
typedef std::vector< std::string > Particles
 

Private Attributes

std::string m_filename = "ParticleTable.txt"
 Filename of the particle properties file. More...
 
Files m_other
 additional file names More...
 
Particles m_particles
 
VectPP m_vectpp
 Vector of all particle properties. More...
 
MapID m_idmap
 Map for geant IDs. More...
 
MapName m_namemap
 Map for particle names. More...
 
MapStdHepID m_stdhepidmap
 Map for StdHep Ids. More...
 
MapPythiaID m_pythiaidmap
 Map for Pythia Ids. More...
 
std::set< std::unique_ptr< ParticleProperty > > m_owned
 
std::set< std::string > m_replaced
 
SmartIF< IFileAccessm_fileAccess
 

Detailed Description

This service provides access to particle properties.

The settable property of this service is the ParticlePropertiesFile, an ASCII file containing the list of properties for the particles. The default file is: "$PARAMFILESROOT/data/ParticleTable.txt" or if $PARAMFILESROOT is not defined "ParticleTable.txt"

Author
Iain Last
Gloria Corti 8/11/1999 change default file from $CDF/particle.cdf to $LHCBDBASE/cdf/particle.cdf on Unix and use environment variable also on WinNT Also introduce finding of particle by StdHepID
Vanya BELYAEV
Date
2006-09-22 1) Modified to add possibility to redefine properties of existing particles and to read additional files. New property "OtherFiles" (default is empty vector) is introduces. Service parsed additional files after the main one.
// read additional properties
ParticlePropertySvc.OtherFiles = {
"$SOMELOCATION1/file1.txt" ,
"$SOMELOCATION2/file2.txt"
} ;

2) Add possibility to modify only certain particles through the new property "Particles" (default is empty list), Each line is interpreted as a line in particle data table, e.g.

// redefine the properties of H_20 and H_30 particles:
ParticlePropertySvc.Particles = {
"H_20 88 35 0.0 120.0 9.4e-26 Higgs'0 35 0.0e+00" ,
"H_30 89 36 0.0 40.0 1.0e-12 A0 36 0.0e+00"
} ;

The replaces/modified particles are reported.

Definition at line 71 of file ParticlePropertySvc.h.

Member Typedef Documentation

typedef VectPP::const_iterator IParticlePropertySvc::const_iterator

Definition at line 26 of file IParticlePropertySvc.h.

typedef VectPP::const_iterator IParticlePropertySvc::const_iterator

Definition at line 26 of file IParticlePropertySvc.h.

typedef std::vector<std::string> Gaudi::ParticlePropertySvc::Files
private

Definition at line 180 of file ParticlePropertySvc.h.

typedef VectPP::iterator IParticlePropertySvc::iterator

Definition at line 27 of file IParticlePropertySvc.h.

typedef VectPP::iterator IParticlePropertySvc::iterator

Definition at line 27 of file IParticlePropertySvc.h.

typedef std::map< int, mapped_type > Gaudi::ParticlePropertySvc::MapID

Definition at line 76 of file ParticlePropertySvc.h.

typedef std::map< std::string, mapped_type > Gaudi::ParticlePropertySvc::MapName

Definition at line 77 of file ParticlePropertySvc.h.

typedef ParticleProperty* Gaudi::ParticlePropertySvc::mapped_type

Definition at line 75 of file ParticlePropertySvc.h.

typedef std::map< int, mapped_type > Gaudi::ParticlePropertySvc::MapPythiaID

Definition at line 79 of file ParticlePropertySvc.h.

typedef std::map< int, mapped_type > Gaudi::ParticlePropertySvc::MapStdHepID

Definition at line 78 of file ParticlePropertySvc.h.

typedef std::vector<std::string> Gaudi::ParticlePropertySvc::Particles
private

Definition at line 181 of file ParticlePropertySvc.h.

Definition at line 25 of file IParticlePropertySvc.h.

Definition at line 25 of file IParticlePropertySvc.h.

Constructor & Destructor Documentation

Gaudi::ParticlePropertySvc::ParticlePropertySvc ( const std::string &  name,
ISvcLocator svc 
)

Standard Constructor.

Parameters
nameString with service name
svcPointer to service locator interface
Todo:
: remove reference to LHCb-specific environment variable

Definition at line 54 of file ParticlePropertySvc.cpp.

56  : base_class( name, svc )
57 {
59  // Redefine the default name:
60  if( System::getEnv("PARAMFILESROOT", m_filename) )
61  {
62  m_filename += "/data/ParticleTable.txt";
63  }
64  //
65  declareProperty ( "ParticlePropertiesFile" , m_filename ) ;
66  declareProperty ( "OtherFiles" , m_other ) ;
67  declareProperty ( "Particles" , m_particles ) ;
68 }
extends base_class
Typedef to this class.
Definition: extends.h:14
Files m_other
additional file names
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:617
std::string m_filename
Filename of the particle properties file.
Gaudi::ParticlePropertySvc::~ParticlePropertySvc ( )
overridedefault

Destructor.

Member Function Documentation

StatusCode Gaudi::ParticlePropertySvc::addParticles ( )
protected

Definition at line 431 of file ParticlePropertySvc.cpp.

432 {
433 
434  MsgStream log ( msgSvc() , name() ) ;
435  // loop over all "explicit" particles
436  for ( const auto& item : m_particles )
437  {
438  std::istringstream input( item ) ;
439  // get the name
440  std::string p_name ;
441  int p_geant ;
442  int p_jetset ;
443  double p_charge ;
444  double p_mass ;
445  double p_ltime ;
446  std::string p_evtgen ;
447  int p_pythia ;
448  double p_maxwid ;
449  if ( input
450  >> p_name
451  >> p_geant
452  >> p_jetset
453  >> p_charge
454  >> p_mass
455  >> p_ltime
456  >> p_evtgen
457  >> p_pythia
458  >> p_maxwid )
459  {
460  log << MSG::ALWAYS
461  << " Add/Modify the particle: "
462  << " name='" << p_name << "'"
463  << " geant=" << p_geant
464  << " jetset=" << p_jetset
465  << " charge=" << p_charge
466  << " mass=" << p_mass
467  << " ltime=" << p_ltime
468  << " evtgen='" << p_evtgen << "'"
469  << " pythia=" << p_pythia
470  << " maxwid=" << p_maxwid << endmsg ;
471  //
473  ( p_name ,
474  p_geant ,
475  p_jetset ,
476  p_charge ,
477  p_mass * Gaudi::Units::GeV ,
478  p_ltime * Gaudi::Units::s ,
479  p_evtgen ,
480  p_pythia ,
481  p_maxwid * Gaudi::Units::GeV ) ;
482  if ( sc.isFailure() ) { return sc ; } // RETURN
483  }
484  else
485  {
486  log << MSG::ERROR
487  << " could not parse '" << item << "'" << endmsg ;
488  return StatusCode::FAILURE ; // RETURN
489  }
490  }
491  //
492  return StatusCode::SUCCESS ;
493 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
constexpr double s
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode push_back(const std::string &particle, int geantId, int jetsetId, double charge, double mass, double tlife, const std::string &evtName, int pythiaId, double maxWidth) override
Create a new particle property.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple item
print s1,s2
Definition: ana.py:146
constexpr double GeV
const ParticleProperty * Gaudi::ParticlePropertySvc::anti ( const ParticleProperty pp) const
protected

helper (protected) function to find an antiparticle for the given particle ID (StdHepID)

Helper (protected) function to find an antiparticle for the given particle ID (StdHepID)

Parameters
pppointer to particle property
Returns
pointer to antiparticle

Definition at line 371 of file ParticlePropertySvc.cpp.

372 {
373  if ( !pp ) { return nullptr ; }
374  const int ID = pp->pdgID() ;
375  const int antiID = -1 * ID ;
376  for ( const auto& ap : m_vectpp )
377  {
378  if ( ap && antiID == ap->pdgID() ) { return ap ; } // RETURN
379  };
380  //
381  return pp ; // RETURN
382 }
int pdgID() const
Get the PDG (= JETSET) ID.
VectPP m_vectpp
Vector of all particle properties.
const_iterator Gaudi::ParticlePropertySvc::begin ( ) const
inlineoverride

Get a const reference to the beginning of the container.

Definition at line 118 of file ParticlePropertySvc.h.

118 { return m_vectpp.begin() ; }
VectPP m_vectpp
Vector of all particle properties.
bool Gaudi::ParticlePropertySvc::diff ( const ParticleProperty o,
const ParticleProperty n,
const MSG::Level  l = MSG::DEBUG 
) const
protected

Definition at line 502 of file ParticlePropertySvc.cpp.

505 {
506  //
507  if ( o == n ) { return false ; }
508  //
509  MsgStream log ( msgSvc() , name() ) ;
510  log << l ;
511  if ( !o || !n )
512  {
513  log << MSG::WARNING << " ParticleProperty* point to NULL" << endmsg ;
514  return true ; // RETURN
515  }
516  //
517  bool result = false ;
518  if ( o -> particle () != n -> particle () )
519  {
520  result = true ;
521  log << " Name:'" << o -> particle () << "'/'" << n -> particle () << "'" ;
522  }
523  if ( o -> geantID () != n -> geantID () )
524  {
525  result = true ;
526  log << " G3ID:" << o -> geantID () << "/" << n -> geantID () << "'" ;
527  }
528  if ( o -> pdgID () != n -> pdgID () )
529  {
530  result = true ;
531  log << " PDGID:" << o -> pdgID () << "/" << n -> pdgID () << "'" ;
532  }
533  if ( o -> pythiaID () != n -> pythiaID () )
534  {
535  result = true ;
536  log << " PYID:" << o -> pythiaID () << "/" << n -> pythiaID () << "'" ;
537  }
538  if ( o -> charge () != n -> charge () )
539  {
540  result = true ;
541  log << " Q:" << o -> charge () << "/" << n -> charge () << "'" ;
542  }
543  if ( o -> mass () != n -> mass () )
544  {
545  result = true ;
546  log << " M:" << o -> mass () << "/" << n -> mass () << "'" ;
547  }
548  if ( o -> lifetime () != n -> lifetime () )
549  {
550  result = true ;
551  log << " T:" << o -> lifetime () << "/" << n -> lifetime () << "'" ;
552  }
553  if ( o -> evtGenName () != n -> evtGenName () )
554  {
555  result = true ;
556  log << " EvtGen:" << o -> evtGenName () << "/" << n -> evtGenName () << "'" ;
557  }
558  if ( o -> maxWidth () != n -> maxWidth () )
559  {
560  result = true ;
561  log << " WMAX:" << o -> maxWidth () << "/" << n -> maxWidth () << "'" ;
562  }
563  if ( result ) { log << endmsg ; }
564  //
565  return result ;
566 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
dictionary l
Definition: gaudirun.py:421
const_iterator Gaudi::ParticlePropertySvc::end ( ) const
inlineoverride

Get a const reference to the end of the container.

Definition at line 120 of file ParticlePropertySvc.h.

120 { return m_vectpp.end() ; }
VectPP m_vectpp
Vector of all particle properties.
StatusCode Gaudi::ParticlePropertySvc::erase ( int  geantId)
inlineoverride

Erase a property by geant3 id.

Definition at line 136 of file ParticlePropertySvc.h.

137  { return erase ( find ( geantId ) ) ; }
StatusCode erase(int geantId) override
Erase a property by geant3 id.
ParticleProperty * find(int geantId) override
Retrieve a property by geant3 id.
StatusCode Gaudi::ParticlePropertySvc::erase ( const std::string &  name)
inlineoverride

Erase a property by particle name.

Definition at line 139 of file ParticlePropertySvc.h.

140  { return erase ( find ( name ) ) ; }
StatusCode erase(int geantId) override
Erase a property by geant3 id.
ParticleProperty * find(int geantId) override
Retrieve a property by geant3 id.
StatusCode Gaudi::ParticlePropertySvc::erase ( const ParticleProperty pp)
protected

remove particle property from all maps

Definition at line 269 of file ParticlePropertySvc.cpp.

270 {
271  if ( !pp ) { return StatusCode::FAILURE ; }
272 
273  _remove_ ( m_idmap , pp ) ;
274  _remove_ ( m_namemap , pp ) ;
275  _remove_ ( m_stdhepidmap , pp ) ;
276  _remove_ ( m_pythiaidmap , pp ) ;
277  //
278  return rebuild() ;
279 }
StatusCode rebuild()
rebuild "the linear container" from the map
MapName m_namemap
Map for particle names.
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
MapID m_idmap
Map for geant IDs.
MapPythiaID m_pythiaidmap
Map for Pythia Ids.
StatusCode Gaudi::ParticlePropertySvc::eraseByStdHepID ( int  stdHepId)
inlineoverride

Erase a property by StdHep id ???

Definition at line 142 of file ParticlePropertySvc.h.

143  { return erase( findByStdHepID ( stdHepId ) ) ; }
StatusCode erase(int geantId) override
Erase a property by geant3 id.
ParticleProperty * findByStdHepID(int stdHepId) override
Retrieve a property by StdHep id.
StatusCode Gaudi::ParticlePropertySvc::finalize ( )
override

Finalise the service.

finalize

finalize the base class

Definition at line 137 of file ParticlePropertySvc.cpp.

138 {
139  if ( !m_other.empty() )
140  {
141  MsgStream log( msgSvc() , name() ) ;
142  log << MSG::INFO
143  << "Additional Properties have been read from files: "
145  << endmsg ;
146  }
147 
148  if ( !m_replaced.empty() )
149  {
150  MsgStream log( msgSvc() , name() ) ;
151  log << MSG::ALWAYS
152  << "Properties have been redefined for "
153  << m_replaced.size() << " particles : "
155  << endmsg ;
156  }
157 
159 
161  return Service::finalize () ;
162 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:371
Files m_other
additional file names
SmartIF< IFileAccess > m_fileAccess
std::set< std::string > m_replaced
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
ParticleProperty* Gaudi::ParticlePropertySvc::find ( int  geantId)
inlineoverride

Retrieve a property by geant3 id.

Definition at line 124 of file ParticlePropertySvc.h.

125  { return m_idmap[ geantId ] ; }
MapID m_idmap
Map for geant IDs.
ParticleProperty* Gaudi::ParticlePropertySvc::find ( const std::string &  name)
inlineoverride

Retrieve a property by particle name.

Definition at line 127 of file ParticlePropertySvc.h.

128  { return m_namemap[ name ] ; }
MapName m_namemap
Map for particle names.
ParticleProperty* Gaudi::ParticlePropertySvc::findByPythiaID ( int  pythiaID)
inlineoverride

Retrieve a property by Pythia id.

Definition at line 133 of file ParticlePropertySvc.h.

134  { return m_pythiaidmap[ pythiaID ]; }
MapPythiaID m_pythiaidmap
Map for Pythia Ids.
ParticleProperty* Gaudi::ParticlePropertySvc::findByStdHepID ( int  stdHepId)
inlineoverride

Retrieve a property by StdHep id.

Definition at line 130 of file ParticlePropertySvc.h.

131  { return m_stdhepidmap[ stdHepId ] ; }
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
StatusCode Gaudi::ParticlePropertySvc::initialize ( )
override

Initialise the service.

initialize the service and setProperties

Definition at line 72 of file ParticlePropertySvc.cpp.

73 {
75  if ( sc.isFailure() ) { return sc ; }
76 
77  MsgStream log( msgSvc() , name() ) ;
78 
79  sc = setProperties();
80  if ( sc.isFailure() )
81  {
82  log << MSG::ERROR << " Could not set the properties " << endmsg ;
83  return sc ;
84  }
85 
86  m_fileAccess = service("VFSSvc");
87  if ( !m_fileAccess )
88  {
89  log << MSG::ERROR << " Cannot retrieve the VFS service " << endmsg ;
90  return StatusCode::FAILURE ;
91  }
92 
93  sc = parse();
94  if ( sc.isFailure() )
95  {
96  log << MSG::ERROR << " Could not parse the file " << endmsg ;
97  return sc ;
98  }
99  if ( !m_particles.empty() )
100  {
101  sc = addParticles () ;
102  if ( sc.isFailure() )
103  {
104  log << MSG::ERROR << " Could not treat particles! " << endmsg ;
105  return sc ;
106  }
107  }
108  log << MSG::DEBUG << "ParticleProperties parsed successfully" << endmsg;
109 
110  log << MSG::DEBUG << "Access properties" << endmsg;
111  // For debugging purposes print out the size of the internal maps
112  // particle name as key: all particles in database are present here
113  log << MSG::DEBUG << "NameMap size =" << m_namemap.size() << endmsg;
114  // Geant3 ID as key: all particles in database are present here
115  log << MSG::DEBUG << "GeantID Map size =" << m_idmap.size() << endmsg;
116  // StdHep ID as key: some particles have no valid StdHep ID
117  log << MSG::DEBUG << "StdHepID Map size =" << m_stdhepidmap.size()
118  << endmsg;
119  // Pythia ID as key: some particles are not defined in Pythia
120  log << MSG::DEBUG << "PythiaID Map size =" << m_pythiaidmap.size()
121  << endmsg;
122 
123  if ( !m_replaced.empty() )
124  {
125  log << MSG::INFO
126  << "Properties have been redefined for "
127  << m_replaced.size() << " particles : "
129  << endmsg ;
130  }
131 
132  return StatusCode::SUCCESS ;
133 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:371
MapName m_namemap
Map for particle names.
StatusCode parse()
Parses the file and fill all the maps.
SmartIF< IFileAccess > m_fileAccess
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::set< std::string > m_replaced
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
MapID m_idmap
Map for geant IDs.
MapPythiaID m_pythiaidmap
Map for Pythia Ids.
StatusCode Gaudi::ParticlePropertySvc::parse ( const std::string &  file)
protected

parse the file

Definition at line 311 of file ParticlePropertySvc.cpp.

312 {
313  MsgStream log( msgSvc(), name() );
314 
315  auto infile = ( m_fileAccess ? m_fileAccess->open(file) : nullptr );
316  if ( !infile )
317  {
318  log << MSG::ERROR << "Unable to open properties file : " << file
319  << endmsg;
320  return StatusCode::FAILURE ;
321  }
322 
324  log << MSG::INFO
325  << "Opened particle properties file : " << file << endmsg;
326 
327  std::vector<std::string> tokens; tokens.reserve(9);
328  std::string line;
329  while( std::getline( *infile, line ) )
330  {
331  // parse each line of the file (comment lines begin with # in the cdf
332  // file,
333  if ( line.front() == '#' ) continue;
334 
335  tokens.clear();
336  ba::trim_left_if( line, ba::is_space() );
337  ba::split( tokens, line, ba::is_space() , boost::token_compress_on );
338  if (tokens.size()!=9) continue;
339 
340  auto gid = std::stoi( tokens[1] );
341  auto jid = std::stoi( tokens[2] );
342  // Change the particles that do not correspond to a pdg number
343  if ( jid == 0 ) jid = 10000000*gid;
344 
345  // add a particle property
346  sc = push_back( tokens[0], gid, jid,
347  std::stod( tokens[3] ),
348  std::stod( tokens[4] ) * Gaudi::Units::GeV,
349  std::stod( tokens[5] ) * Gaudi::Units::s,
350  tokens[6],
351  std::stoi( tokens[7] ),
352  std::stod( tokens[8] ) * Gaudi::Units::GeV ) ;
353 
354  if ( sc.isFailure() )
355  {
356  log << MSG::ERROR
357  << "Error from ParticlePropertySvc::push_back for particle='"
358  << tokens[0] << "'" << endmsg ;
359  }
360  }
361  return StatusCode::SUCCESS ;
362 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
constexpr double s
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IFileAccess > m_fileAccess
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode push_back(const std::string &particle, int geantId, int jetsetId, double charge, double mass, double tlife, const std::string &evtName, int pythiaId, double maxWidth) override
Create a new particle property.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
list file
Definition: ana.py:160
constexpr double GeV
virtual std::unique_ptr< std::istream > open(const std::string &url)=0
Find the URL and returns a unique_ptr to an input stream interface of an object that can be used to r...
StatusCode Gaudi::ParticlePropertySvc::parse ( )
protected

Parses the file and fill all the maps.

Definition at line 283 of file ParticlePropertySvc.cpp.

284 {
285 
286  // parse "the main" file
287  StatusCode sc = parse ( m_filename ) ;
288  if ( sc.isFailure() ) { return sc ; }
289 
290  // parse "other" files
291  for ( auto& file : m_other )
292  {
293  sc = parse ( file ) ;
294  if ( sc.isFailure() ) { return sc ; }
295  }
296 
297  // Now check that the file format was consistent with what parser
298  // expected
299  if ( m_namemap.empty() )
300  {
301  MsgStream log( msgSvc(), name() );
302  log << MSG::ERROR
303  << "Format of input file inconsistent with what expected"
304  << " - Check you are using ParticleData.txt" << endmsg;
305  return StatusCode::FAILURE;
306  }
307 
308  return sc;
309 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MapName m_namemap
Map for particle names.
StatusCode parse()
Parses the file and fill all the maps.
Files m_other
additional file names
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string m_filename
Filename of the particle properties file.
list file
Definition: ana.py:160
StatusCode Gaudi::ParticlePropertySvc::push_back ( const std::string &  particle,
int  geantId,
int  jetsetId,
double  charge,
double  mass,
double  tlife,
const std::string &  evtName,
int  pythiaId,
double  maxWidth 
)
override

Create a new particle property.

Create a particle property and insert it in the maps.

Attention
ParticlePropertySvc IS the owner if this property! String name of the particle.
Parameters
geantIdGeant3 ID of the particle.
jetsetIdJetset ID of the particle.
chargeParticle charge (/e).
massParticle mass (GeV).
tlifeParticle lifetime (s).
evtNameString name of the particle in EvtGen.
pythiaIdPythia ID of the particle.
Returns
StatusCode - SUCCESS if the particle property was added.

Definition at line 167 of file ParticlePropertySvc.cpp.

176 {
177  //
178  auto i = m_owned.insert(
179  make_unique_<ParticleProperty>( particle , geantId , jetsetId ,
180  charge , mass , tlife ,
181  evtName , pythiaId , maxWidth )
182  ) ;
183  //
184  return i.second ? push_back( i.first->get() ) : StatusCode::FAILURE;
185 }
StatusCode push_back(const std::string &particle, int geantId, int jetsetId, double charge, double mass, double tlife, const std::string &evtName, int pythiaId, double maxWidth) override
Create a new particle property.
std::set< std::unique_ptr< ParticleProperty > > m_owned
list i
Definition: ana.py:128
StatusCode Gaudi::ParticlePropertySvc::push_back ( ParticleProperty pp)
override

Add a new particle property.

Add a particle property.

Attention
ParticlePropertySvc is not the owner of this property!
Parameters
pp,aparticle property class.
Returns
StatusCode - SUCCESS if the particle property was added.

Definition at line 189 of file ParticlePropertySvc.cpp.

190 {
191  if ( !pp ) { return StatusCode::FAILURE ; }
192  //
193  { // try to add into Geant(3)ID map
194  const int ID = pp->geantID() ;
195  // is this already in the map?
196  auto ifind = m_idmap.find( ID ) ;
197  if ( m_idmap.end() != ifind && 0 != m_idmap[ ID ])
198  {
199  diff ( ifind->second , pp ) ;
200  m_replaced.insert( m_idmap[ ID ]->particle() ) ;
201  }
202  // put it into the map
203  m_idmap[ ID ] = pp ;
204  }
205  //
206  { // try to add into Name map
207  const std::string& particle = pp->particle() ;
208  // is this already in the map?
209  auto ifind = m_namemap.find( particle ) ;
210  if ( ifind != m_namemap.end() && ifind->second )
211  {
212  diff ( ifind->second , pp ) ;
213  m_replaced.insert( ifind->second->particle() ) ;
214  }
215  // put it into the map
216  m_namemap[ particle ] = pp ;
217  }
218  //
219  // add to StdHep map only if StdHep ID different from zero and if
220  // not Cerenkov (StdHep ID = gamma)
221  if ( 0 != pp->jetsetID() && "Tcherenkov" != pp->particle() )
222  { // try to add into StdHepID map
223  const int ID = pp->jetsetID() ;
224  // is this already in the map?
225  auto ifind = m_stdhepidmap.find( ID ) ;
226  if ( m_stdhepidmap.end() != ifind && ifind->second )
227  {
228  diff ( ifind->second , pp ) ;
229  m_replaced.insert( ifind->second->particle() ) ;
230  }
231  // put it into the map
232  m_stdhepidmap[ ID ] = pp ;
233  }
234  //
235  // add to Pythia map only if Pythia ID is different from
236  // zero ( StdHep id is always different from zero in this case )
237  if ( 0 != pp->pythiaID() &&
238  0 != pp->jetsetID() &&
239  "Tcherenkov" != pp->particle() )
240  { // try to add into PythiaID map
241  const int ID = pp->pythiaID() ;
242  // is this already in the map?
243  auto ifind = m_pythiaidmap.find( ID ) ;
244  if ( m_pythiaidmap.end() != ifind && ifind->second )
245  {
246  diff ( ifind->second , pp ) ;
247  m_replaced.insert( ifind->second ->particle() ) ;
248  }
249  // put it into the map
250  m_pythiaidmap[ ID ] = pp ;
251  }
252  //
253  return rebuild() ;
254 }
StatusCode rebuild()
rebuild "the linear container" from the map
int geantID() const
Get the GEANT3 ID.
MapName m_namemap
Map for particle names.
std::set< std::string > m_replaced
int jetsetID() const
Get the JETSET(StdHep) ID.
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
bool diff(const ParticleProperty *o, const ParticleProperty *n, const MSG::Level l=MSG::DEBUG) const
MapID m_idmap
Map for geant IDs.
const std::string & particle() const
Get the particle name.
int pythiaID() const
Get the Pythia ID.
MapPythiaID m_pythiaidmap
Map for Pythia Ids.
StatusCode Gaudi::ParticlePropertySvc::rebuild ( )
protected

rebuild "the linear container" from the map

Definition at line 414 of file ParticlePropertySvc.cpp.

415 {
416  std::set<mapped_type> local ;
417  m_vectpp.clear() ;
418  m_vectpp.reserve ( m_idmap.size() + 100 ) ;
419  // load information from maps into the set
420  _load_ ( m_idmap , local ) ;
421  _load_ ( m_namemap , local ) ;
422  _load_ ( m_stdhepidmap , local ) ;
423  _load_ ( m_pythiaidmap , local ) ;
424  // load information from set to the linear container vector
425  std::copy( std::begin(local), std::end(local), std::back_inserter(m_vectpp) );
426  return setAntiParticles() ;
427 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
MapName m_namemap
Map for particle names.
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
MapID m_idmap
Map for geant IDs.
StatusCode setAntiParticles()
helper (protected) function to set the valid particle<–>antiparticle relations
VectPP m_vectpp
Vector of all particle properties.
MapPythiaID m_pythiaidmap
Map for Pythia Ids.
StatusCode Gaudi::ParticlePropertySvc::setAntiParticles ( )
protected

helper (protected) function to set the valid particle<–>antiparticle relations

Returns
status code

Definition at line 389 of file ParticlePropertySvc.cpp.

390 {
391  // initialize particle<-->antiParticle relations
392  for ( auto& pp : m_vectpp )
393  {
394  if ( !pp ) { continue ; } // CONTINUE
395  const ParticleProperty* ap = anti ( pp ) ;
396  if ( ap ) { pp->setAntiParticle( ap ) ; }
397  }
398  return StatusCode::SUCCESS ;
399 }
A trivial class to hold information about a single particle properties.
const ParticleProperty * anti(const ParticleProperty *pp) const
helper (protected) function to find an antiparticle for the given particle ID (StdHepID) ...
VectPP m_vectpp
Vector of all particle properties.
int Gaudi::ParticlePropertySvc::size ( ) const
inlineoverride

Get the container size.

Definition at line 122 of file ParticlePropertySvc.h.

122 { return m_vectpp.size() ; };
VectPP m_vectpp
Vector of all particle properties.

Member Data Documentation

SmartIF<IFileAccess> Gaudi::ParticlePropertySvc::m_fileAccess
private

Definition at line 198 of file ParticlePropertySvc.h.

std::string Gaudi::ParticlePropertySvc::m_filename = "ParticleTable.txt"
private

Filename of the particle properties file.

Definition at line 183 of file ParticlePropertySvc.h.

MapID Gaudi::ParticlePropertySvc::m_idmap
private

Map for geant IDs.

Definition at line 189 of file ParticlePropertySvc.h.

MapName Gaudi::ParticlePropertySvc::m_namemap
private

Map for particle names.

Definition at line 190 of file ParticlePropertySvc.h.

Files Gaudi::ParticlePropertySvc::m_other
private

additional file names

Definition at line 184 of file ParticlePropertySvc.h.

std::set<std::unique_ptr<ParticleProperty> > Gaudi::ParticlePropertySvc::m_owned
private

Definition at line 195 of file ParticlePropertySvc.h.

Particles Gaudi::ParticlePropertySvc::m_particles
private

Definition at line 186 of file ParticlePropertySvc.h.

MapPythiaID Gaudi::ParticlePropertySvc::m_pythiaidmap
private

Map for Pythia Ids.

Definition at line 192 of file ParticlePropertySvc.h.

std::set<std::string> Gaudi::ParticlePropertySvc::m_replaced
private

Definition at line 196 of file ParticlePropertySvc.h.

MapStdHepID Gaudi::ParticlePropertySvc::m_stdhepidmap
private

Map for StdHep Ids.

Definition at line 191 of file ParticlePropertySvc.h.

VectPP Gaudi::ParticlePropertySvc::m_vectpp
private

Vector of all particle properties.

Definition at line 188 of file ParticlePropertySvc.h.


The documentation for this class was generated from the following files: