| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 + "'" );
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 + "'" );
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 } else {
107 this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
108 Gaudi::Utils::Histos::htitle( histo, title ) + "'" );
109 }
110 // return
111 return histo;
112 }
113 // ============================================================================
114 // fill the 2D histogram (book on demand)
115 // ============================================================================
116 template <class PBASE>
117 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
118 const double lowX, const double highX, const double lowY,
119 const double highY, const unsigned long binsX,
120 const unsigned long binsY, const double weight ) const
121 {
122 AIDA::IHistogram2D* h( nullptr );
123 if ( produceHistos() ) {
124 // retrieve or book the histogram
125 h = histo2D( title );
126 if ( !h ) {
127 h = book2D( title, lowX, highX, binsX, lowY, highY, binsY );
128 }
129 // fill the histogram
130 h = fill( h, valueX, valueY, weight, title );
131 }
132 return h;
133 }
134 // ============================================================================
135 // fill the 2D histogram with forced ID assignment (book on demand)
136 // ============================================================================
137 template <class PBASE>
138 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
139 const std::string& title, const double lowX, const double highX,
140 const double lowY, const double highY, const unsigned long binsX,
141 const unsigned long binsY, const double weight ) const
142 {
143 AIDA::IHistogram2D* h( nullptr );
144 // produce histograms ?
145 if ( produceHistos() ) {
146 // retrieve or book the histogram
147 h = histo2D( ID );
148 if ( !h ) {
149 h = book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
150 }
151 // fill the histogram
152 h = fill( h, valueX, valueY, weight, title );
153 }
154 return h;
155 }
156 // ============================================================================
157 // The END
158 // ============================================================================
Gaudi::Utils::Histos::htitle
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:126
std::string::empty
T empty(T...args)
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:74
MSG::DEBUG
Definition: IMessageSvc.h:16
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.
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
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
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:68
std::isfinite
T isfinite(T...args)
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:117
GaudiAlg::ID::literalID
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
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::numeric
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:66
std::isnan
T isnan(T...args)
Gaudi::Utils::Histos::toBase
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:180
GaudiAlg::ID::undefined
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:70
GaudiAlg::ID
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:44
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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