CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Validation/MuonRPCGeometry/src/PTStatistics.cc

Go to the documentation of this file.
00001 #include "Validation/MuonRPCGeometry/interface/PTStatistics.h"
00002 
00003 #include <sstream>
00004 #include <numeric>
00005 #include <iostream>
00006 //-----------------------------------------------------------------------------
00007 //  PTStatistics
00008 //-----------------------------------------------------------------------------
00009 bool PTStatistics::rateInitilized = false;
00010 std::vector<long double> PTStatistics::m_rates = std::vector<long double>(RPCpg::ptBins_s,0);
00011 
00012 PTStatistics::PTStatistics(){
00013    this->assign(RPCpg::ptBins_s,0);
00014    
00015    if(!rateInitilized){
00016      //std::cout << "Initilizing rates" << std::endl;
00017      rateInitilized = true;
00018      m_rates.assign(RPCpg::ptBins_s,0);
00019      
00020      // Note bin=0 is empty during generation
00021      // bin=0 is used only when calculating efficiencies (for storing muons,that werent found)
00022      for (unsigned int i = 1;i < this->m_rates.size(); ++i ){
00023 
00024         long double low =  RPCpg::pts[i];
00025         long double high =  RPCpg::pts[i+1];
00026         long double rt = RPCpg::rate(low)-RPCpg::rate(high);
00027 
00028        /* std::cout << "PtCode " << i
00029               << " " << low
00030               << " " << high
00031               << " " << rt
00032               << std::endl;*/
00033         this->m_rates.at(i) = rt;
00034      }
00035 
00036    }
00037 
00038 }
00039 
00040 void PTStatistics::update(PTStatistics & otherPtStats){
00041    
00042    for (unsigned int i=0; i<this->size();++i){
00043       //this->at(i)+=otherPtStats.at(i);
00044       (*this)[i]+=otherPtStats[i];
00045    }
00046    
00047 
00048 }
00049 std::string PTStatistics::toString(){
00050    
00051    std::stringstream ss;
00052    ss << "PTStats:";
00053    for (unsigned int i=0; i<this->size();++i){
00054       ss << " " << this->at(i);
00055    }
00056    
00057    return ss.str();
00058 }
00059 
00060 long double PTStatistics::eff(int ptCut){  // ptCut=0 -> total rate
00061    //int eqOrAbovePtCut = 0;
00062    //for(unsigned int i=ptCut;i<this->size();++i) eqOrAbovePtCut += this->at(i);
00063    // return double(eqOrAbovePtCut)/this->sum();
00064    return double(sum(ptCut))/this->sum();
00065 }
00066 
00067 
00068 long int PTStatistics::sum(const int & ptCut) const{
00069 //inline int PTStatistics::sum(const int & ptCut) const{  
00070    //return std::accumulate(this->begin(),this->end(),0);
00071    long int eqOrAbovePtCut = 0;
00072    unsigned int size = this->size();
00073    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
00074    for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
00075    return eqOrAbovePtCut;
00076 }
00077 
00078 //inline int PTStatistics::sum() const{
00079 long int PTStatistics::sum() const{  
00080    //return std::accumulate(this->begin(),this->end(),0);
00081    long int eqOrAbovePtCut = 0;
00082    //unsigned int size = this->size();
00083    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
00084    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
00085    PTStatistics::const_iterator it = this->begin();
00086    PTStatistics::const_iterator itend = this->end();
00087    for(;it!=itend;++it) eqOrAbovePtCut += *it;
00088    
00089    return eqOrAbovePtCut;
00090 }
00091 
00092 long double PTStatistics::sumR(const int & ptCut) const{ 
00093    //return std::accumulate(this->begin(),this->end(),0);
00094    long double eqOrAbovePtCut = 0;
00095    unsigned int size = this->size();
00096    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
00097    for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i]*m_rates[i];
00098    return eqOrAbovePtCut;
00099 }
00100 
00101 long double PTStatistics::sumR() const{ 
00102    //return std::accumulate(this->begin(),this->end(),0);
00103    long double eqOrAbovePtCut = 0;
00104    //unsigned int size = this->size();
00105    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
00106    //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
00107    //PTStatistics::const_iterator it = this->begin();
00108    //PTStatistics::const_iterator itend = this->end();
00109    //PtCode 0 - muons not found
00110    unsigned int size = this->size();
00111    for(unsigned int i=1;i<size;++i) eqOrAbovePtCut += (*this)[i]*m_rates[i];
00112    //for(;it!=itend;++it) eqOrAbovePtCut += *it*m_rates[i];
00113    
00114    return eqOrAbovePtCut;
00115 }
00116