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