Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:16

0001 //
0002 //
0003 // File   : src/EtaDepResolution.cc
0004 // Author : Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0005 // Purpose: Hold on to eta-dependent resolution.
0006 //
0007 
0008 /**
0009 
0010     @file EtaDepResolution.cc
0011 
0012     @brief Hold on to \f$\eta\f$-dependent
0013     resolution.  See the documentation for the header file EtaDepResolution.h
0014     for details.
0015 
0016     @author
0017     Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0018 
0019     @par Creation date:
0020     June 2009
0021 
0022  */
0023 
0024 #include <algorithm>
0025 #include <sstream>
0026 #include <stdexcept>
0027 #include "TopQuarkAnalysis/TopHitFit/interface/EtaDepResolution.h"
0028 
0029 namespace hitfit {
0030 
0031   std::vector<EtaDepResElement>::const_iterator EtaDepResolution::FindResolution(double& eta) const {
0032     for (std::vector<EtaDepResElement>::const_iterator res = _EtaDepResElement.begin(); res != _EtaDepResElement.end();
0033          ++res) {
0034       if (res->IsInInterval(eta) || res->IsOnEdge(eta)) {
0035         return res;
0036       }
0037     }
0038     return _EtaDepResElement.end();
0039   }
0040 
0041   void EtaDepResolution::sort() { std::stable_sort(_EtaDepResElement.begin(), _EtaDepResElement.end()); }
0042 
0043   EtaDepResolution::EtaDepResolution() {}
0044 
0045   EtaDepResolution::EtaDepResolution(const std::string& default_file) { Read(default_file); }
0046 
0047   EtaDepResolution::~EtaDepResolution() {}
0048 
0049   std::vector<EtaDepResElement>::size_type EtaDepResolution::Read(const std::string& default_file) {
0050     const Defaults_Text defs(default_file);
0051     Read(defs);
0052     return _EtaDepResElement.size();
0053   }
0054 
0055   std::vector<EtaDepResElement>::size_type EtaDepResolution::Read(const Defaults_Text& defs) {
0056     _EtaDepResElement.clear();
0057 
0058     for (std::vector<EtaDepResElement>::size_type i = 0;; ++i) {
0059       std::ostringstream os_etamin;
0060       std::ostringstream os_etamax;
0061       std::ostringstream os_res;
0062 
0063       os_etamin << "etadep_etamin" << i;
0064       os_etamax << "etadep_etamax" << i;
0065       os_res << "etadep_vecres" << i;
0066 
0067       if (defs.exists(os_etamin.str()) && defs.exists(os_etamax.str()) && defs.exists(os_res.str())) {
0068         double etamin = defs.get_float(os_etamin.str());
0069         double etamax = defs.get_float(os_etamax.str());
0070         Vector_Resolution res(defs.get_string(os_res.str()));
0071         _EtaDepResElement.push_back(EtaDepResElement(etamin, etamax, res));
0072 
0073       } else {
0074         break;
0075       }
0076     }
0077 
0078     if (CheckNoOverlap(_EtaDepResElement)) {
0079       sort();
0080     } else {
0081       _EtaDepResElement.clear();
0082     }
0083 
0084     return _EtaDepResElement.size();
0085   }
0086 
0087   bool EtaDepResolution::CheckNoOverlap(const std::vector<EtaDepResElement>& v) {
0088     for (std::vector<EtaDepResElement>::size_type i = 0; i != v.size(); i++) {
0089       for (std::vector<EtaDepResElement>::size_type j = i + 1; j != v.size(); j++) {
0090         if (v[i].IsOverlap(v[j])) {
0091           return false;
0092         }
0093       }
0094     }
0095     return true;
0096   }
0097 
0098   const double EtaDepResolution::EtaMin() const {
0099     if (!(_EtaDepResElement.empty())) {
0100       return _EtaDepResElement.front().EtaMin();
0101     }
0102     return 999.;  // a ridiculously positive large number
0103   }
0104 
0105   const double EtaDepResolution::EtaMax() const {
0106     if (!(_EtaDepResElement.empty())) {
0107       return _EtaDepResElement.back().EtaMax();
0108     }
0109     return -999.;  // a ridiculously negative large number
0110   }
0111 
0112   const bool EtaDepResolution::CheckEta(double eta) const { return FindResolution(eta) != _EtaDepResElement.end(); }
0113 
0114   Vector_Resolution EtaDepResolution::operator()(double& eta) { return GetResolution(eta); }
0115 
0116   Vector_Resolution EtaDepResolution::GetResolution(double& eta) const {
0117     std::vector<EtaDepResElement>::const_iterator etaDepResEleVecIter = FindResolution(eta);
0118     if (etaDepResEleVecIter != _EtaDepResElement.end()) {
0119       return etaDepResEleVecIter->GetResolution();
0120     }
0121 
0122     std::stringstream message;
0123     message << "Error, the given eta value : " << eta << " is not inside the valid eta range!";
0124 
0125     throw std::runtime_error(message.str());
0126   }
0127 
0128   EtaDepResElement EtaDepResolution::GetEtaDepResElement(double& eta) const { return *(FindResolution(eta)); }
0129 
0130   const std::vector<EtaDepResElement> EtaDepResolution::GetEtaDepResElement() const { return _EtaDepResElement; }
0131 
0132 }  // namespace hitfit