The Gaudi Framework  master (37c0b60a)
EvtCollectionSelector.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 \***********************************************************************************/
15 #include <GaudiKernel/NTuple.h>
17 #include <GaudiKernel/Selector.h>
18 #include <GaudiKernel/System.h>
19 #include <GaudiKernel/ToStream.h>
20 #include <GaudiTestSuite/MyTrack.h>
21 #include <cmath>
22 
23 #ifdef __ICC
24 // disable icc warning #1125: function "ISelectStatement::operator()(void *)"
25 // is hidden by "Gaudi::TestSuite::EvtCollectionSelector::operator()"
26 // -- virtual function override intended?
27 # pragma warning( disable : 1125 )
28 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
29 # pragma warning( disable : 1572 )
30 #endif
31 namespace Gaudi {
32  namespace TestSuite {
40  protected:
43 #ifndef NO_TRKMOMFIX
45 #endif
47  int m_cut = 10;
48 
49  public:
51 
55  sc = nt->item( "TrkMom", m_trkMom );
56  if ( !sc.isSuccess() ) {
57  std::cerr << "EvtCollectionSelector: initialize " << sc << std::endl;
58  std::cerr << "TrkMom" << std::endl;
59  return sc;
60  }
61 #ifndef NO_TRKMOMFIX
62  sc = nt->item( "TrkMomFix", m_trkMomFixed );
63  if ( !sc.isSuccess() ) {
64  std::cerr << "EvtCollectionSelector: initialize " << sc << std::endl;
65  std::cerr << "TrkMomFix" << std::endl;
66  return sc;
67  }
68 #endif
69  sc = nt->item( "Ntrack", m_ntrack );
70  if ( !sc.isSuccess() ) {
71  std::cerr << "EvtCollectionSelector: initialize " << sc << std::endl;
72  std::cerr << "Ntrack" << std::endl;
73  return sc;
74  }
75 
76  sc = nt->item( "Track", m_track );
77  if ( !sc.isSuccess() ) {
78  std::cerr << "EvtCollectionSelector: initialize " << sc << std::endl;
79  std::cerr << "Track" << std::endl;
80  return sc;
81  }
82 
83  return sc;
84  }
85 
86  using NTuple::Selector::operator(); // avoid hiding base-class methods
88  bool operator()( NTuple::Tuple* /* nt */ ) override {
89  const int n = m_ntrack;
90  std::cout << System::typeinfoName( typeid( *this ) ) << "\t -> #tracks : " << n << std::endl
91  << System::typeinfoName( typeid( *this ) ) << "\t -> Momenta(Var): ";
92  for ( int i = 0; i < std::min( 5, n ); ++i ) { std::cout << "[" << i << "]=" << m_trkMom[i] << " "; }
93 #ifndef NO_TRKMOMFIX
94  std::cout << std::endl << System::typeinfoName( typeid( *this ) ) << "\t -> Momenta(Fix): ";
95  for ( int i = 0; i < std::min( 5, n ); ++i ) { std::cout << "[" << i << "]=" << m_trkMomFixed[i] << " "; }
96  for ( int i = 5; i < 99; ++i ) {
98  std::cout << "[" << i << "]= Error in Fixed momentum" << std::endl;
99  }
100  }
101 #endif
102  std::cout << std::endl;
103  std::cout << System::typeinfoName( typeid( *this ) );
104  if ( 0 != *m_track ) {
105  std::cout << "\t -> Track : "
106  << " px=" << ( *m_track )->px() << " py=" << ( *m_track )->py() << " pz=" << ( *m_track )->pz()
107  << std::endl;
108  } else {
109  std::cout << " Track* is NULL" << std::endl;
110  }
111  //
112  const bool selected = m_cut < m_ntrack && 0 != *m_track;
113  std::cout << System::typeinfoName( typeid( *this ) ) << " SELECTED : ";
115  //
116  return selected; // RETURN
117  }
118  };
120  } // namespace TestSuite
121 } // end of namespace Gaudi
122 
123 namespace Gaudi::Examples {
126  };
128 } // namespace Gaudi::Examples
Selector.h
Gaudi::TestSuite::EvtCollectionSelector::m_trkMomFixed
NTuple::Array< float > m_trkMomFixed
Definition: EvtCollectionSelector.cpp:44
Gaudi::TestSuite::EvtCollectionSelector::m_trkMom
NTuple::Array< float > m_trkMom
Definition: EvtCollectionSelector.cpp:42
MyTrack.h
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Gaudi::TestSuite::EvtCollectionSelector::m_track
NTuple::Item< Gaudi::TestSuite::MyTrack * > m_track
Definition: EvtCollectionSelector.cpp:46
System.h
TestSuite
#define TestSuite
Definition: MakeAndConsume.cpp:658
Gaudi::TestSuite::EvtCollectionSelector
Definition: EvtCollectionSelector.cpp:39
Gaudi::TestSuite::EvtCollectionSelector::m_cut
int m_cut
Definition: EvtCollectionSelector.cpp:47
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:315
ObjectFactory.h
ToStream.h
NTuple::Tuple::item
StatusCode item(const std::string &name, Item< TYPE > &result)
Locate a scalar Item of data to the N tuple type safe.
Definition: NTuple.h:472
Gaudi::Examples::EvtCollectionSelector
Definition: EvtCollectionSelector.cpp:124
Gaudi::TestSuite::EvtCollectionSelector::m_ntrack
NTuple::Item< int > m_ntrack
Definition: EvtCollectionSelector.cpp:41
Gaudi::Examples
Definition: Collision.h:20
StatusCode
Definition: StatusCode.h:65
NTuple::Selector
NTuple Selector class.
Definition: Selector.h:39
std::cerr
NTuple.h
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
cpluginsvc.n
n
Definition: cpluginsvc.py:234
std::numeric_limits::epsilon
T epsilon(T... args)
Gaudi::TestSuite::EvtCollectionSelector::operator()
bool operator()(NTuple::Tuple *) override
Specialized callback for NTuples.
Definition: EvtCollectionSelector.cpp:88
std::min
T min(T... args)
NTuple::Selector::Selector
Selector(IInterface *svc)
Standard constructor.
Definition: Selector.h:50
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::endl
T endl(T... args)
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:388
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
Gaudi::TestSuite::EvtCollectionSelector::initialize
StatusCode initialize(NTuple::Tuple *nt) override
Initialization.
Definition: EvtCollectionSelector.cpp:53
NTuple::Array< float >
EvtCollectionSelector
#define EvtCollectionSelector
Definition: EvtExtCollectionSelector.cpp:12
DECLARE_OBJECT_FACTORY
#define DECLARE_OBJECT_FACTORY(x)
Definition: ObjectFactory.h:25
NTuple::Item< int >