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