Loading [MathJax]/jax/output/HTML-CSS/config.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
P2D.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 "GaudiPI.h"
18 #include <Gaudi/MonitoringHub.h>
20 #include <GaudiCommonSvc/P2D.h>
21 #include <GaudiKernel/DataObject.h>
23 
24 #include <TH2D.h>
25 #include <TProfile2D.h>
26 
27 namespace Gaudi {
28  template <>
29  void* Generic2D<AIDA::IProfile2D, TProfile2D>::cast( const std::string& className ) const {
30  return className == "AIDA::IProfile2D"
31  ? const_cast<AIDA::IProfile2D*>( static_cast<const AIDA::IProfile2D*>( this ) )
32  : className == "AIDA::IProfile" ? const_cast<AIDA::IProfile*>( static_cast<const AIDA::IProfile*>( this ) )
33  : className == "AIDA::IBaseHistogram"
34  ? const_cast<AIDA::IBaseHistogram*>( static_cast<const AIDA::IBaseHistogram*>( this ) )
35  : nullptr;
36  }
37 
38  template <>
40  int rBin = m_rep->GetBin( rIndexX( idX ), rIndexY( idY ) );
41  return int( m_rep->GetBinEntries( rBin ) + 0.5 );
42  }
43 
44  template <>
46  TProfile2D* imp = dynamic_cast<TProfile2D*>( rep );
47  if ( !imp ) throw std::runtime_error( "Cannot adopt native histogram representation." );
48  m_rep.reset( imp );
49  m_xAxis.initialize( m_rep->GetXaxis(), true );
50  m_yAxis.initialize( m_rep->GetYaxis(), true );
51  setTitle( m_rep->GetTitle() );
52  }
53 } // namespace Gaudi
54 
55 std::pair<DataObject*, AIDA::IProfile2D*> Gaudi::createProf2D( ISvcLocator* svcLocator, const std::string& path,
56  const std::string& title, const Edges& eX,
57  const Edges& eY, double /* zlow */, double /* zup */ ) {
58  // Not implemented in ROOT! Can only use TProfile2D with no z-limits
59  auto p = new Profile2D( new TProfile2D( title.c_str(), title.c_str(), eX.size() - 1, &eX.front(), eY.size() - 1,
60  &eY.front() /*,zlow,zup */ ) );
61  svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
62  return { p, p };
63 }
64 
65 std::pair<DataObject*, AIDA::IProfile2D*> Gaudi::createProf2D( ISvcLocator* svcLocator, const std::string& path,
66  const std::string& title, int binsX, double xlow,
67  double xup, int binsY, double ylow, double yup,
68  double zlow, double zup ) {
69  auto p =
70  new Profile2D( new TProfile2D( title.c_str(), title.c_str(), binsX, xlow, xup, binsY, ylow, yup, zlow, zup ) );
71  svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
72  return { p, p };
73 }
74 
75 std::pair<DataObject*, AIDA::IProfile2D*> Gaudi::createProf2D( ISvcLocator* svcLocator, const std::string& path,
76  const AIDA::IProfile2D& hist ) {
77  auto h = getRepresentation<AIDA::IProfile2D, TProfile2D>( hist );
78  auto n = ( h ? new Profile2D( new TProfile2D( *h ) ) : nullptr );
79  if ( n ) { svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *n ); }
80  return { n, n };
81 }
82 
83 Gaudi::Profile2D::Profile2D( TProfile2D* rep ) {
84  m_classType = "IProfile2D";
85  rep->SetDirectory( nullptr );
86  adoptRepresentation( rep );
87  m_sumEntries = 0;
88 }
ISvcLocator::monitoringHub
Gaudi::Monitoring::Hub & monitoringHub()
Definition: ISvcLocator.cpp:24
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
MonitoringHub.h
ISvcLocator
Definition: ISvcLocator.h:42
P2D.h
ObjectFactory.h
Gaudi::Generic2D::cast
void * cast(const std::string &className) const override
Introspection method.
HistogramUtility.h
Gaudi::Profile2D::Profile2D
Profile2D()
Default Constructor.
Definition: P2D.h:34
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
AlgSequencer.h
h
Definition: AlgSequencer.py:31
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::m_classType
std::string m_classType
class type
Definition: Generic2D.h:163
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
Gaudi::Monitoring::Hub::registerEntity
void registerEntity(std::string c, std::string n, std::string t, T &ent)
Definition: MonitoringHub.h:137
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
DataObject.h
GaudiPI.h
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::m_sumEntries
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself
Definition: Generic2D.h:165
Gaudi::Generic2D
Definition: Generic2D.h:45
Gaudi::createProf2D
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IProfile2D &hist)
Copy constructor.