Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include "DQMOffline/RecoB/interface/EtaPtBin.h"

#include <algorithm>
#include <sstream>

EtaPtBin::EtaPtBin(const bool& etaActive_,
                   const double& etaMin_,
                   const double& etaMax_,
                   const bool& ptActive_,
                   const double& ptMin_,
                   const double& ptMax_)
    : etaActive(etaActive_), etaMin(etaMin_), etaMax(etaMax_), ptActive(ptActive_), ptMin(ptMin_), ptMax(ptMax_) {
  descriptionString = buildDescriptionString(etaActive, etaMin, etaMax, ptActive, ptMin, ptMax);
}

std::string EtaPtBin::buildDescriptionString(const bool& etaActive_,
                                             const double& etaMin_,
                                             const double& etaMax_,
                                             const bool& ptActive_,
                                             const double& ptMin_,
                                             const double& ptMax_) {
  // create string only from the active parts
  std::stringstream stream("");

  if (etaActive_) {
    stream << "_ETA_" << etaMin_ << "-" << etaMax_;
  }

  if (ptActive_) {
    stream << "_PT_" << ptMin_ << "-" << ptMax_;
  }
  if (!(etaActive_ || ptActive_))
    stream << "_GLOBAL";

  std::string descr(stream.str());
  // remove blanks which are introduced when adding doubles
  auto last = std::remove(descr.begin(), descr.end(), ' ');
  descr.erase(last, descr.end());
  std::replace(descr.begin(), descr.end(), '.', 'v');

  return descr;
}

bool EtaPtBin::inBin(const reco::Jet& jet, const double jec) const { return inBin(jet.eta(), jet.pt() * jec); }

// bool EtaPtBin::inBin(const BTagMCTools::JetFlavour & jetFlavour) const
// {
//   return inBin(jetFlavour.underlyingParton4Vec().Eta(),
// 	       jetFlavour.underlyingParton4Vec().Pt());
// }

bool EtaPtBin::inBin(const double& eta, const double& pt) const {
  if (etaActive) {
    if (fabs(eta) < etaMin)
      return false;
    if (fabs(eta) > etaMax)
      return false;
  }

  if (ptActive) {
    if (pt < ptMin)
      return false;
    if (pt > ptMax)
      return false;
  }

  return true;
}