CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/SimCalorimetry/CaloSimAlgos/src/CaloValidationStatistics.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/CaloSimAlgos/interface/CaloValidationStatistics.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <cmath>
00004 #include <iostream>
00005 
00006 CaloValidationStatistics::CaloValidationStatistics(std::string name, float expectedMean, float expectedRMS) 
00007 :  name_(name),
00008    expectedMean_(expectedMean),
00009    expectedRMS_(expectedRMS),
00010    sum_(0.),
00011    sumOfSquares_(0.),
00012    weightedSum_(0.),
00013    sumOfWeights_(0.),
00014    n_(0)
00015 {
00016 }
00017 
00018 
00019 CaloValidationStatistics::~CaloValidationStatistics() 
00020 {
00021   edm::LogInfo("CaloValidationStatistics") << *this;
00022 }
00023 
00024 void CaloValidationStatistics::addEntry(float value, float weight) {
00025   sum_ += value;
00026   sumOfSquares_ += (value*value);
00027   weightedSum_ += value*weight;
00028   sumOfWeights_ += weight;
00029   ++n_;
00030 }
00031 
00032 
00033 float CaloValidationStatistics::mean() const {
00034   return sum_/n_;
00035 }
00036 
00037 
00038 float CaloValidationStatistics::RMS() const {
00039   float numerator = n_ * sumOfSquares_ - sum_*sum_;
00040   int denominator = n_ * (n_-1);
00041   return std::sqrt(numerator/denominator);
00042 }
00043 
00044  
00045 float CaloValidationStatistics::weightedMean() const  {
00046   return weightedSum_ / sumOfWeights_;
00047 }
00048 
00049 
00050 std::ostream& operator<<(std::ostream & os,const CaloValidationStatistics & stat) {
00051   os << "OVAL " << stat.name() << " entries:" << stat.nEntries();
00052   if(stat.nEntries() > 0) {
00053      os << " Mean: " << stat.mean() 
00054         << " (expect " << stat.expectedMean() << ")";
00055   }
00056   if(stat.nEntries() > 1) {      
00057                  os << "  RMS: " << stat.RMS()
00058         << " (expect " << stat.expectedRMS() << ")";
00059   }
00060   return os;
00061 }
00062 
00063