Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ExtendedEvtCol.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 // ============================================================================
12 // Include files
13 // =============================================================================
14 // STD& STL
15 // =============================================================================
16 #include <algorithm>
17 #include <cmath>
18 #include <functional>
19 #include <math.h>
20 #include <numeric>
21 // =============================================================================
22 // GaudiKernel
23 // =============================================================================
24 #include "GaudiKernel/IRegistry.h"
25 // =============================================================================
26 // GaudiAlg
27 // =============================================================================
28 #include "GaudiAlg/GaudiTupleAlg.h"
29 // =============================================================================
30 // Local
31 // =============================================================================
32 #include "GaudiExamples/Event.h"
33 #include "GaudiExamples/MyTrack.h"
34 // =============================================================================
35 namespace Gaudi {
36  namespace Examples {
44  class ExtendedEvtCol : public GaudiTupleAlg {
45  public:
47  StatusCode execute() override;
48 
49  public:
56  setProperty( "NTupleProduce", false ).ignore();
57  setProperty( "NTuplePrint", false ).ignore();
58  setProperty( "HistogramProduce", false ).ignore();
59  setProperty( "HistogramPrint", false ).ignore();
60  setProperty( "PropertiesPrint", true ).ignore();
61  setProperty( "TypePrint", false ).ignore();
62  setProperty( "EvtColsProduce", true ).ignore();
63  setProperty( "EvtColsPrint", true ).ignore();
64  }
65 
66  private:
67  Gaudi::Property<std::string> m_tracks{ this, "Tracks", "MyTracks" };
68  };
69  } // end of namespace Examples
70 } // end of namespace Gaudi
71 // ============================================================================
73 // ============================================================================
76 // ============================================================================
78 // ============================================================================
79 namespace {
81  inline double trkMomentum( const Gaudi::Examples::MyTrack* track ) {
82  if ( !track ) { return 0; }
83  return ::sqrt( track->px() * track->px() + track->py() * track->py() + track->pz() * track->pz() );
84  }
85 } // namespace
86 // ============================================================================
88 // ============================================================================
90  // get the event
91  auto event = get<DataObject>( "/Event" );
92  // get the tracks
93  auto tracks = get<MyTrackVector>( m_tracks );
94 
95  // book/retreieve the Event Tag Collection:
96  auto tuple = evtCol( TupleID( "MyCOL1" ), "Trivial Event Tag Collection" );
97 
99  tuple->column( "Address", event->registry()->address() ).ignore();
100 
102  tuple
103  ->farray( "TrkMom", trkMomentum, "px", &MyTrack::px, "py", &MyTrack::py, "pz", &MyTrack::pz, tracks->begin(),
104  tracks->end(), "Ntrack", 5000 )
105  .ignore();
106 
107  // evaluate the total energy of all tracks:
108  double energy =
109  std::accumulate( tracks->begin(), tracks->end(), 0.0,
110  [&]( double e, const Gaudi::Examples::MyTrack* track ) { return e + trkMomentum( track ); } );
111 
112  tuple->column( "Energy", energy ).ignore();
113 
114  // put a track into Event Tag Collection
115  tuple->put( "Track", !tracks->empty() ? *( tracks->begin() ) : nullptr ).ignore();
116 
117  return tuple->write();
118 }
119 // ============================================================================
121 // ============================================================================
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
std::string
STL class.
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:528
Gaudi::Examples::ExtendedEvtCol::execute
StatusCode execute() override
the only one essential method: execute the algorithm
Definition: ExtendedEvtCol.cpp:89
GaudiTuples< GaudiHistoAlg >::TupleID
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Examples::ExtendedEvtCol::ExtendedEvtCol
ExtendedEvtCol(const std::string &name, ISvcLocator *pSvc)
standard constructor
Definition: ExtendedEvtCol.cpp:54
Gaudi::Examples::ExtendedEvtCol
Definition: ExtendedEvtCol.cpp:44
GaudiTupleAlg
Definition: GaudiTupleAlg.h:51
Gaudi::Examples::MyTrack::pz
float pz() const
Accessors: Retrieve z-component of the track momentum.
Definition: MyTrack.h:98
GaudiTupleAlg.h
StatusCode
Definition: StatusCode.h:65
MyTrack.h
std::accumulate
T accumulate(T... args)
GaudiTuples< GaudiHistoAlg >::evtCol
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
Definition: GaudiTuples.icpp:134
IRegistry.h
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Event.h
Gaudi::Examples::MyTrack
Definition: MyTrack.h:53
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Examples::MyTrack::px
float px() const
Accessors: Retrieve x-component of the track momentum.
Definition: MyTrack.h:94
Gaudi::Examples::ExtendedEvtCol::m_tracks
Gaudi::Property< std::string > m_tracks
Definition: ExtendedEvtCol.cpp:67
Gaudi::Examples::MyTrack::py
float py() const
Accessors: Retrieve y-component of the track momentum.
Definition: MyTrack.h:96
Gaudi::Property< std::string >