The Gaudi Framework  v36r1 (3e2fb5a8)
GaudiHistos_2DProfFixedBinning.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 2D profile histogram (book on demand)
13 // ============================================================================
14 template <class PBASE>
15 AIDA::IProfile2D* GaudiHistos<PBASE>::bookProfile2D( const std::string& title, const double lowX, const double highX,
16  const unsigned long binsX, const double lowY, const double highY,
17  const unsigned long binsY ) const {
18  //
19  if ( !produceHistos() ) { return 0; } // RETURN
20  //
21  // exist?
22  auto hist = profile2D( title );
23  // histogram is already booked
24  if ( 0 != hist ) { return hist; } // RETURN !!
25 
26  // propose the histogram ID
27  HistoID ID;
28  newHistoID( title, ID );
29 
30  // book histogram and return
31  return this->bookProfile2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
32 }
33 // ============================================================================
34 // book the 2D profile histogram with forced ID (book on demand)
35 // ============================================================================
36 template <class PBASE>
37 AIDA::IProfile2D* GaudiHistos<PBASE>::bookProfile2D( const HistoID& ID, const std::string& title, const double lowX,
38  const double highX, const unsigned long binsX, const double lowY,
39  const double highY, const unsigned long binsY ) const {
40  //
41  if ( !produceHistos() ) { return 0; } // RETURN
42  //
43  // Check ID
44  if ( ID.undefined() ) {
45  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
46  return nullptr;
47  }
48  // exist?
49  auto hist = profile2D( ID );
50  // histogram is already booked
51  if ( 0 != hist ) { return hist; } // RETURN !!
52 
53  // Histogram title
54  const std::string& htitle = ( title.empty() ? "Unnamed 2D Profile Histogram ID=" + ID.idAsString() : title );
55 
56  // book the histogram
57  if ( ID.numeric() ) {
58  hist = this->histoSvc()->bookProf( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
59  } else if ( ID.literal() ) {
60  hist = this->histoSvc()->bookProf( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY,
61  highY );
62  }
63 
64  // test OK
65  if ( 0 == hist ) {
66  this->Error( "IProfile2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
67  return 0;
68  } // RETURN !!
69 
70  // add histogram into histogram storages
71  m_profile2DMapID[ID] = hist;
72  m_profile2DMapTitle[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 Profile Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
80  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
81  }
82  return hist;
83 }
84 // ============================================================================
85 // fill the 2D profile histogram with the value and weight
86 // ============================================================================
87 template <class PBASE>
88 AIDA::IProfile2D* GaudiHistos<PBASE>::fill( AIDA::IProfile2D* histo, const double valueX, const double valueY,
89  const double valueZ, const double weight, const std::string& title ) const {
90  if ( 0 == histo ) { return 0; } // RETURN
91  //
92  if ( !checkForNaN() ) {
93  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
94  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( valueZ ) &&
95  std::isfinite( weight ) ) {
96  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
97  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( valueZ ) || std::isnan( weight ) ) {
98  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
99  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
100  .ignore();
101  } else {
102  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
103  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
104  .ignore();
105  }
106  // return
107  return histo;
108 }
109 // ============================================================================
110 // fill the 2D profile histogram (book on demand)
111 // ============================================================================
112 template <class PBASE>
113 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
114  const std::string& title, const double lowX, const double highX,
115  const double lowY, const double highY, const unsigned long binsX,
116  const unsigned long binsY, const double weight ) const {
117  AIDA::IProfile2D* h = nullptr;
118  if ( produceHistos() ) {
119  // retrieve or book the histogram
120  h = profile2D( title );
121  if ( 0 == h ) { h = bookProfile2D( title, lowX, highX, binsX, lowY, highY, binsY ); }
122  // fill the histogram
123  h = fill( h, valueX, valueY, valueZ, weight, title );
124  }
125  return h;
126 }
127 // ============================================================================
128 // fill the 2D profile histogram with forced ID assignment (book on demand)
129 // ============================================================================
130 template <class PBASE>
131 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
132  const HistoID& ID, const std::string& title, const double lowX,
133  const double highX, const double lowY, const double highY,
134  const unsigned long binsX, const unsigned long binsY,
135  const double weight ) const {
136  AIDA::IProfile2D* h = nullptr;
137  if ( produceHistos() ) {
138  // retrieve or book the histogram
139  h = profile2D( ID );
140  if ( 0 == h ) { h = bookProfile2D( ID, title, lowX, highX, binsX, lowY, highY, binsY ); }
141  // fill the histogram
142  h = fill( h, valueX, valueY, valueZ, weight, title );
143  }
144  return h;
145 }
146 // ============================================================================
147 // The END
148 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
GaudiHistos::bookProfile2D
AIDA::IProfile2D * bookProfile2D(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 profile histogram
Definition: GaudiHistos_2DProfFixedBinning.icpp:15
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
std::string::empty
T empty(T... args)
GaudiHistos::profile2D
AIDA::IProfile2D * profile2D(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 unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D profile histogram (book on demand)
Definition: GaudiHistos_2DProfFixedBinning.icpp:113
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