| The Gaudi Framework v32r1 (f65d50dc)

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