Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
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 "GaudiAlg/GaudiHistoAlg.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 GaudiHistoAlg {
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 ) : GaudiHistoAlg( 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 // ============================================================================
78 // ============================================================================
80 
81 // ============================================================================
83 // ============================================================================
84 StatusCode Aida2Root::finalize() {
85 
86  always() << "Get the native ROOT representation of histograms!" << endmsg;
87 
88  { // loop over all 1D-histograms
89  for ( auto& path : m_1Ds ) {
91  AIDA::IHistogram1D* aida = 0;
92  StatusCode sc = histoSvc()->retrieveObject( path, aida );
93  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 1D-histogram '" + ( path ) + "'" ); }
96  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 1D-histogram '" + ( path ) + "'" ); }
98  info() << "The native ROOT printout for 1D-histogram '" << ( path ) << "':" << endmsg;
99  root->Print();
100 
101  info() << " | Compare | AIDA/HistoStats | ROOT/TH1 | Delta | " << endmsg;
102  auto print = []( double aida, double root, std::string_view name ) {
103  return fmt::format( " | {:<14.14s} | {:>15.8g} | {:< 15.8g} | {:^ 15.8g} | ", name, aida, root,
104  ( aida - root ) );
105  };
106  info() << print( Gaudi::Utils::HistoStats::mean( aida ), root->GetMean(), "'mean'" ) << endmsg;
107  info() << print( Gaudi::Utils::HistoStats::meanErr( aida ), root->GetMeanError(), "'meanErr'" ) << endmsg;
108  info() << print( Gaudi::Utils::HistoStats::rms( aida ), root->GetRMS(), "'rms'" ) << endmsg;
109  info() << print( Gaudi::Utils::HistoStats::rmsErr( aida ), root->GetRMSError(), "'rmsErr'" ) << endmsg;
110  info() << print( Gaudi::Utils::HistoStats::skewness( aida ), root->GetSkewness(), "'skewness'" ) << endmsg;
111  info() << print( Gaudi::Utils::HistoStats::skewnessErr( aida ), root->GetSkewness( 11 ), "'skewnessErr'" )
112  << endmsg;
113  info() << print( Gaudi::Utils::HistoStats::kurtosis( aida ), root->GetKurtosis(), "'kurtosis'" ) << endmsg;
114  info() << print( Gaudi::Utils::HistoStats::kurtosisErr( aida ), root->GetKurtosis( 11 ), "'kurtosisErr'" )
115  << endmsg;
116  }
117  }
118 
119  { // loop over all 2D-histograms
120  for ( auto& path : m_2Ds ) {
122  AIDA::IHistogram2D* aida = 0;
123  StatusCode sc = histoSvc()->retrieveObject( path, aida );
124  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 2D-histogram '" + ( path ) + "'" ); }
127  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 2D-histogram '" + ( path ) + "'" ); }
129  info() << "The native ROOT printout for 2D-histogram '" << ( path ) << "':" << endmsg;
130  root->Print();
131  }
132  }
133 
134  { // loop over all 3D-histograms
135  for ( auto& path : m_3Ds ) {
137  AIDA::IHistogram3D* aida = 0;
138  StatusCode sc = histoSvc()->retrieveObject( path, aida );
139  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 3D-histogram '" + ( path ) + "'" ); }
142  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 3D-histogram '" + ( path ) + "'" ); }
144  info() << "The native ROOT printout for 3D-histogram '" << ( path ) << "':" << endmsg;
145  root->Print();
146  }
147  }
148 
149  { // loop over all 1D-profiles
150  for ( auto& path : m_1Ps ) {
152  AIDA::IProfile1D* aida = 0;
153  StatusCode sc = histoSvc()->retrieveObject( path, aida );
154  if ( sc.isFailure() || 0 == aida ) { return Error( "Unable to retrieve 1D-profile '" + ( path ) + "'" ); }
156  TProfile* root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
157  if ( 0 == root ) { return Error( "Unable to convert to ROOT the 1D-profile '" + ( path ) + "'" ); }
159  info() << "The native ROOT printout for 1D-profile '" << ( path ) << "':" << endmsg;
160  root->Print();
161  }
162  }
163 
164  { // loop over all 2D-profiles
165  for ( auto& path : m_2Ps ) {
167  AIDA::IProfile2D* aida = 0;
168  StatusCode sc = histoSvc()->retrieveObject( path, aida );
169  if ( sc.isFailure() || 0 == aida ) { Error( "Unable to retrieve 2D-profile '" + ( path ) + "'" ).ignore(); }
171  TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
172  if ( 0 == root ) { Error( "Unable to convert to ROOT the 2D-profile '" + ( path ) + "'" ).ignore(); }
174  info() << "The native ROOT printout for 2D-profile '" << ( path ) << "':" << endmsg;
175  root->Print();
176  }
177  }
178 
179  return GaudiHistoAlg::finalize();
180 }
181 
182 // ============================================================================
183 // The END
184 // ============================================================================
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
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
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
Aida2Root::m_1Ps
Gaudi::Property< std::vector< std::string > > m_1Ps
Definition: Aida2Root.cpp:70
Gaudi::Utils::HistoStats::rmsErr
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:661
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:43
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:621
GaudiHistoAlg.h
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:645
TimingHistograms.name
name
Definition: TimingHistograms.py:25
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
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Aida2Root::finalize
StatusCode finalize() override
finalization of the algorithm
Definition: Aida2Root.cpp:84
GaudiHistoAlg
Definition: GaudiHistoAlg.h:47
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:637
Gaudi::Utils::HistoStats::rms
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:653
Gaudi::Utils::HistoStats::kurtosis
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:613
GaudiHistos< GaudiAlgorithm >::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiHistos.icpp:128
Gaudi::Utils::HistoStats::skewnessErr
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:605
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:597
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