CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DataFormats/RecoCandidate/src/IsoDeposit.cc

Go to the documentation of this file.
00001 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00002 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include <sstream>
00006 
00007 using namespace reco;
00008 
00009 IsoDeposit::IsoDeposit(const Direction & candDirection)
00010   : theDirection(candDirection),theCandTag(0.)
00011 { 
00012   theVeto.vetoDir = theDirection;
00013   theVeto.dR = 0.;
00014 }
00015 
00016 IsoDeposit::IsoDeposit(double eta, double phi)
00017   : theDirection(Direction(eta,phi)), theCandTag(0.)
00018 { 
00019   theVeto.vetoDir = theDirection;
00020   theVeto.dR = 0.;
00021 }
00022 
00023 void IsoDeposit::addDeposit(double dr, double value){
00024   Distance relDir = {float(dr),0.f};
00025   theDeposits.insert( std::make_pair( relDir, value));
00026 }
00027 
00028 void IsoDeposit::addDeposit(const Direction & depDir, double deposit)
00029 {
00030   Distance relDir = depDir - theDirection;
00031   theDeposits.insert( std::make_pair( relDir,deposit));
00032 }
00033 
00034 double IsoDeposit::depositWithin(double coneSize, const Vetos& vetos, bool skipDepositVeto) const 
00035 {
00036   return depositAndCountWithin(coneSize, vetos, -1e+36, skipDepositVeto).first;
00037 }
00038 
00039 double IsoDeposit::depositWithin(Direction dir, double coneSize, const Vetos& vetos, bool skipDepositVeto) const 
00040 {
00041   return depositAndCountWithin(dir, coneSize, vetos, -1e+36, skipDepositVeto).first;
00042 }
00043 
00044 std::pair<double,int> IsoDeposit::depositAndCountWithin(double coneSize, const Vetos& vetos, 
00045                                                           double threshold, bool skipDepositVeto) const 
00046 {
00047   double result = 0;
00048   int count = 0;
00049 
00050   Vetos allVetos = vetos;
00051   typedef Vetos::const_iterator IV;
00052   if (!skipDepositVeto) allVetos.push_back(theVeto);
00053   IV ivEnd = allVetos.end();
00054 
00055   Distance maxDistance = {float(coneSize),999.f};
00056   typedef DepositsMultimap::const_iterator IM;
00057   IM imLoc = theDeposits.upper_bound( maxDistance ); 
00058   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
00059     bool vetoed = false;
00060     for ( IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
00061       Direction dirDep = theDirection+im->first;
00062       if (dirDep.deltaR(iv->vetoDir) < iv->dR) vetoed = true; 
00063     }  
00064     if (!vetoed && im->second > threshold){
00065       result += im->second;
00066       count++;
00067     }
00068   }
00069   return std::pair<double,int>(result,count);
00070 }
00071 
00072 std::pair<double,int> IsoDeposit::depositAndCountWithin(Direction dir, double coneSize, const Vetos& vetos, 
00073                                                           double threshold, bool skipDepositVeto) const 
00074 {
00075   double result = 0;
00076   int count = 0;
00077 
00078   Vetos allVetos = vetos;
00079   typedef Vetos::const_iterator IV;
00080   if (!skipDepositVeto) allVetos.push_back(theVeto);
00081   IV ivEnd = allVetos.end();
00082 
00083   typedef DepositsMultimap::const_iterator IM;
00084   for (IM im = theDeposits.begin(); im != theDeposits.end(); ++im) {
00085     bool vetoed = false;
00086     Direction dirDep = theDirection+im->first;
00087     Distance newDist = dirDep - dir;
00088     if (newDist.deltaR > coneSize) continue;
00089     for ( IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
00090       if (dirDep.deltaR(iv->vetoDir) < iv->dR) vetoed = true; 
00091     }  
00092     if (!vetoed && im->second > threshold){
00093       result += im->second;
00094       count++;
00095     }
00096   }
00097   return std::pair<double,int>(result,count);
00098 }
00099 
00100 std::pair<double,int>  IsoDeposit::depositAndCountWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00101 {
00102   using namespace reco::isodeposit;
00103   double result = 0;
00104   int count =  0;
00105   typedef AbsVetos::const_iterator IV;
00106 
00107   IV ivEnd = vetos.end();
00108 
00109   Distance maxDistance = {float(coneSize),999.f};
00110   typedef DepositsMultimap::const_iterator IM;
00111   IM imLoc = theDeposits.upper_bound( maxDistance ); 
00112   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
00113     bool vetoed = false;
00114     Direction dirDep = theDirection+im->first;
00115     for ( IV iv = vetos.begin(); iv < ivEnd; ++iv) {
00116       if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true;  break; }
00117     }
00118     if (!vetoed) {
00119        if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
00120           result += im->second;
00121                   count++;
00122         }
00123     }
00124   }
00125   return std::pair<double,int>(result,count);
00126 }
00127 
00128 
00129 double IsoDeposit::depositWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00130 {
00131         return depositAndCountWithin(coneSize, vetos, skipDepositVeto).first;
00132 }
00133 
00134 double IsoDeposit::countWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00135 {
00136         return algoWithin<CountAlgo>(coneSize, vetos, skipDepositVeto);
00137 }
00138 double IsoDeposit::sumWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00139 {
00140         return algoWithin<SumAlgo>(coneSize, vetos, skipDepositVeto);
00141 }
00142 double IsoDeposit::sumWithin(const Direction& dir, double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00143 {
00144         return algoWithin<SumAlgo>(dir, coneSize, vetos, skipDepositVeto);
00145 }
00146 double IsoDeposit::sum2Within(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00147 {
00148         return algoWithin<Sum2Algo>(coneSize, vetos, skipDepositVeto);
00149 }
00150 double IsoDeposit::maxWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00151 {
00152         return algoWithin<MaxAlgo>(coneSize, vetos, skipDepositVeto);
00153 }
00154 
00155 double IsoDeposit::nearestDR(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00156 {
00157   using namespace reco::isodeposit;
00158   double result = coneSize;
00159   typedef AbsVetos::const_iterator IV;
00160 
00161   IV ivEnd = vetos.end();
00162 
00163   Distance maxDistance = {float(coneSize),999.f};
00164   typedef DepositsMultimap::const_iterator IM;
00165   IM imLoc = theDeposits.upper_bound( maxDistance ); 
00166   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
00167     bool vetoed = false;
00168     Direction dirDep = theDirection+im->first;
00169     for ( IV iv = vetos.begin(); iv < ivEnd; ++iv) {
00170       if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true;  break; }
00171     }
00172     if (!vetoed) {
00173        if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
00174           result = ( dirDep.deltaR(theVeto.vetoDir) < result ) ? dirDep.deltaR(theVeto.vetoDir) : result;
00175         }
00176     }
00177   }
00178   return result;
00179 }
00180 
00181 std::string IsoDeposit::print() const {
00182   std::ostringstream str;
00183   str<<"Direction : "<<theDirection.print()<<std::endl;
00184   str<<"Veto:       ("<<theVeto.vetoDir.eta()<<", "<<theVeto.vetoDir.phi()<<" dR="<<theVeto.dR<<")"<<std::endl;
00185   typedef DepositsMultimap::const_iterator IM;
00186   IM imEnd = theDeposits.end();
00187   for (IM im = theDeposits.begin(); im != imEnd; ++im) {
00188     str<<"(dR="<< im->first.deltaR<<", alpha="<<im->first.relativeAngle<<", Pt="<<im->second<<"),";
00189   }
00190   str<<std::endl;
00191 
00192   
00193   
00194   return str.str();
00195 }