The Gaudi Framework master (1fbcc22a)
Loading...
Searching...
No Matches
P1D.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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// Local includes
13#include "GaudiPI.h"
14
15// Framework includes
16#include <Gaudi/MonitoringHub.h>
18#include <GaudiCommonSvc/P1D.h>
20
21// STL includes
22#include <cmath>
23
25 const std::string& title, int nBins, double xlow,
26 double xup, double ylow, double yup,
27 const std::string& opt ) {
28 auto _p = new TProfile( title.c_str(), title.c_str(), nBins, xlow, xup, ylow, yup, opt.c_str() );
29 auto p = new Profile1D( _p );
30 svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
31 return { p, p };
32}
33
35 const std::string& title, const Edges& e, double ylow,
36 double yup, const std::string& opt ) {
37 auto p =
38 new Profile1D( new TProfile( title.c_str(), title.c_str(), e.size() - 1, &e.front(), ylow, yup, opt.c_str() ) );
39 svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
40 return { p, p };
41}
42
44 const AIDA::IProfile1D& hist ) {
46 auto n = ( h ? new Profile1D( new TProfile( *h ) ) : nullptr );
47 if ( n ) { svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *n ); }
48 return { n, n };
49}
50
51namespace Gaudi {
52 template <>
54 return int( m_rep->GetBinEntries( rIndex( index ) ) + 0.5 );
55 }
56
57 template <>
58 void* Generic1D<AIDA::IProfile1D, TProfile>::cast( const std::string& className ) const {
59 return className == "AIDA::IProfile1D"
60 ? const_cast<AIDA::IProfile1D*>( static_cast<const AIDA::IProfile1D*>( this ) )
61 : className == "AIDA::IProfile" ? const_cast<AIDA::IProfile*>( static_cast<const AIDA::IProfile*>( this ) )
62 : className == "AIDA::IBaseHistogram"
63 ? const_cast<AIDA::IBaseHistogram*>( static_cast<const AIDA::IBaseHistogram*>( this ) )
64 : nullptr;
65 }
66
67 template <>
69 TProfile* imp = dynamic_cast<TProfile*>( rep );
70 if ( !imp ) throw std::runtime_error( "Cannot adopt native histogram representation." );
71 m_rep.reset( imp );
72 m_axis.initialize( m_rep->GetXaxis(), true );
73 const TArrayD* a = m_rep->GetSumw2();
74 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
75 setTitle( m_rep->GetTitle() );
76 }
77} // namespace Gaudi
78
79Gaudi::Profile1D::Profile1D() : Base( new TProfile() ) { init( "", false ); }
80
81Gaudi::Profile1D::Profile1D( TProfile* rep ) : Base( rep ) { init( m_rep->GetTitle() ); }
82
83void Gaudi::Profile1D::init( const std::string& title, bool initialize_axis ) {
84 m_classType = "IProfile1D";
85 setTitle( title );
86 setName( title );
87 if ( initialize_axis ) { axis().initialize( m_rep->GetXaxis(), false ); }
88 // m_rep->SetErrorOption("s");
89 m_rep->SetDirectory( nullptr );
90 m_sumEntries = 0;
91}
92
93bool Gaudi::Profile1D::setBinContents( int i, int entries, double height, double /*error*/, double spread,
94 double /* centre */ ) {
95 m_rep->SetBinEntries( rIndex( i ), entries );
96 // set content takes in root height * entries
97 m_rep->SetBinContent( rIndex( i ), height * entries );
98 // set error takes sqrt of bin sum(w*y**2)
99 double sumwy2Bin = ( spread * spread + height * height ) * entries;
100 m_rep->SetBinError( rIndex( i ), sqrt( sumwy2Bin ) );
102 // not very efficient (but do evey bin since root cannot figure out by himself)
103 m_rep->SetEntries( m_sumEntries );
104 return true;
105}
106
107bool Gaudi::Profile1D::fill( double x, double y, double weight ) {
108 // avoid race conditions when filling the profile
109 auto guard = std::scoped_lock{ m_fillSerialization };
110 m_rep->Fill( x, y, weight );
111 return true;
112}
complex< _Tp > sqrt(const complex< _Tp > &)
const _CharT * c_str() const noexcept
int binEntries(int index) const override
Number of entries in the corresponding bin (ie the number of times fill was called for this bin).
std::string title() const override
Definition Generic1D.h:65
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
void * cast(const std::string &cl) const override
Manual cast by class name.
bool setTitle(const std::string &title) override
Definition Generic1D.h:148
Generic1D< AIDA::IProfile1D, TProfile > Base
Definition Generic1D.h:47
virtual int rIndex(int index) const
Definition Generic1D.h:112
bool setName(const std::string &newName)
Definition Generic1D.h:156
Profile1D()
Default Constructor.
Definition P1D.cpp:79
bool fill(double x, double y, double weight=1.) override
Fill the Profile1D with a value and the corresponding weight.
Definition P1D.cpp:107
std::mutex m_fillSerialization
Definition P1D.h:56
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition P1D.cpp:93
void init(const std::string &title, bool initialize_axis=true)
Definition P1D.cpp:83
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::IProfile1D * > createProf1D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IProfile1D &hist)
Copy constructor.
T * getRepresentation(const Q &hist)
void registerEntity(std::string c, std::string n, std::string t, T &ent)