| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

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
8 ( const std::string& title ,
9 const double low ,
10 const double high ,
11 const unsigned long bins ) const
12 {
13 //
14 if ( !produceHistos() ) { return nullptr ; } // RETURN
15 //
16 // exist?
17 auto hist = histo1D ( title ) ;
18 // histogram is already booked
19 if( hist ) { return hist ; } // RETURN !!
20
21 // propose the histogram ID
22 HistoID ID;
23 newHistoID( title, ID );
24
25 // Create a new histogram and return
26 return this -> book1D ( ID, title, low, high, bins );
27 }
28 // ============================================================================
29 // book the 1D histogram with forced ID (book on demand)
30 // ============================================================================
31 template <class PBASE>
32 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D
33 ( const HistoID& ID ,
34 const std::string& title ,
35 const double low ,
36 const double high ,
37 const unsigned long bins ) const
38 {
39 //
40 if ( !produceHistos() ) { return nullptr ; } // RETURN
41 //
42
43 // Check ID
44 if ( ID.undefined() )
45 {
46 this->Error("Undefined Histogram ID : Title='"+title+"'");
47 return nullptr;
48 }
49
50 // exist?
51 auto* hist = histo1D ( ID ) ;
52 // histogram is already booked
53 if ( hist ) { return hist ; } // RETURN !!
54
55 // Histogram title
56 const std::string & htitle =
57 ( title.empty() ? "Unnamed 1D Histogram ID="+ID.idAsString() : title ) ;
58
59 // book the histogram
60 if ( ID.numeric() )
61 {
62 hist = this->histoSvc() -> book ( histoPath() ,
63 ID.numericID() ,
64 htitle ,
65 bins ,
66 low ,
67 high ) ;
68 }
69 else if ( ID.literal() )
70 {
71 hist = this->histoSvc() -> book ( histoPath()+"/"+
72 ID.literalID() ,
73 htitle ,
74 bins ,
75 low ,
76 high ) ;
77 }
78
79 // check OK
80 if( !hist )
81 { this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() +
82 "' title='"+htitle+"'" ) ; return nullptr; } // RETURN !!
83
84 // add histogram into histogram storages
85 m_histo1DMapID [ ID ] = hist ;
86 m_histo1DMapTitle [ title ] = hist ;
87
88 // Declare to monitoring service
89 monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
90
91 // Printout and return
92 if ( this->msgLevel(MSG::DEBUG) )
93 { this->debug() << "Booked 1D Histogram : ID='" << ID
94 << "' Path=" << histoPath()
95 << " Title='"
96 << Gaudi::Utils::Histos::htitle ( hist )
97 << "'" << endmsg; }
98 return hist ;
99 }
100 // ============================================================================
101 // fill the 1D histogram with the value and weight
102 // ============================================================================
103 template <class PBASE>
104 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill
105 ( AIDA::IHistogram1D* histo ,
106 const double value ,
107 const double weight ,
108 const std::string& title ) const
109 {
110 if ( !histo ) { return nullptr ; } // RETURN
111 //
112 if ( !checkForNaN() )
113 { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
114 else if ( std::isfinite ( value ) && std::isfinite ( weight ) )
115 { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
116 else if ( std::isnan ( value ) || std::isnan ( weight ) )
117 {
118 this -> Warning
119 ("fill():: 'NaN' value is skipped from the histogram '"
120 + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
121 }
122 else
123 {
124 this -> Warning
125 ("fill():: 'Infinite' value is skipped from the histogram '"
126 + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
127 }
128 // return
129 return histo ;
130 }
131 // ============================================================================
132 // fill the 1D histogram (book on demand)
133 // ============================================================================
134 template <class PBASE>
135 AIDA::IHistogram1D*
136 GaudiHistos<PBASE>::plot1D
137 ( const double value ,
138 const std::string& title ,
139 const double low ,
140 const double high ,
141 const unsigned long bins ,
142 const double weight ) const
143 {
144 AIDA::IHistogram1D * h(nullptr);
145 if ( produceHistos() )
146 {
147 // retrieve or book the histogram
148 h = histo1D ( title ) ;
149 if ( !h ) { h = book1D ( title , low , high , bins ) ; }
150 // fill the histogram
151 h = fill ( h , value , weight , title );
152 }
153 return h;
154 }
155 // ============================================================================
156 // fill the 1D histogram with forced ID assignment (book on demand)
157 // ============================================================================
158 template <class PBASE>
159 AIDA::IHistogram1D*
160 GaudiHistos<PBASE>::plot1D
161 ( const double value ,
162 const HistoID& ID ,
163 const std::string& title ,
164 const double low ,
165 const double high ,
166 const unsigned long bins ,
167 const double weight ) const
168 {
169 AIDA::IHistogram1D* h(nullptr);
170 if ( produceHistos() )
171 {
172 // retrieve or book the histogram
173 h = histo1D ( ID ) ;
174 if ( !h ) { h = book1D ( ID , title , low , high , bins ) ; }
175 // fill
176 h = fill ( h , value , weight , title ) ;
177 }
178 return h;
179 }
180 // ============================================================================
181 // book the 1D histogram
182 // ============================================================================
183 template <class PBASE>
184 AIDA::IHistogram1D*
185 GaudiHistos<PBASE>::book
186 ( const Gaudi::Histo1DDef& hdef ) const
187 {
188 return book1D ( hdef.title () ,
189 hdef.lowEdge () ,
190 hdef.highEdge () ,
191 hdef.bins () ) ;
192 }
193 // ============================================================================
194 // book the 1D histogram with forced ID
195 // ============================================================================
196 template <class PBASE>
197 AIDA::IHistogram1D*
198 GaudiHistos<PBASE>::book
199 ( const HistoID& ID ,
200 const Gaudi::Histo1DDef& hdef ) const
201 {
202 return book1D ( ID ,
203 hdef.title () ,
204 hdef.lowEdge () ,
205 hdef.highEdge () ,
206 hdef.bins () ) ;
207 }
208 // ============================================================================
209 // fill the 1D histogram (book on demand)
210 // ============================================================================
211 template <class PBASE>
212 AIDA::IHistogram1D*
213 GaudiHistos<PBASE>::plot1D
214 ( const double value ,
215 const Gaudi::Histo1DDef& hdef ,
216 const double weight ) const
217 {
218 return plot1D
219 ( value ,
220 hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
221 weight ) ;
222 }
223 // ============================================================================
224 // fill the 1D histogram with forced ID assignment (book on demand)
225 // ============================================================================
226 template <class PBASE>
227 AIDA::IHistogram1D*
228 GaudiHistos<PBASE>::plot1D
229 ( const double value ,
230 const HistoID& ID ,
231 const Gaudi::Histo1DDef& hdef ,
232 const double weight ) const
233 {
234 return plot1D
235 ( value , ID ,
236 hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
237 weight ) ;
238 }
239 // ============================================================================
240 // The END
241 // ============================================================================
242
Gaudi::Utils::Histos::htitle
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:138
std::string::empty
T empty(T...args)
Gaudi::Histos::book
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:124
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:8
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:82
MSG::DEBUG
Definition: IMessageSvc.h:18
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:36
Gaudi::Histo1DDef::highEdge
double highEdge() const
get the high edge
Definition: HistoDef.h:66
Gaudi::Histo1DDef::lowEdge
double lowEdge() const
get the low edge
Definition: HistoDef.h:64
Gaudi::Histo1DDef::title
const std::string & title() const
get the title
Definition: HistoDef.h:70
std::string
STL class.
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
Gaudi::Histo1DDef
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:30
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:76
std::isfinite
T isfinite(T...args)
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:1865
Gaudi::Histo1DDef::bins
int bins() const
get the number of bins
Definition: HistoDef.h:68
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:20
GaudiAlg::ID::numeric
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:74
std::isnan
T isnan(T...args)
Gaudi::Utils::Histos::toBase
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:193
GaudiAlg::ID::undefined
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:78
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:137
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:244
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:105