CMS 3D CMS Logo

EtaDepResolution.cc
Go to the documentation of this file.
1 //
2 //
3 // File : src/EtaDepResolution.cc
4 // Author : Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
5 // Purpose: Hold on to eta-dependent resolution.
6 //
7 
24 #include <algorithm>
25 #include <sstream>
26 #include <stdexcept>
28 
29 namespace hitfit {
30 
31  std::vector<EtaDepResElement>::const_iterator EtaDepResolution::FindResolution(double& eta) const {
32  for (std::vector<EtaDepResElement>::const_iterator res = _EtaDepResElement.begin(); res != _EtaDepResElement.end();
33  ++res) {
34  if (res->IsInInterval(eta) || res->IsOnEdge(eta)) {
35  return res;
36  }
37  }
38  return _EtaDepResElement.end();
39  }
40 
41  void EtaDepResolution::sort() { std::stable_sort(_EtaDepResElement.begin(), _EtaDepResElement.end()); }
42 
44 
45  EtaDepResolution::EtaDepResolution(const std::string& default_file) { Read(default_file); }
46 
48 
50  const Defaults_Text defs(default_file);
51  Read(defs);
52  return _EtaDepResElement.size();
53  }
54 
56  _EtaDepResElement.clear();
57 
59  std::ostringstream os_etamin;
60  std::ostringstream os_etamax;
61  std::ostringstream os_res;
62 
63  os_etamin << "etadep_etamin" << i;
64  os_etamax << "etadep_etamax" << i;
65  os_res << "etadep_vecres" << i;
66 
67  if (defs.exists(os_etamin.str()) && defs.exists(os_etamax.str()) && defs.exists(os_res.str())) {
68  double etamin = defs.get_float(os_etamin.str());
69  double etamax = defs.get_float(os_etamax.str());
70  Vector_Resolution res(defs.get_string(os_res.str()));
72 
73  } else {
74  break;
75  }
76  }
77 
79  sort();
80  } else {
81  _EtaDepResElement.clear();
82  }
83 
84  return _EtaDepResElement.size();
85  }
86 
87  bool EtaDepResolution::CheckNoOverlap(const std::vector<EtaDepResElement>& v) {
88  for (std::vector<EtaDepResElement>::size_type i = 0; i != v.size(); i++) {
89  for (std::vector<EtaDepResElement>::size_type j = i + 1; j != v.size(); j++) {
90  if (v[i].IsOverlap(v[j])) {
91  return false;
92  }
93  }
94  }
95  return true;
96  }
97 
98  const double EtaDepResolution::EtaMin() const {
99  if (!(_EtaDepResElement.empty())) {
100  return _EtaDepResElement.front().EtaMin();
101  }
102  return 999.; // a ridiculously positive large number
103  }
104 
105  const double EtaDepResolution::EtaMax() const {
106  if (!(_EtaDepResElement.empty())) {
107  return _EtaDepResElement.back().EtaMax();
108  }
109  return -999.; // a ridiculously negative large number
110  }
111 
112  const bool EtaDepResolution::CheckEta(double eta) const { return FindResolution(eta) != _EtaDepResElement.end(); }
113 
115 
117  std::vector<EtaDepResElement>::const_iterator etaDepResEleVecIter = FindResolution(eta);
118  if (etaDepResEleVecIter != _EtaDepResElement.end()) {
119  return etaDepResEleVecIter->GetResolution();
120  }
121 
122  std::stringstream message;
123  message << "Error, the given eta value : " << eta << " is not inside the valid eta range!";
124 
125  throw std::runtime_error(message.str());
126  }
127 
129 
130  const std::vector<EtaDepResElement> EtaDepResolution::GetEtaDepResElement() const { return _EtaDepResElement; }
131 
132 } // namespace hitfit
hitfit::EtaDepResolution::~EtaDepResolution
~EtaDepResolution()
Definition: EtaDepResolution.cc:47
hitfit::EtaDepResolution::CheckNoOverlap
bool CheckNoOverlap(const std::vector< EtaDepResElement > &v)
Check for non-overlapping -range between -dependent resolution elements in a list.
Definition: EtaDepResolution.cc:87
mps_fire.i
i
Definition: mps_fire.py:355
hitfit
Definition: Base_Constrainer.h:43
EtaDepResolution.h
Hold on to -dependent resolution. This class acts as a function object and returns Vector_Resolution ...
hitfit::Defaults_Text::get_string
std::string get_string(std::string name) const override
Definition: Defaults_Text.cc:416
hitfit::Vector_Resolution
Definition: Vector_Resolution.h:89
hitfit::EtaDepResolution::sort
void sort()
Definition: EtaDepResolution.cc:41
hitfit::Defaults_Text::get_float
double get_float(std::string name) const override
Definition: Defaults_Text.cc:383
findQualityFiles.v
v
Definition: findQualityFiles.py:179
muonTiming_cfi.etamin
etamin
Definition: muonTiming_cfi.py:30
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
hitfit::EtaDepResolution::CheckEta
const bool CheckEta(double eta) const
Check is an input value is within the valid -range of this instance.
Definition: EtaDepResolution.cc:112
hitfit::EtaDepResolution::GetResolution
Vector_Resolution GetResolution(double &eta) const
Return the corresponding resolution for a value of .
Definition: EtaDepResolution.cc:116
PVValHelper::eta
Definition: PVValidationHelpers.h:69
hitfit::Defaults_Text
A lightweight implementation of the Defaults interface that uses simple ASCII text files.
Definition: Defaults_Text.h:117
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
hitfit::EtaDepResolution::FindResolution
std::vector< EtaDepResElement >::const_iterator FindResolution(double &eta) const
Internal method to return the corresponding -dependent resolution element for a given value.
Definition: EtaDepResolution.cc:31
hitfit::EtaDepResolution::EtaMin
const double EtaMin() const
Return the lower limit of the valid -range.
Definition: EtaDepResolution.cc:98
hitfit::EtaDepResolution::GetEtaDepResElement
const std::vector< EtaDepResElement > GetEtaDepResElement() const
Access the internal list of -dependent resolution elements.
Definition: EtaDepResolution.cc:130
res
Definition: Electron.h:6
hitfit::EtaDepResolution::_EtaDepResElement
std::vector< EtaDepResElement > _EtaDepResElement
Definition: EtaDepResolution.h:91
muonTiming_cfi.etamax
etamax
Definition: muonTiming_cfi.py:23
hitfit::EtaDepResolution::EtaMax
const double EtaMax() const
Return the upper limit of the valid -range.
Definition: EtaDepResolution.cc:105
hitfit::Defaults_Text::exists
bool exists(std::string name) const override
Definition: Defaults_Text.cc:354
hitfit::EtaDepResolution::EtaDepResolution
EtaDepResolution()
Default constructor, instantiate an EtaDepResolution object with empty list of -dependent resolution ...
Definition: EtaDepResolution.cc:43
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hitfit::EtaDepResElement
Represent a resolution and an range in which the resolution is valid.
Definition: EtaDepResElement.h:61
hitfit::EtaDepResolution::Read
std::vector< EtaDepResElement >::size_type Read(const std::string &default_file)
Read the -dependent resolution information from an ASCII text file.
Definition: EtaDepResolution.cc:49
hitfit::EtaDepResolution::operator()
Vector_Resolution operator()(double &eta)
Allow users to call this instance as a function to access the corresponding resolution for an input v...
Definition: EtaDepResolution.cc:114