All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
8 ( const std::string& title ,
9  const double low ,
10  const double high ,
11  const unsigned long bins ) const
12 {
13  //
14  if ( !produceHistos() ) { return 0 ; } // RETURN
15  //
16  // exist?
17  AIDA::IHistogram1D* hist = histo1D ( title ) ;
18  // histogram is already booked
19  if( NULL != hist ) { return hist ; } // 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, low, high, bins );
27 }
28 // ============================================================================
29 // book the 1D histogram with forced ID (book on demand)
30 // ============================================================================
31 template <class PBASE>
32 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D
33 ( const HistoID& ID ,
34  const std::string& title ,
35  const double low ,
36  const double high ,
37  const unsigned long bins ) const
38 {
39  //
40  if ( !produceHistos() ) { return 0 ; } // RETURN
41  //
42 
43  // Check ID
44  if ( ID.undefined() )
45  {
46  this->Error("Undefined Histogram ID : Title='"+title+"'");
47  return NULL;
48  }
49 
50  // exist?
51  AIDA::IHistogram1D* hist = histo1D ( ID ) ;
52  // histogram is already booked
53  if ( NULL != hist ) { return hist ; } // RETURN !!
54 
55  // Histogram title
56  const std::string & htitle =
57  ( title.empty() ? "Unnamed 1D Histogram ID="+ID.idAsString() : title ) ;
58 
59  // book the histogram
60  if ( ID.numeric() )
61  {
62  hist = this->histoSvc() -> book ( histoPath() ,
63  ID.numericID() ,
64  htitle ,
65  bins ,
66  low ,
67  high ) ;
68  }
69  else if ( ID.literal() )
70  {
71  hist = this->histoSvc() -> book ( histoPath()+"/"+
72  ID.literalID() ,
73  htitle ,
74  bins ,
75  low ,
76  high ) ;
77  }
78 
79  // check OK
80  if( NULL == hist )
81  { this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() +
82  "' title='"+htitle+"'" ) ; return NULL; } // RETURN !!
83 
84  // add histogram into histogram storages
85  m_histo1DMapID [ ID ] = hist ;
86  m_histo1DMapTitle [ title ] = hist ;
87 
88  // Declare to monitoring service
89  monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
90 
91  // Printout and return
92  if ( this->msgLevel(MSG::DEBUG) )
93  { this->debug() << "Booked 1D Histogram : ID='" << ID
94  << "' Path=" << histoPath()
95  << " Title='"
97  << "'" << endmsg; }
98  return hist ;
99 }
100 // ============================================================================
101 // fill the 1D histogram with the value and weight
102 // ============================================================================
103 template <class PBASE>
104 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill
105 ( AIDA::IHistogram1D* histo ,
106  const double value ,
107  const double weight ,
108  const std::string& title ) const
109 {
110  if ( 0 == histo ) { return 0 ; } // RETURN
111  //
112  if ( !checkForNaN() )
113  { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
114  else if ( lfin ( value ) && lfin ( weight ) )
115  { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
116  else if ( lnan ( value ) || lnan ( weight ) )
117  {
118  this -> Warning
119  ("fill():: 'NaN' value is skipped from the histogram '"
120  + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
121  }
122  else
123  {
124  this -> Warning
125  ("fill():: 'Infinite' value is skipped from the histogram '"
126  + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
127  }
128  // return
129  return histo ;
130 }
131 // ============================================================================
132 // fill the 1D histogram (book on demand)
133 // ============================================================================
134 template <class PBASE>
135 AIDA::IHistogram1D*
137 ( const double value ,
138  const std::string& title ,
139  const double low ,
140  const double high ,
141  const unsigned long bins ,
142  const double weight ) const
143 {
144  AIDA::IHistogram1D * h(NULL);
145  if ( produceHistos() )
146  {
147  // retrieve or book the histogram
148  h = histo1D ( title ) ;
149  if ( NULL == h ) { h = book1D ( title , low , high , bins ) ; }
150  // fill the histogram
151  h = fill ( h , value , weight , title );
152  }
153  return h;
154 }
155 // ============================================================================
156 // fill the 1D histogram with forced ID assignment (book on demand)
157 // ============================================================================
158 template <class PBASE>
159 AIDA::IHistogram1D*
161 ( const double value ,
162  const HistoID& ID ,
163  const std::string& title ,
164  const double low ,
165  const double high ,
166  const unsigned long bins ,
167  const double weight ) const
168 {
169  AIDA::IHistogram1D* h(NULL);
170  if ( produceHistos() )
171  {
172  // retrieve or book the histogram
173  h = histo1D ( ID ) ;
174  if ( NULL == h ) { h = book1D ( ID , title , low , high , bins ) ; }
175  // fill
176  h = fill ( h , value , weight , title ) ;
177  }
178  return h;
179 }
180 // ============================================================================
181 // book the 1D histogram
182 // ============================================================================
183 template <class PBASE>
184 AIDA::IHistogram1D*
186 ( const Gaudi::Histo1DDef& hdef ) const
187 {
188  return book1D ( hdef.title () ,
189  hdef.lowEdge () ,
190  hdef.highEdge () ,
191  hdef.bins () ) ;
192 }
193 // ============================================================================
194 // book the 1D histogram with forced ID
195 // ============================================================================
196 template <class PBASE>
197 AIDA::IHistogram1D*
199 ( const HistoID& ID ,
200  const Gaudi::Histo1DDef& hdef ) const
201 {
202  return book1D ( ID ,
203  hdef.title () ,
204  hdef.lowEdge () ,
205  hdef.highEdge () ,
206  hdef.bins () ) ;
207 }
208 // ============================================================================
209 // fill the 1D histogram (book on demand)
210 // ============================================================================
211 template <class PBASE>
212 AIDA::IHistogram1D*
214 ( const double value ,
215  const Gaudi::Histo1DDef& hdef ,
216  const double weight ) const
217 {
218  return plot1D
219  ( value ,
220  hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
221  weight ) ;
222 }
223 // ============================================================================
224 // fill the 1D histogram with forced ID assignment (book on demand)
225 // ============================================================================
226 template <class PBASE>
227 AIDA::IHistogram1D*
229 ( const double value ,
230  const HistoID& ID ,
231  const Gaudi::Histo1DDef& hdef ,
232  const double weight ) const
233 {
234  return plot1D
235  ( value , ID ,
236  hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
237  weight ) ;
238 }
239 // ============================================================================
240 // The END
241 // ============================================================================
242 
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:139
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:132
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
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:37
double highEdge() const
get the high edge
Definition: HistoDef.h:68
double lowEdge() const
get the low edge
Definition: HistoDef.h:66
const std::string & title() const
get the title
Definition: HistoDef.h:72
NumericID numericID() const
Returns the numerical ID.
Definition: GaudiHistoID.h:74
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:32
const LiteralID & literalID() const
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:72
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:2031
int bins() const
get the number of bins
Definition: HistoDef.h:70
bool undefined() const
Is this ID undefined.
Definition: GaudiHistoID.h:70
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
bool literal() const
Is this ID numeric.
Definition: GaudiHistoID.h:68
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:194
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:46
bool numeric() const
Is this ID numeric.
Definition: GaudiHistoID.h:66
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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