GaudiHistos_2DVariableBinning.icpp
Go to the documentation of this file.
1 // ==================================== 2D ====================================
2 // ============================= Variable Binning =============================
3 // ============================================================================
4 // book the 2D histogram (book on demand)
5 // ============================================================================
6 template <class PBASE>
7 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D
8 ( const std::string& title ,
9  const HistoBinEdges& edgesX ,
10  const HistoBinEdges& edgesY ) const
11 {
12  //
13  if ( !produceHistos() ) { return nullptr; } // RETURN
14  //
15  // exist?
16  auto hist = histo2D ( title ) ;
17  // histogram is already booked
18  if ( hist ) { return hist ; } // RETURN !!
19 
20  // propose the histogram ID
21  HistoID ID;
22  newHistoID( title, ID );
23 
24  // Create a new histogram and return
25  return this -> book2D ( ID, title, edgesX, edgesY );
26 }
27 // ============================================================================
28 // book the 2D histogram with forced ID (book on demand)
29 // ============================================================================
30 template <class PBASE>
31 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D
32 ( const HistoID& ID ,
33  const std::string& title ,
34  const HistoBinEdges& edgesX ,
35  const HistoBinEdges& edgesY ) const
36 {
37  //
38  if ( !produceHistos() ) { return nullptr; } // RETURN
39  //
40  // Check ID
41  if (ID.undefined())
42  {
43  this->Error("Undefined Histogram ID : Title='"+title+"'");
44  return nullptr;
45  }
46 
47  // exist?
48  auto hist = histo2D ( ID ) ;
49  // histogram is already booked
50  if ( hist ) { return hist ; } // RETURN !!
51 
52  // Histogram title
53  const std::string & htitle =
54  ( title.empty() ? "Unnamed 2D Histogram ID="+ID.idAsString() : title ) ;
55 
56  // book the histogram
57  if ( ID.numeric() )
58  {
59  hist = this->histoSvc() -> book ( histoPath() ,
60  ID.numericID() ,
61  htitle ,
62  edgesX ,
63  edgesY ) ;
64  }
65  else if ( ID.literal() )
66  {
67  hist = this->histoSvc() -> book ( histoPath()+"/"+
68  ID.literalID() ,
69  htitle ,
70  edgesX ,
71  edgesY ) ;
72  }
73 
74  // check OK
75  if( !hist )
76  { this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() +
77  "' title='"+htitle+"'" ) ; return nullptr; } // RETURN !!
78 
79  // add histogram into histogram storages
80  m_histo2DMapID [ ID ] = hist ;
81  m_histo2DMapTitle [ title ] = hist ;
82 
83  // Declare to monitoring service
84  monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
85 
86  // Printout and return
87  if ( this->msgLevel(MSG::DEBUG) )
88  { this->debug() << "Booked 2D Histogram : ID='" << ID
89  << "' Path=" << histoPath()
90  << " Title='"
92  << "'" << endmsg; }
93  return hist ;
94 }
95 // ============================================================================
96 // fill the 2D histogram (book on demand)
97 // ============================================================================
98 template <class PBASE>
99 AIDA::IHistogram2D*
101 ( const double valueX ,
102  const double valueY ,
103  const std::string& title ,
104  const HistoBinEdges& edgesX ,
105  const HistoBinEdges& edgesY ,
106  const double weight ) const
107 {
108  AIDA::IHistogram2D * h(nullptr);
109  if ( produceHistos() )
110  {
111  // retrieve or book the histogram
112  h = histo2D ( title ) ;
113  if ( !h ) { h = book2D ( title , edgesX , edgesY ) ; }
114  // fill the histogram
115  h = fill ( h , valueX , valueY , weight , title );
116  }
117  return h;
118 }
119 // ============================================================================
120 // fill the 2D variable histogram with forced ID assignment (book on demand)
121 // ============================================================================
122 template <class PBASE>
123 AIDA::IHistogram2D*
125 ( const double valueX ,
126  const double valueY ,
127  const HistoID& ID ,
128  const std::string& title ,
129  const HistoBinEdges& edgesX ,
130  const HistoBinEdges& edgesY ,
131  const double weight ) const
132 {
133  AIDA::IHistogram2D * h(nullptr);
134  if ( produceHistos() )
135  {
136  // retrieve or book the histogram
137  h = histo2D ( ID ) ;
138  if ( !h ) { h = book2D ( ID , title , edgesX , edgesY ) ; }
139  // fill
140  h = fill ( h , valueX , valueY , weight , title ) ;
141  }
142  return h;
143 }
144 // ============================================================================
145 // The END
146 // ============================================================================
147 
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
Definition: Fill.cpp:138
T empty(T...args)
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:124
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:82
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:36
STL class.
AIDA::IHistogram2D * book2D(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 histogram
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:76
AIDA::IHistogram2D * plot2D(const double valueX, const double valueY, 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 histogram (book on demand)
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:80
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:74
GAUDI_API AIDA::IBaseHistogram * toBase(AIDA::IHistogram1D *histo)
Definition: Fill.cpp:193
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:78
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:244