| The Gaudi Framework v32r1 (f65d50dc)

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