The Gaudi Framework  master (37c0b60a)
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
23  return StatusCode::SUCCESS;
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
46  const Gaudi::Interfaces::IParticlePropertySvc* svc = ppSvc();
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
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
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
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
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
161  log << endmsg;
162  }
163 
164  return StatusCode::SUCCESS;
165 }
166 
std::string
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
Gaudi::TestSuite::PartPropAlg
an algorithm to test the particle property service
Definition: PartPropAlg.h:27
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
PartPropAlg.h
std::vector
STL class.
ISvcLocator
Definition: ISvcLocator.h:46
std::back_inserter
T back_inserter(T... args)
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
GaudiException
Definition: GaudiException.h:31
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::TestSuite::PartPropAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: PartPropAlg.cpp:44
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
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
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Units::micrometer
constexpr double micrometer
Definition: SystemOfUnits.h:79
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::ParticleProperty
Definition: ParticleProperty.h:37
MsgStream
Definition: MsgStream.h:33
Gaudi::TestSuite::PartPropAlg::initialize
StatusCode initialize() override
Definition: PartPropAlg.cpp:18
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::endl
T endl(T... args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Interfaces::IParticlePropertySvc::get
OUTPUT get(const PREDICATE &cut, OUTPUT output) const
get the properties according to some criteria
Definition: IParticlePropertySvc.h:492
EventContext
Definition: EventContext.h:34
Gaudi::TestSuite::PartPropAlg::PartPropAlg
PartPropAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PartPropAlg.cpp:15
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
Gaudi::TestSuite::PartPropAlg::ppSvc
const Gaudi::Interfaces::IParticlePropertySvc * ppSvc() const
Definition: PartPropAlg.cpp:33
Gaudi::TestSuite::PartPropAlg::finalize
StatusCode finalize() override
Definition: PartPropAlg.cpp:26