The Gaudi Framework  v36r9p1 (5c15b2bb)
GaudiHistos_1DProfVariableBinning.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 // ============================================================================
12 // book the 1D profile histogram (book on demand)
13 // ============================================================================
14 template <class PBASE>
15 AIDA::IProfile1D* GaudiHistos<PBASE>::bookProfile1D( const std::string& title, const HistoBinEdges& edges ) const {
16  //
17  if ( !produceHistos() ) { return nullptr; } // RETURN
18  //
19  // exist?
20  auto hist = profile1D( title );
21  // histogram is already booked
22  if ( hist ) { return hist; } // RETURN !!
23 
24  // propose the histogram ID
25  HistoID ID;
26  newHistoID( title, ID );
27 
28  // Book the histo and return
29  return this->bookProfile1D( ID, title, edges );
30 }
31 // ============================================================================
32 // book the 1D profile histogram with forced ID (book on demand)
33 // ============================================================================
34 template <class PBASE>
35 AIDA::IProfile1D* GaudiHistos<PBASE>::bookProfile1D( const HistoID& ID, const std::string& title,
36  const HistoBinEdges& edges ) const {
37  //
38  if ( !produceHistos() ) { return nullptr; } // RETURN
39  //
40  // Check ID
41  if ( ID.undefined() ) {
42  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
43  return nullptr;
44  }
45 
46  // exist?
47  auto hist = profile1D( ID );
48  // histogram is already booked
49  if ( hist ) { return hist; } // RETURN !!
50 
51  // Histogram title
52  const std::string& htitle = ( title.empty() ? "Unnamed 1D Profile Histogram ID=" + ID.idAsString() : title );
53 
54  // book the histogram
55  if ( ID.numeric() ) {
56  hist = this->histoSvc()->bookProf( histoPath(), ID.numericID(), htitle, edges );
57  } else if ( ID.literal() ) {
58  hist = this->histoSvc()->bookProf( histoPath() + "/" + ID.literalID(), htitle, edges );
59  }
60 
61  // test ok
62  if ( !hist ) {
63  this->Error( "IProfile1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
64  return nullptr;
65  } // RETURN !!
66 
67  // add histogram into histogram storages
68  m_profile1DMapID[ID] = hist;
69  m_profile1DMapTitle[title] = hist;
70 
71  // Declare to monitoring service
72  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
73 
74  // printout and return
75  if ( this->msgLevel( MSG::DEBUG ) ) {
76  this->debug() << "Booked 1D Profile Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
77  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
78  }
79  return hist;
80 }
81 // ============================================================================
82 // fill the 1D profile histogram (book on demand)
83 // ============================================================================
84 template <class PBASE>
85 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D( const double valueX, const double valueY, const std::string& title,
86  const HistoBinEdges& edges, const double weight ) const {
87  AIDA::IProfile1D* h( nullptr );
88  if ( produceHistos() ) {
89  // retrieve or book the histogram
90  h = profile1D( title );
91  if ( !h ) { h = bookProfile1D( title, edges ); }
92  // fill the histogram
93  h = fill( h, valueX, valueY, weight, title );
94  }
95  return h;
96 }
97 // ============================================================================
98 // fill the 1D profile histogram with forced ID assignment (book on demand)
99 // ============================================================================
100 template <class PBASE>
101 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D( const double valueX, const double valueY, const HistoID& ID,
102  const std::string& title, const HistoBinEdges& edges,
103  const double weight ) const {
104  AIDA::IProfile1D* h( nullptr );
105  if ( produceHistos() ) {
106  // retrieve or book the histogram
107  h = profile1D( ID );
108  if ( !h ) { h = bookProfile1D( ID, title, edges ); }
109  // fill the histogram
110  h = fill( h, valueX, valueY, weight, title );
111  }
112  return h;
113 }
114 // ============================================================================
115 // The END
116 // ============================================================================
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
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::bookProfile1D
AIDA::IProfile1D * bookProfile1D(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100, const std::string &opt="", const double lowY=-std::numeric_limits< double >::max(), const double highY=std::numeric_limits< double >::max()) const
book the 1D profile histogram
Definition: GaudiHistos_1DProfFixedBinning.icpp:15
GaudiHistos::profile1D
AIDA::IProfile1D * profile1D(const double valueX, const double valueY, const std::string &title, const double lowX, const double highX, const unsigned long binsX=100, const std::string &opt="", const double lowY=-std::numeric_limits< double >::max(), const double highY=std::numeric_limits< double >::max(), const double weight=1.0) const
fill the 1D profile histogram (book on demand)
Definition: GaudiHistos_1DProfFixedBinning.icpp:114
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