Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiHistoAlgorithm.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 // GaudiKernel
13 // ============================================================================
16 
17 // local
18 #include "GaudiHistoAlgorithm.h"
19 
20 // onl needed for old style histogram for speed comparision
21 #include "AIDA/IHistogram1D.h"
22 
23 //-----------------------------------------------------------------------------
24 // Implementation file for class : GaudiHistoAlgorithm
25 //
26 // 2005-08-12 : Chris Jones
27 //-----------------------------------------------------------------------------
28 
29 // Declaration of the Algorithm Factory
31 
32 //=============================================================================
33 // Standard constructor, initializes variables
34 //=============================================================================
36  : GaudiHistoAlg( name, pSvcLocator ) {}
37 //=============================================================================
38 // Destructor
39 //=============================================================================
41 
42 //=============================================================================
43 // Initialization
44 //=============================================================================
46  // must be called first
48  if ( sc.isFailure() ) return sc;
49 
50  return sc;
51 }
52 
53 //=============================================================================
54 // Main execution
55 //=============================================================================
57 
58  // count calls
59  static int nCalls( 0 );
60 
61  // some random number generators, just to provide numbers
62  static Rndm::Numbers Gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
63  static Rndm::Numbers Flat( randSvc(), Rndm::Flat( -10.0, 10.0 ) );
64  static Rndm::Numbers Expo( randSvc(), Rndm::Exponential( 1.0 ) );
65  static Rndm::Numbers Breit( randSvc(), Rndm::BreitWigner( 0.0, 1.0 ) );
66  static Rndm::Numbers Poisson( randSvc(), Rndm::Poisson( 2.0 ) );
67  static Rndm::Numbers Binom( randSvc(), Rndm::Binomial( 8, 0.25 ) );
68 
69  // cache some numbers
70  const double gauss( Gauss() );
71  const double flat( Flat() );
72  const double expo( Expo() );
73  const double breit( Breit() );
74  const double poisson( Poisson() );
75  const double binom( Binom() );
76 
77  // =============== Histogramming TestSuite =================================
78 
79  // 1D plots with auto ID
80  plot1D( gauss, "Gaussian mean=0, sigma=1", -5, 5, 100 );
81 
82  // 1D plot with forced numerical ID
83  plot1D( expo, 101, "Exponential", 0, 5, 100 );
84  plot1D( breit, 102, "Breit", -5, 5, 100 );
85 
86  // 1D plot with forced alpha-numeric ID
87  plot1D( poisson, "poisson", "Poisson", -5, 5, 100 );
88 
89  // 1D plot with forced alpha-numeric ID in a sub directory
90  plot1D( binom, "subdir1/bino", "Binominal", -5, 5, 100 );
91  plot1D( binom, "subdir2/bino", "Binominal", -5, 5, 100 );
92 
93  // 2D plots with auto ID
94  plot2D( flat, gauss, "Gaussian V Flat", -5, 5, -5, 5 );
95  plot2D( flat, expo, "Exponential V Flat", -5, 5, 0, 5 );
96 
97  // 2D with forced alpha-numeric ID
98  plot2D( poisson, binom, "binVpois", "Binom V poisson", -5, 5, -5, 5 );
99  plot2D( poisson, expo, "expoVpois", "Expo V poisson", -5, 5, -5, 5 );
100 
101  // 3D plot with auto ID
102  plot3D( gauss, expo, breit, "3D plot AutoID", -5, 5, 0, 5, -5, 5 );
103 
104  // 3D plot with forced alpha-numeric ID
105  plot3D( gauss, expo, breit, "3d", "3D plot ForcedID", -5, 5, 0, 5, -5, 5 );
106 
107  // 1D profile histo with auto ID
108  profile1D( gauss, expo, "Expo V Gauss 1DProf", -5, 5, 50 );
109  profile1D( gauss, expo, "Expo V Gauss 1DProf s", -5, 5, 50, "s" );
110  profile1D( flat, gauss, "Gauss V Flat 1DProf", -10, 10, 10 );
111  profile1D( flat, gauss, "Gauss V Flat 1DProf S", -10, 10, 10, "s" );
112  profile1D( flat, gauss, "Gauss V Flat 1DProf, with limits-I", -10, 10, 10, "", 0, 5 );
113  profile1D( flat, gauss, "Gauss V Flat 1DProf, with limits-I s", -10, 10, 10, "s", 0, 5 );
114  profile1D( flat, gauss, "Gauss V Flat 1DProf, with limits-II", -10, 10, 10, "", -5, 0 );
115  profile1D( flat, gauss, "Gauss V Flat 1DProf, with limits-II s", -10, 10, 10, "s", -5, 0 );
116 
117  // 2D profile histo with forced ID
118  profile2D( gauss, expo, poisson, "2dprof", "2D profile1", -5, 5, 0, 5 );
119  profile2D( gauss, expo, poisson, 321, "2D profile2", -5, 5, 0, 5 );
120 
121  // variable binning
122  const GaudiAlg::HistoBinEdges edgesX = { -5, -4, -2.5, 0, 1, 2.25, 4, 5 };
123  const GaudiAlg::HistoBinEdges edgesY = { -5, -3.7, -2, 0.5, 1, 2, 4.5, 5 };
124  const GaudiAlg::HistoBinEdges edgesZ = { -5, -3, 0, 5 };
125 
126  // 1D
127  plot1D( flat, "varBinning/x", "1D Variable Binning", edgesX );
128  // 2D
129  plot2D( flat, gauss, "varBinning/y", "2D Variable Binning", edgesX, edgesY );
130  // 3D
131  plot3D( flat, gauss, expo, "varBinning/z", "3D Variable Binning", edgesX, edgesY, edgesZ );
132  // 1D profile
133  profile1D( flat, gauss, "varBinning/a", "1D Profile Variable Binning", edgesX );
134  // 2D Profile
135  profile2D( flat, gauss, expo, "varBinning/b", "2D Profile Variable Binning", edgesX, edgesY );
136 
137  // ============================================================================
138  // The following is just a comparision of fill times for the various 1D methods
139  // to illustrate that the shortcut methods are not significantly slower
140  // than directly interacting with the histoSvc (At least on linux. On windows
141  // there is a difference, due either to the implementation or the
142  // non-optimised build)
143  // ===========================================================================
144 
145  // old style filling
146  static IHistogram1D* test( 0 );
147  if ( 0 == nCalls ) { test = histoSvc()->book( "OldStyle/1112", "Old Style Histo", 100, -5, 5 ); }
148  if ( nCalls > 0 ) chronoSvc()->chronoStart( "1DOldStyle" );
149  test->fill( gauss );
150  if ( nCalls > 0 ) chronoSvc()->chronoStop( "1DOldStyle" );
151 
152  // timing test for histo fill with autoID (skip first booking call)
153  if ( nCalls > 0 ) chronoSvc()->chronoStart( "1DAutoID" );
154  plot1D( gauss, "AutoID time test", -5, 5, 100 );
155  if ( nCalls > 0 ) chronoSvc()->chronoStop( "1DAutoID" );
156 
157  // timing test for histo fill with forced numeric ID (skip first booking call)
158  if ( nCalls > 0 ) chronoSvc()->chronoStart( "1DForcedNumericID" );
159  plot1D( gauss, 1111, "Forced Numeric ID time test", -5, 5, 100 );
160  if ( nCalls > 0 ) chronoSvc()->chronoStop( "1DForcedNumericID" );
161 
162  // timing test for histo fill with forced alpha ID (skip first booking call)
163  if ( nCalls > 0 ) chronoSvc()->chronoStart( "1DForcedAlphaID" );
164  plot1D( gauss, "test1", "Forced Alpha ID time test", -5, 5, 100 );
165  if ( nCalls > 0 ) chronoSvc()->chronoStop( "1DForcedAlphaID" );
166 
167  if ( 0 == nCalls ) Print( "Filling Histograms...... Please be patient !" ).ignore();
168  ++nCalls;
169  return StatusCode::SUCCESS;
170 }
171 
172 //=============================================================================
173 // Finalize
174 //=============================================================================
176  // must be called after all other actions
177  return GaudiHistoAlg::finalize();
178 }
179 
180 //=============================================================================
GaudiHistos< GaudiAlgorithm >::plot3D
AIDA::IHistogram3D * plot3D(const double valueX, const double valueY, const double valueZ, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const double lowZ, const double highZ, const unsigned long binsX=10, const unsigned long binsY=10, const unsigned long binsZ=10, const double weight=1.0) const
fill the 3D histogram (book on demand)
Definition: GaudiHistos_3DFixedBinning.icpp:121
GaudiHistos< GaudiAlgorithm >::plot1D
AIDA::IHistogram1D * plot1D(const double value, const std::string &title, const double low, const double high, const unsigned long bins=100, const double weight=1.0) const
fill the 1D histogram (book on demand)
Definition: GaudiHistos_1DFixedBinning.icpp:113
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
std::vector< double >
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Algorithm::histoSvc
SmartIF< IHistogramSvc > & histoSvc() const
The standard histogram service.
Definition: Algorithm.cpp:563
IRndmGenSvc.h
GaudiHistoAlgorithm::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: GaudiHistoAlgorithm.cpp:45
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
GaudiHistoAlgorithm.h
GaudiHistos< GaudiAlgorithm >::plot2D
AIDA::IHistogram2D * plot2D(const double valueX, const double valueY, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D histogram (book on demand)
Definition: GaudiHistos_2DFixedBinning.icpp:116
GaudiHistoAlgorithm::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: GaudiHistoAlgorithm.cpp:175
Gaudi::Algorithm::chronoSvc
SmartIF< IChronoStatSvc > & chronoSvc() const
The standard Chrono & Stat service, Return a pointer to the service if present.
Definition: Algorithm.cpp:558
GaudiHistoAlgorithm::execute
StatusCode execute() override
Algorithm execution.
Definition: GaudiHistoAlgorithm.cpp:56
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
GaudiHistoAlgorithm::~GaudiHistoAlgorithm
~GaudiHistoAlgorithm() override
Destructor.
Definition: GaudiHistoAlgorithm.cpp:40
GaudiCommon< Algorithm >::Print
StatusCode Print(std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
Print the message and return with the given StatusCode.
Definition: GaudiCommon.icpp:314
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
GaudiHistoAlgorithm
Definition: GaudiHistoAlgorithm.h:27
GaudiHistos< GaudiAlgorithm >::profile1D
AIDA::IProfile1D * profile1D(const double valueX, const double valueY, const std::string &title, const double lowX, const double highX, const unsigned long binsX=100, const std::string &opt="", const double lowY=-std::numeric_limits< double >::max(), const double highY=std::numeric_limits< double >::max(), const double weight=1.0) const
fill the 1D profile histogram (book on demand)
Definition: GaudiHistos_1DProfFixedBinning.icpp:114
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
Gaudi::Units::gauss
constexpr double gauss
Definition: SystemOfUnits.h:252
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
GaudiHistoAlg
Definition: GaudiHistoAlg.h:47
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
compareRootHistos.test
test
Definition: compareRootHistos.py:28
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
GaudiHistos< GaudiAlgorithm >::profile2D
AIDA::IProfile2D * profile2D(const double valueX, const double valueY, const double valueZ, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D profile histogram (book on demand)
Definition: GaudiHistos_2DProfFixedBinning.icpp:113
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiHistos< GaudiAlgorithm >::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiHistos.icpp:128
GaudiHistos< GaudiAlgorithm >::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiHistos.icpp:91
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230