Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TupleAlg3.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 <utility>
17 // ============================================================================
18 // GaudiKernel
19 // ============================================================================
23 // ============================================================================
24 // GaudiAlg
25 // ============================================================================
26 #include "GaudiAlg/GaudiTupleAlg.h"
27 #include "GaudiAlg/Tuple.h"
28 // ============================================================================
29 
30 // ============================================================================
39 // ============================================================================
40 
41 class TupleAlg3 : public GaudiTupleAlg {
42 public:
44  StatusCode initialize() override {
46  if ( sc.isFailure() ) { return sc; }
47  // check for random numbers service
48  Assert( randSvc() != 0, "Random Service is not available!" );
49  //
50  return StatusCode::SUCCESS;
51  }
55  StatusCode execute() override;
60  using GaudiTupleAlg::GaudiTupleAlg;
61 
62 private:
63  // copy constructor is disabled
64  TupleAlg3( const TupleAlg3& );
65  // assignement op[erator is disabled
67 };
68 // ============================================================================
70 // ============================================================================
74 // ============================================================================
77  using namespace Tuples;
78  using namespace Gaudi::Units;
79 
80  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
81  Rndm::Numbers flat( randSvc(), Rndm::Flat( -10.0, 10.0 ) );
82  Rndm::Numbers expo( randSvc(), Rndm::Exponential( 1.0 ) );
83  Rndm::Numbers breit( randSvc(), Rndm::BreitWigner( 0.0, 1.0 ) );
84  Rndm::Numbers poisson( randSvc(), Rndm::Poisson( 2.0 ) );
85  Rndm::Numbers binom( randSvc(), Rndm::Binomial( 8, 0.25 ) );
86 
87  // ==========================================================================
88  // book and fill simple NTuple with Lorentz Vectors
89  // ==========================================================================
90  {
91  Tuple tuple = nTuple( "LorentzVectors", "Tuple with Lorentz Vectors " );
92 
93  typedef ROOT::Math::PxPyPzEVector LV;
94 
95  LV lv;
96 
97  lv.SetPx( gauss() );
98  lv.SetPy( gauss() );
99  lv.SetPz( flat() );
100  lv.SetE( ::sqrt( lv.P2() + 1 * GeV * GeV ) );
101 
102  LV lv2 = lv;
103  lv2.SetE( ::sqrt( lv.P2() + 4 * GeV * GeV ) );
104 
105  tuple->column( "lv1", lv ).ignore();
106  tuple->column( "lv2", lv2 ).ignore();
107 
108  tuple->write().ignore();
109  }
110  // ==========================================================================
111  // book and fill simple NTuple with 3D Vectors & Points
112  // ==========================================================================
113  {
114 
115  Tuple tuple = nTuple( "Vectors-3D", "Tuple with Vectors in 3D " );
116 
117  typedef ROOT::Math::XYZPoint P3;
118  typedef ROOT::Math::XYZVector V3;
119 
120  P3 p1;
121  p1.SetX( flat() );
122  p1.SetY( flat() );
123  p1.SetZ( flat() );
124 
125  tuple->column( "p3", p1 ).ignore();
126 
127  V3 p2;
128  p2.SetX( gauss() );
129  p2.SetY( gauss() );
130  p2.SetZ( gauss() );
131 
132  tuple->column( "v3", p2 ).ignore();
133 
134  tuple->write().ignore();
135  }
136  // ==========================================================================
137  // book and fill simple NTuple with Math-vectors
138  // ==========================================================================
139  {
140 
141  Tuple tuple = nTuple( "Math-vectors", "Tuple with Math Vectors" );
142 
143  ROOT::Math::SVector<float, 4> v1;
144  ROOT::Math::SVector<double, 25> v2;
145  ROOT::Math::SVector<long double, 50> v3;
146 
147  std::generate( v1.begin(), v1.end(), gauss );
148  std::generate( v2.begin(), v2.end(), breit );
149  std::generate( v3.begin(), v3.end(), flat );
150 
151  tuple->array( "g", v1 ).ignore();
152  tuple->array( "b", v2 ).ignore();
153  tuple->array( "f", v3 ).ignore();
154 
155  tuple->write().ignore();
156  }
157  // ==========================================================================
158  // book and fill simple NTuple with S-matrices
159  // ==========================================================================
160  {
161 
162  Tuple tuple = nTuple( "S-matrices", "Tuple with S-matrices" );
163 
164  ROOT::Math::SMatrix<float, 4> v1;
165  ROOT::Math::SMatrix<double, 3, 15> v2;
166  ROOT::Math::SMatrix<long double, 5, 5, ROOT::Math::MatRepSym<long double, 5>> v3;
167 
168  std::generate( v1.begin(), v1.end(), gauss );
169  std::generate( v2.begin(), v2.end(), breit );
170  std::generate( v3.begin(), v3.end(), flat );
171 
172  tuple->matrix( "g", v1 ).ignore();
173  tuple->matrix( "b", v2 ).ignore();
174  tuple->matrix( "f", v3 ).ignore();
175 
176  tuple->write().ignore();
177  }
178 
179  // ==========================================================================
180  // book and fill simple NTuple with VectorMap
181  // ==========================================================================
182  {
183 
184  Tuple tuple = nTuple( "VectorMaps", "Tuple with VectorMaps/'ExtraInfo'" );
185 
190 
191  VM1 vm1;
192  VM2 vm2;
193  VM3 vm3;
194  VM4 vm4;
195 
196  for ( int i = 200; 0 < i; --i ) {
197  vm1.insert( std::make_pair( i, i * 2 ) );
198  vm2.insert( std::make_pair( i, i * 3 ) );
199  vm3.insert( std::make_pair( i, float( i * 4 ) ) );
200  vm4.insert( std::make_pair( i, i * 5 ) );
201  }
202 
203  tuple->fmatrix( "map1", vm1, "n1", 500 ).ignore();
204  tuple->fmatrix( "map2", vm2, "n2", 500 ).ignore();
205  tuple->fmatrix( "map3", vm3, "n3", 500 ).ignore();
206  tuple->fmatrix( "map4", vm4, "n4", 500 ).ignore();
207 
208  tuple->write().ignore();
209  }
210 
211  return StatusCode::SUCCESS;
212 }
213 // ============================================================================
214 
215 // ============================================================================
216 // The END
217 // ============================================================================
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
TupleAlg3::execute
StatusCode execute() override
the only one essential method
Definition: TupleAlg3.cpp:75
Tuple.h
TupleAlg3
Definition: TupleAlg3.cpp:41
HistoDumpEx.v2
v2
Definition: HistoDumpEx.py:28
RndmGenerators.h
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:565
Tuples::TupleObj::column
StatusCode column(std::string_view name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:267
AlgSequencer.p2
p2
Definition: AlgSequencer.py:31
ROOT::Math::PositionVector3D
Definition: IMagneticFieldSvc.h:25
Tuples::TupleObj::matrix
StatusCode matrix(std::string_view name, const MATRIX &data, const MIndex &rows, const MIndex &cols)
fill N-Tuple with fixed-size matrix
Definition: TupleObj.h:1699
GaudiCommon< Algorithm >::Assert
void Assert(const bool ok, std::string_view message="", const StatusCode sc=StatusCode::FAILURE) const
Assertion - throw exception if the given condition is not fulfilled.
Definition: GaudiCommonImp.h:175
Gaudi::Units::GeV
constexpr double GeV
Definition: SystemOfUnits.h:179
GaudiUtils::VectorMap
Definition: VectorMap.h:112
IRndmGenSvc.h
TupleAlg3::TupleAlg3
TupleAlg3(const TupleAlg3 &)
GaudiTupleAlg
Definition: GaudiTupleAlg.h:51
std::generate
T generate(T... args)
Tuples::TupleObj::array
StatusCode array(std::string_view name, DATA first, DATA last)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1544
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
Tuples
Definition: Maps.h:43
GaudiTupleAlg.h
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
SystemOfUnits.h
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
GaudiPython.Pythonizations.execute
execute
Definition: Pythonizations.py:588
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
GaudiPython.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
Definition: TupleUtils.py:85
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
Tuples::TupleObj::fmatrix
StatusCode fmatrix(std::string_view name, const MATRIX &data, size_t rows, const MIndex &cols, std::string_view length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1303
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:126
AlgSequencer.p1
p1
Definition: AlgSequencer.py:30
TupleAlg3::initialize
StatusCode initialize() override
initialize the algorithm
Definition: TupleAlg3.cpp:44
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
GaudiUtils::VectorMap::insert
result_type insert(const key_type &key, const mapped_type &mapped)
insert the (key,value) pair into the container
Definition: VectorMap.h:312
ROOT::Math::DisplacementVector3D
Definition: IMagneticFieldSvc.h:28
Tuples::TupleObj::write
StatusCode write()
write a record to NTuple
Definition: TupleObj.cpp:245
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
std::make_pair
T make_pair(T... args)
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiTuples< GaudiHistoAlg >::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiTuples.icpp:47
TupleAlg3::operator=
TupleAlg3 & operator=(const TupleAlg3 &)
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230
Gaudi::Units
Definition: PhysicalConstants.h:53