Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 //
0004 // File   : src/EtaDepResolution.cc
0005 // Author : Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0006 // Purpose: Hold on to an element eta-dependent resolution.
0007 //
0008 
0009 /**
0010 
0011     @file EtaDepResElement.cc
0012 
0013     @brief Hold on to an element of eta-dependent
0014     resolution object, namely a resolution and the eta range in which the
0015     resolution is valid.  See the documentation for the header file
0016     EtaDepResElement.h for details.
0017 
0018     @author
0019     Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0020 
0021     @par Creation Date:
0022     June 2009
0023 
0024  */
0025 
0026 #include <sstream>
0027 #include <stdexcept>
0028 #include "TopQuarkAnalysis/TopHitFit/interface/EtaDepResElement.h"
0029 
0030 namespace hitfit {
0031 
0032   EtaDepResElement::EtaDepResElement(double eta1, double eta2, const Vector_Resolution& res) : _Vector_Resolution(res) {
0033     SetEta(eta1, eta2);
0034   }
0035 
0036   EtaDepResElement::EtaDepResElement(double eta1, double eta2, std::string res) : _Vector_Resolution(res) {
0037     SetEta(eta1, eta2);
0038   }
0039 
0040   EtaDepResElement::EtaDepResElement(double eta1,
0041                                      double eta2,
0042                                      const Resolution& p_res,
0043                                      const Resolution& eta_res,
0044                                      const Resolution& phi_res,
0045                                      bool use_et)
0046       : _Vector_Resolution(p_res, eta_res, phi_res, use_et) {
0047     SetEta(eta1, eta2);
0048   }
0049 
0050   EtaDepResElement::~EtaDepResElement() {}
0051 
0052   void EtaDepResElement::SetEta(double eta1, double eta2) {
0053     if (fabs(eta1 - eta2) < (1.0 / double(InverseEtaPrecision))) {
0054       throw std::runtime_error("EtaDepResElement::equal EtaMin and EtaMax");
0055     }
0056 
0057     if (eta1 < eta2) {
0058       _EtaMin = eta1;
0059       _EtaMax = eta2;
0060     } else {
0061       _EtaMin = eta2;
0062       _EtaMax = eta1;
0063     }
0064   }
0065 
0066   /**
0067    @brief Comparison operator, compare two EtaDepResElement instances
0068    based on their respective valid \f$\eta\f$ ranges.
0069 
0070    @param a The first instance of EtaDepResElement to be compared.
0071 
0072    @param b The second instance of EtaDepResElement to be compared.
0073 
0074    @par Return:
0075    <b>TRUE</b> if <i>a</i>'s upper limit is less than <i>b</i>'s lower
0076    limit.<br>
0077    <b>FALSE</b> all other cases.
0078 */
0079   bool operator<(const EtaDepResElement& a, const EtaDepResElement& b) {
0080     if (a.IsOverlap(b)) {
0081       return false;
0082     }
0083     return !(a._EtaMax > b._EtaMin);
0084   }
0085 
0086   const double EtaDepResElement::EtaMin() const { return _EtaMin; }
0087 
0088   const double EtaDepResElement::EtaMax() const { return _EtaMax; }
0089 
0090   bool EtaDepResElement::IsOverlap(const EtaDepResElement& e) const {
0091     return (IsInInterval(e._EtaMin) || IsInInterval(e._EtaMax));
0092   }
0093 
0094   bool EtaDepResElement::IsNotOverlap(const EtaDepResElement& e) const { return !(IsOverlap(e)); }
0095 
0096   bool EtaDepResElement::IsInInterval(const double& eta) const { return ((_EtaMin < eta) && (eta < _EtaMax)); }
0097 
0098   bool EtaDepResElement::IsOnEdge(const double& eta) const {
0099     bool nearEtaMin = fabs(eta - _EtaMin) < (1.0 / double(InverseEtaPrecision));
0100     bool nearEtaMax = fabs(eta - _EtaMax) < (1.0 / double(InverseEtaPrecision));
0101     return nearEtaMin || nearEtaMax;
0102   }
0103 
0104   bool EtaDepResElement::IsOnEdge(const EtaDepResElement& e) const {
0105     return (e.IsOnEdge(_EtaMin) || e.IsOnEdge(_EtaMax));
0106   }
0107 
0108   const Vector_Resolution EtaDepResElement::GetResolution() const { return _Vector_Resolution; }
0109 
0110   std::ostream& operator<<(std::ostream& s, const EtaDepResElement& e) {
0111     s << "(" << e._EtaMin << " to " << e._EtaMax << ")"
0112       << " / " << e.GetResolution();
0113     return s;
0114   }
0115 
0116 }  // namespace hitfit