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