The Gaudi Framework  v30r0 (c919700c)
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 + "'" ).ignore();
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 + "'" ).ignore();
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  .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 2D profile histogram (book on demand)
114 // ============================================================================
115 template <class PBASE>
116 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
117  const std::string& title, const double lowX, const double highX,
118  const double lowY, const double highY, const unsigned long binsX,
119  const unsigned long binsY, const double weight ) const
120 {
121  AIDA::IProfile2D* h = nullptr;
122  if ( produceHistos() ) {
123  // retrieve or book the histogram
124  h = profile2D( title );
125  if ( 0 == h ) {
126  h = bookProfile2D( title, lowX, highX, binsX, lowY, highY, binsY );
127  }
128  // fill the histogram
129  h = fill( h, valueX, valueY, valueZ, weight, title );
130  }
131  return h;
132 }
133 // ============================================================================
134 // fill the 2D profile histogram with forced ID assignment (book on demand)
135 // ============================================================================
136 template <class PBASE>
137 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D( const double valueX, const double valueY, const double valueZ,
138  const HistoID& ID, const std::string& title, const double lowX,
139  const double highX, const double lowY, const double highY,
140  const unsigned long binsX, const unsigned long binsY,
141  const double weight ) const
142 {
143  AIDA::IProfile2D* h = nullptr;
144  if ( produceHistos() ) {
145  // retrieve or book the histogram
146  h = profile2D( ID );
147  if ( 0 == h ) {
148  h = bookProfile2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
149  }
150  // fill the histogram
151  h = fill( h, valueX, valueY, valueZ, weight, title );
152  }
153  return h;
154 }
155 // ============================================================================
156 // The END
157 // ============================================================================
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