Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/GaudiAlg/GaudiHistos_2DFixedBinning.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 // ============================================================================
0012 // ==================================== 2D ====================================
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 double lowX, const double highX,
0018                                                 const unsigned long binsX, const double lowY, const double highY,
0019                                                 const unsigned long binsY ) const {
0020   //
0021   if ( !produceHistos() ) { return nullptr; } // RETURN
0022   //
0023   // exist?
0024   auto hist = histo2D( title );
0025   // histogram is already booked
0026   if ( hist ) { return hist; } // RETURN !!
0027 
0028   // propose the histogram ID
0029   HistoID ID;
0030   newHistoID( title, ID );
0031 
0032   // Create a new histogram and return
0033   return this->book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY );
0034 }
0035 // ============================================================================
0036 // book the 2D histogram with forced ID (book on demand)
0037 // ============================================================================
0038 template <class PBASE>
0039 AIDA::IHistogram2D* GaudiHistos<PBASE>::book2D( const HistoID& ID, const std::string& title, const double lowX,
0040                                                 const double highX, const unsigned long binsX, const double lowY,
0041                                                 const double highY, const unsigned long binsY ) const {
0042   //
0043   if ( !produceHistos() ) { return nullptr; } // RETURN
0044   //
0045   // Check ID
0046   if ( ID.undefined() ) {
0047     this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
0048     return nullptr;
0049   }
0050 
0051   // exist?
0052   auto hist = histo2D( ID );
0053   // histogram is already booked
0054   if ( hist ) { return hist; } // RETURN !!
0055 
0056   // Histogram title
0057   const std::string& htitle = ( title.empty() ? "Unnamed 2D Histogram ID=" + ID.idAsString() : title );
0058 
0059   // book the histogram
0060   if ( ID.numeric() ) {
0061     hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
0062   } else if ( ID.literal() ) {
0063     hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, binsX, lowX, highX, binsY, lowY, highY );
0064   }
0065 
0066   // Check OK
0067   if ( !hist ) {
0068     this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
0069     return nullptr;
0070   } // RETURN !!
0071 
0072   // add histogram into histogram storages
0073   m_histo2DMapID[ID]       = hist;
0074   m_histo2DMapTitle[title] = hist;
0075 
0076   // Declare to monitoring service
0077   monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
0078 
0079   // Printout and return
0080   if ( this->msgLevel( MSG::DEBUG ) ) {
0081     this->debug() << "Booked 2D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
0082                   << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
0083   }
0084   // return
0085   return hist;
0086 }
0087 // ============================================================================
0088 // fill the 2D histogram with the values and weight
0089 // ============================================================================
0090 template <class PBASE>
0091 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill( AIDA::IHistogram2D* histo, const double valueX, const double valueY,
0092                                               const double weight, const std::string& title ) const {
0093   //
0094   if ( !histo ) { return nullptr; } // RETURN
0095   //
0096   if ( !checkForNaN() ) {
0097     Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
0098   } else if ( std::isfinite( valueX ) && std::isfinite( valueY ) && std::isfinite( weight ) ) {
0099     Gaudi::Utils::Histos::fill( histo, valueX, valueY, weight );
0100   } else if ( std::isnan( valueX ) || std::isnan( valueY ) || std::isnan( weight ) ) {
0101     this->Warning( "fill():: 'NaN'      value is skipped from the histogram '" +
0102                    Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
0103         .ignore();
0104   } else {
0105     this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
0106                    Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
0107         .ignore();
0108   }
0109   // return
0110   return histo;
0111 }
0112 // ============================================================================
0113 // fill the 2D histogram (book on demand)
0114 // ============================================================================
0115 template <class PBASE>
0116 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const std::string& title,
0117                                                 const double lowX, const double highX, const double lowY,
0118                                                 const double highY, const unsigned long binsX,
0119                                                 const unsigned long binsY, const double weight ) const {
0120   AIDA::IHistogram2D* h( nullptr );
0121   if ( produceHistos() ) {
0122     // retrieve or book the histogram
0123     h = histo2D( title );
0124     if ( !h ) { h = book2D( title, lowX, highX, binsX, lowY, highY, binsY ); }
0125     // fill the histogram
0126     h = fill( h, valueX, valueY, weight, title );
0127   }
0128   return h;
0129 }
0130 // ============================================================================
0131 // fill the 2D histogram with forced ID assignment (book on demand)
0132 // ============================================================================
0133 template <class PBASE>
0134 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D( const double valueX, const double valueY, const HistoID& ID,
0135                                                 const std::string& title, const double lowX, const double highX,
0136                                                 const double lowY, const double highY, const unsigned long binsX,
0137                                                 const unsigned long binsY, const double weight ) const {
0138   AIDA::IHistogram2D* h( nullptr );
0139   // produce histograms ?
0140   if ( produceHistos() ) {
0141     // retrieve or book the histogram
0142     h = histo2D( ID );
0143     if ( !h ) { h = book2D( ID, title, lowX, highX, binsX, lowY, highY, binsY ); }
0144     // fill the histogram
0145     h = fill( h, valueX, valueY, weight, title );
0146   }
0147   return h;
0148 }
0149 // ============================================================================
0150 // The END
0151 // ============================================================================