Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:27

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 #pragma once
0012 
0013 #include "Generic1D.h"
0014 #include <AIDA/IHistogram1D.h>
0015 #include <Gaudi/Histograming/Sink/Utils.h>
0016 #include <GaudiKernel/DataObject.h>
0017 #include <TH1D.h>
0018 
0019 #include <nlohmann/json.hpp>
0020 
0021 #include <mutex>
0022 
0023 namespace Gaudi {
0024 
0025   /**@class Histogram1D
0026    *
0027    * AIDA implementation for 1 D histograms using ROOT THD1
0028    *
0029    * @author  M.Frank
0030    */
0031   class GAUDI_API Histogram1D : public DataObject, public Gaudi::Generic1D<AIDA::IHistogram1D, TH1D> {
0032   private:
0033     void init( const std::string& title, bool initialize_axis = true );
0034     void initSums();
0035 
0036   protected:
0037     /// cache sumwx  when setting contents since I don't have bin mean
0038     double m_sumwx = 0;
0039 
0040   public:
0041     /// Standard constructor
0042     Histogram1D();
0043     /// Standard constructor with initialization. The histogram representation will be adopted
0044     Histogram1D( TH1D* rep );
0045 
0046     /// Adopt ROOT histogram representation
0047     void adoptRepresentation( TObject* rep ) override;
0048     /// set bin content (entries and centre are not used )
0049     virtual bool setBinContents( int i, int entries, double height, double error, double centre );
0050     // overwrite reset
0051     bool reset() override;
0052     // free function reset
0053     friend void reset( Histogram1D& h ) { h.reset(); }
0054     /// conversion to json via nlohmann library
0055     friend void to_json( nlohmann::json& j, Gaudi::Histogram1D const& h ) { j = *h.m_rep.get(); }
0056     /// set histogram statistics
0057     virtual bool setStatistics( int allEntries, double eqBinEntries, double mean, double rms );
0058     /// Fill the Profile1D with a value and the corresponding weight.
0059     bool fill( double x, double weight ) override;
0060     /// Update histogram RMS
0061     bool setRms( double rms );
0062     /// Create new histogram from any AIDA based histogram
0063     void copyFromAida( const AIDA::IHistogram1D& h );
0064     /// Retrieve reference to class defininition identifier
0065     const CLID&        clID() const override { return classID(); }
0066     static const CLID& classID() { return CLID_H1D; }
0067     /** Serialization mechanism, Serialize the object for reading.
0068      * @param s the StreamBuffer containing the data to be read
0069      * @return the resulting StreamBuffer, after reading
0070      */
0071     StreamBuffer& serialize( StreamBuffer& s );
0072 
0073     /** Serialization mechanism, Serialize the object for writing.
0074      * @param s the StreamBuffer where to write the data
0075      * @return the resulting StreamBuffer, after wrinting
0076      */
0077     StreamBuffer& serialize( StreamBuffer& s ) const;
0078 
0079   private:
0080     std::mutex m_fillSerialization;
0081 
0082   }; // end class Histogram1D
0083 } // end namespace Gaudi