Warning, /include/GaudiAlg/GaudiHistos_2DVariableBinning.icpp is written in an unsupported language. File is not indexed.
0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 * *
0004 * This software is distributed under the terms of the Apache version 2 licence, *
0005 * copied verbatim in the file "LICENSE". *
0006 * *
0007 * In applying this licence, CERN does not waive the privileges and immunities *
0008 * granted to it by virtue of its status as an Intergovernmental Organization *
0009 * or submit itself to any jurisdiction. *
0010 \***********************************************************************************/
0011 // ==================================== 2D ====================================
0012 // ============================= Variable Binning =============================
0013 // ============================================================================
0014 // book the 2D histogram (book on demand)
0015 // ============================================================================
0016 template <class PBASE>
0017 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const std::string& title, const HistoBinEdges& edgesX,
0018 const HistoBinEdges& edgesY ) const {
0019 //
0020 if ( !produceHistos() ) { return nullptr; } // RETURN
0021 //
0022 // exist?
0023 auto hist = histo2D( title );
0024 // histogram is already booked
0025 if ( hist ) { return hist; } // RETURN !!
0026
0027 // propose the histogram ID
0028 HistoID ID;
0029 newHistoID( title, ID );
0030
0031 // Create a new histogram and return
0032 return this->book2D( ID, title, edgesX, edgesY );
0033 }
0034 // ============================================================================
0035 // book the 2D histogram with forced ID (book on demand)
0036 // ============================================================================
0037 template <class PBASE>
0038 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const HistoID& ID, const std::string& title,
0039 const HistoBinEdges& edgesX, const HistoBinEdges& edgesY ) const {
0040 //
0041 if ( !produceHistos() ) { return nullptr; } // RETURN
0042 //
0043 // Check ID
0044 if ( ID.undefined() ) {
0045 this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
0046 return nullptr;
0047 }
0048
0049 // exist?
0050 auto hist = histo2D( ID );
0051 // histogram is already booked
0052 if ( hist ) { return hist; } // RETURN !!
0053
0054 // Histogram title
0055 const std::string& htitle = ( title.empty() ? "Unnamed 2D Histogram ID=" + ID.idAsString() : title );
0056
0057 // book the histogram
0058 if ( ID.numeric() ) {
0059 hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, edgesX, edgesY );
0060 } else if ( ID.literal() ) {
0061 hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, edgesX, edgesY );
0062 }
0063
0064 // check OK
0065 if ( !hist ) {
0066 this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
0067 return nullptr;
0068 } // RETURN !!
0069
0070 // add histogram into histogram storages
0071 m_histo2DMapID[ID] = hist;
0072 m_histo2DMapTitle[title] = hist;
0073
0074 // Declare to monitoring service
0075 monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
0076
0077 // Printout and return
0078 if ( this->msgLevel( MSG::DEBUG ) ) {
0079 this->debug() << "Booked 2D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
0080 << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
0081 }
0082 return hist;
0083 }
0084 // ============================================================================
0085 // fill the 2D histogram (book on demand)
0086 // ============================================================================
0087 template <class PBASE>
0088 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
0089 const HistoBinEdges& edgesX, const HistoBinEdges& edgesY,
0090 const double weight ) const {
0091 AIDA::IHistogram2D* h( nullptr );
0092 if ( produceHistos() ) {
0093 // retrieve or book the histogram
0094 h = histo2D( title );
0095 if ( !h ) { h = book2D( title, edgesX, edgesY ); }
0096 // fill the histogram
0097 h = fill( h, valueX, valueY, weight, title );
0098 }
0099 return h;
0100 }
0101 // ============================================================================
0102 // fill the 2D variable histogram with forced ID assignment (book on demand)
0103 // ============================================================================
0104 template <class PBASE>
0105 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
0106 const std::string& title, const HistoBinEdges& edgesX,
0107 const HistoBinEdges& edgesY, const double weight ) const {
0108 AIDA::IHistogram2D* h( nullptr );
0109 if ( produceHistos() ) {
0110 // retrieve or book the histogram
0111 h = histo2D( ID );
0112 if ( !h ) { h = book2D( ID, title, edgesX, edgesY ); }
0113 // fill
0114 h = fill( h, valueX, valueY, weight, title );
0115 }
0116 return h;
0117 }
0118 // ============================================================================
0119 // The END
0120 // ============================================================================