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