The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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>
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 */
30std::ostream& operator<<( std::ostream& stream, const Gaudi::ParticleProperty& pp ) { return pp.fillStream( stream ); }
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 )
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 )
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 */
80std::ostream& Gaudi::ParticleProperty::fillStream( std::ostream& s ) const {
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
155 std::ostringstream s;
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 */
173std::ostream& Gaudi::ParticleProperties::printAsTable_( const std::vector<const Gaudi::ParticleProperty*>& particles,
174 std::ostream& stream,
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; }
220 boost::format line( fmt );
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 */
319std::string Gaudi::ParticleProperties::printAsTable( const std::vector<const Gaudi::ParticleProperty*>& particles,
321 std::ostringstream s;
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 */
333MsgStream& Gaudi::ParticleProperties::printAsTable( const std::vector<const Gaudi::ParticleProperty*>& particles,
334 MsgStream& stream,
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 */
346std::ostream& Gaudi::Utils::toStream( const std::vector<const Gaudi::ParticleProperty*>& particles,
347 std::ostream& stream ) {
348 return Gaudi::ParticleProperties::printAsTable_( particles, 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 */
358std::ostream& Gaudi::ParticleProperties::printAsTable_( const std::vector<Gaudi::ParticleID>& particles,
359 std::ostream& stream,
361 //
362 if ( 0 == service ) { return Gaudi::Utils::toStream( particles, stream ); }
363
364 // convert list of ParticleIDs to list fo Particle properties:
365 std::vector<const Gaudi::ParticleProperty*> props;
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 */
381MsgStream& Gaudi::ParticleProperties::printAsTable( const std::vector<Gaudi::ParticleID>& particles, MsgStream& stream,
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 */
393std::string Gaudi::ParticleProperties::printAsTable( const std::vector<Gaudi::ParticleID>& particles,
395 std::ostringstream s;
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}
std::ostream & operator<<(std::ostream &stream, const Gaudi::ParticleProperty &pp)
standard output operator to the stream
implementation of various functions for streaming.
The abstract interface to Particle Property Service.
virtual const ParticleProperty * find(const std::string &name) const =0
Retrieve an object by name:
Holds PDG + LHCb extension particle code, following the PDG particle numbering scheme (pdg....
Definition ParticleID.h:43
int pid() const
Retrieve the PDG ID.
Definition ParticleID.h:54
A trivial class to hold information about a single particle properties.
bool selfcc() const
self-charge conjugated?
double charge() const
Get the particle charge.
std::string m_name
the name for the particle
double lifetime() const
Get the particle lifetime.
const std::string & evtGen() const
Get the EvtGen name.
const Gaudi::ParticleProperty * anti() const
get the pointer to the anti-particle
const Gaudi::ParticleID & particleID() const
get the particle ID
std::string toString() const
simple method for conversion into the string
double width() const
Get the particle natural width.
double m_charge
the charge for the particle
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 )
double maxWidth() const
Get the max width deviation.
double mass() const
Get the particle mass.
Gaudi::ParticleID m_pid
the PID for the particle
void setAntiParticle(const ParticleProperty *p)
set the pointer to the antiparticle
const Gaudi::ParticleID & pid() const
get the particle ID
const std::string & name() const
Get the particle name.
std::ostream & fillStream(std::ostream &s) const
the standard (a'la Gaudi) printout of the object
int pythia() const
Get the Pythia ID.
double m_tlife
the nominal proper lifetime for the particle
double m_mass
the nominal mass for the particle
double ctau() const
Get the particle proper lifetime in c*tau units.
int m_pythia
the ID for the particle used in Pythia generator
const Gaudi::ParticleProperty * m_anti
the pointer to the anti-particle
double m_maxWidth
The maximum width deviation.
std::string m_evtgen
the name of the particle for EvtGen program
double lifeTime() const
Get the particle lifetime.
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
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...
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
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
constexpr double TeV
constexpr double eV
constexpr double micrometer
constexpr double second
constexpr double MeV
constexpr double meter
constexpr double keV
constexpr double km
constexpr double mm
constexpr double cm
constexpr double ns
constexpr double GeV
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:304
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition ParticleID.h:191