Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/GaudiAlg/GaudiHistos_1DFixedBinning.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 // ==================================== 1D ====================================
0012 // ================================ Fixed Binning =============================
0013 // ============================================================================
0014 // book the 1D histogram (book on demand)
0015 // ============================================================================
0016 template <class PBASE>
0017 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const std::string& title, const double low, const double high,
0018                                                 const unsigned long bins ) const {
0019   //
0020   if ( !produceHistos() ) { return nullptr; } // RETURN
0021   //
0022   // exist?
0023   auto hist = histo1D( 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->book1D( ID, title, low, high, bins );
0033 }
0034 // ============================================================================
0035 // book the 1D histogram with forced ID (book on demand)
0036 // ============================================================================
0037 template <class PBASE>
0038 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const HistoID& ID, const std::string& title, const double low,
0039                                                 const double high, const unsigned long bins ) const {
0040   //
0041   if ( !produceHistos() ) { return nullptr; } // RETURN
0042   //
0043 
0044   // Check ID
0045   if ( ID.undefined() ) {
0046     this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
0047     return nullptr;
0048   }
0049 
0050   // exist?
0051   auto* hist = histo1D( ID );
0052   // histogram is already booked
0053   if ( hist ) { return hist; } // RETURN !!
0054 
0055   // Histogram title
0056   const std::string& htitle = ( title.empty() ? "Unnamed 1D Histogram ID=" + ID.idAsString() : title );
0057 
0058   // book the histogram
0059   if ( ID.numeric() ) {
0060     hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, bins, low, high );
0061   } else if ( ID.literal() ) {
0062     hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, bins, low, high );
0063   }
0064 
0065   // check OK
0066   if ( !hist ) {
0067     this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
0068     return nullptr;
0069   } // RETURN !!
0070 
0071   // add histogram into histogram storages
0072   m_histo1DMapID[ID]       = hist;
0073   m_histo1DMapTitle[title] = hist;
0074 
0075   // Declare to monitoring service
0076   monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
0077 
0078   // Printout and return
0079   if ( this->msgLevel( MSG::DEBUG ) ) {
0080     this->debug() << "Booked 1D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
0081                   << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
0082   }
0083   return hist;
0084 }
0085 // ============================================================================
0086 // fill the 1D histogram with the value and weight
0087 // ============================================================================
0088 template <class PBASE>
0089 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill( AIDA::IHistogram1D* histo, const double value, const double weight,
0090                                               const std::string& title ) const {
0091   if ( !histo ) { return nullptr; } // RETURN
0092   //
0093   if ( !checkForNaN() ) {
0094     Gaudi::Utils::Histos::fill( histo, value, weight );
0095   } else if ( std::isfinite( value ) && std::isfinite( weight ) ) {
0096     Gaudi::Utils::Histos::fill( histo, value, weight );
0097   } else if ( std::isnan( value ) || std::isnan( weight ) ) {
0098     this->Warning( "fill():: 'NaN'      value is skipped from the histogram '" +
0099                    Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
0100         .ignore();
0101   } else {
0102     this->Warning( "fill():: 'Infinite' value is skipped from the histogram '" +
0103                    Gaudi::Utils::Histos::htitle( histo, title ) + "'" )
0104         .ignore();
0105   }
0106   // return
0107   return histo;
0108 }
0109 // ============================================================================
0110 // fill the 1D histogram (book on demand)
0111 // ============================================================================
0112 template <class PBASE>
0113 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const std::string& title, const double low,
0114                                                 const double high, const unsigned long bins,
0115                                                 const double weight ) const {
0116   AIDA::IHistogram1D* h( nullptr );
0117   if ( produceHistos() ) {
0118     // retrieve or book the histogram
0119     h = histo1D( title );
0120     if ( !h ) { h = book1D( title, low, high, bins ); }
0121     // fill the histogram
0122     h = fill( h, value, weight, title );
0123   }
0124   return h;
0125 }
0126 // ============================================================================
0127 // fill the 1D histogram with forced ID assignment (book on demand)
0128 // ============================================================================
0129 template <class PBASE>
0130 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const std::string& title,
0131                                                 const double low, const double high, const unsigned long bins,
0132                                                 const double weight ) const {
0133   AIDA::IHistogram1D* h( nullptr );
0134   if ( produceHistos() ) {
0135     // retrieve or book the histogram
0136     h = histo1D( ID );
0137     if ( !h ) { h = book1D( ID, title, low, high, bins ); }
0138     // fill
0139     h = fill( h, value, weight, title );
0140   }
0141   return h;
0142 }
0143 // ============================================================================
0144 // book the 1D histogram
0145 // ============================================================================
0146 template <class PBASE>
0147 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const Gaudi::Histo1DDef& hdef ) const {
0148   return book1D( hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
0149 }
0150 // ============================================================================
0151 // book the 1D histogram with forced ID
0152 // ============================================================================
0153 template <class PBASE>
0154 AIDA::IHistogram1D* GaudiHistos<PBASE>::book( const HistoID& ID, const Gaudi::Histo1DDef& hdef ) const {
0155   return book1D( ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins() );
0156 }
0157 // ============================================================================
0158 // fill the 1D histogram (book on demand)
0159 // ============================================================================
0160 template <class PBASE>
0161 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const Gaudi::Histo1DDef& hdef,
0162                                                 const double weight ) const {
0163   return plot1D( value, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
0164 }
0165 // ============================================================================
0166 // fill the 1D histogram with forced ID assignment (book on demand)
0167 // ============================================================================
0168 template <class PBASE>
0169 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const Gaudi::Histo1DDef& hdef,
0170                                                 const double weight ) const {
0171   return plot1D( value, ID, hdef.title(), hdef.lowEdge(), hdef.highEdge(), hdef.bins(), weight );
0172 }
0173 // ============================================================================
0174 // The END
0175 // ============================================================================