| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

P1D.cpp
Go to the documentation of this file.
1 #ifdef __ICC
2 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
3 // TODO: To be removed, since it comes from ROOT TMathBase.h
4 #pragma warning( disable : 2259 )
5 #endif
6 #ifdef WIN32
7 // Disable warning
8 // warning C4996: 'sprintf': This function or variable may be unsafe.
9 // coming from TString.h
10 #pragma warning( disable : 4996 )
11 #endif
12
13 #include "GaudiPI.h"
14 #include <GaudiCommonSvc/HistogramUtility.h>
15 #include <GaudiCommonSvc/P1D.h>
16 #include <GaudiKernel/ObjectFactory.h>
17 #include <cmath>
18
19 std::pair<DataObject*, AIDA::IProfile1D*> Gaudi::createProf1D( const std::string& title, int nBins, double xlow,
20 double xup, double ylow, double yup,
21 const std::string& opt )
22 {
23 auto _p = new TProfile( title.c_str(), title.c_str(), nBins, xlow, xup, ylow, yup, opt.c_str() );
24 auto p = new Profile1D( _p );
25 return {p, p};
26 }
27
28 std::pair<DataObject*, AIDA::IProfile1D*> Gaudi::createProf1D( const std::string& title, const Edges& e, double ylow,
29 double yup, const std::string& opt )
30 {
31 auto p =
32 new Profile1D( new TProfile( title.c_str(), title.c_str(), e.size() - 1, &e.front(), ylow, yup, opt.c_str() ) );
33 return {p, p};
34 }
35
36 std::pair<DataObject*, AIDA::IProfile1D*> Gaudi::createProf1D( const AIDA::IProfile1D& hist )
37 {
38 TProfile* h = getRepresentation<AIDA::IProfile1D, TProfile>( hist );
39 auto n = ( h ? new Profile1D( new TProfile( *h ) ) : nullptr );
40 return {n, n};
41 }
42
43 namespace Gaudi
44 {
45 template <>
46 int Generic1D<AIDA::IProfile1D, TProfile>::binEntries( int index ) const
47 {
48 return int( m_rep->GetBinEntries( rIndex( index ) ) + 0.5 );
49 }
50
51 template <>
52 void* Generic1D<AIDA::IProfile1D, TProfile>::cast( const std::string& className ) const
53 {
54 if ( className == "AIDA::IProfile1D" )
55 return const_cast<AIDA::IProfile1D*>( (AIDA::IProfile1D*)this );
56 else if ( className == "AIDA::IProfile" )
57 return const_cast<AIDA::IProfile*>( (AIDA::IProfile*)this );
58 else if ( className == "AIDA::IBaseHistogram" )
59 return const_cast<AIDA::IBaseHistogram*>( (AIDA::IBaseHistogram*)this );
60 return nullptr;
61 }
62
63 template <>
64 void Generic1D<AIDA::IProfile1D, TProfile>::adoptRepresentation( TObject* rep )
65 {
66 TProfile* imp = dynamic_cast<TProfile*>( rep );
67 if ( !imp ) throw std::runtime_error( "Cannot adopt native histogram representation." );
68 m_rep.reset( imp );
69 m_axis.initialize( m_rep->GetXaxis(), true );
70 const TArrayD* a = m_rep->GetSumw2();
71 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
72 setTitle( m_rep->GetTitle() );
73 }
74 }
75
76 Gaudi::Profile1D::Profile1D() : Base( new TProfile() ) { init( "", false ); }
77
78 Gaudi::Profile1D::Profile1D( TProfile* rep ) : Base( rep ) { init( m_rep->GetTitle() ); }
79
80 void Gaudi::Profile1D::init( const std::string& title, bool initialize_axis )
81 {
82 m_classType = "IProfile1D";
83 setTitle( title );
84 setName( title );
85 if ( initialize_axis ) {
86 axis().initialize( m_rep->GetXaxis(), false );
87 }
88 // m_rep->SetErrorOption("s");
89 m_rep->SetDirectory( nullptr );
90 m_sumEntries = 0;
91 }
92
93 bool Gaudi::Profile1D::setBinContents( int i, int entries, double height, double /*error*/, double spread,
94 double /* centre */ )
95 {
96 m_rep->SetBinEntries( rIndex( i ), entries );
97 // set content takes in root height * entries
98 m_rep->SetBinContent( rIndex( i ), height * entries );
99 // set error takes sqrt of bin sum(w*y**2)
100 double sumwy2Bin = ( spread * spread + height * height ) * entries;
101 m_rep->SetBinError( rIndex( i ), sqrt( sumwy2Bin ) );
102 m_sumEntries += entries;
103 // not very efficient (but do evey bin since root cannot figure out by himself)
104 m_rep->SetEntries( m_sumEntries );
105 return true;
106 }
107
108 #ifdef __ICC
109 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
110 // The comparison is correct
111 #pragma warning( disable : 1572 )
112 #endif
113 bool Gaudi::Profile1D::fill( double x, double y, double weight )
114 {
115 ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight );
116 return true;
117 }
Gaudi::Generic1D::cast
void * cast(const std::string &cl) const override
Manual cast by class name.
Gaudi::Generic1D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:76
Gaudi::Generic1D::m_classType
std::string m_classType
Definition: Generic1D.h:136
ObjectFactory.h
Gaudi::Edges
std::vector< double > Edges
Definition: GaudiPI.h:18
Gaudi::Profile1D::setBinContents
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition: P1D.cpp:93
Gaudi::Generic1D::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
GaudiPI.h
P1D.h
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
Gaudi::Generic1D::axis
Axis & axis()
Access to axis object.
Definition: Generic1D.h:71
Gaudi::Generic1D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:134
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
Gaudi::Generic1D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic1D.h:142
std::runtime_error
STL class.
Gaudi::Generic1D::binEntries
int binEntries(int index) const override
Number of entries in the corresponding bin (ie the number of times fill was called for this bin)...
Gaudi::Generic1D::m_sumEntries
int m_sumEntries
Definition: Generic1D.h:138
std::pair
Gaudi::Profile1D::Profile1D
Profile1D()
Default Constructor.
Definition: P1D.cpp:76
Gaudi::Axis::initialize
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:67
std::string::c_str
T c_str(T...args)
Gaudi::Profile1D::fill
bool fill(double x, double y, double weight=1.) override
Fill the Profile1D with a value and the corresponding weight.
Definition: P1D.cpp:113
HistogramUtility.h
Gaudi::Generic1D::rIndex
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:106
Gaudi::Profile1D::init
void init(const std::string &title, bool initialize_axis=true)
Definition: P1D.cpp:80
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::createProf1D
std::pair< DataObject *, AIDA::IProfile1D * > createProf1D(const AIDA::IProfile1D &hist)
Copy constructor.
Gaudi::Generic1D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:151
Gaudi::Generic1D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:36