CMS 3D CMS Logo

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