| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

GaudiHistos_3DFixedBinning.icpp
Go to the documentation of this file.
1 // ============================================================================
2 // ==================================== 3D ====================================
3 // ============================================================================
4 // book the 3D histogram (book on demand)
5 // ============================================================================
6 template <class PBASE>
7 AIDA::IHistogram3D* GaudiHistos<PBASE>::book3D( 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 double lowZ, const double highZ,
10 const unsigned long binsZ ) const
11 {
12 //
13 if ( !produceHistos() ) {
14 return nullptr;
15 } // RETURN
16 //
17 // exist?
18 auto hist = histo3D( title );
19 // histogram is already booked
20 if ( hist ) {
21 return hist;
22 } // 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->book3D( ID, title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ );
30 }
31 // ============================================================================
32 // book the 3D histogram with forced ID (book on demand)
33 // ============================================================================
34 template <class PBASE>
35 AIDA::IHistogram3D* GaudiHistos<PBASE>::book3D( const HistoID& ID, const std::string& title, const double lowX,
36 const double highX, const unsigned long binsX, const double lowY,
37 const double highY, const unsigned long binsY, const double lowZ,
38 const double highZ, const unsigned long binsZ ) const
39 {
40 //
41 if ( !produceHistos() ) {
42 return nullptr;
43 } // RETURN
44 //
45 // Check ID
46 if ( ID.undefined() ) {
47 this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
48 return nullptr;
49 }
50
51 // exist?
52 auto hist = histo3D( ID );
53 // histogram is already booked
54 if ( hist ) {
55 return hist;
56 } // RETURN !!
57
58 // Histogram title
59 const std::string& htitle = ( title.empty() ? "Unnamed 3D Histogram ID=" + ID.idAsString() : title );
60
61 // book the histogram
62 if ( ID.numeric() ) {
63 hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY, binsZ,
64 lowZ, highZ );
65 } else if ( ID.literal() ) {
66 hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY, highY,
67 binsZ, lowZ, highZ );
68 }
69
70 // Check OK
71 if ( !hist ) {
72 this->Error( "IHistogram3D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
73 return nullptr;
74 } // RETURN !!
75
76 // add histogram into histogram storages
77 m_histo3DMapID[ID] = hist;
78 m_histo3DMapTitle[title] = hist;
79
80 // Declare to monitoring service
81 monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
82
83 // Printout and return
84 if ( this->msgLevel( MSG::DEBUG ) ) {
85 this->debug() << "Booked 3D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
86 << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
87 }
88 return hist;
89 }
90 // ============================================================================
91 // fill the 3D histogram with the values and weight
92 // ============================================================================
93 template <class PBASE>
94 AIDA::IHistogram3D* GaudiHistos<PBASE>::fill( AIDA::IHistogram3D* histo, const double valueX, const double valueY,
95 const double valueZ, const double weight, const std::string& title ) const
96 {
97 if ( !histo ) {
98 return nullptr;
99 } // RETURN
100 //
101 if ( !checkForNaN() ) {
102 Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
103 } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( valueZ ) &&
104 std::isfinite( weight ) ) {
105 Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
106 } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( valueZ ) || std::isnan( weight ) ) {
107 this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
108 Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
109 .ignore();
110 } else {
111 this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
112 Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
113 .ignore();
114 }
115 // return
116 return histo;
117 }
118 // ============================================================================
119 // fill the 3D histogram (book on demand)
120 // ============================================================================
121 template <class PBASE>
122 AIDA::IHistogram3D*
123 GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ, const std::string& title,
124 const double lowX, const double highX, const double lowY, const double highY,
125 const double lowZ, const double highZ, const unsigned long binsX, const unsigned long binsY,
126 const unsigned long binsZ, const double weight ) const
127 {
128 AIDA::IHistogram3D* h( nullptr );
129 if ( produceHistos() ) {
130 // retrieve or book the histogram
131 h = histo3D( title );
132 if ( !h ) {
133 h = book3D( title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ );
134 }
135 // fill the histogram
136 h = fill( h, valueX, valueY, valueZ, weight, title );
137 }
138 return h;
139 }
140 // ============================================================================
141 // fill the 3D histogram with forced ID assignment (book on demand)
142 // ============================================================================
143 template <class PBASE>
144 AIDA::IHistogram3D*
145 GaudiHistos<PBASE>::plot3D( const double valueX, const double valueY, const double valueZ, const HistoID& ID,
146 const std::string& title, const double lowX, const double highX, const double lowY,
147 const double highY, const double lowZ, const double highZ, const unsigned long binsX,
148 const unsigned long binsY, const unsigned long binsZ, const double weight ) const
149 {
150 AIDA::IHistogram3D* h( nullptr );
151 if ( produceHistos() ) {
152 // retrieve or book the histogram
153 h = histo3D( ID );
154 if ( !h ) {
155 h = book3D( ID, title, lowX, highX, binsX, lowY, highY, binsY, lowZ, highZ, binsZ );
156 }
157 // fill the histogram
158 h = fill( h, valueX, valueY, valueZ, weight, title );
159 }
160 return h;
161 }
162 // ============================================================================
163 // The END
164 // ============================================================================
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.
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:68
std::isfinite
T isfinite(T...args)
GaudiHistos::plot3D
AIDA::IHistogram3D * plot3D(const double valueX, const double valueY, const double valueZ, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const double lowZ, const double highZ, const unsigned long binsX=10, const unsigned long binsY=10, const unsigned long binsZ=10, const double weight=1.0) const
fill the 3D histogram (book on demand)
Definition: GaudiHistos_3DFixedBinning.icpp:123
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)
GaudiHistos::book3D
AIDA::IHistogram3D * book3D(const std::string &title, const double lowX=0, const double highX=100, const unsigned long binsX=10, const double lowY=0, const double highY=100, const unsigned long binsY=10, const double lowZ=0, const double highZ=100, const unsigned long binsZ=10) const
book the 3D histogram
Definition: GaudiHistos_3DFixedBinning.icpp:7
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