The Gaudi Framework  v36r9p1 (5c15b2bb)
GaudiHistos_2DFixedBinning.icpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 // ==================================== 2D ====================================
13 // ============================================================================
14 // book the 2D histogram (book on demand)
15 // ============================================================================
16 template <class PBASE>
17 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const std::string& title, const double lowX, const double highX,
18  const unsigned long binsX, const double lowY, const double highY,
19  const unsigned long binsY ) const {
20  //
21  if ( !produceHistos() ) { return nullptr; } // RETURN
22  //
23  // exist?
24  auto hist = histo2D( title );
25  // histogram is already booked
26  if ( hist ) { return hist; } // RETURN !!
27 
28  // propose the histogram ID
29  HistoID ID;
30  newHistoID( title, ID );
31 
32  // Create a new histogram and return
33  return this->book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
34 }
35 // ============================================================================
36 // book the 2D histogram with forced ID (book on demand)
37 // ============================================================================
38 template <class PBASE>
39 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const HistoID& ID, const std::string& title, const double lowX,
40  const double highX, const unsigned long binsX, const double lowY,
41  const double highY, const unsigned long binsY ) const {
42  //
43  if ( !produceHistos() ) { return nullptr; } // RETURN
44  //
45  // Check ID
46  if ( ID.undefined() ) {
47  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
48  return nullptr;
49  }
50 
51  // exist?
52  auto hist = histo2D( ID );
53  // histogram is already booked
54  if ( hist ) { return hist; } // RETURN !!
55 
56  // Histogram title
57  const std::string& htitle = ( title.empty() ? "Unnamed 2D Histogram ID=" + ID.idAsString() : title );
58 
59  // book the histogram
60  if ( ID.numeric() ) {
61  hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
62  } else if ( ID.literal() ) {
63  hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
64  }
65 
66  // Check OK
67  if ( !hist ) {
68  this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
69  return nullptr;
70  } // RETURN !!
71 
72  // add histogram into histogram storages
73  m_histo2DMapID[ID] = hist;
74  m_histo2DMapTitle[title] = hist;
75 
76  // Declare to monitoring service
77  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
78 
79  // Printout and return
80  if ( this->msgLevel( MSG::DEBUG ) ) {
81  this->debug() << "Booked 2D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
82  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
83  }
84  // return
85  return hist;
86 }
87 // ============================================================================
88 // fill the 2D histogram with the values and weight
89 // ============================================================================
90 template <class PBASE>
91 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill( AIDA::IHistogram2D* histo, const double valueX, const double valueY,
92  const double weight, const std::string& title ) const {
93  //
94  if ( !histo ) { return nullptr; } // RETURN
95  //
96  if ( !checkForNaN() ) {
97  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
98  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( weight ) ) {
99  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
100  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( weight ) ) {
101  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
102  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
103  .ignore();
104  } else {
105  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
106  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
107  .ignore();
108  }
109  // return
110  return histo;
111 }
112 // ============================================================================
113 // fill the 2D histogram (book on demand)
114 // ============================================================================
115 template <class PBASE>
116 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
117  const double lowX, const double highX, const double lowY,
118  const double highY, const unsigned long binsX,
119  const unsigned long binsY, const double weight ) const {
120  AIDA::IHistogram2D* h( nullptr );
121  if ( produceHistos() ) {
122  // retrieve or book the histogram
123  h = histo2D( title );
124  if ( !h ) { h = book2D( title, lowX, highX, binsX, lowY, highY, binsY ); }
125  // fill the histogram
126  h = fill( h, valueX, valueY, weight, title );
127  }
128  return h;
129 }
130 // ============================================================================
131 // fill the 2D histogram with forced ID assignment (book on demand)
132 // ============================================================================
133 template <class PBASE>
134 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
135  const std::string& title, const double lowX, const double highX,
136  const double lowY, const double highY, const unsigned long binsX,
137  const unsigned long binsY, const double weight ) const {
138  AIDA::IHistogram2D* h( nullptr );
139  // produce histograms ?
140  if ( produceHistos() ) {
141  // retrieve or book the histogram
142  h = histo2D( ID );
143  if ( !h ) { h = book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY ); }
144  // fill the histogram
145  h = fill( h, valueX, valueY, weight, title );
146  }
147  return h;
148 }
149 // ============================================================================
150 // The END
151 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::string
STL class.
GaudiAlg::ID
Definition: GaudiHistoID.h:53
HistoEx.histo
histo
Definition: HistoEx.py:105
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:82
GaudiHistos::plot2D
AIDA::IHistogram2D * plot2D(const double valueX, const double valueY, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D histogram (book on demand)
Definition: GaudiHistos_2DFixedBinning.icpp:116
std::isnan
T isnan(T... args)
std::isfinite
T isfinite(T... args)
Gaudi::Utils::Histos::toBase
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:165
AlgSequencer.h
h
Definition: AlgSequencer.py:32
GaudiAlg::ID::undefined
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:78
Gaudi::Utils::Histos::htitle
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:119
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
GaudiHistos::book2D
AIDA::IHistogram2D * book2D(const std::string &title, const double lowX=0, const double highX=100, const unsigned long binsX=50, const double lowY=0, const double highY=100, const unsigned long binsY=50) const
book the 2D histogram
Definition: GaudiHistos_2DFixedBinning.icpp:17
std::string::empty
T empty(T... args)
Gaudi::Utils::Histos::fill
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:45
GaudiAlg::ID::literalID
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:80
GaudiAlg::ID::idAsString
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
Definition: GaudiHistoID.cpp:30
GaudiAlg::ID::numeric
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:74
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:76
GaudiHistos::fill
AIDA::IHistogram1D * fill(AIDA::IHistogram1D *histo, const double value, const double weight, const std::string &title="") const
fill the 1D histogram with the value and weight
Definition: GaudiHistos_1DFixedBinning.icpp:89