| The Gaudi Framework v28r2-patches (bc4ad17a)

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