CMS 3D CMS Logo

PTStatistics.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 #include <numeric>
5 #include <iostream>
6 //-----------------------------------------------------------------------------
7 // PTStatistics
8 //-----------------------------------------------------------------------------
9 static std::vector<long double> initializeRates()
10 {
11  std::vector<long double> rates(RPCpg::ptBins_s,0);
12  //std::cout << "Initilizing rates" << std::endl;
13 
14  // Note bin=0 is empty during generation
15  // bin=0 is used only when calculating efficiencies (for storing muons,that werent found)
16  for (unsigned int i = 1;i < rates.size(); ++i ){
17 
18  long double low = RPCpg::pts[i];
19  long double high = RPCpg::pts[i+1];
20  long double rt = RPCpg::rate(low)-RPCpg::rate(high);
21 
22  /* std::cout << "PtCode " << i
23  << " " << low
24  << " " << high
25  << " " << rt
26  << std::endl;*/
27  rates[i] = rt;
28  }
29  return rates;
30 }
31 
32 const std::vector<long double> PTStatistics::m_rates = initializeRates();
33 
35  this->assign(RPCpg::ptBins_s,0);
36 }
37 
38 
39 void PTStatistics::update(PTStatistics & otherPtStats){
40 
41  for (unsigned int i=0; i<this->size();++i){
42  //this->at(i)+=otherPtStats.at(i);
43  (*this)[i]+=otherPtStats[i];
44  }
45 
46 
47 }
49 
50  std::stringstream ss;
51  ss << "PTStats:";
52  for (unsigned int i=0; i<this->size();++i){
53  ss << " " << (*this)[i];
54  }
55 
56  return ss.str();
57 }
58 
59 long double PTStatistics::eff(int ptCut){ // ptCut=0 -> total rate
60  //int eqOrAbovePtCut = 0;
61  //for(unsigned int i=ptCut;i<this->size();++i) eqOrAbovePtCut += this->at(i);
62  // return double(eqOrAbovePtCut)/this->sum();
63  return double(sum(ptCut))/this->sum();
64 }
65 
66 
67 long int PTStatistics::sum(const int & ptCut) const{
68 //inline int PTStatistics::sum(const int & ptCut) const{
69  //return std::accumulate(this->begin(),this->end(),0);
70  long int eqOrAbovePtCut = 0;
71  unsigned int size = this->size();
72  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
73  for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
74  return eqOrAbovePtCut;
75 }
76 
77 //inline int PTStatistics::sum() const{
78 long int PTStatistics::sum() const{
79  //return std::accumulate(this->begin(),this->end(),0);
80  long int eqOrAbovePtCut = 0;
81  //unsigned int size = this->size();
82  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
83  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
84  PTStatistics::const_iterator it = this->begin();
85  PTStatistics::const_iterator itend = this->end();
86  for(;it!=itend;++it) eqOrAbovePtCut += *it;
87 
88  return eqOrAbovePtCut;
89 }
90 
91 long double PTStatistics::sumR(const int & ptCut) const{
92  //return std::accumulate(this->begin(),this->end(),0);
93  long double eqOrAbovePtCut = 0;
94  unsigned int size = this->size();
95  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
96  for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i]*m_rates[i];
97  return eqOrAbovePtCut;
98 }
99 
100 long double PTStatistics::sumR() const{
101  //return std::accumulate(this->begin(),this->end(),0);
102  long double eqOrAbovePtCut = 0;
103  //unsigned int size = this->size();
104  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += this->at(i);
105  //for(unsigned int i=ptCut;i<size;++i) eqOrAbovePtCut += (*this)[i];
106  //PTStatistics::const_iterator it = this->begin();
107  //PTStatistics::const_iterator itend = this->end();
108  //PtCode 0 - muons not found
109  unsigned int size = this->size();
110  for(unsigned int i=1;i<size;++i) eqOrAbovePtCut += (*this)[i]*m_rates[i];
111  //for(;it!=itend;++it) eqOrAbovePtCut += *it*m_rates[i];
112 
113  return eqOrAbovePtCut;
114 }
115 
size
Write out results.
int i
Definition: DBlmapReader.cc:9
void update(PTStatistics &otherPtStats)
Definition: PTStatistics.cc:39
static const std::vector< long double > m_rates
Definition: PTStatistics.h:25
static const double pts[33]
Definition: Constants.h:30
void assign(const std::vector< float > &vec, float &a, float &b, float &c, float &d)
#define end
Definition: vmac.h:37
long int sum() const
Definition: PTStatistics.cc:78
static std::vector< long double > initializeRates()
Definition: PTStatistics.cc:9
const unsigned int ptBins_s
Definition: Constants.h:28
long double eff(int ptCut)
Definition: PTStatistics.cc:59
double rate(double x)
Definition: Constants.cc:3
#define begin
Definition: vmac.h:30
long double sumR() const
std::string toString()
Definition: PTStatistics.cc:48