Warning, /include/GaudiAlg/GaudiHistos_1DVariableBinning.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 // ============================= Variable 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 HistoBinEdges& edges ) const {
0018 //
0019 if ( !produceHistos() ) { return nullptr; } // RETURN
0020 //
0021 // exist?
0022 auto hist = histo1D( title );
0023 // histogram is already booked
0024 if ( hist ) { return hist; } // RETURN !!
0025
0026 // propose the histogram ID
0027 HistoID ID;
0028 newHistoID( title, ID );
0029
0030 // Create a new histogram and return
0031 return this->book1D( ID, title, edges );
0032 }
0033 // ============================================================================
0034 // book the 1D histogram with forced ID (book on demand)
0035 // ============================================================================
0036 template <class PBASE>
0037 AIDA::IHistogram1D* GaudiHistos<PBASE>::book1D( const HistoID& ID, const std::string& title,
0038 const HistoBinEdges& edges ) const {
0039 //
0040 if ( !produceHistos() ) { return nullptr; } // RETURN
0041 //
0042 // Check ID
0043 if ( ID.undefined() ) {
0044 this->Error( "Undefined Histogram ID : Title='" + title + "'" ).ignore();
0045 return nullptr;
0046 }
0047
0048 // exist?
0049 auto hist = histo1D( ID );
0050 // histogram is already booked
0051 if ( hist ) { return hist; } // RETURN !!
0052
0053 // Histogram title
0054 const std::string& htitle = ( title.empty() ? "Unnamed 1D Histogram ID=" + ID.idAsString() : title );
0055
0056 // book the histogram
0057 if ( ID.numeric() ) {
0058 hist = this->histoSvc()->book( histoPath(), ID.numericID(), htitle, edges );
0059 } else if ( ID.literal() ) {
0060 hist = this->histoSvc()->book( histoPath() + "/" + ID.literalID(), htitle, edges );
0061 }
0062
0063 // check OK
0064 if ( !hist ) {
0065 this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() + "' title='" + htitle + "'" ).ignore();
0066 return nullptr;
0067 } // RETURN !!
0068
0069 // add histogram into histogram storages
0070 m_histo1DMapID[ID] = hist;
0071 m_histo1DMapTitle[title] = hist;
0072
0073 // Declare to monitoring service
0074 monitorHisto( Gaudi::Utils::Histos::toBase( hist ), ID );
0075
0076 // Printout and return
0077 if ( this->msgLevel( MSG::DEBUG ) ) {
0078 this->debug() << "Booked 1D Histogram : ID='" << ID << "' Path=" << histoPath() << " Title='"
0079 << Gaudi::Utils::Histos::htitle( hist ) << "'" << endmsg;
0080 }
0081 return hist;
0082 }
0083 // ============================================================================
0084 // fill the 1D histogram (book on demand)
0085 // ============================================================================
0086 template <class PBASE>
0087 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const std::string& title,
0088 const HistoBinEdges& edges, const double weight ) const {
0089 AIDA::IHistogram1D* h( nullptr );
0090 if ( produceHistos() ) {
0091 // retrieve or book the histogram
0092 h = histo1D( title );
0093 if ( !h ) { h = book1D( title, edges ); }
0094 // fill the histogram
0095 h = fill( h, value, weight, title );
0096 }
0097 return h;
0098 }
0099 // ============================================================================
0100 // fill the 1D variable histogram with forced ID assignment (book on demand)
0101 // ============================================================================
0102 template <class PBASE>
0103 AIDA::IHistogram1D* GaudiHistos<PBASE>::plot1D( const double value, const HistoID& ID, const std::string& title,
0104 const HistoBinEdges& edges, const double weight ) const {
0105 AIDA::IHistogram1D* h( nullptr );
0106 if ( produceHistos() ) {
0107 // retrieve or book the histogram
0108 h = histo1D( ID );
0109 if ( !h ) { h = book1D( ID, title, edges ); }
0110 // fill
0111 h = fill( h, value, weight, title );
0112 }
0113 return h;
0114 }
0115 // ============================================================================
0116 // The END
0117 // ============================================================================