| The Gaudi Framework v32r1 (f65d50dc)

GaudiHistos_1DFixedBinning.icpp
Go to the documentation of this file.
1 // ==================================== 1D ====================================
2 // ================================ Fixed Binning =============================
3 // ============================================================================
4 // book the 1D histogram (book on demand)
5 // ============================================================================
6 template <class PBASE>
7 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const std::string& title, const double low, const double high,
8 const unsigned long bins ) const {
9 //
10 if ( !produceHistos() ) { return nullptr; } // RETURN
11 //
12 // exist?
13 auto hist = histo1D( title );
14 // histogram is already booked
15 if ( hist ) { return hist; } // RETURN !!
16
17 // propose the histogram ID
18 HistoID ID;
19 newHistoID( title, ID );
20
21 // Create a new histogram and return
22 return this->book1D( ID, title, low, high, bins );
23 }
24 // ============================================================================
25 // book the 1D histogram with forced ID (book on demand)
26 // ============================================================================
27 template <class PBASE>
28 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const HistoID& ID, const std::string& title, const double low,
29 const double high, const unsigned long bins ) const {
30 //
31 if ( !produceHistos() ) { return nullptr; } // RETURN
32 //
33
34 // Check ID
35 if ( ID.undefined() ) {
36 this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
37 return nullptr;
38 }
39
40 // exist?
41 auto* hist = histo1D( ID );
42 // histogram is already booked
43 if ( hist ) { return hist; } // RETURN !!
44
45 // Histogram title
46 const std::string& htitle = ( title.empty() ? "Unnamed 1D Histogram ID=" + ID.idAsString() : title );
47
48 // book the histogram
49 if ( ID.numeric() ) {
50 hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, bins, low, high );
51 } else if ( ID.literal() ) {
52 hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, bins, low, high );
53 }
54
55 // check OK
56 if ( !hist ) {
57 this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
58 return nullptr;
59 } // RETURN !!
60
61 // add histogram into histogram storages
62 m_histo1DMapID[ID] = hist;
63 m_histo1DMapTitle[title] = hist;
64
65 // Declare to monitoring service
66 monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
67
68 // Printout and return
69 if ( this->msgLevel( MSG::DEBUG ) ) {
70 this->debug() << "Booked 1D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
71 << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
72 }
73 return hist;
74 }
75 // ============================================================================
76 // fill the 1D histogram with the value and weight
77 // ============================================================================
78 template <class PBASE>
79 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill( AIDA::IHistogram1D* histo, const double value, const double weight,
80 const std::string& title ) const {
81 if ( !histo ) { return nullptr; } // RETURN
82 //
83 if ( !checkForNaN() ) {
84 Gaudi::Utils::Histos::fill( histo, value, weight );
85 } else if ( std::isfinite( value ) && std::isfinite( weight ) ) {
86 Gaudi::Utils::Histos::fill( histo, value, weight );
87 } else if ( std::isnan( value ) || std::isnan( weight ) ) {
88 this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
89 Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
90 .ignore();
91 } else {
92 this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
93 Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
94 .ignore();
95 }
96 // return
97 return histo;
98 }
99 // ============================================================================
100 // fill the 1D histogram (book on demand)
101 // ============================================================================
102 template <class PBASE>
103 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const std::string& title, const double low,
104 const double high, const unsigned long bins,
105 const double weight ) const {
106 AIDA::IHistogram1D* h( nullptr );
107 if ( produceHistos() ) {
108 // retrieve or book the histogram
109 h = histo1D( title );
110 if ( !h ) { h = book1D( title, low, high, bins ); }
111 // fill the histogram
112 h = fill( h, value, weight, title );
113 }
114 return h;
115 }
116 // ============================================================================
117 // fill the 1D histogram with forced ID assignment (book on demand)
118 // ============================================================================
119 template <class PBASE>
120 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const std::string& title,
121 const double low, const double high, const unsigned long bins,
122 const double weight ) const {
123 AIDA::IHistogram1D* h( nullptr );
124 if ( produceHistos() ) {
125 // retrieve or book the histogram
126 h = histo1D( ID );
127 if ( !h ) { h = book1D( ID, title, low, high, bins ); }
128 // fill
129 h = fill( h, value, weight, title );
130 }
131 return h;
132 }
133 // ============================================================================
134 // book the 1D histogram
135 // ============================================================================
136 template <class PBASE>
137 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const Gaudi::Histo1DDef& hdef ) const {
138 return book1D( hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
139 }
140 // ============================================================================
141 // book the 1D histogram with forced ID
142 // ============================================================================
143 template <class PBASE>
144 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const HistoID& ID, const Gaudi::Histo1DDef& hdef ) const {
145 return book1D( ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
146 }
147 // ============================================================================
148 // fill the 1D histogram (book on demand)
149 // ============================================================================
150 template <class PBASE>
151 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const Gaudi::Histo1DDef& hdef,
152 const double weight ) const {
153 return plot1D( value, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
154 }
155 // ============================================================================
156 // fill the 1D histogram with forced ID assignment (book on demand)
157 // ============================================================================
158 template <class PBASE>
159 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const Gaudi::Histo1DDef& hdef,
160 const double weight ) const {
161 return plot1D( value, ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
162 }
163 // ============================================================================
164 // The END
165 // ============================================================================
GaudiAlg::ID::literalID
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:70
GaudiHistos::plot1D
AIDA::IHistogram1D * plot1D(const double value, const std::string &title, const double low, const double high, const unsigned long bins=100, const double weight=1.0) const
fill the 1D histogram (book on demand)
Definition: GaudiHistos_1DFixedBinning.icpp:103
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
GaudiHistos::book1D
AIDA::IHistogram1D * book1D(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100) const
book the 1D histogram
Definition: GaudiHistos_1DFixedBinning.icpp:7
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
Gaudi::Histo1DDef
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:31
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)
Gaudi::Histo1DDef::title
const std::string & title() const
get the title
Definition: HistoDef.h:59
Gaudi::Histo1DDef::bins
int bins() const
get the number of bins
Definition: HistoDef.h:57
GaudiHistos::book
AIDA::IHistogram1D * book(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100) const
book the 1D histogram
Definition: GaudiHistos.h:1849
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
Gaudi::Histo1DDef::highEdge
double highEdge() const
get the high edge
Definition: HistoDef.h:55
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
Gaudi::Histo1DDef::lowEdge
double lowEdge() const
get the low edge
Definition: HistoDef.h:53