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