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