The Gaudi Framework  v30r3 (a5ef0a68)
GaudiHistos_1DFixedBinning.icpp
Go to the documentation of this file.
1 // ==================================== 1D ====================================
2 // ================================ Fixed 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 double low, const double high,
8  const unsigned long bins ) const
9 {
10  //
11  if ( !produceHistos() ) {
12  return nullptr;
13  } // RETURN
14  //
15  // exist?
16  auto hist = histo1D( 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->book1D( ID, title, low, high, bins );
28 }
29 // ============================================================================
30 // book the 1D histogram with forced ID (book on demand)
31 // ============================================================================
32 template <class PBASE>
33 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const HistoID& ID, const std::string& title, const double low,
34  const double high, const unsigned long bins ) const
35 {
36  //
37  if ( !produceHistos() ) {
38  return nullptr;
39  } // RETURN
40  //
41 
42  // Check ID
43  if ( ID.undefined() ) {
44  this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
45  return nullptr;
46  }
47 
48  // exist?
49  auto* hist = histo1D( ID );
50  // histogram is already booked
51  if ( hist ) {
52  return hist;
53  } // RETURN !!
54 
55  // Histogram title
56  const std::string& htitle = ( title.empty() ? "Unnamed 1D Histogram ID=" + ID.idAsString() : title );
57 
58  // book the histogram
59  if ( ID.numeric() ) {
60  hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, bins, low, high );
61  } else if ( ID.literal() ) {
62  hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, bins, low, high );
63  }
64 
65  // check OK
66  if ( !hist ) {
67  this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
68  return nullptr;
69  } // RETURN !!
70 
71  // add histogram into histogram storages
72  m_histo1DMapID[ID] = hist;
73  m_histo1DMapTitle[title] = hist;
74 
75  // Declare to monitoring service
76  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
77 
78  // Printout and return
79  if ( this->msgLevel( MSG::DEBUG ) ) {
80  this->debug() << "Booked 1D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
81  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
82  }
83  return hist;
84 }
85 // ============================================================================
86 // fill the 1D histogram with the value and weight
87 // ============================================================================
88 template <class PBASE>
89 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill( AIDA::IHistogram1D* histo, const double value, const double weight,
90  const std::string& title ) const
91 {
92  if ( !histo ) {
93  return nullptr;
94  } // RETURN
95  //
96  if ( !checkForNaN() ) {
97  Gaudi::Utils::Histos::fill( histo, value, weight );
98  } else if ( std::isfinite( value ) && std::isfinite( weight ) ) {
99  Gaudi::Utils::Histos::fill( histo, value, weight );
100  } else if ( std::isnan( value ) || std::isnan( weight ) ) {
101  this->Warning( "fill():: 'NaN' value is skipped from the histogram '" +
102  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
103  .ignore();
104  } else {
105  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
106  Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
107  .ignore();
108  }
109  // return
110  return histo;
111 }
112 // ============================================================================
113 // fill the 1D histogram (book on demand)
114 // ============================================================================
115 template <class PBASE>
116 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const std::string& title, const double low,
117  const double high, const unsigned long bins, const double weight ) const
118 {
119  AIDA::IHistogram1D* h( nullptr );
120  if ( produceHistos() ) {
121  // retrieve or book the histogram
122  h = histo1D( title );
123  if ( !h ) {
124  h = book1D( title, low, high, bins );
125  }
126  // fill the histogram
127  h = fill( h, value, weight, title );
128  }
129  return h;
130 }
131 // ============================================================================
132 // fill the 1D histogram with forced ID assignment (book on demand)
133 // ============================================================================
134 template <class PBASE>
135 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const std::string& title,
136  const double low, const double high, const unsigned long bins,
137  const double weight ) const
138 {
139  AIDA::IHistogram1D* h( nullptr );
140  if ( produceHistos() ) {
141  // retrieve or book the histogram
142  h = histo1D( ID );
143  if ( !h ) {
144  h = book1D( ID, title, low, high, bins );
145  }
146  // fill
147  h = fill( h, value, weight, title );
148  }
149  return h;
150 }
151 // ============================================================================
152 // book the 1D histogram
153 // ============================================================================
154 template <class PBASE>
155 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const Gaudi::Histo1DDef& hdef ) const
156 {
157  return book1D( hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
158 }
159 // ============================================================================
160 // book the 1D histogram with forced ID
161 // ============================================================================
162 template <class PBASE>
163 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const HistoID& ID, const Gaudi::Histo1DDef& hdef ) const
164 {
165  return book1D( ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
166 }
167 // ============================================================================
168 // fill the 1D histogram (book on demand)
169 // ============================================================================
170 template <class PBASE>
171 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const Gaudi::Histo1DDef& hdef,
172  const double weight ) const
173 {
174  return plot1D( value, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
175 }
176 // ============================================================================
177 // fill the 1D histogram with forced ID assignment (book on demand)
178 // ============================================================================
179 template <class PBASE>
180 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const Gaudi::Histo1DDef& hdef,
181  const double weight ) const
182 {
183  return plot1D( value, ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
184 }
185 // ============================================================================
186 // The END
187 // ============================================================================
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:126
T empty(T...args)
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
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:74
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
double highEdge() const
get the high edge
Definition: HistoDef.h:58
double lowEdge() const
get the low edge
Definition: HistoDef.h:56
const std::string & title() const
get the title
Definition: HistoDef.h:62
STL class.
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:33
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:68
T isfinite(T...args)
AIDA::IHistogram1D * book(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100) const
book the 1D histogram
Definition: GaudiHistos.h:1865
int bins() const
get the number of bins
Definition: HistoDef.h:60
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:72
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:66
T isnan(T...args)
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:180
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:70
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)
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:44
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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