The Gaudi Framework  v29r5 (37229091)
GaudiHistos_2DProfFixedBinning.icpp
Go to the documentation of this file.
1 // ============================================================================
2 // book the 2D profile histogram (book on demand)
3 // ============================================================================
4 template <class PBASE>
5 AIDA::IProfile2D* GaudiHistos<PBASE>::bookProfile2D( const std::string& title, const double lowX, const double highX,
6  const unsigned long binsX, const double lowY, const double highY,
7  const unsigned long binsY ) const
8 {
9  //
10  if ( !produceHistos() ) {
11  return 0;
12  } // RETURN
13  //
14  // exist?
15  auto hist = profile2D( title );
16  // histogram is already booked
17  if ( 0 != hist ) {
18  return hist;
19  } // RETURN !!
20 
21  // propose the histogram ID
22  HistoID ID;
23  newHistoID( title, ID );
24 
25  // book histogram and return
26  return this->bookProfile2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
27 }
28 // ============================================================================
29 // book the 2D profile histogram with forced ID (book on demand)
30 // ============================================================================
31 template <class PBASE>
32 AIDA::IProfile2D* GaudiHistos<PBASE>::bookProfile2D( const HistoID& ID, const std::string& title, const double lowX,
33  const double highX, const unsigned long binsX, const double lowY,
34  const double highY, const unsigned long binsY ) const
35 {
36  //
37  if ( !produceHistos() ) {
38  return 0;
39  } // RETURN
40  //
41  // Check ID
42  if ( ID.undefined() ) {
43  this->Error( "Undefined Histogram ID : Title='" + title + "'" );
44  return nullptr;
45  }
46  // exist?
47  auto hist = profile2D( ID );
48  // histogram is already booked
49  if ( 0 != hist ) {
50  return hist;
51  } // RETURN !!
52 
53  // Histogram title
54  const std::string& htitle = ( title.empty() ? "Unnamed 2D Profile Histogram ID=" + ID.idAsString() : title );
55 
56  // book the histogram
57  if ( ID.numeric() ) {
58  hist = this->histoSvc()->bookProf( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
59  } else if ( ID.literal() ) {
60  hist = this->histoSvc()->bookProf( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY,
61  highY );
62  }
63 
64  // test OK
65  if ( 0 == hist ) {
66  this->Error( "IProfile2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" );
67  return 0;
68  } // RETURN !!
69 
70  // add histogram into histogram storages
71  m_profile2DMapID[ID] = hist;
72  m_profile2DMapTitle[title] = hist;
73 
74  // Declare to monitoring service
75  monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
76 
77  // printout and return
78  if ( this->msgLevel( MSG::DEBUG ) ) {
79  this->debug() << "Booked 2D Profile Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
80  << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
81  }
82  return hist;
83 }
84 // ============================================================================
85 // fill the 2D profile histogram with the value and weight
86 // ============================================================================
87 template <class PBASE>
88 AIDA::IProfile2D* GaudiHistos<PBASE>::fill( AIDA::IProfile2D* histo, const double valueX, const double valueY,
89  const double valueZ, const double weight, const std::string& title ) const
90 {
91  if ( 0 == histo ) {
92  return 0;
93  } // RETURN
94  //
95  if ( !checkForNaN() ) {
96  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
97  } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( valueZ ) &&
98  std::isfinite( weight ) ) {
99  Gaudi::Utils::Histos::fill( histo, valueX, valueY, valueZ, weight );
100  } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( valueZ ) || 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 2D profile histogram (book on demand)
112 // ============================================================================
113 template <class PBASE>
114 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
115  const std::string& title, const double lowX, const double highX,
116  const double lowY, const double highY, const unsigned long binsX,
117  const unsigned long binsY, const double weight ) const
118 {
119  AIDA::IProfile2D* h = nullptr;
120  if ( produceHistos() ) {
121  // retrieve or book the histogram
122  h = profile2D( title );
123  if ( 0 == h ) {
124  h = bookProfile2D( title, lowX, highX, binsX, lowY, highY, binsY );
125  }
126  // fill the histogram
127  h = fill( h, valueX, valueY, valueZ, weight, title );
128  }
129  return h;
130 }
131 // ============================================================================
132 // fill the 2D profile histogram with forced ID assignment (book on demand)
133 // ============================================================================
134 template <class PBASE>
135 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
136  const HistoID& ID, const std::string& title, const double lowX,
137  const double highX, const double lowY, const double highY,
138  const unsigned long binsX, const unsigned long binsY,
139  const double weight ) const
140 {
141  AIDA::IProfile2D* h = nullptr;
142  if ( produceHistos() ) {
143  // retrieve or book the histogram
144  h = profile2D( ID );
145  if ( 0 == h ) {
146  h = bookProfile2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
147  }
148  // fill the histogram
149  h = fill( h, valueX, valueY, valueZ, weight, title );
150  }
151  return h;
152 }
153 // ============================================================================
154 // The END
155 // ============================================================================
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::IProfile2D * bookProfile2D(const std::string &title, const double lowX=0, const double highX=100, const unsigned long binsX=50, const double lowY=0, const double highY=100, const unsigned long binsY=50) const
book the 2D profile 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
STL class.
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:68
T isfinite(T...args)
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::IProfile2D * profile2D(const double valueX, const double valueY, const double valueZ, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D profile 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