Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  auto _p = new TProfile( title.c_str(), title.c_str(), nBins, xlow, xup, ylow, yup, opt.c_str() );
23  auto p = new Profile1D( _p );
24  return {p, p};
25 }
26 
28  double yup, const std::string& opt ) {
29  auto p =
30  new Profile1D( new TProfile( title.c_str(), title.c_str(), e.size() - 1, &e.front(), ylow, yup, opt.c_str() ) );
31  return {p, p};
32 }
33 
34 std::pair<DataObject*, AIDA::IProfile1D*> Gaudi::createProf1D( const AIDA::IProfile1D& hist ) {
35  TProfile* h = getRepresentation<AIDA::IProfile1D, TProfile>( hist );
36  auto n = ( h ? new Profile1D( new TProfile( *h ) ) : nullptr );
37  return {n, n};
38 }
39 
40 namespace Gaudi {
41  template <>
43  return int( m_rep->GetBinEntries( rIndex( index ) ) + 0.5 );
44  }
45 
46  template <>
47  void* Generic1D<AIDA::IProfile1D, TProfile>::cast( const std::string& className ) const {
48  return className == "AIDA::IProfile1D"
49  ? const_cast<AIDA::IProfile1D*>( static_cast<const AIDA::IProfile1D*>( this ) )
50  : className == "AIDA::IProfile"
51  ? const_cast<AIDA::IProfile*>( static_cast<const AIDA::IProfile*>( this ) )
52  : className == "AIDA::IBaseHistogram"
53  ? const_cast<AIDA::IBaseHistogram*>( static_cast<const AIDA::IBaseHistogram*>( this ) )
54  : nullptr;
55  }
56 
57  template <>
59  TProfile* imp = dynamic_cast<TProfile*>( rep );
60  if ( !imp ) throw std::runtime_error( "Cannot adopt native histogram representation." );
61  m_rep.reset( imp );
62  m_axis.initialize( m_rep->GetXaxis(), true );
63  const TArrayD* a = m_rep->GetSumw2();
64  if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
65  setTitle( m_rep->GetTitle() );
66  }
67 } // namespace Gaudi
68 
69 Gaudi::Profile1D::Profile1D() : Base( new TProfile() ) { init( "", false ); }
70 
71 Gaudi::Profile1D::Profile1D( TProfile* rep ) : Base( rep ) { init( m_rep->GetTitle() ); }
72 
73 void Gaudi::Profile1D::init( const std::string& title, bool initialize_axis ) {
74  m_classType = "IProfile1D";
75  setTitle( title );
76  setName( title );
77  if ( initialize_axis ) { axis().initialize( m_rep->GetXaxis(), false ); }
78  // m_rep->SetErrorOption("s");
79  m_rep->SetDirectory( nullptr );
80  m_sumEntries = 0;
81 }
82 
83 bool Gaudi::Profile1D::setBinContents( int i, int entries, double height, double /*error*/, double spread,
84  double /* centre */ ) {
85  m_rep->SetBinEntries( rIndex( i ), entries );
86  // set content takes in root height * entries
87  m_rep->SetBinContent( rIndex( i ), height * entries );
88  // set error takes sqrt of bin sum(w*y**2)
89  double sumwy2Bin = ( spread * spread + height * height ) * entries;
90  m_rep->SetBinError( rIndex( i ), sqrt( sumwy2Bin ) );
92  // not very efficient (but do evey bin since root cannot figure out by himself)
93  m_rep->SetEntries( m_sumEntries );
94  return true;
95 }
96 
97 #ifdef __ICC
98 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
99 // The comparison is correct
100 # pragma warning( disable : 1572 )
101 #endif
102 bool Gaudi::Profile1D::fill( double x, double y, double weight ) {
103  // avoid race conditions when filling the profile
105  ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight );
106  return true;
107 }
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:72
std::string m_classType
Definition: Generic1D.h:132
std::vector< double > Edges
Definition: GaudiPI.h:17
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition: P1D.cpp:83
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
STL class.
Axis & axis()
Access to axis object.
Definition: Generic1D.h:67
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:130
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic1D.h:138
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:69
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:63
std::mutex m_fillSerialization
Definition: P1D.h:40
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:102
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:102
void init(const std::string &title, bool initialize_axis=true)
Definition: P1D.cpp:73
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:146
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:35