Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:07

0001 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0002 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <sstream>
0006 
0007 using namespace reco;
0008 
0009 IsoDeposit::IsoDeposit(const Direction& candDirection) : theDirection(candDirection), theCandTag(0.) {
0010   theVeto.vetoDir = theDirection;
0011   theVeto.dR = 0.;
0012 }
0013 
0014 IsoDeposit::IsoDeposit(double eta, double phi) : theDirection(Direction(eta, phi)), theCandTag(0.) {
0015   theVeto.vetoDir = theDirection;
0016   theVeto.dR = 0.;
0017 }
0018 
0019 void IsoDeposit::addDeposit(double dr, double value) {
0020   Distance relDir = {float(dr), 0.f};
0021   theDeposits.insert(std::make_pair(relDir, value));
0022 }
0023 
0024 void IsoDeposit::addDeposit(const Direction& depDir, double deposit) {
0025   Distance relDir = depDir - theDirection;
0026   theDeposits.insert(std::make_pair(relDir, deposit));
0027 }
0028 
0029 double IsoDeposit::depositWithin(double coneSize, const Vetos& vetos, bool skipDepositVeto) const {
0030   return depositAndCountWithin(coneSize, vetos, -1e+36, skipDepositVeto).first;
0031 }
0032 
0033 double IsoDeposit::depositWithin(Direction dir, double coneSize, const Vetos& vetos, bool skipDepositVeto) const {
0034   return depositAndCountWithin(dir, coneSize, vetos, -1e+36, skipDepositVeto).first;
0035 }
0036 
0037 std::pair<double, int> IsoDeposit::depositAndCountWithin(double coneSize,
0038                                                          const Vetos& vetos,
0039                                                          double threshold,
0040                                                          bool skipDepositVeto) const {
0041   double result = 0;
0042   int count = 0;
0043 
0044   Vetos allVetos = vetos;
0045   typedef Vetos::const_iterator IV;
0046   if (!skipDepositVeto)
0047     allVetos.push_back(theVeto);
0048   IV ivEnd = allVetos.end();
0049 
0050   Distance maxDistance = {float(coneSize), 999.f};
0051   typedef DepositsMultimap::const_iterator IM;
0052   IM imLoc = theDeposits.upper_bound(maxDistance);
0053   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
0054     bool vetoed = false;
0055     for (IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
0056       Direction dirDep = theDirection + im->first;
0057       if (dirDep.deltaR(iv->vetoDir) < iv->dR)
0058         vetoed = true;
0059     }
0060     if (!vetoed && im->second > threshold) {
0061       result += im->second;
0062       count++;
0063     }
0064   }
0065   return std::pair<double, int>(result, count);
0066 }
0067 
0068 std::pair<double, int> IsoDeposit::depositAndCountWithin(
0069     Direction dir, double coneSize, const Vetos& vetos, double threshold, bool skipDepositVeto) const {
0070   double result = 0;
0071   int count = 0;
0072 
0073   Vetos allVetos = vetos;
0074   typedef Vetos::const_iterator IV;
0075   if (!skipDepositVeto)
0076     allVetos.push_back(theVeto);
0077   IV ivEnd = allVetos.end();
0078 
0079   typedef DepositsMultimap::const_iterator IM;
0080   for (IM im = theDeposits.begin(); im != theDeposits.end(); ++im) {
0081     bool vetoed = false;
0082     Direction dirDep = theDirection + im->first;
0083     Distance newDist = dirDep - dir;
0084     if (newDist.deltaR > coneSize)
0085       continue;
0086     for (IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
0087       if (dirDep.deltaR(iv->vetoDir) < iv->dR)
0088         vetoed = true;
0089     }
0090     if (!vetoed && im->second > threshold) {
0091       result += im->second;
0092       count++;
0093     }
0094   }
0095   return std::pair<double, int>(result, count);
0096 }
0097 
0098 std::pair<double, int> IsoDeposit::depositAndCountWithin(double coneSize,
0099                                                          const AbsVetos& vetos,
0100                                                          bool skipDepositVeto) const {
0101   using namespace reco::isodeposit;
0102   double result = 0;
0103   int count = 0;
0104   typedef AbsVetos::const_iterator IV;
0105 
0106   IV ivEnd = vetos.end();
0107 
0108   Distance maxDistance = {float(coneSize), 999.f};
0109   typedef DepositsMultimap::const_iterator IM;
0110   IM imLoc = theDeposits.upper_bound(maxDistance);
0111   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
0112     bool vetoed = false;
0113     Direction dirDep = theDirection + im->first;
0114     for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
0115       if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) {
0116         vetoed = true;
0117         break;
0118       }
0119     }
0120     if (!vetoed) {
0121       if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
0122         result += im->second;
0123         count++;
0124       }
0125     }
0126   }
0127   return std::pair<double, int>(result, count);
0128 }
0129 
0130 double IsoDeposit::depositWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0131   return depositAndCountWithin(coneSize, vetos, skipDepositVeto).first;
0132 }
0133 
0134 double IsoDeposit::countWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0135   return algoWithin<CountAlgo>(coneSize, vetos, skipDepositVeto);
0136 }
0137 double IsoDeposit::sumWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0138   return algoWithin<SumAlgo>(coneSize, vetos, skipDepositVeto);
0139 }
0140 double IsoDeposit::sumWithin(const Direction& dir, double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0141   return algoWithin<SumAlgo>(dir, coneSize, vetos, skipDepositVeto);
0142 }
0143 double IsoDeposit::sum2Within(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0144   return algoWithin<Sum2Algo>(coneSize, vetos, skipDepositVeto);
0145 }
0146 double IsoDeposit::maxWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0147   return algoWithin<MaxAlgo>(coneSize, vetos, skipDepositVeto);
0148 }
0149 
0150 double IsoDeposit::nearestDR(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
0151   using namespace reco::isodeposit;
0152   double result = coneSize;
0153   typedef AbsVetos::const_iterator IV;
0154 
0155   IV ivEnd = vetos.end();
0156 
0157   Distance maxDistance = {float(coneSize), 999.f};
0158   typedef DepositsMultimap::const_iterator IM;
0159   IM imLoc = theDeposits.upper_bound(maxDistance);
0160   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
0161     bool vetoed = false;
0162     Direction dirDep = theDirection + im->first;
0163     for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
0164       if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) {
0165         vetoed = true;
0166         break;
0167       }
0168     }
0169     if (!vetoed) {
0170       if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
0171         result = (dirDep.deltaR(theVeto.vetoDir) < result) ? dirDep.deltaR(theVeto.vetoDir) : result;
0172       }
0173     }
0174   }
0175   return result;
0176 }
0177 
0178 std::string IsoDeposit::print() const {
0179   std::ostringstream str;
0180   str << "Direction : " << theDirection.print() << std::endl;
0181   str << "Veto:       (" << theVeto.vetoDir.eta() << ", " << theVeto.vetoDir.phi() << " dR=" << theVeto.dR << ")"
0182       << std::endl;
0183   typedef DepositsMultimap::const_iterator IM;
0184   IM imEnd = theDeposits.end();
0185   for (IM im = theDeposits.begin(); im != imEnd; ++im) {
0186     str << "(dR=" << im->first.deltaR << ", alpha=" << im->first.relativeAngle << ", Pt=" << im->second << "),";
0187   }
0188   str << std::endl;
0189 
0190   return str.str();
0191 }