The Gaudi Framework  v29r0 (ff2e7097)
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 + "'" );
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 + "'" );
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  } else {
104  this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
105  Gaudi::Utils::Histos::htitle( histo, title ) + "'" );
106  }
107  // return
108  return histo;
109 }
110 // ============================================================================
111 // fill the 1D histogram (book on demand)
112 // ============================================================================
113 template <class PBASE>
114 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const std::string& title, const double low,
115  const double high, const unsigned long bins, const double weight ) const
116 {
117  AIDA::IHistogram1D* h( nullptr );
118  if ( produceHistos() ) {
119  // retrieve or book the histogram
120  h = histo1D( title );
121  if ( !h ) {
122  h = book1D( title, low, high, bins );
123  }
124  // fill the histogram
125  h = fill( h, value, weight, title );
126  }
127  return h;
128 }
129 // ============================================================================
130 // fill the 1D histogram with forced ID assignment (book on demand)
131 // ============================================================================
132 template <class PBASE>
133 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const std::string& title,
134  const double low, const double high, const unsigned long bins,
135  const double weight ) const
136 {
137  AIDA::IHistogram1D* h( nullptr );
138  if ( produceHistos() ) {
139  // retrieve or book the histogram
140  h = histo1D( ID );
141  if ( !h ) {
142  h = book1D( ID, title, low, high, bins );
143  }
144  // fill
145  h = fill( h, value, weight, title );
146  }
147  return h;
148 }
149 // ============================================================================
150 // book the 1D histogram
151 // ============================================================================
152 template <class PBASE>
153 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const Gaudi::Histo1DDef& hdef ) const
154 {
155  return book1D( hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
156 }
157 // ============================================================================
158 // book the 1D histogram with forced ID
159 // ============================================================================
160 template <class PBASE>
161 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const HistoID& ID, const Gaudi::Histo1DDef& hdef ) const
162 {
163  return book1D( ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
164 }
165 // ============================================================================
166 // fill the 1D histogram (book on demand)
167 // ============================================================================
168 template <class PBASE>
169 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const Gaudi::Histo1DDef& hdef,
170  const double weight ) const
171 {
172  return plot1D( value, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
173 }
174 // ============================================================================
175 // fill the 1D histogram with forced ID assignment (book on demand)
176 // ============================================================================
177 template <class PBASE>
178 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const Gaudi::Histo1DDef& hdef,
179  const double weight ) const
180 {
181  return plot1D( value, ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
182 }
183 // ============================================================================
184 // The END
185 // ============================================================================
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:61
double lowEdge() const
get the low edge
Definition: HistoDef.h:59
const std::string & title() const
get the title
Definition: HistoDef.h:65
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:63
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