| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

GaudiHistos_2DVariableBinning.icpp
Go to the documentation of this file.
1 // ==================================== 2D ====================================
2 // ============================= Variable Binning =============================
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 HistoBinEdges& edgesX,
8 const HistoBinEdges& edgesY ) const
9 {
10 //
11 if ( !produceHistos() ) {
12 return nullptr;
13 } // RETURN
14 //
15 // exist?
16 auto hist = histo2D( title );
17 // histogram is already booked
18 if ( hist ) {
19 return hist;
20 } // RETURN !!
21
22 // propose the histogram ID
23 HistoID ID;
24 newHistoID( title, ID );
25
26 // Create a new histogram and return
27 return this->book2D( ID, title, edgesX, edgesY );
28 }
29 // ============================================================================
30 // book the 2D histogram with forced ID (book on demand)
31 // ============================================================================
32 template <class PBASE>
33 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const HistoID& ID, const std::string& title,
34 const HistoBinEdges& edgesX, const HistoBinEdges& edgesY ) const
35 {
36 //
37 if ( !produceHistos() ) {
38 return nullptr;
39 } // RETURN
40 //
41 // Check ID
42 if ( ID.undefined() ) {
43 this->Error( "Undefined Histogram ID : Title='" + title + "'" );
44 return nullptr;
45 }
46
47 // exist?
48 auto hist = histo2D( ID );
49 // histogram is already booked
50 if ( hist ) {
51 return hist;
52 } // RETURN !!
53
54 // Histogram title
55 const std::string& htitle = ( title.empty() ? "Unnamed 2D Histogram ID=" + ID.idAsString() : title );
56
57 // book the histogram
58 if ( ID.numeric() ) {
59 hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, edgesX, edgesY );
60 } else if ( ID.literal() ) {
61 hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, edgesX, edgesY );
62 }
63
64 // check OK
65 if ( !hist ) {
66 this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" );
67 return nullptr;
68 } // RETURN !!
69
70 // add histogram into histogram storages
71 m_histo2DMapID[ID] = hist;
72 m_histo2DMapTitle[title] = hist;
73
74 // Declare to monitoring service
75 monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
76
77 // Printout and return
78 if ( this->msgLevel( MSG::DEBUG ) ) {
79 this->debug() << "Booked 2D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
80 << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
81 }
82 return hist;
83 }
84 // ============================================================================
85 // fill the 2D histogram (book on demand)
86 // ============================================================================
87 template <class PBASE>
88 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
89 const HistoBinEdges& edgesX, const HistoBinEdges& edgesY,
90 const double weight ) const
91 {
92 AIDA::IHistogram2D* h( nullptr );
93 if ( produceHistos() ) {
94 // retrieve or book the histogram
95 h = histo2D( title );
96 if ( !h ) {
97 h = book2D( title, edgesX, edgesY );
98 }
99 // fill the histogram
100 h = fill( h, valueX, valueY, weight, title );
101 }
102 return h;
103 }
104 // ============================================================================
105 // fill the 2D variable histogram with forced ID assignment (book on demand)
106 // ============================================================================
107 template <class PBASE>
108 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
109 const std::string& title, const HistoBinEdges& edgesX,
110 const HistoBinEdges& edgesY, const double weight ) const
111 {
112 AIDA::IHistogram2D* h( nullptr );
113 if ( produceHistos() ) {
114 // retrieve or book the histogram
115 h = histo2D( ID );
116 if ( !h ) {
117 h = book2D( ID, title, edgesX, edgesY );
118 }
119 // fill
120 h = fill( h, valueX, valueY, weight, title );
121 }
122 return h;
123 }
124 // ============================================================================
125 // The END
126 // ============================================================================
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::vector< double >
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
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