The Gaudi Framework  v36r9p1 (5c15b2bb)
GaudiHistos_3DFixedBinning.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 // ==================================== 3D ====================================
13 // ============================================================================
14 // book the 3D histogram (book on demand)
15 // ============================================================================
16 template <class PBASE>
17 AIDA::IHistogram3D* GaudiHistos<PBASE>::book3D( 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 double lowZ, const double highZ,
20  const unsigned long binsZ ) const {
21  //
22  if ( !produceHistos() ) { return nullptr; } // RETURN
23  //
24  // exist?
25  auto hist = histo3D( title );
26  // histogram is already booked
27  if ( hist ) { return hist; } // RETURN !!
28 
29  // propose the histogram ID
30  HistoID ID;
31  newHistoID( title, ID );
32 
33  // Create a new histogram and return
34  return this->book3D( ID, title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ );
35 }
36 // ============================================================================
37 // book the 3D histogram with forced ID (book on demand)
38 // ============================================================================
39 template <class PBASE>
40 AIDA::IHistogram3D* GaudiHistos<PBASE>::book3D( const HistoID& ID, const std::string& title, const double lowX,
41  const double highX, const unsigned long binsX, const double lowY,
42  const double highY, const unsigned long binsY, const double lowZ,
43  const double highZ, const unsigned long binsZ ) const {
44  //
45  if ( !produceHistos() ) { return nullptr; } // RETURN
46  //
47  // Check ID
48  if ( ID.undefined() ) {
49  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
50  return nullptr;
51  }
52 
53  // exist?
54  auto hist = histo3D( ID );
55  // histogram is already booked
56  if ( hist ) { return hist; } // RETURN !!
57 
58  // Histogram title
59  const std::string& htitle = ( title.empty() ? "Unnamed 3D Histogram ID=" + ID.idAsString() : title );
60 
61  // book the histogram
62  if ( ID.numeric() ) {
63  hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY, binsZ,
64  lowZ, highZ );
65  } else if ( ID.literal() ) {
66  hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY, highY,
67  binsZ, lowZ, highZ );
68  }
69 
70  // Check OK
71  if ( !hist ) {
72  this->Error( "IHistogram3D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
73  return nullptr;
74  } // RETURN !!
75 
76  // add histogram into histogram storages
77  m_histo3DMapID[ID] = hist;
78  m_histo3DMapTitle[title] = hist;
79 
80  // Declare to monitoring service
81  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
82 
83  // Printout and return
84  if ( this->msgLevel( MSG::DEBUG ) ) {
85  this->debug() << "Booked 3D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
86  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
87  }
88  return hist;
89 }
90 // ============================================================================
91 // fill the 3D histogram with the values and weight
92 // ============================================================================
93 template <class PBASE>
94 AIDA::IHistogram3D* GaudiHistos<PBASE>::fill( AIDA::IHistogram3D* histo, const double valueX, const double valueY,
95  const double valueZ, const double weight,
96  const std::string& title ) const {
97  if ( !histo ) { return nullptr; } // RETURN
98  //
99  if ( !checkForNaN() ) {
100  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
101  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( valueZ ) &&
102  std::isfinite( weight ) ) {
103  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
104  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( valueZ ) || std::isnan( weight ) ) {
105  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
106  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
107  .ignore();
108  } else {
109  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
110  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
111  .ignore();
112  }
113  // return
114  return histo;
115 }
116 // ============================================================================
117 // fill the 3D histogram (book on demand)
118 // ============================================================================
119 template <class PBASE>
120 AIDA::IHistogram3D*
121 GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ, const std::string& title,
122  const double lowX, const double highX, const double lowY, const double highY,
123  const double lowZ, const double highZ, const unsigned long binsX, const unsigned long binsY,
124  const unsigned long binsZ, const double weight ) const {
125  AIDA::IHistogram3D* h( nullptr );
126  if ( produceHistos() ) {
127  // retrieve or book the histogram
128  h = histo3D( title );
129  if ( !h ) { h = book3D( title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ ); }
130  // fill the histogram
131  h = fill( h, valueX, valueY, valueZ, weight, title );
132  }
133  return h;
134 }
135 // ============================================================================
136 // fill the 3D histogram with forced ID assignment (book on demand)
137 // ============================================================================
138 template <class PBASE>
139 AIDA::IHistogram3D*
140 GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ, const HistoID& ID,
141  const std::string& title, const double lowX, const double highX, const double lowY,
142  const double highY, const double lowZ, const double highZ, const unsigned long binsX,
143  const unsigned long binsY, const unsigned long binsZ, const double weight ) const {
144  AIDA::IHistogram3D* h( nullptr );
145  if ( produceHistos() ) {
146  // retrieve or book the histogram
147  h = histo3D( ID );
148  if ( !h ) { h = book3D( ID, title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ ); }
149  // fill the histogram
150  h = fill( h, valueX, valueY, valueZ, weight, title );
151  }
152  return h;
153 }
154 // ============================================================================
155 // The END
156 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
GaudiHistos::plot3D
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)
Definition: GaudiHistos_3DFixedBinning.icpp:121
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
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::book3D
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
Definition: GaudiHistos_3DFixedBinning.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