Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:21

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloValidationStatistics.h"
0003 #include <cmath>
0004 #include <iostream>
0005 
0006 CaloValidationStatistics::CaloValidationStatistics(std::string name, float expectedMean, float expectedRMS)
0007     : name_(name),
0008       expectedMean_(expectedMean),
0009       expectedRMS_(expectedRMS),
0010       sum_(0.),
0011       sumOfSquares_(0.),
0012       weightedSum_(0.),
0013       sumOfWeights_(0.),
0014       n_(0) {}
0015 
0016 CaloValidationStatistics::~CaloValidationStatistics() { edm::LogInfo("CaloValidationStatistics") << *this; }
0017 
0018 void CaloValidationStatistics::addEntry(float value, float weight) {
0019   sum_ += value;
0020   sumOfSquares_ += (value * value);
0021   weightedSum_ += value * weight;
0022   sumOfWeights_ += weight;
0023   ++n_;
0024 }
0025 
0026 float CaloValidationStatistics::mean() const { return sum_ / n_; }
0027 
0028 float CaloValidationStatistics::RMS() const {
0029   float numerator = n_ * sumOfSquares_ - sum_ * sum_;
0030   int denominator = n_ * (n_ - 1);
0031   return std::sqrt(numerator / denominator);
0032 }
0033 
0034 float CaloValidationStatistics::weightedMean() const { return weightedSum_ / sumOfWeights_; }
0035 
0036 std::ostream &operator<<(std::ostream &os, const CaloValidationStatistics &stat) {
0037   os << "OVAL " << stat.name() << " entries:" << stat.nEntries();
0038   if (stat.nEntries() > 0) {
0039     os << " Mean: " << stat.mean() << " (expect " << stat.expectedMean() << ")";
0040   }
0041   if (stat.nEntries() > 1) {
0042     os << "  RMS: " << stat.RMS() << " (expect " << stat.expectedRMS() << ")";
0043   }
0044   return os;
0045 }