| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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
8 ( const std::string& title ,
9 const double lowX ,
10 const double highX ,
11 const unsigned long binsX ,
12 const double lowY ,
13 const double highY ,
14 const unsigned long binsY ) const
15 {
16 //
17 if ( !produceHistos() ) { return nullptr ; } // RETURN
18 //
19 // exist?
20 auto hist = histo2D ( title ) ;
21 // histogram is already booked
22 if( hist ) { return hist ; } // RETURN !!
23
24 // propose the histogram ID
25 HistoID ID;
26 newHistoID( title, ID );
27
28 // Create a new histogram and return
29 return this -> book2D ( ID, title, lowX, highX, binsX, lowY, highY, binsY );
30 }
31 // ============================================================================
32 // book the 2D histogram with forced ID (book on demand)
33 // ============================================================================
34 template <class PBASE>
35 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D
36 ( const HistoID& ID ,
37 const std::string& title ,
38 const double lowX ,
39 const double highX ,
40 const unsigned long binsX ,
41 const double lowY ,
42 const double highY ,
43 const unsigned long binsY ) const
44 {
45 //
46 if ( !produceHistos() ) { return nullptr ; } // RETURN
47 //
48 // Check ID
49 if (ID.undefined())
50 {
51 this->Error("Undefined Histogram ID : Title='"+title+"'");
52 return nullptr;
53 }
54
55 // exist?
56 auto hist = histo2D( ID ) ;
57 // histogram is already booked
58 if( hist ) { return hist ; } // RETURN !!
59
60 // Histogram title
61 const std::string & htitle =
62 ( title.empty() ? "Unnamed 2D Histogram ID="+ID.idAsString() : title ) ;
63
64 // book the histogram
65 if ( ID.numeric() )
66 {
67 hist = this->histoSvc() -> book ( histoPath() ,
68 ID.numericID() ,
69 htitle ,
70 binsX ,
71 lowX ,
72 highX ,
73 binsY ,
74 lowY ,
75 highY ) ;
76 }
77 else if ( ID.literal() )
78 {
79 hist = this->histoSvc() -> book ( histoPath()+"/"+
80 ID.literalID() ,
81 htitle ,
82 binsX ,
83 lowX ,
84 highX ,
85 binsY ,
86 lowY ,
87 highY ) ;
88 }
89
90 // Check OK
91 if( !hist )
92 { this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() +
93 "' title='"+htitle+"'" ) ; return nullptr; } // RETURN !!
94
95 // add histogram into histogram storages
96 m_histo2DMapID [ ID ] = hist ;
97 m_histo2DMapTitle [ title ] = hist ;
98
99 // Declare to monitoring service
100 monitorHisto( Gaudi::Utils::Histos::toBase ( hist) , ID );
101
102 // Printout and return
103 if ( this->msgLevel(MSG::DEBUG) )
104 { this->debug() << "Booked 2D Histogram : ID='"
105 << ID << "' Path=" << histoPath()
106 << " Title='"
107 << Gaudi::Utils::Histos::htitle ( hist )
108 << "'" << endmsg; }
109 // return
110 return hist ;
111 }
112 // ============================================================================
113 // fill the 2D histogram with the values and weight
114 // ============================================================================
115 template <class PBASE>
116 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill
117 ( AIDA::IHistogram2D* histo ,
118 const double valueX ,
119 const double valueY ,
120 const double weight ,
121 const std::string& title ) const
122 {
123 //
124 if ( !histo ) { return nullptr ; } // RETURN
125 //
126 if ( !checkForNaN() )
127 { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
128 else if ( std::isfinite ( valueX ) && std::isfinite ( valueY ) && std::isfinite ( weight ) )
129 { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
130 else if ( std::isnan ( valueX ) || std::isnan ( valueY ) || std::isnan ( weight ) )
131 {
132 this -> Warning
133 ("fill():: 'NaN' value is skipped from the histogram '"
134 + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
135 }
136 else
137 {
138 this -> Warning
139 ("fill():: 'Infinite' value is skipped from the histogram '"
140 + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
141 }
142 // return
143 return histo ;
144 }
145 // ============================================================================
146 // fill the 2D histogram (book on demand)
147 // ============================================================================
148 template <class PBASE>
149 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D
150 ( const double valueX ,
151 const double valueY ,
152 const std::string& title ,
153 const double lowX ,
154 const double highX ,
155 const double lowY ,
156 const double highY ,
157 const unsigned long binsX ,
158 const unsigned long binsY ,
159 const double weight ) const
160 {
161 AIDA::IHistogram2D * h(nullptr);
162 if ( produceHistos() )
163 {
164 // retrieve or book the histogram
165 h = histo2D ( title ) ;
166 if ( !h )
167 { h = book2D ( title , lowX , highX , binsX , lowY , highY , binsY ) ; }
168 // fill the histogram
169 h = fill ( h , valueX , valueY , weight , title ) ;
170 }
171 return h;
172 }
173 // ============================================================================
174 // fill the 2D histogram with forced ID assignment (book on demand)
175 // ============================================================================
176 template <class PBASE>
177 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D
178 ( const double valueX ,
179 const double valueY ,
180 const HistoID& ID ,
181 const std::string& title ,
182 const double lowX ,
183 const double highX ,
184 const double lowY ,
185 const double highY ,
186 const unsigned long binsX ,
187 const unsigned long binsY ,
188 const double weight ) const
189 {
190 AIDA::IHistogram2D * h(nullptr);
191 // produce histograms ?
192 if ( produceHistos() )
193 {
194 // retrieve or book the histogram
195 h = histo2D ( ID ) ;
196 if ( !h ) { h = book2D ( ID , title ,
197 lowX , highX , binsX ,
198 lowY , highY , binsY ) ; }
199 // fill the histogram
200 h = fill ( h , valueX , valueY , weight , title ) ;
201 }
202 return h;
203 }
204 // ============================================================================
205 // The END
206 // ============================================================================
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
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
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:8
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:76
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:150
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
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