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