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_3DVariableBinning.icpp
Go to the documentation of this file.
1 // ==================================== 3D ====================================
2 // ============================= Variable Binning =============================
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 HistoBinEdges& edgesX,
8  const HistoBinEdges& edgesY, const HistoBinEdges& edgesZ ) const {
9  //
10  if ( !produceHistos() ) { return nullptr; } // RETURN
11  //
12  // exist?
13  auto hist = histo3D( title );
14  // histogram is already booked
15  if ( hist ) { return hist; } // RETURN !!
16 
17  // propose the histogram ID
18  HistoID ID;
19  newHistoID( title, ID );
20 
21  // Create a new histogram and return
22  return this->book3D( ID, title, edgesX, edgesY, edgesZ );
23 }
24 // ============================================================================
25 // book the 2D histogram with forced ID (book on demand)
26 // ============================================================================
27 template <class PBASE>
28 AIDA::IHistogram3D* GaudiHistos<PBASE>::book3D( const HistoID& ID, const std::string& title,
29  const HistoBinEdges& edgesX, const HistoBinEdges& edgesY,
30  const HistoBinEdges& edgesZ ) const {
31  //
32  if ( !produceHistos() ) { return nullptr; } // RETURN
33  //
34  // Check ID
35  if ( ID.undefined() ) {
36  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
37  return nullptr;
38  }
39 
40  // exist?
41  auto hist = histo3D( ID );
42  // histogram is already booked
43  if ( hist ) { return hist; } // RETURN !!
44 
45  // Histogram title
46  const std::string& htitle = ( title.empty() ? "Unnamed 3D Histogram ID=" + ID.idAsString() : title );
47 
48  // book the histogram
49  if ( ID.numeric() ) {
50  hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, edgesX, edgesY, edgesZ );
51  } else if ( ID.literal() ) {
52  hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, edgesX, edgesY, edgesZ );
53  }
54 
55  // check OK
56  if ( !hist ) {
57  this->Error( "IHistogram3D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
58  return nullptr;
59  } // RETURN !!
60 
61  // add histogram into histogram storages
62  m_histo3DMapID[ID] = hist;
63  m_histo3DMapTitle[title] = hist;
64 
65  // Declare to monitoring service
66  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
67 
68  // Printout and return
69  if ( this->msgLevel( MSG::DEBUG ) ) {
70  this->debug() << "Booked 3D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
71  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
72  }
73  return hist;
74 }
75 // ============================================================================
76 // fill the 3D histogram (book on demand)
77 // ============================================================================
78 template <class PBASE>
79 AIDA::IHistogram3D* GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ,
80  const std::string& title, const HistoBinEdges& edgesX,
81  const HistoBinEdges& edgesY, const HistoBinEdges& edgesZ,
82  const double weight ) const {
83  AIDA::IHistogram3D* h( nullptr );
84  if ( produceHistos() ) {
85  // retrieve or book the histogram
86  h = histo3D( title );
87  if ( !h ) { h = book3D( title, edgesX, edgesY, edgesZ ); }
88  // fill the histogram
89  h = fill( h, valueX, valueY, valueZ, weight, title );
90  }
91  return h;
92 }
93 // ============================================================================
94 // fill the 3D variable histogram with forced ID assignment (book on demand)
95 // ============================================================================
96 template <class PBASE>
97 AIDA::IHistogram3D* GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ,
98  const HistoID& ID, const std::string& title,
99  const HistoBinEdges& edgesX, const HistoBinEdges& edgesY,
100  const HistoBinEdges& edgesZ, const double weight ) const {
101  AIDA::IHistogram3D* h( nullptr );
102  if ( produceHistos() ) {
103  // retrieve or book the histogram
104  h = histo3D( ID );
105  if ( !h ) { h = book3D( ID, title, edgesX, edgesY, edgesZ ); }
106  // fill
107  h = fill( h, valueX, valueY, valueZ, weight, title );
108  }
109  return h;
110 }
111 // ============================================================================
112 // The END
113 // ============================================================================
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
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
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