The Gaudi Framework  master (37c0b60a)
ParticleProperty.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
12 #include <Gaudi/ParticleID.h>
13 #include <Gaudi/ParticleProperty.h>
14 #include <GaudiKernel/MsgStream.h>
16 #include <GaudiKernel/ToStream.h>
17 #include <boost/format.hpp>
18 #include <ostream>
19 
25 /* standard output operator to the stream
26  * @param stream the stream
27  * @param pp the particle property object
28  * @return the stream
29  */
31 /* full constructor, from all data (except the antiparticle )
32  * @param name the name for the particle
33  * @param pid the PID for the particle
34  * @param charge the charge of the particle
35  * @param mass the nominal mass of the particle
36  * @param tlife the nominal lifetime of the particle
37  * @param evtGen the name of particle in EvtGen program
38  * @param pythia the ID for the particle used in Pythia generator
39  * @param maxWidth the maximal width of the particle (used in generator)
40  */
42  const double mass, const double tlife, const double maxWidth,
43  const std::string& evtgen, const int pythia )
44  : m_name( name )
45  , m_pid( pid )
46  , m_charge( charge )
47  , m_mass( mass )
48  , m_tlife( tlife )
49  , m_maxWidth( maxWidth )
50  , m_evtgen( evtgen )
51  , m_pythia( pythia )
52  , m_anti( 0 ) {}
53 /* A bit simplified constructor, from all data (except the antiparticle )
54  *
55  * - "evtgen" is set from the regular "name"
56  * - "pythia" is set from the regular PID
57  *
58  * @param name the name for the particle
59  * @param pid the PID for the particle
60  * @param charge the charge of the particle
61  * @param mass the nominal mass of the particle
62  * @param tlife the nominal lifetime of the particle
63  * @param maxWidth the maximal width of the particle (used in generator)
64  */
66  const double mass, const double tlife, const double maxWidth )
67  : m_name( name )
68  , m_pid( pid )
69  , m_charge( charge )
70  , m_mass( mass )
71  , m_tlife( tlife )
72  , m_maxWidth( maxWidth )
73  , m_evtgen( name )
74  , m_pythia( pid.pid() )
75  , m_anti( 0 ) {}
76 /* the standard (a'la Gaudi) printout of the object
77  * @param s reference to the output stream
78  * @return reference to the output stream
79  */
81  //
82  typedef boost::format BF;
83  //
84  // name & code
85  s << BF( "%1$-14s %|16t| PDG:%2$9d," ) % name() % particleID().pid();
86 #ifdef __INTEL_COMPILER // Disable ICC remark
87 # pragma warning( disable : 1572 ) // Floating-point equality and inequality comparisons are unreliable
88 # pragma warning( push )
89 #endif
90  // charge
91  if ( 0 == charge() ) {
92  s << " Q: 0";
93  } else if ( 1.0 == charge() ) {
94  s << " Q: +1";
95  } else if ( -1.0 == charge() ) {
96  s << " Q: -1";
97  } else if ( 2.0 == charge() ) {
98  s << " Q: +2";
99  } else if ( -2.0 == charge() ) {
100  s << " Q: -2";
101  } else if ( 0.3 == charge() ) {
102  s << " Q:+1/3";
103  } else if ( -0.3 == charge() ) {
104  s << " Q:-1/3";
105  } else if ( 0.7 == charge() ) {
106  s << " Q:+2/3";
107  } else if ( -0.7 == charge() ) {
108  s << " Q:-2/3";
109  } else {
110  s << BF( " Q:%|+3.1f|," ) % float( charge() );
111  }
112 #ifdef __INTEL_COMPILER // Re-enable ICC remark
113 # pragma warning( pop )
114 #endif
115  // mass
116  if ( mass() < 1 * Gaudi::Units::MeV ) {
117  s << BF( ", mass:%|9.6g| keV" ) % ( mass() / Gaudi::Units::keV );
118  } else if ( mass() < 1 * Gaudi::Units::GeV ) {
119  s << BF( ", mass:%|9.6g| MeV" ) % ( mass() / Gaudi::Units::MeV );
120  } else {
121  s << BF( ", mass:%|9.6g| GeV" ) % ( mass() / Gaudi::Units::GeV );
122  }
123  // lifetime
124  if ( 1 * Gaudi::Units::km < ctau() ) {
125  s << ", lifetime: infinity ";
126  } else if ( 0 == lifeTime() ) {
127  } // ATTENTION!!
128  else if ( 1 * Gaudi::Units::meter < ctau() ) {
129  s << BF( ", ctau:%|12.6g| m" ) % ( ctau() / Gaudi::Units::meter );
130  } else if ( 1 * Gaudi::Units::cm < ctau() ) {
131  s << BF( ", ctau:%|11.6g| cm" ) % ( ctau() / Gaudi::Units::cm );
132  } else if ( 0.5 * Gaudi::Units::mm < ctau() ) {
133  s << BF( ", ctau:%|11.6g| mm" ) % ( ctau() / Gaudi::Units::mm );
134  } else if ( 0.1 * Gaudi::Units::micrometer < ctau() ) {
135  s << BF( ", ctau:%|11.6g| um" ) % ( ctau() / Gaudi::Units::micrometer );
136  } else if ( 1 * Gaudi::Units::GeV <= width() ) {
137  s << BF( ", width:%|10.6g| GeV" ) % ( width() / Gaudi::Units::GeV );
138  } else if ( 1 * Gaudi::Units::MeV <= width() ) {
139  s << BF( ", width:%|10.6g| MeV" ) % ( width() / Gaudi::Units::MeV );
140  } else if ( 1 * Gaudi::Units::keV <= width() ) {
141  s << BF( ", width:%|10.6g| keV" ) % ( width() / Gaudi::Units::keV );
142  } else if ( 1 * Gaudi::Units::eV <= width() ) {
143  s << BF( ", width:%|10.6g| eV" ) % ( width() / Gaudi::Units::eV );
144  } else {
145  s << BF( ", ltime:%|12.6g| ns" ) % ( lifetime() / Gaudi::Units::ns );
146  }
147  // Evt Gen name
148  if ( evtGen() != name() ) { s << BF( ", EvtGen: %|-10s|" ) % evtGen(); }
149  // pythia ID
150  if ( m_pid.pid() != pythia() ) { s << BF( ", Pythia: %|-9d|" ) % pythia(); }
151  return s;
152 }
153 // simple method for conversion into string
156  fillStream( s );
157  return s.str();
158 }
159 /* set the pointer to the antipartice
160  * @attention it is the only one "setter"
161  * @param p pointer to anti-particle
162  */
164 
165 /* print a list of properties in a form of the table
166  * @see Gaudi::ParticleProperty
167  * @param particles the list of particle properties
168  * @param stream the reference to the output stream
169  * @param service the service to extract global information
170  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
171  * @date 2008-08-03
172  */
175  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
176  std::string fmt, hdr;
177  //
178  if ( 0 != service ) {
179  fmt += " | %|-4.4s| "; // index
180  hdr += " | %|-4.4s| "; // index
181  }
182  //
183  fmt += "| %|-18.18s|"; // the name
184  fmt += "| %|12d| "; // PDGID
185  fmt += "| %|=4s| "; // charge
186  fmt += "| %|13.8g|"; // mass
187  fmt += " %|-3s| "; // unit
188  fmt += "| %|13.8g|"; // lifetime/gamma/ctau
189  fmt += " %|-3s| "; // unit
190  fmt += "| %|=10.4g| "; // maxwidth
191  fmt += "| %|=20.20s|"; // evtgen name
192  fmt += " | %|=10d| |"; // pythia ID
193  fmt += " %|=20.20d| |"; // antiparticle
194  //
195  hdr += "| %|=18.18s|"; // the name
196  hdr += "| %|=12.12s| "; // PDGID
197  hdr += "| %|=4.4s| "; // charge
198  hdr += "| %|=18.18s|"; // mass
199  // hdr += "%|=5.5s|" ; // unit
200  hdr += "| %|=18.18s|"; // lifetime/gamma/ctau
201  // hdr += "%|=5.5s|" ; // unit
202  hdr += "| %|=10.10g| "; // maxwidth
203  hdr += "| %|=20.20s|"; // evtgen name
204  hdr += " | %|=10.10s| |"; // pythia ID
205  hdr += " %|=20.20d| |"; // antiparticle
206 
207  boost::format header( hdr );
208  header.exceptions( boost::io::all_error_bits ^ ( boost::io::too_many_args_bit | boost::io::too_few_args_bit ) );
209 
210  if ( service ) { header % "#"; }
211  header % "Name" % "PdgID" % "Q" % "Mass" % "(c*)Tau/Gamma" % "MaxWidth" % "EvtGen" % "PythiaID" % "Antiparticle";
212 
213  const std::string hdrLine = header.str();
214  const std::string dashes = " " + std::string( hdrLine.size() - 1, '-' );
215  stream << dashes << std::endl << hdrLine << std::endl << dashes << std::endl;
216 
217  for ( auto ip = particles.begin(); particles.end() != ip; ++ip ) {
218  const Gaudi::ParticleProperty* pp = *ip;
219  if ( 0 == pp ) { continue; }
221  line.exceptions( boost::io::all_error_bits ^ ( boost::io::too_many_args_bit | boost::io::too_few_args_bit ) );
222  //
223  if ( 0 != service ) {
224  size_t index = Gaudi::ParticleProperties::index( pp, service );
225  if ( 0 == index ) {
226  line % "?";
227  } else {
228  line % index;
229  }
230  }
231  //
232  line % pp->name() // name
233  % pp->particleID().pid(); // PDG-ID
234  //
235 #ifdef __INTEL_COMPILER // Disable ICC remark
236 # pragma warning( disable : 1572 ) // Floating-point equality and inequality comparisons are unreliable
237 # pragma warning( push )
238 #endif
239  if ( 0 == pp->charge() ) {
240  line % "0";
241  } else if ( 0.3 == pp->charge() ) {
242  line % "+1/3";
243  } else if ( -0.3 == pp->charge() ) {
244  line % "-1/3";
245  } else if ( 0.7 == pp->charge() ) {
246  line % "+2/3";
247  } else if ( -0.7 == pp->charge() ) {
248  line % "-2/3";
249  } else {
250  line % pp->charge();
251  }
252 #ifdef __INTEL_COMPILER // Re-enable ICC remark
253 # pragma warning( pop )
254 #endif
255  //
256  // mass
257  if ( pp->mass() < 1 * Gaudi::Units::keV ) {
258  line % ( pp->mass() / Gaudi::Units::eV ) % "eV";
259  } else if ( pp->mass() < 1 * Gaudi::Units::MeV ) {
260  line % ( pp->mass() / Gaudi::Units::keV ) % "keV";
261  } else if ( pp->mass() < 1 * Gaudi::Units::GeV ) {
262  line % ( pp->mass() / Gaudi::Units::MeV ) % "MeV";
263  } else if ( pp->mass() < 1 * Gaudi::Units::TeV ) {
264  line % ( pp->mass() / Gaudi::Units::GeV ) % "GeV";
265  } else {
266  line % ( pp->mass() / Gaudi::Units::TeV ) % "TeV";
267  }
268  // lifetime/width/ctau
269  const double ctau = pp->ctau();
270  const double width = pp->width();
271  const double ltime = pp->lifetime();
272  if ( 3600 * Gaudi::Units::second < ltime ) {
273  line % "stable" % "";
274  } else if ( 1 * Gaudi::Units::second < ltime ) {
275  line % ( ltime / Gaudi::Units::second ) % "s";
276  } else if ( 1 * Gaudi::Units::meter < ctau ) {
277  line % ( ctau / Gaudi::Units::meter ) % "m";
278  } else if ( 1 * Gaudi::Units::cm < ctau ) {
279  line % ( ctau / Gaudi::Units::cm ) % "cm";
280  } else if ( 0.5 * Gaudi::Units::mm < ctau ) {
281  line % ( ctau / Gaudi::Units::mm ) % "mm";
282  } else if ( 0.1 * Gaudi::Units::micrometer < ctau ) {
283  line % ( ctau / Gaudi::Units::micrometer ) % "um";
284  } else if ( 1 * Gaudi::Units::GeV < width ) {
285  line % ( width / Gaudi::Units::GeV ) % "GeV";
286  } else if ( 1 * Gaudi::Units::MeV < width ) {
287  line % ( width / Gaudi::Units::MeV ) % "MeV";
288  } else if ( 1 * Gaudi::Units::keV < width ) {
289  line % ( width / Gaudi::Units::keV ) % "keV";
290  } else if ( 1 * Gaudi::Units::eV < width ) {
291  line % ( width / Gaudi::Units::eV ) % "eV";
292  } else {
293  line % ( ltime / Gaudi::Units::ns ) % "ns";
294  }
295  //
296  line % pp->maxWidth() % pp->evtGen() % pp->pythia();
297  //
298  const Gaudi::ParticleProperty* const anti = pp->antiParticle();
299  //
300  if ( 0 == anti ) {
301  line % "-";
302  } else if ( anti == pp ) {
303  line % "self-cc";
304  } else {
305  line % anti->name();
306  }
307  //
308  stream << line << std::endl;
309  }
310  return stream << dashes << std::endl;
311 }
312 /* print a list of properties in a form of the table
313  * @see Gaudi::ParticleProperty
314  * @param particles the list of particle properties
315  * @param service the service to extract global information
316  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
317  * @date 2008-08-03
318  */
320  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
322  printAsTable_( particles, s, service );
323  return s.str();
324 }
325 /* print a list of properties in a form of the table
326  * @see Gaudi::ParticleProperty
327  * @param particles the list of particle properties
328  * @param stream the reference to the output stream
329  * @param service the service to extract global information
330  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
331  * @date 2008-08-03
332  */
334  MsgStream& stream,
335  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
336  if ( stream.isActive() ) { printAsTable_( particles, stream.stream(), service ); }
337  return stream;
338 }
339 /* print a list of particle properties as formatted table
340  * @see Gaudi::ParticleProperty
341  * @param particles the list of particle properties
342  * @param stream the reference to the output stream
343  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
344  * @date 2008-08-03
345  */
347  std::ostream& stream ) {
349 }
350 /* print properties in a form of the table
351  * @param particles (INPUT) list of particles
352  * @param stream (UPDATE) the stream
353  * @param service (INPUT) pointer to particle property service
354  * @return the stream
355  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
356  * @date 2010-01-04
357  */
360  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
361  //
362  if ( 0 == service ) { return Gaudi::Utils::toStream( particles, stream ); }
363 
364  // convert list of ParticleIDs to list fo Particle properties:
366  for ( std::vector<Gaudi::ParticleID>::const_iterator ipid = particles.begin(); particles.end() != ipid; ++ipid ) {
367  const Gaudi::ParticleProperty* pp = service->find( *ipid );
368  if ( 0 == pp ) { continue; }
369  props.push_back( pp );
370  }
371  return printAsTable_( props, stream, service );
372 }
373 /* print properties in a form of the table
374  * @param particles (INPUT) list of particles
375  * @param stream (UPDATE) the stream
376  * @param service (INPUT) pointer to particle property service
377  * @return the stream
378  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
379  * @date 2010-01-04
380  */
382  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
383  if ( stream.isActive() ) { printAsTable_( particles, stream.stream(), service ); }
384  return stream;
385 }
386 /* print properties in a form of the table
387  * @param particles (INPUT) list of particles
388  * @param service (INPUT) pointer to particle property service
389  * @return string-representation
390  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
391  * @date 2010-01-04
392  */
394  const Gaudi::Interfaces::IParticlePropertySvc* service ) {
396  printAsTable_( particles, s, service );
397  return s.str();
398 }
400  if ( 0 == p ) { return 0; }
401  //
402  if ( p->selfcc() || 0 <= p->particleID().pid() ) { return p; }
403  //
404  const Gaudi::ParticleProperty* a = p->anti();
405  if ( 0 != a && 0 <= a->particleID().pid() ) { return a; }
406  //
407  return p; // should it be 0 ?
408 }
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
Gaudi::Units::keV
constexpr double keV
Definition: SystemOfUnits.h:178
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector
STL class.
std::string::size
T size(T... args)
check_ParticleID.props
props
Definition: check_ParticleID.py:21
Gaudi::Units::GeV
constexpr double GeV
Definition: SystemOfUnits.h:179
Gaudi::ParticleProperty::toString
std::string toString() const
simple method for conversion into the string
Definition: ParticleProperty.cpp:154
ParticleProperty
Definition: ParticleProperty.py:1
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::Utils::Histos::Formats::header
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
Definition: HistoTableFormat.cpp:186
Gaudi::ParticleProperty::name
const std::string & name() const
Get the particle name.
Definition: ParticleProperty.h:80
Gaudi::Units::TeV
constexpr double TeV
Definition: SystemOfUnits.h:180
Gaudi::Units::meter
constexpr double meter
Definition: SystemOfUnits.h:69
ParticleID.h
Gaudi::ParticleProperty::anti
const Gaudi::ParticleProperty * anti() const
get the pointer to the anti-particle
Definition: ParticleProperty.h:106
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
Gaudi::ParticleProperty::ParticleProperty
ParticleProperty(const std::string &name, const Gaudi::ParticleID &pid, const double charge, const double mass, const double tlife, const double maxWidth, const std::string &evtgen, const int pythia)
full constructor, from all data (except the antiparticle )
Definition: ParticleProperty.cpp:41
IParticlePropertySvc.h
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:139
Gaudi::ParticleProperty::fillStream
std::ostream & fillStream(std::ostream &s) const
the standard (a'la Gaudi) printout of the object
Definition: ParticleProperty.cpp:80
Gaudi::Units::mm
constexpr double mm
Definition: SystemOfUnits.h:100
ToStream.h
Gaudi::ParticleProperties::printAsTable
GAUDI_API std::string printAsTable(const std::vector< const Gaudi::ParticleProperty * > &particles, const Gaudi::Interfaces::IParticlePropertySvc *service=0)
print a list of properties in a form of the table
Definition: ParticleProperty.cpp:319
SystemOfUnits.h
std::ostream
STL class.
Gaudi::Units::ns
constexpr double ns
Definition: SystemOfUnits.h:152
Gaudi::ParticleProperties::printAsTable_
GAUDI_API std::ostream & printAsTable_(const std::vector< const Gaudi::ParticleProperty * > &particles, std::ostream &stream, const Gaudi::Interfaces::IParticlePropertySvc *service=0)
print a list of properties in a form of the table
Definition: ParticleProperty.cpp:173
Gaudi::Units::micrometer
constexpr double micrometer
Definition: SystemOfUnits.h:79
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Gaudi::ParticleProperty
Definition: ParticleProperty.h:37
MsgStream
Definition: MsgStream.h:33
std::ostringstream
STL class.
Gaudi::ParticleProperty::particleID
const Gaudi::ParticleID & particleID() const
get the particle ID
Definition: ParticleProperty.h:82
Gaudi::Units::cm
constexpr double cm
Definition: SystemOfUnits.h:104
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::endl
T endl(T... args)
Gaudi::ParticleID::pid
int pid() const
Retrieve the PDG ID.
Definition: ParticleID.h:54
operator<<
std::ostream & operator<<(std::ostream &stream, const Gaudi::ParticleProperty &pp)
standard output operator to the stream
Definition: ParticleProperty.cpp:30
std::vector::begin
T begin(T... args)
Gaudi::ParticleProperties::particleID
const Gaudi::ParticleID particleID(const size_t index, const Gaudi::Interfaces::IParticlePropertySvc *service)
the inverse mapping of the integer sequential number onto Gaudi::ParticleID object
Definition: IParticlePropertySvc.cpp:117
Gaudi::Utils::toStream
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:299
fmt
Gaudi::Interfaces::IParticlePropertySvc::find
virtual const ParticleProperty * find(const std::string &name) const =0
Retrieve an object by name:
Gaudi::ParticleID
Definition: ParticleID.h:43
Gaudi::ParticleProperty::setAntiParticle
void setAntiParticle(const ParticleProperty *p)
set the pointer to the antiparticle
Definition: ParticleProperty.cpp:163
Gaudi::Units::km
constexpr double km
Definition: SystemOfUnits.h:112
Gaudi::ParticleProperty::selfcc
bool selfcc() const
self-charge conjugated?
Definition: ParticleProperty.h:109
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:198
std::vector::end
T end(T... args)
Gaudi::Units::eV
constexpr double eV
Definition: SystemOfUnits.h:177
Gaudi::Units::MeV
constexpr double MeV
Definition: SystemOfUnits.h:176
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
ParticleProperty.h
MsgStream.h
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39