The Gaudi Framework  v30r3 (a5ef0a68)
GaudiHistos_2DFixedBinning.icpp
Go to the documentation of this file.
1 // ============================================================================
2 // ==================================== 2D ====================================
3 // ============================================================================
4 // book the 2D histogram (book on demand)
5 // ============================================================================
6 template <class PBASE>
7 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const std::string& title, const double lowX, const double highX,
8  const unsigned long binsX, const double lowY, const double highY,
9  const unsigned long binsY ) const
10 {
11  //
12  if ( !produceHistos() ) {
13  return nullptr;
14  } // RETURN
15  //
16  // exist?
17  auto hist = histo2D( title );
18  // histogram is already booked
19  if ( hist ) {
20  return hist;
21  } // RETURN !!
22 
23  // propose the histogram ID
24  HistoID ID;
25  newHistoID( title, ID );
26 
27  // Create a new histogram and return
28  return this->book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
29 }
30 // ============================================================================
31 // book the 2D histogram with forced ID (book on demand)
32 // ============================================================================
33 template <class PBASE>
34 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const HistoID& ID, const std::string& title, const double lowX,
35  const double highX, const unsigned long binsX, const double lowY,
36  const double highY, const unsigned long binsY ) const
37 {
38  //
39  if ( !produceHistos() ) {
40  return nullptr;
41  } // 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 ) {
53  return hist;
54  } // RETURN !!
55 
56  // Histogram title
57  const std::string& htitle = ( title.empty() ? "Unnamed 2D Histogram ID=" + ID.idAsString() : title );
58 
59  // book the histogram
60  if ( ID.numeric() ) {
61  hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
62  } else if ( ID.literal() ) {
63  hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
64  }
65 
66  // Check OK
67  if ( !hist ) {
68  this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
69  return nullptr;
70  } // RETURN !!
71 
72  // add histogram into histogram storages
73  m_histo2DMapID[ID] = hist;
74  m_histo2DMapTitle[title] = hist;
75 
76  // Declare to monitoring service
77  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
78 
79  // Printout and return
80  if ( this->msgLevel( MSG::DEBUG ) ) {
81  this->debug() << "Booked 2D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
82  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
83  }
84  // return
85  return hist;
86 }
87 // ============================================================================
88 // fill the 2D histogram with the values and weight
89 // ============================================================================
90 template <class PBASE>
91 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill( AIDA::IHistogram2D* histo, const double valueX, const double valueY,
92  const double weight, const std::string& title ) const
93 {
94  //
95  if ( !histo ) {
96  return nullptr;
97  } // RETURN
98  //
99  if ( !checkForNaN() ) {
100  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
101  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( weight ) ) {
102  Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
103  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( weight ) ) {
104  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
105  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
106  .ignore();
107  } else {
108  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
109  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
110  .ignore();
111  }
112  // return
113  return histo;
114 }
115 // ============================================================================
116 // fill the 2D histogram (book on demand)
117 // ============================================================================
118 template <class PBASE>
119 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
120  const double lowX, const double highX, const double lowY,
121  const double highY, const unsigned long binsX,
122  const unsigned long binsY, const double weight ) const
123 {
124  AIDA::IHistogram2D* h( nullptr );
125  if ( produceHistos() ) {
126  // retrieve or book the histogram
127  h = histo2D( title );
128  if ( !h ) {
129  h = book2D( title, lowX, highX, binsX, lowY, highY, binsY );
130  }
131  // fill the histogram
132  h = fill( h, valueX, valueY, weight, title );
133  }
134  return h;
135 }
136 // ============================================================================
137 // fill the 2D histogram with forced ID assignment (book on demand)
138 // ============================================================================
139 template <class PBASE>
140 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
141  const std::string& title, const double lowX, const double highX,
142  const double lowY, const double highY, const unsigned long binsX,
143  const unsigned long binsY, const double weight ) const
144 {
145  AIDA::IHistogram2D* h( nullptr );
146  // produce histograms ?
147  if ( produceHistos() ) {
148  // retrieve or book the histogram
149  h = histo2D( ID );
150  if ( !h ) {
151  h = book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
152  }
153  // fill the histogram
154  h = fill( h, valueX, valueY, weight, title );
155  }
156  return h;
157 }
158 // ============================================================================
159 // The END
160 // ============================================================================
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:126
T empty(T...args)
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:74
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:35
STL class.
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
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:68
T isfinite(T...args)
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)
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:72
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:66
T isnan(T...args)
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:180
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:70
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:44
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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