The Gaudi Framework  v30r3 (a5ef0a68)
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"
15 #include <GaudiCommonSvc/P1D.h>
17 #include <cmath>
18 
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 
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 
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 <>
47  {
48  return int( m_rep->GetBinEntries( rIndex( index ) ) + 0.5 );
49  }
50 
51  template <>
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 <>
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 ) );
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 }
void * cast(const std::string &cl) const override
Manual cast by class name.
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:74
std::string m_classType
Definition: Generic1D.h:134
std::vector< double > Edges
Definition: GaudiPI.h:18
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition: P1D.cpp:93
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
STL class.
Axis & axis()
Access to axis object.
Definition: Generic1D.h:69
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:132
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic1D.h:140
int binEntries(int index) const override
Number of entries in the corresponding bin (ie the number of times fill was called for this bin)...
Profile1D()
Default Constructor.
Definition: P1D.cpp:76
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:67
T c_str(T...args)
bool fill(double x, double y, double weight=1.) override
Fill the Profile1D with a value and the corresponding weight.
Definition: P1D.cpp:113
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:104
void init(const std::string &title, bool initialize_axis=true)
Definition: P1D.cpp:80
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::pair< DataObject *, AIDA::IProfile1D * > createProf1D(const AIDA::IProfile1D &hist)
Copy constructor.
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:149
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:36