The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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>
23
24#include <TH2D.h>
25#include <TProfile2D.h>
26
27namespace 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
55std::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
65std::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
75std::pair<DataObject*, AIDA::IProfile2D*> Gaudi::createProf2D( ISvcLocator* svcLocator, const std::string& path,
76 const AIDA::IProfile2D& 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
83Gaudi::Profile2D::Profile2D( TProfile2D* rep ) {
84 m_classType = "IProfile2D";
85 rep->SetDirectory( nullptr );
87 m_sumEntries = 0;
88}
virtual int rIndexX(int index) const
Definition Generic2D.h:78
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
int binEntries(int indexX, int indexY) const override
The number of entries (ie the number of times fill was called for this bin).
virtual int rIndexY(int index) const
Definition Generic2D.h:80
void * cast(const std::string &className) const override
Introspection method.
bool setTitle(const std::string &title) override
Definition Generic2D.h:169
AIDA implementation for 2 D profiles using ROOT TProfile2D.
Definition P2D.h:31
Profile2D()
Default Constructor.
Definition P2D.h:34
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Gaudi::Monitoring::Hub & monitoringHub()
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
GAUDI_API ISvcLocator * svcLocator()
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IProfile2D &hist)
Copy constructor.
T * getRepresentation(const Q &hist)
void registerEntity(std::string c, std::string n, std::string t, T &ent)