Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:06

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4StatDouble
0027 //
0028 // Class description:
0029 //
0030 // Class providing simple "one variable statistics" capability.
0031 
0032 // Original Author: Giovanni Santin (ESA) - October 2005 in GRAS tool
0033 // Adaptation and comments by: John Apostolakis (CERN) - November 2011
0034 // --------------------------------------------------------------------
0035 #ifndef G4StatDouble_hh
0036 #define G4StatDouble_hh 1
0037 
0038 #include "globals.hh"
0039 
0040 class G4StatDouble
0041 {
0042  public:
0043   G4StatDouble();
0044   G4StatDouble(G4double);
0045   virtual ~G4StatDouble() = default;
0046 
0047   G4StatDouble(const G4StatDouble&) = default;
0048 
0049   G4StatDouble& operator=(const G4double& rhs)
0050   {
0051     reset();
0052     fill(rhs);
0053     return *this;
0054   }
0055   G4StatDouble& operator=(const G4StatDouble& rhs) = default;
0056   G4StatDouble& operator+=(const G4double& rhs)
0057   {
0058     fill(rhs);
0059     return *this;
0060   }
0061   G4StatDouble& operator+=(const G4StatDouble& rhs)
0062   {
0063     add(&rhs);
0064     return *this;
0065   }
0066 
0067   void reset();
0068   void fill(G4double x, G4double weight = 1.);
0069   // Add new data point: value "x" with weight
0070   void scale(G4double);
0071   // Reset scale
0072 
0073   G4double mean() const;
0074   G4double rms();
0075   // The moments
0076 
0077   G4double mean(G4double ext_sum_w) const;
0078   // Mean scaled to sum of weights
0079   G4double rms(G4double ext_sum_w, G4int ext_n);
0080   // RMS  scaled to sum of weights
0081 
0082   void add(const G4StatDouble*);
0083   // merge 2 statistics
0084 
0085   inline G4int n() const { return m_n; }
0086   inline G4double sum_w() const { return m_sum_w; }
0087   inline G4double sum_w2() const { return m_sum_w2; }
0088   inline G4double sum_wx() const { return m_sum_wx; }
0089   inline G4double sum_wx2() const { return m_sum_wx2; }
0090 
0091  protected:
0092   G4double rms(G4double sum_wx, G4double sum_wx2, G4double sum_w, G4int n);
0093 
0094  protected:
0095   G4double m_sum_wx  = 0.0;
0096   G4double m_sum_wx2 = 0.0;
0097   G4int m_n          = 0;
0098   G4double m_sum_w   = 0.0;
0099   G4double m_sum_w2  = 0.0;
0100   G4double m_scale   = 0.0;
0101 };
0102 
0103 #endif