Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Aida2Root.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 #ifdef __ICC
12 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
13 // TODO: To be removed, since it comes from ROOT TMathBase.h
14 # pragma warning( disable : 2259 )
15 #endif
16 
17 #include "GaudiUtils/Aida2ROOT.h"
18 #include "AIDA/IHistogram1D.h"
19 #include "AIDA/IHistogram2D.h"
20 #include "AIDA/IHistogram3D.h"
21 #include "AIDA/IProfile1D.h"
22 #include "AIDA/IProfile2D.h"
23 #include "GaudiKernel/Algorithm.h"
24 #include "GaudiUtils/HistoStats.h"
25 #include "TH1D.h"
26 #include "TH2D.h"
27 #include "TH3D.h"
28 #include "TProfile.h"
29 #include "TProfile2D.h"
30 #include <fmt/format.h>
31 
32 // ============================================================================
40 class Aida2Root : public Algorithm {
41 public:
43  StatusCode execute() override { return StatusCode::SUCCESS; };
45  StatusCode finalize() override;
46 
47 public:
48  // standard constructor
49  Aida2Root( const std::string& name, ISvcLocator* pSvc ) : Algorithm( name, pSvc ) {
50  setProperty( "PropertiesPrint", true ).ignore();
51  }
52 
53 private:
55  this,
56  "Histos1D",
57  { "SimpleHistos/Gaussian mean=0, sigma=1", "SimpleHistos/101", "SimpleHistos/102", "SimpleHistos/1111",
58  "SimpleHistos/test1", "SimpleHistos/subdir2/bino", "SimpleHistos/subdir1/bino", "SimpleHistos/poisson" },
59  "list of 1D-histograms" };
60 
62  "Histos2D",
63  { "SimpleHistos/Gaussian V Flat", "SimpleHistos/Exponential V Flat",
64  "SimpleHistos/binVpois", "SimpleHistos/expoVpois" },
65  "list of 2D-histograms" };
66 
68  this, "Histos3D", { "SimpleHistos/3D plot AutoID", "SimpleHistos/3d" }, "list of 3D-histograms" };
69 
71  this, "Profs1D", { "SimpleHistos/Expo V Gauss 1DProf" }, "list of 1D-profiles" };
72 
74  this, "Profs2D", { "SimpleHistos/321", "SimpleHistos/2dprof" }, "list of 2D-profiles" };
75 
76  StatusCode Error( const std::string& msg ) const {
77  error() << msg << endmsg;
78  return StatusCode::FAILURE;
79  }
80 };
81 // ============================================================================
83 // ============================================================================
85 
86 // ============================================================================
88 // ============================================================================
89 StatusCode Aida2Root::finalize() {
90 
91  always() << "Get the native ROOT representation of histograms!" << endmsg;
92 
93  { // loop over all 1D-histograms
94  for ( auto& path : m_1Ds ) {
96  AIDA::IHistogram1D* aida = 0;
97  StatusCode sc = histoSvc()->retrieveObject( path, aida );
98  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 1D-histogram '" + ( path ) + "'" ); }
101  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 1D-histogram '" + ( path ) + "'" ); }
103  info() << "The native ROOT printout for 1D-histogram '" << ( path ) << "':" << endmsg;
104  root->Print();
105 
106  info() << " | Compare | AIDA/HistoStats | ROOT/TH1 | Delta | " << endmsg;
107  auto print = []( double aida, double root, std::string_view name ) {
108  return fmt::format( " | {:<14.14s} | {:>15.8g} | {:< 15.8g} | {:^ 15.8g} | ", name, aida, root,
109  ( aida - root ) );
110  };
111  info() << print( Gaudi::Utils::HistoStats::mean( aida ), root->GetMean(), "'mean'" ) << endmsg;
112  info() << print( Gaudi::Utils::HistoStats::meanErr( aida ), root->GetMeanError(), "'meanErr'" ) << endmsg;
113  info() << print( Gaudi::Utils::HistoStats::rms( aida ), root->GetRMS(), "'rms'" ) << endmsg;
114  info() << print( Gaudi::Utils::HistoStats::rmsErr( aida ), root->GetRMSError(), "'rmsErr'" ) << endmsg;
115  info() << print( Gaudi::Utils::HistoStats::skewness( aida ), root->GetSkewness(), "'skewness'" ) << endmsg;
116  info() << print( Gaudi::Utils::HistoStats::skewnessErr( aida ), root->GetSkewness( 11 ), "'skewnessErr'" )
117  << endmsg;
118  info() << print( Gaudi::Utils::HistoStats::kurtosis( aida ), root->GetKurtosis(), "'kurtosis'" ) << endmsg;
119  info() << print( Gaudi::Utils::HistoStats::kurtosisErr( aida ), root->GetKurtosis( 11 ), "'kurtosisErr'" )
120  << endmsg;
121  }
122  }
123 
124  { // loop over all 2D-histograms
125  for ( auto& path : m_2Ds ) {
127  AIDA::IHistogram2D* aida = 0;
128  StatusCode sc = histoSvc()->retrieveObject( path, aida );
129  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 2D-histogram '" + ( path ) + "'" ); }
132  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 2D-histogram '" + ( path ) + "'" ); }
134  info() << "The native ROOT printout for 2D-histogram '" << ( path ) << "':" << endmsg;
135  root->Print();
136  }
137  }
138 
139  { // loop over all 3D-histograms
140  for ( auto& path : m_3Ds ) {
142  AIDA::IHistogram3D* aida = 0;
143  StatusCode sc = histoSvc()->retrieveObject( path, aida );
144  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 3D-histogram '" + ( path ) + "'" ); }
147  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 3D-histogram '" + ( path ) + "'" ); }
149  info() << "The native ROOT printout for 3D-histogram '" << ( path ) << "':" << endmsg;
150  root->Print();
151  }
152  }
153 
154  { // loop over all 1D-profiles
155  for ( auto& path : m_1Ps ) {
157  AIDA::IProfile1D* aida = 0;
158  StatusCode sc = histoSvc()->retrieveObject( path, aida );
159  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 1D-profile '" + ( path ) + "'" ); }
161  TProfile* root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
162  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 1D-profile '" + ( path ) + "'" ); }
164  info() << "The native ROOT printout for 1D-profile '" << ( path ) << "':" << endmsg;
165  root->Print();
166  }
167  }
168 
169  { // loop over all 2D-profiles
170  for ( auto& path : m_2Ps ) {
172  AIDA::IProfile2D* aida = 0;
173  StatusCode sc = histoSvc()->retrieveObject( path, aida );
174  if ( sc.isFailure() || 0 == aida ) { Error( "Unable to retrieve 2D-profile '" + ( path ) + "'" ).ignore(); }
176  TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
177  if ( 0 == root ) { Error( "Unable to convert to ROOT the 2D-profile '" + ( path ) + "'" ).ignore(); }
179  info() << "The native ROOT printout for 2D-profile '" << ( path ) << "':" << endmsg;
180  root->Print();
181  }
182  }
183 
184  return Algorithm::finalize();
185 }
186 
187 // ============================================================================
188 // The END
189 // ============================================================================
Aida2Root::m_3Ds
Gaudi::Property< std::vector< std::string > > m_3Ds
Definition: Aida2Root.cpp:67
HistoStats.h
std::string
STL class.
Aida2Root::m_2Ps
Gaudi::Property< std::vector< std::string > > m_2Ps
Definition: Aida2Root.cpp:73
GaudiAlg.HistoUtils.path
path
Definition: HistoUtils.py:960
Aida2ROOT.h
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:528
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
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Algorithm.h
Aida2Root::m_1Ps
Gaudi::Property< std::vector< std::string > > m_1Ps
Definition: Aida2Root.cpp:70
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::Utils::HistoStats::rmsErr
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:652
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:42
Gaudi::Utils::Aida2ROOT::aida2root
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Definition: Aida2ROOT.cpp:68
Gaudi::Utils::HistoStats::kurtosisErr
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:612
Aida2Root::execute
StatusCode execute() override
execution of the algorithm
Definition: Aida2Root.cpp:43
Gaudi::Utils::HistoStats::meanErr
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:636
StatusCode
Definition: StatusCode.h:65
Aida2Root::m_2Ds
Gaudi::Property< std::vector< std::string > > m_2Ds
Definition: Aida2Root.cpp:61
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Aida2Root::m_1Ds
Gaudi::Property< std::vector< std::string > > m_1Ds
Definition: Aida2Root.cpp:54
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
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Aida2Root::finalize
StatusCode finalize() override
finalization of the algorithm
Definition: Aida2Root.cpp:89
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Utils::HistoStats::mean
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
Definition: HistoStats.cpp:628
Gaudi::Utils::HistoStats::rms
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:644
Gaudi::Utils::HistoStats::kurtosis
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:604
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Utils::HistoStats::skewnessErr
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:596
Aida2Root
Definition: Aida2Root.cpp:40
Gaudi::Utils::HistoStats::skewness
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:588
Aida2Root::Error
StatusCode Error(const std::string &msg) const
Definition: Aida2Root.cpp:76
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:39
Aida2Root::Aida2Root
Aida2Root(const std::string &name, ISvcLocator *pSvc)
Definition: Aida2Root.cpp:49