| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

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