The Gaudi Framework  v36r1 (3e2fb5a8)
GaudiHistos_1DProfFixedBinning.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 double low, const double high,
16  const unsigned long bins, const std::string& opt,
17  const double lowY, const double highY ) const {
18  //
19  if ( !produceHistos() ) { return nullptr; } // RETURN
20  //
21  // exist?
22  auto hist = profile1D( 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  // Book the histo and return
31  return this->bookProfile1D( ID, title, low, high, bins, opt, lowY, highY );
32 }
33 // ============================================================================
34 // book the 1D profile histogram with forced ID (book on demand)
35 // ============================================================================
36 template <class PBASE>
37 AIDA::IProfile1D* GaudiHistos<PBASE>::bookProfile1D( const HistoID& ID, const std::string& title, const double low,
38  const double high, const unsigned long bins,
39  const std::string& opt, const double lowY,
40  const double highY ) 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 = profile1D( ID );
52  // histogram is already booked
53  if ( hist ) { return hist; } // RETURN !!
54 
55  // Histogram title
56  const std::string& htitle = ( title.empty() ? "Unnamed 1D Profile Histogram ID=" + ID.idAsString() : title );
57 
58  // book the histogram
59  if ( ID.numeric() ) {
60  hist = this->histoSvc()->bookProf( histoPath(), ID.numericID(), htitle, bins, low, high, lowY, highY, opt );
61  } else if ( ID.literal() ) {
62  hist = this->histoSvc()->bookProf( histoPath() + "/" + ID.literalID(), htitle, bins, low, high, lowY, highY, opt );
63  }
64 
65  // test ok
66  if ( !hist ) {
67  this->Error( "IProfile1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
68  return nullptr;
69  } // RETURN !!
70 
71  // add histogram into histogram storages
72  m_profile1DMapID[ID] = hist;
73  m_profile1DMapTitle[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 1D Profile Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
81  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
82  }
83  return hist;
84 }
85 // ============================================================================
86 // fill the 1D profile histogram with the value and weight
87 // ============================================================================
88 template <class PBASE>
89 AIDA::IProfile1D* GaudiHistos<PBASE>::fill( AIDA::IProfile1D* histo, const double valueX, const double valueY,
90  const double weight, const std::string& title ) const {
91  //
92  if ( !histo ) { return nullptr; } // RETURN
93  //
94  if ( !checkForNaN() ) {
95  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
96  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( weight ) ) {
97  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
98  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( weight ) ) {
99  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
100  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
101  .ignore();
102  } else {
103  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
104  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
105  .ignore();
106  }
107  // return
108  return histo;
109 }
110 // ============================================================================
111 // fill the 1D profile histogram (book on demand)
112 // ============================================================================
113 template <class PBASE>
114 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D( const double valueX, const double valueY, const std::string& title,
115  const double lowX, const double highX, const unsigned long binsX,
116  const std::string& opt, const double lowY, const double highY,
117  const double weight ) const {
118  AIDA::IProfile1D* h = nullptr;
119  if ( produceHistos() ) {
120  // retrieve or book the histogram
121  h = profile1D( title );
122  if ( !h ) { h = bookProfile1D( title, lowX, highX, binsX, opt, lowY, highY ); }
123  // fill the histogram
124  h = fill( h, valueX, valueY, weight, title );
125  }
126  return h;
127 }
128 // ============================================================================
129 // fill the 1D profile histogram with forced ID assignment (book on demand)
130 // ============================================================================
131 template <class PBASE>
132 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D( const double valueX, const double valueY, const HistoID& ID,
133  const std::string& title, const double lowX, const double highX,
134  const unsigned long binsX, const std::string& opt, const double lowY,
135  const double highY, const double weight ) const {
136  AIDA::IProfile1D* h = nullptr;
137  if ( produceHistos() ) {
138  // retrieve or book the histogram
139  h = profile1D( ID );
140  if ( !h ) { h = bookProfile1D( ID, title, lowX, highX, binsX, opt, lowY, highY ); }
141  // fill the histogram
142  h = fill( h, valueX, valueY, weight, title );
143  }
144  return h;
145 }
146 // ============================================================================
147 // The END
148 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::string
STL class.
GaudiAlg::ID
Definition: GaudiHistoID.h:53
HistoEx.histo
histo
Definition: HistoEx.py:103
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:82
std::isnan
T isnan(T... args)
std::isfinite
T isfinite(T... args)
Gaudi::Utils::Histos::toBase
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:165
AlgSequencer.h
h
Definition: AlgSequencer.py:26
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
GaudiHistos::fill
AIDA::IHistogram1D * fill(AIDA::IHistogram1D *histo, const double value, const double weight, const std::string &title="") const
fill the 1D histogram with the value and weight
Definition: GaudiHistos_1DFixedBinning.icpp:89