The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
PartPropAlg.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2019 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\***********************************************************************************/
11#include <iostream>
12
13#include "PartPropAlg.h"
14
16 : Gaudi::Algorithm( name, pSvcLocator ) {}
17
19 StatusCode sc = Algorithm::initialize(); // initialize the base
20 if ( sc.isFailure() ) { return sc; }
21 // locate particle property service
24}
25
27 // release the aquired service
28 m_ppSvc.reset();
29 return Algorithm::finalize(); // finalize the base
30}
31
32// locate the new particle property service
34 if ( !m_ppSvc ) {
35 m_ppSvc = service( "Gaudi::ParticlePropertySvc", true );
36 if ( !m_ppSvc ) {
37 throw GaudiException( "Service [Gaudi::ParticlePropertySvc] not found", name(), StatusCode::FAILURE );
38 }
39 }
40 return m_ppSvc.get();
41}
42
43// execute the algorithm
45 // get the service
47
48 if ( !svc ) { return StatusCode::FAILURE; }
49 if ( !ctx.valid() ) { return StatusCode::FAILURE; }
50
51 // avoid long names
53
54 MsgStream log( msgSvc(), name() );
55
56 { // get all invalid
57 PPs invalid;
58 svc->get(
59 // functor : invalid
60 []( const Gaudi::ParticleProperty* pp ) { return !pp->pid().isValid(); },
61 // output
62 std::back_inserter( invalid ) );
63 // print as the table
64 // header ?
65 log << MSG::INFO << " # Invalid = " << invalid.size() << std::endl;
66 // content
67 Gaudi::ParticleProperties::printAsTable( invalid, log, svc );
68 log << endmsg;
69 }
70
71 { // get all not from quarks
72 PPs noquarks;
73 svc->get(
74 // functor : has no quarks
75 []( const Gaudi::ParticleProperty* pp ) { return !pp->pid().hasQuarks(); },
76 // output
77 std::back_inserter( noquarks ) );
78 // print as the table
79 // header ?
80 log << MSG::INFO << " # Has no quarks = " << noquarks.size() << std::endl;
81 // content
82 Gaudi::ParticleProperties::printAsTable( noquarks, log, svc );
83 log << endmsg;
84 }
85
86 { // get all 'fundamental'
87 PPs fundamental;
88 svc->get(
89 // functor : fundamental
90 []( const Gaudi::ParticleProperty* pp ) {
91 auto fid = pp->pid().fundamentalID();
92 return 0 < fid && 100 >= fid;
93 },
94 // output
95 std::back_inserter( fundamental ) );
96 // print as the table
97 // header ?
98 log << MSG::INFO << " # Fundamental (0,100] = " << fundamental.size() << std::endl;
99 // content
100 Gaudi::ParticleProperties::printAsTable( fundamental, log, svc );
101 log << endmsg;
102 }
103
104 { // get all leptons
105 PPs leptons;
106 svc->get(
107 // functor : lepton
108 []( const Gaudi::ParticleProperty* pp ) { return pp->pid().isLepton(); },
109 // output
110 std::back_inserter( leptons ) );
111 // print as the table
112 // header ?
113 log << MSG::INFO << " # Leptons = " << leptons.size() << std::endl;
114 // content
115 Gaudi::ParticleProperties::printAsTable( leptons, log, svc );
116 log << endmsg;
117 }
118
119 { // get all long-lived (>1um)
120 PPs longlived;
121 svc->get(
122 // functor : ctau>1um
123 []( const Gaudi::ParticleProperty* pp ) { return pp->ctau() > 1 * Gaudi::Units::micrometer; },
124 // output
125 std::back_inserter( longlived ) );
126 // print as the table
127 // header ?
128 log << MSG::INFO << " # Long-lived(>1mu) = " << longlived.size() << std::endl;
129 // content
130 Gaudi::ParticleProperties::printAsTable( longlived, log, svc );
131 log << endmsg;
132 }
133
134 { // get all nuclea
135 PPs nuclea;
136 svc->get(
137 // functor : nucleus
138 []( const Gaudi::ParticleProperty* pp ) { return pp->pid().isNucleus(); },
139 // output
140 std::back_inserter( nuclea ) );
141 // print as the table
142 // header ?
143 log << MSG::INFO << " # Nuclea = " << nuclea.size() << std::endl;
144 // content
145 Gaudi::ParticleProperties::printAsTable( nuclea, log, svc );
146 log << endmsg;
147 }
148
149 { // get all beauty baryons
150 PPs bbaryons;
151 svc->get(
152 // functor : beauty & baryon
153 []( const Gaudi::ParticleProperty* pp ) { return pp->pid().hasBottom() && pp->pid().isBaryon(); },
154 // output
155 std::back_inserter( bbaryons ) );
156 // print as the table
157 // header ?
158 log << MSG::INFO << " # Beauty Baryons = " << bbaryons.size() << std::endl;
159 // content
160 Gaudi::ParticleProperties::printAsTable( bbaryons, log, svc );
161 log << endmsg;
162 }
163
164 return StatusCode::SUCCESS;
165}
166
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
This class represents an entry point to all the event specific data.
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181
const std::string & name() const override
The identifying name of the algorithm object.
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name")
The abstract interface to Particle Property Service.
OUTPUT get(const PREDICATE &cut, OUTPUT output) const
get the properties according to some criteria
std::vector< const Gaudi::ParticleProperty * > ParticleProperties
the actual type of (ordered) container of particle properties
A trivial class to hold information about a single particle properties.
an algorithm to test the particle property service
Definition PartPropAlg.h:26
StatusCode finalize() override
SmartIF< Gaudi::Interfaces::IParticlePropertySvc > m_ppSvc
Definition PartPropAlg.h:38
StatusCode initialize() override
const Gaudi::Interfaces::IParticlePropertySvc * ppSvc() const
StatusCode execute(const EventContext &ctx) const override
PartPropAlg(const std::string &name, ISvcLocator *pSvcLocator)
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
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
constexpr double micrometer
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
@ INFO
Definition IMessageSvc.h:22